Skip to content
Business logic Audit finding Intermediate

Wrong balanceOf user after minting legendary gobbler

The mintLegendaryGobbler function incorrectly increments the user's gobblersOwned count by one extra, because the new legendary token is already counted in the _mint function. This causes balanceOf to return an inflated balance for the user after minting a legendary gobbler.

wagmi Follow

Originally disclosed on Code4rena

Submitted by wagmi, also found by 0x52, arcoun, CertoraInc, Lambda, RaymondFam, and zzykxx

ArtGobblers.sol#L458

In ArtGobblers.mintLegendaryGobbler() function, line 458 calculates the number of gobblers user owned after minting.

// We subtract the amount of gobblers burned, and then add 1 to factor in the new legendary.
getUserData[msg.sender].gobblersOwned = uint32(getUserData[msg.sender].gobblersOwned - cost + 1);

It added 1 to factor in the new legendary. But actually, this new legendary is accounted in _mint() function already

function _mint(address to, uint256 id) internal {
    // Does not check if the token was already minted or the recipient is address(0)
    // because ArtGobblers.sol manages its ids in such a way that it ensures it won't
    // double mint and will only mint to safe addresses or msg.sender who cannot be zero.

    unchecked {
        ++getUserData[to].gobblersOwned;
    }

    getGobblerData[id].owner = to;

    emit Transfer(address(0), to, id);
}

So the result is gobblersOwned is updated incorrectly. And balanceOf() will return wrong value.

Proof of Concept

Script modified from testMintLegendaryGobbler()

function testMintLegendaryGobbler() public {
    uint256 startTime = block.timestamp + 30 days;
    vm.warp(startTime);
    // Mint full interval to kick off first auction.
    mintGobblerToAddress(users[0], gobblers.LEGENDARY_AUCTION_INTERVAL());
    uint256 cost = gobblers.legendaryGobblerPrice();
    assertEq(cost, 69);
    setRandomnessAndReveal(cost, "seed");
    uint256 emissionMultipleSum;
    for (uint256 curId = 1; curId <= cost; curId++) {
        ids.push(curId);
        assertEq(gobblers.ownerOf(curId), users[0]);
        emissionMultipleSum += gobblers.getGobblerEmissionMultiple(curId);
    }

    assertEq(gobblers.getUserEmissionMultiple(users[0]), emissionMultipleSum);

    uint256 beforeSupply = gobblers.balanceOf(users[0]);
    vm.prank(users[0]);
    uint256 mintedLegendaryId = gobblers.mintLegendaryGobbler(ids);

    // Check balance
    assertEq(gobblers.balanceOf(users[0]), beforeSupply - cost + 1);
}

Tools Used

Foundry

Recommended Mitigation Steps

Consider remove adding 1 when calculating gobblersOwned

getUserData[msg.sender].gobblersOwned = uint32(getUserData[msg.sender].gobblersOwned - cost);

transmissions11 (Art Gobblers) commented:

Great find!

FrankieIsLost (Art Gobblers) confirmed and commented:

Good find, fixed here: https://github.com/artgobblers/art-gobblers/pull/153

Alex the Entreprenerd (judge) commented:

The warden has demonstrated an accounting issue in the system, the Sponsor has mitigated.

Because the finding is valid and the behaviour shown diverges from the intended one, without a severe risk of loss, I agree with Medium Severity.


The original report as published on Code4rena, by wagmi. 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 code manually adds 1 to gobblersOwned after subtracting the burned cost, but the _mint function already increments gobblersOwned, leading to double counting.

What the attacker needed

User owns enough gobblers to mint a legendary

The fix

The fix is to remove the addition of 1 when updating gobblersOwned after minting a legendary gobbler.

How it was found

  1. Set up the test environment with a user who owns enough gobblers to mint a legendary.
  2. Record the user's balance before minting.
  3. Call mintLegendaryGobbler with the required gobbler IDs.
  4. Check that the user's balance is now beforeSupply - cost + 1, which is incorrect because it should be beforeSupply - cost.

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.

When a user mints a legendary gobbler, the contract updates a counter of how many gobblers they own. The code adds one extra to that counter, but the minting process already adds one, so the counter ends up too high. This means the balance shown for the user is wrong.

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 wagmi

View all

2 more disclosed reports, best first.

More from Art Gobblers 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.