Missing Check When Transferring Tokens Out For A Given Promotion
The claimRewards function in TwabRewards.sol does not verify that the total rewards claimed for a promotion stay within the promotion's allocated balance. An attacker could exploit inaccuracies in reward calculation to claim more tokens than allocated, potentially draining funds meant for other promotions.
Submitted by leastwood
Impact
The claimRewards function is called upon by ticket holders who parse a set of _epochIds they wish to claim rewards on. An internal call is made to _calculateRewardAmount to calculate the correct reward amount owed to the user. Subsequently, the _updateClaimedEpoch function will set the epoch bit of the tracked _claimedEpochs mapping, ensuring an epochId cannot be claimed twice for a given promotion.
However, there may be inaccuracies in the _calculateRewardAmount function, which results in more tokens being sent out than allocated by a promotion creator. This severely impacts the ability for users to claim their owed tokens on other promotions.
Proof of Concept
function claimRewards(
address _user,
uint256 _promotionId,
uint256[] calldata _epochIds
) external override returns (uint256) {
Promotion memory _promotion = _getPromotion(_promotionId);
uint256 _rewardsAmount;
uint256 _userClaimedEpochs = _claimedEpochs[_promotionId][_user];
for (uint256 index = 0; index < _epochIds.length; index++) {
uint256 _epochId = _epochIds[index];
require(
!_isClaimedEpoch(_userClaimedEpochs, _epochId),
"TwabRewards/rewards-already-claimed"
);
_rewardsAmount += _calculateRewardAmount(_user, _promotion, _epochId);
_userClaimedEpochs = _updateClaimedEpoch(_userClaimedEpochs, _epochId);
}
_claimedEpochs[_promotionId][_user] = _userClaimedEpochs;
_promotion.token.safeTransfer(_user, _rewardsAmount);
emit RewardsClaimed(_promotionId, _epochIds, _user, _rewardsAmount);
return _rewardsAmount;
}
Recommended Mitigation Steps
Consider checking that the total rewards claimed for a given promotion is strictly <= than the total allotted balance provided by the promotion creator. This should help prevent a single promotion from affecting the rewards claimable from other promotions.
PierrickGT (PoolTogether) acknowledged:
This check seems redundant, especially now that we have restricted the contract to only support one ticket (in this PR), this will avoid a promotion with a fake ticket to manipulate the amount of rewards claimable and an attacker won’t be able to drain funds from a promotion. So for this reason, I’ve acknowledged the issue but we won’t implement this check.
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 claimRewards function lacks a check that the cumulative rewards claimed for a promotion do not exceed the promotion's total allocated balance.
Impact
An attacker could claim more tokens than allocated for a promotion, which could prevent users from claiming owed tokens on other promotions.
What the attacker needed
A promotion with reward calculation inaccuracies
The fix
The project acknowledged the issue but decided not to implement the suggested check, citing redundancy after restricting the contract to support only one ticket.
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.
This is a smart contract that lets users claim rewards. The code that calculates how many tokens a user gets might have small errors, and there is no check to stop someone from claiming more than the promotion creator set aside. That could let someone take tokens that belong to other promotions.
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.