In the Lender.sol contract,unchecked
can be used to 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 certain number cannot go below or beyond a certain limit, implementing unchecked
is good to reduce gas usage. For instance, you can find the gas usage by my deployment on sepolia network, the as-is deployment consumed about 3,399,220
gas, whereas, when I implemented the unchecked
method for a single function, startAuction()
function. The gas dropped to 3,396,784
which is a difference of 2436 gas
.
Original Contract
Contract with just a single changed instance of the optimization
There are a total of 6 functions using for
loops, namely: borrow()
, repay()
, giveLoan()
, startAuction()
, seizeLoan()
, and refinance()
. Implementing this change for each function will mean saving tx. gas of about:
6 * 2436 = 14616 gas
Considerable save on gas.
Manual audit
Foundry
You can find my implementation on the testnet too. Implementing this simple change as shown below can help serve the impact:
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.