从 The Saudis NFT 事件浅析 EIP-2535 钻石协议

慢雾科技Pubblicato 2022-07-12Pubblicato ultima volta 2022-07-12

Introduzione

2022 年 7 月 10 号,一个火热的 NFT 项目 TheSaudis 开启了 freemint 活动(白名单用户可以免费铸造其 NFT)。

背景信息

2022 年 7 月 10 号,一个火热的 NFT 项目 TheSaudis 开启了 freemint 活动(白名单用户可以免费铸造其 NFT)。而就在 mint 活动结束后,一位名叫 RIGHTBLOCK 的用户在市场上大量地抛售该 NFT,项目方发现后迅速锁定到了该用户并对合约进行改动以此来将该用户手里的大量 NFT 转移回来,他们之后承诺会将这些 NFT 回馈给社区用户。

那么为什么项目方可以将该用户手里的 NFT 转移呢?经过我们的分析发现该 NFT 项目的合约采用了 EIP-2535 协议也叫做钻石协议,项目方利用该协议重写了合约的功能,以此来实现这些 NFT 的转移。接下来慢雾安全团队将会为大家介绍下这个钻石协议(EIP-2535)的细节。

钻石协议介绍

EIP-2535 是以太坊上一个将合约进行代码模块化组合的提案,其目的是为了让大型的智能合约突破 24kb 大小的最大限制,并且让合约更方便地更新功能。

要理解钻石协议,首先有几个相关的概念定义需要知道:

钻石(diamond): 钻石可以理解为代理合约(Proxy),也是与用户进行交互的主合约

切面(facet): 正如真正的钻石有不同的侧面一样,一个钻石合约也有着不同的面,钻石合约的每个功能所需要调用的合约对应一个切面,所以也可以理解为实现合约 (Implementation)

钻石切割(diamondCut): 钻石协议标准扩展了一种叫钻石切割的功能,其主要作用从钻石中增加、替换或删除切面和功能,可以理解为合约的升级 (Upgrade)

放大镜(The Loupe): 钻石协议标准中的放大镜功能主要是返回关于切面的信息和钻石存在的功能,这些信息是保存在钻石合约内部的存储结构——DiamondStorage 中

整个钻石模型类似下图:

通过使用钻石标准规范去创建钻石合约,这个合约可以像使用当前合约的代码一样使用任何数量的其他切面合约的代码。

在该钻石合约中不同的函数功能需要调用对应的不同的切面合约的代码来实现,并且可以利用钻石切割的功能来对钻石合约中的函数功能进行修改(添加、替换或删除)。

这与市面上大多数使用一个代理合约和一个实现合约来实现交互与升级的方式有所区别。

事件分析

接下来回头分析下 The Saudis 这次事件中的一些细节,在该项目的 DiamondCutFacet.sol 合约中,可以看到实现了 diamondCut 功能的函数。

该函数首先会调用 LibDiamond 库的 enforceIsContractOwner 函数来判断调用者是否是合约的 owner,如果是 owner 调用的话会调用 LibDiamond 库的 diamondCut 函数来实现钻石合约的功能更新。

跟进到该函数我们发现钻石切割会根据传入的不同的 action 来判断进行添加、替换或删除功能,故接下来跟进看看项目方调用该函数的交易。

我们发现传入了新的切面合约 0x70d8ccaf6b50b051ab1e8fa238626163e45a8b03(未开源),传入的 action 设置为 1 则应该是调用了 replaceFunctions 来实现替换功能。

从 replaceFunctions 函数中可以分析出该函数首先会为传入的地址新增一个切面,接着从存储中循环读取传入的每个函数选择器对应的旧的切面进行删除,并为这些函数的切面添加为传入的新的切面地址。

至此可得知 The Saudis 项目方就是利用了钻石切割函数来重写了转账功能,以此来将用户 RIGHTBLOCK 手中的 NFT 转移回自己的账户。

相关信息

The Saudis 合约地址:

0xe21ebcd28d37a67757b9bc7b290f4c4928a430b1

用户 Rightblock 地址:

0x80266b1e3f0C2cAdAE65A4Ef5Df20f3DF3707FfB

项目方更新合约的交易:

0xbc559a72f73e6c9a53416fd13a3ebaaa76dca5855ff8b79511585f514eaf2390

Letture associate

What If the CLARITY Act Ultimately Fails to Pass?

This article examines the potential consequences if the CLARITY Act, a major US crypto market structure bill, fails to pass in the Senate. Having cleared the House in July 2025 and a key committee in May 2026, the bill's passage into law this year is now considered uncertain, with prediction markets showing its probability dropping from 82% in February to 35%. The article analyzes three main areas of impact should the bill fail. First, for the crypto market, analysts believe a negative reaction is limited and partially priced in already, with Bitcoin's recent weakness attributed more to macro factors. The specific details of the failed bill would matter more than its failure alone. Second, for US stocks, Coinbase (COIN) could see short-term pressure, with analysts citing a potential drop to the $140-$160 range, though its long-term thesis is not solely tied to the bill. For Circle, failure might be neutral or even positive long-term, as a passed bill could invite more stablecoin competition. Bitcoin-treasury firms like Strategy (MSTR) are seen as more directly tied to Bitcoin's price than the legislation. Third, in Washington, the failure is framed within a broader political struggle. Democratic resistance is partly linked to concerns over former President Trump's crypto holdings, making the bill a political tool. If it fails in 2026, the industry would likely rely on existing frameworks like the GENIUS Act and agency-level rules. Missing the August window likely pushes any significant progress to 2027, a period of political reshuffling after midterm elections, making consensus harder to achieve.

Odaily星球日报48 min fa

What If the CLARITY Act Ultimately Fails to Pass?

Odaily星球日报48 min fa

SK Hynix Q2 Profit Soars Sixfold, Still 'Misses Expectations'; Secures Long-Term Agreements with 10 Clients, HBM4 to Accelerate Volume Ramp in Second Half

SK Hynix reported record-breaking Q2 2026 financial results, with operating profit soaring 557% year-over-year to 60.5 trillion won and revenue increasing 257% to 79.3 trillion won, driven by strong demand for AI server memory, HBM, and enterprise SSDs. The operating profit margin reached 76.3%. However, both figures fell short of analyst expectations, leading to a drop in its share price. The company attributed the earnings miss to three factors: a high sales mix of HBM, which limited upside from surging prices of general-purpose DRAM; a deceleration in memory price increases compared to Q1; and long-term supply agreements (LTAs) with major customers that lock in prices, reducing sensitivity to spot market gains. SK Hynix has signed LTAs with about 10 clients, covering roughly half of its sales. Despite the miss, the company remains optimistic about AI-driven demand. Its net profit of 93.9 trillion won was significantly boosted by a one-time gain from the partial sale of its Kioxia stake. Financially, it strengthened its cash position, ending the quarter with a net cash position of 69.4 trillion won. Looking ahead, SK Hynix plans capital expenditures at the high end of its 40-50 trillion won range for 2026 to expand capacity for HBM and advanced NAND products, including accelerating the mass production of HBM4 in the second half of the year.

marsbit1 h fa

SK Hynix Q2 Profit Soars Sixfold, Still 'Misses Expectations'; Secures Long-Term Agreements with 10 Clients, HBM4 to Accelerate Volume Ramp in Second Half

marsbit1 h fa

Trading

Spot
活动图片