The _getNormalizedWeights function and its helper function calculateBlockNormalisedWeight may propagate invalid negative weights due to insufficient validation at critical stages, including weight initialization, unpacking, and adjustment. While weights are expected to be positive and represent proportions of liquidity, improper handling of arithmetic operations, multipliers, or external inputs could lead to negative weights, disrupting pool functionality and downstream calculations.
_getNormalizedWeights
Role: Computes normalized weights for the pool.
Issue: Unpacks weights and multipliers using quantAMMUnpack32, but lacks validation to ensure weights are non-negative.
calculateBlockNormalisedWeight
Role: Dynamically adjusts weights based on multipliers and elapsed time.
Issue: Converts signed weight to unsigned without validation, allowing negative weights to propagate as large positive values due to bitwise casting.
Unpacking Functions (quantAMMUnpack32 and Variants)
Role: Extract weights and multipliers from packed storage formats.
Issue: Assumes weights are valid, but if initialization or storage corruption introduces negative values, these propagate without validation.
Unvalidated Inputs:
Weights unpacked from _normalizedFirstFourWeights and _normalizedSecondFourWeights may be negative if improperly initialized or corrupted.
Arithmetic Issues:
Multipliers applied to weights can reduce positive weights below zero, particularly over long time intervals (timeSinceLastUpdate).
Signed-to-Unsigned Casting:
Negative weights cast to uint256 in calculateBlockNormalisedWeight result in underflow, producing large positive values.
Logical Errors:
Negative weights violate the core assumption that weights represent proportions and should always be non-negative.
Disruption of Pool Calculations:
Invalid weights could destabilize token balances, disrupt swaps, or cause incorrect rebalancing.
Protocol Integrity:
Propagation of invalid weights through external functions could lead to user losses, reputational damage, and diminished trust in the protocol.
Manual Code Review
Validate unpacked weights and multipliers to ensure they are non-negative before further computations in _getNormalizedWeights:
Ensure the weight parameter is non-negative before casting to uint256:
_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.