Cosmos: The hacker forges Merkle proof through RangeProof in BNB Chain attack
Cosmos co-founder Ethan Buchman has commented on the BSC cross-chain bridge attack, saying that the key to the problem in this case is that hackers were able to forge Merkle certificates. It shouldn't, because Merkle's proof should provide high completeness. Blockchain light clients (and IBC) are built on Merkle proofs, and many blockchains store data in Merkle trees so that proofs can be generated to prove that certain data is included in the tree. In the case of BSC, the attacker can prove that some data is in the tree, but it is not in the tree.
The Cosmos chain uses a Merkle tree called IAVL, and the IAVL repository exposes an API that uses range proof "RangeProof", but it turns out that the inner workings of RangeProof are seriously flawed. A proof should consist of a leaf node and a series of internal nodes that outline the path in the tree from the leaf to the root, with enough information to compute the Merkle root hash of the tree and verify that the leaves are actually part of the tree. Since this is a binary tree, each internal node can have a left and a right branch. But the proof is by tracing paths in the tree, so the internal node should only contain its left or right branch hash, and the other is constructed from the hash of the other nodes in the proof. The problem with the IAVL RangeProof code is that it allows the Left and Right fields in the InnerNode to be filled in. The attacker basically took advantage of pasting information into the Right field that was never verified and never affected the hash. To convince the verifier that some leaves are part of the tree. So they succeeded in forging the Merkle proof.
Buchman says that while RangeProof is not a good idea, there may be a way around this problem by denying proof in advance when any internal node fills both left and right fields. While RangeProof is part of the core Cosmos repository (IAVL), it is not actually used for the blockchain protocol in the Cosmos stack. The IAVL tree itself is used by all Cosmos-SDK chains, but RangeProof is not. For Merkle proof in IBC, IBC does not use the built-in RangeProof system of IAVL tree, but uses ICS23 standard to generate and verify Merkle proof from IAVL tree. ICS23 code does not have this vulnerability. It explicitly "rejects" RangeProof.