Skip to content
Business logic Audit finding Intermediate

There is no slippage check in the nuke() function

The nuke() function lacks a minimum claim amount check, so a user's payout can be reduced if another user's nuke transaction is processed first. An attacker could front-run or benefit from transaction ordering to receive a larger share, leaving the victim with less than expected.

KupiaSec Follow with burnerelu, gajiknownnothing and 26 others

Originally disclosed on Code4rena

Submitted by KupiaSec, also found by burnerelu, gajiknownnothing, Decap, Rhaydden, p0wd3r, 0x3b, samuraii77, peanuts, DemoreX, Abdessamed, desaperh, jesjupyter, franfran20, vinica_boy, 0xvd, amaron, slvDev, Joshuajee, cozymfer, phoenixV110, gkrastenov, ilchovski (1, 2), 0xrex, Kalogerone, ke1caM, shaflow2, shaka, dimulski, and hl_

NFT owners may receive significantly less nuke funds than they expected.

Proof of Concept

In the nuke() function, there is no minimum claim amount check. Consider the following scenario:

  1. The fund value of the NukeFund contract is 10 ETH.

  2. Alice is about to nuke an NFT with a nuke factor of 0.5, allowing her to receive 5 ETH.

  3. Bob also has an NFT with a nuke factor of 0.5 and calls the nuke() function with his NFT, front-running Alice.

    • Bob receives 5 ETH (see L166).
    • The remaining fund is now 10 ETH - 5 ETH = 5 ETH (see L174).
  4. Next, Alice’s transaction is processed, and she receives only 2.5 ETH (0.5 of the remaining fund of 5 ETH).

If Alice’s transaction had been processed before Bob’s, she would have received 5 ETH. However, due to being front-run by Bob, she only receives 2.5 ETH, which is significantly less than expected. This highlights the necessity of implementing a minimum claim amount check in the nuke() function. With such a check, it is possible to prevent Alice from receiving only 2.5 ETH which is far below her expectations.

    function nuke(uint256 tokenId) public whenNotPaused nonReentrant {
      require(
        nftContract.isApprovedOrOwner(msg.sender, tokenId),
        'ERC721: caller is not token owner or approved'
      );
      require(
        nftContract.getApproved(tokenId) == address(this) ||
          nftContract.isApprovedForAll(msg.sender, address(this)),
        'Contract must be approved to transfer the NFT.'
      );
      require(canTokenBeNuked(tokenId), 'Token is not mature yet');

      uint256 finalNukeFactor = calculateNukeFactor(tokenId); // finalNukeFactor has 5 digits
166   uint256 potentialClaimAmount = (fund * finalNukeFactor) / MAX_DENOMINATOR; // Calculate the potential claim amount based on the finalNukeFactor
      uint256 maxAllowedClaimAmount = fund / maxAllowedClaimDivisor; // Define a maximum allowed claim amount as 50% of the current fund size

      // Directly assign the value to claimAmount based on the condition, removing the redeclaration
      uint256 claimAmount = finalNukeFactor > nukeFactorMaxParam
        ? maxAllowedClaimAmount
        : potentialClaimAmount;

174   fund -= claimAmount; // Deduct the claim amount from the fund

      nftContract.burn(tokenId); // Burn the token
      (bool success, ) = payable(msg.sender).call{ value: claimAmount }('');
      require(success, 'Failed to send Ether');

      emit Nuked(msg.sender, tokenId, claimAmount); // Emit the event with the actual claim amount
      emit FundBalanceUpdated(fund); // Update the fund balance
    }

Recommended Mitigation Steps

It is recommended to implement a minimum claim amount check in the nuke() function.

TForge1 (TraitForge) confirmed and commented:

Although base-chain has a private mempool, meaning MEV and Front-Running is not possible. There is a possibility of the mempool privacy changing, which will make this a valid issue. But it is impossible, now, judges can decide what they want to do with this. But possibility of mempool going public means this is still a risk.

Koolex (judge) increased severity to High and commented:

Valid issue.

