Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ jobs:

- name: Check simple-sparse-state (lib only)
run: cargo check --locked -p simple-sparse-state --lib

- name: Run integration tests
run: cargo test --locked -p integration-tests
23 changes: 12 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["crates/mpt", "crates/simple-sparse-state", "crates/simple-trie", "crates/sparsestate"]
members = ["crates/mpt", "crates/simple-sparse-state", "crates/simple-trie", "crates/sparsestate", "tests"]
resolver = "2"

[workspace.package]
Expand Down
6 changes: 0 additions & 6 deletions crates/simple-sparse-state/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@ simple-trie = { path = "../simple-trie" }

[dev-dependencies]
alloy-consensus = { version = "1.0.42", default-features = false }
guest-libs.workspace = true
reth-evm-ethereum.workspace = true
reth-chainspec.workspace = true
reth-primitives-traits.workspace = true
anyhow = "1.0"
sparsestate = { path = "../sparsestate" }

[lints]
workspace = true


60 changes: 0 additions & 60 deletions crates/simple-sparse-state/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,19 +201,9 @@ impl StatelessTrie for SimpleSparseState {
#[cfg(test)]
mod tests {
use super::*;
use alloy_consensus::private::serde_json;
use alloy_consensus::Header;
use alloy_primitives::hex;
use anyhow;
use guest_libs::senders::recover_signers;
use reth_chainspec::ChainSpec;
use reth_evm_ethereum::EthEvmConfig;
use reth_primitives_traits::account::Account;
use reth_stateless::{
stateless_validation_with_trie, validation::stateless_validation, Genesis, StatelessInput,
};
use sparsestate::SparseState;
use std::sync::Arc;

#[test]
fn test_sparse_state() {
Expand Down Expand Up @@ -350,54 +340,4 @@ mod tests {
trie.0.calculate_state_root(hashed_post_state).unwrap()
);
}

#[test]
fn stateless_validation_test() {
let input = serde_json::from_reader::<_, StatelessInput>(
std::fs::File::open(String::from("./../../test_data/rpc_block_23439901.json")).unwrap(),
)
.unwrap();

let genesis = Genesis {
config: input.chain_config.clone(),
..Default::default()
};
let chain_spec: Arc<ChainSpec> = Arc::new(genesis.into());
let evm_config = EthEvmConfig::new(chain_spec.clone());

let public_keys = recover_signers(input.block.body.transactions.iter())
.map_err(|err| anyhow::anyhow!("recovering signers: {err}"))
.unwrap();

let r_reth = stateless_validation(
input.block.clone(),
public_keys.clone(),
input.witness.clone(),
chain_spec.clone(),
evm_config.clone(),
)
.expect("Stateless validation error");

let r_zeth = stateless_validation_with_trie::<SparseState, ChainSpec, EthEvmConfig>(
input.block.clone(),
public_keys.clone(),
input.witness.clone(),
chain_spec.clone(),
evm_config.clone(),
)
.expect("Stateless validation error");

let r_simple =
stateless_validation_with_trie::<SimpleSparseState, ChainSpec, EthEvmConfig>(
input.block.clone(),
public_keys.clone(),
input.witness.clone(),
chain_spec.clone(),
evm_config.clone(),
)
.expect("Stateless validation error");

assert_eq!(r_reth, r_zeth);
assert_eq!(r_zeth, r_simple);
}
}
6 changes: 3 additions & 3 deletions crates/simple-trie/src/trie/hash.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Hashing element implementation for different node's types of MPT.
use super::nodes::{BranchNode, DigestNode, LeafNode, TrieNode};
use crate::trie::rlp::encode_list_header;
use crate::trie::TrieNode::{Branch, Digest, Leaf};
use crate::trie::rlp::encode_list_header;
use alloy_primitives::private::alloy_rlp::Encodable;
use alloy_primitives::{keccak256, B256};
use alloy_primitives::{B256, keccak256};
use alloy_trie::nodes::encode_path_leaf;

impl TrieNode {
Expand Down Expand Up @@ -170,7 +170,7 @@ fn shorten_encoding(b: Vec<u8>) -> Vec<u8> {
mod tests {
use crate::trie::Trie;
use alloy_primitives::private::alloy_rlp::Encodable;
use alloy_primitives::{hex, keccak256, Bytes};
use alloy_primitives::{Bytes, hex, keccak256};
use alloy_trie::{HashBuilder, Nibbles};
use std::vec;

Expand Down
2 changes: 1 addition & 1 deletion crates/simple-trie/src/trie/reveal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::trie::B256Map;
use crate::trie::TrieNode;
use crate::trie::TrieNode::{Branch, Digest, Leaf};
use alloy_primitives::{Bytes, B256};
use alloy_primitives::{B256, Bytes};

impl TrieNode {
fn set_cache(&mut self, hash: B256) {
Expand Down
6 changes: 3 additions & 3 deletions crates/simple-trie/src/trie/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use super::nodes::{DigestNode, LeafNode};
use crate::trie::Trie;
use crate::trie::TrieNode::{Digest, Leaf};
use alloy_primitives::map::{FbBuildHasher, HashMap};
use alloy_primitives::{Bytes, B256};
use alloy_trie::{Nibbles, EMPTY_ROOT_HASH};
use alloy_primitives::{B256, Bytes};
use alloy_trie::{EMPTY_ROOT_HASH, Nibbles};

/// Added only to make an IDE happy. It is defined in alloy_primitives::map
pub type B256Map<V> = HashMap<B256, V, FbBuildHasher<32>>;
Expand Down Expand Up @@ -93,7 +93,7 @@ impl Trie {
#[cfg(test)]
mod tests {
use super::*;
use alloy_primitives::{hex, keccak256, Bytes};
use alloy_primitives::{Bytes, hex, keccak256};
use alloy_trie::{HashBuilder, Nibbles};
use std::collections::BTreeMap;

Expand Down
17 changes: 17 additions & 0 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "integration-tests"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true

[dev-dependencies]
simple-sparse-state = { path = "../crates/simple-sparse-state" }
guest-libs.workspace = true
reth-evm-ethereum.workspace = true
reth-chainspec.workspace = true
reth-stateless.workspace = true
serde_json = "1.0"

[lints]
workspace = true
59 changes: 59 additions & 0 deletions tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#![allow(missing_docs)]

#[cfg(test)]
mod tests {
use guest_libs::senders::recover_signers;
use reth_chainspec::ChainSpec;
use reth_evm_ethereum::EthEvmConfig;
use reth_stateless::{
stateless_validation_with_trie, validation::stateless_validation, Genesis, StatelessInput,
};
use simple_sparse_state::SimpleSparseState;
use std::{fs::File, path::PathBuf, sync::Arc};

#[test]
fn stateless_validation_test() {
let mut input_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
input_path.push("../test_data/rpc_block_23439901.json");
if !input_path.exists() {
eprintln!("skipping stateless_validation_test: missing fixture {input_path:?}");
return;
}

let input = serde_json::from_reader::<_, StatelessInput>(
File::open(input_path).expect("failed to open test input"),
)
.expect("failed to parse stateless input");

let genesis = Genesis {
config: input.chain_config.clone(),
..Default::default()
};
let chain_spec: Arc<ChainSpec> = Arc::new(genesis.into());
let evm_config = EthEvmConfig::new(chain_spec.clone());

let public_keys =
recover_signers(input.block.body.transactions.iter()).expect("recovering signers");

let reth_result = stateless_validation(
input.block.clone(),
public_keys.clone(),
input.witness.clone(),
chain_spec.clone(),
evm_config.clone(),
)
.expect("reth stateless validation error");

let simple_result =
stateless_validation_with_trie::<SimpleSparseState, ChainSpec, EthEvmConfig>(
input.block,
public_keys,
input.witness,
chain_spec,
evm_config,
)
.expect("simple sparse stateless validation error");

assert_eq!(reth_result, simple_result);
}
}