Trick or Treat

First Flight #27
Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: low
Invalid

Gas Inefficiency in treatNames[] Retrieval

Summary

The getTreats() function returns the entire treatNames[] array, which can become inefficient as the array grows in size.

Vulnerability Details

  • Function: getTreats()

  • Code Reference:

function getTreats() public view returns (string[] memory) {
return treatNames;
}

As the number of treats grows, retrieving the entire array in a single call will increase gas usage significantly, making it impractical for users.

Impact

As the list of treats grows, gas costs for this function could become prohibitive, affecting the usability of the contract.

Tools Used

Manual Code Review

Recommendations

Implement pagination for retrieving treat names:

function getTreats(uint256 start, uint256 limit) public view returns (string[] memory) {
uint256 end = start + limit > treatNames.length ? treatNames.length : start + limit;
string[] memory treats = new string[]();
for (uint256 i = start; i < end; i++) {
treats[i - start] = treatNames[i];
}
return treats;
}
Updates

Appeal created

bube Lead Judge 8 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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