NBA的16进制合约漏洞是怎么被科学家薅秃噜皮的?

今天有更懂这个世界一点了吗2022-04-22 tarihinde yayınlandı2022-04-22 tarihinde güncellendi

Özet

用户绕开官网,直接通过matemask用别人已经产生的16进制Input Data与合约直接交互。

今早一觉睡起来看群里大家都在讨论昨晚NBA带给科学家的狂欢,据说有人直接free mint了100个,按照现在0.4ETH的地板价也有一百万人民币了,原由是合约又出现了漏洞,所以来看看到底是怎么回事。
NBA于昨日发售了他们的NFT系列The Association NFT,将240个球员各制作了75个NFT,总共供应18000个,白名单持有者可以free mint 1 个,这句话重点圈起来,之前的讲过的Gh0stlyGh0sts的那篇文章也是free mint,只需要缴纳gas费就可以mint到坐等升值,在肉眼可见的获利空间下如果能再发现点合约漏洞,比如绕过白名单或者绕过mint 1个的限制,那不得把羊毛薅秃噜皮了,所以每当出现这种NFT项目都会有大量科学家盯着找漏洞,NBA这次整了个王炸,白名单限制和mint 1个限制都被攻破了。

漏洞

这次漏洞对于辛辛苦苦干白名单的用户也是很大的打击,没有白名单的能mint也就算了,还可以无限mint,导致把有白名单的用户名额都抢了,甚至很多用户当初都是在场外花费几千美金购买的白名单。并且在mint时涌进去一大堆科学家导致gas费飙升,白名单用户也受了无妄之灾被迫缴纳更多gas(毕竟白名单的目的之一就是避免 gas war),所以也有大量的用户在维权哭诉,白名单用户在DC哀嚎一片。

漏洞

这的问题主要是两个情况导致的:
1.用户绕开官网,直接通过matemask用别人已经产生的16进制Input Data与合约直接交互。
2.合约对于mint的白名单校验存在漏洞。 
我们先来讲第一个,先考大家一个知识,与智能合约进行交互mint的方式都有哪几种?
首先大家肯定会说,不是在网站上点一个“mint”按钮去调用智能合约来mint吗?
这是最常规的也是所有项目方都希望我们进行的一种操作,大家应该都有蹲在屏幕前狂戳mint按钮抢公售的经历。
另外有经验的同学会说,还可以直接打开区块链浏览器如etherscan,找到项目方的合约地址,在read contract和write contract里对合约进行操作,很多同学都是通过这种方式抢公售的,因为你在官网里点击mint,前端要再触发请求去合约进行操作,合约再完成执行,而你直接在etherscan里操作合约会跳过第一步,速度更快,对于这个方式不了解的可以看我之前的文章怎么通过看懂etherscan了解NFT项目情况?
但是这种方式遇到两种情况是行不通的,一种是项目方根本没有开源它的合约,或者是项目方在合约接口里必须要求你传入一些如签名等参数,而这种参数只能通过项目方的中心化服务器来生成,所以强制你必须要通过项目方的官网进行操作。
其实还有第三种,直接通过matemask钱包来和合约进行操作。
大家也许会对这一种很陌生,其实你已经在不知不觉中大量的使用了这种操作,转账的过程其实就是你用钱包直接交互合约的过程。
当我给某个地址转钱时,首先点击发送。

漏洞

然后输入收款地址,并输入你要转账的金额。

漏洞

这个过程大家已经非常熟悉了,这其实就是你与合约交互的过程,因为转账这种动作是我把钱转给某个地址,该地址只需要收钱就好,不需要让我输入更多额外的信息,这时候你会问,mint可不一样呀,至少我需要输入mint几个,还可能包括白名单校验等,这些参数怎么输入呢?
我们打开小狐狸钱包等设置,进入高级,然后下拉会看到有一个开关叫“显示十六进制数据”,把它打开。

漏洞

这个开关是干嘛的呢?需要先为你讲清楚什么是十六进制数据。
你与任何一个合约交互都会为其输入一定的数据,合约接收到这部分数据进行处理,这个数据定义了你要和合约的哪个接口函数交互,要给这个接口函数传入什么参数等等,这些数据都会以16进制的形式进行压缩。
你打开etherscan,随意找到你曾经的一个交易记录点击进入详情,然后一直下拉,你会在最下面看到 input data,右边有一长串字符,这就是你当时与这个合约的函数交互时输入的数据转成16进制后的样子。

