🎉 Gate xStocks Trading is Now Live! Spot, Futures, and Alpha Zone – All Open!
📝 Share your trading experience or screenshots on Gate Square to unlock $1,000 rewards!
🎁 5 top Square creators * $100 Futures Voucher
🎉 Share your post on X – Top 10 posts by views * extra $50
How to Participate:
1️⃣ Follow Gate_Square
2️⃣ Make an original post (at least 20 words) with #Gate xStocks Trading Share#
3️⃣ If you share on Twitter, submit post link here: https://www.gate.com/questionnaire/6854
Note: You may submit the form multiple times. More posts, higher chances to win!
📅 July 3, 7:00 – July 9,
Orion Protocol suffers a $2.9 million reentrancy attack: Analysis of the attack process and prevention recommendations.
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.
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.
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.
Prevention Suggestions
To prevent similar attacks, it is recommended that project parties pay attention to the following points when designing contracts:
By taking these measures, the project can significantly enhance the security and stability of the contracts, minimizing the risk of being attacked.