Incorrect mintPrice
When maxTokensPerGen
Is Reached
#861
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-L193
Vulnerability details
Impact
In the white paper, it is expected that
**The first starts at 0.005 ETH and each subsequent one rises linearly by 0.0000245 ETH until the final is 0.25 ETH. In total if all are minted then 1,275 ETH is raised in Generation 1. Each generation’s price increment increases by 0.000005.**
.However, the current implementation of the
calculateMintPrice
function does not correctly account for generation increments happening after price calculation, leading to incorrect pricing. This could result in users either facing DoS (Denial of Service) issues or overpaying for minting.Proof of Concept
In the white paper, it is expected that
**The first starts at 0.005 ETH and each subsequent one rises linearly by 0.0000245 ETH until the final is 0.25 ETH. In total if all are minted then 1,275 ETH is raised in Generation 1. Each generation’s price increment increases by 0.000005.**
.The
calculateMintPrice
function calculates the mint price based on the current generation and the number of mints within that generation:However, the function is called before the generation is incremented in the
mintToken
function:In the edge case where
generationMintCounts[currentGeneration]
equalsmaxTokensPerGen
, the generation should increase by1
, and the price should be reset to thestartPrice
. However, thecalculateMintPrice
function calculates the price before this increment, leading to an overestimation of the price.Example Scenario
currentGeneration
= 1 andgenerationMintCounts[currentGeneration] = maxTokensPerGen
= 10000.mintPrice
isstartPrice + generationMintCounts[currentGeneration] * priceIncrement
=0.005 + 10000 * 0.0000245 = 0.25 ETH
.startPrice = 0.005 ETH
.0.005 ETH
(transaction reverts) or overpays significantly if he sends0.25 ETH
.Note: Since this is also used in
mintWithBudget
, this could also lead to thewhile
loop exits earlier than expected.Tools Used
Manual
Recommended Mitigation Steps
To mitigate this issue:
_incrementGeneration
after each mint: update the_mintInternal
function just like_mintNewEntity
to include agenerationMintCounts[gen]
check and update thegeneration
if necessary.Assessed type
Payable
The text was updated successfully, but these errors were encountered: