Skip to content
Business logic Audit finding Intermediate

Absence of restrictions on the sender of the twTAP.claimsReward() function could enable attackers to freeze reward tokens within the Tap token contract

The twTAP.claimRewards() function allows any caller to claim rewards for a token ID as long as the recipient is approved. An attacker can front-run a cross-chain claim by calling claimRewards with the TapTokenReceiver contract as recipient, causing the rewards to be sent to that contract and trapped there, so the legitimate cross-chain claim returns zero.

KIntern_NA Follow with KIntern_NA, immeas and 4 others

Originally disclosed on Code4rena

Submitted by KIntern_NA, also found by KIntern_NA, immeas, carrotsmuggler, ronnyx2017, GalloDaSballo (1, 2, 3), cccz, and ladboy233

https://github.com/Tapioca-DAO/tap-token/blob/20a83b1d2d5577653610a6c3879dff9df4968345/contracts/governance/twTAP.sol#L396-L404

The function twTAP.claimRewards() is utilized to claim the reward distributed to the position identified by _tokenId.

function claimRewards(uint256 _tokenId, address _to)
    external
    nonReentrant
    whenNotPaused
    returns (uint256[] memory amounts_)
{
    _requireClaimPermission(_to, _tokenId);
    amounts_ = _claimRewards(_tokenId, _to);
}

This function can be triggered by anyone, provided that the receiver of the claimed reward _to is either the owner of the position or an address approved by the position’s owner.

In the function TapTokenReceiver._claimTwpTapRewardsReceiver(), the twTAP.claimRewards() function is invoked at line 156 to calculate the reward assigned to _tokenId and claim the reward to this contract before transferring it to the receiver on another chain. To achieve this, the position’s owner must first approve this contract to access the position before executing the function.

function _claimTwpTapRewardsReceiver(bytes memory _data) internal virtual twTapExists {
    ClaimTwTapRewardsMsg memory claimTwTapRewardsMsg_ = TapTokenCodec.decodeClaimTwTapRewardsMsg(_data);
    uint256[] memory claimedAmount_ = twTap.claimRewards(claimTwTapRewardsMsg_.tokenId, address(this));

    ...
}

However, between the call to grant approval to the contract and the execution of the _claimTwpTapRewardsReceiver() function, an attacker can insert a transaction calling twTAP.claimRewards(_tokenId, TapTokenReceiver). By doing so, the rewards will be claimed to the TapTokenReceiver contract before the _claimTwpTapRewardsReceiver() function is invoked. Consequently, the return value of claimedAmount_ = twTap.claimRewards(claimTwTapRewardsMsg_.tokenId, address(this)) within the function will be 0 for all elements, resulting in no rewards being claimed for the receiver. As a result, the reward tokens will become trapped in the contract.

In the event that the sender utilizes multiple LayerZero composed messages containing two messages:

  • Permit message: to approve permission of _tokenId to the TapTokenReceiver contract.
  • Claim reward message: to trigger the _claimTwpTapRewardsReceiver() function and claim the reward.

The attacker cannot insert any twTAP.claimRewards() between these two messages, as they are executed within the same transaction on the destination chain. However, the permit message can be triggered by anyone, not just the contract TapTokenReceiver. The attacker can thus trigger the permit message on the destination chain and subsequently call the twTAP.claimRewards() function before the _claimTwpTapRewardsReceiver() message is delivered on the destination chain.

Impact

The reward tokens will become trapped within the TapTokenReceiver contract.

Recommended Mitigation Steps

Consider updating the function twTAP.claimRewards() as depicted below to impose restrictions on who can invoke this function:

function claimRewards(uint256 _tokenId, address _to)
    external
    nonReentrant
    whenNotPaused
    returns (uint256[] memory amounts_)
{
    _requireClaimPermission(msg.sender, _tokenId);
    _requireClaimPermission(_to, _tokenId);
    amounts_ = _claimRewards(_tokenId, _to);
}

0xRektora (Tapioca) confirmed via duplicate Issue #120

0xRektora (Tapioca) commented:

Just as reference, the proposed mitigation will not work, because in this context msg.sender == _to.


The original report as published on Code4rena, by KIntern_NA. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 only checks that the recipient is approved, not that the caller is authorised, allowing anyone to redirect rewards to an approved contract.

Impact

Reward tokens could become permanently trapped in the TapTokenReceiver contract, and the intended recipient receives nothing.

What the attacker needed

Position owner approves TapTokenReceiver; attacker can front-run the claim

The fix

The project should restrict who can call claimRewards, but the suggested mitigation of checking msg.sender was noted by the project as not working because msg.sender equals _to in this context.

How it was found

  1. The position owner approves the TapTokenReceiver contract to access their token ID.
  2. Before the cross-chain claim message is delivered, the attacker calls twTAP.claimRewards with the token ID and the TapTokenReceiver contract as the recipient.
  3. The rewards are sent to the TapTokenReceiver contract.
  4. When the legitimate cross-chain claim executes, it receives zero rewards, and the tokens remain trapped in the contract.

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 lets anyone trigger a reward claim for a token, as long as the reward goes to an approved address. An attacker can jump in first and send the reward to a helper contract that is not set up to forward it, so the reward gets stuck there. The real owner then gets nothing.

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.

More by KIntern_NA

View all

21 more disclosed reports, best first.

More from Tapioca Invitational

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.