Skip to content

ADR 002: Specify BLAKE3→keccak256 Merkle proof scheme for on-chain slashing #4

Closed

Description

@thiras

Priority: Must-fix before implementation

ADR 002 and 003 both acknowledge BLAKE3 isn't an EVM precompile and mention "Merkle proof over chunks using keccak256" for PoC. But no ADR specifies:

  • What chunk size for the Merkle tree?
  • How does a client construct the proof?
  • What's the gas cost of verifying a Merkle proof on-chain?
  • Is the proof over iroh-blobs' internal 1024-byte chunks or the 1 MB payment chunks?

This is critical for slashing to work. Without a concrete spec, slashing for BLAKE3 mismatch is aspirational.

Recommendation

Add a section to ADR 002 or create a new ADR specifying the exact Merkle proof scheme, including chunk size, proof construction, and estimated gas costs.

ADRs affected

  • ADR 002 (Content Addressing)
  • ADR 003 (Payment Model)
  • ADR 004 (Tokenomics — slashing)

Activity

  1. self-assigned this
    on Mar 29, 2026
  2. altanoruc commented on Mar 31, 2026

    @altanoruc
    Contributor

    1. Keccak256 Merkle Proof

    • On-Chain Gas: Low (~30k–50k gas). This solution is highly efficient on-chain because Keccak256 is an EVM-native precompile.
    • Node Overhead: High. Nodes are required to re-hash all incoming content using Keccak256 during the ingestion process.
    • Storage: Additional Requirements. This approach requires storing and managing secondary Keccak Merkle trees alongside original data.
    • Complexity: High Off-Chain. Complexity is shifted to the off-chain environment, as developers must manage and sync two entirely different sets of hashes.

    2. BLAKE3 Path Verification (ADR 012)

    • On-Chain Gas: High (~250k+ gas). Verification is expensive because it requires executing complex BLAKE3 mathematical operations directly in Solidity.
    • Node Overhead: Zero. This solution is optimized for the Iroh ecosystem, as it aligns perfectly with Iroh's native BLAKE3 content IDs.
    • Storage: Efficient. There is no extra storage burden; it simply reuses the existing Bao (outboard) files generated by Iroh.
    • Complexity: High On-Chain. The primary difficulty lies in the smart contract implementation, which requires a robust Solidity version of the BLAKE3 algorithm.

    Comparing the two main approaches reveals a trade-off between computational efficiency for nodes and gas efficiency on-chain.

    Verdict: The BLAKE3 Path Verification (ADR 012) is technically superior for a decentralized CDN. In a high-throughput network, CPU and I/O overhead on nodes is a far greater bottleneck than the occasional gas cost of a slashing event.


    Other Potential Solutions

    1. The "Dual-Hash" Hybrid (Metadata Approach)

    Instead of forcing the node to hash everything, the Origin Node provides a manifest that includes both the BLAKE3 hash (for delivery) and a Keccak256 root (for the EVM) during ingest.

    • Pros: Verification is cheap for the contract; nodes only store one extra 32-byte hash per 1MB chunk.

    • Cons: Breaks the "content-agnostic" principle. If the BLAKE3 hash is the only unique ID, adding a Keccak ID creates a secondary mapping that must be kept in sync across all nodes.

    2. ZK-Fraud Proofs (Succinct Verification)

    The challenger (client) generates a Zero-Knowledge Proof (like a SNARK) proving: "I have a 1024-byte chunk that hashes to BLAKE3 root X, but contains data Y."

    • Pros: The contract only verifies a simple proof (~200k gas), never performing BLAKE3 itself.

    • Cons: Generating ZK proofs for $1024$-byte chunks is computationally expensive for the client and likely too slow for a PoC.

    3. Optimistic Fishermen (Off-Chain Arbitration)

    When a dispute occurs, the contract does not verify the hash. Instead, it "pings" a set of staked Verifier Nodes. If a majority of verifiers agree the data is bad, the node is slashed.

    • Pros: No complex cryptography on-chain.

    • Cons: Introduces a new trust assumption and requires an "honesty majority" of verifiers, which complicates the PoC's simple node/client model.


    Recommendation: Stick with BLAKE3 (Bao)

    For the project, you should move forward with ADR 012 (BLAKE3 Path Verification).

    Why?

    • Architectural Purity: Your entire stack (Rust, iroh, BLAKE3) is built around content-addressing. Introducing Keccak256 just to satisfy the EVM creates "technical debt" at the core delivery layer.

    • Incentive Alignment: Slashing is a rare "edge case" event. It is better to pay a higher gas fee once every few months for a slash than to increase the CPU/Storage cost of every single byte ingested into the network.

    • Future Proofing: If BLAKE3 eventually becomes an EVM precompile (as has been proposed in various EIPs), your code will become significantly cheaper without needing a protocol-wide migration.

    :

  3. added a commit that references this issue on Apr 1, 2026
    0a38eab
  4. yigitdot commented on Apr 1, 2026

    @yigitdot
    Contributor

    ADR 012: On-Chain Merkle Proof Scheme — Status & Open Issues

    Branch pushed: adr/012-onchain-merkle-proof-scheme

    What ADR 012 covers

    • Dual-tree architecture: BLAKE3/bao-tree for streaming (off-chain), keccak256 binary Merkle tree for disputes (on-chain)
    • 1 MB chunks matching ADR 003 payment granularity
    • Voucher integration: keccak root embedded in the ADR 003 voucher — no separate deal registration (saves ~113K gas)
    • Domain separation: 0x00/0x01 leaf/interior prefixes (OpenZeppelin convention) + channel_id in leaf encoding to prevent cross-channel replay
    • Two dispute types: corruption (Merkle proof) and non-delivery (voucher nonce comparison)
    • Settlement-gated: content disputes open after settleChannel(), not during close — watchtower (ADR 007) corrects nonce first

    Remaining issues to resolve

    1. Slash uses ch.stake but stake lives in StakingRegistry (Medium)
    ADR 004 defines stake in a separate registry contract, not in the channel struct. The resolution function should call stakingRegistry.slash(provider, amount) instead of modifying a local field.

    2. No provider defense function (Medium)
    The contract auto-slashes after the content dispute window, but there's no defendCorruptionDispute() function for the provider to prove the data was correct. Simplest PoC approach: provider submits the correct chunk on-chain, contract verifies it reconstructs to the committed root, dispute is dismissed and challenger loses bond.

    3. settledAt timestamp not in ADR 003 channel struct (Low)
    Content disputes reference ch.settledAt + CONTENT_DISPUTE_WINDOW but ADR 003's settleChannel() doesn't record a settlement timestamp. Needs a small addition to the channel struct.

    4. One channel = one blob (Low, design trade-off)
    Each channel delivers exactly one blob. Multi-file downloads need multiple channels. Acceptable for PoC, worth noting as a scaling consideration.

    5. Client sibling path acquisition (Low)
    ADR 012 assumes the client has the Merkle sibling paths but doesn't specify the protocol. Recommended: client builds the tree locally by hashing each 1 MB chunk on receipt.

    6. Corruption proof is a plausibility filter, not cryptographic proof (Acknowledged)
    The Merkle walk only rejects disputes where the submitted data matches the commitment. For all other cases, security relies on the dispute bond (100 TOKEN per ADR 004) + challenge window + off-chain BLAKE3 verification. This is explicitly acknowledged in the ADR.

  5. thiras commented on Apr 3, 2026

    @thiras
    ContributorAuthor

    Resolved by commit 0a38eab ("docs: add ADR 012 on-chain Merkle proof scheme for content verification (fixes #4)"). The Merkle proof scheme is fully specified in ADR 012.

  6. reopened this on Apr 3, 2026
  7. thiras commented on Apr 3, 2026

    @thiras
    ContributorAuthor

    Reopening — the dedicated ADR 012 Merkle proof spec added in 0a38eab was deleted in PR #162 (b7412ab), which repurposed ADR 012 for client architecture. The concrete spec (chunk size, proof construction, gas costs) no longer exists on main. Only vague references to "Merkle proof over chunks using keccak256" remain in ADR 002 and 003.

  8. added a commit that references this issue on Apr 3, 2026
    d7bfe94
  9. 5 remaining items

  10. added a commit that references this issue on May 21, 2026
  11. thiras commented on Oct 16, 2026

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

Metadata

Metadata

Labels

prio:critical

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions