Closed code423n4 closed 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:
https://github.com/code-423n4/2021-11-vader/blob/429970427b4dc65e37808d7116b9de27e395ce0c/contracts/dex/math/VaderMath.sol#L92-L92
if (originalValue > releasedValue) loss = originalValue - releasedValue;
loss = originalValue - releasedValue will never underflow.
loss = originalValue - releasedValue
https://github.com/code-423n4/2021-11-vader/blob/429970427b4dc65e37808d7116b9de27e395ce0c/contracts/tokens/Vader.sol#L258-L262
uint256 fee = calculateFee(); uint256 tax = (amount * fee) / _MAX_BASIS_POINTS; amount -= tax;
amount -= tax will never underflow.
amount -= tax
Duplicate of #43
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:
https://github.com/code-423n4/2021-11-vader/blob/429970427b4dc65e37808d7116b9de27e395ce0c/contracts/dex/math/VaderMath.sol#L92-L92
loss = originalValue - releasedValue
will never underflow.https://github.com/code-423n4/2021-11-vader/blob/429970427b4dc65e37808d7116b9de27e395ce0c/contracts/tokens/Vader.sol#L258-L262
amount -= tax
will never underflow.