Skip to content
Business logic Audit finding Intermediate

Lack of slippage protection in dynamic pricing mint function

The mint function recalculates the price of each NFT inside the minting loop, so the price can rise between the user's estimate and their transaction being processed. A user could therefore receive fewer NFTs than expected for the same budget, or pay more per NFT than anticipated.

OMEN Follow with p0wd3r, KupiaSec and 2 others

Originally disclosed on Code4rena

Submitted by OMEN, also found by p0wd3r, KupiaSec, gesha17, and kutugu

The mintWithBudget function uses a dynamic pricing mechanism without implementing slippage protection. Given the specific pricing parameters, this can lead to users paying more than anticipated for their NFTs, especially for larger mints or mints occurring later in a generation. Specific impacts include:

  • Unexpected cost increases for users, particularly for multi-NFT mints.
  • Potential for users to receive fewer NFTs than expected if prices rise during minting.
  • Possible transaction failures if the price increases beyond the user’s budget, wasting gas.

Proof of Concept

The current implementation calculates the mint price for each NFT individually within the minting loop:

function mintWithBudget(bytes32[] calldata proof) public payable whenNotPaused nonReentrant onlyWhitelisted(proof, keccak256(abi.encodePacked(msg.sender))) {
    uint256 mintPrice = calculateMintPrice();
    uint256 amountMinted = 0;
    uint256 budgetLeft = msg.value;

    while (budgetLeft >= mintPrice && _tokenIds < maxTokensPerGen) {
      _mintInternal(msg.sender, mintPrice);
      amountMinted++;
      budgetLeft -= mintPrice;
      mintPrice = calculateMintPrice();  // Price recalculated for each mint
    }
    // ...
}

function calculateMintPrice() public view returns (uint256) {
    uint256 currentGenMintCount = generationMintCounts[currentGeneration];
    uint256 priceIncrease = priceIncrement * currentGenMintCount;
    uint256 price = startPrice + priceIncrease;
    return price;
}

Consider the following scenario:

User calculates that they can mint 100 NFTs with a budget of 12.75 ETH when 5000 NFTs have been minted in the current generation.

  • Initial price: 0.005 + (0.0000245 * 5000) = 0.1275 ETH per NFT.
  • Expected total: 100 * 0.1275 = 12.75 ETH
  • Before the user’s transaction is processed, another person mints 50 NFTs.
  • When the user’s transaction is processed, the new starting price is: 0.005 + (0.0000245 * 5050) = 0.128725 ETH
  • The user attempts to mint with their 12.75 ETH budget:

They can now only mint 99 NFTs (12.75 / 0.128725 ≈ 99.04).

  • Total cost for 99 NFTs: approximately 12.74 ETH
  • Remaining 0.01 ETH is refunded.

Actual outcome:

  • User receives 99 NFTs instead of the expected 100.
  • The average price paid per NFT is higher than initially calculated.

This scenario demonstrates how the lack of slippage protection in the dynamic pricing mechanism can lead to users receiving fewer NFTs than they anticipated or paying more per NFT than expected, due to price increases caused by other users’ minting activities between the time of calculation and the transaction being processed.

Recommended Mitigation Steps

Add slippage protection.

Assessed type

Context


The original report as published on Code4rena, by OMEN. 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 mint loop recalculates the price for each NFT without letting the caller set a maximum acceptable price, so the total cost is not bounded by the user's expectation.

Impact

Users could receive fewer NFTs than expected or pay a higher average price per NFT, and a transaction may fail if the price rises beyond their budget, wasting gas.

What the attacker needed

Whitelisted minter; other users mint before your transaction

The fix

The mint function should be fixed by adding slippage protection, such as a caller-supplied maximum price or minimum number of NFTs.

How it was found

  1. The user works out how many NFTs their budget buys at the current price.
  2. Another user mints more NFTs first, raising the current generation count and therefore the price.
  3. The user's transaction runs and recalculates the price for each mint, so fewer NFTs fit within the budget.
  4. The leftover budget is refunded and the user ends up with fewer NFTs than expected.

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 you buy something, you usually agree a maximum price first. Here the contract kept recalculating the price for every single NFT while it was minting, so if other people minted just before you, the price went up and your money bought fewer items. Slippage protection means telling the contract 'do not spend more than this per item', and it stops that surprise.

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 OMEN

View all

1 more disclosed report, best first.

More from TraitForge

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.