Skip to content

Commit ba7e900

Browse files
starknet_os_runner: run os (#10941)
1 parent ec149ba commit ba7e900

File tree

2 files changed

+61
-12
lines changed

2 files changed

+61
-12
lines changed

crates/starknet_os_runner/src/errors.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use blockifier_reexecution::errors::ReexecutionError;
2+
use starknet_os::errors::StarknetOsError;
23
use starknet_rust::providers::ProviderError;
34
use thiserror::Error;
45

@@ -23,6 +24,8 @@ pub enum RunnerError {
2324
ProofProvider(#[from] ProofProviderError),
2425
#[error(transparent)]
2526
VirtualBlockExecutor(#[from] VirtualBlockExecutorError),
27+
#[error(transparent)]
28+
OsExecution(#[from] StarknetOsError),
2629
#[error("OS Input generation failed: {0}")]
2730
InputGenerationError(String),
2831
}

crates/starknet_os_runner/src/runner.rs

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ use blockifier::state::contract_class_manager::ContractClassManager;
44
use starknet_api::block::{BlockHash, BlockNumber};
55
use starknet_api::block_hash::block_hash_calculator::BlockHeaderCommitments;
66
use starknet_api::transaction::{InvokeTransaction, TransactionHash};
7-
use starknet_os::io::os_input::{OsBlockInput, StarknetOsInput};
7+
use starknet_os::io::os_input::{
8+
OsBlockInput,
9+
OsChainInfo,
10+
OsHints,
11+
OsHintsConfig,
12+
StarknetOsInput,
13+
};
14+
use starknet_os::io::os_output::StarknetOsRunnerOutput;
15+
use starknet_os::runner::{run_os_stateless, DEFAULT_OS_LAYOUT};
816

917
use crate::classes_provider::ClassesProvider;
1018
use crate::errors::RunnerError;
@@ -32,29 +40,36 @@ where
3240
Self { classes_provider, storage_proofs_provider, virtual_block_executor }
3341
}
3442

35-
/// Creates the OS input hint required to run the given transactions virtually
43+
/// Creates the OS hints required to run the given transactions virtually
3644
/// on top of the given block number.
37-
pub fn create_os_input(
45+
pub fn create_os_hints(
3846
&self,
3947
block_number: BlockNumber,
4048
contract_class_manager: ContractClassManager,
4149
txs: Vec<(InvokeTransaction, TransactionHash)>,
42-
) -> Result<StarknetOsInput, RunnerError> {
50+
) -> Result<OsHints, RunnerError> {
4351
// Execute virtual block and get execution data.
4452
let mut execution_data = self.virtual_block_executor.execute(
4553
block_number,
4654
contract_class_manager,
4755
txs.clone(),
4856
)?;
4957

50-
// Fetch classes (consuming executed_class_hashes).
58+
// Extract chain info from block context.
59+
let chain_info = execution_data.block_context.chain_info();
60+
let os_chain_info = OsChainInfo {
61+
chain_id: chain_info.chain_id.clone(),
62+
strk_fee_token_address: chain_info.fee_token_addresses.strk_fee_token_address,
63+
};
64+
65+
// Fetch classes.
5166
let classes = self.classes_provider.get_classes(&execution_data.executed_class_hashes)?;
5267

53-
// Fetch storage proofs (pass execution_data by reference to avoid moving yet).
68+
// Fetch storage proofs.
5469
let storage_proofs =
5570
self.storage_proofs_provider.get_storage_proofs(block_number, &execution_data)?;
5671

57-
// vert execution outputs to CentralTransactionExecutionInfo (consuming).
72+
// Convert execution outputs to CentralTransactionExecutionInfo.
5873
let tx_execution_infos =
5974
execution_data.execution_outputs.into_iter().map(|output| output.0.into()).collect();
6075

@@ -102,11 +117,42 @@ where
102117
initial_reads: execution_data.initial_reads,
103118
};
104119

105-
// 7. Final StarknetOsInput (consuming classes).
106-
Ok(StarknetOsInput {
107-
os_block_inputs: vec![os_block_input],
108-
deprecated_compiled_classes: classes.deprecated_compiled_classes,
109-
compiled_classes: classes.compiled_classes,
120+
// Build OsHints.
121+
Ok(OsHints {
122+
os_input: StarknetOsInput {
123+
os_block_inputs: vec![os_block_input],
124+
deprecated_compiled_classes: classes.deprecated_compiled_classes,
125+
compiled_classes: classes.compiled_classes,
126+
},
127+
// TODO(Aviv): choose os hints config.
128+
os_hints_config: OsHintsConfig {
129+
debug_mode: false,
130+
full_output: true,
131+
use_kzg_da: false,
132+
chain_info: os_chain_info,
133+
public_keys: None,
134+
rng_seed_salt: None,
135+
},
110136
})
111137
}
138+
139+
/// Runs the Starknet OS with the given transactions.
140+
///
141+
/// This method:
142+
/// 1. Executes transactions to collect state reads
143+
/// 2. Fetches storage proofs and classes
144+
/// 3. Builds OS hints
145+
/// 4. Runs the OS in stateless mode (all state pre-loaded in input)
146+
///
147+
/// Returns the OS output containing the Cairo PIE and execution metrics.
148+
pub fn run_os(
149+
&self,
150+
block_number: BlockNumber,
151+
contract_class_manager: ContractClassManager,
152+
txs: Vec<(InvokeTransaction, TransactionHash)>,
153+
) -> Result<StarknetOsRunnerOutput, RunnerError> {
154+
let os_hints = self.create_os_hints(block_number, contract_class_manager, txs)?;
155+
let output = run_os_stateless(DEFAULT_OS_LAYOUT, os_hints)?;
156+
Ok(output)
157+
}
112158
}

0 commit comments

Comments
 (0)