Skip to content

Commit

Permalink
Update with latest changes on mpt_trie
Browse files Browse the repository at this point in the history
  • Loading branch information
Nashtare committed May 20, 2024
1 parent e33156a commit 99e3f26
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ serde_cbor = "0.11.2"
tokio = { version = "1.28.1" }

# zk-evm dependencies
plonky2 = "0.2.0"
plonky2 = "0.2.2"
mpt_trie = { git = "https://github.com/0xPolygonZero/zk_evm", branch = "feat/cancun" }
evm_arithmetization = { git = "https://github.com/0xPolygonZero/zk_evm", branch = "feat/cancun" }

Expand Down
59 changes: 30 additions & 29 deletions eth_test_parser/src/trie_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use common::{
use ethereum_types::{H160, H256, U256};
use evm_arithmetization::{generation::TrieInputs, proof::BlockMetadata};
use keccak_hash::keccak;
use mpt_trie::utils::TryFromIterator;
use mpt_trie::{
nibbles::Nibbles,
partial_trie::{HashedPartialTrie, PartialTrie},
Expand Down Expand Up @@ -115,17 +116,19 @@ impl TestBody {
accounts
.iter()
.map(|(acc_key, pre_acc)| {
let storage_trie = pre_acc
.storage
.iter()
.filter(|(_, v)| !v.is_zero())
.map(|(k, v)| {
(
Nibbles::from_h256_be(hash(&u256_to_be_bytes(*k))),
v.rlp_bytes().to_vec(),
)
})
.collect();
let storage_trie = HashedPartialTrie::try_from_iter(
pre_acc
.storage
.iter()
.filter(|(_, v)| !v.is_zero())
.map(|(k, v)| {
(
Nibbles::from_h256_be(hash(&u256_to_be_bytes(*k))),
v.rlp_bytes().to_vec(),
)
}),
)
.unwrap();

(hash(acc_key.as_bytes()), storage_trie)
})
Expand All @@ -137,24 +140,22 @@ impl TestBody {
accounts: &HashMap<H160, PreAccount>,
storage_tries: &[(H256, HashedPartialTrie)],
) -> HashedPartialTrie {
accounts
.iter()
.map(|(acc_key, pre_acc)| {
let addr_hash = hash(acc_key.as_bytes());
let code_hash = hash(&pre_acc.code.0);
let storage_hash = get_storage_hash(&addr_hash, storage_tries);

let rlp = AccountRlp {
nonce: pre_acc.nonce,
balance: pre_acc.balance,
storage_hash,
code_hash,
}
.rlp_bytes();

(Nibbles::from_h256_be(addr_hash), rlp.to_vec())
})
.collect()
HashedPartialTrie::try_from_iter(accounts.iter().map(|(acc_key, pre_acc)| {
let addr_hash = hash(acc_key.as_bytes());
let code_hash = hash(&pre_acc.code.0);
let storage_hash = get_storage_hash(&addr_hash, storage_tries);

let rlp = AccountRlp {
nonce: pre_acc.nonce,
balance: pre_acc.balance,
storage_hash,
code_hash,
}
.rlp_bytes();

(Nibbles::from_h256_be(addr_hash), rlp.to_vec())
}))
.unwrap()
}

pub(crate) fn get_txn_bytes(&self) -> Vec<u8> {
Expand Down

0 comments on commit 99e3f26

Please sign in to comment.