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
17 changes: 13 additions & 4 deletions crates/executor/src/implementation/blockifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::sync::Arc;

// Re-export the blockifier crate.
pub use blockifier;
use blockifier::blockifier_versioned_constants::VersionedConstants;
use blockifier::bouncer::{n_steps_to_sierra_gas, Bouncer, BouncerConfig, BouncerWeights};

pub mod cache;
Expand Down Expand Up @@ -99,6 +100,7 @@ pub struct StarknetVMProcessor<'a> {
stats: ExecutionStats,
bouncer: Bouncer,
starknet_version: StarknetVersion,
cfg_env: CfgEnv,
}

impl<'a> StarknetVMProcessor<'a> {
Expand Down Expand Up @@ -134,6 +136,7 @@ impl<'a> StarknetVMProcessor<'a> {
let bouncer = Bouncer::new(BouncerConfig { block_max_capacity });

Self {
cfg_env,
state,
transactions,
block_context,
Expand Down Expand Up @@ -165,10 +168,6 @@ impl<'a> StarknetVMProcessor<'a> {
NonzeroGasPrice::new(header.l1_data_gas_prices.strk.get().into())
.unwrap_or(NonzeroGasPrice::MIN);

// TODO: @kariy, not sure here if we should add some functions to alter it
// instead of cloning. Or did I miss a function?
// https://github.com/starkware-libs/blockifier/blob/a6200402ab635d8a8e175f7f135be5914c960007/crates/blockifier/src/context.rs#L23
let versioned_constants = self.block_context.versioned_constants().clone();
let chain_info = self.block_context.chain_info().clone();
let block_info = BlockInfo {
block_number: number,
Expand All @@ -189,6 +188,16 @@ impl<'a> StarknetVMProcessor<'a> {
use_kzg_da: false,
};

let sn_version = header.starknet_version.try_into().expect("valid version");
let mut versioned_constants = VersionedConstants::get(&sn_version).unwrap().clone();

// NOTE:
// These overrides would potentially make the `snos` run be invalid as it doesn't know about
// the new overridden values.
versioned_constants.max_recursion_depth = self.cfg_env.max_recursion_depth;
versioned_constants.validate_max_n_steps = self.cfg_env.validate_max_n_steps;
versioned_constants.invoke_tx_max_n_steps = self.cfg_env.invoke_tx_max_n_steps;

self.starknet_version = header.starknet_version;
self.block_context = Arc::new(BlockContext::new(
block_info,
Expand Down
23 changes: 13 additions & 10 deletions crates/executor/src/implementation/blockifier/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,16 @@ pub fn block_context_from_envs(block_env: &BlockEnv, cfg_env: &CfgEnv) -> BlockC
strk_fee_token_address: to_blk_address(cfg_env.fee_token_addresses.strk),
};

let eth_l2_gas_price = NonzeroGasPrice::new(block_env.l2_gas_prices.eth.get().into())
.unwrap_or(NonzeroGasPrice::MIN);
let strk_l2_gas_price = NonzeroGasPrice::new(block_env.l2_gas_prices.strk.get().into())
.unwrap_or(NonzeroGasPrice::MIN);

let eth_l1_gas_price = NonzeroGasPrice::new(block_env.l1_gas_prices.eth.get().into())
.unwrap_or(NonzeroGasPrice::MIN);
let strk_l1_gas_price = NonzeroGasPrice::new(block_env.l1_gas_prices.strk.get().into())
.unwrap_or(NonzeroGasPrice::MIN);

let eth_l1_data_gas_price = NonzeroGasPrice::new(block_env.l1_data_gas_prices.eth.get().into())
.unwrap_or(NonzeroGasPrice::MIN);
let strk_l1_data_gas_price =
Expand All @@ -446,16 +452,14 @@ pub fn block_context_from_envs(block_env: &BlockEnv, cfg_env: &CfgEnv) -> BlockC

let gas_prices = GasPrices {
eth_gas_prices: GasPriceVector {
l2_gas_price: eth_l2_gas_price,
l1_gas_price: eth_l1_gas_price,
l1_data_gas_price: eth_l1_data_gas_price,
// TODO: update to use the correct value
l2_gas_price: eth_l1_gas_price,
},
strk_gas_prices: GasPriceVector {
l2_gas_price: strk_l2_gas_price,
l1_gas_price: strk_l1_gas_price,
l1_data_gas_price: strk_l1_data_gas_price,
// TODO: update to use the correct value
l2_gas_price: strk_l1_gas_price,
},
};

Expand All @@ -471,12 +475,11 @@ pub fn block_context_from_envs(block_env: &BlockEnv, cfg_env: &CfgEnv) -> BlockC

// IMPORTANT:
//
// The versioned constants that we use here must match the version that is used in `snos`.
// Otherwise, there might be a mismatch between the calculated fees.
//
// The version of `snos` we're using is still limited up to Starknet version `0.13.3`.
const SN_VERSION: StarknetVersion = StarknetVersion::V0_13_4;
let mut versioned_constants = VersionedConstants::get(&SN_VERSION).unwrap().clone();
// The versioned constants that we use here must match the version that is used during
// re-execution with `snos`. Otherwise, there might be a mismatch between the calculated
// fees.
let sn_version: StarknetVersion = block_env.starknet_version.try_into().expect("valid version");
let mut versioned_constants = VersionedConstants::get(&sn_version).unwrap().clone();

// NOTE:
// These overrides would potentially make the `snos` run be invalid as it doesn't know about the
Expand Down
41 changes: 40 additions & 1 deletion crates/primitives/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

impl core::default::Default for StarknetVersion {
fn default() -> Self {
StarknetVersion::new([0, 1, 0, 0])
CURRENT_STARKNET_VERSION
}
}

Expand Down Expand Up @@ -104,6 +104,45 @@
}
}

/// An error when the version doesn't correspond to any of the official Starknet releases.
///
/// List for all of the official releases can be found at <https://docs.starknet.io/resources/version-notes/>
#[derive(thiserror::Error, Debug)]
#[error("invalid version: {0}")]
pub struct InvalidVersionError(StarknetVersion);

impl TryFrom<StarknetVersion> for starknet_api::block::StarknetVersion {
type Error = InvalidVersionError;

fn try_from(version: StarknetVersion) -> Result<Self, Self::Error> {
match version.segments {
[0, 9, 1, 0] => Ok(Self::V0_9_1),
[0, 10, 0, 0] => Ok(Self::V0_10_0),
[0, 10, 1, 0] => Ok(Self::V0_10_1),
[0, 10, 2, 0] => Ok(Self::V0_10_2),
[0, 10, 3, 0] => Ok(Self::V0_10_3),
[0, 11, 0, 0] => Ok(Self::V0_11_0),
[0, 11, 0, 2] => Ok(Self::V0_11_0_2),
[0, 11, 1, 0] => Ok(Self::V0_11_1),
[0, 11, 2, 0] => Ok(Self::V0_11_2),
[0, 12, 0, 0] => Ok(Self::V0_12_0),
[0, 12, 1, 0] => Ok(Self::V0_12_1),
[0, 12, 2, 0] => Ok(Self::V0_12_2),
[0, 12, 3, 0] => Ok(Self::V0_12_3),
[0, 13, 0, 0] => Ok(Self::V0_13_0),
[0, 13, 1, 0] => Ok(Self::V0_13_1),

Check warning on line 133 in crates/primitives/src/version.rs

View check run for this annotation

Codecov / codecov/patch

crates/primitives/src/version.rs#L119-L133

Added lines #L119 - L133 were not covered by tests
[0, 13, 1, 1] => Ok(Self::V0_13_3),
[0, 13, 2, 0] => Ok(Self::V0_13_2),
[0, 13, 2, 1] => Ok(Self::V0_13_2_1),
[0, 13, 3, 0] => Ok(Self::V0_13_3),
[0, 13, 4, 0] => Ok(Self::V0_13_4),
[0, 13, 5, 0] => Ok(Self::V0_13_5),
[0, 14, 0, 0] => Ok(Self::V0_14_0),
_ => Err(InvalidVersionError(version)),

Check warning on line 141 in crates/primitives/src/version.rs

View check run for this annotation

Codecov / codecov/patch

crates/primitives/src/version.rs#L135-L141

Added lines #L135 - L141 were not covered by tests
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading