diff --git a/crates/zksync/core/src/vm/runner.rs b/crates/zksync/core/src/vm/runner.rs index 835b1efca..ce10ccbb6 100644 --- a/crates/zksync/core/src/vm/runner.rs +++ b/crates/zksync/core/src/vm/runner.rs @@ -275,10 +275,12 @@ pub fn encode_create_params( signature.iter().copied().chain(params).collect() } -/// Get last 256 block hashes mapped to block numbers. This excludes the current block. +/// Get historical block hashes mapped to block numbers. This excludes the current block. fn get_historical_block_hashes(ecx: &mut EvmContext) -> HashMap { let mut block_hashes = HashMap::default(); - for i in 1..=256u32 { + let num_blocks = get_env_historical_block_count(); + tracing::debug!("fetching last {num_blocks} block hashes"); + for i in 1..=num_blocks { let (block_number, overflow) = ecx.env.block.number.overflowing_sub(alloy_primitives::U256::from(i)); if overflow { @@ -294,3 +296,16 @@ fn get_historical_block_hashes(ecx: &mut EvmContext) -> HashMa block_hashes } + +/// Get the number of historical blocks to fetch for mapping to block hashes from env. Default: `256`. +fn get_env_historical_block_count() -> u32 { + let name = "ZK_DEBUG_HISTORICAL_BLOCK_HASHES"; + std::env::var(name) + .map(|value| { + value.parse::().unwrap_or_else(|err| { + panic!("failed parsing env variable {}={}, {:?}", name, value, err) + }) + }) + .map(|num| num.min(256)) + .unwrap_or(256) +}