Reasoning:

  • Even without intentional front-running, transaction ordering can still have impacts similar to front-running.
  • While users can’t see other pending transactions, market conditions can still change between transaction submission and execution
  • As far as I know, Transactions on Base are generally ordered on a first-come, first-served basis by the sequencer. Since, there is no guarantee that the first submitted TX will be processed first (due to multiple factors including network latency), the risk still exists.

ABAIKUNANBAEV (warden) commented:

I think this should downgraded to medium or QA for the same reasoning as described in Issue #166:

  1. The mempool is private meaning the probability is extremely low.
  2. Front-running issues will always exist and it’s the same reasoning as with the auctions: “If I front-run you, you will have to pay the bigger price”. I guess it’s just the nature of the game.
  3. This certainly has a risk but the problem is that the game allows “the fastest” to win and let’s say the suggested mitigation is introduced and Alice gets minNukeAmount. Her tx will revert multiple times before that due to deviation from minNukeAmount and it’s not likely that she will get a much bigger amount as the competition will be extremely high for such amounts of ETH. There will be just the same situation if she was front-runned with the absence of slippage. The example with 2.5 ETH and 5 ETH seems highly unrealistic, as such amounts from NukeFund in real scenario will be taken almost right away.

Abdessamed (warden) commented:

@ABAIKUNANBAEV - You are mistaking two things:

  1. The slippage here is different from #166. The slippage here can cause significant loss for users (up to 50% of what they expected) as outlined by the PoC: the user received 2.5 ETH instead of 5 ETH, we are talking about a 2.5 ETH difference which is about $6k.
  2. There doesn’t have to be front-running for this issue to happen as explained in another duplicate Issue #753, the warden incorrectly mentioned this in his report.

If Alice submits her transaction before Bob, according to the fastest rule, Alice’s transaction should be executed first. But still, Bob’s transaction can be executed before Alice due to several reasons like network congestion, etc.; something that players can not control.

ABAIKUNANBAEV (warden) commented:

Yes, and as I outlined, such minAmount mitigation for this issue is senseless as, at the start of the game, everybody will try to claim and here “the fastest wins” rule comes into play. The fastest here will get the most amount of money. You make a logical mistake by saying that users here “lose the funds” as they don’t lose anything - they only own a tokenId that makes them eligible to claim at most 50% of the funds. By saying they lose funds - they didn’t lose, they just did not get amount that they could potentially get - big difference. I personally think it’s at most QA.

dimulski (warden) commented:

I disagree that users don’t lose the funds. If they don’t receive what they expect, they have burned their NFT with which later on they can claim what they desire. There is definitely a loss of funds, as you have to pay for the NFT; either mint it, forge it or buy it on an open market.

ABAIKUNANBAEV (warden) commented:

They don’t own any funds to lose them, it’s just opportunity for everybody.

Koolex (judge) decreased severity to Medium and commented:

I believe it is fair to downgrade it to Medium for similar reasons explained here.


The original report as published on Code4rena, by KupiaSec. 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 nuke() function calculates the payout from the current fund balance without letting the caller specify a minimum acceptable amount, so the payout changes if the fund is reduced by another transaction first.

Impact

A user could receive significantly less than expected when nuking, though the report notes that on Base the private mempool makes front-running currently impossible and the judge ultimately rated the issue Medium.

What the attacker needed

A user with an NFT eligible to be nuked; another user nukes first or transaction ordering changes

The fix

A minimum claim amount check should be added to the nuke() function so users can specify the least they will accept.

How it was found

  1. The NukeFund contract has 10 ETH.
  2. Alice plans to nuke an NFT with a nuke factor of 0.5, expecting 5 ETH.
  3. Bob also has an NFT with a nuke factor of 0.5 and calls nuke() with his NFT, front-running Alice.
  4. Bob receives 5 ETH, leaving the fund at 5 ETH.
  5. Alice's transaction is processed and she receives only 2.5 ETH (0.5 of the remaining 5 ETH).

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 'nuke' an NFT, you get a share of a shared pool of funds. The amount you get depends on the pool size at the moment your transaction runs. If someone else takes their share first, the pool shrinks and you get less. This report says the function should let you set a minimum you are willing to accept, so you do not get less than you expected.

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 KupiaSec

View all

28 more disclosed reports, 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.