Skip to content
Access control Audit finding Intermediate

exerciseOptionsReceiver() Lack of Ownership Check for oTAP, Allowing Anyone to Use oTAPTokenID

The exerciseOptionsReceiver function lacks an ownership check for the oTAPTokenID, so once the owner approves USDO to use the token, anyone can front-run and call the function with their own address as the recipient, effectively using the token without permission.

bin2chen Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-02-tapioca-judging/issues/102

Found by

bin2chen

Summary

In UsdoOptionReceiverModule.exerciseOptionsReceiver(): For this method to execute successfully, the owner of the oTAPTokenID needs to approve it to address(usdo). Once approved, anyone can front-run execute exerciseOptionsReceiver() and utilize this authorization.

Vulnerability Detail

In USDO.lzCompose(), it is possible to specify _msgType == MSG_TAP_EXERCISE to execute USDO.exerciseOptionsReceiver() across chains.

Solidity
    function exerciseOptionsReceiver(address srcChainSender, bytes memory _data) public payable {
...
            ITapiocaOptionBroker(_options.target).exerciseOption(
@>              _options.oTAPTokenID,
                address(this), //payment token
                _options.tapAmount
            );
            _approve(address(this), address(pearlmit), 0);
            uint256 bAfter = balanceOf(address(this));

            // Refund if less was used.
            if (bBefore > bAfter) {
                uint256 diff = bBefore - bAfter;
                if (diff < _options.paymentTokenAmount) {
                    IERC20(address(this)).safeTransfer(_options.from, _options.paymentTokenAmount - diff);
                }
            }
...

For this method to succeed, USDO must first obtain approve for the oTAPTokenID.

Example: The owner of oTAPTokenID is Alice.

  1. alice in A chain execute lzSend(dstEid = B) with
    • composeMsg = [oTAP.permit(usdo,oTAPTokenID,v,r,s) 2.exerciseOptionsReceiver(oTAPTokenID,_options.from=alice) 3. oTAP.revokePermit(oTAPTokenID)]
  2. in chain B USDO.lzCompose() will
    • execute oTAP.permit(usdo,oTAPTokenID)
    • exerciseOptionsReceiver(srcChainSender=alice,_options.from=alice,oTAPTokenID )
    • oTAP.revokePermit(oTAPTokenID)

The signature of oTAP.permit is public, allowing anyone to use it.

Note: if alice call approve(oTAPTokenID,usdo) in chain B without signature, but The same result

This opens up the possibility for malicious users to front-run use this signature. Let's consider an example with Bob:

  1. Bob in Chain A uses Alice's signature (v, r, s):
    • composeMsg = [oTAP.permit(usdo, oTAPTokenID, v, r, s), exerciseOptionsReceiver(oTAPTokenID, _options.from=bob)]-----> (Note: _options.from should be set to Bob.)
  2. In Chain B, when executing USDO.lzCompose(dstEid = B), the following actions occur:
    • Execute oTAP.permit(usdo, oTAPTokenID)
    • Execute exerciseOptionsReceiver(srcChainSender=bob, _options.from=bob, oTAPTokenID)

As a result, Bob gains unconditional access to this oTAPTokenID.

It is advisable to check the ownership of oTAPTokenID is _options.from before executing ITapiocaOptionBroker(_options.target).exerciseOption().

Impact

The exerciseOptionsReceiver() function lacks ownership checks for oTAP, allowing anyone to use oTAPTokenID.

Code Snippet

https://github.com/sherlock-audit/2024-02-tapioca/blob/main/Tapioca-bar/contracts/usdo/modules/UsdoOptionReceiverModule.sol#L67

Tool used

Manual Review

Recommendation

add check _options.from is owner or be approved

Diff
    function exerciseOptionsReceiver(address srcChainSender, bytes memory _data) public payable {

...
            uint256 bBefore = balanceOf(address(this));
+           address oTap = ITapiocaOptionBroker(_options.target).oTAP();
+           address oTapOwner = IERC721(oTap).ownerOf(_options.oTAPTokenID);
+           require(oTapOwner == _options.from
+                         || IERC721(oTap).isApprovedForAll(oTapOwner,_options.from)
+                         || IERC721(oTap).getApproved(_options.oTAPTokenID) == _options.from
+                        ,"invalid");
            ITapiocaOptionBroker(_options.target).exerciseOption(
                _options.oTAPTokenID,
                address(this), //payment token
                _options.tapAmount
            );
            _approve(address(this), address(pearlmit), 0);
            uint256 bAfter = balanceOf(address(this));

            // Refund if less was used.
            if (bBefore > bAfter) {
                uint256 diff = bBefore - bAfter;
                if (diff < _options.paymentTokenAmount) {
                    IERC20(address(this)).safeTransfer(_options.from, _options.paymentTokenAmount - diff);
                }
            }
        }

Discussion

sherlock-admin4

The protocol team fixed this issue in PR/commit https://github.com/Tapioca-DAO/Tapioca-bar/pull/360; https://github.com/Tapioca-DAO/TapiocaZ/pull/182.

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

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 function does not verify that the caller or the specified from address is the owner of the oTAPTokenID or has been approved to use it.

Impact

An attacker could use someone else's oTAPTokenID to exercise options and potentially gain the benefits, as long as the owner has approved USDO to use the token.

What the attacker needed

Owner has approved USDO to use oTAPTokenID; attacker can front-run the transaction

The fix

The function should check that _options.from is the owner of the oTAPTokenID or has been approved to use it before exercising the option.

How it was found

  1. Alice, the owner of oTAPTokenID, sends a cross-chain message that includes a permit for USDO to use her token and a call to exerciseOptionsReceiver with from set to Alice.
  2. Bob observes Alice's transaction and front-runs by sending his own cross-chain message using the same permit signature but with from set to Bob.
  3. Bob's message is processed first, executing the permit and then exerciseOptionsReceiver with Bob as the recipient, allowing Bob to use Alice's token.

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 bug where a function that exercises options on a token does not check who actually owns that token. If the real owner approves the contract to use their token, an attacker can quickly call the function first and set themselves as the beneficiary, stealing the benefit of the exercise.

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 bin2chen

View all

139 more disclosed reports, best first.

More from Tapioca

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.