AMM quote overflow can disable swaps and liquidations
The AMM quote helper multiplies two i128 values that can exceed i128::MAX for ordinary 18-decimal token reserves and swap sizes, causing the quote to fail. Because swaps and liquidation callbacks rely on this helper, transactions revert, and an attacker can inflate pool reserves to block liquidations of underwater positions.
Submitted by v12, also found by qed
Found by V12
contracts/shared/src/dex.rs#L55contracts/kinetic-router/src/swap.rs#L38contracts/kinetic-router/src/flash_loan.rs#L345
Targets
- dex::calculateamountout
- dex::swap_collateral
- KineticRouter::executeliquidationcallback
Affected Locations
- dex.calculateamountout: AMM output estimation multiplies
amount_in_with_feebyreserve_outusingi128, which can overflow for common 18-decimal token reserves and swap sizes. - dex.swap_collateral: Collateral swap flows depend on
calculate_amount_out, so liquidation-related swaps revert when the AMM math overflows. - KineticRouter.executeliquidationcallback: Flash-liquidation callback paths rely on the same AMM quote helper, propagating overflow-induced failures into liquidation execution.
Description
The AMM quote helper calculate_amount_out performs its invariant numerator computation with native i128 arithmetic, specifically multiplying amount_in_with_fee by reserve_out. For 18-decimal assets, ordinary reserve depths and liquidation-sized swaps can push this intermediate product beyond i128::MAX, causing checked_mul to return None and the quote path to fail. Because both ordinary swap handling and liquidation flows depend on this helper, the overflow turns into a transaction revert rather than a bounded pricing result. This is not limited to extreme inputs: standard scaled token balances can naturally reach the unsafe range, and an adversary can also inflate pool reserves to force the failure condition. The same remediation applies across both reports: perform the constant-product math in a wider integer domain such as U256 and only downcast after bounds are validated.
Root Cause
calculate_amount_out uses i128 intermediate multiplication for AMM invariant math instead of a wider integer type, so valid 18-decimal reserve and swap values can overflow before output computation completes.
Impact
Liquidations that need the AMM path can be blocked, allowing underwater positions to avoid being unwound and leaving bad debt in the protocol. An attacker may exacerbate this by increasing external pool reserves until calculate_amount_out consistently overflows, disabling direct or callback-based flash liquidation routes for targeted positions.
Proof of Concept
See this gist for full Proof of Concept
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the AMM invariant numerator is computed with i128 multiplication instead of a wider integer type, so valid 18-decimal reserve and swap values overflow before the output is calculated.
Impact
Liquidations that need the AMM path can be blocked, letting underwater positions avoid being unwound and leaving bad debt; an attacker may inflate external pool reserves to make the overflow consistent and disable direct or callback-based flash liquidation routes for targeted positions.
What the attacker needed
18-decimal token reserves; swap or liquidation sized to overflow; attacker can inflate pool reserves
The fix
The constant-product math should be performed in a wider integer domain such as U256, downcasting only after bounds are validated.
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 report has not been written yet. The Original tab links to the source.
A smart contract calculates how many tokens a swap will return by multiplying two large numbers. It stores the result in a fixed-size integer type that cannot hold values above a certain limit, so the multiplication fails and the whole transaction is cancelled. An attacker can make the numbers large enough on purpose, which stops liquidations from running and leaves bad debt in the protocol.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.