Using the unchecked keyword to avoid redundant arithmetic underflow/overflow checks to save gas when an underflow/overflow cannot happen. E.g. 'unchecked' can be applied in the following lines of code since there are require statements before to ensure the arithmetic operations would not cause an integer underflow or overflow:
require(underlyingDecimals <= 18, "underlying decimals must be <= 18");
exchangeRateToBackingPrecision = 10**(18 - underlyingDecimals);
or
if (sharesUsed[0] < mintedShares) {
ammTokens[0].safeTransfer(msg.sender, mintedShares - sharesUsed[0]);
}
if (sharesUsed[1] < mintedShares) {
ammTokens[1].safeTransfer(msg.sender, mintedShares - sharesUsed[1]);
}
Recommended Mitigation Steps
Consider if you want to apply this keyword and then carefully select where it is safe to do this.
Handle
pauliax
Vulnerability details
Impact
Using the unchecked keyword to avoid redundant arithmetic underflow/overflow checks to save gas when an underflow/overflow cannot happen. E.g. 'unchecked' can be applied in the following lines of code since there are require statements before to ensure the arithmetic operations would not cause an integer underflow or overflow:
require(underlyingDecimals <= 18, "underlying decimals must be <= 18"); exchangeRateToBackingPrecision = 10**(18 - underlyingDecimals);
or if (sharesUsed[0] < mintedShares) { ammTokens[0].safeTransfer(msg.sender, mintedShares - sharesUsed[0]); } if (sharesUsed[1] < mintedShares) { ammTokens[1].safeTransfer(msg.sender, mintedShares - sharesUsed[1]); }
Recommended Mitigation Steps
Consider if you want to apply this keyword and then carefully select where it is safe to do this.