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

[G-01] Unchecking arithmetics operations that can’t underflow/overflow

Summary

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

25 gas saved per instance

Instances:

  • https://github.com/Cyfrin/2023-07-foundry-defi-stablecoin/blob/main/src/DSCEngine.sol#L252

uint256 totalCollateralToRedeem = tokenAmountFromDebtCovered + bonusCollateral;
  • https://github.com/Cyfrin/2023-07-foundry-defi-stablecoin/blob/main/src/DSCEngine.sol#L118

for (uint256 i = 0; i < tokenAddresses.length; i++) {
  • https://github.com/Cyfrin/2023-07-foundry-defi-stablecoin/blob/main/src/DSCEngine.sol#L353

for (uint256 i = 0; i < s_collateralTokens.length; i++) {
  • https://github.com/Cyfrin/2023-07-foundry-defi-stablecoin/blob/main/src/libraries/OracleLib.sol#L29

uint256 secondsSince = block.timestamp - updatedAt;

Support

FAQs

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