漏洞

关键是这一长串无规律的数字也压根都不懂呀,先不急,这里面是有规律的,虽然这次NBA的漏洞也不要求你读懂16进制就可以直接用,但是本着求真的态度,我们还是要能理解这里面的含义。
首先我们可以看到开头的0x后面有几位字符,再往后全是0。

漏洞

这几位字符就代表着你调用的这个合约函数的编码,每个函数会有一个自己的编码。
我们打开一个合约的交易记录,你会看到调用的方法中有的是如mint、transfer这种可以理解的文字,有的是0x开头的编码,因为mint、transfer这种操作函数是非常标准的,所以etherscan自动帮你把它们的编码翻译成了文字,但是有的函数是项目方自己开发的,所以只显示其原始编码。

漏洞

我们在测试网试一下使用这种方式和合约直接进行交互的流程,我找到了之前部署的一套合约,然后点击进入已经完成的mint交易详情中。

漏洞

然后拉到最下面复制当时的input data。

漏洞

将合约地址填写进入后,并粘贴我刚才复制的input data,点击下一步。

漏洞

然后到了缴纳gas费的步骤。

漏洞

我们可以点击数据看一下,果然这里功能类型是Mint,没错就是mint函数,说明我们成功的用之前的16进制input data调用到了合约。

漏洞

然后点击确认缴纳gas费,到etherscan上看一下,成功了!

漏洞

漏洞

好了到这里我们已经很清楚的知道用已经存在的交易的16进制数据可以原模原样的执行一次合约函数。
我们刚才讲到这次问题出现的原因第二点是合约校验白名单出现了漏洞。这个漏洞给了科学家用16进制手段薅到到机会。
接下来我们看合约mint到底有什么问题,看过我之前的文章的读者应该都清楚,在mint时一般都会经过几层校验,主要包括是否开启mint校验、数量校验、白名单校验等,如下图NBA的mint合约所示,它有三层校验:
batchNumber是用来校验第几批mint,这个不是我们今天要讲的重点可以先略过。
重点是第二层的白名单校验和第三层的mint数量校验。

漏洞

重点来了,第二层校验用到了一个叫 verify 的函数,传入了一个 info 参数,这是用来校验当前用户是否在白名单,问题就是出在了这里。
在解释白名单校验的问题之前,我们有必要先了解一下常见的2种白名单校验方式,在NFT行业初期,那时候很多项目的白名单都是一个个的录入的,然后在mint时校验一下当前用户的地址是否能够匹配到白名单,每录入一个都要缴纳一次gas费,成本投入极高,我周围就有人仅录入白名单就花费了数万美金。
逐渐的有人意识到这种方法又贵又笨,于是采取了一种技术难度较高但更节省gas费的方式如梅克尔树这种加密签名验证,它的原理就是将白名单不要存储在链上合约中,而是放在链下由项目方自己保管,当用户在官网mint时根据用户的钱包地址用算法生成一个签名,NBA这次使用的就是加密签名方式的校验。
具体的加密原理和代码实现方式讲起来就太复杂了先略过,感兴趣的可以自己去学习椭圆加密算法、梅克尔树这些内容。我们先了解原理即可,我们现在只需要知道这个验证的方法是需要输入一个钱包地址,校验该地址是否存在于白名单,如果存在则返回一个签名。
这时候你可能会隐约觉得有问题,既然校验的方式是输入地址返回结果,那我如果用刚才说的16进制交互的方法,我把白名单用户已经执行的交易16进制数据输入进去,不就可以完成“白名单mint”了吗,这就相当于是指纹识别开门,你把有权限人的手指头剁下来放在识别机上也一样可以进门(有点残忍)。
这里有个问题是如果项目方又多加了一层校验比如mint者地址和校验白名单地址必须是一样的,即你解锁的手指头和进门的人必须得是一体的,这个漏洞也就堵住了,可偏偏NBA还就没有堵住。
我们再回顾一下代码,先用msg.sender获取了当前执行合约的用户地址,在最终执行mint时传入的是这个地址。

漏洞

而在mint前校验的是传入一个叫info的参数,这个info的参数里面包含的地址是官网获取到操作官网用户的地址后传进来的。

漏洞

明白问题所在了吗?有白名单的张三在官网点了mint,官网把张三的地址传入了info后给到合约校验通过,然后合约再执行mint时再获取一遍当前正在执行的张三地址,把NFT转给他,但是!但是没有去判断此张三是否为彼张三呀!他没有去校验这两个地址是否为同一个。
所以我完全可以先找到张三的交易记录,然后把他的16进制复制粘贴到钱包里执行交易,这时候在校验白名单时用的是张三的地址,所以会校验通过,但是mint时用的是我的地址,因为是我正在和合约进行交互。
破案了!精不精彩!我把张三的手指头砍下来进到了金库!
我们看一下规规矩矩用白名单mint的用户他们的16进制长什么样,可以看到这个地址他mint了1个NFT成功了。

漏洞

然后我们看一下16进制,有两个关键点,数字1代表着他mint了1个,下面的地址就是他自己的地址,对上了。

漏洞

我们再看一个昨天传遍科学家圈的一次撸了69个的巨能撸干了点啥,以下为他的地址和mint的100个NFT。

漏洞

我们来看一下他的16进制都是什么,先看到45,这是什么意思呢?这不是代表着数量吗?可不是1也不是64呀,因为64的16进制就是45,所以这位巨能撸把1改成了45从而撸撸64个。

漏洞

你会疑惑不是说有限制每人只能1个吗?这里就又是个漏洞,我们看到代码确实有限制,mint时你的持有量不能超过1,但是我mint的时候是0呀,我mint一万个这个限制也管不住我....不知道这个合约工程师在想啥。

漏洞

接下来我们回到16进制数据,看那个合约地址,你会发现和巨能撸的对不上,说明巨能撸是把他的手指头砍下来解锁了,我们来看看是哪个倒霉蛋。
进入他的地址看到这小子也挺有钱账上躺着30个以太,被撸了也不算亏。

漏洞


然后看到他的交易记录确实在昨晚mint了一个NBA,看来巨能撸就是拿着他的16进制开锁的。

漏洞

这应该是我写过最精彩的一篇文章,犹如破案一般层层抽丝剥茧为大家讲清楚了科学家是怎么把羊毛薅干净的,也是我写过最累的一篇,耗时整整5个小时,写作不易,如果对你有用麻烦大家多转发扩散哈。
我之前的文章中多次强调,web3的世界因为其开源性使得作恶空间很多,当然科学家的行为是否是作恶有待商榷,但是作为项目方一定是有责任保障自己用户利益的,需要对技术有敬畏之心,代码review一定要严谨。

İlgili Okumalar

Bitcoin Panicking? Mythos Cracks Post-Quantum Cryptography Algorithm in 60 Hours

Claude Mythos Preview, a new AI system from Anthropic, has made significant breakthroughs in fundamental cryptanalysis, targeting the mathematics underlying algorithms rather than just implementation bugs. Its first target was HAWK, a candidate in the NIST post-quantum signature standardization process. Mythos identified a previously unexploited symmetry (a nontrivial automorphism) in the lattice structure of HAWK, effectively halving its effective key strength. It achieved this feat in just 60 hours, a task that had eluded two years of human expert review. Crucially, the human operator was not a lattice cryptography expert, primarily managing the project while AI agents debated and discovered the attack path. Its second, more dramatic achievement was against a simplified 7-round version of AES-128, the world's most widely used symmetric encryption algorithm. Initially reluctant, stating the task was "impossible," Mythos was prompted to "try novel ideas." It then autonomously rewrote its own agent framework and proceeded to discover a novel attack method it named "Möbius Bridge." This technique bypasses a critical 256-guess step in previous "meet-in-the-middle" attacks, resulting in a speedup of 200-800 times. Both findings are currently "harmless"—HAWK is not deployed, and full AES-128 remains secure. However, the process reveals a profound shift. Mythos completed the AES discovery in about a week, while human researchers spent nearly a month verifying its correctness. This highlights a new bottleneck: the rate of AI-driven discovery may soon outpace human capacity for verification. The research concludes with a pressing, unanswered question: what happens when such an AI finds a critical flaw in a widely deployed, real-world cryptosystem?

marsbit3 dk önce

Bitcoin Panicking? Mythos Cracks Post-Quantum Cryptography Algorithm in 60 Hours

marsbit3 dk önce

From Computing to Storage: The Two-Dimensional Semiconductor Industry Chain is Taking Shape

