Orion Protocol Reentrancy Exploit

From Quadriga Initiative Cryptocurrency Hacks, Scams, and Frauds Repository
Revision as of 23:21, 3 May 2023 by Azoundria (talk | contribs) (Initial 30 minutes completed.)
Jump to navigation Jump to search

Notice: This page is a freshly imported case study from the original repository. The original content was in a different format, and may not have relevant information for all sections. Please help restructure the content by moving information from the 'About' section to other sections, and add any missing information or sources you can find. If you are new here, please read General Tutorial on Wikis or Anatomy of a Case Study for help getting started.

Notice: This page contains sources which are not attributed to any text. The unattributed sources follow the initial description. Please assist by visiting each source, reviewing the content, and placing that reference next to any text it can be used to support. Feel free to add any information that you come across which isn't present already. Sources which don't contain any relevant information can be removed. Broken links can be replaced with versions from the Internet Archive. See General Tutorial on Wikis, Anatomy of a Case Study, and/or Citing Your Sources Guide for additional information. Thanks for your help!

Orion Protocol

Orion Protocol is a DeFi platform that combines the best features of exchanges, brokerages, and instant trading apps. The platform is built around a liquidity aggregator connected to all of the major crypto exchanges and swap pools, enabling users to gain the best price for their trades from a single portal. The platform is powered by the ORN token and offers exceptional security, convenience, and flexibility. On May 2023, Orion Protocol was exploited via a reentrancy attack, which resulted in a total loss of $3 million on ETH and BSC. The attack was contained to an internal broker account and user funds remain safe. The stolen funds were deposited into Tornado Cash, with approximately $1 million of ETH remaining in the Ethereum address. Orion Protocol believes that the issue was not a result of any shortcomings in its core protocol.

This is a global/international case not involving a specific country.[1][2]

About Orion Protocol

[3][4]

Orion Protocol is "[y]our single point of access to the crypto market. Access CEXs, DEXs, and swap pools - directly from your wallet. No account. Global access." "We're here to help you save your time, money, and assets. Access the entire crypto market on one platform, without ever giving up your private keys."

"No one has solved liquidity, custody, accessibility, and scalability in one platform. Until now."

"Built on the most advanced liquidity aggregator ever developed, Orion Protocol solves some of the largest issues in DeFi by aggregating the liquidity of the entire crypto market into one decentralized platform. Governing the protocol is the proprietary staking mechanism Delegated Proof of Broker, fulfilling every function via a decentralized brokerage with the supply-capped ORN token at its core. This underpins each industry-critical solution built on the protocol, from Orion Terminal to Orion Enterprise solutions for blockchains, exchanges, and crypto projects, with thirteen different revenue streams."

"Orion is a new kind of DeFi platform that combines the best features of exchanges, brokerages, and instant trading apps. The platform is built around a liquidity aggregator connected to all of the major crypto exchanges and swap pools (centralized and decentralized), enabling users to gain the best price for their trades from a single portal. Along with powerful tools for portfolio management, Orion offers exceptional security, convenience, and flexibility. The platform is suitable for experienced traders, institutional traders, and newcomers alike.

The Orion platform and ecosystem is powered by the ORN token, an ERC-20 token. Orion Protocol will be an open source repository for dApps, making all of the platform’s functionality available to developers and businesses, enabling anyone to build powerful financial tools."

"Orion Terminal seamlessly aggregates bottomless liquidity from major exchanges, centralized + decentralized: providing rich trading tools in one easy to use platform. Powered by ORN."

"Don't waste time exchange hopping. Access the liquidity of the entire crypto market on one decentralized platform. Access the liquidity of centralized exchanges, decentralized exchanges, and swapping pools in one place."

"Don’t give up control of your private keys. Your key, your control: access bottomless liquidity without ever giving up your private keys. Simply connect your wallet and execute your order across any major exchange - even those you don’t have accounts with."

"Don't buy or sell unless you're getting the best price. Buy or sell your assets at the best price, every time. Orion aggregates all major exchange liquidity into one seamlessly aggregated order book to give you the best price possible."

"Don't waste money on high trading fees and slippage. Best prices, lowest fees, zero spread. By aggregating every exchanges' order book, Orion provides the best prices and lowest fees in market with almost zero spread - and zero slippage."

"We don’t compete with exchanges: we aggregate them. Instead of competing with exchanges and swapping pools, we unite their order books into one easy-to-use terminal, giving you access to the crypto market in one place."

"Orion Protocol fell prey to a reentrancy exploit on Thursday, losing a total of $3M on ETH and BSC."

"A few hours after the news spread on Twitter, Orion’s CEO announced the loss, clarifying that the damage was contained to an internal broker account and that user funds remain safe."

