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

Input Parameter Mismatch in `feedHorse` & `isHappyHorse` functions

Summary

The feedHorse and isHappyHorse functions in the HorseStore huff code lack specification of their input parameters in their corresponding macros. This oversight can lead to confusion and errors during code execution, as it may not be clear to developers or auditors what input parameters are expected by these functions.

Vulnerability Details

The vulnerability arises from the discrepancy between the function declarations and their corresponding macro implementations. In the function declarations, both feedHorse and isHappyHorse specify a uint256 input parameter, indicating that they expect a horseId as input. However, in their macro implementations, the input parameters are not explicitly defined, leading to potential issues in understanding and using these macros.

Impact

The impact of this issue is primarily on code clarity and maintainability. Developers and auditors reviewing the code may find it challenging to understand the intended usage of these macros due to the absence of explicit input parameter specifications. This can result in misinterpretation, potential errors during integration, and difficulties in maintaining or modifying the code.

Tools Used

Manual review.

Recommendations

To address this issue, it is recommended to update the macro definitions for FEED_HORSE and IS_HAPPY_HORSE to explicitly mention their input parameters, aligning them with the corresponding function declarations. This ensures clarity in the code and assists developers and auditors in understanding the expected input parameters for these functions.

Update code should look like this:

#define macro FEED_HORSE(horseId) = takes (1) returns (0) {
horseId // [horseId]
timestamp // [horseId, timestamp]
STORE_ELEMENT(0x00) // []
// End execution
0x11 timestamp mod
endFeed jumpi
revert
endFeed:
stop
}
#define macro IS_HAPPY_HORSE(horseId) = takes (1) returns (1) {
horseId // [horseId]
0x04 calldataload // [horseId, horseFedTimestamp]
LOAD_ELEMENT(0x00) // [horseId, horseFedTimestamp]
timestamp // [horseId, horseFedTimestamp, timestamp]
dup2 dup2 // [horseId, horseFedTimestamp, timestamp, horseFedTimestamp]
sub // [horseId, timestamp - horseFedTimestamp, timestamp, horseFedTimestamp]
[HORSE_HAPPY_IF_FED_WITHIN_CONST]// [horseId, HORSE_HAPPY_IF_FED_WITHIN, timestamp - horseFedTimestamp, timestamp, horseFedTimestamp]
lt // [horseId, HORSE_HAPPY_IF_FED_WITHIN < timestamp - horseFedTimestamp, timestamp, horseFedTimestamp]
start_return_true jumpi IS_HAPPY_HORSE // [horseId, timestamp, horseFedTimestamp] if true jump to start_return_true else go to next line
eq // [horseId, timestamp == horseFedTimestamp]
start_return
jump
start_return_true:
0x01 // [horseId, 1]
start_return:
// Store value in memory.
0x00 mstore // [horseId]
// Return value
0x20 0x00 return // [horseId]
}
Updates

Lead Judging Commences

inallhonesty Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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