mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-02 22:03:07 +00:00
Removed a type alias
- Was conflicting with the trait `PartialTrie` and also making the types harder to follow.
This commit is contained in:
parent
60ad9e03ba
commit
3c7bc8835c
@ -1,6 +1,8 @@
|
||||
use std::ops::Deref;
|
||||
|
||||
use crate::{Node, PartialTrie};
|
||||
use eth_trie_utils::partial_trie::HashedPartialTrie;
|
||||
|
||||
use crate::Node;
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub(crate) enum PartialTrieType {
|
||||
@ -14,7 +16,7 @@ pub(crate) enum PartialTrieType {
|
||||
impl PartialTrieType {
|
||||
pub(crate) const COUNT: usize = 5;
|
||||
|
||||
pub(crate) fn of(trie: &PartialTrie) -> Self {
|
||||
pub(crate) fn of(trie: &HashedPartialTrie) -> Self {
|
||||
match trie.deref() {
|
||||
Node::Empty => Self::Empty,
|
||||
Node::Hash(_) => Self::Hash,
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use anyhow::Result;
|
||||
use eth_trie_utils::partial_trie::PartialTrie as PartialTrieTrait;
|
||||
use eth_trie_utils::partial_trie::{HashedPartialTrie, PartialTrie};
|
||||
use ethereum_types::{Address, BigEndianHash, H256, U256};
|
||||
use keccak_hash::keccak;
|
||||
use rand::{thread_rng, Rng};
|
||||
@ -12,14 +12,14 @@ use crate::cpu::kernel::interpreter::Interpreter;
|
||||
use crate::cpu::kernel::tests::mpt::nibbles_64;
|
||||
use crate::generation::mpt::{all_mpt_prover_inputs_reversed, AccountRlp};
|
||||
use crate::memory::segments::Segment;
|
||||
use crate::{Node, PartialTrie};
|
||||
use crate::Node;
|
||||
|
||||
// Test account with a given code hash.
|
||||
fn test_account(code: &[u8]) -> AccountRlp {
|
||||
AccountRlp {
|
||||
nonce: U256::from(1111),
|
||||
balance: U256::from(2222),
|
||||
storage_root: PartialTrie::from(Node::Empty).hash(),
|
||||
storage_root: HashedPartialTrie::from(Node::Empty).hash(),
|
||||
code_hash: keccak(code),
|
||||
}
|
||||
}
|
||||
@ -40,7 +40,7 @@ fn prepare_interpreter(
|
||||
let load_all_mpts = KERNEL.global_labels["load_all_mpts"];
|
||||
let mpt_insert_state_trie = KERNEL.global_labels["mpt_insert_state_trie"];
|
||||
let mpt_hash_state_trie = KERNEL.global_labels["mpt_hash_state_trie"];
|
||||
let mut state_trie: PartialTrie = Default::default();
|
||||
let mut state_trie: HashedPartialTrie = Default::default();
|
||||
let trie_inputs = Default::default();
|
||||
|
||||
interpreter.generation_state.registers.program_counter = load_all_mpts;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use anyhow::Result;
|
||||
use eth_trie_utils::partial_trie::PartialTrie as PartialTrieTrait;
|
||||
use eth_trie_utils::partial_trie::{HashedPartialTrie, PartialTrie};
|
||||
use ethereum_types::{Address, BigEndianHash, H256, U256};
|
||||
use keccak_hash::keccak;
|
||||
use rand::{thread_rng, Rng};
|
||||
@ -9,14 +9,14 @@ use crate::cpu::kernel::constants::global_metadata::GlobalMetadata;
|
||||
use crate::cpu::kernel::interpreter::Interpreter;
|
||||
use crate::cpu::kernel::tests::mpt::nibbles_64;
|
||||
use crate::generation::mpt::{all_mpt_prover_inputs_reversed, AccountRlp};
|
||||
use crate::{Node, PartialTrie};
|
||||
use crate::Node;
|
||||
|
||||
// Test account with a given code hash.
|
||||
fn test_account(balance: U256) -> AccountRlp {
|
||||
AccountRlp {
|
||||
nonce: U256::from(1111),
|
||||
balance,
|
||||
storage_root: PartialTrie::from(Node::Empty).hash(),
|
||||
storage_root: HashedPartialTrie::from(Node::Empty).hash(),
|
||||
code_hash: H256::from_uint(&U256::from(8888)),
|
||||
}
|
||||
}
|
||||
@ -31,7 +31,7 @@ fn prepare_interpreter(
|
||||
let load_all_mpts = KERNEL.global_labels["load_all_mpts"];
|
||||
let mpt_insert_state_trie = KERNEL.global_labels["mpt_insert_state_trie"];
|
||||
let mpt_hash_state_trie = KERNEL.global_labels["mpt_hash_state_trie"];
|
||||
let mut state_trie: PartialTrie = Default::default();
|
||||
let mut state_trie: HashedPartialTrie = Default::default();
|
||||
let trie_inputs = Default::default();
|
||||
|
||||
interpreter.generation_state.registers.program_counter = load_all_mpts;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use anyhow::Result;
|
||||
use eth_trie_utils::partial_trie::PartialTrie as PartialTrieTrait;
|
||||
use eth_trie_utils::partial_trie::PartialTrie;
|
||||
use ethereum_types::{BigEndianHash, H256};
|
||||
|
||||
use crate::cpu::kernel::aggregator::KERNEL;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use anyhow::Result;
|
||||
use eth_trie_utils::nibbles::Nibbles;
|
||||
use eth_trie_utils::partial_trie::PartialTrie as PartialTrieTrait;
|
||||
use eth_trie_utils::partial_trie::{HashedPartialTrie, PartialTrie};
|
||||
use ethereum_types::{BigEndianHash, H256};
|
||||
|
||||
use crate::cpu::kernel::aggregator::KERNEL;
|
||||
@ -11,7 +11,7 @@ use crate::cpu::kernel::tests::mpt::{
|
||||
};
|
||||
use crate::generation::mpt::{all_mpt_prover_inputs_reversed, AccountRlp};
|
||||
use crate::generation::TrieInputs;
|
||||
use crate::{Node, PartialTrie};
|
||||
use crate::Node;
|
||||
|
||||
#[test]
|
||||
fn mpt_insert_empty() -> Result<()> {
|
||||
@ -152,11 +152,15 @@ fn mpt_insert_branch_to_leaf_same_key() -> Result<()> {
|
||||
|
||||
/// Note: The account's storage_root is ignored, as we can't insert a new storage_root without the
|
||||
/// accompanying trie data. An empty trie's storage_root is used instead.
|
||||
fn test_state_trie(mut state_trie: PartialTrie, k: Nibbles, mut account: AccountRlp) -> Result<()> {
|
||||
fn test_state_trie(
|
||||
mut state_trie: HashedPartialTrie,
|
||||
k: Nibbles,
|
||||
mut account: AccountRlp,
|
||||
) -> Result<()> {
|
||||
assert_eq!(k.count, 64);
|
||||
|
||||
// Ignore any storage_root; see documentation note.
|
||||
account.storage_root = PartialTrie::from(Node::Empty).hash();
|
||||
account.storage_root = HashedPartialTrie::from(Node::Empty).hash();
|
||||
|
||||
let trie_inputs = TrieInputs {
|
||||
state_trie: state_trie.clone(),
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
use eth_trie_utils::nibbles::Nibbles;
|
||||
use eth_trie_utils::partial_trie::HashedPartialTrie;
|
||||
use ethereum_types::{BigEndianHash, H256, U256};
|
||||
|
||||
use crate::generation::mpt::AccountRlp;
|
||||
use crate::{Node, PartialTrie};
|
||||
use crate::Node;
|
||||
|
||||
mod hash;
|
||||
mod hex_prefix;
|
||||
@ -47,7 +48,7 @@ pub(crate) fn test_account_2_rlp() -> Vec<u8> {
|
||||
}
|
||||
|
||||
/// A `PartialTrie` where an extension node leads to a leaf node containing an account.
|
||||
pub(crate) fn extension_to_leaf(value: Vec<u8>) -> PartialTrie {
|
||||
pub(crate) fn extension_to_leaf(value: Vec<u8>) -> HashedPartialTrie {
|
||||
Node::Extension {
|
||||
nibbles: 0xABC_u64.into(),
|
||||
child: Node::Leaf {
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use eth_trie_utils::partial_trie::HashedPartialTrie;
|
||||
use ethereum_types::{Address, BigEndianHash, H256, U256};
|
||||
use plonky2::field::extension::Extendable;
|
||||
use plonky2::field::polynomial::PolynomialValues;
|
||||
@ -23,7 +24,6 @@ use crate::memory::segments::Segment;
|
||||
use crate::proof::{BlockMetadata, PublicValues, TrieRoots};
|
||||
use crate::witness::memory::{MemoryAddress, MemoryChannel};
|
||||
use crate::witness::transition::transition;
|
||||
use crate::PartialTrie;
|
||||
|
||||
pub mod mpt;
|
||||
pub mod outputs;
|
||||
@ -59,19 +59,19 @@ pub struct GenerationInputs {
|
||||
pub struct TrieInputs {
|
||||
/// A partial version of the state trie prior to these transactions. It should include all nodes
|
||||
/// that will be accessed by these transactions.
|
||||
pub state_trie: PartialTrie,
|
||||
pub state_trie: HashedPartialTrie,
|
||||
|
||||
/// A partial version of the transaction trie prior to these transactions. It should include all
|
||||
/// nodes that will be accessed by these transactions.
|
||||
pub transactions_trie: PartialTrie,
|
||||
pub transactions_trie: HashedPartialTrie,
|
||||
|
||||
/// A partial version of the receipt trie prior to these transactions. It should include all nodes
|
||||
/// that will be accessed by these transactions.
|
||||
pub receipts_trie: PartialTrie,
|
||||
pub receipts_trie: HashedPartialTrie,
|
||||
|
||||
/// A partial version of each storage trie prior to these transactions. It should include all
|
||||
/// storage tries, and nodes therein, that will be accessed by these transactions.
|
||||
pub storage_tries: Vec<(Address, PartialTrie)>,
|
||||
pub storage_tries: Vec<(Address, HashedPartialTrie)>,
|
||||
}
|
||||
|
||||
fn apply_metadata_memops<F: RichField + Extendable<D>, const D: usize>(
|
||||
|
||||
@ -2,14 +2,14 @@ use std::collections::HashMap;
|
||||
use std::ops::Deref;
|
||||
|
||||
use eth_trie_utils::nibbles::Nibbles;
|
||||
use eth_trie_utils::partial_trie::PartialTrie as PartialTrieTrait;
|
||||
use eth_trie_utils::partial_trie::{HashedPartialTrie, PartialTrie};
|
||||
use ethereum_types::{BigEndianHash, H256, U256};
|
||||
use keccak_hash::keccak;
|
||||
use rlp_derive::{RlpDecodable, RlpEncodable};
|
||||
|
||||
use crate::cpu::kernel::constants::trie_type::PartialTrieType;
|
||||
use crate::generation::TrieInputs;
|
||||
use crate::{Node, PartialTrie};
|
||||
use crate::Node;
|
||||
|
||||
#[derive(RlpEncodable, RlpDecodable, Debug)]
|
||||
pub struct AccountRlp {
|
||||
@ -24,7 +24,7 @@ impl Default for AccountRlp {
|
||||
Self {
|
||||
nonce: U256::zero(),
|
||||
balance: U256::zero(),
|
||||
storage_root: PartialTrie::from(Node::Empty).hash(),
|
||||
storage_root: HashedPartialTrie::from(Node::Empty).hash(),
|
||||
code_hash: keccak([]),
|
||||
}
|
||||
}
|
||||
@ -73,7 +73,7 @@ pub(crate) fn all_mpt_prover_inputs(trie_inputs: &TrieInputs) -> Vec<U256> {
|
||||
/// is serialized as `(TYPE_LEAF, key, value)`, where key is a `(nibbles, depth)` pair and `value`
|
||||
/// is a variable-length structure which depends on which trie we're dealing with.
|
||||
pub(crate) fn mpt_prover_inputs<F>(
|
||||
trie: &PartialTrie,
|
||||
trie: &HashedPartialTrie,
|
||||
prover_inputs: &mut Vec<U256>,
|
||||
parse_value: &F,
|
||||
) where
|
||||
@ -113,10 +113,10 @@ pub(crate) fn mpt_prover_inputs<F>(
|
||||
/// Like `mpt_prover_inputs`, but for the state trie, which is a bit unique since each value
|
||||
/// leads to a storage trie which we recursively traverse.
|
||||
pub(crate) fn mpt_prover_inputs_state_trie(
|
||||
trie: &PartialTrie,
|
||||
trie: &HashedPartialTrie,
|
||||
key: Nibbles,
|
||||
prover_inputs: &mut Vec<U256>,
|
||||
storage_tries_by_state_key: &HashMap<Nibbles, &PartialTrie>,
|
||||
storage_tries_by_state_key: &HashMap<Nibbles, &HashedPartialTrie>,
|
||||
) {
|
||||
prover_inputs.push((PartialTrieType::of(trie) as u32).into());
|
||||
match trie.deref() {
|
||||
@ -159,9 +159,9 @@ pub(crate) fn mpt_prover_inputs_state_trie(
|
||||
code_hash,
|
||||
} = account;
|
||||
|
||||
let storage_hash_only = PartialTrie::new(Node::Hash(storage_root));
|
||||
let storage_hash_only = HashedPartialTrie::new(Node::Hash(storage_root));
|
||||
let merged_key = key.merge_nibbles(nibbles);
|
||||
let storage_trie: &PartialTrie = storage_tries_by_state_key
|
||||
let storage_trie: &HashedPartialTrie = storage_tries_by_state_key
|
||||
.get(&merged_key)
|
||||
.copied()
|
||||
.unwrap_or(&storage_hash_only);
|
||||
|
||||
@ -43,5 +43,4 @@ use jemallocator::Jemalloc;
|
||||
#[global_allocator]
|
||||
static GLOBAL: Jemalloc = Jemalloc;
|
||||
|
||||
pub type PartialTrie = HashedPartialTrie;
|
||||
pub type Node = eth_trie_utils::partial_trie::Node<PartialTrie>;
|
||||
pub type Node = eth_trie_utils::partial_trie::Node<HashedPartialTrie>;
|
||||
|
||||
@ -3,7 +3,7 @@ use std::time::Duration;
|
||||
|
||||
use env_logger::{try_init_from_env, Env, DEFAULT_FILTER_ENV};
|
||||
use eth_trie_utils::nibbles::Nibbles;
|
||||
use eth_trie_utils::partial_trie::PartialTrie as PartialTrieTrait;
|
||||
use eth_trie_utils::partial_trie::{HashedPartialTrie, PartialTrie};
|
||||
use ethereum_types::Address;
|
||||
use hex_literal::hex;
|
||||
use keccak_hash::keccak;
|
||||
@ -17,7 +17,7 @@ use plonky2_evm::generation::{GenerationInputs, TrieInputs};
|
||||
use plonky2_evm::proof::BlockMetadata;
|
||||
use plonky2_evm::prover::prove;
|
||||
use plonky2_evm::verifier::verify_proof;
|
||||
use plonky2_evm::{Node, PartialTrie};
|
||||
use plonky2_evm::Node;
|
||||
|
||||
type F = GoldilocksField;
|
||||
const D: usize = 2;
|
||||
@ -60,7 +60,7 @@ fn add11_yml() -> anyhow::Result<()> {
|
||||
..AccountRlp::default()
|
||||
};
|
||||
|
||||
let mut state_trie_before = PartialTrie::from(Node::Empty);
|
||||
let mut state_trie_before = HashedPartialTrie::from(Node::Empty);
|
||||
state_trie_before.insert(
|
||||
beneficiary_nibbles,
|
||||
rlp::encode(&beneficiary_account_before).to_vec(),
|
||||
@ -112,7 +112,7 @@ fn add11_yml() -> anyhow::Result<()> {
|
||||
balance: 0xde0b6b3a76586a0u64.into(),
|
||||
code_hash,
|
||||
// Storage map: { 0 => 2 }
|
||||
storage_root: PartialTrie::from(Node::Leaf {
|
||||
storage_root: HashedPartialTrie::from(Node::Leaf {
|
||||
nibbles: Nibbles::from_h256_be(keccak([0u8; 32])),
|
||||
value: vec![2],
|
||||
})
|
||||
@ -120,7 +120,7 @@ fn add11_yml() -> anyhow::Result<()> {
|
||||
..AccountRlp::default()
|
||||
};
|
||||
|
||||
let mut expected_state_trie_after = PartialTrie::from(Node::Empty);
|
||||
let mut expected_state_trie_after = HashedPartialTrie::from(Node::Empty);
|
||||
expected_state_trie_after.insert(
|
||||
beneficiary_nibbles,
|
||||
rlp::encode(&beneficiary_account_after).to_vec(),
|
||||
|
||||
@ -3,7 +3,7 @@ use std::time::Duration;
|
||||
|
||||
use env_logger::{try_init_from_env, Env, DEFAULT_FILTER_ENV};
|
||||
use eth_trie_utils::nibbles::Nibbles;
|
||||
use eth_trie_utils::partial_trie::PartialTrie as PartialTrieTrait;
|
||||
use eth_trie_utils::partial_trie::{HashedPartialTrie, PartialTrie};
|
||||
use ethereum_types::{Address, U256};
|
||||
use hex_literal::hex;
|
||||
use keccak_hash::keccak;
|
||||
@ -18,7 +18,7 @@ use plonky2_evm::generation::{GenerationInputs, TrieInputs};
|
||||
use plonky2_evm::proof::BlockMetadata;
|
||||
use plonky2_evm::prover::prove;
|
||||
use plonky2_evm::verifier::verify_proof;
|
||||
use plonky2_evm::{Node, PartialTrie};
|
||||
use plonky2_evm::Node;
|
||||
|
||||
type F = GoldilocksField;
|
||||
const D: usize = 2;
|
||||
@ -113,7 +113,7 @@ fn test_basic_smart_contract() -> anyhow::Result<()> {
|
||||
let proof = prove::<F, C, D>(&all_stark, &config, inputs, &mut timing)?;
|
||||
timing.filter(Duration::from_millis(100)).print();
|
||||
|
||||
let expected_state_trie_after: PartialTrie = {
|
||||
let expected_state_trie_after: HashedPartialTrie = {
|
||||
let txdata_gas = 2 * 16;
|
||||
let gas_used = 21_000 + code_gas + txdata_gas;
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ use std::collections::HashMap;
|
||||
use std::time::Duration;
|
||||
|
||||
use env_logger::{try_init_from_env, Env, DEFAULT_FILTER_ENV};
|
||||
use eth_trie_utils::partial_trie::PartialTrie as PartialTrieTrait;
|
||||
use eth_trie_utils::partial_trie::{HashedPartialTrie, PartialTrie};
|
||||
use keccak_hash::keccak;
|
||||
use plonky2::field::goldilocks_field::GoldilocksField;
|
||||
use plonky2::plonk::config::PoseidonGoldilocksConfig;
|
||||
@ -14,7 +14,7 @@ use plonky2_evm::generation::{GenerationInputs, TrieInputs};
|
||||
use plonky2_evm::proof::BlockMetadata;
|
||||
use plonky2_evm::prover::prove;
|
||||
use plonky2_evm::verifier::verify_proof;
|
||||
use plonky2_evm::{Node, PartialTrie};
|
||||
use plonky2_evm::Node;
|
||||
|
||||
type F = GoldilocksField;
|
||||
const D: usize = 2;
|
||||
@ -31,9 +31,9 @@ fn test_empty_txn_list() -> anyhow::Result<()> {
|
||||
|
||||
let block_metadata = BlockMetadata::default();
|
||||
|
||||
let state_trie = PartialTrie::from(Node::Empty);
|
||||
let transactions_trie = PartialTrie::from(Node::Empty);
|
||||
let receipts_trie = PartialTrie::from(Node::Empty);
|
||||
let state_trie = HashedPartialTrie::from(Node::Empty);
|
||||
let transactions_trie = HashedPartialTrie::from(Node::Empty);
|
||||
let receipts_trie = HashedPartialTrie::from(Node::Empty);
|
||||
let storage_tries = vec![];
|
||||
|
||||
let state_trie_root = state_trie.hash();
|
||||
|
||||
@ -3,7 +3,7 @@ use std::time::Duration;
|
||||
|
||||
use env_logger::{try_init_from_env, Env, DEFAULT_FILTER_ENV};
|
||||
use eth_trie_utils::nibbles::Nibbles;
|
||||
use eth_trie_utils::partial_trie::PartialTrie as PartialTrieTrait;
|
||||
use eth_trie_utils::partial_trie::{HashedPartialTrie, PartialTrie};
|
||||
use ethereum_types::{Address, U256};
|
||||
use hex_literal::hex;
|
||||
use keccak_hash::keccak;
|
||||
@ -17,7 +17,7 @@ use plonky2_evm::generation::{GenerationInputs, TrieInputs};
|
||||
use plonky2_evm::proof::BlockMetadata;
|
||||
use plonky2_evm::prover::prove;
|
||||
use plonky2_evm::verifier::verify_proof;
|
||||
use plonky2_evm::{Node, PartialTrie};
|
||||
use plonky2_evm::Node;
|
||||
|
||||
type F = GoldilocksField;
|
||||
const D: usize = 2;
|
||||
@ -47,7 +47,7 @@ fn test_simple_transfer() -> anyhow::Result<()> {
|
||||
let sender_account_before = AccountRlp {
|
||||
nonce: 5.into(),
|
||||
balance: eth_to_wei(100_000.into()),
|
||||
storage_root: PartialTrie::from(Node::Empty).hash(),
|
||||
storage_root: HashedPartialTrie::from(Node::Empty).hash(),
|
||||
code_hash: keccak([]),
|
||||
};
|
||||
let to_account_before = AccountRlp::default();
|
||||
@ -59,8 +59,8 @@ fn test_simple_transfer() -> anyhow::Result<()> {
|
||||
.into();
|
||||
let tries_before = TrieInputs {
|
||||
state_trie: state_trie_before,
|
||||
transactions_trie: PartialTrie::from(Node::Empty),
|
||||
receipts_trie: PartialTrie::from(Node::Empty),
|
||||
transactions_trie: HashedPartialTrie::from(Node::Empty),
|
||||
receipts_trie: HashedPartialTrie::from(Node::Empty),
|
||||
storage_tries: vec![],
|
||||
};
|
||||
|
||||
@ -88,7 +88,7 @@ fn test_simple_transfer() -> anyhow::Result<()> {
|
||||
let proof = prove::<F, C, D>(&all_stark, &config, inputs, &mut timing)?;
|
||||
timing.filter(Duration::from_millis(100)).print();
|
||||
|
||||
let expected_state_trie_after: PartialTrie = {
|
||||
let expected_state_trie_after: HashedPartialTrie = {
|
||||
let txdata_gas = 2 * 16;
|
||||
let gas_used = 21_000 + txdata_gas;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user