From c787deb8317243db5831c28aa4ee6219171a2534 Mon Sep 17 00:00:00 2001 From: Nisheeth Barthwal Date: Fri, 13 Sep 2024 16:20:29 +0200 Subject: [PATCH 1/3] take historical block count from env --- crates/zksync/core/src/vm/runner.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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) +} From 503afc3e9e3b5ccf23570e649f617a75d8911317 Mon Sep 17 00:00:00 2001 From: Nisheeth Barthwal Date: Fri, 13 Sep 2024 16:23:34 +0200 Subject: [PATCH 2/3] fmt --- crates/zksync/core/src/vm/runner.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/zksync/core/src/vm/runner.rs b/crates/zksync/core/src/vm/runner.rs index ce10ccbb6..aa33c8527 100644 --- a/crates/zksync/core/src/vm/runner.rs +++ b/crates/zksync/core/src/vm/runner.rs @@ -297,7 +297,8 @@ 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`. +/// 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) From bc6da8f196841ed260b124bcc70e583d5d4e6c68 Mon Sep 17 00:00:00 2001 From: Nisheeth Barthwal Date: Fri, 13 Sep 2024 16:32:35 +0200 Subject: [PATCH 3/3] fmt --- crates/zksync/core/src/vm/runner.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/zksync/core/src/vm/runner.rs b/crates/zksync/core/src/vm/runner.rs index aa33c8527..291ab045f 100644 --- a/crates/zksync/core/src/vm/runner.rs +++ b/crates/zksync/core/src/vm/runner.rs @@ -297,7 +297,7 @@ 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. +/// Get the number of historical blocks to fetch, from the env. /// Default: `256`. fn get_env_historical_block_count() -> u32 { let name = "ZK_DEBUG_HISTORICAL_BLOCK_HASHES";