Jet Protocol 任意提款漏洞

慢雾科技2022-04-02 tarihinde yayınlandı2022-04-02 tarihinde güncellendi

Özet

目前在 Solana 上发生过多起黑客攻击事件均与账号校验问题有关,慢雾安全团队提醒广大 Solana 开发者,注意对账号体系进行严密的审查。

据 Jet Protocol 官方博客披露,他们近期修复了一个赏金漏洞,这个漏洞会导致恶意用户可以提取任意用户的存款资金,慢雾安全团队对此漏洞进行了简要分析,并将分析结果分享如下。

账号

(来源:https://www.jetprotocol.io/posts/jet-bug-disclosure)
相关信息
Jet Protocol 是运行在 Solana 上的一个借贷市场,用户可将账号里的代币(如:USDC、SOL)存入金库,赚取年化收益,同时也可以按一定的比例借出另一种代币。在这个过程中合约会给用户一个 note 凭证,作为用户未来的提款凭证,用我们熟悉的字眼来说就是 LP,而本次漏洞发生的原因也和这个 LP 的设计有关。
我们知道和以太坊合约相比,Solana 合约没有状态的概念,取而代之的是账号机制,合约数据都存储在相关联的账号中,这种机制极大提升了 Solana 的区块链性能,但也给合约编写带来了一些困难,最大的困难就是需要对输入的账号进行全面的验证。Jet Protocol 在开发时使用了 Anchor 框架进行开发,Anchor 是由 Solana 上的知名项目 Serum 团队开发的,可以精简很多账号验证及跨合约调用逻辑。
Anchor 是如何工作的呢?我们可以从 Jet Protocol 的一段代码说起:
programs/jet/src/instructions/init_deposit_account.rs

账号

这里的 deposit_account 账号就是用于存储 LP 代币数据的账号,用户在首次使用时,需要调用合约生成该账号,并支付一定的存储费用。
而这里的 #[account] 宏定义限定了这个账号的生成规则:
规则 1:#[account(init, payer = <target_account>, space = <num_bytes>)]
这个约束中,init 是指通过跨合约调用系统合约创建账号并初始化,payer=depositor 意思是 depositor 为新账号支付存储空间费用。
规则 2:#[account(seeds = <seeds>, bump)]
这个约束中将检查给定帐户是否是当前执行程序派生的 PDA,PDA (Program Derived Address) 账号是一个没有私钥、由程序派生的账号,seed 和 bump 是生成种子,如果 bump 未提供,则 Anchor 框架默认使用 canonical bump,可以理解成自动赋予一个确定性的值。
使用 PDA,程序可以以编程方式对某些地址进行签名,而无需私钥。同时,PDA 确保没有外部用户也可以为同一地址生成有效签名。这些地址是跨程序调用的基础,它允许 Solana 应用程序相互组合。这里用的是 "deposits" 字符 + reserve 账号公钥 + depositor 账号公钥作为 seeds,bump 则是在用户调用时传入。
规则 3:#[account(token::mint = <target_account>, token::authority = <target_account>)]
这是一个 SPL 约束,用于更简便地验证 SPL 账号。这里指定 deposit_account 账号是一个 token 账号,它的 mint 权限是 deposit_note_mint 账号,authority 权限是 market_authority。
Account 的宏定义还有很多,这里略表不提,详细可以考虑文档:
https://docs.rs/anchor-lang/latest/anchor_lang/derive.Accounts.html
有了这些前置知识,我们就可以直接来看漏洞代码:
programs/jet/src/instructions/withdraw_tokens.rs

账号

正常情况下,用户调用函数 withdraw_tokens 提币时,会传入自己的 LP 账号,然后合约会销毁他的 LP 并返还相应数量的代币。但这里我们可以看到 deposit_note_account 账号是没有进行任何约束的,用户可以随意传入其他用户的 LP 账号。难道使用别人的 LP 账号不需要他们的签名授权吗?
通过前面分析宏定义代码,我们已经知道了 market_authority 账号拥有 LP 代币的操作权限,确实不需要用户自己的签名。那么 market_authority 又是一个怎么样的账号呢?我们可以看这里:

  • programs/jet/src/instructions/init_market.rs
账号

这个 market_authority 也是一个 PDA 账号。也就是说合约通过自身的调用就可以销毁用户的 LP 代币。那么对于恶意用户来说,要发起攻击就很简单了,只要简单地把 deposit_note_account 账号设置为想要窃取的目标账号,withdraw_account 账号设置为自己的收款账号,就可以销毁他的 LP,并把他的存款本金提现到自己的账号上。
最后我们看一下官方的修复方法:

账号

补丁中并未直接去约束 deposit_note_account 账号,而是去除了 burn 操作的 PDA 签名,并将 authority 权限改成了 depositor,这样的话用户将无法直接调用这里的函数进行提现,而是要通过另一个函数 withdraw() 去间接调用,而在 withdraw() 函数中账号宏定义已经进行了严密的校验,恶意用户如果传入的是他人的 LP 账号,将无法通过宏规则的验证,将无法通过宏规则的验证,因为 depositor 需要满足 signer 签名校验,无法伪造成他人的账号。

programs/jet/src/instructions/withdraw.rs

账号

总结
本次漏洞的发现过程比较有戏剧性,漏洞的发现人 @charlieyouai 在他的个人推特上分享了漏洞发现的心路历程,当时他发现 burn 的权限是 market_authority,用户无法进行签名,认为这是一个 bug,会导致调用失败且用户无法提款,于是给官方提交了一个赏金漏洞,然后就去吃饭睡觉打豆豆了。
而后官方开发者意识到了问题的严重性,严格地说,他们知道这段代码没有无法提现的漏洞,而是人人都可以提现啊,老铁,一个能良好运行的 bug 你知道意味着什么吗?!所幸的是没有攻击事件发生。
目前在 Solana 上发生过多起黑客攻击事件均与账号校验问题有关,慢雾安全团队提醒广大 Solana 开发者,注意对账号体系进行严密的审查。

İlgili Okumalar

Microsoft CEO Satya Nadella's Latest Warning: Betting Entirely on a Single AI Model Hands Over a Company's Lifeblood

Microsoft CEO Satya Nadella warns that companies relying solely on a single AI model could jeopardize their survival. He argues that over-dependence leads to "vendor lock-in," where businesses risk ceding control over their core data, memory, contextual history, and AI usage patterns. This dependence essentially outsources a company's critical thinking and operational know-how to an external provider. The deeper a company integrates with one AI system—feeding it prompts, internal data, and workflows—the more it reveals its unique business methods and competitive edge. This accumulated knowledge could become accessible to the AI supplier. Furthermore, switching providers becomes extremely costly and complex, as companies would need to rebuild their entire AI-augmented workflow, memory, and tool integrations from scratch. Nadella's solution is "decoupling." Companies should separate their proprietary data, memory, and control layer (or "harness") from the underlying AI models. By retaining metadata from every AI interaction, businesses can preserve their operational "brain" or institutional knowledge. This allows them to flexibly use different AI models (e.g., from OpenAI, Anthropic, Microsoft) for specific tasks without losing their accumulated expertise. The core idea: companies can rent the smartest models available, but they must keep their own "brain" and operational control firmly in-house.

marsbit5 dk önce

Microsoft CEO Satya Nadella's Latest Warning: Betting Entirely on a Single AI Model Hands Over a Company's Lifeblood

marsbit5 dk önce

Miners Advised Not to Buy GPUs for AI and to Focus on Infrastructure

A founder at an energy investment forum advises bitcoin miners not to purchase GPUs for AI themselves, but to instead focus on infrastructure like power and data center space. Mike Alfred of Alpine Fox stated that while AI infrastructure demand is a long-term, 20-30 year trend, it presents a key choice for miners. The first, riskier model involves owning and operating GPUs, which requires financing expensive hardware that quickly becomes obsolete. The second, more conservative model is akin to real estate: providing colocation services where clients bring their own servers, and the miner sells space, power, cooling, and water. Alfred noted this model is easier to finance. Most existing bitcoin mining sites are difficult and expensive to convert for AI, as AI data centers require far higher construction costs, redundant fiber connections, backup power, complex cooling, and near 100% uptime. A hybrid model, where mining acts as a flexible load to use excess power during AI data center construction or from generation facilities, was discussed. However, participants concluded this is only viable with very cheap power; otherwise, developers are better off focusing solely on AI. Miners are increasingly being evaluated for their available power capacity and project portfolios rather than just bitcoin output. Panelists also warned of risks in the AI sector, predicting at least one major default or contract breach among AI tenants, lenders, or landlords before bitcoin's next halving in 2028.

cryptonews.ru15 dk önce

Miners Advised Not to Buy GPUs for AI and to Focus on Infrastructure

cryptonews.ru15 dk önce

Millisecond 'Pay-to-Cut': How Did Hyperliquid's Priority Fee Turn into a Multi-Million Dollar Business?

"Millisecond 'Paid Queue-Jumping': How Hyperliquid's Priority Fee Became a Multi-Million Dollar Annual Business" In traditional finance, high-frequency trading firms spend millions on infrastructure for millisecond advantages. Hyperliquid has translated this race onto the blockchain with its "Priority Fee" system, creating an open economic game for speed. This system auctions two types of priority: **Gossip Priority** for faster data feeds (via a Dutch auction every 3 minutes), and **Order Priority** for front-of-queue trade execution (users bid a fee for lower latency). This converts a hardware race into a transparent, market-priced mechanism. Since launch, this feature has generated over $5M in protocol revenue. Projected annualized buybacks from this income exceed $30M, accounting for ~7% of total protocol revenue. The demand stems from large traders and market makers on Hyperliquid, for whom milliseconds can mean the difference between profit/loss or avoiding liquidation. Market makers pay these fees as "protection" to ensure their orders execute first, which in turn improves liquidity for all users. Crucially, Hyperliquid internalizes Maximum Extractable Value (MEV) that typically leaks to external validators or searchers, creating a new revenue stream beyond trading fees. The mechanism also strengthens HYPE's tokenomics. While 97% of trading fees fund secondary market buybacks (via the Assistance Fund), Priority Fees are **directly burned**, adding a second deflationary engine. Furthermore, fees for order priority are deducted from users' undelegated HYPE balances, encouraging large traders to hold and lock up tokens, reducing circulating supply. However, a key challenge remains: balancing the speed needs of institutional players with fair market access for retail users, as those who cannot pay high fees may suffer worse slippage during volatility. In summary, Hyperliquid's Priority Fee is a novel model that monetizes latency, captures MEV for the protocol, and enhances its native token's value through burning and lock-ups.

marsbit20 dk önce

Millisecond 'Pay-to-Cut': How Did Hyperliquid's Priority Fee Turn into a Multi-Million Dollar Business?

marsbit20 dk önce

İşlemler

Spot
活动图片