Skip to content
Smart contracts Audit finding Intermediate

cancelPromotion() Unable to cancel unstarted promotions

The cancelPromotion() function fails for promotions that have not yet started because it calls _getCurrentEpochId(), which subtracts the future start timestamp from the current block timestamp, causing an underflow and revert. An attacker could not exploit this directly, but it prevents legitimate cancellation of unstarted promotions.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug, also found by kenzo, and certora

For unstarted promotions, cancelPromotion() will revert at block.timestamp - _promotion.startTimestamp in _getCurrentEpochId().

Call stack: cancelPromotion() -> _getRemainingRewards() -> _getCurrentEpochId().

https://github.com/pooltogether/v4-periphery/blob/0e94c54774a6fce29daf9cb23353208f80de63eb/contracts/TwabRewards.sol#L331-L336

function _getRemainingRewards(Promotion memory _promotion) internal view returns (uint256) {
    // _tokensPerEpoch * _numberOfEpochsLeft
    return
        _promotion.tokensPerEpoch *
        (_promotion.numberOfEpochs - _getCurrentEpochId(_promotion));
}

https://github.com/pooltogether/v4-periphery/blob/0e94c54774a6fce29daf9cb23353208f80de63eb/contracts/TwabRewards.sol#L276-L279

function _getCurrentEpochId(Promotion memory _promotion) internal view returns (uint256) {
    // elapsedTimestamp / epochDurationTimestamp
    return (block.timestamp - _promotion.startTimestamp) / _promotion.epochDuration;
}

Recommendation

Consider checking if _promotion.startTimestamp > block.timestamp and refund _promotion.tokensPerEpoch * _promotion.numberOfEpochs in cancelPromotion().

PierrickGT (PoolTogether) confirmed

The original report as published on Code4rena, by WatchPug. 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 function _getCurrentEpochId() does not handle the case where the promotion's start timestamp is in the future, leading to an arithmetic underflow when subtracting block.timestamp.

Impact

The cancellation of unstarted promotions is impossible, potentially locking rewards or preventing promoters from reclaiming funds.

What the attacker needed

A promotion that has not started

The fix

The recommendation is to check if the promotion start timestamp is in the future and, if so, refund the total reward amount directly in cancelPromotion().

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 function meant to cancel a promotion before it starts crashes because it tries to calculate time elapsed since a start time that is in the future. This makes the subtraction negative, which the contract cannot handle, so the cancellation always fails.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by WatchPug

View all

197 more disclosed reports, best first.

More from PoolTogether

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.