Orion Protocol Reentrancy Exploit

From Quadriga Initiative Cryptocurrency Hacks, Scams, and Frauds Repository
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.

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.

About Orion Protocol

[1][2]

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[3].
February 2nd, 2023 8:56:35 AM MST Ethereum Exploit Transaction The protocol is also exploited on the Ethereum blockchain[4].
February 2nd, 2023 9:08:00 AM MST PeckShield Notifies Orion Protocol PeckShield shares a tweet with Orion Protocol with the Binance Smart Chain exploit on their protocol[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].
February 3rd, 2023 2:53:00 PM MST Downplaying Issue on Twitter Orion Protocol tweets to assure the community that "[a]ll user funds remain safe and secure" and that they "resolved a temporary issue within one of the smart contracts of Orion’s experimental private brokers"[9].
February 5th, 2023 1:04:00 PM MST Rekt Article Published Rekt publishes an article covering over the Orion Finance incident[10][11].

Technical Details

The protocol was exploited through a re-entrancy vulnerability in their ExchangeWithOrionPool contract.

This involved the creation of a malicious token which would call the depositAsset function. This allowed the attacker to deposit loaned capital from a flash loan, after already completing the initial deposit, and the deposit was "double-counted" towards their withdrawable balance. They then made the request to withdraw the full balance (double what was actually deposited), repaid the flash loan, and deposited the proceeds into TornadoCash.

PeckShield Analysis

PeckShield publishes an analysis of the exploit[7]. They use the Binance Smart Chain hack transaction[3] as their example.

1/  Again, a $3M lesson from the reentrancy bug! The @orion_protocol is hacked due to a reentrancy issue in its core contract: ExchangeWithOrionPool. Both eth/bsc deployment are hacked.

2/ The hack is made possible due to incomplete reentrancy protection:  swapThroughOrionPool func allows user-provided swap path w/ crafted tokens whose transfer can be hijacked into re-entering  depositAsset func to increase user balance accounting w/o actually costing funds!

3/ To illustrate, we use the hack tx and show the key steps.

4/ The hack is started first on BSC w/ initial fund 0.4 BNB from @TornadoCash. The ETH hack draws initial fund 0.4 ETH from @SimpleSwap_io. After hack, the gain of 1100 ETH is deposited into @TornadoCash and [the] other 657 ETH stays in the hacker’s account.

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.

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[12][6].

Orion is secure, Orion is strong

All users' funds are safe and secure.

- Staking: secure

- Orion Pool: secure

- Bridge: secure

- Liquidity providers: secure

- Depositless trading: secure

We were notified of an event; here's a [thread] on what happened.

Orion Protocol has enabled CEX liquidity on-chain. This revolutionary technology is the future of DeFi, and we are developing new apps every quarter to maximize the utility of our powerful architecture.

2023 is a year for ripe harvests: what's due brings ease of CEX trading available on-chain. DeFi for your neighbor is here.

The community has inquired about opening our lucrative broker network to the public for years (it has always been kept private, and funded by our own internal treasury).

Although extremely profitable (with one of our many internal brokers generating over $1m in revenue over the course of the year), we chose to keep the broker network private & funded with our own company treasury until we are fully comfortable with releasing the public main net.

We do this for the safety of our community and for the integrity of our work.

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.

This contract was not of significant importance to the public in the sense that it was mainly used by one of our experimental brokers, with our company treasury in the broker's account balance.

Please rest assured that all users have always, and will always have full access to 100% of their funds.

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.

Exclusively relying on internal development for our contracts will further minimize any potential exposure to hacks.

It's also important to note that Orion is a TVL light protocol that generates revenue through fees on volume with transient TVL.

This makes it one of the least exposed protocols to large scale hacks, hence why we fill brokers with our internal funds - even our experimental brokers.

In the event that issues occur, our protocol treasury is robust and can handle any incidents without affecting user funds.

We want to reassure our users that no user experienced any loss during this incident. The assets at risk were in internal brokers accounts run by ourselves, the Orion Team, to enable decentralized access to centralized liquidity.

Over the last few years, we have utilized our own funds to fund brokerage accounts. Our brokers use our proprietary Orion Brokerage Software and Orion smart contracts to allow users to trade at best prices (from Binance, KuCoin, OKX and others) from the comfort of their wallet, without losing custody of their assets. Users' funds always remain available via smart contracts.

Instead of relying on low-impact bounty programs, our own funds were used in our smart contracts as a way to attract Web3's most sophisticated hackers. Of course, we always hoped that a vulnerability would not be found.

We have been investigating this very sophisticated attack from the minutes it occurred. We will not reopen the Deposit function until we feel confident that the bug has been fixed which will only be after successfully passing new audits from leading audit firms.

As always, users can withdraw their funds from the Orion Exchange Contract. However, we have temporarily suspended deposits from this contract until we assure the issue with the experimental broker is rectified. Staking and pools on Orion have not been affected.

Rest assured, users have always, and will always have exposure to contracts that have been thoroughly battle-tested and deemed secure by our team.

We take the security of our protocol and user funds very seriously and will continue to take all necessary measures to ensure their safety.

Orion's liquidity aggregator technology is an industry first as it combines the top sources of centralized & decentralized liquidity into one decentralized place, with top security as an absolute priority.

Orion continues to make fine improvements every single day.

For an open transparency, the Orion team will be holding a Twitter Space in the next hour to alleviate any concerns you may have & to assure you that a DeFi bump in the road only makes Orion stronger.

Tune in & ask your questions to the team.

ALL user funds are SAFE.

The Orion Protocol team hosted a Twitter Space an hour later to address any remaining community questions.

Twitter Community Reactions

There were various reactions from the Twitter community to the situation[13][14][15][16][17][18].

"We have reasons to believe that the issue was not a result of any shortcomings in our core protocol code"? So you still did not find a real exploit reason yet?

Great thread, hope can we know more detailed information about the third party vulnerability, like is it Reentrancy, unchecked return values or integer overflow/underflow

What exactly are you trying to say? My main takeaway is you THINK you know how it happened... Not very reassuring

Useless coin. Nobody will use it. And after this, the tweet are just words. For years orn has only words. No B2B. No real improvments. No volume. Only supply increasing. Team is an mess. Keep out of this people !!

With all the respect: Third party libraries are only an issue if your integration is wrong or you don’t understand the library. Calling it not an issue with the “core” code is very misleading. And how is a bug bounty a not a better idea???

1-it is an illusion that they claim that the @orion_protocol is decentralized and that it is a centralised search a new contract of the token was issued and the old one was disposed of due to the hacker stealing the orion token

Ultimate Outcome

The Orion Protocol appears to have downplayed the issue in all subsequent communication.

Total Amount Recovered

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

Ongoing Developments

There don't appear to be any remaining developments in this case. Funds were lost and will most likely not be recovered.

Individual Prevention Policies

Avoid the use of smart contracts unless necessary. Minimize the level of exposure by removing or withdrawing assets whenever possible. Aim to choose smart contracts which have obtained third party security audits, preferably having been audited by at least three separate reputable firms. Pay attention to the audit reports, which smart contracts are covered, and whether the smart contract has been upgraded or modified since the report. Ensure that any administrative functions with the ability to remove funds from the smart contract are under the authority of a multi-signature wallet which is controlled by at least three separate and reputable entities.

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

Platform Prevention Policies

All aspects of any platform should undergo a regular validation/inspection by experts. This validation should include a security audit of any smart contracts, reporting any risks to the backing (of any customer assets, ensuring treasuries or minting functions are properly secured under the control of a multi-signature wallet, and finding any inadequacies in the level of training or integrity of the team. The recommended interval is twice prior to launch or significant system upgrade, once after 3 months, and every 6 months thereafter. It is recommended that the third party performing the inspection not be repeated within a 14 month period.

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

Regulatory Prevention Policies

All platforms should undergo published security and risk assessments by independent third parties. Two assessments are required at founding or major upgrade, one after 3 months, and one every 6 months thereafter. The third parties must not repeat within the past 14 months. A risk assessment needs to include what assets back customer deposits and the risk of default from any third parties being lent to. The security assessment must include ensuring a proper multi-signature wallet, and that all signatories are properly trained. Assessments must be performed on social media, databases, and DNS security.

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

References

  1. Orion Protocol (May 3, 2023)
  2. https://www.orionprotocol.io/hubfs/whitepaper.pdf (May 3, 2023)
  3. 3.0 3.1 Binance Exploit Transaction - BscScan (May 3, 2023)
  4. Orion Protocol Exploit - Etherscan (May 31, 2023)
  5. PeckShield - "Hi, @orion_protocol you may want to take a look" - Twitter (May 31, 2023)
  6. 6.0 6.1 alexeykoloskov - "Moving forward, any and all contracts will be developed in-house to eliminate any potential vulnerabilities from third-party libraries." - Twitter (May 3, 2023)
  7. 7.0 7.1 peckshield - "Again, a $3M lesson from the reentrancy bug! The @orion_protocol is hacked due to a reentrancy issue in its core contract: ExchangeWithOrionPool. Both eth/bsc deployment are hacked." - Twitter (May 3, 2023)
  8. 8.0 8.1 SlowMist_Team - "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." - Twitter (May 3, 2023)
  9. Orion Protocol - "Orion Protocol: Strong Foundations Orion resolved a temporary issue within one of the smart contracts of Orion’s experimental private brokers yesterday. All user funds remain safe and secure" - Twitter (May 31, 2023)
  10. RektHQ - "he hunter has become the hunted. @orion_protocol fell prey to a $3M reentrancy exploit on ETH and BSC. No user funds were lost, but let's hope they take a more Sirius approach in future...T" - witter (May 3, 2023)
  11. Rekt - Orion Protocol - REKT (May 3, 2023)
  12. Alexey Koloskov - "Orion is secure, Orion is strong All users' funds are safe and secure." - Twitter (May 31, 2023)
  13. heckenhacker.eth - "We have reasons to believe that the issue was not a result of any shortcomings in our core protocol code"? So you still did not find a real exploit reason yet? - Twitter (May 31, 2023)
  14. Crypto4Inu - "Great thread, hope can we know more detailed information about the third party vulnerability, like is it Reentrancy, unchecked return values or integer overflow/underflow" - Twitter (May 31, 2023)
  15. LD126 - "What exactly are you trying to say? My main takeaway is you THINK you know how it happened... Not very reassuring" - Twitter (May 31, 2023)
  16. TheResistanceNL - "Useless coin. Nobody will use it. And after this, the tweet are just words. For years orn has only words. No B2B. No real improvments. No volume. Only supply increasing. Team is an mess. Keep out of this people !!" - Twitter (May 31, 2023)
  17. hake - "With all the respect: Third party libraries are only an issue if your integration is wrong or you don’t understand the library. Calling it not an issue with the “core” code is very misleading. And how is a bug bounty a not a better idea???" - Twitter (May 31, 2023)
  18. Mohtasem - "1-it is an illusion that they claim that the @orion_protocol is decentralized and that it is a centralised search a new contract of the token was issued and the old one was disposed of due to the hacker stealing the orion token" - Twitter (May 31, 2023)