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

`HorseStore::TOTAL_SUPPLY` is not incremented after mint

Description: The HorseStore::_MINT function does not increase the total_supply after a token has been successfully minted. This would prevent the contract from minting more than one token because the total_supply would always be zero.

Impact: High, the contract should be able to mint as many tokens as needed

Proof of Code:

Code
function test_totalSupplyDoesNotIncrease() public {
uint256 initialSupply = horseStore.totalSupply();
console2.log("initial total supply", initialSupply);
vm.prank(user);
horseStore.mintHorse();
uint256 afterFirstMint = horseStore.totalSupply();
console2.log("total supply after minting first token", afterFirstMint);
assertEq(initialSupply, afterFirstMint);
}

Recommendation:

#define macro _MINT() = takes (2) returns (0) {
// Input stack: // [to, tokenId]
// Output stack: // []
// Check that the recipient is valid
dup1 iszero invalid_recipient jumpi // [to, tokenId]
// Create the minting params
0x00 dup3 // [tokenId, from (0x00), to, tokenId]
// Check token ownership
[OWNER_LOCATION] LOAD_ELEMENT_FROM_KEYS(0x00) // [owner, from (0x00), to, tokenId]
unauthorized jumpi
// Give tokens to the recipient.
TRANSFER_GIVE_TO() // [from (0x00), to, tokenId]
// Emit the transfer event.
__EVENT_HASH(Transfer) // [sig, from (0x00), to, tokenId]
0x00 0x00 log4 // []
// Continue Executing
cont jump
invalid_recipient:
INVALID_RECIPIENT(0x00)
unauthorized:
ALREADY_MINTED(0x00)
cont:
+ [TOTAL_SUPPLY] //[TOTAL_SUPPLY]
+ sload //[total_supply]
+ 0x01 add //[total_supply+1]
+ [TOTAL_SUPPLY] //[TOTAL_SUPPLY,total_supply+1]
+ sstore //[]
}
Updates

Lead Judging Commences

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

honour Submitter
over 1 year ago

Support

FAQs

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