Skip to content

Commit 2c05bd8

Browse files
authored
chore: upgrade revm to v40, rust toolchain to nightly-2024-07-07 (#16)
* upgrade revm to v37 * suppress log * bps counter * fix * less log * noticeable log * short hash * upgrade revm and rust toolchain * remove legacy feature gate * upgrade to v40 * update zkevm-circuits
1 parent 17b633f commit 2c05bd8

File tree

10 files changed

+181
-80
lines changed

10 files changed

+181
-80
lines changed

Cargo.lock

Lines changed: 146 additions & 58 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ log = "0.4"
88
hex = "0.4"
99
eth-types = { git = "https://github.com/scroll-tech/zkevm-circuits", features = ["scroll"], branch = "develop" }
1010
mpt-zktrie = { git = "https://github.com/scroll-tech/zkevm-circuits", branch = "develop" }
11-
revm = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v36" , default-features = false, features = ["scroll-default-handler", "std", "optional_no_base_fee"] } # v36
11+
revm = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v40" , default-features = false, features = ["scroll-default-handler", "std", "optional_no_base_fee"] } # v40
1212
zktrie = { git = "https://github.com/scroll-tech/zktrie.git", branch = "main", features= ["rs_zktrie"] }
1313

1414
# for local development
1515
#eth-types = { path = "../zkevm-circuits/eth-types", features = ["scroll"] }
1616
#mpt-zktrie = { path = "../zkevm-circuits/zktrie" }
17-
#revm = {path = "../revm/crates/revm", default-features = false, features = ["scroll-default-handler", "std", "optional_no_base_fee"] } # v36
17+
#revm = {path = "../revm/crates/revm", default-features = false, features = ["scroll-default-handler", "std", "optional_no_base_fee"] } # v37
1818

1919
# binary dependencies
2020
anyhow = { version = "1.0", optional = true }

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[toolchain]
2-
channel = "nightly-2023-12-03"
2+
channel = "nightly-2024-07-07"

src/bin/trace-verifier/commands/run_rpc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl RunRpcCommand {
9191
.await?;
9292

9393
info!(
94-
"worker#{idx}: load trace for block #{block_number}({:?})",
94+
"worker#{idx}: load trace for block #{block_number}({})",
9595
l2_trace.header.hash.unwrap()
9696
);
9797

src/bin/trace-verifier/main.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(lazy_cell)]
2-
#![feature(slice_group_by)]
31
#[macro_use]
42
extern crate log;
53

src/bin/trace-verifier/utils.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
use eth_types::l2_types::BlockTrace;
22
use eth_types::ToWord;
33
use stateless_block_verifier::{EvmExecutor, HardforkConfig};
4+
use std::sync::atomic::AtomicUsize;
5+
use std::sync::{LazyLock, Mutex};
6+
use std::time::Instant;
47

58
pub fn verify(
69
l2_trace: BlockTrace,
710
fork_config: &HardforkConfig,
811
disable_checks: bool,
912
log_error: bool,
1013
) -> bool {
14+
static BLOCK_COUNTER: AtomicUsize = AtomicUsize::new(0);
15+
static LAST_TIME: LazyLock<Mutex<Instant>> = LazyLock::new(|| Mutex::new(Instant::now()));
16+
1117
trace!("{:#?}", l2_trace);
1218
let root_after = l2_trace.storage_trace.root_after.to_word();
13-
info!("Root after in trace: {:x}", root_after);
1419

15-
let now = std::time::Instant::now();
20+
let now = Instant::now();
1621

1722
#[cfg(feature = "profiling")]
1823
let guard = pprof::ProfilerGuardBuilder::default()
@@ -39,16 +44,28 @@ pub fn verify(
3944
info!("Profiling report saved to: {:?}", path);
4045
}
4146

42-
info!("Root after in revm: {:x}", revm_root_after);
4347
let elapsed = now.elapsed();
4448

4549
if root_after != revm_root_after {
50+
error!("Root after in trace: {:x}", root_after);
51+
error!("Root after in revm: {:x}", revm_root_after);
4652
error!("Root mismatch");
4753
if !log_error {
4854
std::process::exit(1);
4955
}
5056
return false;
5157
}
5258
info!("Root matches in: {} ms", elapsed.as_millis());
59+
60+
let block_counter = BLOCK_COUNTER.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
61+
if block_counter > 50 {
62+
let mut last_time = LAST_TIME.lock().unwrap();
63+
let blocks = BLOCK_COUNTER.swap(0, std::sync::atomic::Ordering::SeqCst);
64+
let elapsed = last_time.elapsed().as_secs_f64();
65+
let bps = blocks as f64 / elapsed;
66+
warn!("Verifying avg speed: {:.2} bps", bps);
67+
*last_time = Instant::now();
68+
}
69+
5370
true
5471
}

src/database.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl DatabaseRef for ReadOnlyDB {
8888
}
8989

9090
/// Get block hash by block number.
91-
fn block_hash_ref(&self, _: U256) -> Result<B256, Self::Error> {
91+
fn block_hash_ref(&self, _: u64) -> Result<B256, Self::Error> {
9292
unimplemented!("BLOCKHASH is disabled")
9393
}
9494
}
@@ -108,7 +108,7 @@ impl revm::Database for ReadOnlyDB {
108108
DatabaseRef::storage_ref(self, address, index)
109109
}
110110

111-
fn block_hash(&mut self, _: U256) -> Result<B256, Self::Error> {
111+
fn block_hash(&mut self, _: u64) -> Result<B256, Self::Error> {
112112
unimplemented!("BLOCKHASH is disabled")
113113
}
114114
}

src/executor.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,12 @@ impl EvmExecutor {
9191
env.tx.scroll.rlp_bytes = Some(revm::primitives::Bytes::from(eth_tx.rlp().to_vec()));
9292
trace!("{env:#?}");
9393
{
94-
info!("self.spec_id: {:?}", self.spec_id);
95-
9694
let mut revm = revm::Evm::builder()
9795
.with_spec_id(self.spec_id)
9896
.with_db(&mut self.db)
9997
.with_env(env)
10098
.build();
101-
info!("handler cfg: {:?}", revm.handler.cfg);
99+
trace!("handler cfg: {:?}", revm.handler.cfg);
102100
let result = revm.transact_commit().unwrap(); // TODO: handle error
103101
trace!("{result:#?}");
104102
}

src/hardfork.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use eth_types::{
33
l2_predeployed::l1_gas_price_oracle,
44
};
55
use revm::{
6-
primitives::{Account, AccountStatus, Address, Bytecode, Bytes, SpecId, StorageSlot, U256},
6+
primitives::{Account, AccountStatus, Address, Bytecode, Bytes, EvmStorageSlot, SpecId, U256},
77
Database, DatabaseCommit,
88
};
99
use std::{collections::HashMap, sync::LazyLock};
@@ -13,7 +13,7 @@ static HARDFORK_HEIGHTS: LazyLock<HashMap<u64, HashMap<SpecId, u64>>> = LazyLock
1313
let mut heights = hardfork_heights();
1414
heights.sort_by_key(|a| a.1);
1515
let heights = heights
16-
.group_by(|a, b| a.1 == b.1)
16+
.chunk_by(|a, b| a.1 == b.1)
1717
.map(|slice| {
1818
let chain_id = slice[0].1;
1919
(
@@ -106,21 +106,23 @@ impl HardforkConfig {
106106
storage: HashMap::from([
107107
(
108108
U256::from_limbs(l1_gas_price_oracle::IS_CURIE_SLOT.0),
109-
StorageSlot::new(U256::from(1)),
109+
EvmStorageSlot::new(U256::from(1)),
110110
),
111111
(
112112
U256::from_limbs(l1_gas_price_oracle::L1_BLOB_BASEFEE_SLOT.0),
113-
StorageSlot::new(U256::from(1)),
113+
EvmStorageSlot::new(U256::from(1)),
114114
),
115115
(
116116
U256::from_limbs(l1_gas_price_oracle::COMMIT_SCALAR_SLOT.0),
117-
StorageSlot::new(U256::from_limbs(
117+
EvmStorageSlot::new(U256::from_limbs(
118118
l1_gas_price_oracle::INITIAL_COMMIT_SCALAR.0,
119119
)),
120120
),
121121
(
122122
U256::from_limbs(l1_gas_price_oracle::BLOB_SCALAR_SLOT.0),
123-
StorageSlot::new(U256::from_limbs(l1_gas_price_oracle::INITIAL_BLOB_SCALAR.0)),
123+
EvmStorageSlot::new(U256::from_limbs(
124+
l1_gas_price_oracle::INITIAL_BLOB_SCALAR.0,
125+
)),
124126
),
125127
]),
126128
status: AccountStatus::Touched,

src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(lazy_cell)]
2-
#![feature(slice_group_by)]
31
#![deny(missing_docs)]
42
#![deny(missing_debug_implementations)]
53
//! Stateless Block Verifier

0 commit comments

Comments
 (0)