Orion Protocol suffers a $2.9 million reentrancy attack: Analysis of the attack process and prevention recommendations.

robot
Abstract generation in progress

Analysis of the Reentrancy Attack Incident on Orion Protocol

On February 2, 2023, OrionProtocol suffered a reentrancy attack on Ethereum and Binance Smart Chain, resulting in a loss of approximately $2.9 million. The attacker exploited a contract vulnerability to steal 2,844,766 USDT on the Ethereum chain and 191,606 BUSD on the Binance Smart Chain.

Attack Process

The attacker first created a custom Token contract and performed relevant transfer and authorization operations. Subsequently, the attacker borrowed through the swap method of a certain DEX and called the ExchangeWithAtomic.swapThroughOrionPool method for token exchange. The exchange path included the address of the Token contract created by the attacker.

During the exchange process, due to the callback mechanism in the attacker's Token contract, the attacker is able to continue calling the ExchangeWithAtomic.depositAsset method through Token.Transfer, thereby enabling a reentrancy attack. This results in the deposit amount being repeatedly accumulated, and ultimately the attacker profits through the withdrawal operation.

OrionProtocol Reentrancy Attack Analysis with PoC

Capital Flow

The attacker's initial funds came from the hot wallet account of a certain trading platform. Out of the profit of 1,651 ETH, 657.5 ETH still remain in the attacker's wallet address, while the rest have been transferred through a mixing service.

OrionProtocol Reentrancy Attack Analysis with PoC

Vulnerability Analysis

The core issue of the vulnerability lies in the doSwapThroughOrionPool function. This function calls the _doSwapTokens function, which updates the curBalance variable after the transfer operation. The attacker exploited the callback functionality added in the transfer function of a custom Token, calling the depositAsset function again before curBalance was updated, leading to an incorrect update of curBalance. Ultimately, after repaying the flash loan, the attacker withdrew additional funds through the withdraw function.

OrionProtocol Reentrancy Attack Analysis with PoC

OrionProtocol Reentrancy Attack Analysis with PoC

OrionProtocol Re-Entrancy Attack Analysis with PoC

OrionProtocol Re-entrancy Attack Analysis with PoC

OrionProtocol Reentrancy Attack Analysis with PoC

OrionProtocol Reentrancy Attack Analysis with PoC

OrionProtocol Reentrancy Attack Analysis with PoC

OrionProtocol Reentrancy Attack Analysis with PoC

OrionProtocol Reentrancy Attack Analysis with PoC

Prevention Suggestions

To prevent similar attacks, it is recommended that project parties pay attention to the following points when designing contracts:

  1. Consider the unexpected situations that may arise from various tokens and multiple exchange paths.
  2. Follow the "Checks-Effects-Interactions" coding pattern, which means first perform condition checks, then update state variables, and finally execute external calls.
  3. Use reentrant locks before and after critical operations to prevent reentrant attacks.
  4. Perform security verification on the Token contracts for external calls.
  5. Regularly conduct code audits and security testing to promptly identify and fix potential vulnerabilities.

By taking these measures, the project can significantly enhance the security and stability of the contracts, minimizing the risk of being attacked.

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
  • 7
  • Share
Comment
0/400
AirdropHunterXiaovip
· 6h ago
Blockchain projects have been harvested again.
View OriginalReply0
MemecoinResearchervip
· 6h ago
ngmi... seems the reentrancy curse strikes again fr fr
Reply0
NightAirdroppervip
· 6h ago
Being blacked out every day is really miserable.
View OriginalReply0
rugpull_survivorvip
· 6h ago
play people for suckers one cut and there is another cut
View OriginalReply0
LightningLadyvip
· 6h ago
The coding skills are pretty good.
View OriginalReply0
PrivacyMaximalistvip
· 6h ago
Another Rug Pull project
View OriginalReply0
NotFinancialAdviservip
· 6h ago
Another project has been exploited.
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)