"The attacker’s account was funded from a Binance-labelled wallet, though the original source was allegedly another CEX, SimpleSwap."

"By creating a fake token (ATK) and routing a swap of the flash loaned funds via ATK, a reentrancy hook called depositAsset within ATK’s transfer function, effectively doubling the attacker’s account balance."

"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:

Next, the attacker makes a flashloan of 284,700 USDT and then calls the doSwapThroughOrionPool function of the ExchangeWithAtomic contract to swap the tokens, the exchange path is "USDC -> ATK(malicious token created by the attacker) -> USDT".

The out amount of the exchange is the USDT balance in the ExchangeWithAtomic contract after the exchange minus the initial balance of 2,844,700 USDT.

The problem arises when a call to the ATK token transfer function during the exchange causes the attacker to re-enter the ExchangeWithAtomic contract depositAsset function, resulting in the transfer of 284.4 million USDT from the flashloan to the ExchangeWithAtomic contract.

The attacker's deposit in the ExchangeWithAtomic contract is 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 is calculated as 5,689,000 minus 2,844,700.

By calling the library function creditUserAssets to update the attacking contract's ledger in the ExchangeWithAtomic contract used the exchanged USDT, resulting in the attacking contract's final deposit of USDT in the ExchangeWithAtomic contract being recorded as 5.68 million.

Finally, the attacker withdraws the USDT and returns it to the flashloan lender and swaps 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.

The root cause of the attack was the contract exchange function is not protected from reentrancy..."

"Stolen funds have mostly been deposited to Tornado Cash, with approximately $1M of ETH remaining in the Ethereum address."

"We have reasons to believe that the issue was not a result of any shortcomings in our core protocol code, but rather might have been caused by a vulnerability in mixing third-party libraries in one of the smart contracts used by our experimental and private brokers."

"Moving forward, any and all contracts will be developed in-house to eliminate any potential vulnerabilities from third-party libraries. Our focus is to fortify the Orion Protocol and make sure it remains robust."

This is a global/international case not involving a specific country.

The background of the exchange platform, service, or individuals involved, as it would have been seen or understood at the time of the events.

Include:

  • Known history of when and how the service was started.
  • What problems does the company or service claim to solve?
  • What marketing materials were used by the firm or business?
  • Audits performed, and excerpts that may have been included.
  • Business registration documents shown (fake or legitimate).
  • How were people recruited to participate?
  • Public warnings and announcements prior to the event.

Don't Include:

  • Any wording which directly states or implies that the business is/was illegitimate, or that a vulnerability existed.
  • Anything that wasn't reasonably knowable at the time of the event.

There could be more than one section here. If the same platform is involved with multiple incidents, then it can be linked to a main article page.

The Reality

This sections is included if a case involved deception or information that was unknown at the time. Examples include:

  • When the service was actually started (if different than the "official story").
  • Who actually ran a service and their own personal history.
  • How the service was structured behind the scenes. (For example, there was no "trading bot".)
  • Details of what audits reported and how vulnerabilities were missed during auditing.

What Happened

The specific events of the loss and how it came about. What actually happened to cause the loss and some of the events leading up to it.

Key Event Timeline - Orion Protocol Reentrancy Exploit
Date Event Description
February 2nd, 2023 8:40:20 AM MST BSC Exploit Transaction The exploit transaction occurs on Binance Smart Chain[5].
February 2nd, 2023 3:08:00 PM MST Alexey Koloskov Tweet Stream CEO Alexey Koloskov posts on Twitter to reassure users that all funds are safe and secure after being notified of an event[6]. The staking, Orion Pool, bridge, liquidity providers, and depositless trading on the platform are all secure. The company explained the issue was likely caused by a vulnerability in mixing third-party libraries in one of their experimental and private brokers, which was not of significant importance to the public. The company also confirmed that all users always had, and will always have, full access to 100% of their funds. Going forward, the company plans to eliminate any potential vulnerabilities from third-party libraries by developing all contracts in-house. Orion Protocol has recently enabled CEX liquidity on-chain and has plans to release its broker network to the public.
February 2nd, 2023 7:40:00 PM MST PeckShield Analysis Tweet PeckShield shares an analysis of the incident on Twitter. The Orion Protocol was hacked due to a reentrancy issue in its core contract, ExchangeWithOrionPool, resulting in a loss of $3 million. Both ETH and BSC deployments were affected. The hack was made possible due to incomplete reentrancy protection in the swapThroughOrionPool function, which allows user-provided swap paths with crafted tokens that can be hijacked into re-entering the depositAsset function to increase user balance accounting without actually costing funds. The hack drew an initial fund of 0.4 BNB from TornadoCash on BSC and 0.4 ETH from SimpleSwap_io on ETH. After the hack, the hacker gained 1100 ETH and deposited it into TornadoCash, while keeping the remaining 657 ETH in their account[7].
February 3rd, 2023 2:34:00 AM MST SlowMist Analysis Tweet The SlowMist team provides a summary of a recent hack on the Orion Protocol due to a reentrancy bug in the ExchangeWithOrionPool contract. The hack involved the attacker using a flash loan to call the doSwapThroughOrionPool function to swap tokens, with the exchange path being "USDC -> ATK(malicious token created by the attacker) -> USDT." However, a call to the ATK token transfer function during the exchange caused the attacker to re-enter the depositAsset function, resulting in the transfer of 284.4 million USDT from the flash loan to the ExchangeWithAtomic contract. As a result, the attacker's deposit in the contract was recorded as 2,844,700 USDT, and the balance of USDT tokens in the contract became 5,689,000 USDT. Finally, the attacker withdrew the USDT and returned it to the flash loan lender and swapped the remaining 2.836 million USDT into WETH for profit[8].

