Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose trie struct and return payload in verification #8

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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