Skip to content

Commit

Permalink
Merge pull request #8 from HerodotusDev/feat/expose-trie
Browse files Browse the repository at this point in the history
feat: expose trie struct and return payload in verification
  • Loading branch information
rkdud007 authored Apr 30, 2024
2 parents cbac28b + 494ef01 commit bb73166
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/tx_receipt_trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct TxReceiptsMptHandler {
/// The [`TxReceiptsMpt`] struct encapsulates the MPT (Merkle Patricia Trie) specifically for transaction receipts,
/// including the trie structure itself, the [`ConsensusTxReceipt`] as elements, and the root hash.
pub struct TxReceiptsMpt {
trie: EthTrie<MemoryDB>,
pub trie: EthTrie<MemoryDB>,
elements: Vec<ConsensusTxReceipt>,
root: B256,
}
Expand Down Expand Up @@ -120,14 +120,14 @@ impl TxReceiptsMptHandler {
}

/// Verifies a proof for a transaction at a given index against the stored trie.
pub fn verify_proof(&self, tx_index: u64, proof: Vec<Vec<u8>>) -> Result<(), Error> {
pub fn verify_proof(&self, tx_index: u64, proof: Vec<Vec<u8>>) -> Result<Vec<u8>, Error> {
let target_trie = self.trie.as_ref().ok_or(Error::TrieNotFound)?;
match target_trie.trie.verify_proof(
H256::from_slice(target_trie.root.as_slice()),
alloy_rlp::encode(U256::from(tx_index)).as_slice(),
proof,
) {
Ok(Some(_)) => Ok(()),
Ok(Some(result)) => Ok(result),
_ => Err(Error::InvalidMPTProof),
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/tx_trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct TxsMptHandler {
/// The [`TxsMpt`] struct encapsulates the MPT (Merkle Patricia Trie) specifically for transactions,
/// including the trie structure itself, the [`ConsensusTx`] as elements, and the root hash.
pub struct TxsMpt {
trie: EthTrie<MemoryDB>,
pub trie: EthTrie<MemoryDB>,
elements: Vec<ConsensusTx>,
root: B256,
}
Expand Down Expand Up @@ -114,14 +114,14 @@ impl TxsMptHandler {
}

/// Verifies a proof for a transaction at a given index against the stored trie.
pub fn verify_proof(&self, tx_index: u64, proof: Vec<Vec<u8>>) -> Result<(), Error> {
pub fn verify_proof(&self, tx_index: u64, proof: Vec<Vec<u8>>) -> Result<Vec<u8>, Error> {
let target_trie = self.trie.as_ref().ok_or(Error::TrieNotFound)?;
match target_trie.trie.verify_proof(
H256::from_slice(target_trie.root.as_slice()),
alloy_rlp::encode(U256::from(tx_index)).as_slice(),
proof,
) {
Ok(Some(_)) => Ok(()),
Ok(Some(result)) => Ok(result),
_ => Err(Error::InvalidMPTProof),
}
}
Expand Down

0 comments on commit bb73166

Please sign in to comment.