Pancakeswap Logic Error Bug Fix Review
The lottery contract's multiClaim function did not check that the submitted ticket IDs were unique, so a user could claim the same winning ticket many times in one transaction. An attacker could have claimed a winning ticket at least 255 times, inflating the reward by that factor and potentially draining up to $700,000.
immunefi.com
Published on immunefi.com
Whitehat Juno submitted a critical vulnerability in PancakeSwap’s lottery contract on April 27. The vulnerability consisted of a logic error.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The contract checked all tickets for prior claims before marking any as claimed, and the NFT contract's multiClaimReward did not verify that a ticket had not already been marked as claimed, so duplicate ticket IDs in the input were each paid out.
Impact
An attacker could have claimed the same winning ticket at least 255 times in one transaction, inflating the reward by that factor and potentially draining up to $700,000; however, PancakeSwap had already stopped new lottery drawings, and there is no evidence the bug was exploited.
What the attacker needed
A lottery ticket; the ticket must be a winner; the lottery contract must still hold funds
The fix
The multiClaim function was rewritten to mark each ticket as claimed inside the loop before calculating its reward, and PancakeSwap withdrew all funds from the contract.
How it was found
- Buy a lottery ticket.
- Win at least a small prize (matching two or more numbers).
- Call multiClaim with the same winning ticket ID repeated many times (up to 255 in one transaction).
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 write-up has not been written yet. The Original tab links to the source.
A lottery contract lets people claim a prize for a winning ticket. The claim function accepted a list of tickets but never checked for duplicates, so someone could put the same winning ticket in the list over and over. Each duplicate was paid out again, letting the attacker take far more money than they should.
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.