Pancakeswap Lottery Vulnerability Bug Fix Review And Bug Bounty
The multibuy method in PancakeSwap's lottery contract lacked a check to prevent ticket purchases during the drawing phase, unlike the buy method. An attacker could see the draw transaction, compute the winning number, and buy the correct ticket with a high gas fee to frontrun and win the lottery.
immunefi.com
Published on immunefi.com
Whitehat hacker Thunder requested disclosure assistance from Immunefi for a critical vulnerability found in PancakeSwap’s lottery contract. This vulnerability was never exploited and was fixed before any malicious actors had the chance to exploit it.
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 multibuy function did not include a check to prevent purchases during the drawing phase, unlike the buy function.
Impact
An attacker could repeatedly steal the entire lottery pot, worth about $240,000 per draw, though the attack required quick computation and a high gas fee.
What the attacker needed
Ability to submit transactions to Binance Smart Chain; knowledge of the lottery draw timing; high gas fee to frontrun
The fix
The contract was fixed by adding a check to prevent purchases via multibuy during the drawing phase.
How it was found
- Observe the transaction that draws the winning lottery number.
- Compute the winning lottery number from that transaction.
- Call the multibuy method to purchase the winning ticket during the drawing phase.
- Frontrun with a high gas fee to ensure the purchase is processed before others.
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.
In a lottery, you shouldn't be able to buy a ticket after the winning number is chosen. But a function that let people buy many tickets at once forgot to check if the draw was happening. So someone could quickly buy the winning ticket right after seeing the draw, stealing the prize.
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.