Skip to content

Commit 92b91ea

Browse files
starknet_os_runner: execution data provider
1 parent 48e0a77 commit 92b91ea

File tree

5 files changed

+112
-1
lines changed

5 files changed

+112
-1
lines changed

Cargo.lock

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/starknet_os_runner/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ license-file.workspace = true
77
description = "Runs transactions through the Starknet OS and returns Cairo PIE and OS output."
88

99
[dependencies]
10+
blockifier.workspace = true
11+
blockifier_reexecution = { path = "../blockifier_reexecution" }
12+
starknet_api.workspace = true
13+
thiserror.workspace = true
1014

1115
[lints]
1216
workspace = true
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use blockifier_reexecution::errors::ReexecutionError;
2+
use thiserror::Error;
3+
4+
#[derive(Debug, Error)]
5+
pub enum ExecutionDataError {
6+
#[error(transparent)]
7+
ReexecutionError(#[from] ReexecutionError),
8+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
use blockifier::blockifier::transaction_executor::TransactionExecutionOutput;
2+
use blockifier::context::BlockContext;
3+
use blockifier::state::cached_state::StateMaps;
4+
use blockifier_reexecution::execute_single_transaction;
5+
use starknet_api::block::BlockNumber;
6+
use starknet_api::core::ChainId;
7+
use starknet_api::transaction::Transaction;
8+
9+
use crate::errors::ExecutionDataError;
10+
11+
/// Captures all execution data from blockifier needed for OS input generation.
12+
///
13+
/// This struct contains the complete execution state and context information that blockifier
14+
/// produces when executing a transaction. It serves as the foundation for generating the OS
15+
/// (Operating System) input required for proof generation.
16+
pub struct BlockifierExecutionData {
17+
/// The output from executing the transaction, including execution info and state changes.
18+
pub execution_output: TransactionExecutionOutput,
19+
/// The block context in which the transaction was executed.
20+
pub block_context: BlockContext,
21+
/// The initial state reads (accessed state) during transaction execution.
22+
pub initial_reads: StateMaps,
23+
}
24+
25+
/// Provides execution data from various sources for OS input generation.
26+
///
27+
/// This trait abstracts over different ways of obtaining transaction execution data from
28+
/// blockifier. Implementations can fetch execution data from different sources (RPC nodes,
29+
/// local state, mocked data, etc.).
30+
///
31+
/// The primary use case is the first step in OS input generation: capturing the necessary
32+
/// execution information from blockifier that will be used to construct the full OS input
33+
/// for proving.
34+
///
35+
/// # Examples
36+
///
37+
/// ```ignore
38+
/// let provider = RpcExecutionDataProvider {
39+
/// rpc_url: "http://localhost:9545".to_string(),
40+
/// chain_id: ChainId::Mainnet,
41+
/// };
42+
///
43+
/// let execution_data = provider.get_execution_data(block_number, transaction)?;
44+
/// // Use execution_data to build OS input...
45+
/// ```
46+
pub trait ExecutionDataProvider {
47+
/// Retrieves execution data for a transaction at a specific block.
48+
///
49+
/// # Arguments
50+
///
51+
/// * `block_number` - The block number at which to execute the transaction
52+
/// * `tx` - The transaction to execute
53+
///
54+
/// # Returns
55+
///
56+
/// Returns `BlockifierExecutionData` containing all execution information needed for OS
57+
/// input generation, or an error if execution fails.
58+
fn get_execution_data(
59+
&self,
60+
block_number: BlockNumber,
61+
tx: Transaction,
62+
) -> Result<BlockifierExecutionData, ExecutionDataError>;
63+
}
64+
65+
/// RPC-based implementation of `ExecutionDataProvider`.
66+
///
67+
/// This provider fetches historical state from an RPC node and uses blockifier's re-execution
68+
/// functionality to obtain execution data.
69+
pub struct RpcExecutionDataProvider {
70+
/// URL of the RPC node to fetch state from.
71+
pub rpc_url: String,
72+
/// The chain ID for which to execute transactions.
73+
pub chain_id: ChainId,
74+
}
75+
76+
impl ExecutionDataProvider for RpcExecutionDataProvider {
77+
fn get_execution_data(
78+
&self,
79+
block_number: BlockNumber,
80+
tx: Transaction,
81+
) -> Result<BlockifierExecutionData, ExecutionDataError> {
82+
let (execution_output, initial_reads, block_context) = execute_single_transaction(
83+
block_number,
84+
self.rpc_url.clone(),
85+
self.chain_id.clone(),
86+
tx,
87+
)?;
88+
89+
Ok(BlockifierExecutionData { execution_output, block_context, initial_reads })
90+
}
91+
}
92+
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
//! Starknet OS Runner - executes transactions through the OS and returns Cairo PIE and output.
1+
pub mod errors;
2+
pub mod execution_data;

0 commit comments

Comments
 (0)