A critical vulnerability exists where donating tokens to the pool causes unbalanced liquidity even when the disableUnbalancedLiquidity flag is set to true in the QuantAMMWeightedPoolFactory.sol contract. This bypasses an important protocol safeguard meant to maintain balanced pool ratios.
Affected segment of code: https://github.com/Cyfrin/2024-12-quantamm/blob/a775db4273eb36e7b4536c5b60207c9f17541b92/pkg/pool-quantamm/contracts/QuantAMMWeightedPoolFactory.sol#L131-L173
When the disableUnbalancedLiquidity flag is enabled, the pool is supposed to prevent any operations that would result in unbalanced token ratios. However, the donate() function can be used to circumvent this protection. The provided proof of concept demonstrates that an attacker can donate tokens in arbitrary ratios, disrupting the pool's balanced state.
The vulnerability manifests in the following sequence:
Pool is deployed with disableUnbalancedLiquidity = true
Initial liquidity is added proportionally
The donate function can then be called with unbalanced token amounts
The pool accepts the donation despite the protection flag being set
The test case shows that when donating only DAI (with 0 USDC), the pool's balance ratios become skewed, contradicting the intended behavior of disableUnbalancedLiquidity.
This vulnerability has several severe implications:
Price manipulation potential through intentionally skewing pool ratios
Arbitrage opportunities that could drain value from legitimate liquidity providers
Undermining of the pool's core protection mechanism
Potential for economic attacks through strategic unbalancing
The severity is high because it bypasses a critical protocol safety mechanism and could lead to direct financial losses for users.
Foundry testing framework
Manual code review
Modify the donate() function in the router to enforce balance checks when disableUnbalancedLiquidity is true:
Implement a proportionality validation function:
Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelyhood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.
Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelyhood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.