createPromotion() Lack of input validation for _epochDuration can potentially freeze promotion creator’s funds
The createPromotion function allowed an epoch duration of zero, which caused reward claims to revert due to a division by zero and prevented the creator from cancelling the promotion because it was considered ended. As a result, the creator's deposited tokens were permanently frozen in the contract.
Submitted by WatchPug
function createPromotion(
address _ticket,
IERC20 _token,
uint216 _tokensPerEpoch,
uint32 _startTimestamp,
uint32 _epochDuration,
uint8 _numberOfEpochs
) external override returns (uint256) {
_requireTicket(_ticket);
uint256 _nextPromotionId = _latestPromotionId + 1;
_latestPromotionId = _nextPromotionId;
_promotions[_nextPromotionId] = Promotion(
msg.sender,
_ticket,
_token,
_tokensPerEpoch,
_startTimestamp,
_epochDuration,
_numberOfEpochs
);
_token.safeTransferFrom(msg.sender, address(this), _tokensPerEpoch * _numberOfEpochs);
emit PromotionCreated(_nextPromotionId);
return _nextPromotionId;
}
In the current implementation of createPromotion(), _epochDuration is allowed to be 0.
However, when _epochDuration = 0, it will be impossible for users to claim the rewards, and the promotion creator won’t be able to cancel it.
Proof of Concept
-
Alice called
createPromotion()to create a promotion with the following parameters:- _token:
USDC - _tokensPerEpoch:
10,000 - _epochDuration:
0 - _numberOfEpochs:
10
- _token:
-
100,000 USDCwas transferred from Alice to theTwabRewardscontract; -
Users tries to
claimRewards()but the transaction always revert at_ticket.getAverageTotalSuppliesBetween()->TwabLib.getAverageBalanceBetween()due to div by 0. -
Alice tries to
cancelPromotion()to retrieve the funds, but it always reverts at_requirePromotionActive()since the promotion already ended.
As a result, Alice’s 100,000 USDC is frozen in the contract.
Recommendation
Consider adding require(_epochDuration > 0) in createPromotion().
PierrickGT (PoolTogether) marked as duplicate:
Duplicate of https://github.com/code-423n4/2021-12-pooltogether-findings/issues/29
I do not consider this to be a duplicate of #29 because the warden in #29 does not mention this specific failure case. This is indeed an easy to encounter bug that can be triggered as the result of a user error or a frontend bug. Loss of all funds for the promotion would be the result.
PierrickGT (PoolTogether) confirmed and resolved:
Implemented the suggested require: https://github.com/pooltogether/v4-periphery/blob/e0010b689fb170daac77af5f62abba7ca1397524/contracts/TwabRewards.sol#L126
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 createPromotion function did not validate that _epochDuration is greater than zero, leading to a division by zero in reward calculations and an inability to cancel.
Impact
The promotion creator's funds (100,000 USDC in the example) are permanently frozen in the contract.
What the attacker needed
Attacker or user creates a promotion with _epochDuration = 0
The fix
The issue was fixed by adding a require statement to ensure _epochDuration is greater than zero.
How it was found
- Alice calls createPromotion with _epochDuration set to 0 and other parameters.
- The contract transfers the total reward tokens from Alice.
- Users attempt to claim rewards but the transaction reverts due to division by zero.
- Alice attempts to cancel the promotion but it reverts because the promotion is already ended.
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 let someone start a promotion with a zero-length epoch. When users tried to claim rewards, the calculation divided by zero and failed, and the creator could not cancel because the promotion was already marked as ended. The creator's money got stuck in the contract.
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.