You can use do while
loops instead of for
loops to save gas.
A do while
loop will cost less gas since the condition is not being checked for the first iteration. Also, using do while loop with ++i is more gas efficient and wrapping ++i with unchecked keyword makes the whole iteration the most gas efficient of all. Also, the i is not initialized to 0 and the length of loop is cached.
There are two instances of for loops in the DSCEnginge.sol
contract.
Savings for getAccountCollateralValue()
can be up to 373
gas:
Average | Median | Max | |
---|---|---|---|
Before | 42356 | 42356 | 42356 |
After | 41983 | 41983 | 41983 |
Savings for constructor
can be up to 7381
gas:
Deployment Cost | |
---|---|
Before | 1004332 |
After | 996951 |
Manual Review and gas report via $ forge test --gas-report
For getAccountCollateralValue()
change from:
To:
For constructor
change from:
To:
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.