Technical Details

This section includes specific detailed technical analysis of any security breaches which happened. What specific software vulnerabilities contributed to the problem and how were they exploited?

PeckShield Analysis

[7]

SlowMist Analysis

The SlowMist team has provided a summary of a recent hack on the Orion Protocol due to a reentrancy bug in the ExchangeWithOrionPool contract. The hack involved the attacker using a flash loan to call the doSwapThroughOrionPool function to swap tokens, with the exchange path being "USDC -> ATK(malicious token created by the attacker) -> USDT." However, a call to the ATK token transfer function during the exchange caused the attacker to re-enter the depositAsset function, resulting in the transfer of 284.4 million USDT from the flash loan to the ExchangeWithAtomic contract. As a result, the attacker's deposit in the contract was recorded as 2,844,700 USDT, and the balance of USDT tokens in the contract became 5,689,000 USDT. Finally, the attacker withdrew the USDT and returned it to the flash loan lender and swapped the remaining 2.836 million USDT into WETH for profit[8].

According to the reports of our team, the contracts on the ETH and BSC chains of the @orion_protocol were attacked on February 3rd, and the attackers made a profit of about $3.027 million.

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:

2/ Next, the attacker makes a flashloan of 284,700 USDT and then calls the doSwapThroughOrionPool function of the ExchangeWithAtomic contract to swap the tokens, the exchange path is "USDC -> ATK(malicious token created by the attacker) -> USDT".

3/ The out amount of the exchange is the USDT balance in the ExchangeWithAtomic contract after the exchange minus the initial balance of 2,844,700 USDT.

4/ The problem arises when a call to the ATK token transfer function during the exchange causes the attacker to re-enter the ExchangeWithAtomic contract depositAsset function, resulting in the transfer of 284.4 million USDT from the flashloan to the ExchangeWithAtomic contract.

5/ The attacker's deposit in the ExchangeWithAtomic contract is 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 is calculated as 5,689,000 minus 2,844,700.

6/ By calling the library function creditUserAssets to update the attacking contract's ledger in the ExchangeWithAtomic contract used the exchanged USDT, resulting in the attacking contract's final deposit of USDT in the ExchangeWithAtomic contract being recorded as 5.68 million.

7/ Finally, the attacker withdraws the USDT and returns it to the flashloan lender and swaps 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.

8/ The root cause of the attack was the contract exchange function is not protected from reentrancy...

9/ The value of the deposit is 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.

Total Amount Lost

The total amount lost has been estimated at $3,027,000 USD.

How much was lost and how was it calculated? If there are conflicting reports, which are accurate and where does the discrepancy lie?

Immediate Reactions

How did the various parties involved (firm, platform, management, and/or affected individual(s)) deal with the events? Were services shut down? Were announcements made? Were groups formed?

Alexey Koloskov Twitter Thread

Orion Protocol CEO Alexey Koloskov posted on Twitter to reassure users and highlight the plan forward[6].

Ultimate Outcome

What was the end result? Was any investigation done? Were any individuals prosecuted? Was there a lawsuit? Was any tracing done?

Total Amount Recovered

There do not appear to have been any funds recovered in this case.

What funds were recovered? What funds were reimbursed for those affected users?

Ongoing Developments

What parts of this case are still remaining to be concluded?

Individual Prevention Policies

No specific policies for individual prevention have yet been identified in this case.

For the full list of how to protect your funds as an individual, check our Prevention Policies for Individuals guide.

Platform Prevention Policies

Policies for platforms to take to prevent this situation have not yet been selected in this case.

For the full list of how to protect your funds as a financial service, check our Prevention Policies for Platforms guide.

Regulatory Prevention Policies

No specific regulatory policies have yet been identified in this case.

For the full list of regulatory policies that can prevent loss, check our Prevention Policies for Regulators guide.

References