Minus before addition -> underflow risk (But reverted due to solidity 0.8) #172
Labels
bug
Something isn't working
QA (Quality Assurance)
Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
sponsor disputed
Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
Lines of code
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/InflationManager.sol#L574
Vulnerability details
Impact
If currentUInts256[key] > totalKeeperPoolWeight it is clearly reverted due to underflow.
Proof of Concept
Obviously minus currentUInts256[key] before addition pendingUInts256[key]. If currentUInts256[key] > totalKeeperPoolWeight it is clearly reverted due to underflow.
But if you plus before minus, it never get underflow even if currentUInts256[key] > totalKeeperPoolWeight
But still underflow if currentUInts256[key] > totalKeeperPoolWeight + pendingUInts256[key]
Tools Used
Scan code by eye
Recommended Mitigation Steps
pendingUInts256[key] will be added to totalKeeperPoolWeight first, greater value resist underflow error.
The text was updated successfully, but these errors were encountered: