The QuantAMMMathGuard::_clampWeights function contains wrong calculation for weights using the proportionalRemainder.
The following are the errors in calculation the weights :-
proportionalRemainder can be greater than 1, which causes the weights to exceed the absoluteMax value again.
proportionalRemainder is calculated from dividing sumRemainerWeightby sumOtherWeights.if [ sumRemainerWeight > sumOtherWeights] which have a high chances will make ( proportionalRemainder> 1 ).
In further calculation the weights are multiplied by proportionalRemainder, if weights are equal to absoluteMax or near that value than they will become more than the absoluteMax.
2 . The same issue can occur with absoluteMin, where weights near the absoluteMin value can fall below it if proportionalRemainder is very small.
This will cause the weights to take values outside the permitted range, either exceeding absoluteMax or falling below absoluteMin.
The incorrect calculation will cause the weights either exceeding absoluteMax or falling below absoluteMin.
Manual review
The following can be done to mitigate this issue or as needed :-
Add a check for weights after the calculation that they are in permitted range.
multiply the proportionalRemainder only to that wights which is not near absoluteMaxand absoluteMin, or which will not get out of the range after calculation.
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.
According the sponsor and my understanding, sum of weights does not have to be exactly 1 to work fine. So no real impact here. Please provide a PoC showing a realistic impact if you disagree. This PoC cannot contains negative weights because they will be guarded per clampWeights.
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.
According the sponsor and my understanding, sum of weights does not have to be exactly 1 to work fine. So no real impact here. Please provide a PoC showing a realistic impact if you disagree. This PoC cannot contains negative weights because they will be guarded per clampWeights.
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.