Attacker can pass duplicated reward token addresses to steal the reward of contract twTAP.sol
The reward-claiming function in twTAP.sol did not check for duplicate token addresses in the caller-supplied reward token list, so an attacker could pass the same token twice and receive its reward amount multiple times. This allowed stealing rewards that should have been paid only once.
KIntern_NA Follow with bin2chen and glcanvas
Originally disclosed on Code4rena
Submitted by KIntern_NA, also found by bin2chen and glcanvas
The attacker can exploit the contract twTAP.sol to steal rewards.
Proof of Concept
The function twTAP.claimAndSendRewards() -> twTAP._claimRewardsOn() is intended for users who utilize the cross-chain message of BaseTOFT.sol to claim a specific set of reward tokens.
function _claimRewardsOn(
uint256 _tokenId,
address _to,
IERC20[] memory _rewardTokens
) internal {
uint256[] memory amounts = claimable(_tokenId);
unchecked {
uint256 len = _rewardTokens.length;
for (uint256 i = 0; i < len; ) {
uint256 claimableIndex = rewardTokenIndex[_rewardTokens[i]];
uint256 amount = amounts[i];
if (amount > 0) {
// Math is safe: `amount` calculated safely in `claimable()`
claimed[_tokenId][claimableIndex] += amount;
rewardTokens[claimableIndex].safeTransfer(_to, amount);
}
++i;
}
}
}
The internal function iterates through the list of reward tokens specified by the user after calculating the claimable amount for each token in the STORAGE array twTAP.rewardTokens[]. Unfortunately, there is no check if the _rewardTokens contain duplicated reward tokens, and the function claimable(_tokenId) is not called after each iteration, which allows the attacker to manipulate the function call using the same reward address repeatedly.
For example,
- STORAGE array
rewardTokens[] = [usdc, usdt] - The function
_claimRewardsOn()is called with_rewardTokens[] = [usdt, usdt]. In each iteration, theclaimableIndexwill berewardTokenIndex[usdc] = 0, which transfers the usdt two times to the attacker.
Recommended Mitigation Steps
One solution to mitigate this issue is to require the MEMORY array _rewardTokens to be sorted in ascending order.
function _claimRewardsOn(
uint256 _tokenId,
address _to,
IERC20[] memory _rewardTokens
) internal {
uint256[] memory amounts = claimable(_tokenId);
unchecked {
uint256 len = _rewardTokens.length;
for (uint256 i = 0; i < len; ) {
// CHANGE HERE
if (i != 0) {
require(_rewardTokens[i] > _rewardTokens[i-1]);
}
uint256 claimableIndex = rewardTokenIndex[_rewardTokens[i]];
uint256 amount = amounts[i];
if (amount > 0) {
// Math is safe: `amount` calculated safely in `claimable()`
claimed[_tokenId][claimableIndex] += amount;
rewardTokens[claimableIndex].safeTransfer(_to, amount);
}
++i;
}
}
}
By ensuring that the reward tokens are sorted in ascending order, we can prevent the exploit where the attacker claims the same reward token multiple times and effectively mitigate the vulnerability.
0xRektora (Tapioca) confirmed via duplicate issue 1304
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
The function used a caller-supplied list of reward tokens to index into storage without ensuring the list had no duplicates, and it reused the same precomputed amounts array for each entry.
Impact
An attacker could claim the same reward token multiple times and steal rewards from the contract.
What the attacker needed
A position with claimable rewards; ability to call the reward-claiming function
The fix
The function should reject duplicate reward token addresses, for example by requiring the supplied list to be strictly sorted in ascending order.
How it was found
- Call the reward-claiming function with a list of reward tokens that contains the same token address twice.
- The function looks up the storage index for that token and transfers the corresponding amount for each duplicate entry.
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 pays out rewards in several tokens. The function that pays out trusted the caller's list of tokens and did not notice if the same token appeared twice. By listing one token twice, an attacker could get paid that token's reward more than once.
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.