Skip to content
DoS Audit finding Intermediate

The governance will fail to add an ecosystem token if someone creates a hToken that uses that ecosystem token

Anyone can create a local token whose underlying asset is an ecosystem token before governance adds it, causing the mapping to be set. When governance later calls addEcosystemToken, the transaction reverts because the check sees a non-zero address, preventing the ecosystem token from being added.

Arz Follow

Originally disclosed on Code4rena

Submitted by Arz

Ecosystem tokens are tokens that don’t have an underlying token address in any branch and only the global representation exists. The governance adds them by calling addEcosystemToken() where the _ecoTokenGlobalAddress will be the Maia or Hermes token, as the sponsor mentioned, or any other tokens that could be added in the future.

The problem is that anyone can create a hToken where the underlying asset is the ecosystem token and then this mapping will get updated in setAddresses():

https://github.com/code-423n4/2023-09-maia/blob/f5ba4de628836b2a29f9b5fff59499690008c463/src/RootPort.sol#L252

252:  getLocalTokenFromUnderlying[_underlyingAddress][_srcChainId] = _localAddress;

The _underlyingAddress equals to the _ecoTokenGlobalAddress and when the admin calls addEcosystemToken(), it will then revert because of this check that is incorrect:

https://github.com/code-423n4/2023-09-maia/blob/f5ba4de628836b2a29f9b5fff59499690008c463/src/RootPort.sol#L493

493:   if (getLocalTokenFromUnderlying[_ecoTokenGlobalAddress][localChainId] != address(0)) {
494:       revert AlreadyAddedEcosystemToken();
495:   }

getLocalTokenFromUnderlying[_ecoTokenGlobalAddress] will not be a zero address because it was set when the attacker added the hToken.

The check here is redundant. Even if someone creates a hToken where the underlying asset will be the ecosystem token, it will not be tied to the ecosystem token in any way, as it has a different global address and a different local address.

Impact

The governance will fail to add the ecosystem tokens. They will not work with this part of Ulysses because an attacker can easily create a hToken before the ecosystem token is set.

Proof of Concept

Add this to RootTest.t.sol

function testAddEcosystemTokenAttack() public {
        //arbitrumMockToken will be the Maia or Hermes token
        hevm.deal(address(this), 1 ether);

        //Attacker adds the Maia or Hermes token
        arbitrumCoreRouter.addLocalToken{value: 0.0005 ether}(
            address(arbitrumMockToken), GasParams(0.5 ether, 0.5 ether)
        );

        newArbitrumAssetGlobalAddress =
            RootPort(rootPort).getLocalTokenFromUnderlying(address(arbitrumMockToken), rootChainId);

        require(
            RootPort(rootPort).getGlobalTokenFromLocal(address(newArbitrumAssetGlobalAddress), rootChainId)
                == address(newArbitrumAssetGlobalAddress),
            "Token should be added"
        );
        require(
            RootPort(rootPort).getLocalTokenFromGlobal(newArbitrumAssetGlobalAddress, rootChainId)
                == address(newArbitrumAssetGlobalAddress),
            "Token should be added"
        );
        require(
            RootPort(rootPort).getUnderlyingTokenFromLocal(address(newArbitrumAssetGlobalAddress), rootChainId)
                == address(arbitrumMockToken),
            "Token should be added"
        );

        //The admin will then fail to add an ecosystem token because the tx reverts
        rootPort.addEcosystemToken(address(arbitrumMockToken));

    }

As you can see here, the tx reverts because of that check and the admin will fail to add the ecosystem token.

Tools Used

Foundry

Recommended Mitigation Steps

Remove this check as it’s redundant, as setting the ecosystem tokens when initializing is not the best solution because other tokens can be added in the future.

if (getLocalTokenFromUnderlying[_ecoTokenGlobalAddress][localChainId] != address(0)) {
     revert AlreadyAddedEcosystemToken();
}

Assessed type

DoS

0xBugsy (Maia) disputed and commented:

If the token has not yet been added to the system, a new one can simply be deployed. In addition, this can be done in a multicall paired with the token deployment itself for added security. Removing this check would lead to added governance power / responsibility.

alcueca (judge) commented:

Regardless of the mitigation, which might not be great, the issue is that if an ecosystem token is not set, an attacker can add it as an underlying of some other token. Then, it will not be possible to set it anymore as a global address (because the ecosystem token already is an underlying token).

0xLightt (Maia) commented:

The attacker would have to act between token deployment and adding it as an ecosystem token. The only way for that to happen would need to come from a governance/setup mistake.

The check cannot be overridden if there is any deposits of that underlying or there would be funds lost. Mitigation could be improved by this, allowing an ecosystem token to override a global token if its total supply is zero. This way, any mistake can be circumvented without any redeployment (if the ecosystem token is not distributed yet) and our setup can be more flexible.

alcueca (judge) commented:

Adding an ecosystem token immediately after creation is not obvious, or in the documentation. This is then a valid DoS attack, which you can mitigate with careful governance.

0xLightt (Maia) confirmed, but disagreed with severity and commented:

Updated review and feedback to reflect our opinion on this issue.

0xBugsy (Maia) commented:

Addressed here.

Note: For full discussion, see here.


The original report as published on Code4rena, by Arz. 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 check in addEcosystemToken incorrectly assumes that if a local token exists for the ecosystem token's global address, the ecosystem token has already been added, but that mapping can be populated by anyone creating a local token with that underlying.

What the attacker needed

Ecosystem token not yet added; attacker can call addLocalToken

The fix

The check should be removed or improved to allow an ecosystem token to override a global token if its total supply is zero, as suggested in the discussion.

How it was found

  1. Attacker calls addLocalToken on a core router, specifying the ecosystem token as the underlying asset.
  2. This sets getLocalTokenFromUnderlying for the ecosystem token's address.
  3. Later, governance calls addEcosystemToken for that token.
  4. The call reverts because the check finds a non-zero local token address.

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 project has a special kind of token (ecosystem token) that only exists globally, not on each chain. The system lets anyone create a local version of a token by specifying its underlying asset. If someone creates a local token using the ecosystem token as the underlying before the project officially adds the ecosystem token, a record is set. Later, when the project tries to add the ecosystem token, a safety check sees that record and blocks the addition, so the ecosystem token can never be used.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by Arz

View all

4 more disclosed reports, best first.

More from Maia DAO - Ulysses

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.