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

`HorseStore.huff::TOTAL_SUPPLY` never increases, breaking the protocol.

Description

The HorseStore.huff::TOTAL_SUPPLY forgets to increase after the execution of the _MINT macro. Since the total supply is managed by the user (without utilizing a library like ERC721Enumeration), the contract needs to autonomously increment the value.

#define macro MINT_HORSE() = takes (0) returns (0) {
[TOTAL_SUPPLY] // [TOTAL_SUPPLY]
sload // added in another finding to actually use the real value for _MINT
caller // [msg.sender, totalSupply]
@> _MINT() // []
@>
stop // []
}

Impact

The consequence is the impossibility to mint more than one horse.

Proof of Concept

Foundry PoC
function testTotalSupplyDontIncrease() public {
uint id = horseStore.totalSupply();
vm.startPrank(user);
horseStore.mintHorse();
// will fail because totalSupply() returns 0
assertEq(horseStore.totalSupply(), id+1);
vm.stopPrank();
}

Recommended Mitigation

To resolve this issue, increment the totalSupply after _MINT. Here is a suggested example:

#define macro MINT_HORSE() = takes (0) returns (0) {
[TOTAL_SUPPLY] // [TOTAL_SUPPLY]
sload // added in another finding to actually use the real value for _MINT
caller // [msg.sender, totalSupply]
_MINT() // []
+ [TOTAL_SUPPLY] // [TOTAL_SUPPLY]
+ sload // [totalSupply]
+ 0x01 add // [totalSupply+1]
+ [TOTAL_SUPPLY] // [TOTAL_SUPPLY, totalSupply]
+ sstore
stop // []
}
Updates

Lead Judging Commences

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

Failure to increment total supply on mint

Failure to properly load the totalSupply in Huff

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

Failure to increment total supply on mint

Failure to properly load the totalSupply in Huff

Support

FAQs

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