Denaria Finance Exploit: $166K Lost to Asymmetric Rounding and an
Denaria Finance's liquidity matrix used inconsistent rounding (floor for additions, ceil for subtractions), causing a matrix entry to drift negative after several trades. An unchecked int256-to-uint256 cast then turned negative one into the maximum unsigned integer, which a silent clamp converted into a claim on the entire pool, allowing the attacker to withdraw about 165,618 USDC.
On April 5, 2026, Denaria Finance, a decentralized perpetual exchange on the Linea blockchain, was drained of approximately 165,618 USDC. The root cause was the interaction of two separate defects in the protocol’s liquidity accounting.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the combination of asymmetric rounding in the liquidity matrix update and an unchecked signed-to-unsigned cast followed by a silent clamp instead of a revert.
Impact
The attacker could withdraw approximately 165,618 USDC, the entire asset pool, because the clamp converted an accounting error into a full-pool claim.
What the attacker needed
Flash loan for capital; ability to deploy helper contracts; execute multiple trades
The fix
The code should use consistent rounding for additions and subtractions, use SafeCast or check for non-negative values before casting, and revert instead of silently clamping when a computed balance exceeds the pool total.
How it was found
- The attacker took a flash loan from Aave and deployed helper contracts to act as LPs and traders.
- Acting as an LP, the attacker supplied one-sided liquidity (stablecoin only, zero asset), snapshotting the inverse of the current liquidity matrix.
- The attacker's helper traders executed a sequence of trades, each applying the asymmetric rounding and nudging the matrix further down until an entry went negative.
- The attacker called getLpLiquidityBalance, where the unchecked cast turned a negative dot product into the maximum unsigned integer.
- A guard clause silently clamped the astronomical balance to the entire asset pool instead of reverting.
- The attacker called realizePnL to convert the inflated balance into USDC and withdrew from the vault.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
The protocol kept track of liquidity using a small grid of numbers. Each trade updated the grid with slightly inconsistent rounding, so over time one number became negative when it should have stayed at zero. A later step treated that negative number as a huge positive one, and instead of stopping, the code quietly capped it at the whole pool, letting the attacker take everything.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.