Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/starknet_os_runner/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use blockifier_reexecution::errors::ReexecutionError;
use starknet_os::errors::StarknetOsError;
use starknet_rust::providers::ProviderError;
use thiserror::Error;

Expand All @@ -23,6 +24,8 @@ pub enum RunnerError {
ProofProvider(#[from] ProofProviderError),
#[error(transparent)]
VirtualBlockExecutor(#[from] VirtualBlockExecutorError),
#[error(transparent)]
OsExecution(#[from] StarknetOsError),
#[error("OS Input generation failed: {0}")]
InputGenerationError(String),
}
Expand Down
70 changes: 58 additions & 12 deletions crates/starknet_os_runner/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ use blockifier::state::contract_class_manager::ContractClassManager;
use starknet_api::block::{BlockHash, BlockNumber};
use starknet_api::block_hash::block_hash_calculator::BlockHeaderCommitments;
use starknet_api::transaction::{InvokeTransaction, TransactionHash};
use starknet_os::io::os_input::{OsBlockInput, StarknetOsInput};
use starknet_os::io::os_input::{
OsBlockInput,
OsChainInfo,
OsHints,
OsHintsConfig,
StarknetOsInput,
};
use starknet_os::io::os_output::StarknetOsRunnerOutput;
use starknet_os::runner::{run_os_stateless, DEFAULT_OS_LAYOUT};

use crate::classes_provider::ClassesProvider;
use crate::errors::RunnerError;
Expand Down Expand Up @@ -32,29 +40,36 @@ where
Self { classes_provider, storage_proofs_provider, virtual_block_executor }
}

/// Creates the OS input hint required to run the given transactions virtually
/// Creates the OS hints required to run the given transactions virtually
/// on top of the given block number.
pub fn create_os_input(
pub fn create_os_hints(
&self,
block_number: BlockNumber,
contract_class_manager: ContractClassManager,
txs: Vec<(InvokeTransaction, TransactionHash)>,
) -> Result<StarknetOsInput, RunnerError> {
) -> Result<OsHints, RunnerError> {
// Execute virtual block and get execution data.
let mut execution_data = self.virtual_block_executor.execute(
block_number,
contract_class_manager,
txs.clone(),
)?;

// Fetch classes (consuming executed_class_hashes).
// Extract chain info from block context.
let chain_info = execution_data.block_context.chain_info();
let os_chain_info = OsChainInfo {
chain_id: chain_info.chain_id.clone(),
strk_fee_token_address: chain_info.fee_token_addresses.strk_fee_token_address,
};

// Fetch classes.
let classes = self.classes_provider.get_classes(&execution_data.executed_class_hashes)?;

// Fetch storage proofs (pass execution_data by reference to avoid moving yet).
// Fetch storage proofs.
let storage_proofs =
self.storage_proofs_provider.get_storage_proofs(block_number, &execution_data)?;

// vert execution outputs to CentralTransactionExecutionInfo (consuming).
// Convert execution outputs to CentralTransactionExecutionInfo.
let tx_execution_infos =
execution_data.execution_outputs.into_iter().map(|output| output.0.into()).collect();

Expand Down Expand Up @@ -102,11 +117,42 @@ where
initial_reads: execution_data.initial_reads,
};

// 7. Final StarknetOsInput (consuming classes).
Ok(StarknetOsInput {
os_block_inputs: vec![os_block_input],
deprecated_compiled_classes: classes.deprecated_compiled_classes,
compiled_classes: classes.compiled_classes,
// Build OsHints.
Ok(OsHints {
os_input: StarknetOsInput {
os_block_inputs: vec![os_block_input],
deprecated_compiled_classes: classes.deprecated_compiled_classes,
compiled_classes: classes.compiled_classes,
},
// TODO(Aviv): choose os hints config.
os_hints_config: OsHintsConfig {
debug_mode: false,
full_output: true,
use_kzg_da: false,
chain_info: os_chain_info,
public_keys: None,
rng_seed_salt: None,
},
})
}

/// Runs the Starknet OS with the given transactions.
///
/// This method:
/// 1. Executes transactions to collect state reads
/// 2. Fetches storage proofs and classes
/// 3. Builds OS hints
/// 4. Runs the OS in stateless mode (all state pre-loaded in input)
///
/// Returns the OS output containing the Cairo PIE and execution metrics.
pub fn run_os(
&self,
block_number: BlockNumber,
contract_class_manager: ContractClassManager,
txs: Vec<(InvokeTransaction, TransactionHash)>,
) -> Result<StarknetOsRunnerOutput, RunnerError> {
let os_hints = self.create_os_hints(block_number, contract_class_manager, txs)?;
let output = run_os_stateless(DEFAULT_OS_LAYOUT, os_hints)?;
Ok(output)
}
}