Skip to content
Access control Audit finding Intermediate

twTAP.participate() can be permanently frozen due to lack of access control on host-chain-only operations

The twTAP contract lacks access control to restrict the participate() function to the host chain, allowing an attacker to mint a twTAP with a tokenId on a non-host chain and then transfer it to the host chain, where it is minted with the same tokenId. This causes the host chain's participate() to permanently revert when trying to mint that tokenId, freezing governance participation and reward claims.

peakbolt Follow

Originally disclosed on Code4rena

Submitted by peakbolt

twTAP is a omnichain NFT (ONFT721) that will be deployed on all supported chains.

However, there are no access control for operations meant for execution on the host chain only, such as participate(), which mints twTAP.

The implication of not restricting participate() to host chain is that an attacker can lock TAP and participate on other chain to mint twTAP with a tokenId that does not exist on the host chain yet. The attacker can then send that twTAP to the host chain using the inherited sendFrom(), to permanently freeze the twTAP contract as participate() will fail when attempting to mint an existing tokenId.

It is important to restrict minting to the host chain so that mintedTWTap (which keeps track of last minted tokenId) is only incremented at one chain, to prevent duplicate tokenId. That is because the twTAP contracts on each chain have their own mintedTWTap variable and there is no mechanism to sync them.

Detailed Explanation

In TwTAP, there are no modifiers or checks to ensure participte() can only be called on the host chain. So we can use it to mint a twTAP on a non-host chain. https://github.com/Tapioca-DAO/tap-token-audit/blob/59749be5bc2286f0bdbf59d7ddc258ddafd49a9f/contracts/governance/twTAP.sol#L252-L256

    function participate(
        address _participant,
        uint256 _amount,
        uint256 _duration
    ) external returns (uint256 tokenId) {
        require(_duration >= EPOCH_DURATION, "twTAP: Lock not a week");

The tokenId to be minted is determined by mintedTWTap, which is not synchronized across the chains.

https://github.com/Tapioca-DAO/tap-token-audit/blob/59749be5bc2286f0bdbf59d7ddc258ddafd49a9f/contracts/governance/twTAP.sol#L309-L310

    function participate(
        ...
        //@audit tokenId to mint is obtained from `mintedTWTap`
        tokenId = ++mintedTWTap;
        _safeMint(_participant, tokenId);

Suppose on host chain, the last minted tokenId is N. From a non-host chain, we can use sendFrom() to send over a twTAP with tokenId N+1 and mint a new twTAP with the same tokenId (see _creditTo() below). This will not increment mintedTWTap on the host chain, causing a de-sync.

<br>https:

    function _creditTo(uint16, address _toAddress, uint _tokenId) internal virtual override {
        require(!_exists(_tokenId) || (_exists(_tokenId) && ERC721.ownerOf(_tokenId) == address(this)));
        if (!_exists(_tokenId)) {
            //@audit transfering token N+1 will mint it as it doesnt exists. this will not increment mintedTwTap
            _safeMint(_toAddress, _tokenId);
        } else {
            _transfer(address(this), _toAddress, _tokenId);
        }
    }

On the host chain, participate() will always revert when it tries to mint the next twTAP with tokenId N+1, as it now exists on the host chain due to sendFrom().

https://github.com/Tapioca-DAO/tap-token-audit/blob/59749be5bc2286f0bdbf59d7ddc258ddafd49a9f/contracts/governance/twTAP.sol#L309-L310

    function participate(
        ...
        tokenId = ++mintedTWTap;
        //@audit this will always revert when tokenId already exists
        _safeMint(_participant, tokenId);

Impact

An attacker will be able to permanent freeze the twTAP.participate(). This will prevent TAP holders from participating in the governance and from claiming rewards, causing loss of rewards to users.

Proof of Concept

Consider the following scenario,

  1. Suppose we start with twTAP.mintedTwTap == 0 on all the chains, so next tokenId will be 1.
  2. Attacker participate() with 1 TAP and minttwTAP on a non-host chain with tokenId 1.
  3. Attacker sends the minted twTAP across to host chain using twTAP.sendFrom() to permanently freeze the twTAP contract.
  4. On the host chain, the twTAP contract receives the cross chain message and mint a twTAP with tokenId 1 to attacker as it does not exist on host chain yet. (Note this cross-chain transfer is part of Layer Zero ONFT71 mechanism)
  5. Now on the host chain, we have a twTAP with tokenId 1 but mintedTwTap is still 0. That means when users try to participate() on the host chain, it will try to mint a twTAP with tokenId 1, and that will fail as it now exists on the host chain. At this point participate() will be permanently DoS, affecting governance and causing loss of rewards.
  6. Note that the attacker can then transfer the twTAP back to the source chain and exit position to retrieve the locked TAP token. However, the host chain still remain frozen as the owner of tokenId 1 will now be twTAP contract itself after the cross chain transfer.

Note that the attack is still possible even when mintedTwTap > 0 on host chain as attacker just have to repeatly mint on the non-host chain till it obtain the required tokenId.

Recommended Mitigation Steps

Add in access control to prevent host-chain-only operations such as participate() from being executed on other chains .

0xRektora (Tapioca) confirmed


The original report as published on Code4rena, by peakbolt. 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 lack of access control to restrict the participate() function to the host chain, combined with unsynchronized mintedTWTap counters across chains, allows duplicate tokenIds to be created on the host chain via cross-chain transfers.

What the attacker needed

Attacker has TAP tokens to lock; twTAP deployed on multiple chains; attacker can call participate() on non-host chain; attacker can send twTAP cross-chain

The fix

Add access control to prevent host-chain-only operations such as participate() from being executed on other chains.

How it was found

  1. Attacker calls participate() on a non-host chain to mint a twTAP with a tokenId that does not yet exist on the host chain.
  2. Attacker sends the minted twTAP to the host chain using sendFrom().
  3. On the host chain, the twTAP contract mints the same tokenId to the attacker because it does not exist there yet.
  4. Now the host chain has a twTAP with that tokenId but mintedTWTap is not incremented, so future participate() calls try to mint the same tokenId and revert.

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.

The twTAP contract is like a membership card that can be moved between different blockchains. The problem is that the function to create a new card (participate) can be called on any blockchain, not just the main one. An attacker can create a card on a side blockchain with a number that hasn't been used yet on the main blockchain, then move it to the main blockchain. This makes the main blockchain think that number is taken, so it can never create a new card with that number, blocking everyone from joining.

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 peakbolt

View all

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