Sitemap

SlowMist: An Analysis of the Attack on Orion Protocol

4 min readMay 8, 2023

--

Press enter or click to view image in full size

According to the reports of our team, the contracts on the ETH and BSC chains of the Orion protocol were attacked on February 3rd, 2023 and the attackers made a profit of about $3.027 million. The SlowMist Security Team intervened and analyzed the situation promptly, and shared the results as follows:

Related Information

Orion Protocol is a decentralized encrypted gateway through which users can conduct token transactions, pledge, cross chain, and more.

Here are the addresses involved in the attack:

The EOA address of the attacker:

0x837962b686fd5a407fb4e5f92e8be86a230484bd

Attack contract addresses:

https://etherscan.io/address/0x5061F7e6dfc1a867D945d0ec39Ea2A33f772380A

https://bscscan.com/address/0x84452042cb7be650be4eb641025ac3c8a0079b67

Attack transactions:

https://etherscan.io/tx/0xa6f63fcb6bec8818864d96a5b1bb19e8bd85ee37b2cc916412e720988440b2aa

https://bscscan.com/tx/0xfb153c572e304093023b4f9694ef39135b6ed5b2515453173e81ec02df2e2104

Attacked contract addresses:

https://etherscan.io/address/0xb5599f568D3f3e6113B286d010d2BCa40A7745AA

https://bscscan.com/address/0xe9d1d2a27458378dd6c6f0b2c390807aed2217ca

Core of the Attack

The attacked ExchangeWithAtomic contract is like a marketplace where users can deposit money in an ExchangeWithAtomic contract and exchange and withdraw tokens through the contract. However, the function of ExchangeWithAtomic contract for exchanging tokens does not do reentrant protection, and the value of account deposit is updated again after exchange only by the balance difference before and after exchange, which makes it controlled by reentrant.

Detailed Analysis

  1. The attacker first called the depositAsset function of the ExchangeWithAtomic contract to make a deposit of 0.5 USDC tokens in preparation for the following attack.
Press enter or click to view image in full size

2. Next, the attacker made a flash loan of 284,700 USDT and then called the doSwapThroughOrionPool function of the ExchangeWithAtomic contract to swap the tokens, the exchange path was [USDC -> ATK(malicious token created by the attacker) -> USDT].

Press enter or click to view image in full size

3. The out amount of the exchange was the USDT balance in the ExchangeWithAtomic contract after the exchange minus the initial balance of 2,844,700 USDT. The problem arose when a call to the ATK token transfer function during the exchange caused the attacker to re-enter the depositAsset function of the ExchangeWithAtomic contract and deposit 284.4 million USDT into the ExchangeWithAtomic contract.

Press enter or click to view image in full size

The attacker’s deposit in the ExchangeWithAtomic contract was recorded as 2,844,700 and the balance of USDT tokens in the contract becomes 5,689,000. As a result, the attacker’s exchange of USDT was calculated as 5,689,000 minus 2,844,700.

Press enter or click to view image in full size
Press enter or click to view image in full size
Press enter or click to view image in full size

4. The converted USDT token finally updated the attack contract’s account used in the ExchangeWithAtomic contract by calling the library function creditUserAssets. As a result, the attack contract ultimately deposited 5.689 million USDT tokens in an ExchangeWithAtomic contract. Note that amountIn was the amountOut returned in the previous exchange.

Press enter or click to view image in full size

5. Finally, the attacker withdrew the USDT and returned it to the flash loan lender and exchanged the remaining 2.836 million USDT into WETH for profit. The attackers used the same method to launch an attack on the BSC chain and made $191,000 in profit.

Press enter or click to view image in full size

6. According to MistTrack analysis by SlowMist Company, after a series of exchange and cross-chain operations, the hacker’s address on BSC is still about 30.5BNB. Already, 1,100 ETH has been allocated to TornadoCash, with 657.55 ETH saved. MistTrack will continue to monitor hacker movements and follow up the shielding.

Press enter or click to view image in full size
Press enter or click to view image in full size

Summary

The root cause of the attack is the contract exchange function was not protected from reentrancy. The value of the deposit was calculated based on the difference between the token balance in the contract before and after the exchange, resulting in the attacker using fake tokens to re-enter the deposit function to get more tokens than expected. The SlowMist Security Team recommends adding reentrant lock protection to functions where protocol is the core function, considering the calculation method of the incoming value of the operation of user assets, such as bookkeeping, and choosing an appropriate and safe method according to the business logic to prevent external manipulation.

About SlowMist

SlowMist is a blockchain security firm established in January 2018. The firm was started by a team with over ten years of network security experience to become a global force. Our goal is to make the blockchain ecosystem as secure as possible for everyone. We are now a renowned international blockchain security firm that has worked on various well-known projects such as Huobi, OKX, Binance, imToken, Crypto.com, Amber Group, Klaytn, EOS, 1inch, PancakeSwap, TUSD, Alpaca Finance, MultiChain, O3Swap, etc.

Website:
https://www.slowmist.com
Twitter:
https://twitter.com/SlowMist_Team
Github:
https://github.com/slowmist/

--

--

SlowMist
SlowMist

Written by SlowMist

SlowMist is a Blockchain security firm established in 2018, providing services such as security audits, security consultants, red teaming, and more.