20,000 USDC
View results
Submission Details
Severity: gas
Valid

Uncheck Arithmetic where overflow/underflow impossible

Summary

Use unchecked blocks in code parts where overflow or underflow is not possible to save on gas

Vulnerability Details

Impact

Gas savings: Solidity compiler from 0.8.0 upwards does default internal overflow and underflow checks for arithmetic.
This adds more computation to functions increasing gas costs. However its possible to use unchecked blocks in order to avoid these compiler operation checks in order to save on gas

Tools Used

Manual Analysis

Recommendations

  1. Use the format below for all loops to ensure update i is in unchcheked block
    for (uint256 i = 0; ...}
    unchecked { ++i}
    }

  2. Use care and check if balance updates e.g
    unchecked { balances[msg.sender] += _amount;} // only if sure _amount cant ever be too large or balances and e.g impact flash loans, token supply taken into account for specific tokens etc. Could potentially gain more gas savings from these updates as long as there is sureness they do not overflow

  3. unchecked {index = index + _ratio;} // only if sure no possibility so high a _ratio e.g flashloan deposit etc

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.