The article "From Computing to Storage: The 2D Semiconductor Industry Chain is Taking Shape" discusses the rise of two-dimensional (2D) semiconductors as a pivotal material in the post-Moore era. As silicon-based chips approach physical limits, 2D semiconductors like molybdenum disulfide (MoS2), offer atomic-layer thinness and superior electrical properties, making them a promising non-silicon alternative for advanced nodes beyond 1nm. Globally, industry leaders like TSMC, Intel, and Samsung, along with research institutes like IMEC, are actively investing in this field. Domestically in China, significant progress is being made across the entire supply chain, from material production and equipment R&D to chip integration and ecosystem development. **Key highlights include:** * **Material & Equipment Breakthroughs:** Chinese research teams and companies like Jimo Xin Technology have achieved mass production of 6-inch and 8-inch 2D semiconductor single-crystal wafers using domestically developed equipment like Oxy-MOCVD. This addresses the critical challenge of large-area, high-quality material growth. Breakthroughs have also been made in p-type 2D materials (e.g., MoSi2N4) and wafer-scale ferroelectric thin films, essential for building complementary circuits and low-power transistors. * **Engineering Ecosystem Formation:** A landmark 8-inch 2D semiconductor pilot line in Pudong has become fully operational, bridging the gap between lab research and industrial manufacturing. The release of a Process Design Kit (PDK) compatible with mainstream EDA tools further connects design and fabrication, supporting wafer-level manufacturing of complex circuits. * **Expanding Application Landscape:** Applications are expanding from logic computing to memory. Chinese researchers have developed pioneering 2D semiconductor-based microprocessors, including a 32-bit RISC-V CPU and a higher-density multi-bit parallel processor. In memory, 2D materials' ultra-low leakage current enables DRAM with exceptionally long data retention and advances toward single-electron non-volatile storage. 2D semiconductors also show unique potential in RF circuits, radiation-hardened communications, flexible electronics, and quantum computing. In conclusion, the 2D semiconductor industry in China is rapidly advancing from laboratory research into the engineering validation and small-batch production phase. A complete industrial chain covering materials, equipment, manufacturing, design, and application is初步 forming, positioning the sector as a new competitive dimension in the global semiconductor landscape.

marsbit9 dk önce

From Computing to Storage: The Two-Dimensional Semiconductor Industry Chain is Taking Shape

marsbit9 dk önce

Coinbase and Robinhood Vie for the Next Phase of Cryptocurrency Market Evolution Ahead of Earnings Reports

Coinbase and Robinhood are set to report their Q2 2026 financial results this week, with the outcomes serving as key indicators for the future direction of the crypto market. While both companies have grown from their 2021 IPOs—Coinbase as a dedicated crypto exchange and Robinhood as a commission-free brokerage that expanded into crypto—their paths are now converging in competition. Analysts project Robinhood to report a profit of about $0.40 per share on ~$1.25B revenue, while Coinbase is expected to post a loss of ~$0.36 per share on ~$1.3B revenue. Despite similar revenue figures, investors value Robinhood more highly, viewing it as a diversified fintech firm rather than a pure-play crypto company. This perception has been reinforced as Robinhood gained retail trading market share, with its quarterly trading volume growing from ~$261B in early 2024 to over $704B in Q1 2026, outpacing Coinbase's growth to ~$517B. Both companies are investing heavily in blockchain-based financial infrastructure, such as tokenized stocks and stablecoins, to build more sustainable revenue streams beyond transaction fees. Coinbase has successfully reduced its reliance on trading fees, with subscription/service revenue and stablecoin revenue seeing significant growth. However, over half of its subscription revenue is tied to USDC, exposing it to new competition from banks and payment processors launching rival stablecoins. Robinhood is pursuing a global expansion strategy, recently launching its own layer-2 blockchain (Robinhood Chain) and offering tokenized U.S. stocks in over 120 countries. Its revenue is more diversified, with crypto assets making up only about 12% of its total, which helps explain its premium valuation compared to Coinbase. The upcoming reports will reveal which company's strategy is gaining more traction in shaping the next phase of crypto market evolution.

cryptonews.ru13 dk önce

Coinbase and Robinhood Vie for the Next Phase of Cryptocurrency Market Evolution Ahead of Earnings Reports

cryptonews.ru13 dk önce

İşlemler

Spot
活动图片