Skip to content

Commit

Permalink
feat(starknet_os): initial API definition, execution helper (#3946)
Browse files Browse the repository at this point in the history
  • Loading branch information
dorimedini-starkware authored Feb 5, 2025
1 parent b0e1ed9 commit 88380d6
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/starknet_os/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ description = "The Starknet OS."
testing = ["dep:strum", "dep:strum_macros"]

[dependencies]
blockifier.workspace = true
cairo-vm.workspace = true
indoc.workspace = true
starknet-types-core.workspace = true
Expand Down
2 changes: 2 additions & 0 deletions crates/starknet_os/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[derive(Debug, thiserror::Error)]
pub enum StarknetOsError {}
1 change: 1 addition & 0 deletions crates/starknet_os/src/hint_processor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod execution_helper;
20 changes: 20 additions & 0 deletions crates/starknet_os/src/hint_processor/execution_helper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use blockifier::state::cached_state::CachedState;
use blockifier::state::state_api::StateReader;

use crate::io::os_input::StarknetOsInput;

/// A helper struct that provides access to the OS state and commitments.
pub struct OsExecutionHelper<S: StateReader> {
_cached_state: CachedState<S>,
}

impl<S: StateReader> OsExecutionHelper<S> {
pub fn new(os_input: &StarknetOsInput) -> Self {
Self { _cached_state: Self::initialize_cached_state(os_input) }
}

// TODO(Dori): Create a cached state with all initial read values from the OS input.
fn initialize_cached_state(_os_input: &StarknetOsInput) -> CachedState<S> {
todo!()
}
}
2 changes: 2 additions & 0 deletions crates/starknet_os/src/io.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod os_input;
pub mod os_output;
4 changes: 4 additions & 0 deletions crates/starknet_os/src/io/os_input.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// All input needed to initialize the execution helper.
// TODO(Dori): Add all fields needed to compute commitments, initialize a CachedState and other data
// required by the execution helper.
pub struct StarknetOsInput {}
9 changes: 9 additions & 0 deletions crates/starknet_os/src/io/os_output.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use cairo_vm::vm::runners::cairo_pie::CairoPie;

// TODO(Dori): Add fields.
pub struct StarknetOsOutput {}

pub struct StarknetOsRunnerOutput {
pub os_output: StarknetOsOutput,
pub cairo_pie: CairoPie,
}
4 changes: 4 additions & 0 deletions crates/starknet_os/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
pub mod errors;
pub mod hint_processor;
pub mod hints;
pub mod io;
pub mod runner;
18 changes: 18 additions & 0 deletions crates/starknet_os/src/runner.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use blockifier::context::BlockContext;
use blockifier::state::state_api::StateReader;
use cairo_vm::types::layout_name::LayoutName;

use crate::errors::StarknetOsError;
use crate::hint_processor::execution_helper::OsExecutionHelper;
use crate::io::os_input::StarknetOsInput;
use crate::io::os_output::StarknetOsRunnerOutput;

pub fn run_os<S: StateReader>(
_compiled_os: &[u8],
_layout: LayoutName,
_block_context: BlockContext,
os_input: &StarknetOsInput,
) -> Result<StarknetOsRunnerOutput, StarknetOsError> {
let _execution_helper = OsExecutionHelper::<S>::new(os_input);
todo!()
}

0 comments on commit 88380d6

Please sign in to comment.