Skip to content

Commit

Permalink
feat: Euclid V2 (#87)
Browse files Browse the repository at this point in the history
* feat: add EIP-7702 tx support (#85)

* upgrade

* upgrade

* Update Cargo.toml

* change branches

* remove poseidon field

* fix scroll types

* trailing lf

* feat: dump utils (#83)

* provide utils lib

* clippy

* unify imports

* fix

* style fix

* add EIP-7702 tx support

* upgrade reth

---------

Co-authored-by: Zhang Zhuo <[email protected]>

* feat: msg queue hash (#84)

* upgrade

* upgrade

* Update Cargo.toml

* change branches

* remove poseidon field

* fix scroll types

* trailing lf

* feat: dump utils (#83)

* provide utils lib

* clippy

* unify imports

* fix

* style fix

* impl msg queue hash

* remove legacy test

* move chunk into primitives and impl EuclidV2

* set prev_msg_queue_hash

* use is_l1_message

* feat: num l1 msgs in scroll block

* fix: usize instead of u64 for num txs

* chore: clippy fix remove unused import

* apply suggestion

---------

Co-authored-by: Zhang Zhuo <[email protected]>
Co-authored-by: Rohit Narurkar <[email protected]>

* fix Eip7702 signature

* chore: update reth dep

* fix bytecode construct

* upgrade to fix

* add euclid v2 test cases

* fix cli

* remove unused

* impl is_euclid_v2 in chunk

* clippy

* fix ChunkInfo

* fix chunk mode

* refactor

* refactor

---------

Co-authored-by: Zhang Zhuo <[email protected]>
Co-authored-by: Rohit Narurkar <[email protected]>
  • Loading branch information
3 people authored Mar 4, 2025
1 parent 43938a8 commit 34cd296
Show file tree
Hide file tree
Showing 25 changed files with 1,706 additions and 252 deletions.
104 changes: 50 additions & 54 deletions Cargo.lock

Large diffs are not rendered by default.

61 changes: 24 additions & 37 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,38 +38,25 @@ alloy-trie = { version = "0.7", default-features = false }
# https://github.com/alloy-rs/core
alloy-primitives = { version = "0.8", default-features = false, features = ["map-hashbrown", "map-fxhash", "rkyv"] }

reth-chainspec = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
reth-evm = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
reth-evm-ethereum = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
reth-ethereum-forks = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
reth-execution-types = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
reth-primitives = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
reth-primitives-traits = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
reth-storage-errors = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
reth-trie = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
reth-trie-sparse = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }

reth-scroll-chainspec = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
reth-scroll-evm = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
reth-scroll-forks = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
reth-scroll-primitives = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }

scroll-alloy-consensus = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
scroll-alloy-primitives = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
scroll-alloy-rpc-types = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }
scroll-alloy-network = { git = "https://github.com/scroll-tech/reth", branch = "scroll", default-features = false }

#reth-chainspec = { path = "../reth/crates/chainspec", default-features = false }
#reth-evm = { path = "../reth/crates/evm/", default-features = false }
#reth-evm-ethereum = { path = "../reth/crates/ethereum/evm", default-features = false }
#reth-execution-types = { path = "../reth/crates/evm/execution-types", default-features = false }
#reth-primitives = { path = "../reth/crates/primitives", default-features = false }
#reth-scroll-chainspec = { path = "../reth/crates/scroll/chainspec", default-features = false }
#reth-scroll-evm = { path = "../reth/crates/scroll/evm", default-features = false }
#reth-scroll-primitives = { path = "../reth/crates/scroll/primitives", default-features = false }
#reth-storage-errors = { path = "../reth/crates/storage/errors", default-features = false }
#reth-trie = { path = "../reth/crates/trie/trie", default-features = false }
#reth-trie-sparse = { path = "../reth/crates/trie/sparse", default-features = false }
reth-chainspec = { git = "https://github.com/scroll-tech/reth", branch = "feat/euclid-v2", default-features = false }
reth-evm = { git = "https://github.com/scroll-tech/reth", branch = "feat/euclid-v2", default-features = false }
reth-evm-ethereum = { git = "https://github.com/scroll-tech/reth", branch = "feat/euclid-v2", default-features = false }
reth-ethereum-forks = { git = "https://github.com/scroll-tech/reth", branch = "feat/euclid-v2", default-features = false }
reth-execution-types = { git = "https://github.com/scroll-tech/reth", branch = "feat/euclid-v2", default-features = false }
reth-primitives = { git = "https://github.com/scroll-tech/reth", branch = "feat/euclid-v2", default-features = false }
reth-primitives-traits = { git = "https://github.com/scroll-tech/reth", branch = "feat/euclid-v2", default-features = false }
reth-storage-errors = { git = "https://github.com/scroll-tech/reth", branch = "feat/euclid-v2", default-features = false }
reth-trie = { git = "https://github.com/scroll-tech/reth", branch = "feat/euclid-v2", default-features = false }
reth-trie-sparse = { git = "https://github.com/scroll-tech/reth", branch = "feat/euclid-v2", default-features = false }

reth-scroll-chainspec = { git = "https://github.com/scroll-tech/reth", branch = "feat/euclid-v2", default-features = false }
reth-scroll-evm = { git = "https://github.com/scroll-tech/reth", branch = "feat/euclid-v2", default-features = false }
reth-scroll-forks = { git = "https://github.com/scroll-tech/reth", branch = "feat/euclid-v2", default-features = false }
reth-scroll-primitives = { git = "https://github.com/scroll-tech/reth", branch = "feat/euclid-v2", default-features = false }

scroll-alloy-consensus = { git = "https://github.com/scroll-tech/reth", branch = "feat/euclid-v2", default-features = false }
scroll-alloy-rpc-types = { git = "https://github.com/scroll-tech/reth", branch = "feat/euclid-v2", default-features = false }
scroll-alloy-network = { git = "https://github.com/scroll-tech/reth", branch = "feat/euclid-v2", default-features = false }

async-trait = "0.1"
auto_impl = "1.2"
Expand Down Expand Up @@ -120,7 +107,7 @@ sbv-utils = { path = "crates/utils" }

[workspace.dependencies.revm]
git = "https://github.com/scroll-tech/revm"
branch = "scroll-evm-executor/v55"
branch = "scroll-evm-executor/feat/v55/euclid-v2"
default-features = false
features = ["std"]

Expand All @@ -134,10 +121,10 @@ ruint = { git = "https://github.com/scroll-tech/uint.git", branch = "v1.12.3" }

alloy-primitives = { git = "https://github.com/scroll-tech/alloy-core", branch = "v0.8.18" }

revm = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v55" }
revm-interpreter = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v55" }
revm-precompile = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v55" }
revm-primitives = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v55" }
revm = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/feat/v55/euclid-v2" }
revm-interpreter = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/feat/v55/euclid-v2" }
revm-precompile = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/feat/v55/euclid-v2" }
revm-primitives = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/feat/v55/euclid-v2" }

# for local development
# [patch."https://github.com/scroll-tech/revm"]
Expand Down
1 change: 0 additions & 1 deletion crates/bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ workspace = true
[dependencies]
anyhow.workspace = true
clap = { workspace = true, features = ["derive"] }
futures.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
serde_path_to_error.workspace = true
Expand Down
43 changes: 28 additions & 15 deletions crates/bin/src/commands/run_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ pub struct RunFileCommand {
#[cfg(feature = "scroll")]
#[arg(short, long)]
chunk_mode: bool,
#[cfg(feature = "scroll")]
#[arg(long)]
prev_msg_queue_hash: Option<sbv::primitives::B256>,
}

impl RunFileCommand {
Expand Down Expand Up @@ -42,13 +45,13 @@ impl RunFileCommand {
fn run_chunk(self) -> anyhow::Result<()> {
use anyhow::bail;
use sbv::{
core::{ChunkInfo, EvmDatabase, EvmExecutor},
core::{EvmDatabase, EvmExecutor},
kv::{nohash::NoHashMap, null::NullProvider},
primitives::{
BlockWitness as _,
chainspec::{Chain, get_chain_spec},
ext::{BlockWitnessChunkExt, BlockWitnessExt, TxBytesHashExt},
types::BlockWitness,
chainspec::{Chain, get_chain_spec_or_build},
ext::{BlockWitnessChunkExt, BlockWitnessExt},
types::{BlockWitness, ChunkInfoBuilder},
},
trie::BlockWitnessTrieExt,
};
Expand All @@ -71,18 +74,32 @@ impl RunFileCommand {
.iter()
.map(|w| w.build_reth_block())
.collect::<Result<Vec<_>, _>>()?;
let chunk_info =
ChunkInfo::from_blocks(witnesses[0].chain_id, witnesses[0].pre_state_root, &blocks);

let chain_spec = get_chain_spec(Chain::from_id(chunk_info.chain_id())).unwrap();
let chain_spec = get_chain_spec_or_build(Chain::from_id(witnesses.chain_id()), |_spec| {
#[cfg(feature = "scroll")]
{
use sbv::primitives::hardforks::{ForkCondition, ScrollHardfork};
_spec
.inner
.hardforks
.insert(ScrollHardfork::EuclidV2, ForkCondition::Timestamp(0));
}
});

let mut chunk_info_builder =
ChunkInfoBuilder::new(&chain_spec, witnesses.prev_state_root(), &blocks);
if let Some(prev_msg_queue_hash) = self.prev_msg_queue_hash {
chunk_info_builder.set_prev_msg_queue_hash(prev_msg_queue_hash);
}

let mut code_db = NoHashMap::default();
witnesses.import_codes(&mut code_db);
let mut nodes_provider = NoHashMap::default();
witnesses.import_nodes(&mut nodes_provider)?;

let mut db = EvmDatabase::new_from_root(
&code_db,
chunk_info.prev_state_root(),
chunk_info_builder.prev_state_root(),
&nodes_provider,
&NullProvider,
)?;
Expand All @@ -91,16 +108,12 @@ impl RunFileCommand {
db.update(&nodes_provider, output.state.state.iter())?;
}
let post_state_root = db.commit_changes();
if post_state_root != chunk_info.post_state_root() {
if post_state_root != chunk_info_builder.post_state_root() {
bail!("post state root mismatch");
}

let withdraw_root = db.withdraw_root()?;
let tx_bytes_hash = blocks
.iter()
.flat_map(|b| b.body().transactions.iter())
.tx_bytes_hash();
let _public_input_hash = chunk_info.public_input_hash(&withdraw_root, &tx_bytes_hash);
let chunk_info = chunk_info_builder.build(db.withdraw_root()?);
let _public_input_hash = chunk_info.pi_hash();
dev_info!("[chunk mode] public input hash: {_public_input_hash:?}");

Ok(())
Expand Down
13 changes: 11 additions & 2 deletions crates/bin/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use sbv::{
kv::nohash::NoHashMap,
primitives::{
BlockWitness,
chainspec::{Chain, get_chain_spec},
chainspec::{Chain, get_chain_spec_or_build},
ext::BlockWitnessExt,
},
trie::BlockWitnessTrieExt,
Expand All @@ -30,7 +30,16 @@ fn verify_inner<T: BlockWitness + BlockWitnessTrieExt + BlockWitnessExt>(
.build()
.unwrap();

let chain_spec = get_chain_spec(Chain::from_id(witness.chain_id())).unwrap();
let chain_spec = get_chain_spec_or_build(Chain::from_id(witness.chain_id()), |_spec| {
#[cfg(feature = "scroll")]
{
use sbv::primitives::hardforks::{ForkCondition, ScrollHardfork};
_spec
.inner
.hardforks
.insert(ScrollHardfork::EuclidV2, ForkCondition::Timestamp(0));
}
});

let mut code_db = NoHashMap::default();
witness.import_codes(&mut code_db);
Expand Down
6 changes: 1 addition & 5 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ reth-evm-ethereum.workspace = true
reth-execution-types.workspace = true
reth-scroll-evm = { workspace = true, optional = true }
reth-storage-errors.workspace = true
serde.workspace = true
serde_json.workspace = true

thiserror.workspace = true
tiny-keccak.workspace = true

sbv-primitives.workspace = true
sbv-helpers.workspace = true
Expand All @@ -30,8 +28,6 @@ sbv-trie.workspace = true

[dev-dependencies]
ctor.workspace = true
serde.workspace = true
serde_json.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true

Expand Down
119 changes: 0 additions & 119 deletions crates/core/src/chunk.rs

This file was deleted.

4 changes: 3 additions & 1 deletion crates/core/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ impl<
nodes_provider: NodesProvider,
block_hashes: BlockHashProvider,
) -> Result<Self> {
dev_trace!("open trie from root {:?}", state_root_before);

let state = cycle_track!(
PartialStateTrie::open(&nodes_provider, state_root_before),
"PartialStateTrie::open"
Expand Down Expand Up @@ -110,7 +112,7 @@ impl<
.code_db
.get(&hash)
.cloned()
.map(Bytecode::new_legacy)
.map(Bytecode::new_raw)
.map(to_analysed);
code_cache.insert(hash, code.clone());
code
Expand Down
5 changes: 0 additions & 5 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
extern crate sbv_helpers;
extern crate core;

#[cfg(feature = "scroll")]
mod chunk;
#[cfg(feature = "scroll")]
pub use chunk::ChunkInfo;

mod database;
pub use database::{DatabaseError, DatabaseRef, EvmDatabase};

Expand Down
Loading

0 comments on commit 34cd296

Please sign in to comment.