Adding unchecked directive can save gas #27
Labels
bug
Warden finding
duplicate
Another warden found this issue
G (Gas Optimization)
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Handle
WatchPug
Vulnerability details
For the arithmetic operations that will never over/underflow, using the unchecked directive (Solidity v0.8 has default overflow/underflow checks) can save some gas from the unnecessary internal over/underflow checks.
For example:
LeveragedPool.sol#intervalPassed()
https://github.com/tracer-protocol/perpetual-pools-contracts/blob/646360b0549962352fe0c3f5b214ff8b5f73ba51/contracts/implementation/LeveragedPool.sol#L259-L261
lastPriceTimestamp + updateInterval
will never overlow.LeveragedPool.sol#executePriceChange()
https://github.com/tracer-protocol/perpetual-pools-contracts/blob/646360b0549962352fe0c3f5b214ff8b5f73ba51/contracts/implementation/LeveragedPool.sol#L175-L204
int256(newShortBalance) - int256(_shortBalance)
andint256(newLongBalance) - int256(_longBalance)
will never underflow.The text was updated successfully, but these errors were encountered: