Location: contracts/libraries/Statistics.sol
Problem: The line sum += diff * diff
may overflow if diff
is large, especially for high values of data[i]
. Since diff
is squared, this can easily exceed the uint256
limit.
Recommendation: Use Solidity’s overflow checks (built-in for Solidity >=0.8) or break up calculations into smaller components if working with large values. Alternatively, consider scaling down the values before squaring to reduce the risk of overflow.
Tools used: Github and VSC.
POC :
Expected Outcome: If overflow occurs, variance
will produce an incorrect result or revert (in Solidity >=0.8.0 due to automatic checks). This shows that the function does not handle large values robustly.
Impact: Overflow can result in incorrect calculations, which could propagate incorrect data to other parts of the contract, potentially impacting financial calculations or data integrity.
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.