Skip to content
NFTVenue Ledger
Directory

Cross Chain Bridge Validator Exploits

Merkle Tree Second-Preimage Attacks, abi.encodePacked Collisions & Bridge Proof Forgery

Hashing 64-byte Merkle leaves identically to 64-byte internal branch nodes—or concatenating dynamic fields via abi.encodePacked—lets attackers forge valid proofs for unbacked mints.

By Dr. Devon Kurosawa, PhDReview not recorded · Updated
Merkle Tree Second-Preimage Attacks, abi.encodePacked Collisions & Bridge Proof Forgery — NFTVenue Ledger 2026 quantitative & supervisory data card
NFTVenue Ledger (Cross-Chain Bridge Verification Models, Oracle Manipulation & Exploit RCAs): Double-hashed 32B leaves, abi.encode boundaries, and Cosmos IAVL multi-path patches.Source: NFTVenue Ledger Institutional Research DeskLicense: CC-BY-4.0

Merkle trees verify cross-chain bridge deposits, ZK rollup state withdrawals, Seaport bulk orders, and institutional reward distributions in O(log_2 N) hashes. Yet subtle Domain-Separation Omissions inside Merkle leaf construction and Multi-Path Range-Proof Bugs (such as the October 2022 $570M BNB Chain IAVL Proof Forgery!) allow attackers to construct valid proofs against an authentic, uncompromised Merkle Root!

Anchored in our cross-chain bridge, oracle & exploit RCA master guide, every Solidity auditor inspects Merkle verifiers across DEXs, bridges, and airdrop claim contracts in our marketplaces directory (from Cosmos IAVL-connected Astroport to EVM venues like 9mm Pro) against three distinct cryptographic collision bugs.

Vulnerability #1: The 64-Byte Leaf vs Internal Branch Second-Preimage Attack!#

Look at how a textbook binary Merkle verifier computes each internal parent node from two 32-byte child hashes (L, R): parentHash = keccak256(abi.encodePacked(L, R)) — notice the preimage passed to keccak256 is exact 64 bytes!

Now watch what happens if a developer constructs a Leaf Hash over (address recipient [20B padded to 32B], uint256 amount [32B]) as: leafHash = keccak256(abi.encode(recipient, amount)) — ALSO exact 64 bytes with NO domain prefix!

  • Suppose the legitimate Merkle tree has an internal branch node B = keccak256(Child_Left || Child_Right) at height 1.
  • Suppose uint256(Child_Left) < 2^160 (or can be ground via vanity address so upper 12 bytes are 0x00!): the attacker submits a fake claim passing recipient = address(uint160(uint256(Child_Left))), amount = uint256(Child_Right), and a shortened Merkle proof omitting height 0!
  • The contract computes leafHash = keccak256(abi.encode(recipient, amount)) == B, walks the remaining valid upper branch straight to merkleRoot, and mints uint256(Child_Right) (~10^75 tokens!) to the attacker!

OpenZeppelin StandardMerkleTree Double-Hash Fix: Hash every leaf twice—leaf = keccak256(bytes.concat(keccak256(abi.encode(addr, amt)))) (32-byte outer preimage != 64-byte branch preimage!), OR prepend 0x00 to leaves and 0x01 to internal nodes (RFC 6962 Certificate Transparency standard)!

RFC 6962 / OpenZeppelin StandardMerkleTree leaf double-hashing and abi.encode collision-free pipeline
RFC 6962 / OpenZeppelin StandardMerkleTree leaf double-hashing and abi.encode collision-free pipelineVerified Exhibit

Vulnerability #2: abi.encodePacked Dynamic Array / String Collisions & Vulnerability #3: IAVL Forgery#

  1. abi.encodePacked Boundary Shifting: Calling keccak256(abi.encodePacked(stringA, stringB)) or abi.encodePacked(address path1, address path2) strips length prefixes! abi.encodePacked("eth", "usdc") produces the exact identical byte stream "ethusdc" as abi.encodePacked("ethu", "sdc")! Always use abi.encode(...) when hashing variable-length types!
  2. The $570M BNB Bridge Cosmos iavl:v Multi-Path Forgery: Tendermint/Cosmos ics23 range proofs allowed an InnerNode struct containing both left and right fields. When a legitimate leaf sat on the left, left was empty—and the verifier hashed left || computedChild || right. By crafting a malicious proof injecting a bogus right hash into an existing tree node, the attacker tricked the verifier into matching the real appHash while proving a non-existent 2,000,000 BNB deposit!

Merkle & Trie Proof Vulnerability Audit Matrix#

