diff --git a/evm/Cargo.toml b/evm/Cargo.toml index 1e8f3c56..9d1bfa02 100644 --- a/evm/Cargo.toml +++ b/evm/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" [dependencies] plonky2 = { path = "../plonky2", default-features = false, features = ["rand", "timing"] } plonky2_util = { path = "../util" } +eth-trie-utils = { git = "https://github.com/mir-protocol/eth-trie-utils.git", rev = "3ca443fd18e3f6d209dd96cbad851e05ae058b34" } maybe_rayon = { path = "../maybe_rayon" } anyhow = "1.0.40" env_logger = "0.9.0" @@ -21,6 +22,7 @@ pest_derive = "2.1.0" rand = "0.8.5" rand_chacha = "0.3.1" rlp = "0.5.1" +serde = { version = "1.0.144", features = ["derive"] } keccak-hash = "0.9.0" tiny-keccak = "2.0.2" diff --git a/evm/src/generation/mod.rs b/evm/src/generation/mod.rs index 5b0b3c8f..baf2ec32 100644 --- a/evm/src/generation/mod.rs +++ b/evm/src/generation/mod.rs @@ -1,15 +1,16 @@ +use eth_trie_utils::partial_trie::PartialTrie; use ethereum_types::Address; use plonky2::field::extension::Extendable; use plonky2::field::polynomial::PolynomialValues; use plonky2::field::types::Field; use plonky2::hash::hash_types::RichField; +use serde::{Deserialize, Serialize}; use crate::all_stark::{AllStark, NUM_TABLES}; use crate::config::StarkConfig; use crate::cpu::bootstrap_kernel::generate_bootstrap_kernel; use crate::cpu::columns::NUM_CPU_COLUMNS; use crate::cpu::kernel::global_metadata::GlobalMetadata; -use crate::generation::partial_trie::PartialTrie; use crate::generation::state::GenerationState; use crate::memory::segments::Segment; use crate::memory::NUM_CHANNELS; @@ -17,9 +18,9 @@ use crate::proof::{BlockMetadata, PublicValues, TrieRoots}; use crate::util::trace_rows_to_poly_values; pub(crate) mod memory; -pub mod partial_trie; pub(crate) mod state; +#[derive(Clone, Debug, Deserialize, Serialize)] /// Inputs needed for trace generation. pub struct GenerationInputs { pub signed_txns: Vec>, diff --git a/evm/src/generation/partial_trie.rs b/evm/src/generation/partial_trie.rs deleted file mode 100644 index 5e52e1e0..00000000 --- a/evm/src/generation/partial_trie.rs +++ /dev/null @@ -1,34 +0,0 @@ -use ethereum_types::U256; - -#[derive(Clone, Debug)] -/// A partial trie, or a sub-trie thereof. This mimics the structure of an Ethereum trie, except -/// with an additional `Hash` node type, representing a node whose data is not needed to process -/// our transaction. -pub enum PartialTrie { - /// An empty trie. - Empty, - /// The digest of trie whose data does not need to be stored. - Hash(U256), - /// A branch node, which consists of 16 children and an optional value. - Branch { - children: [Box; 16], - value: Option, - }, - /// An extension node, which consists of a list of nibbles and a single child. - Extension { - nibbles: Nibbles, - child: Box, - }, - /// A leaf node, which consists of a list of nibbles and a value. - Leaf { nibbles: Nibbles, value: Vec }, -} - -#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] -/// A sequence of nibbles. -pub struct Nibbles { - /// The number of nibbles in this sequence. - pub count: usize, - /// A packed encoding of these nibbles. Only the first (least significant) `4 * count` bits are - /// used. The rest are unused and should be zero. - pub packed: U256, -} diff --git a/evm/src/proof.rs b/evm/src/proof.rs index a5bc61a7..81614e67 100644 --- a/evm/src/proof.rs +++ b/evm/src/proof.rs @@ -12,6 +12,7 @@ use plonky2::hash::merkle_tree::MerkleCap; use plonky2::iop::ext_target::ExtensionTarget; use plonky2::iop::target::Target; use plonky2::plonk::config::GenericConfig; +use serde::{Deserialize, Serialize}; use crate::all_stark::NUM_TABLES; use crate::config::StarkConfig; @@ -58,7 +59,7 @@ pub struct TrieRoots { pub receipts_root: U256, } -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone, Default, Deserialize, Serialize)] pub struct BlockMetadata { pub block_beneficiary: Address, pub block_timestamp: U256, diff --git a/evm/tests/transfer_to_new_addr.rs b/evm/tests/transfer_to_new_addr.rs index ecb71076..1cd79194 100644 --- a/evm/tests/transfer_to_new_addr.rs +++ b/evm/tests/transfer_to_new_addr.rs @@ -1,10 +1,10 @@ +use eth_trie_utils::partial_trie::PartialTrie; use hex_literal::hex; use plonky2::field::goldilocks_field::GoldilocksField; use plonky2::plonk::config::PoseidonGoldilocksConfig; use plonky2::util::timing::TimingTree; use plonky2_evm::all_stark::AllStark; use plonky2_evm::config::StarkConfig; -use plonky2_evm::generation::partial_trie::PartialTrie; use plonky2_evm::generation::GenerationInputs; use plonky2_evm::proof::BlockMetadata; use plonky2_evm::prover::prove;