mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-07 16:23:12 +00:00
Merge pull request #740 from mir-protocol/h256_trie_roots
Trie roots now use `H256` instead of `U256`
This commit is contained in:
commit
09ba1b6fce
@ -7,11 +7,11 @@ 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 = "c52a04c9f349ac812b886f383a7306b27c8b96dc" }
|
||||
eth-trie-utils = { git = "https://github.com/mir-protocol/eth-trie-utils.git", rev = "dd3595b4ba7923f8d465450d210f17a2b4e20f96" }
|
||||
maybe_rayon = { path = "../maybe_rayon" }
|
||||
anyhow = "1.0.40"
|
||||
env_logger = "0.9.0"
|
||||
ethereum-types = "0.13.1"
|
||||
ethereum-types = "0.14.0"
|
||||
hex = { version = "0.4.3", optional = true }
|
||||
hex-literal = "0.3.4"
|
||||
itertools = "0.10.3"
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use anyhow::{anyhow, bail, ensure};
|
||||
use ethereum_types::{BigEndianHash, U256, U512};
|
||||
use ethereum_types::{U256, U512};
|
||||
use keccak_hash::keccak;
|
||||
use plonky2::field::goldilocks_field::GoldilocksField;
|
||||
|
||||
@ -444,7 +444,7 @@ impl<'a> Interpreter<'a> {
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let hash = keccak(bytes);
|
||||
self.push(hash.into_uint());
|
||||
self.push(U256::from_big_endian(hash.as_bytes()));
|
||||
}
|
||||
|
||||
fn run_prover_input(&mut self) -> anyhow::Result<()> {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use eth_trie_utils::partial_trie::PartialTrie;
|
||||
use ethereum_types::{Address, H256};
|
||||
use ethereum_types::{Address, BigEndianHash, H256};
|
||||
use plonky2::field::extension::Extendable;
|
||||
use plonky2::field::polynomial::PolynomialValues;
|
||||
use plonky2::field::types::Field;
|
||||
@ -87,14 +87,20 @@ pub(crate) fn generate_traces<F: RichField + Extendable<D>, const D: usize>(
|
||||
};
|
||||
|
||||
let trie_roots_before = TrieRoots {
|
||||
state_root: read_metadata(GlobalMetadata::StateTrieRootDigestBefore),
|
||||
transactions_root: read_metadata(GlobalMetadata::TransactionsTrieRootDigestBefore),
|
||||
receipts_root: read_metadata(GlobalMetadata::ReceiptsTrieRootDigestBefore),
|
||||
state_root: H256::from_uint(&read_metadata(GlobalMetadata::StateTrieRootDigestBefore)),
|
||||
transactions_root: H256::from_uint(&read_metadata(
|
||||
GlobalMetadata::TransactionsTrieRootDigestBefore,
|
||||
)),
|
||||
receipts_root: H256::from_uint(&read_metadata(
|
||||
GlobalMetadata::ReceiptsTrieRootDigestBefore,
|
||||
)),
|
||||
};
|
||||
let trie_roots_after = TrieRoots {
|
||||
state_root: read_metadata(GlobalMetadata::StateTrieRootDigestAfter),
|
||||
transactions_root: read_metadata(GlobalMetadata::TransactionsTrieRootDigestAfter),
|
||||
receipts_root: read_metadata(GlobalMetadata::ReceiptsTrieRootDigestAfter),
|
||||
state_root: H256::from_uint(&read_metadata(GlobalMetadata::StateTrieRootDigestAfter)),
|
||||
transactions_root: H256::from_uint(&read_metadata(
|
||||
GlobalMetadata::TransactionsTrieRootDigestAfter,
|
||||
)),
|
||||
receipts_root: H256::from_uint(&read_metadata(GlobalMetadata::ReceiptsTrieRootDigestAfter)),
|
||||
};
|
||||
|
||||
let GenerationState {
|
||||
|
||||
@ -52,7 +52,7 @@ pub(crate) fn mpt_prover_inputs<F>(
|
||||
prover_inputs.push((PartialTrieType::of(trie) as u32).into());
|
||||
match trie {
|
||||
PartialTrie::Empty => {}
|
||||
PartialTrie::Hash(h) => prover_inputs.push(*h),
|
||||
PartialTrie::Hash(h) => prover_inputs.push(U256::from_big_endian(h.as_bytes())),
|
||||
PartialTrie::Branch { children, value } => {
|
||||
for child in children {
|
||||
mpt_prover_inputs(child, prover_inputs, parse_leaf);
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use ethereum_types::{Address, U256};
|
||||
use ethereum_types::{Address, H256, U256};
|
||||
use itertools::Itertools;
|
||||
use maybe_rayon::*;
|
||||
use plonky2::field::extension::{Extendable, FieldExtension};
|
||||
@ -54,9 +54,9 @@ pub struct PublicValues {
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct TrieRoots {
|
||||
pub state_root: U256,
|
||||
pub transactions_root: U256,
|
||||
pub receipts_root: U256,
|
||||
pub state_root: H256,
|
||||
pub transactions_root: H256,
|
||||
pub receipts_root: H256,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
|
||||
|
||||
@ -11,7 +11,6 @@ use plonky2::plonk::config::{AlgebraicHasher, GenericConfig};
|
||||
use plonky2::util::reducing::ReducingFactorTarget;
|
||||
use plonky2::with_context;
|
||||
|
||||
use crate::all_stark::{AllStark, Table};
|
||||
use crate::config::StarkConfig;
|
||||
use crate::constraint_consumer::RecursiveConstraintConsumer;
|
||||
use crate::cpu::cpu_stark::CpuStark;
|
||||
@ -27,9 +26,13 @@ use crate::proof::{
|
||||
StarkProofChallengesTarget, StarkProofTarget, TrieRoots, TrieRootsTarget,
|
||||
};
|
||||
use crate::stark::Stark;
|
||||
use crate::util::{h160_limbs, u256_limbs};
|
||||
use crate::util::h160_limbs;
|
||||
use crate::vanishing_poly::eval_vanishing_poly_circuit;
|
||||
use crate::vars::StarkEvaluationTargets;
|
||||
use crate::{
|
||||
all_stark::{AllStark, Table},
|
||||
util::h256_limbs,
|
||||
};
|
||||
|
||||
pub fn verify_proof_circuit<
|
||||
F: RichField + Extendable<D>,
|
||||
@ -504,15 +507,15 @@ pub fn set_trie_roots_target<F, W, const D: usize>(
|
||||
{
|
||||
witness.set_target_arr(
|
||||
trie_roots_target.state_root,
|
||||
u256_limbs(trie_roots.state_root),
|
||||
h256_limbs(trie_roots.state_root),
|
||||
);
|
||||
witness.set_target_arr(
|
||||
trie_roots_target.transactions_root,
|
||||
u256_limbs(trie_roots.transactions_root),
|
||||
h256_limbs(trie_roots.transactions_root),
|
||||
);
|
||||
witness.set_target_arr(
|
||||
trie_roots_target.receipts_root,
|
||||
u256_limbs(trie_roots.receipts_root),
|
||||
h256_limbs(trie_roots.receipts_root),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use std::mem::{size_of, transmute_copy, ManuallyDrop};
|
||||
|
||||
use ethereum_types::{H160, U256};
|
||||
use ethereum_types::{H160, H256, U256};
|
||||
use itertools::Itertools;
|
||||
use plonky2::field::extension::Extendable;
|
||||
use plonky2::field::packed::PackedField;
|
||||
@ -59,6 +59,17 @@ pub(crate) fn u256_limbs<F: Field>(u256: U256) -> [F; 8] {
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
/// Returns the 32-bit little-endian limbs of a `H256`.
|
||||
pub(crate) fn h256_limbs<F: Field>(h256: H256) -> [F; 8] {
|
||||
h256.0
|
||||
.chunks(4)
|
||||
.map(|chunk| u32::from_le_bytes(chunk.try_into().unwrap()))
|
||||
.map(F::from_canonical_u32)
|
||||
.collect_vec()
|
||||
.try_into()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
/// Returns the 32-bit limbs of a `U160`.
|
||||
pub(crate) fn h160_limbs<F: Field>(h160: H160) -> [F; 5] {
|
||||
h160.0
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user