diff --git a/crates/blockifier/src/abi/constants.rs b/crates/blockifier/src/abi/constants.rs index 563a3f3f76..b444165259 100644 --- a/crates/blockifier/src/abi/constants.rs +++ b/crates/blockifier/src/abi/constants.rs @@ -29,8 +29,6 @@ pub const CONSUMED_MSG_TO_L2_ENCODED_DATA_SIZE: usize = (L1_TO_L2_MSG_HEADER_SIZE + 1) - CONSUMED_MSG_TO_L2_N_TOPICS; // Transaction resource names. -pub const MAX_VALIDATE_STEPS_PER_TX: usize = 1_000_000; -pub const MAX_STEPS_PER_TX: usize = 4_000_000; pub const L1_GAS_USAGE: &str = "l1_gas_usage"; pub const BLOB_GAS_USAGE: &str = "l1_blob_gas_usage"; pub const N_STEPS_RESOURCE: &str = "n_steps"; diff --git a/crates/blockifier/src/execution/entry_point.rs b/crates/blockifier/src/execution/entry_point.rs index 3b7a9c3bb3..bda9297017 100644 --- a/crates/blockifier/src/execution/entry_point.rs +++ b/crates/blockifier/src/execution/entry_point.rs @@ -202,20 +202,14 @@ impl EntryPointExecutionContext { let block_upper_bound = match mode { // TODO(Ori, 1/2/2024): Write an indicative expect message explaining why the conversion // works. - ExecutionMode::Validate => min( - versioned_constants - .validate_max_n_steps - .try_into() - .expect("Failed to convert u32 to usize."), - constants::MAX_VALIDATE_STEPS_PER_TX, - ), - ExecutionMode::Execute => min( - versioned_constants - .invoke_tx_max_n_steps - .try_into() - .expect("Failed to convert u32 to usize."), - constants::MAX_STEPS_PER_TX, - ), + ExecutionMode::Validate => versioned_constants + .validate_max_n_steps + .try_into() + .expect("Failed to convert validate_max_n_steps (u32) to usize."), + ExecutionMode::Execute => versioned_constants + .invoke_tx_max_n_steps + .try_into() + .expect("Failed to convert invoke_tx_max_n_steps (u32) to usize."), }; if !limit_steps_by_resources || !tx_info.enforce_fee()? { diff --git a/crates/native_blockifier/src/errors.rs b/crates/native_blockifier/src/errors.rs index d11a11b3cd..79383d478f 100644 --- a/crates/native_blockifier/src/errors.rs +++ b/crates/native_blockifier/src/errors.rs @@ -72,6 +72,10 @@ native_blockifier_errors!( #[derive(Debug, Error)] pub enum NativeBlockifierInputError { + #[error("Max steps per tx out of range: {0}")] + MaxStepsPerTxOutOfRange(u32), + #[error("Max validate steps per tx out of range: {0}")] + MaxValidateStepsPerTxOutOfRange(u32), #[error(transparent)] InvalidNativeBlockifierInputError(#[from] InvalidNativeBlockifierInputError), #[error(transparent)] diff --git a/crates/native_blockifier/src/py_block_executor.rs b/crates/native_blockifier/src/py_block_executor.rs index fb655df210..a696d8f8d8 100644 --- a/crates/native_blockifier/src/py_block_executor.rs +++ b/crates/native_blockifier/src/py_block_executor.rs @@ -30,6 +30,9 @@ use crate::transaction_executor::{RawTransactionExecutionInfo, TransactionExecut #[path = "py_block_executor_test.rs"] mod py_block_executor_test; +const MAX_STEPS_PER_TX: u32 = 4_000_000; +const MAX_VALIDATE_STEPS_PER_TX: u32 = 1_000_000; + #[pyclass] pub struct PyBlockExecutor { pub general_config: PyGeneralConfig, @@ -362,6 +365,17 @@ fn pre_process_block( let old_block_number_and_hash = old_block_number_and_hash .map(|(block_number, block_hash)| BlockNumberHashPair::new(block_number, block_hash.0)); + // Input validation. + if versioned_constants.invoke_tx_max_n_steps > MAX_STEPS_PER_TX { + return Err(NativeBlockifierInputError::MaxStepsPerTxOutOfRange( + versioned_constants.invoke_tx_max_n_steps, + ))?; + } else if versioned_constants.validate_max_n_steps > MAX_VALIDATE_STEPS_PER_TX { + return Err(NativeBlockifierInputError::MaxValidateStepsPerTxOutOfRange( + versioned_constants.validate_max_n_steps, + ))?; + } + let (block_info, chain_info) = into_block_context_args(general_config, block_info)?; let block_context = pre_process_block_blockifier( state,