The Standard

The Standard
DeFiHardhat
20,000 USDC
View results
Submission Details
Severity: low
Invalid

Breaking out of the loop in advance can save a lot of gas costs

Summary

Because in the holders[i] array, each address only appears once. You can use a loop to find the addresses you want to delete. Once found, swap with the last element of the array and then delete the last element. At this time, you can exit the for loop directly, which can save money. A lot of gas.

Vulnerability Details

https://github.com/Cyfrin/2023-12-the-standard/blob/main/contracts/LiquidationPool.sol#L97-L101

function deleteHolder(address _holder) private {
for (uint256 i = 0; i < holders.length; i++) {
if (holders[i] == _holder) {
holders[i] = holders[holders.length - 1];
holders.pop();
}
}
}

Impact

After finding the _holder address, you can jump out of the loop directly. There is no need to judge the subsequent address situation, because the addresses of this array are all unique.

Tools Used

Manual review

Recommendations

function deleteHolder(address _holder) private {
for (uint256 i = 0; i < holders.length; i++) {
if (holders[i] == _holder) {
holders[i] = holders[holders.length - 1];
holders.pop();
break;
}
}
}
Updates

Lead Judging Commences

hrishibhat Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Known issue
Assigned finding tags:

informational/invalid

Support

FAQs

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