Groupbuy: _verifyUnsuccessfulState and _verifySuccessfulState both can return true when block.timestamp == pool.terminationPeriod
The state-checking functions for a group-buy pool both allow the same timestamp condition, so an attacker can claim a refund and then re-bid to receive the same funds again. This lets the attacker drain the contract.
Submitted by Lambda
Impact
The functions _verifyUnsuccessfulState and _verifySuccessfulState should always have a differing behavior with regards to reversion, i.e. when one does not revert, the other should revert. In one condition, this is not true. Namely, when we have pool.success == false and block.timestamp == pool.terminationPeriod, this check within _verifyUnsuccessfulState is false:
if (pool.success || block.timestamp > pool.terminationPeriod) revert InvalidState();
Similarly, this check within _verifySuccessfulState is also false:
if (!pool.success && block.timestamp < pool.terminationPeriod) revert InvalidState();
Because this breaks a fundamental invariant of the contract, there are probably multiple ways to exploit it. One way an attacker can exploit is by calling claim (to get his contribution back completely), bidding again with a higher value than his previous contributions (to get his contributions back again).
Proof Of Concept
Let’s assume we are at timestamp pool.terminationPeriod. Attacker Charlie has performed the lowest bid with quantity 10 and price 1 ETH. He calls claim to get his 10 ETH back. Now, he calls contribute with a quantity of 10 and a price of 2 ETH. Because this bid is higher than his previous one (which was the lowest one), his pendingBalances is set to 10 ETH (for the deleted entries) and his userContributions is set to 20 ETH (for this new contribution). He can now call claim again to get back his 20 ETH in userContributions, but also the 10 ETH in pendingBalances. Like that, he has stolen 10 ETH (and could use this attack pattern to drain the whole contract).
Recommended Mitigation Steps
Change < in _verifySuccessfulState to <=.
Given that block timestamp period for ETH mainnet is now a constant 12s, the probability of a block timestamp being equal to
terminationPeriodis 1/12 (~8.3%), which is non-trivial.
stevennevins (Tessera) confirmed and mitigated:
https://github.com/fractional-company/modular-fractional/pull/203
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 boundary condition in `_verifySuccessfulState` uses a strict less-than comparison, so at exactly the termination timestamp both the successful and unsuccessful checks pass.
Impact
An attacker could steal funds from the contract, potentially draining it, if they can act at the exact termination timestamp.
What the attacker needed
Attacker has a bid in the pool; block timestamp equals terminationPeriod
How it was found
- Wait until the block timestamp equals the pool's termination period.
- Call `claim` to get the initial contribution back.
- Call `contribute` again with a higher bid than the previous one.
- Call `claim` again to receive both the new contribution and the pending balance.
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 smart contract has rules about when a pool is successful or unsuccessful. Two checks that should be opposites both allow the same moment in time. An attacker can use that moment to take back money they already paid, then bid again and take back more money than they put in.
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.