# Number of entities in generation can surpass the 10k number

incrementGeneration resets genMintCount to 0, so entities forged into the next generation before the first mint of that generation are uncounted, letting the 10k per-generation cap be surpassed.

- Payout: Audit contest
- Severity: high
- Program: TraitForge
- Found by: hakunamatata
- Disclosed: 2024-09-13
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-07-traitforge-findings/issues/219
- Library page: https://bugbountylibrary.com/r/c4%3A2024-07-traitforge%3AH-04
- Tags: area:web3 domain:web3 impact:integrity kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** TraitForgeNft / EntityForging Solidity contracts
**Root cause:** incrementGeneration sets generationMintCounts[newGen] = 0, wiping counts of entities already forged into the new generation before the first mint of that generation.
**Steps:**
1. Mint tokens up to token 10,000 (end of generation 1).
2. Forge token 1 with token 2 via `entityForging.forgeWithListed(1, 2)` producing token 10,001 in generation 2; `generationMintCounts(2)` becomes 1.
3. Call `nft.mintToken([], {value: 1 ether})` which triggers incrementGeneration and resets `generationMintCounts(2)` to 0.
4. Observe `generationMintCounts(2)` still 1 after mint, and token 10,002 is generation 2 — the forged entity was not counted, so the 10k cap per generation is exceeded.
**How found:** Code reading of incrementGeneration revealed it zeroes genMintCount for the new generation, and the auditor hypothesized that entities forged into that generation before the first mint would be erased from the count, then confirmed with a Hardhat PoC.
**Exploitation:** Attacker forges entities into the upcoming generation before the first mint of that generation; the subsequent mint resets the counter, so forged entities are not counted toward the 10k cap, allowing more than 10k entities per generation and breaking the protocol's core supply invariant.
**Insight:** When a counter is reset on generation/epoch rollover, check whether any state (e.g. forged/minted items) can be written into the new epoch before the reset fires — the reset then silently drops those entries.

