diff --git a/crates/batcher/src/block_builder.rs b/crates/batcher/src/block_builder.rs index 92193f9c26b..c2ac6970376 100644 --- a/crates/batcher/src/block_builder.rs +++ b/crates/batcher/src/block_builder.rs @@ -26,7 +26,13 @@ use papyrus_config::dumping::{append_sub_config_name, ser_param, SerializeConfig use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam}; use papyrus_storage::StorageReader; use serde::{Deserialize, Serialize}; -use starknet_api::block::{BlockHashAndNumber, BlockNumber, BlockTimestamp, NonzeroGasPrice}; +use starknet_api::block::{ + BlockHashAndNumber, + BlockNumber, + BlockTimestamp, + NonzeroGasPrice, + StarknetVersion, +}; use starknet_api::core::ContractAddress; use starknet_api::executable_transaction::Transaction; use starknet_api::transaction::TransactionHash; @@ -256,6 +262,7 @@ impl BlockBuilderFactory { GasPrices::new(tmp_val, tmp_val, tmp_val, tmp_val, tmp_val, tmp_val) }, use_kzg_da: block_builder_config.use_kzg_da, + starknet_version: StarknetVersion::LATEST, }; let block_context = BlockContext::new( next_block_info, diff --git a/crates/blockifier/src/blockifier/block.rs b/crates/blockifier/src/blockifier/block.rs index 83aca48b1c4..e922adc3266 100644 --- a/crates/blockifier/src/blockifier/block.rs +++ b/crates/blockifier/src/blockifier/block.rs @@ -6,6 +6,7 @@ use starknet_api::block::{ GasPrice, GasPriceVector, NonzeroGasPrice, + StarknetVersion, }; use starknet_api::core::ContractAddress; use starknet_api::state::StorageKey; @@ -30,6 +31,7 @@ pub struct BlockInfo { pub sequencer_address: ContractAddress, pub gas_prices: GasPrices, pub use_kzg_da: bool, + pub starknet_version: StarknetVersion, } #[cfg_attr(feature = "transaction_serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/crates/blockifier/src/test_utils/struct_impls.rs b/crates/blockifier/src/test_utils/struct_impls.rs index 714ff8d56ed..41526a3997f 100644 --- a/crates/blockifier/src/test_utils/struct_impls.rs +++ b/crates/blockifier/src/test_utils/struct_impls.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass; use cairo_vm::vm::runners::cairo_runner::ExecutionResources; use serde_json::Value; -use starknet_api::block::{BlockNumber, BlockTimestamp, NonzeroGasPrice}; +use starknet_api::block::{BlockNumber, BlockTimestamp, NonzeroGasPrice, StarknetVersion}; use starknet_api::core::{ChainId, ClassHash, ContractAddress, Nonce}; use starknet_api::deprecated_contract_class::ContractClass as DeprecatedContractClass; use starknet_api::transaction::{Fee, TransactionHash, TransactionVersion}; @@ -157,6 +157,7 @@ impl BlockInfo { .unwrap(), ), use_kzg_da: false, + starknet_version: StarknetVersion::LATEST, } } diff --git a/crates/gateway/src/errors.rs b/crates/gateway/src/errors.rs index 5ffc49f2cee..ab16e97ab2d 100644 --- a/crates/gateway/src/errors.rs +++ b/crates/gateway/src/errors.rs @@ -3,6 +3,7 @@ use blockifier::state::errors::StateError; use serde_json::{Error as SerdeError, Value}; use starknet_api::block::GasPrice; use starknet_api::transaction::{Resource, ResourceBounds}; +use starknet_api::StarknetApiError; use starknet_gateway_types::errors::GatewaySpecError; use thiserror::Error; @@ -84,6 +85,8 @@ pub enum RPCStateReaderError { ReqwestError(#[from] reqwest::Error), #[error("Unexpected error code: {0}")] UnexpectedErrorCode(u16), + #[error(transparent)] + StarknetAPIError(#[from] StarknetApiError), } pub type RPCStateReaderResult = Result; diff --git a/crates/gateway/src/rpc_objects.rs b/crates/gateway/src/rpc_objects.rs index e6118f393bb..fef3e7eec2e 100644 --- a/crates/gateway/src/rpc_objects.rs +++ b/crates/gateway/src/rpc_objects.rs @@ -93,6 +93,7 @@ impl TryInto for BlockHeader { parse_gas_price(self.l2_gas_price.price_in_fri)?, ), use_kzg_da: matches!(self.l1_da_mode, L1DataAvailabilityMode::Blob), + starknet_version: self.starknet_version.try_into()?, }) } } diff --git a/crates/native_blockifier/src/py_state_diff.rs b/crates/native_blockifier/src/py_state_diff.rs index 70f15e98e39..5e9a5532535 100644 --- a/crates/native_blockifier/src/py_state_diff.rs +++ b/crates/native_blockifier/src/py_state_diff.rs @@ -13,7 +13,7 @@ use blockifier::versioned_constants::VersionedConstants; use indexmap::IndexMap; use pyo3::prelude::*; use pyo3::FromPyObject; -use starknet_api::block::{BlockNumber, BlockTimestamp, NonzeroGasPrice}; +use starknet_api::block::{BlockNumber, BlockTimestamp, NonzeroGasPrice, StarknetVersion}; use starknet_api::core::{ClassHash, ContractAddress, Nonce}; use starknet_api::state::{StateDiff, StorageKey}; @@ -144,6 +144,7 @@ pub struct PyBlockInfo { pub l2_gas_price: PyResourcePrice, pub sequencer_address: PyFelt, pub use_kzg_da: bool, + pub starknet_version: Option, } /// Block info cannot have gas prices set to zero; implement `Default` explicitly. @@ -170,6 +171,7 @@ impl Default for PyBlockInfo { }, sequencer_address: PyFelt::default(), use_kzg_da: bool::default(), + starknet_version: Some(StarknetVersion::LATEST.into()), } } } @@ -231,6 +233,10 @@ impl TryFrom for BlockInfo { })?, ), use_kzg_da: block_info.use_kzg_da, + starknet_version: block_info + .starknet_version + .unwrap_or(StarknetVersion::LATEST.into()) + .try_into()?, }) } } diff --git a/crates/papyrus_execution/src/lib.rs b/crates/papyrus_execution/src/lib.rs index 228b698cf52..055449a6a8c 100644 --- a/crates/papyrus_execution/src/lib.rs +++ b/crates/papyrus_execution/src/lib.rs @@ -371,6 +371,10 @@ fn create_block_context( } }; + let starknet_version = storage_reader + .begin_ro_txn()? + .get_starknet_version(block_number)? + .unwrap_or(StarknetVersion::LATEST); let block_info = BlockInfo { block_timestamp, sequencer_address: sequencer_address.0, @@ -385,6 +389,7 @@ fn create_block_context( NonzeroGasPrice::new(l2_gas_price.price_in_wei).unwrap_or(NonzeroGasPrice::MIN), NonzeroGasPrice::new(l2_gas_price.price_in_fri).unwrap_or(NonzeroGasPrice::MIN), ), + starknet_version, }; let chain_info = ChainInfo { chain_id, @@ -393,10 +398,6 @@ fn create_block_context( eth_fee_token_address: execution_config.eth_fee_contract_address, }, }; - let starknet_version = storage_reader - .begin_ro_txn()? - .get_starknet_version(block_number)? - .unwrap_or(StarknetVersion::LATEST); let versioned_constants = VersionedConstants::get(&starknet_version)?; let block_context = BlockContext::new(