Skip to content

feat: add EIP-1186 MPT proof verification for on-chain reads#414

Open
decofe wants to merge 2 commits intomainfrom
dankrad/mpt-proof-verification
Open

feat: add EIP-1186 MPT proof verification for on-chain reads#414
decofe wants to merge 2 commits intomainfrom
dankrad/mpt-proof-verification

Conversation

@decofe
Copy link
Copy Markdown
Member

@decofe decofe commented Apr 5, 2026

Summary

Adds Merkle-Patricia trie (MPT) proof verification for token balance queries using eth_getProof. This is the first step toward trustless RPC verification for Tempo and Zones.

Motivation

In Zones (privacy validium L2s), there's a single RPC operator — users can't pick a trusted provider. By verifying EIP-1186 proofs against the block's state root, the wallet can detect inconsistent or forged data from the RPC.

Currently the state root is fetched from the same RPC, so this provides consistency verification (proof matches the provider's claimed state). Full malicious-RPC resistance requires anchoring the state root to an independent trust source (e.g., Tempo L1), which is a follow-up.

Changes

  • New proof module in tempo-common with:
    • pin_latest_block — fetches latest block header for state root anchoring
    • verify_account_proof / verify_storage_proof — MPT verification via alloy-trie
    • verified_storage_at / verified_token_balance / verified_account_balance — high-level verified read helpers
    • Storage proof key binding to prevent proof substitution attacks
    • Configurable mapping slot index for contract-specific storage layouts
  • TokenConfig gains balance_mapping_slot field for explicit slot configuration
  • query_all_balances now attempts proof-verified reads first, falls back to eth_call
  • Session deposit clamping also uses verified reads when available
  • query_token_balance_verified added to channel module

Testing

  • 11 unit tests covering slot computation, error formatting, error conversion, key mismatch detection
  • All 534 existing tests pass
  • Zero clippy warnings, clean fmt, clean docs

Follow-up

  • Anchor state root to Tempo L1 for full trustless verification
  • Add proof verification for escrow channel state (getChannel)
  • Add proof verification for spending limits
  • Proof fixture tests with real eth_getProof responses

Prompted by: dankrad

Co-Authored-By: dankrad 6130607+dankrad@users.noreply.github.com

Add Merkle-Patricia trie proof verification for token balance queries
using eth_getProof. The proof module verifies account and storage proofs
against a pinned block's state root, detecting inconsistent or forged
data from the RPC provider.

Changes:
- New proof module in tempo-common with verify_account_proof,
  verify_storage_proof, verified_token_balance, and helpers
- TokenConfig gains balance_mapping_slot for contract-specific slot
- query_all_balances now attempts proof-verified reads first
- Session deposit clamping also uses verified reads when available
- Storage proof key binding prevents proof substitution attacks

Co-authored-by: dankrad <6130607+dankrad@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019d5e67-b71b-734c-b532-ba31a316edca
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 5, 2026

✅ Changelog found on PR.

Edit changelog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants