从 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

When 8 Million ETH Start 'Moving': The Post-Pectra Era Ushers in a Structural Transformation for Staking?

A major shift is underway in Ethereum staking, as Lido begins migrating over 8 million ETH (worth ~$16B) from traditional validators to a new architecture enabled by the Pectra upgrade. This migration involves consolidating over 265,000 legacy validators (using 0x01 withdrawal credentials) into a smaller number of higher-balance "0x02" validators, potentially reducing the total validator count on Ethereum by nearly a third. The core driver is EIP-7251 from the Pectra upgrade, which introduced "compounding validators." These allow a single validator's effective balance to grow up to 2048 ETH, with staking rewards automatically reinvested to compound earnings. This contrasts with the old model, where rewards exceeding 32 ETH were automatically sent to a withdrawal address, creating idle funds and operational complexity for reinvestment. While the direct APR boost from compounding is modest—estimated at a ~4.7% relative improvement for smaller validators—the structural benefits are significant. For large operators like Lido, the primary value is operational efficiency: managing fewer validators reduces node, key management, and network message overhead. For smaller individual stakers, the upgrade lowers the barrier to reinvestment by eliminating the need to manually accumulate 32 ETH for new validators. The migration signifies a deeper change in Ethereum's staking landscape. Competition is evolving beyond simple yield, focusing instead on capital efficiency, liquidity management, risk distribution, and infrastructure optimization. Lido's parallel move to require node operator security deposits further highlights this shift towards more robust, capital-backed services. Ultimately, Pectra's compounding validators represent a key step in maturing Ethereum's staking lifecycle, moving the ecosystem from standardized yield products towards more sophisticated capital management and infrastructure solutions.

marsbit8 min fa

When 8 Million ETH Start 'Moving': The Post-Pectra Era Ushers in a Structural Transformation for Staking?

marsbit8 min fa

Double Long Hynix ETF Plummets, Halved and Halved Again

On July 29th, shares of South Korean semiconductor firm SK Hynix plummeted over 19% intraday, marking its largest single-day drop on record. The Hong Kong-listed "CSOP SK Hynix Daily Leveraged (2x) Product" (Stock Code: 07709) tumbled more than 28% intraday before closing 13.99% lower at HK$32.70. This leveraged product, designed to deliver twice the daily return of SK Hynix, has seen a catastrophic decline of over 80% from its June 25th high of HK$193.65, far exceeding the underlying stock's roughly 50% drop from its peak. Its assets under management have shrunk dramatically, falling over 70% from a high of HKD 130 billion in June to approximately HKD 31.9 billion. This steep sell-off occurred despite SK Hynix reporting stellar Q2 2026 earnings, with revenue and operating profit surging 257% and 557% year-over-year, respectively. However, the results fell short of market expectations. Analysts cited concerns about potential oversupply from expansion and noted that long-term supply agreements for its high-bandwidth memory (HBM) chips might limit near-term price increases. In response to heightened volatility and regulatory changes, the product's issuer, CSOP Asset Management, announced a transition to a "flexible leverage mechanism" starting August 3rd. Under new Hong Kong SFC rules, the fund's daily leverage multiplier can now be dynamically adjusted between 1.1x and 2x (or -1.1x to -2x for inverse products) based on market conditions, moving away from a fixed 2x target. The fund's name will also be changed to clarify its nature as a daily trading tool unsuitable for long-term holding. Experts warn that this change means investors can no longer assume constant 2x returns and must check the disclosed leverage ratio daily.

marsbit24 min fa

Double Long Hynix ETF Plummets, Halved and Halved Again

marsbit24 min fa

A7 Discusses Accumulated Experience in Using Stablecoins

The Russian State Duma and Federation Council have passed the "Law on Digital Currencies and Digital Rights," which is set to expand the use of stablecoins in cross-border trade settlements starting September 1, 2026. According to the Bank of Russia, exporters and importers will be able to use cryptocurrency in international payments, both directly and through intermediaries, while domestic crypto payments will remain largely prohibited. Company A7, which facilitates operations with the A7A5 stablecoin—Russia's first ruble-pegged stablecoin classified as a Digital Financial Asset (DFA)—commented on the development. Oleg Ogienko, Director of Government Relations and International Affairs for the A7A5 project, stated that while digital asset settlements are still a new practice for many firms, A7 has already accumulated significant expertise in legal documentation, compliance, currency control, and working with infrastructure participants. He added that A7 will continue to apply this expertise for client operations after the law takes effect and will adapt its business processes as the Central Bank issues further regulations. A7 is a Russian international settlement system established in 2024 with participation from PSB Bank. It facilitates cross-border payments and supports foreign trade operations for Russian businesses. Its key instrument, the A7A5 stablecoin, operates on the Tron and Ethereum networks with a market capitalization exceeding $567 million and is circulated in Russia as a DFA via the "Token" platform.

cryptonews.ru39 min fa

A7 Discusses Accumulated Experience in Using Stablecoins

cryptonews.ru39 min fa

Trading

Spot
活动图片