$300,000 on-chain attack incident: transient storage vulnerability causes harm to margin trading projects

robot
Abstract generation in progress

Fatal Residue: A $300,000 on-chain Attack Event Originating from Transient Storage

On March 30, 2025, a security monitoring system detected that a leveraged trading project on the Ethereum链上 was attacked, resulting in losses of over $300,000 in assets. The security team conducted an in-depth analysis of this incident and is now sharing the results as follows:

Background

The Solidity version 0.8.24 (to be released in January 2024) introduces transient storage features based on EIP-1153. This is a new data storage location designed to provide developers with a low-cost, transaction-effective temporary storage method.

The main features of transient storage include:

  1. Low gas cost: The gas cost for TSTORE and TLOAD operations is fixed at 100.
  2. Transaction Persistence: Data remains valid throughout the transaction.
  3. Automatic clearing: After the transaction ends, the transient storage is automatically reset to zero.

Fatal Residue: A $300,000 on-chain Heist Triggered by Transient Storage

Source of Attack

The root cause of this incident is that the values used for transient storage with tstore in the function were not cleared after the function call ended. This allowed attackers to exploit this characteristic to construct specific malicious addresses, bypassing permission checks to withdraw tokens.

Fatal Residue: A $300,000 on-chain Heist Triggered by Transient Storage

Attack Process

  1. The attacker creates two malicious tokens A and B, creates pools for these two tokens on a DEX and injects liquidity, where token A is the attack contract.

  2. The attacker calls the initialize function of the Vault contract to create a leveraged trading market APE-21 with A token as the collateral token and B token as the debt token.

  3. The attacker calls the mint function of the Vault contract, depositing the debt token B to mint the leveraged token APE. During this process, two transient storage operations are involved: first storing the address of a certain DEX pool, and then storing the quantity of the minted tokens.

Deadly Residue: A $300,000 on-chain Heist Triggered by Transient Storage

  1. The attacker creates a malicious contract through a special method, with an address that is the same as the value of the second transient storage.

  2. The attacker directly calls the callback function of the Vault contract through the malicious contract to transfer tokens. Since the values in the transient storage have not been cleared, the identity check for the caller is incorrectly passed.

  3. Finally, the attacker profits by calling the callback function of the Vault contract through an attack on the contract (Token A), transferring out other tokens (such as WBTC, WETH) from the Vault contract.

Fatal residue: A $300,000 on-chain heist triggered by transient storage

Deadly Residue: A $300,000 on-chain Heist Triggered by Transient Storage

Deadly Residue: A $300,000 on-chain Heist Caused by Transient Storage

Deadly Residue: A $300,000 on-chain Heist Triggered by Transient Storage

Fatal Residue: A $300,000 on-chain Heist Triggered by Transient Storage

Fatal Residue: A $300,000 on-chain Heist Triggered by Transient Storage

Fatal Residue: A $300,000 on-chain Heist Triggered by Transient Storage

Deadly Residue: A $300,000 on-chain Heist Caused by Transient Storage

Fatal Residue: A $300,000 on-chain Heist Triggered by Transient Storage

Fatal Residue: A $300,000 on-chain Heist Triggered by Transient Storage

Fatal Residue: A $300,000 on-chain Heist Triggered by Transient Storage

Fatal Residue: A $300,000 on-chain Heist Triggered by Transient Storage

Fatal Residue: A $300,000 on-chain Heist Triggered by Transient Storage

Fatal Residue: A $300,000 on-chain Heist Triggered by Transient Storage

Capital Flow Analysis

According to the analysis of on-chain analysis tools, attackers stole approximately $300,000 worth of assets, including 17,814.8626 USDC, 1.4085 WBTC, and 119.871 WETH. These assets were subsequently consolidated and converted into WETH, ultimately transferred to a certain privacy trading protocol.

The attacker's initial funds came from the 0.3 ETH transferred in from the privacy trading protocol.

Summary and Recommendations

The core of this attack lies in the fact that the attacker exploited the characteristic of transient storage, which maintains a constant value throughout the entire transaction, thereby circumventing the permission verification of the callback function to profit. To prevent similar situations from occurring, it is recommended that the project team:

  1. Immediately use tstore(key to clear the value in transient storage after the function call ends according to business logic.
  2. Strengthen contract code auditing and security testing.
  3. Use the newly introduced features with caution and fully understand their potential risks.
View Original
This page may contain third-party content, which is provided for information purposes only (not representations/warranties) and should not be considered as an endorsement of its views by Gate, nor as financial or professional advice. See Disclaimer for details.
  • Reward
  • 6
  • Share
Comment
0/400
LayerZeroHerovip
· 08-02 23:27
There must be a backdoor in the attack.
View OriginalReply0
Web3ProductManagervip
· 08-01 12:37
Classic UX friction point attack
Reply0
OnchainDetectivevip
· 08-01 04:23
A single mistake in the code can lead to complete failure.
View OriginalReply0
SchrodingersFOMOvip
· 08-01 04:18
Dangerous to go up without testing first
View OriginalReply0
ProbablyNothingvip
· 08-01 04:18
Eventually there will be loopholes.
View OriginalReply0
rug_connoisseurvip
· 08-01 04:11
New vulnerabilities make money fast
View OriginalReply0
Trade Crypto Anywhere Anytime
qrCode
Scan to download Gate app
Community
English
  • 简体中文
  • English
  • Tiếng Việt
  • 繁體中文
  • Español
  • Русский
  • Français (Afrique)
  • Português (Portugal)
  • Bahasa Indonesia
  • 日本語
  • بالعربية
  • Українська
  • Português (Brasil)