mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-08 00:33:06 +00:00
Fix tests and address comments
This commit is contained in:
parent
925cdd5351
commit
ad9796cb10
@ -66,31 +66,7 @@ pub(crate) fn all_mpt_prover_inputs_reversed(trie_inputs: &TrieInputs) -> Vec<U2
|
||||
inputs
|
||||
}
|
||||
|
||||
/// Generate prover inputs for the initial MPT data, in the format expected by `mpt/load.asm`.
|
||||
pub(crate) fn all_mpt_prover_inputs(trie_inputs: &TrieInputs) -> Vec<U256> {
|
||||
let mut prover_inputs = vec![];
|
||||
|
||||
let storage_tries_by_state_key = trie_inputs
|
||||
.storage_tries
|
||||
.iter()
|
||||
.map(|(hashed_address, storage_trie)| {
|
||||
let key = Nibbles::from_bytes_be(hashed_address.as_bytes()).unwrap();
|
||||
(key, storage_trie)
|
||||
})
|
||||
.collect();
|
||||
|
||||
mpt_prover_inputs_state_trie(
|
||||
&trie_inputs.state_trie,
|
||||
empty_nibbles(),
|
||||
&mut prover_inputs,
|
||||
&storage_tries_by_state_key,
|
||||
);
|
||||
|
||||
mpt_prover_inputs(&trie_inputs.transactions_trie, &mut prover_inputs, &|rlp| {
|
||||
rlp::decode_list(rlp)
|
||||
});
|
||||
|
||||
mpt_prover_inputs(&trie_inputs.receipts_trie, &mut prover_inputs, &|rlp| {
|
||||
pub(crate) fn parse_receipts(rlp: &[u8]) -> Vec<U256> {
|
||||
let payload_info = PayloadInfo::from(rlp).unwrap();
|
||||
let decoded_receipt: LegacyReceiptRlp = rlp::decode(rlp).unwrap();
|
||||
let mut parsed_receipt = Vec::new();
|
||||
@ -116,8 +92,37 @@ pub(crate) fn all_mpt_prover_inputs(trie_inputs: &TrieInputs) -> Vec<U256> {
|
||||
}
|
||||
|
||||
parsed_receipt
|
||||
}
|
||||
/// Generate prover inputs for the initial MPT data, in the format expected by `mpt/load.asm`.
|
||||
pub(crate) fn all_mpt_prover_inputs(trie_inputs: &TrieInputs) -> Vec<U256> {
|
||||
let mut prover_inputs = vec![];
|
||||
|
||||
let storage_tries_by_state_key = trie_inputs
|
||||
.storage_tries
|
||||
.iter()
|
||||
.map(|(hashed_address, storage_trie)| {
|
||||
let key = Nibbles::from_bytes_be(hashed_address.as_bytes()).unwrap();
|
||||
(key, storage_trie)
|
||||
})
|
||||
.collect();
|
||||
|
||||
mpt_prover_inputs_state_trie(
|
||||
&trie_inputs.state_trie,
|
||||
empty_nibbles(),
|
||||
&mut prover_inputs,
|
||||
&storage_tries_by_state_key,
|
||||
);
|
||||
|
||||
mpt_prover_inputs(&trie_inputs.transactions_trie, &mut prover_inputs, &|rlp| {
|
||||
rlp::decode_list(rlp)
|
||||
});
|
||||
|
||||
mpt_prover_inputs(
|
||||
&trie_inputs.receipts_trie,
|
||||
&mut prover_inputs,
|
||||
&parse_receipts,
|
||||
);
|
||||
|
||||
// Temporary! The actual number of transactions in the trie cannot be known if the trie
|
||||
// contains hash nodes.
|
||||
let num_transactions = trie_inputs
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
use std::str::FromStr;
|
||||
use std::time::Duration;
|
||||
|
||||
use env_logger::{try_init_from_env, Env, DEFAULT_FILTER_ENV};
|
||||
@ -12,7 +13,7 @@ use plonky2::plonk::config::KeccakGoldilocksConfig;
|
||||
use plonky2::util::timing::TimingTree;
|
||||
use plonky2_evm::all_stark::AllStark;
|
||||
use plonky2_evm::config::StarkConfig;
|
||||
use plonky2_evm::generation::mpt::AccountRlp;
|
||||
use plonky2_evm::generation::mpt::{AccountRlp, LegacyReceiptRlp};
|
||||
use plonky2_evm::generation::{GenerationInputs, TrieInputs};
|
||||
use plonky2_evm::proof::{BlockMetadata, TrieRoots};
|
||||
use plonky2_evm::prover::prove;
|
||||
@ -124,10 +125,22 @@ fn add11_yml() -> anyhow::Result<()> {
|
||||
expected_state_trie_after.insert(to_nibbles, rlp::encode(&to_account_after).to_vec());
|
||||
expected_state_trie_after
|
||||
};
|
||||
|
||||
let receipt_0 = LegacyReceiptRlp {
|
||||
status: true,
|
||||
cum_gas_used: 0xa868u64.into(),
|
||||
bloom: vec![0; 256].into(),
|
||||
logs: vec![],
|
||||
};
|
||||
let mut receipts_trie = HashedPartialTrie::from(Node::Empty);
|
||||
receipts_trie.insert(
|
||||
Nibbles::from_str("0x80").unwrap(),
|
||||
rlp::encode(&receipt_0).to_vec(),
|
||||
);
|
||||
let trie_roots_after = TrieRoots {
|
||||
state_root: expected_state_trie_after.hash(),
|
||||
transactions_root: tries_before.transactions_trie.hash(), // TODO: Fix this when we have transactions trie.
|
||||
receipts_root: tries_before.receipts_trie.hash(), // TODO: Fix this when we have receipts trie.
|
||||
receipts_root: receipts_trie.hash(),
|
||||
};
|
||||
let inputs = GenerationInputs {
|
||||
signed_txns: vec![txn.to_vec()],
|
||||
|
||||
@ -111,7 +111,7 @@ fn test_log_opcodes() -> anyhow::Result<()> {
|
||||
logs: vec![log_0],
|
||||
};
|
||||
|
||||
// Insert the first receipt into the initial receipt trie.
|
||||
// Insert the first receipt into the initial receipt trie. The initial receipts trie has an initial node with a random nibble.
|
||||
let mut receipts_trie = HashedPartialTrie::from(Node::Empty);
|
||||
receipts_trie.insert(
|
||||
Nibbles::from_str("0x1337").unwrap(),
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
use std::str::FromStr;
|
||||
use std::time::Duration;
|
||||
|
||||
use env_logger::{try_init_from_env, Env, DEFAULT_FILTER_ENV};
|
||||
@ -12,7 +13,7 @@ use plonky2::plonk::config::KeccakGoldilocksConfig;
|
||||
use plonky2::util::timing::TimingTree;
|
||||
use plonky2_evm::all_stark::AllStark;
|
||||
use plonky2_evm::config::StarkConfig;
|
||||
use plonky2_evm::generation::mpt::AccountRlp;
|
||||
use plonky2_evm::generation::mpt::{AccountRlp, LegacyReceiptRlp};
|
||||
use plonky2_evm::generation::{GenerationInputs, TrieInputs};
|
||||
use plonky2_evm::proof::{BlockMetadata, TrieRoots};
|
||||
use plonky2_evm::prover::prove;
|
||||
@ -110,10 +111,23 @@ fn test_simple_transfer() -> anyhow::Result<()> {
|
||||
}
|
||||
.into()
|
||||
};
|
||||
|
||||
let receipt_0 = LegacyReceiptRlp {
|
||||
status: true,
|
||||
cum_gas_used: 21032.into(),
|
||||
bloom: vec![0; 256].into(),
|
||||
logs: vec![],
|
||||
};
|
||||
let mut receipts_trie = HashedPartialTrie::from(Node::Empty);
|
||||
receipts_trie.insert(
|
||||
Nibbles::from_str("0x80").unwrap(),
|
||||
rlp::encode(&receipt_0).to_vec(),
|
||||
);
|
||||
|
||||
let trie_roots_after = TrieRoots {
|
||||
state_root: expected_state_trie_after.hash(),
|
||||
transactions_root: tries_before.transactions_trie.hash(), // TODO: Fix this when we have transactions trie.
|
||||
receipts_root: tries_before.receipts_trie.hash(), // TODO: Fix this when we have receipts trie.
|
||||
receipts_root: receipts_trie.hash(),
|
||||
};
|
||||
let inputs = GenerationInputs {
|
||||
signed_txns: vec![txn.to_vec()],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user