Skip to content
Business logic Audit finding Intermediate

RuniverseLand.sol#mint() can be bricked

The mint() function derives the token ID from numMinted, but mintTokenId() allows arbitrary token IDs, so if a minter mints a token with an ID that collides with a future numMinted value, subsequent mint() calls will fail because the token already exists. This can brick the minting functionality.

Dravee Follow with Lambda and hansfriese

Originally disclosed on Code4rena

Submitted by Dravee, also found by Lambda and hansfriese

contracts/RuniverseLand.sol#L77 contracts/RuniverseLand.sol#L101

The mint() function uses numMinted to generate the tokenId:

File: RuniverseLand.sol
72:     function mint(address recipient, PlotSize size)
73:         public
74:         override
75:         returns (uint256)
76:     {
77:         uint256 tokenId = numMinted;
78:         mintTokenId(recipient, tokenId, size);
79:         return tokenId;
80:     }

This numMinted value corresponds to the totalSupply():

File: RuniverseLand.sol
145:     function totalSupply() public view returns (uint256) {
146:         return numMinted;
147:     }

However, the mintTokenId() function can be called with any tokenId:

File: RuniverseLand.sol
088:     function mintTokenId(
089:         address recipient,
090:         uint256 tokenId,
091:         PlotSize size
092:     ) public override nonReentrant {
093:         require(numMinted < MAX_SUPPLY, "All land has been minted");
094:         require(
095:             _msgSender() == primaryMinter || _msgSender() == secondaryMinter,
096:             "Not a minter"
097:         );
098:         numMinted += 1;
099:         emit LandMinted(recipient, tokenId, size);
100:
101:         _mint(recipient, tokenId);
102:     }

Imagine the following scenario:

  • The contracts just got deployed and numMinted == 0

  • primaryMinter calls mintTokenId() with tokenId == 1

    • Now numMinted == 1
  • secondaryMinter calls mint()

    • In this case, tokenId == numMinted
    • _mint() gets called with tokenId == 1 which already exists, so it fails

Recommended Mitigation Steps

Given that RuniverseLand.sol#mint() isn’t called in RuniverseLandMinter, I feel like it should simply be deleted. primaryMinter or secondaryMinter can simply call mintTokenId() directly.

Alex the Entreprenerd (judge) commented:

Valid concern based on external requirements + the fact that arbitrary data can be inputted.

msclecram (Forgotten Runiverse) confirmed

Alex the Entreprenerd (judge) commented:

The warden has shown an inconsistency in using mint and mintTokenId which can cause the bricking of the minting functionality.

Because this is an undesirable scenario which can happen via ordinary operations, I agree with Medium Severity.

msclecram (Forgotten Runiverse) commented:

We updated the code with the next changes:

  • We removed mint method from interface and contract

https://github.com/bisonic-official/plot-contract/commit/ea8abd7faffde4218232e22ba5d8402e37d96878


The original report as published on Code4rena, by Dravee. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The mint() function assumes token IDs are sequential and equal to numMinted, but mintTokenId() permits arbitrary token IDs, so a token can be created with an ID that collides with a future numMinted value.

Impact

The mint() function can be bricked, preventing further mints through that function, though mintTokenId() remains available.

What the attacker needed

PrimaryMinter or secondaryMinter role; mintTokenId() called with a tokenId that collides with…

The fix

The mint() function was removed from the interface and contract, as confirmed by the project.

How it was found

  1. Deploy contracts with numMinted == 0
  2. primaryMinter calls mintTokenId() with tokenId == 1, making numMinted == 1
  3. secondaryMinter calls mint(), which uses tokenId == numMinted (1)
  4. _mint() fails because tokenId 1 already exists

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

This is a smart contract bug where two ways of creating tokens can clash. One function always uses the next number in line, but another lets you pick any number. If someone picks a number that the first function will later try to use, that later attempt fails because the token already exists, stopping further mints through that function.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by Dravee

View all

9 more disclosed reports, best first.

More from Forgotten Runiverse - Versus contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.