twTAP.claimAndSendRewards() will claim the wrong amount for each reward token due to the use of wrong index
chaduke Follow with bin2chen, KIntern_NA and 2 others
Originally disclosed on Code4rena
Submitted by chaduke, also found by bin2chen, KIntern_NA, 0xRobocop, and rvierdiiev
Detailed description of the impact of this finding. twTAP.claimAndSendRewards() will claim the wrong amount for each reward token due to the use of wrong index. As a result, some users will lose some rewards and others will claim more rewards then they deserve.
Proof of Concept
Provide direct links to all referenced code in GitHub. Add screenshots, logs, or any other relevant proof that illustrates the concept.
twTAP.claimAndSendRewards() allows the tapOFT to claim and send a list of rewards indicated in _rewardTokens.
It calls the function _claimRewardsOn() to achieve this:
Unfortunately, at L509, it uses the index of i instead of the correct index of claimableIndex. As a result, the amount that is claimed and transferred for each reward is wrong.
Tools Used
VSCode
Recommended Mitigation Steps
We need to use index claimableIndex instead of i for function _claimRewardsOn():
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];
+ uint256 amount = amounts[claimableIndex];
if (amount > 0) {
// Math is safe: `amount` calculated safely in `claimable()`
claimed[_tokenId][claimableIndex] += amount;
rewardTokens[claimableIndex].safeTransfer(_to, amount);
}
++i;
}
}
}
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A high-severity business logic bug in Tapioca Invitational. Code4rena made it public on 16 November 2023. Found in the 2023-07-tapioca audit contest (finding H-60), also found by 4 other wardens.
About Business logic
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
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.