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

Some gas optimization for seizeLoan() function

Summary

Focusing on the for loop here, for gas optimization.

Vulnerability Details

Using for loop without any max array length limitations/bounds, and not optimized for gas either.

Impact

Revert on running out of gas during for loop iteration if array is too large. DoS of seizeLoan call.

Tools Used

VSC, manual.

Recommendations

function seizeLoan(uint256[] calldata loanIds) public {
    uint256 loanIdsLength = loanIds.length;
    for (uint256 i; i < loanIdsLength; ) {
        //...
        // for loop logic
        //...
        unchecked {i++;}
    }
}

Additionally, same applies to the refinance() function:
https://github.com/Cyfrin/2023-07-beedle/blob/d9718f2ca6521756624c017c90f3d4d4e80da90c/src/Lender.sol#L591

Support

FAQs

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