Submitted by Shubham, also found by ArsenLupin, ogKapten, zhaojohnson, Tomas0707, aldarion, dontonka, 0x3b (1, 2), eLSeR17, p0wd3r, Agontuk (1, 2), jesjupyter, samuraii77, emerald7017, Ruhum, LSHFGJ, FastChecker, 0xHash, anonymousjoe, TECHFUND-inc, Trident-Audits, hakunamatata, avoloder, Abdessamed, MrValioBg, VulnViper (1, 2, 3), PNS, perseus, shikhar229169, Dots, valy001, inzinko, 0x0bserver, dobrevaleri, Udsen, ABAIKUNANBAEV, eierina, StraawHaat, valentin_s2304, dimah7, gkrastenov, LeFy, dhank, denzi_, King_, rbserver, KupiaSec, Ryonen, 0xJoyBoy03, ZdravkoHr, 4rdiii (1, 2), dimulski, and 0xrex
https://github.com/code-423n4/2024-07-traitforge/blob/main/contracts/TraitForgeNft/TraitForgeNft.sol#L280-L283
https://github.com/code-423n4/2024-07-traitforge/blob/main/contracts/TraitForgeNft/TraitForgeNft.sol#L227-L232
The report covers two bugs:
1st Bug Scenario: Taking generation 1 into consideration, only direct minting can occur. No nft can be minted through forging.
Since generationMintCounts has not reached maxTokensPerGen, the _incrementGeneration() check is skipped. _tokenIds and generationMintCounts is updated to 10000.
Now comes the interesting part.
2nd Bug Scenario:
Suppose we are at the end of generation 2. The generationMintCounts is 10000 and no minting has taken place through forging for generation 2. Meaning that nft count for generation 3 is zero.
If minting happens directly by calling the mintToken(), the same situation is repeated as explained in the scenario above & the user ends up paying the max price of generation 2 to mint the 1st nft of generation 3.
Now, if the generationMintCounts is at 9999 & _mintNewEntity() is called internally through forging, a different scenario takes place.
This scenario would lead to a loss to the protocol and benefit for the user.
Fixing the bugs would require changes in the calculateMintPrice() and _mintInternal(). However, the protocol will not be able to claim the the last calculated price as intended by the whitepaper but it would then align with the number of nfts minted & the price the user pays.
Error
TForge1 (TraitForge) confirmed via duplicate Issue #210
Koolex (judge) decreased severity to Medium
