Skip to content
Business logic Audit finding Intermediate

XC20Wrapper may lose received token forever if LocalAsset(xc20).mint is reverted indefinitely

Chom Follow

Originally disclosed on Code4rena

Submitted by Chom

XC20Wrapper.sol#L124-L126

XC20Wrapper may lose received token forever if LocalAsset(xc20).mint is reverted indefinitely.

Similar to ERC20, the spec said that if mint returns false it means minting is failed. But it is commonly revert instead of returning false which is also a minting failure. XC20 may revert on minting as well and common sense also guiding programmers to use the revert pattern instead of returning false.

This case is not handled if SC20 minting is reverted indefinitely. No matter how hard you retry the GMP message execution, it always fail thus the token get locked forever.

Proof of Concept

    function _executeWithToken(
        string calldata,
        string calldata,
        bytes calldata payload,
        string calldata tokenSymbol,
        uint256 amount
    ) internal override {
        address receiver = abi.decode(payload, (address));
        address tokenAddress = gateway().tokenAddresses(tokenSymbol);
        address xc20 = wrapped[tokenAddress];
        if (xc20 == address(0) || !LocalAsset(xc20).mint(receiver, amount)) {
            _safeTransfer(tokenAddress, receiver, amount);
        }
    }
  • Token is sent to gateway before executing the message on the destination chain.
  • If _executeWithToken fail, the token remain inside gateway. The only way to use that token is to execute the _executeWithToken succesfully.
  • Assume LocalAsset(xc20).mint(…) revert indefinitely, _executeWithToken also revert indefinitely.
  • As a result, _executeWithToken never success thus the tokens remain inside gateway forever.

Recommended Mitigation Steps

Use try catch

    function _executeWithToken(
        string calldata,
        string calldata,
        bytes calldata payload,
        string calldata tokenSymbol,
        uint256 amount
    ) internal override {
        address receiver = abi.decode(payload, (address));
        address tokenAddress = gateway().tokenAddresses(tokenSymbol);
        address xc20 = wrapped[tokenAddress];
        if (xc20 == address(0)) {
            _safeTransfer(tokenAddress, receiver, amount);
        }

        try LocalAsset(xc20).mint(receiver, amount) returns (bool success) {
            if (!success) _safeTransfer(tokenAddress, receiver, amount);
        } catch { _safeTransfer(tokenAddress, receiver, amount); }
    }

re1ro (Axelar) acknowledged and commented:

Mitigation We addressed the issue with introducing _safeMint function https://github.com/axelarnetwork/axelar-xc20-wrapper/pull/4

Alex the Entreprenerd (judge) commented:

The warden states that mint() may fail and cause a revert instead of returning false.

With the code in scope we can check the used ERC20 implementation and we find:

ERC20.sol#L187-L188

        if (account == address(0)) revert InvalidAccount();

Because a revert can happen, the scenario, which hypothetically would brick the functionality can actually happen.

We may also have reverts due to overflow and underflow.

Because the code is built to assume that no revert can happen, but the warden demonstrated how a revert could factually happen, I do agree with Medium Severity.

The sponsor has mitigated by using _safeMint.


The original report as published on Code4rena, by Chom. 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.

What is known

A medium-severity business logic bug in Axelar Network. Code4rena made it public on 6 October 2022. Found in the 2022-07-axelar audit contest (finding M-02).

About Business logic

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

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

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 Chom

View all

13 more disclosed reports, best first.

More from Axelar Network

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.