Open code423n4 opened 3 years ago
WatchPug
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
function intervalPassed() public view override returns (bool) { return block.timestamp >= lastPriceTimestamp + updateInterval; }
lastPriceTimestamp + updateInterval will never overlow.
lastPriceTimestamp + updateInterval
LeveragedPool.sol#executePriceChange()
https://github.com/tracer-protocol/perpetual-pools-contracts/blob/646360b0549962352fe0c3f5b214ff8b5f73ba51/contracts/implementation/LeveragedPool.sol#L175-L204
emit PoolRebalance( int256(newShortBalance) - int256(_shortBalance), int256(newLongBalance) - int256(_longBalance) );
int256(newShortBalance) - int256(_shortBalance) and int256(newLongBalance) - int256(_longBalance) will never underflow.
int256(newShortBalance) - int256(_shortBalance)
int256(newLongBalance) - int256(_longBalance)
Duplicate of https://github.com/code-423n4/2021-10-tracer-findings/issues/34
Although #27 does provide more in-depth examples.
Agree with finding
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.