Cointime

Download App
iOS & Android

MetaTrust: How Onyx's Governance and Vulnerabilities Became Hackers' Golden Shovels

Validated Project

On Nov 1, 2023, MetaScout detected that the lending protocol, Onyx Protocol on Ethereum, was under a flash loan attack with a loss of $2.1M. The root causes are the proposal of adding a new market that was first executed by the hacker, and the precision loss issue of the compound-fork protocol.

MetaTrust Labs conducted in-depth research and analysis on the exploit, revealing how hackers used governance proposals and protocol vulnerabilities to attack Onyx Protocol.

Onyx Protocol

Onyx Protocol(https://docs.onyx.org/) is an algorithmic money market designed to bring secure and trustless credit and lending to users on the Ethereum Network.

On Oct 29, 2023, Onyx protocol(https://x.com/OnyxProtocol/status/1718348637158137858?s=20) launched a proposal OIP-22 to add $PEPE to the market. However, it is unfortunately targeted and executed by the hacker for the exploiting.

The Onyx protocol turned out to be a compound-forked protocol after we checked its on-chain deployed contracts, and its TVL dropped from $2.86M to $557K due to yesterday's attack.

Attacking Timeline

Attack Loss

The total loss of two attacking transactions is ~$2.14M.

Attackers

0x085bDfF2C522e8637D4154039Db8746bb8642BfF

0x5083956303a145f70ba9f3d80c5e6cb5ac842706

Attacking Contract

0x052ad2f779c1b557d9637227036ccaad623fceaa

Attacked Contract

Proxy contract: https://etherscan.io/address/0x5fdbcd61bc9bd4b6d3fd1f49a5d253165ea11750

Implementation Contract: https://etherscan.io/address/0x9dcb6bc351ab416f35aeab1351776e2ad295abc4#code

Governance Contract

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

Attacking Steps

TL;DR

Take one of the attacking transactions, 0xf7c216, as an example.

1. The hacker(0x085bDf) firstly executes proposal OIP-22 to add a new market oPEPE(0x5fdbcd).

2. One minute after the new market is added, launches a flash loan from AAVE and gets 4,000 $WETH

a. Swaps 4,000 $WETH to 2,520,870,348,093 $PEPE

b. Transfers all the $PEPE to the address 0xf8e153

c. Creates contract at the above address 0xf8e153, mints 50,000,000,000,000,000,000 $oPEPE with 1 $PEPE, redeems most of $oPEPE and leaves only 2 wei to the market oPEPE.

d. Transfers 2,520,870,348,093 $PEPE to the market oPEPE and enters the market with $oPEPE

e. Borrow 334 $ETH

f. redeem only 1 wei $oPEPE for 2,520,870,348,093 $PEPE due to precision loss issue.

i. exchangeRate = (totalCash + totalBorrows - totalReserves) / totalSupply = 2,520,870,348,093,423,681,390,050,791,472 / 2 = 1,260,435,174,046,711,840,695,025,395,736

ii. redeemAmountIn = 2,520,870,348,093,423,681,390,050,791,470

iii. redeemTokens = redeemAmountIn / exchangeRate = 1, due to the truncation.

iv. Liquidates borrower(0xf8e153)'s 881,647,840 wei $PEPE

v. Redeems 856,961,701 wei $PEPE

g. Repeats above steps from step b. to step f. borrows $USDC, $USDT, $PAXG, $DAI, $WBTC, and $LINK, and swaps them for $ETH.

3. Repays the AAVE flash loan with 4,002 $WETH and get a profit of 1156.9 $ETH.

Root Cause

• On the one hand, the hacker is very familiar with the precision loss issue of compound-fork protocols and noticed the bug of Onyx protocol in advance, thus, the hacker probably monitors proposal OIP-22, once the proposal is active and ready to be executed, the hacker firstly executes it, only one minute later, launches the attack.

• On the other hand, the precision loss bug is the root cause of the attack. The hacker manipulates the totalSupply to be a tiny value, 2, and increases the totalCash to be extremely high value, 2520870348093423681390050791471, to amplify the exchangeRate, which results in calculation truncation when redeeming.

Recommendation

1. Do a detailed audit of the governance proposal, not limited to the smart contract, especially for the initialization scenario and other edge cases.

2. Consider adding a small amount of shares into the market initialization to prevent manipulation, especially for the compound-fork protocols.

3. Recommend adopting the monitoring system and pausing the protocol when emergency cases happen, if there is a monitoring system for Onyx, the second attack transaction that happened more than half an hour later could be prevented to decrease the loss. Alternatively, integrating a mempool blocking system would be beneficial. This system can effectively detect attack transactions in the mempool when attackers are executing their attacks, allowing for preemptive blocking to avoid losses.

Fund Flow

As of the time of writing, attack(0x085bDf) transfers 1140 $ETH to the money-laundry protocol Tornado.Cash with another controlled address(0x4c9c86).

Another attacker still keeps stolen tokens in the same wallet(0x508395).

Similar Attack

The bug is similar to the previous hack of Hundred Finance on 2023.04.15, which resulted in a loss of approximately $7 million.TX: 0x6e9ebcdebbabda04fa9f2e3bc21ea8b2e4fb4bf4f4670cb8483e2f0b2604f451

About MetaTrust Labs

MetaTrust Labs is a leading provider of Web3 AI security tools and code auditing services incubated at Nanyang Technological University, Singapore. We provide advanced AI solutions that empower developers and project stakeholders to protect Web3 applications and smart contracts. At MetaTrust Labs, we are committed to protecting the Web3 space so that builders can innovate with confidence and reliability.

Website: https://metatrust.io/

Twitter: https://twitter.com/MetatrustLabs

Comments

All Comments

Recommended for you

  • Over $476 Million Liquidated in the Last Hour, Primarily Long Positions

    Data shows that in the past hour, a total of $476 million was liquidated across the network, with long positions accounting for $457 million and short positions for $19.7945 million, primarily affecting long positions. Among these, $200 million in ETH and $116 million in BTC were liquidated.

  • ETH Falls Below $2400

    Market data shows that ETH has fallen below $2400, currently priced at $2395.62, with a 24-hour decline of 4.47%. The market is experiencing significant volatility, so please ensure proper risk management.

  • BTC Drops Below $81,000

    Market data shows that BTC has fallen below $81,000, currently priced at $80,989.9, with a 24-hour decline of 2.87%. The market is experiencing significant volatility, so please ensure proper risk management.

  • US Considers Easing Sanctions on Shadow Fleet to Lower Shipping Rates

    On October 15, a US official stated on Wednesday that the Trump administration is considering easing sanctions on vessels known as the 'shadow fleet.' These ships have previously transported oil and petroleum products from countries such as Russia, Iran, and Venezuela. This move aims to reduce the currently historically high global shipping rates. Shortly before this, President Trump had temporarily lifted sanctions on Russian diesel, a decision that drew strong criticism from Ukrainian President Zelensky, several European governments, and some Republican senators. The US official revealed that current discussions focus on whether the US will allow previously sanctioned vessels to transport 'legitimate oil.' Here, 'legitimate oil' refers to crude oil or petroleum products not subject to US sanctions, rather than oil from Russia and Iran that is under sanctions. The official stated that this move aims to facilitate the export of more refined products and crude oil from the Gulf region.

  • Dollar Index Erases All Gains Since CPI Report Release

    On October 15, the Dollar Index (DXY) slowly declined in the Asian session, completely erasing all gains since the release of the U.S. September CPI data yesterday (which had peaked with a cumulative increase of about 70 points), now reported at 102.16. The British Pound against the U.S. Dollar (GBP/USD) and the Euro against the U.S. Dollar (EUR/USD) both rose about 0.3%, currently reported at 1.3231 and 1.1197, respectively. (Jin10)

  • South Korean Stock Index Opens Down Over 5%

    On October 15, the South Korean KOSPI index fell below 6000 points, dropping 5.59% during the day. SK Hynix fell over 7%, while Samsung Electronics dropped over 6%. (Jinshi)

  • Fed's Daly: Rate Hikes May Be Necessary, But Not Urgent

    On October 15, Mary Daly, President of the San Francisco Federal Reserve, stated on Wednesday that the Fed may need to further raise short-term interest rates to curb excessive inflation. However, she also pointed out that there is no need to take such action at the Fed's meeting on October 27-28. "It is very likely that we will need to make further adjustments, but regarding the timing of those adjustments, I think we are still deliberating," Daly said. "I don’t feel there is a need to rush into a decision with limited information. I believe we have enough time."

  • BTC Falls Below $82,000

    Market data shows that BTC has fallen below $82,000, currently priced at $81,984.48, with a 24-hour decline of 2.01%. The market is experiencing significant volatility, so please ensure proper risk management.

  • BTC Drops Below $83,000

    Market data shows that BTC has fallen below $83,000, currently priced at $83,015.81, with a 24-hour decline of 0.46%. The market is experiencing significant volatility, so please ensure proper risk management.

  • ETH Surpasses $2500

    Market data shows that ETH has surpassed $2500, currently priced at $2500.4, with a 24-hour decline of 0.23%. The market is experiencing significant volatility, so please ensure proper risk management.