Beginner FriendlyFoundryNFT
100 EXP
View results
Submission Details
Severity: low
Invalid

Gas Optimization for isHappyHorse

Summary

I know it is a view function and it does not change the state of the contract but it can be optimized to become more gas-efficient.

Vulnerability Details

The isHappyHorse() function checkes a bool with an if statement and return true/false accordingly instead of directly returning the boolean expression. Also, a <= is used when it can be avoided by using a > instead.

Impact

The code that is going to be deployed is larger, hence the gas payed by the deployer is higher than it should be. And users calling this function will be charged with higher gas fees

Tools Used

Manual review

Recommendations

Replace:
function isHappyHorse(uint256 horseId) external view returns (bool) {
if (horseIdToFedTimeStamp[horseId] <= block.timestamp - HORSE_HAPPY_IF_FED_WITHIN) {
return false;
}
return true;
}
By:
function isHappyHorse(uint256 horseId) external view returns (bool) {
return (horseIdToFedTimeStamp[horseId] > block.timestamp - HORSE_HAPPY_IF_FED_WITHIN)
}

Updates

Lead Judging Commences

inallhonesty Lead Judge over 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.