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

Horses can be fed without existing

Description

There is no check if a horse exists before feeding it.

function feedHorse(uint256 horseId) external {
@>
horseIdToFedTimeStamp[horseId] = block.timestamp;
}

The same case exists in HorseStore.huff.

Impact

A user feeding a non-existing horse won't trigger a revert and can lead to confusion.
Unexpected logic for the protocol.

Proof of Concept

Foundry PoC
function testFeedNonCreatedHorseIsNotHappy() public {
skip(2 days);
uint nonCreatedHorseID = 100;
// will work even if nobody minted this horse!
horseStore.feedHorse(nonCreatedHorseID);
// will fail because, in addition, the non-existing horse is considered happy
assertEq(horseStore.isHappyHorse(nonCreatedHorseID), false);
}

Recommended Mitigation

Add a check in both contracts to ensure that a horse exists before feeding it. A simple check is to call ownerOf with the tokenId; this function will revert if the token is not minted.

Updates

Lead Judging Commences

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

Nonexistent horses can be fed

Support

FAQs

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