3 releases
0.1.2 | Oct 10, 2024 |
---|---|
0.1.1 | Jun 26, 2024 |
0.1.0 | Jun 25, 2024 |
#994 in Magic Beans
359 downloads per month
Used in 8 crates
(3 directly)
50KB
1K
SLoC
eth-trie-proofs
A comprehensive transaction/receipt inclusion proofs handler for Ethereum trie. Tested with various EIPs including Legacy, EIP-2930, EIP-1559, and EIP-4844. This library exposes various proof building functionalities, verification, trie construction etc.
Installation
Add dependency eth-trie-proofs
to your project:
eth-trie-proofs = { version= "0.1.1" }
Usage
- Transaction Trie Handler
#[tokio::test]
async fn test_tx_mpt_frontier() {
let url = Url::parse(MAINNET_RPC_URL_SUB).unwrap();
let target_tx_hash = B256::from(hex!(
"5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060"
));
let mut txs_mpt_handler = TxsMptHandler::new(url).unwrap();
txs_mpt_handler
.build_tx_tree_from_block(46147)
.await
.unwrap();
let tx_index = txs_mpt_handler.tx_hash_to_tx_index(target_tx_hash).unwrap();
let proof = txs_mpt_handler.get_proof(tx_index).unwrap();
txs_mpt_handler
.verify_proof(tx_index, proof.clone())
.unwrap();
}
- Transaction Receipt Trie Handler
#[tokio::test]
async fn test_tx_receipt_1559() {
let url = Url::parse(MAINNET_RPC_URL).unwrap();
let target_tx_hash = B256::from(hex!(
"2055b7e01304f87f9412cd44758cd248bc2da2dab95c97026064ffb084711735"
));
let mut tx_receipts_mpt_handler = TxReceiptsMptHandler::new(url).unwrap();
tx_receipts_mpt_handler
.build_tx_receipts_tree_from_block(12965000)
.await
.unwrap();
let tx_index = tx_receipts_mpt_handler
.tx_hash_to_tx_index(target_tx_hash)
.await
.unwrap();
let proof = tx_receipts_mpt_handler.get_proof(tx_index).unwrap();
tx_receipts_mpt_handler
.verify_proof(tx_index, proof.clone())
.unwrap();
}
Credit
For trie implementation, this project depends on the eth_trie. For transaction and transaction receipt types, heavily depends on the alloy.
License
eth-trie-proofs
is licensed under the GNU General Public License v3.0.
Herodotus Dev Ltd - 2024
Dependencies
~29–43MB
~806K SLoC