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 1, 2024
1 parent 8a0e0e9 commit c9a39d6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
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 @@ -217,20 +217,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 validate_max_n_steps (u32) to usize."),
};

if !limit_steps_by_resources || !account_tx_context.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("Invalid max steps per tx: {0}.")]
InvalidMaxStepsPerTx(u32),
#[error("Invalid max validate steps per tx: {0}.")]
InvalidMaxValidateStepsPerTx(u32),
#[error(transparent)]
ParseError(#[from] ParseError),
#[error(transparent)]
Expand Down
22 changes: 20 additions & 2 deletions crates/native_blockifier/src/py_block_executor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;
use std::sync::Arc;

use blockifier::abi::constants::{MAX_STEPS_PER_TX, MAX_VALIDATE_STEPS_PER_TX};
use blockifier::block::{BlockInfo, GasPrices};
use blockifier::context::{BlockContext, ChainInfo, FeeTokenAddresses};
use blockifier::state::cached_state::{GlobalContractCache, GLOBAL_CONTRACT_CACHE_SIZE_FOR_TEST};
Expand All @@ -10,7 +11,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 Down Expand Up @@ -315,5 +316,22 @@ 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.try_into().expect("Failed to convert MAX_STEPS_PER_TX to u32.")
{
Err(NativeBlockifierInputError::InvalidMaxStepsPerTx(
versioned_constants.invoke_tx_max_n_steps,
))?
} else if versioned_constants.validate_max_n_steps
> MAX_VALIDATE_STEPS_PER_TX
.try_into()
.expect("Failed to convert MAX_VALIDATE_STEPS_PER_TX to u32.")
{
Err(NativeBlockifierInputError::InvalidMaxValidateStepsPerTx(
versioned_constants.validate_max_n_steps,
))?
} else {
Ok(BlockContext::new_unchecked(&block_info, &chain_info, versioned_constants))
}
}

0 comments on commit c9a39d6

Please sign in to comment.