Skip to content
Business logic Audit finding Advanced

Failure in endpoint can cause minting more than one NFT with the same token id in different chains

A flaw in the cross-chain NFT bridging logic allows a user to end up with the same token ID on two different chains. This happens because a failed message is not marked as consumed, so it can be retried after the NFT has been bridged back, leading to duplicate minting.

HE1M Follow

Originally disclosed on Code4rena

Submitted by HE1M

In the contract GovNFT, it is possible to bridge the governance NFT to other chains. It is also stated in the document that:

NFT holders only earn the profits generated by the platform on the chain that the NFT is on.

It is assumed that there is only one unique NFT per token id. But there is a scenario that can lead to more than one NFT with the same token id on different chains.

Proof of Concept

  • Suppose Bob (honest user who owns an NFT with token id X on chain B) plans to bridge this NFT from chain B to chain A. So, Bob calls the function crossChain to bridge the NFT from chain B to chain A. Thus, his NFT will be burnt on chain B, and it is supposed to be minted on chain A.

https://github.com/code-423n4/2022-12-tigris/blob/588c84b7bb354d20cbca6034544c4faa46e6a80e/contracts/GovNFT.sol#L124

  • The endpoint is responsible for completing the bridging task on chain A.
  • Suppose the endpoint calls the function lzReceive with low gas on chain A, so that the transaction will be not successful.
function lzReceive(
        uint16 _srcChainId,
        bytes memory _srcAddress,
        uint64 _nonce,
        bytes memory _payload
    ) external override {
        require(_msgSender() == address(endpoint), "!Endpoint");
        (bool success, bytes memory reason) = address(this).excessivelySafeCall(gasleft()*4/5, 150, abi.encodeWithSelector(this.nonblockingLzReceive.selector, _srcChainId, _srcAddress, _nonce, _payload));
        // try-catch all errors/exceptions
        if (!success) {
            failedMessages[_srcChainId][_srcAddress][_nonce] = keccak256(_payload);
            emit MessageFailed(_srcChainId, _srcAddress, _nonce, _payload, reason);
        }
    }

https://github.com/code-423n4/2022-12-tigris/blob/588c84b7bb354d20cbca6034544c4faa46e6a80e/contracts/GovNFT.sol#L168

  • Since the transaction was not successful, the message will be added as a failed message.
failedMessages[chainB][Bob's address][_nonce] = keccak256(_payload);

https://github.com/code-423n4/2022-12-tigris/blob/588c84b7bb354d20cbca6034544c4faa46e6a80e/contracts/GovNFT.sol#L178

  • Then, due to network lag (or any server issue, or any failure in endpoint), the endpoint assumes that the transaction is not sent, and it again calls this function with enough gas, so, the NFT with token id X will be minted to Bob’s address on chain A. The flow is as follows:

lzReceive ==> nonblockingLzReceive ==> _nonblockingLzReceive ==> _bridgeMint

  • Now Bob has the NFT on chain A. Moreover, he has a failed message on chain A.
  • Then Bob calls the function crossChain to bridge that NFT from chain A to chain B. So, this NFT will be burnt on chain A, and minted to Bob’s address on chain B.
  • Now, Bob has the NFT with token id X on chain B. Moreover, he has a failed message on chain A.
  • He calls the function retryMessage to retry the failed message on chain A.

https://github.com/code-423n4/2022-12-tigris/blob/588c84b7bb354d20cbca6034544c4faa46e6a80e/contracts/GovNFT.sol#L206

  • By doing so the NFT with token id X will be minted to Bob on chain A. The flow is as follows:

retryMessage ==> _nonblockingLzReceive ==> _bridgeMint

  • Now Bob has the NFT with token id X on both chain A and chain B. This is the vulnerability.
  • Now he can, for example, sell the NFT on chain B while he is earning the profits generated by the platform on the chain A that the NFT is on.
  • Please note that Bob can not call the function retryMessage while he owns the NFT on chain A. Because during minting the NFT, it checks whether the token id exists or not. That is why Bob first bridges the NFT to another chain, and then retries the failed message.

The vulnerability is that when the message is failed, it is not considered as consumed, so in case of a failure in endpoint it is possible to have failed messages and be able to mint it at the same time.

Please note that if this scenario happens again, more NFTs with the same token id X will be minted to Bob on different chains.

Recommended Mitigation Steps

It is recommended to track the consumed messages, and add a consumed flag whenever the function lzReceive is called, because it will either immediately mint the NFT or add it to the failed messages to be minted later.

mapping(uint16 => mapping(bytes => mapping(uint64 => bool))) public consumedMessage;

    function lzReceive(
        uint16 _srcChainId,
        bytes memory _srcAddress,
        uint64 _nonce,
        bytes memory _payload
    ) external override {

        require(!consumedMessage[_srcChainId][_srcAddress][_nonce], "already consumed");
        consumedMessage[_srcChainId][_srcAddress][_nonce] = true;

        require(_msgSender() == address(endpoint), "!Endpoint");
        (bool success, bytes memory reason) = address(this).excessivelySafeCall(gasleft()*4/5, 150, abi.encodeWithSelector(this.nonblockingLzReceive.selector, _srcChainId, _srcAddress, _nonce, _payload));
        // try-catch all errors/exceptions
        if (!success) {
            failedMessages[_srcChainId][_srcAddress][_nonce] = keccak256(_payload);
            emit MessageFailed(_srcChainId, _srcAddress, _nonce, _payload, reason);
        }
    }

GainsGoblin (Tigris Trade) confirmed

Alex the Entreprenerd (judge) commented:

The Warden has shown a flaw in the FSM in lzReceive that, due to an unexpected revert, could cause the ability to have the same tokenId on multiple chains.

Because of it’s reliance on external conditions, I agree with Medium Severity.

GainsGoblin (Tigris Trade) resolved:

Mitigation: https://github.com/code-423n4/2022-12-tigris/pull/2#issuecomment-1419174114

This implementation of consumedMessage check returns instead of reverts. We don’t want it to revert because that would cause the message queue to be blocked.


The original report as published on Code4rena, by HE1M. 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 contract does not track whether a cross-chain message has already been processed, so a failed message can be retried after the NFT has been moved back, causing a duplicate mint.

Impact

A user could hold the same NFT on multiple chains, potentially earning profits on one chain while selling the NFT on another; the exploit relies on external conditions such as endpoint failure or network lag.

What the attacker needed

A user owns an NFT; endpoint failure or network lag occurs; user can call crossChain and retryMessage

The fix

The contract should track consumed messages and mark them as consumed when lzReceive is called, so that a failed message cannot be retried after the NFT has been minted.

How it was found

  1. Bob calls crossChain to bridge his NFT from chain B to chain A, burning it on chain B.
  2. The endpoint calls lzReceive with low gas on chain A, causing the transaction to fail and the message to be stored as failed.
  3. Due to network lag, the endpoint calls lzReceive again with enough gas, minting the NFT on chain A.
  4. Bob calls crossChain to bridge the NFT from chain A back to chain B, burning it on chain A and minting it on chain B.
  5. Bob calls retryMessage on chain A to retry the failed message, minting the NFT again on chain A.
  6. Bob now has the same token ID on both chain A and chain B.

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 report is about a system that lets you move a special digital collectible (an NFT) between different blockchains. Normally each NFT has a unique ID and should exist only once. The bug lets someone create a second copy of the same NFT on another chain by exploiting a failed transfer message that can be retried later.

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 HE1M

View all

14 more disclosed reports, best first.

More from Tigris Trade contest

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.