Jet Protocol 任意提款漏洞

慢雾科技Published on 2022-04-02Last updated on 2022-04-02

Abstract

目前在 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 开发者,注意对账号体系进行严密的审查。

Related Reads

Why P2P and Exchangers Are Becoming Obsolete, and What Will Replace Them

Titled "Why P2P and Exchanges Are Becoming Obsolete, and What Will Replace Them," this article discusses the evolution of stablecoins, particularly USDT, from a trading tool to a global payment method. However, converting crypto back to fiat for daily expenses remains a challenge. The process of using P2P platforms or crypto exchanges has become increasingly risky and complex due to stricter banking anti-fraud measures, new legislation in Russia, and rampant fraud schemes like "triangles," where sellers can inadvertently receive stolen funds. The article highlights that while P2P was convenient, banks now scrutinize frequent peer-to-peer transfers, often freezing accounts. Exchanges also pose risks like unfavorable rates and unclear compliance. The market is therefore shifting towards integrated services that eliminate the manual conversion step. It cites OneSix as an example—a crypto wallet accessible via Telegram and web that embeds currency conversion directly into payment and withdrawal scenarios. Users can pay bills or send money as if using a bank app, with the crypto-to-fiat exchange happening seamlessly in the background. It also offers invoicing for freelancers and conducts AML checks, returning suspicious transactions instantly instead of freezing them. In conclusion, as crypto integrates into everyday finance, the demand for manual, risky exchange methods is declining. The future lies in unified platforms that combine storage, compliance, conversion, and payments into a single, secure user experience.

cryptonews.ru23m ago

Why P2P and Exchangers Are Becoming Obsolete, and What Will Replace Them

cryptonews.ru23m ago

The CEO of MARA Holdings Compares AI Operations to Bitcoin Mining! Which is More Profitable?

Fred Thiel, CEO of MARA Holdings (a major Bitcoin mining company), states that the rapid growth of the artificial intelligence (AI) sector is transforming mining companies' business models. He claims that powering data centers for AI is significantly more profitable than Bitcoin mining. In a recent interview, Thiel explained why many mining firms are diversifying into AI infrastructure. According to Thiel, the energy demands of data centers are surging, especially due to the spread of generative AI applications. This creates new revenue opportunities for Bitcoin mining companies with robust power infrastructure. MARA Holdings is among those monitoring this shift and aims to develop its energy and infrastructure services for AI data centers. Thiel emphasized that this move toward AI does not mean the end of Bitcoin mining. He stated that Bitcoin mining remains a sustainable business model, especially for miners in regions with low electricity costs, and it is still a crucial field for utilizing excess or idle power capacity. In recent years, many Bitcoin mining companies have begun using their energy-intensive infrastructure not just for block production but also for high-performance computing (HPC) and AI applications. This strategy aims to diversify revenue sources and increase resilience against cryptocurrency market volatility. Analysts note that the growing energy demand in the AI sector presents significant transformation opportunities for mining companies. The need for high-power, uninterrupted electricity supply, particularly for large data centers, gives Bitcoin miners with existing energy infrastructure expertise a considerable advantage.

cryptonews.ru34m ago

The CEO of MARA Holdings Compares AI Operations to Bitcoin Mining! Which is More Profitable?

cryptonews.ru34m ago

Ratio's CEO Says Multi-Currency Stablecoins Could Eliminate Costly FX Conversions in Asia

The CEO of Ratio, John Cho, argues that multi-currency stablecoins could save Asia billions by eliminating costly foreign exchange conversions in regional trade. While USD stablecoins like USDT and USDC work for global settlements, local Asian trade is conducted in local currencies like the Korean won or Singapore dollar. Forcing these transactions through USD intermediaries creates unnecessary costs and currency risk. Cho envisions a complementary ecosystem where local-currency stablecoins work alongside USD stablecoins, enabling seamless cross-border settlements without conversion friction. A key pain point in traditional banking is the need for pre-funded Nostro and Vostro accounts, which lock up vast amounts of working capital. Blockchain-based settlement layers like Ratio offer a 24/7 alternative, using on-chain liquidity to enable instant execution even when traditional channels are closed. Modern Web3 infrastructure providers are focusing on pragmatic integration with existing corporate systems like ERPs, allowing businesses to gradually shift volumes to digital channels for better speed, cost, and reduced slippage. Clear regulation is cited as the critical catalyst for widespread institutional adoption. As jurisdictions like the U.S. advance legislation (e.g., the CLARITY Act) and Asian countries are expected to pass their own stablecoin laws within 12-24 months, regulatory uncertainty is receding. The ultimate vision is for regulated stablecoins to become an invisible settlement layer integrated into national payment systems, where payments simply happen on-chain, erasing the boundary between traditional banking and digital assets.

cryptonews.ru53m ago

Ratio's CEO Says Multi-Currency Stablecoins Could Eliminate Costly FX Conversions in Asia

cryptonews.ru53m ago

Huang Xiaoming, Li Bin, Lei Jun, Liang Wenfeng... Who Are the Biggest Winners in the CXMT IPO Feast?

Changxin Technology, a leading Chinese memory chip manufacturer, successfully listed on the Shanghai Stock Exchange's STAR Market (科创板) on July 8, 2026. Its share price surged from the IPO price of 8.66 yuan to close at 49 yuan on the first day, catapulting its market capitalization to 3.28 trillion yuan, making it the most valuable A-share company and triggering a massive wealth creation event. The biggest winners were the company's founder, Zhu Yiming, and its employees. Zhu Yiming's family wealth skyrocketed nearly 300% to approximately $13.9 billion, with his direct stake in Changxin valued at around 80 billion yuan. Additionally, over 6700 employees benefited from stock ownership plans, creating at least 237 new millionaires (in CNY). Zhu also pledged to donate 768 million shares, worth over 37.6 billion yuan, for future employee incentives over a ten-year period. Several prominent investors and corporate clients also reaped significant paper gains from the IPO. Notable figures include: * **Liang Wenfeng**, founder of DeepSeek, whose funds netted a paper profit of approximately 827 million yuan. * **Kong Jianping**, founder of Nano Labs, saw his indirect holdings valued at roughly 940 million yuan. * **Li Bin**, founder of Nio, whose company's strategic investment of 158 million yuan is now worth about 740 million yuan. * **Lei Jun**, founder of Xiaomi, whose subsidiary holds shares currently showing a paper gain of over 736 million yuan. Xiaomi clarified this is a corporate investment, not direct personal wealth. The article notes that while this IPO created immense wealth for insiders and large investors, retail investors who were lucky enough to win an allotment in the lottery typically profited by around 20,000 yuan. The listing solidifies Changxin's position as China's premier domestic memory chipmaker.

marsbit1h ago

Huang Xiaoming, Li Bin, Lei Jun, Liang Wenfeng... Who Are the Biggest Winners in the CXMT IPO Feast?

marsbit1h ago

Trading

Spot
活动图片