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

Increments can be unchecked

Summary

In Solidity 0.8+, there’s a default overflow check on unsigned integers. It’s possible to uncheck this in for-loops and save some gas at each iteration, but at the cost of some code readability, as this uncheck cannot be made inline.

Vulnerability Details

https://github.com/Cyfrin/2023-07-beedle/blob/main/src/Lender.sol

Instances included:

Lender.borrow() #232 for (uint256 i = 0; i < borrows.length; i++) {
Lender.repay() #292 for (uint256 i = 0; i < loanIds.length; i++) {
Lender.giveLoan() #355 for (uint256 i = 0; i < loanIds.length; i++) {
Lender.startAuction() #437 for (uint256 i = 0; i < loanIds.length; i++) {
Lender.seizeLoan() #548 for (uint256 i = 0; i < loanIds.length; i++) {
Lender.refinance() #591 for (uint256 i = 0; i < refinances.length; i++) {

Tools Used

Manual

Recommendations

The code would go from:

for (uint256 i = 0; i < [].length; i++) {
// ...
}

to

for (uint256 i = 0; i < [].length;) {
// ...
unchecked { i++; }
}

Support

FAQs

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