The QuantAMMGradientBasedRule contract contains multiple instances of unchecked arithmetic operations and unsafe loop increments that could lead to overflows, underflows, and potential division by zero errors. These issues could result in incorrect gradient calculations and potentially compromise the pool's weight updates.
The vulnerabilities are present in several critical areas of the contract:
https://github.com/Cyfrin/2024-12-quantamm/blob/a775db4273eb36e7b4536c5b60207c9f17541b92/pkg/pool-quantamm/contracts/rules/base/QuantammGradientBasedRule.sol#L71-L101
Unchecked Loop Increments:
Unsafe Power and Division Operations:
https://github.com/Cyfrin/2024-12-quantamm/blob/a775db4273eb36e7b4536c5b60207c9f17541b92/pkg/pool-quantamm/contracts/rules/base/QuantammGradientBasedRule.sol#L61
Unchecked Arithmetic in Gradient Calculations:
https://github.com/Cyfrin/2024-12-quantamm/blob/a775db4273eb36e7b4536c5b60207c9f17541b92/pkg/pool-quantamm/contracts/rules/base/QuantammGradientBasedRule.sol#L73-L75
Unchecked Array Access:
https://github.com/Cyfrin/2024-12-quantamm/blob/a775db4273eb36e7b4536c5b60207c9f17541b92/pkg/pool-quantamm/contracts/rules/base/QuantammGradientBasedRule.sol#L92-L95
The vulnerabilities could lead to:
Silent overflows/underflows in weight calculations
Incorrect gradient computations due to arithmetic errors
Potential division by zero errors
Array access out of bounds
Accumulation of computational errors in loop iterations
Potential manipulation of pool weights through carefully crafted inputs
Severity: High, as these issues could affect the core functionality of the pool's weight calculations and potentially lead to financial losses.
Manual code review
Add Input Validation:
Implement Safe Arithmetic:
Add Bounds Checking:
Implement Value Range Validation:
Consider Using SafeMath:
For critical calculations, consider using SafeMath library even with Solidity 0.8+ to ensure explicit checks
Add explicit overflow checks for important arithmetic operations
Add Circuit Breakers:
Implement maximum and minimum thresholds for gradient values
Add emergency stops if calculations exceed safe bounds
Improve Documentation:
Document expected value ranges for all parameters
Add explicit warnings about potential numerical limitations
Document assumptions about input values and their relationships
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.