Incorrect mint price is applied if there is a generation increment #615
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
downgraded by judge
Judge downgraded the risk level of this issue
duplicate-564
edited-by-warden
🤖_03_group
AI based duplicate group recommendation
satisfactory
satisfies C4 submission criteria; eligible for awards
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2024-07-traitforge/blob/279b2887e3d38bc219a05d332cbcb0655b2dc644/contracts/TraitForgeNft/TraitForgeNft.sol#L190
https://github.com/code-423n4/2024-07-traitforge/blob/279b2887e3d38bc219a05d332cbcb0655b2dc644/contracts/TraitForgeNft/TraitForgeNft.sol#L280-L294
https://github.com/code-423n4/2024-07-traitforge/blob/279b2887e3d38bc219a05d332cbcb0655b2dc644/contracts/TraitForgeNft/TraitForgeNft.sol#L350-L352
Vulnerability details
Impact
This is an edge case that happens every time there is a generation increment when minting a token. As we can see in the
mintToken()
function inTraitForgeNft.sol
there is a mint price calculation after which the calculatedmintPrice
is passed to the_mintInternal()
function.In the
_mintInternal()
function we first check if there is a need to increment generation, before minting the token and setting all the storage variables (e.g.,tokenGenerations[newItemId] = currentGeneration;
).The problem arises when it is time to increment generation (
_incrementGeneration()
) where the current generation is incremented by one, generation mint count is set to 0 and price increment is also recalculated, but there is no update tomintPrice
.This means two things:
Proof of Concept
Imagine following scenario:
mintToken
to mint another tokencurrentGeneration
is still 1msg.value
and it is equal to the calculated mint price. All good so far._mintInternal()
function, we see thatgenerationMintCounts[currentGeneration] >= maxTokensPerGen
is satisfied since10_000 >= 10_000
, so we go to_incrementGeneration()
_incrementGeneration()
we docurrentGeneration++
setting it to 2. We reset thegenerationMintCount[currentGeneration]
to 0, and we addpriceIncrementByGen
to the previouspriceIncrement
. The function is done._mintInternal()
continues its execution where we actually mint the token and set following storage variablesmsg.value >= newMintPrice
. This is necessary because we also increasedpriceIncrement
which is part of the mint price calculation.Tools Used
Manual Review, VS Code
Recommended Mitigation Steps
Considering the
calculateMintPrice()
function, the first NFT of the new generation has to be minted (so thatgenerationMintCounts[currentGeneration]
is not 0, which will causepriceIncrement
to be 0 as well).Therefore, after minting a new token and setting all the variables in
_mintInternal()
, recalculate the price again and check if themsg.value
will be enough for the new mint price. It would look like this:Assessed type
Other
The text was updated successfully, but these errors were encountered: