Overflow is desired when adding/subtracting cumulative prices #148
Labels
bug
Something isn't working
duplicate
This issue or pull request already exists
edited-by-warden
QA (Quality Assurance)
Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
Lines of code
https://github.com/code-423n4/2022-09-canto/blob/6f98ffa7ec55c2ca03aa4cd2301503487f0c412d/src/Swap/BaseV1-core.sol#L141-L143
https://github.com/code-423n4/2022-09-canto/blob/6f98ffa7ec55c2ca03aa4cd2301503487f0c412d/src/Swap/BaseV1-core.sol#L166-L168
Vulnerability details
Impact
Contract will revert when cumulative prices reach
type(uint256).max
PoC
Cumulative prices are designed to work with overflows/underflows because the difference is computed to calculate TWAP so this behavior is desired.
Please see
Notes on overflow
from Uniswap V2.https://docs.uniswap.org/protocol/V2/guides/smart-contract-integration/building-an-oracle
Addition of the variables
reserve0CumulativeLast
,reserve1CumulativeLast
andtotalSupplyCumulativeLast
need to be put in a unchecked block otherwise the contract will revert when some of them reach the maximum.Finally, timestamps can also be put in unchecked box just to save gas, though it is imposible for your case as you use
uint256
. (Uniswap usesuint32
)Recommended
If I am not wrong, you can uncheck all these functions completely
_update
currentCumulativePrice
current
(Except for line 177 maybe)sample
reserves
sampleReserves
sampleSupply
The text was updated successfully, but these errors were encountered: