In the DSCEngine.sol contract, unchecked can reduce a significant amount of gas by adding the increment of counter i in a for loop under an unchecked section.
In cases when we know that a particular variable cannot go below or beyond a specific numerical limit, implementing unchecked is good for reducing gas usage. For instance, you can find the gas usage by my deployment on Sepolia network, the as-is deployment consumed about 1,138,542 gas, whereas, when I implemented the unchecked method for 2 for loops, the gas dropped to 1,130,555 which is a difference of 7987 gas.
Original Contract
Contract with unchecked for loop
Considerable save on gas.
Manual audit
Foundry
Implementing this simple change as shown below can help serve the impact:
Line 130 under constructor:
The same can be done in the for loop on Line 432under thegetAccountCollateralValue()` function:
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.