Skip to content
Smart contracts Audit finding Intermediate

ownerMintUsingTokenId can brick the whole contract

The ownerMintUsingTokenId function lets the owner mint a token with an arbitrary ID, which can collide with a future token ID generated by ownerGetNextTokenId, causing all subsequent mints to revert and bricking the contract. The owner can also mint tokens with plot sizes that are not meant to be for sale.

Lambda Follow

Originally disclosed on Code4rena

Submitted by Lambda

contracts/RuniverseLandMinter.sol#L392

With the function ownerMintUsingTokenId, it is possible for the owner to mint a token with an arbitrary token ID. However, this can brick the whole contract and cause a situation where no more mints / buys are possible. This happens when a token ID is minted with that function that is later on also generated with ownerGetNextTokenId. In that case, the call to runiverseLand.mintTokenId will fail because the function calls _mint internally, which reverts when the token ID was already minted:

function _mint(address to, uint256 tokenId) internal virtual {
        require(to != address(0), "ERC721: mint to the zero address");
        require(!_exists(tokenId), "ERC721: token already minted");
				...
}

Another problem with this function is that the owner can encode an arbitrary plotSize in this tokenId (e.g., also the ones with ID > 4 that are defined in IRuniverseLand, but are not for sale).

Proof Of Concept

Let’s say we have plotsMinted[0] = 101 and plotsMinted[1] = plotsMinted[2] = plotsMinted[3] = plotsMinted[4] = plotGlobalOffset = 0. The owner uses the function to mint the token ID which corresponds to the token encoding [102][102][0] (112150186059264). He might not even be aware of that because it is not immediately visible in the decimal representation that 112150186059264 corresponds to [102][102][0]. This mint increases plotsMinted[0] to 102. When a user now tries to mint for plot size ID 0, the function _mintTokens calls ownerGetNextTokenId(0), which will return [102][102][0] = 112150186059264. This will cause the mint to fail because this ID was already minted.

Recommended Mitigation Steps

Remove the function ownerMintUsingTokenId or implement checks that the provided token ID wil not collide with a future token ID (by decoding it and checking that the provided globalCounter / localCounter are impossible).

Alex the Entreprenerd (judge) commented:

Specific inconsistent state caused by setters, per discussion with other judges I will flag and judge separately.

May end up grouping under admin privilege but will give it a chance vs a more generic report.

msclecram (Forgotten Runiverse) confirmed

Alex the Entreprenerd (judge) commented:

Per similar discussion to #10 and #11, the Warden has shown a way in which the function can cause an inconsistent state, which will cause reverts.

Because the codebase has checks to avoid inconsistent states, but this finding shows a way to sidestep them, I agree with Medium Severity.

msclecram (Forgotten Runiverse) commented:

We updated the code with the next changes:

  • We removed ownerMintUsingTokenId

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


The original report as published on Code4rena, by Lambda. 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 ownerMintUsingTokenId function allows minting arbitrary token IDs without checking that they will not collide with future IDs generated by ownerGetNextTokenId.

What the attacker needed

Owner privileges

The fix

The function ownerMintUsingTokenId was removed in the fix.

How it was found

  1. The owner calls ownerMintUsingTokenId with a token ID that encodes a plot size and counters that will later be generated.
  2. This mint increases the plotsMinted counter for that plot size.
  3. A user later tries to mint a token for that plot size.
  4. The contract calls ownerGetNextTokenId, which returns the same token ID that was already minted.
  5. The mint fails because the token ID already exists, reverting the transaction.

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.

A smart contract has a function that lets the owner create a new token with any ID they choose. If that ID happens to be the same as one the contract will automatically generate later, the contract's minting function will fail because it checks that the ID is not already used. This can stop all future mints, effectively breaking the contract.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by Lambda

View all

64 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.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.