The QuantAMMGradientBasedRule contract is vulnerable to gradient explosion when using small lambda values (e.g., 1e12), causing gradients to reach extreme values (~3.8e26) that violate system constraints. This vulnerability could lead to extreme weight changes and potential economic exploitation.
Location: pkg/pool-quantamm/contracts/rules/base/QuantammGradientBasedRule.sol
The issue occurs in the gradient calculation when using small lambda values. The contract's mathematical formula amplifies small changes when lambda is close to zero, leading to extremely large gradients.
Test Setup:
Exploit Conditions:
Lambda value: 1e12 (0.000001)
Initial price: 8.729e20
New price: 4.364e20 (50% drop)
Result:
Attacker identifies pool with small lambda value
Waits for significant price movement
Triggers gradient calculation
Pool receives extreme gradient values
Weight changes become extreme
Attacker exploits resulting price discrepancies
Severity: HIGH
Technical Impact:
Gradient values reach ~3.8e26
Violates system constraints (>1e24)
Causes extreme weight adjustments
May break pool rebalancing logic
Affects all pools using small lambda values
Economic Impact:
Potential for manipulated weight changes
Could be exploited through arbitrage
May affect connected pools
Risk of economic losses for LPs
System instability during price volatility
Foundry fuzzing tests
Manual code review
Mathematical analysis of gradient formula
Custom test suite for lambda boundary conditions
The issue stems from this calculation in QuantAMMGradientBasedRule.sol:
When lambda is very small (e.g., 1e12):
oneMinusLambda ≈ 1e18
pow(THREE) ≈ 1e18
Division by small lambda (1e12) creates huge multiplier
Results in gradient values > 1e24
Implement Lambda Value Bounds:
Add Gradient Magnitude Checks:
Implement safe bounds for gradient values
Add circuit breakers for extreme gradients
Consider gradual adjustment mechanism
Monitor and limit rate of change
System-Wide Safeguards:
Document safe lambda ranges
Add monitoring for gradient magnitudes
Implement emergency stops for extreme values
Consider adaptive lambda adjustment
While the README mentions "theoretical limitations that are unguarded", this issue:
Creates valid but extreme values (not overflow/underflow)
Doesn't trigger reverts
Silently breaks system constraints
Has direct economic implications
Requires specific parameter bounds
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.