eth-trie-proofs

Crates.ioeth-trie-proofs
lib.rseth-trie-proofs
version0.1.2
sourcesrc
created_at2024-06-25 13:58:32.979687
updated_at2024-10-10 00:58:18.234884
descriptionEthereum Transaction Trie Proofs
homepage
repositoryhttps://github.com/HerodotusDev/eth-trie-proofs
max_upload_size
id1283341
size84,616
HDP (github:herodotusdev:hdp)

documentation

README

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

Commit count: 63

cargo fmt