TSender

Cyfrin
DeFiFoundry
15,000 USDC
View results
Submission Details
Severity: low
Invalid

it is better to implement the while loop like this.

Summary

Implementing the while loop in this way can consume less gas.

Vulnerability Details

function areListsValid(address[] calldata recipients, uint256[] calldata amounts) external pure returns (bool) {
if (recipients.length == 0) {
return false;
}
if (recipients.length != amounts.length) {
return false;
}
=> for (uint256 i; i < recipients.length; i++) {
if (recipients[i] == address(0)) {
return false;
}
if (amounts[i] == 0) {
return false;
}
=> for (uint256 j = i + 1; j < recipients.length; j++) {
if (recipients[i] == recipients[j]) {
return false;
}
}
}
return true;
}
}

Impact

gas consumption.

Tools Used

Recommendations

like this :

for (uint256 i; i < recipients.length) {
if (recipients[i] == address(0)) {
return false;
}
if (amounts[i] == 0) {
return false;
}
for (uint256 j = i + 1; j < recipients.length) {
if (recipients[i] == recipients[j]) {
return false;
}
unchecked {
++i;
}
}
unchecked {
++i;
}
}
Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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