You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently when creating the `ClassInfo` struct from Blockifier, the values used aren't accurate.
First, the sierra version is actually the CASM compiler version. The sierra version is encoded into the `sierra_program` field of a Starknet contract class artifact. The `sierra_program` is a list of field elements and the first six elements are reserved for the compilers - first 3 for sierra compiler version and last 3 for casm compiler version. Fyi, Blockifier performs a sierra version check when executing a contract execution to determine what resource to [track].
Second, we are using mock values for both sierra program length and abi length. I'm not exactly sure what's the specification of the ABI length, but I've referenced with the official StarkWare's [implementation] and it seems to be the length of the ABI in its RPC format i.e., a string of JSON.
The implementation for getting the ABI length is not optimized and would require to be computed every time the class is fetched from database -> class cache.
These values are important for ensuring deterministic executions as they affect transaction execution as well as fees.
[track]:
https://github.com/dojoengine/sequencer/blob/3c206344dc64b5a0f150ea94cd2623b2a9a7da63/crates/blockifier/src/execution/contract_class.rs#L258
[implementation]:
https://github.com/dojoengine/sequencer/blob/3c206344dc64b5a0f150ea94cd2623b2a9a7da63/crates/apollo_rpc/src/v0_8/api/mod.rs#L453-L477
let versioned_constants = block_context.versioned_constants();
82
+
let l2_gas_per_step = versioned_constants.os_constants.gas_costs.base.step_gas_cost;
83
+
84
+
// Convert the sierra gas to cairo steps for the run resources.
85
+
//
86
+
// If values can't fit in a usize, use the maximum. This is to mimic the behaviour of
87
+
// blockifier.
88
+
//
89
+
// For reference: https://github.com/dojoengine/sequencer/blob/5d737b9c90a14bdf4483d759d1a1d4ce64aa9fd2/crates/blockifier/src/execution/entry_point.rs#L382C1-L451
90
+
let n_steps = max_sierra_gas.saturating_div(l2_gas_per_step);
91
+
let n_steps = n_steps.try_into().unwrap_or(usize::MAX);
let call_info = call.execute(state,&mut ctx,&mut remaining_gas)?;
82
96
83
-
// In Starknet 0.13.4 calls return error as return data (Ok variant) instead of returning as an
97
+
// Calls return error as the return data (Ok variant) instead of returning as an
84
98
// Err. Refer to: https://github.com/dojoengine/sequencer/blob/5d737b9c90a14bdf4483d759d1a1d4ce64aa9fd2/crates/blockifier/src/execution/execution_utils.rs#L74
/// Returns the Sierra gas consumed by the contract call execution.
120
+
///
121
+
/// Depending on the the Sierra compiler version of the class, the resources used for the contract
122
+
/// call execution may either be tracked as Cairo steps or Sierra gas. Note that `blockifier`
123
+
/// doesn't store the actual tracked resource consumed value in a single variable of the `CallInfo`
124
+
/// struct but as separate variables i.e., `gas_consumed` of [`CallExecution`] and `n_steps` of
125
+
/// [`ExecutionResources`] for Sierra gas and Cairo steps respectively.
126
+
///
127
+
/// For reference: https://github.com/dojoengine/sequencer/blob/5d737b9c90a14bdf4483d759d1a1d4ce64aa9fd2/crates/blockifier/src/execution/entry_point_execution.rs#L367-L433
0 commit comments