Use unchecked blocks in code parts where overflow or underflow is not possible to save on gas
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
Manual Analysis
DSCEngine.sol line 118 the ++i in for loop can be placed in an unchecked
for (uint256 i = 0; i < tokenAddresses.length;) {
s_priceFeeds[tokenAddresses[i]] = priceFeedAddresses[i];
s_collateralTokens.push(tokenAddresses[i]);
unchecked { ++i}
}
DSCEngine.sol line 155 can be rewritten as
unchecked {s_collateralDeposited[msg.sender][tokenCollateralAddress] += amountCollateral;}
Even if a flashloand where used there would be no such liquidity to get to large number 1157920892373161954235709850086879078532699846656405640394575 needed to overflow uint256
DSCEnginel.sol line 198 can be rewritten as
unchecked {s_DSCMinted[msg.sender] += amountDscToMint;}
Even if a flashloan where used there would be no such liquidity to get to large number 1157920892373161954235709850086879078532699846656405640394575 needed to overflow uint256
DSCEnginel.sol line 252 can be rewritten as
unchecked {uint256 totalCollateralToRedeem = tokenAmountFromDebtCovered + bonusCollateral;}
Even if a flashloan where used there would be no such liquidity to get to large number 1157920892373161954235709850086879078532699846656405640394575 needed to overflow uint256
DSCEngine.sol line 353 the ++i in for loop can be placed in an unchecked
for (uint256 i = 0; i < s_collateralTokens.length; i++) {
address token = s_collateralTokens[i];
uint256 amount = s_collateralDeposited[user][token];
totalCollateralValueInUsd += getUsdValue(token, amount);
unchecked {
++i;
totalCollateralValueInUsd += getUsdValue(token, amount);
}
}
Again adding 1 for ++i cant reach max size uint256 in addition to the adding USD value
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.