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.
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().
function _getRemainingRewards(Promotion memory _promotion) internal view returns (uint256) {
// _tokensPerEpoch * _numberOfEpochsLeft
return
_promotion.tokensPerEpoch *
(_promotion.numberOfEpochs - _getCurrentEpochId(_promotion));
}
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().
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.