In contracts/libraries/math/TimeWeightedAverage.sol, the function updateValue uses unchecked for updates but does not verify whether self.weightedSum will overflow. This could lead to serious issues if the value exceeds the maximum limit of uint256.
In TimeWeightedAverage.sol#L134, the function updateValue computes a timeWeightedValue and adds it to self.weightedSum. However, the code does not check whether this addition causes an overflow.
When self.weightedSum is updated, it does not verify whether the sum exceeds uint256's maximum value, which could lead to an overflow.
If an overflow occurs, it can lead to unintended behavior, incorrect TWAP calculations, and potentially cause loss of funds or incorrect trading decisions in protocols relying on this function.
Manual code review
Before adding timeWeightedValue to self.weightedSum, a check should be added to prevent overflow:
The corrected function:
This ensures that the update does not cause an overflow, improving the function's safety and reliability.
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.