WOOFi Hack— The price calculation flaw

lunaray
3 min readMar 8, 2024

--

Background

On March 5, 2024, we observed an abnormal transaction on the Arbitrum : https://arbiscan.io/tx/0xe80a16678b5008d5be1484ec6e9e77dc6307632030553405863ffb38c1f94266. Upon analysis, we discovered an attack targeting WOOFi, resulting in approximately $9 million in losses.

WOOFi is a decentralized application (DApp) built by WOO Network. WOOFi aims to enhance users' experience in decentralized finance (DeFi) by providing ultra-low slippage, competitive exchange fees, and other useful features.

Users on WOOFi can exchange popular digital assets and also earn income through staking and providing liquidity to the network. A key value proposition of the WOOFi platform for DeFi users is deep liquidity.

The attack targeted the swap contract within WOOFi, with the contract address being https://arbiscan.io/address/0xeff23b4be1091b53205e35f3afcd9c7182bf3062#code.

Attack and Event Analysis

The attacker obtained initial funds for the attack from Uniswap and TraderJoe using a flashLoan, totaling 10504796 USDC.e and 2721172 WOO.

Subsequently, the attacker collateralized the borrowed USDC.e in Slio Finance (collateralizing 7000000 USDC.e) and borrowed 5092663 WOO.

Next, the attacker used the remaining USDC.e to exchange for WOO through WOOFi's swap function, thus inflating the price of WOO.

Through three swap operations, the attacker raised the price of WOO from 56884100 to 60400479, setting the stage for the subsequent attack.

The actual attack step occurred when the attacker exchanged WOO for USDC.e.

After this swap, the price of WOO dropped to 7, equivalent to 0.00000007 USD, a decrease of 8.62 million times compared to the previous price.

By examining the contract code, we discovered a price data processing flaw in the WOOFi contract when converting BaseToken to QuoteToken.

When selling BaseToken for QuoteToken, the calculation method for the price of BaseToken is:

newPrice = (1 - 2 * k * oracle.price * baseAmount) * oracle.price

The attacker can control oracle.price and baseAmount, as the k value remains constant. By manipulating oracle.price and baseAmount through multiple swap operations, the attacker can drive the newPrice to extremely low levels.
Finally, the attacker exchanged a large amount of WOO for a small amount of USDC.e, repaid the borrowed principal, and cashed out.

Two days later, WOOFi officials communicated with the attacker, offering a 10% Whitehat reward. However, as of the time of writing, the attacker has not returned the stolen funds.

Subsequently, the official team fixed the issue by removing the constant coefficient.

https://github.com/woonetwork/WooPoolV2/commit/f5fe28acc77cf3801ac379db9bf99bb61b73ba17

Conclusion

The cause of this vulnerability was a flaw in the economic model calculation, allowing the attacker to manipulate the buying and selling quantities of tokens, resulting in a significant drop in the token price. This ultimately enabled the attacker to drain the project’s WOO tokens using a minimal amount of USDC.e. It is recommended that project teams thoroughly validate economic models and code execution logic, and opt for multiple audits from different audit firms before deploying contracts.

--

--

lunaray
lunaray

Written by lunaray

Lunaray takes a leading position in smart contract auditing and consulting service for blockchain security.

No responses yet