Cryptographic VulnerabilityRoot Coding MistakeExploit ConsequenceDeterministic Solidity Fix
64-Byte Second-PreimageSingle keccak256(abi.encode(a, b)) leafInternal node interpreted as valid leaf!Double-hash leaves (StandardMerkleTree) or 0x00/0x01 prefix
Dynamic Field Boundary Shiftkeccak256(abi.encodePacked(dyn1, dyn2))Shift elements between dyn1 & dyn2Replace abi.encodePacked with abi.encode
Unindexed Duplicate LeavesOmitting unique uint256 leafIndexUser claims same (addr, 100) leaf only once (or replays if unbitmapped!)Include unique leafIndex + chainId + contractAddr in leaf!
Malleable Proof PathAccepting arbitrary left/right fields (ICS-23 bug)Forges arbitrary bridge mints ($570M)Enforce strict mutually exclusive left XOR right spec invariants
On-chain gas cost for verifying Merkle inclusion across 1,000 to 1,000,000 leaves using calldata + BitMap
On-chain gas cost for verifying Merkle inclusion across 1,000 to 1,000,000 leaves using calldata + BitMapVerified Exhibit

RFC 6962 / OpenZeppelin Double-Hashed Merkle Verification Formula#

Always generate trees off-chain with @openzeppelin/merkle-tree and verify on-chain using MerkleProof.verifyCalldata with double-hashed, context-bound leaves:

Formula or model from the articleNot independently verified
1) Second-Preimage Proof Leaf Construction (OpenZeppelin StandardMerkleTree):
  • Inner_Hash = keccak256( abi.encode( block.chainid, address(this), epochId, leafIndex, recipient, tokenAddr, amount ) )
  • LeafNode = keccak256( bytes.concat( InnerHash ) ) [Preimage length = 32 bytes]
  • 2) Internal Branch Node Construction (Sorted Pair Commutative Hash):
  • Branch_Node(A, B) = (A < B) ? keccak256( abi.encodePacked(A, B) ) : keccak256( abi.encodePacked(B, A) ) [Preimage length = 64 bytes]
  • Mathematical Disjointness Proof:
  • Because len(Preimage(LeafNode)) == 32 bytes != 64 bytes == len(Preimage(BranchNode)),
  • under collision resistance of Keccak-256, NO internal node B can ever be forged as a Leaf_Node!

What If a Zero-Day Proof Forgery STILL Happens? (ERC-7265 Circuit Breakers)#

Notice what saved $430M of the $570M minted in the BNB Bridge proof forgery: rapid outflow throttling and chain coordination halted off-ramps before the attacker could bridge everything out! Next, pair ZK-SNARK light-client header verification with sub-second outflow caps inside Solidity via ERC-7265 circuit breakers & rate limiters inside our Cross-Chain Bridge & Oracle Security hub.

Frequently asked questions

Why does OpenZeppelin StandardMerkleTree hash every leaf twice with keccak256?

Internal Merkle tree nodes hash two 32-byte children (64 bytes total); hashing a leaf once with abi.encode(address, uint256) also hashes 64 bytes, allowing an internal node to masquerade as a leaf unless hashed a second time (32-byte preimage).

When is abi.encodePacked safe vs unsafe in Solidity?

abi.encodePacked is safe ONLY when all arguments have fixed static byte lengths (e.g., two bytes32 hashes); passing two dynamic strings or arrays strips boundaries so ("ab","c") collides identically with ("a","bc").

How did the $570M BNB Bridge attacker forge a Merkle proof without stealing validator keys?

A bug in the Cosmos IAVL tree proof verifier allowed specifying both a child calculation and an arbitrary extra sibling field in the same InnerOp, shifting the real state hash into a side branch while proving a fake 2M BNB leaf.

Why should Merkle proof verifiers use verifyCalldata instead of verify?

Declaring bytes32 calldata proof and calling MerkleProof.verifyCalldata reads sibling hashes directly from transaction calldata without allocating and copying a memory array, saving ~35%–45% verification gas.

Publication record

Published
November 13, 2026
Updated
November 14, 2026
Author
Dr. Devon Kurosawa, PhD
Review
Review not recorded
Automated fact check
Passed in the stored pipeline record
Source URLs
3 recorded

AI assistance recorded: anthropic/claude-opus-4.6. This field does not establish human review or source verification.

Academic & Institutional Attribution

Cite This Research & Embed Live Data Card

Open Attribution License (CC BY 4.0)

Standard academic & institutional research paper citation format.

Dr. Devon Kurosawa, PhD. (2026, November 14). Merkle Tree Second-Preimage Attacks, abi.encodePacked Collisions & Bridge Proof Forgery. NFTVenue Ledger. https://nftvenueledger.com/protocols/merkle-tree-leaf-preimage-collision-bridge-proof-forgery
Explore Cross Chain Bridge Validator Exploits Hub (20) →

NFTVenue Ledger Data, Benchmarks & Contributor Records

Merkle Tree Preimage Collisions & Bridge Proof Forgery | NFTVenue Ledger