Skip to content
Business logic Audit finding Intermediate

The buyer of the ticket could be front-runned by the ticket owner who claims the rewards before the ticket’s NFT is traded

A ticket owner could list a winning ticket for sale and then claim its rewards just before the buyer's purchase transaction, leaving the buyer with a worthless ticket. The buyer loses the purchase price while the seller keeps both the rewards and the sale proceeds.

sashik_eth Follow with adriro, horsefacts and 6 others

Originally disclosed on Code4rena

Submitted by sashik_eth, also found by adriro, horsefacts, MadWookie, hl_, 0xbepresent, peanuts, Dug, and Haipls

If the ticket owner lists the winning ticket on the secondary market and initiates their own claiming transaction before the trade transaction takes place, the NFT buyer could lose funds as a result.

Proof of Concept

Given that there are no restrictions on trading tickets on the secondary market, the following scenario could occur:

  1. Alice acquires the winning ticket with 75 DAI worth of claimable rewards, and lists the ticket on the secondary market for 70 DAI.
  2. Bob decides to purchase the ticket, recognizing that it is profitable to trade and claim the rewards associated with it.
  3. Alice monitors the mempool and submits a claimWinningTickets() transaction just before Bob’s purchase transaction.
  4. Bob receives ticket NFT and calls to claimWinningTickets() but this transaction would revert as the rewards have already been claimed by Alice. Consequently, Alice receives a total of 75 + 70 DAI, while Bob is left with an empty ticket and no rewards.

The next test added to /2023-03-wenwin/test/Lottery.t.sol could demonstrate such a scenario:

    function testClaimBeforeTransfer() public {
        uint128 drawId = lottery.currentDraw();
        uint256 ticketId = initTickets(drawId, 0x8E);

        // this will give winning ticket of 0x0F so 0x8E will have 3/4
        finalizeDraw(0);

        uint8 winTier = 3;
        checkTicketWinTier(drawId, 0x8E, winTier);

        address BUYER = address(456);

        vm.prank(USER);
        claimTicket(ticketId); // USER front-run trade transaction and claims rewards
        vm.prank(USER);
        lottery.transferFrom(USER, BUYER, ticketId);

        vm.prank(BUYER);
        vm.expectRevert(abi.encodeWithSelector(NothingToClaim.selector, 0));
        claimTicket(ticketId); // BUYER tries to claim the ticket but it would revert since USER already claimed it
    }

Recommended Mitigation Steps

Consider burning claimed ticket NFTs or remove the possibility to transfer NFTs that have already been claimed.

TutaRicky (Wenwin) confirmed


The original report as published on Code4rena, by sashik_eth. 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 ticket NFT can still be transferred after its rewards have been claimed, so the buyer has no way to know the prize is gone.

Impact

The buyer could lose the purchase price because the ticket's rewards were already claimed by the seller, who keeps both the sale proceeds and the prize.

What the attacker needed

A winning ticket NFT; ticket listed on a secondary market; seller can front-run the purchase

How it was found

  1. Alice lists a winning ticket worth 75 DAI for 70 DAI on the secondary market.
  2. Bob buys the ticket expecting to claim the rewards.
  3. Alice sees Bob's purchase in the mempool and submits a claim transaction first.
  4. Bob receives the ticket but his claim reverts because the rewards are already gone.

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 lottery ticket is an NFT that can be sold on a marketplace. The seller can watch pending transactions and quickly claim the prize before the buyer's purchase goes through, so the buyer pays for a ticket that no longer has any value.

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 sashik_eth

View all

5 more disclosed reports, best first.

More from Wenwin 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.