Reproduced Exploit

TraitForge: onlyOwner on initializeAlphaIndices bricks mint, budget mint, and forge

initializeAlphaIndices is whenNotPaused onlyOwner. TraitForgeNft._incrementGeneration is what calls it, after generationMintCounts reaches maxTokensPerGen. The NFT contract is allowedCaller, not the owner. With the cap set to 1, the first mintToken, mintWithBudget, and forge each hit the cap, call…

Jul 2024•Other•access-control•3 min read

Loss

mintToken, mintWithBudget, and forge all revert. No NFT is issued once a generation fills

Chain

Other

Category

access-control

Date

Jul 2024

Source

AuditVault

EVM Playground

Source-level debugger — step opcodes and Solidity in sync

evm-hack-analyzer

The attack is replayed in an in-browser EVM preloaded with the exact dumped fork state. The execution tree shows every call; step by Solidity line or by opcode across all depths — source, Stack, Memory, Storage, Balances (native / ERC-20 / NFT), Transient storage and Return value stay in sync. Click a tree node, opcode, or source line to jump. Query opens a search over the trace: previous and next writes, balance changes and calls, breakpoints, and a diff of everything that changed between two steps. No backend, no live RPC.

Loading fork state…

Source & credit. Reproduction of a public audit finding curated by AuditVault — the original finding: 37920-h-06-minttoken-mintwithbudget-and-forge-in-the-traitforgenft. Standalone Foundry PoC and full write-up: 37920-h-06-minttoken-mintwithbudget-and-forge-in-the-traitforgenft_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/access-control/broken-logic

Key info#

FieldValue
LossmintToken, mintWithBudget, and forge all revert. No NFT is issued once a generation fills
Vulnerable contractEntropyGenerator.initializeAlphaIndices
Attacker EOA0x1111111111111111111111111111111111111111
Attack contractExploit
Attack txExploit.run()
Chain / block / dateLocal synthetic · 2024-07
Compilersolc 0.8.27, cancun, via IR
Bug classThe NFT contract calls a function gated by onlyOwner

TL;DR#

initializeAlphaIndices is whenNotPaused onlyOwner. TraitForgeNft._incrementGeneration is what calls it, after generationMintCounts reaches maxTokensPerGen. The NFT contract is allowedCaller, not the owner. With the cap set to 1, the first mintToken, mintWithBudget, and forge each hit the cap, call the entropy contract, and revert on onlyOwner. No generation advances and initialized stays false. Replacing the modifier with onlyAllowedCaller lets the same mint open generation 2.

The vulnerable code#

SOLIDITY
modifier onlyOwner() {
    require(msg.sender == owner, "onlyOwner"); // @> VULN
    _;
}

function initializeAlphaIndices() public whenNotPaused onlyOwner {
    initialized = true;
}
SOLIDITY
entropyGenerator.initializeAlphaIndices();

The recommended change is onlyAllowedCaller. The control sets that path and tryMint returns true, fixedInitialized is true, and currentGeneration is 2.

Root cause#

The function was given the owner's modifier instead of the modifier that names the NFT contract. Every mint path that rolls a generation depends on that call succeeding.

Preconditions#

  • allowedCaller is the NFT contract. owner is a different address.
  • maxTokensPerGen is reached by the mint being attempted. The audited code uses a large cap; this run sets it to 1 so the roll happens on the first mint. The revert is the same one the report describes.

Attack walkthrough#

  1. tryMint calls mintToken. The generation count becomes 1, which is the cap, so _incrementGeneration runs.
  2. The NFT calls initializeAlphaIndices. whenNotPaused passes. onlyOwner sees the NFT as msg.sender and reverts.
  3. The mint rolls back. tryMintWithBudget and tryForge do the same thing.
  4. failedMints is 3. Generation is still 1. No index was initialized.

Diagrams#

flowchart TD A["mintToken or forge reaches maxTokensPerGen"] --> B["_incrementGeneration calls initializeAlphaIndices"] B --> C["onlyOwner rejects the NFT contract"] C --> D["The mint reverts and the generation does not advance"] D --> E["mintWithBudget and forge fail the same way"]

Impact#

Users cannot mint, mint against a budget, or forge once a generation is full. With a cap of 1 that is immediate: all three entry points revert and the collection cannot issue the next token. This is a liveness break of the core issuance functions, not a token profit, so the Playground profit is 0.

How to reproduce#

BASH
cd 37920-h-06-minttoken-mintwithbudget-and-forge-in-the-traitforgenft_exp
forge test -vv

Sources#


Sources & further analysis#

Reproductions & code

Alerts & third-party analyses

  • Web3Sec X hacked database: search.
  • Rekt leaderboard: search.
  • Solodit incident search: search.

These dashboards index community alerts tweets, post-mortems, and independent write-ups. Reach them through the protocol name above to cross-check this reproduction against other analyses.