Skip to content

feat(starknet_os): add OsOutput and complete run_os function #5020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

TzahiTaub
Copy link
Contributor

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@TzahiTaub TzahiTaub marked this pull request as ready for review March 18, 2025 12:58
@TzahiTaub TzahiTaub self-assigned this Mar 18, 2025
Copy link
Contributor Author

@TzahiTaub TzahiTaub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 2 files reviewed, 1 unresolved discussion (waiting on @dorimedini-starkware)


crates/starknet_os/src/io/os_output.rs line 0 at r1 (raw file):
Based on the snos output file. There is no need for deserializing the output - the python side does it by itself.

Copy link
Collaborator

@dorimedini-starkware dorimedini-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @TzahiTaub)


crates/starknet_os/src/io/os_output.rs line at r1 (raw file):

Previously, TzahiTaub (Tzahi) wrote…

Based on the snos output file. There is no need for deserializing the output - the python side does it by itself.

well, can you add a TODO to define a struct for it?
not useful now, but when this crate is used as a library for running the OS it will be necessary


crates/starknet_os/src/io/os_output.rs line 8 at r1 (raw file):

use cairo_vm::vm::runners::cairo_pie::CairoPie;
use cairo_vm::vm::vm_core::VirtualMachine;
use cairo_vm::Felt252;

same type, Felt252 is just a re-export

Suggestion:

use starknet_types_core::felt::Felt;

crates/starknet_os/src/io/os_output.rs line 36 at r1 (raw file):

    let builtin_end_ptrs = vm
        .get_return_values(n_builtins)
        .map_err(|err| StarknetOsError::VirtualMachineError(err.into()))?;

don't we have a Memory variant in our error enum? get_return_values returns a MemoryError error type

Code quote:

        .get_return_values(n_builtins)
        .map_err(|err| StarknetOsError::VirtualMachineError(err.into()))?;

crates/starknet_os/src/io/os_output.rs line 41 at r1 (raw file):

    let output_size = builtin_end_ptrs
        .iter()
        .find_map(|ptr| {

why find_map and not the first value?

Code quote:

    let output_size = builtin_end_ptrs
        .iter()
        .find_map(|ptr| {

crates/starknet_os/src/io/os_output.rs line 95 at r1 (raw file):

        .collect();

    raw_output

this way, you don't need explicit type hinting for the collect()

Suggestion:

    Ok(range_of_output
        .iter()
        .map(|x| match x {
            Some(cow) => match **cow {
                MaybeRelocatable::Int(val) => Ok(val),
                MaybeRelocatable::RelocatableValue(val) => {
                    Err(StarknetOsError::VirtualMachineError(
                        VirtualMachineError::ExpectedIntAtRange(Box::new(Some(val.into()))),
                    ))
                }
            },
            None => Err(StarknetOsError::VirtualMachineError(
                MemoryError::MissingMemoryCells(BuiltinName::output.into()).into(),
            )),
        })
        .collect())

crates/starknet_os/src/runner.rs line 77 at r1 (raw file):

    let os_output = get_run_output(&cairo_runner.vm)?;

    log::debug!("output: {}", serde_json::to_string_pretty(&os_output).unwrap());

won't this bloat our logs with random integers?

Code quote:

 log::debug!("output: {}", serde_json::to_string_pretty(&os_output).unwrap());

crates/starknet_os/src/runner.rs line 87 at r1 (raw file):

        .map_err(|e| StarknetOsError::VirtualMachineError(e.into()))?;

    // Parse the Cairo VM output

non blocking...

Suggestion:

// Parse the Cairo VM output.

@TzahiTaub TzahiTaub force-pushed the 03-18-feat_starknet_os_add_osoutput_and_complete_run_os_function branch from 5b9d257 to 351f3eb Compare March 18, 2025 18:17
Copy link
Contributor Author

@TzahiTaub TzahiTaub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @dorimedini-starkware)


crates/starknet_os/src/runner.rs line 77 at r1 (raw file):

Previously, dorimedini-starkware wrote…

won't this bloat our logs with random integers?

Right, this made sense when the os_output was a struct and not raw data.


crates/starknet_os/src/io/os_output.rs line 8 at r1 (raw file):

Previously, dorimedini-starkware wrote…

same type, Felt252 is just a re-export

Done.


crates/starknet_os/src/io/os_output.rs line 36 at r1 (raw file):

Previously, dorimedini-starkware wrote…

don't we have a Memory variant in our error enum? get_return_values returns a MemoryError error type

The cairo-vm VirtualMachineError has a Memory variant, and this is what we'll raise (this is what the into does from MemoryError to the VirtualMachineError - Memory variant.


crates/starknet_os/src/io/os_output.rs line 41 at r1 (raw file):

Previously, dorimedini-starkware wrote…

why find_map and not the first value?

I'm just not sure if the order of the builtins is some commitment or it can change, so I prefer to find it. They also did it in snos (if you ask because you compared) - but in a weird way - they read cell 0, and then assert the segment index of the Relocatable in cell 0, is the same as of the output_basefrom above.


crates/starknet_os/src/io/os_output.rs line 95 at r1 (raw file):

Previously, dorimedini-starkware wrote…

this way, you don't need explicit type hinting for the collect()

It's OK without the Ok.

Copy link
Collaborator

@dorimedini-starkware dorimedini-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 2 of 2 files at r2, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @TzahiTaub)


crates/starknet_os/src/runner.rs line 77 at r1 (raw file):

Previously, TzahiTaub (Tzahi) wrote…

Right, this made sense when the os_output was a struct and not raw data.

maybe add a TODO to log the output once we structify it in rust

@TzahiTaub TzahiTaub added this pull request to the merge queue Mar 18, 2025
Merged via the queue into main with commit afc29df Mar 18, 2025
10 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants