Skip to content

Commit

Permalink
Merge branch 'arpit/fix-develop' of github.com:0xPolygonZero/zk_evm i…
Browse files Browse the repository at this point in the history
…nto arpit/424
  • Loading branch information
temaniarpit27 committed Aug 5, 2024
2 parents 9babdaf + 4615cb5 commit 70fea9d
Showing 1 changed file with 0 additions and 71 deletions.
71 changes: 0 additions & 71 deletions trace_decoder/src/typed_mpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,6 @@ impl TriePath {
pub fn from_hash(H256(bytes): H256) -> Self {
Self::new(AsNibbles(bytes)).expect("32 bytes is 64 nibbles, which fits")
}
fn from_txn_ix(txn_ix: usize) -> Self {
TriePath::new(AsNibbles(rlp::encode(&txn_ix))).expect(
"\
rlp of an usize goes through a u64, which is 8 bytes,
which will be 9 bytes RLP'ed.
9 < 32",
)
}
fn into_nibbles(self) -> mpt_trie::nibbles::Nibbles {
let mut theirs = mpt_trie::nibbles::Nibbles::default();
for component in self.0 {
Expand All @@ -163,60 +155,6 @@ impl TriePath {
}
}

/// Per-block, `txn_ix -> [u8]`.
///
/// See <https://ethereum.org/en/developers/docs/data-structures-and-encoding/patricia-merkle-trie/#receipts-trie>
#[derive(Debug, Clone, Default)]
pub struct TransactionTrie {
untyped: HashedPartialTrie,
}

impl TransactionTrie {
pub fn insert(&mut self, txn_ix: usize, val: Vec<u8>) -> Result<Option<Vec<u8>>, Error> {
let prev = self
.untyped
.get(TriePath::from_txn_ix(txn_ix).into_nibbles())
.map(Vec::from);
self.untyped
.insert(TriePath::from_txn_ix(txn_ix).into_nibbles(), val)
.map_err(|source| Error { source })?;
Ok(prev)
}
pub fn root(&self) -> H256 {
self.untyped.hash()
}
pub fn as_hashed_partial_trie(&self) -> &mpt_trie::partial_trie::HashedPartialTrie {
&self.untyped
}
}

/// Per-block, `txn_ix -> [u8]`.
///
/// See <https://ethereum.org/en/developers/docs/data-structures-and-encoding/patricia-merkle-trie/#transaction-trie>
#[derive(Debug, Clone, Default)]
pub struct ReceiptTrie {
untyped: HashedPartialTrie,
}

impl ReceiptTrie {
pub fn insert(&mut self, txn_ix: usize, val: Vec<u8>) -> Result<Option<Vec<u8>>, Error> {
let prev = self
.untyped
.get(TriePath::from_txn_ix(txn_ix).into_nibbles())
.map(Vec::from);
self.untyped
.insert(TriePath::from_txn_ix(txn_ix).into_nibbles(), val)
.map_err(|source| Error { source })?;
Ok(prev)
}
pub fn root(&self) -> H256 {
self.untyped.hash()
}
pub fn as_hashed_partial_trie(&self) -> &mpt_trie::partial_trie::HashedPartialTrie {
&self.untyped
}
}

/// Global, [`Address`] `->` [`AccountRlp`].
///
/// See <https://ethereum.org/en/developers/docs/data-structures-and-encoding/patricia-merkle-trie/#state-trie>
Expand Down Expand Up @@ -300,16 +238,7 @@ impl StorageTrie {
pub fn root(&self) -> H256 {
self.untyped.hash()
}
pub fn remove(&mut self, path: TriePath) -> Result<Option<Vec<u8>>, Error> {
self.untyped
.delete(path.into_nibbles())
.map_err(|source| Error { source })
}
pub fn as_hashed_partial_trie(&self) -> &mpt_trie::partial_trie::HashedPartialTrie {
&self.untyped
}

pub fn as_mut_hashed_partial_trie_unchecked(&mut self) -> &mut HashedPartialTrie {
&mut self.untyped
}
}

0 comments on commit 70fea9d

Please sign in to comment.