#mpt #ethereum #trie

eth-trie-proofs

Ethereum Transaction Trie Proofs

3 releases

0.1.2 Oct 10, 2024
0.1.1 Jun 26, 2024
0.1.0 Jun 25, 2024

#8 in #mpt

Download history 47/week @ 2024-08-31 36/week @ 2024-09-07 41/week @ 2024-09-14 48/week @ 2024-09-21 25/week @ 2024-09-28 193/week @ 2024-10-05 90/week @ 2024-10-12 33/week @ 2024-10-19 38/week @ 2024-10-26 44/week @ 2024-11-02 12/week @ 2024-11-09 25/week @ 2024-11-16 38/week @ 2024-11-23 41/week @ 2024-11-30 46/week @ 2024-12-07 20/week @ 2024-12-14

146 downloads per month
Used in 8 crates (3 directly)

Custom license

50KB
1K SLoC

eth-trie-proofs

CI Crates.io Documentation

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

~30–44MB
~811K SLoC