Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

feat(execution): moved global max step limit to input validation #1415

Merged
merged 1 commit into from
Feb 6, 2024
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
2 changes: 0 additions & 2 deletions crates/blockifier/src/abi/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
22 changes: 8 additions & 14 deletions crates/blockifier/src/execution/entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()? {
Expand Down
4 changes: 4 additions & 0 deletions crates/native_blockifier/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
14 changes: 14 additions & 0 deletions crates/native_blockifier/src/py_block_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Err(NativeBlockifierInputError::MaxStepsPerTxOutOfRange(
versioned_constants.invoke_tx_max_n_steps,
))?;
} else if versioned_constants.validate_max_n_steps > MAX_VALIDATE_STEPS_PER_TX {
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,
Expand Down
Loading