Skip to content
Business logic Audit finding Intermediate

setPlotsAvailablePerSize does not work correctly

The setPlotsAvailablePerSize function allows the owner to change plot availability per size without checking that the new values are at least the number already minted or that their sum does not exceed the maximum supply. This can cause an underflow in getAvailableLands or prevent some plot sizes from being minted, leading to financial loss.

Lambda Follow

Originally disclosed on Code4rena

Submitted by Lambda

contracts/RuniverseLandMinter.sol#L513

The function setPlotsAvailablePerSize can be used for two things:

  1. Decreasing the number of plots that is available for a certain size
  2. Increase the number of plots that is available for a certain size

However, in both cases it can introduce errors that can brick parts of the contract. In case 1 where the number of plots is decreased, it is possible that the new number is smaller than plotsMinted for a specific ID. This will cause an underflow in getAvailableLands, which subtracts these values:

        plotsAvailableBySize[0] = plotsAvailablePerSize[0] - plotsMinted[0];
        plotsAvailableBySize[1] = plotsAvailablePerSize[1] - plotsMinted[1];
        plotsAvailableBySize[2] = plotsAvailablePerSize[2] - plotsMinted[2];
        plotsAvailableBySize[3] = plotsAvailablePerSize[3] - plotsMinted[3];
        plotsAvailableBySize[4] = plotsAvailablePerSize[4] - plotsMinted[4];

On the other hand, when the number of available plots per size is increased, the minting can fail. This can happen because the MAX_SUPPLY in RuniverseLand is set to 70000, which is also the sum of all plotsAvailablePerSize entries. When the sum of these entries is increased beyond 70000, some tokens cannot be minted, because the MAX_SUPPLY is already reached.

Proof Of Concept

plotsAvailablePerSize[0] is changed by the owner to 54500, all other entries are kept the same. Because more users prefer cheap plots, they buy all 54500 plots of size 8x8 and 15500 plots of size 16x16. However, this means that 70000 tokens are minted and no one can buy the 32x32 or 64x64, leading to a substantial financial loss for the protocol (because larger investors might have bought them later, but can no longer do so).

Recommended Mitigation Steps

Enforce that

  1. All entries are larger than plotsMinted
  2. The new entries sum up to 70000 (or to a number that is <= 70000 if decreasing the max supply should be allowed)

Alex the Entreprenerd (judge) commented:

Lack of check to guarantee invariant.

msclecram (Forgotten Runiverse) acknowledged

Alex the Entreprenerd (judge) commented:

Similarly to #10 and #11, the Warden has shown a way for an invariant to be broken based on configuration.

Because certain aspects of the codebase are using the invariants which can be bypassed as shown above, I agree with Medium Severity.

msclecram (Forgotten Runiverse) commented:

We updated the code with the next changes:

  • We removed setPlotsAvailablePerSize

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

Likely the setter function lacks checks to ensure each new value is at least the number already minted and that the sum of all values does not exceed the maximum supply.

Impact

The contract can underflow and become partially unusable, or the maximum supply can be reached early, preventing larger plot sizes from being minted and causing financial loss to the protocol.

What the attacker needed

Owner calls setPlotsAvailablePerSize

The fix

The function was removed in a later commit.

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 lets the owner adjust how many plots of each size are available. If the owner sets a number lower than what has already been sold, a subtraction goes negative and breaks the contract. If the owner sets the total too high, the contract's maximum supply is reached early, so some plot sizes can never be bought.

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

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.