Incorrect price calculation for first token of each generation due to delayed generation increment #609
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
🤖_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#L181-L200
Vulnerability details
Impact
After incrementing each generation, the
priceIncrement
is incremented bypriceIncrementByGen
in _incrementGeneration. The generation incrementation occurs when minting the first token of the new generation, not when minting the last token of the current generation. This leads to the issue that when minting the first token of each new generation, thepriceIncrementByGen
is not included in the price becausecalculateMintPrice
is called before the generation is incremented:When minting the first token of a new generation, the current generation is incremented after calculating the minting price because the increment occurs inside
_mintInternal
:As a result, the required mint price for the first token of each new generation does not include the
priceIncrementByGen
.Tools Used
Manual Review
Recommended Mitigation Steps
The root cause of this issue is that the generation incrementation occurs when minting the first token of the new generation, rather than when minting the last token of the current generation. A simple fix is to move the generation incrementation check to the end of the mint process. Below is a suggestion for updating the code in
mintToken
and_mintInternal
Assessed type
Context
The text was updated successfully, but these errors were encountered: