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

Commit

Permalink
feat(execution): moved global max step limit to input validation
Browse files Browse the repository at this point in the history
Signed-off-by: Dori Medini <dori@starkware.co>
  • Loading branch information
dorimedini-starkware committed Feb 5, 2024
1 parent 29d2d5f commit 9dcc48e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
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)]
ParseError(#[from] ParseError),
#[error(transparent)]
Expand Down
18 changes: 16 additions & 2 deletions crates/native_blockifier/src/py_block_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use starknet_api::block::{BlockNumber, BlockTimestamp};
use starknet_api::core::{ChainId, ContractAddress};
use starknet_api::hash::StarkFelt;

use crate::errors::{NativeBlockifierError, NativeBlockifierResult};
use crate::errors::{NativeBlockifierError, NativeBlockifierInputError, NativeBlockifierResult};
use crate::py_state_diff::{PyBlockInfo, PyStateDiff};
use crate::py_transaction_execution_info::PyBouncerInfo;
use crate::py_utils::{int_to_chain_id, py_attr, versioned_constants_with_overrides, PyFelt};
Expand All @@ -22,6 +22,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 @@ -317,5 +320,16 @@ pub fn into_block_context(
use_kzg_da: block_info.use_kzg_da,
};

Ok(BlockContext::new_unchecked(&block_info, &chain_info, versioned_constants))
// 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,
))?
} else {
Ok(BlockContext::new_unchecked(&block_info, &chain_info, versioned_constants))
}
}

0 comments on commit 9dcc48e

Please sign in to comment.