Beginner FriendlyFoundryNFT
100 EXP
View results
Submission Details
Severity: medium
Valid

`horseIdToFedTimeStamp` is a mapping and the slot/Id are incorrectly hashed to recover the value of the mapping

Summary

All 3 functions, GET_HORSE_FED_TIMESTAMP,FEED_HORSE and IS_HAPPY_HORSE only hash the horseId variable when trying to load the value of the mapping horseIdToFedTimeStamp. This will result in loading another value from storage rather than the mapping.

Vulnerability Details

These three functions attempt to read the mapping horseIdToFedTimeStamp but fail to hash the correct values to recover it's correct slot.

0x04 calldataload // [horseId] @audit Should also add the storage slot of the mapping horseIdToFedTimeStamp
GET_SLOT_FROM_KEY(0x00) // [horseFedTimestamp] @audit should use this function GET_SLOT_FROM_KEYS to hash both mapping slot and ID
0x04 calldataload // [horseId, timestamp]
STORE_ELEMENT(0x00) // [] //@audit same problem as above
0x04 calldataload // [horseId]
LOAD_ELEMENT(0x00) // [horseFedTimestamp] // @audit same here

Impact

This will cause issues as the values that will be loaded/modified would be from another slot in storage.
A main property of the contract will thus be completely wrong and exposed, as the state of happiness of the horse might always be true or false.

Tools Used

Manual review

Recommendations

Need to load both the mapping location and horseId before hashing both.

#define constant HORSEIDTOTIMESTAMP_LOCATION= add correct slot here

0x24 calldataload [horseId]
0x04 calldataload [HORSEIDTOTIMESTAMP_LOCATION,horseId]
GET_SLOT_FROM_KEYS(0x00)
0x24 calldataload [horseId]
0x04 calldataload [HORSEIDTOTIMESTAMP_LOCATION,horseId]
STORE_ELEMENT_FROM_KEYS(0x00)
0x24 calldataload [horseId]
0x04 calldataload [HORSEIDTOTIMESTAMP_LOCATION,horseId]
LOAD_ELEMENT_FROM_KEYS(0x00)
Updates

Lead Judging Commences

inallhonesty Lead Judge over 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

horseIdToFedTimeStamp mapping is not properly implemented in Huff

Support

FAQs

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