Skip to content
Business logic Audit finding Intermediate

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.

Lambda Follow

Originally disclosed on Code4rena

Submitted by Lambda

https://github.com/code-423n4/2022-12-tessera/blob/1e408ebc1c4fdcc72678ea7f21a94d38855ccc0b/src/modules/GroupBuy.sol#L455

https://github.com/code-423n4/2022-12-tessera/blob/1e408ebc1c4fdcc72678ea7f21a94d38855ccc0b/src/modules/GroupBuy.sol#L478

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 <=.

HickupHH3 (judge) commented:

Given that block timestamp period for ETH mainnet is now a constant 12s, the probability of a block timestamp being equal to terminationPeriod is 1/12 (~8.3%), which is non-trivial.

stevennevins (Tessera) confirmed and mitigated:

https://github.com/fractional-company/modular-fractional/pull/203

Status: Mitigation confirmed by gzeon, IllIllI, and Lambda.


The original report as published on Code4rena, by Lambda. 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 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

  1. Wait until the block timestamp equals the pool's termination period.
  2. Call `claim` to get the initial contribution back.
  3. Call `contribute` again with a higher bid than the previous one.
  4. 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.

More by Lambda

View all

64 more disclosed reports, best first.

More from Tessera - Versus 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.