Denaria Hack

Reported loss $166K
Linea
LP accounting rounding asymmetry and unsafe signed-to-unsigned conversion

What happened

On 5 April 2026 an attacker drained about 165,618 USDC from Denaria Finance, a perpetual futures DEX on Linea that prices trades with a virtual AMM combined with oracle prices. The attack ran in a single transaction funded by an Aave flash loan.

Verichains traced the root cause to two bugs in Denaria's LP accounting. Trade execution rounded additions down but subtractions up (divCeil), so each trade eroded an LP's accounting matrix by about 1 wei more than exact math. Once that drift made the LP balance formula evaluate to -1, an unchecked int256 to uint256 cast in internalPerpLogic.sol wrapped it to the maximum uint256 value, which was then clamped to the pool's total assets. Olympix gives the same root cause. The recently added Chainlink Data Streams feed for BTC/USD did not prevent the attack because the flaw was in internal accounting, not the price feed.

Denaria paused all user interfaces, began investigating with the Linea team and auditors, and said users with open trades or USDC in the Vault at the time would be refunded under a procedure still being finalized. It sent the attacker an on-chain offer of a 15% bounty (about $25,600) if the remaining roughly $140K was returned within 48 hours.

How it happened

  1. The attacker's contract took a USDC flash loan from Aave V3 and deployed helper contracts to act as liquidity providers and traders.
  2. A helper LP deposited collateral into the Vault and added one-sided liquidity (virtual stable only, zero virtual asset).
  3. Helper traders opened trades against the pool. Per Verichains, each trade's asymmetric rounding shifted the LP's accounting matrix by about 1 wei, and after roughly eight trades the element actualM[1][0] drifted from 0 to -1.
  4. The LP balance calculation then produced -1, which the unchecked cast turned into the maximum uint256, capped at the pool's available assets.
  5. The helper LP called realizePnL and withdrew the inflated balance as USDC. The attacker repaid the flash loan and sent about 165,618 USDC to 0x8d6778d7fae00ad2e0bc12194cf03b756fed9db3.

Protocol details

Classification Exchange (DEX) / Oracle Manipulation
Protocol Type Derivatives
Implementation language Solidity
Protocol links Website @DenariaFinance

Build your security review skills

Work through hands-on labs covering real exploit mechanics, review techniques, and defensive patterns.