Unnecessary checked arithmetic when no overflow/underflow possible (2) #77
Labels
bug
Something isn't working
duplicate
This issue or pull request already exists
G (Gas Optimization)
Handle
Dravee
Vulnerability details
Impact
Increased gas cost.
Proof of Concept
Solidity version 0.8+ comes with implicit overflow and underflow checks on unsigned integers.
When an overflow or an underflow isn't possible (as an example, when a comparison is made before the arithmetic operation), some gas can be saved by using an
unchecked
block.https://docs.soliditylang.org/en/v0.8.10/control-structures.html#checked-or-unchecked-arithmetic
Let's look at these lines:
Here, in
MintMath.getLiquidity:L54
:liquidityOut
is set to a value <=liquidityTotal
. ThereforeliquidityTotal - liquidityOut
cannot underflow.Tools Used
VS Code
Recommended Mitigation Steps
Uncheck arithmetic operations when possible.
The text was updated successfully, but these errors were encountered: