Skip to content

Commit

Permalink
feat(starknet_os): get cached state as an input from python
Browse files Browse the repository at this point in the history
  • Loading branch information
nimrod-starkware committed Mar 4, 2025
1 parent a40b53d commit e8bc804
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
7 changes: 4 additions & 3 deletions crates/starknet_committer_and_os_cli/src/os_cli/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::Path;

use cairo_vm::types::layout_name::LayoutName;
use serde::Deserialize;
use starknet_os::io::os_input::StarknetOsInput;
use starknet_os::io::os_input::{CachedStateInput, StarknetOsInput};
use starknet_os::runner::run_os_stateless;
use tracing::info;

Expand All @@ -17,10 +17,11 @@ pub(crate) struct Input {
pub compiled_os_path: String,
pub layout: LayoutName,
pub os_input: StarknetOsInput,
pub cached_state_input: CachedStateInput,
}

pub fn parse_and_run_os(input_path: String, _output_path: String) {
let Input { compiled_os_path, layout, os_input } = load_input(input_path);
let Input { compiled_os_path, layout, os_input, cached_state_input } = load_input(input_path);
assert!(
os_input._transactions.len() == os_input._tx_execution_infos.len(),
"The number of transactions and execution infos should be equal"
Expand All @@ -31,5 +32,5 @@ pub fn parse_and_run_os(input_path: String, _output_path: String) {
let compiled_os =
fs::read(Path::new(&compiled_os_path)).expect("Failed to read compiled_os file");

let _ = run_os_stateless(&compiled_os, layout, os_input);
let _ = run_os_stateless(&compiled_os, layout, os_input, cached_state_input);
}
2 changes: 1 addition & 1 deletion crates/starknet_os/src/io/os_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub struct StarknetOsInput {
pub(crate) full_output: bool,
}

#[derive(Default)]
#[derive(Default, Debug)]
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
pub struct CachedStateInput {
pub(crate) storage: HashMap<ContractAddress, HashMap<StorageKey, Felt>>,
Expand Down
7 changes: 3 additions & 4 deletions crates/starknet_os/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub fn run_os<S: StateReader>(
layout: LayoutName,
os_input: StarknetOsInput,
state_reader: S,
cached_state_input: CachedStateInput,
) -> Result<StarknetOsRunnerOutput, StarknetOsError> {
// Init CairoRunConfig.
let cairo_run_config =
Expand All @@ -41,9 +42,6 @@ pub fn run_os<S: StateReader>(
// Init the Cairo VM.
let end = cairo_runner.initialize(allow_missing_builtins)?;

// TODO(Nimrod): Get `cached_state_input` as input.
let cached_state_input = CachedStateInput::default();

// Create execution helper.
let execution_helper =
OsExecutionHelper::new(os_input, os_program, state_reader, cached_state_input)?;
Expand Down Expand Up @@ -83,6 +81,7 @@ pub fn run_os_stateless(
compiled_os: &[u8],
layout: LayoutName,
os_input: StarknetOsInput,
cached_state_input: CachedStateInput,
) -> Result<StarknetOsRunnerOutput, StarknetOsError> {
run_os(compiled_os, layout, os_input, PanickingStateReader)
run_os(compiled_os, layout, os_input, PanickingStateReader, cached_state_input)
}
2 changes: 2 additions & 0 deletions scripts/sequencer-ci.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ ENV PATH=$PATH:${RUSTUP_HOME}/bin

COPY install_build_tools.sh .
COPY dependencies.sh .
COPY ../rust-toolchain.toml .

RUN ./install_build_tools.sh
RUN rustup toolchain install

0 comments on commit e8bc804

Please sign in to comment.