The QuantAMMMathGuard contract's weight normalization process can result in negative weights under certain conditions, violating a core invariant that pool weights must always be positive and above the minimum weight threshold.
Location: pkg/pool-quantamm/contracts/rules/base/QuantAMMMathGuard.sol
The issue occurs during weight normalization when:
Initial weights are highly uneven (e.g., 80%/19%/1%)
Target weights request extreme changes
The normalization process attempts to maintain the sum-to-one invariant
This can result in negative weights while still maintaining the total weight at 100%, as demonstrated by the following test:
Proof of Concept:
The test reveals that under specific conditions:
Initial weights: [0.828e18, 0.268e18, -0.096e18]
Target weights: [0.01e18, 0.01e18, 0.98e18]
Results in weight: -7.907e15 (negative)
While maintaining sum = 1e18
Severity: HIGH
Technical Impact:
Negative weights break core pool mathematics
Invalidates pricing calculations
Violates fundamental pool invariants
Economic Impact:
Potential economic exploits through arbitrage
Invalid pool state could lead to loss of funds
System-wide failures when interacting with affected pools
Foundry fuzzing tests
Manual code review
Mathematical analysis of weight normalization
Add explicit non-negative validation:
Implement safe normalization:
Add checks before weight adjustments
Ensure intermediate calculations cannot result in negative values
Consider using a different normalization algorithm that preserves non-negativity
Consider architectural changes:
Use unsigned integers (uint256) for weights
Implement a two-step normalization process that first ensures non-negativity
Add invariant checks at key points in the weight update process
_clampWeights will check that these weights are positive and in the boundaries before writing them in storage.
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.