Skip to content
Race condition Audit finding Advanced

_execute can potentially reorder a batch of commands while executing, breaking any assumptions on command orders.

The execute function in AxelarGatewayMultisig is reentrant, allowing an attacker to reenter with the same batch of commands and cause later commands to execute before earlier ones finish. This breaks assumptions about command execution order and enables replay of commands.

rayn Follow

Originally disclosed on Code4rena

Submitted by rayn

AxelarGatewayMultisig.sol#L484 AxelarGatewayMultisig.sol#L490 AxelarGatewayMultisig.sol#L529

Since this is important, we quote it again instead of referring to our other bug report on a different, yet related bug. The context within which a command is executed is extremely important.

AxelarGatewayMultisig.execute() takes a signed batch of commands. Each command has a corresponding commandID. This is guaranteed to be unique from the Axelar network. execute intentionally allows retrying a commandID if the command failed to be processed; this is because commands are state dependent, and someone might submit command 2 before command 1 causing it to fail.

Thus if an attacker manages to rearrange execution order of commands within a batch, it should probably be treated seriously. This is exactly what might happen here due to reentrancy. A malicious player that managed to gain reentrancy over execute can easily execute later commands in a batch before earlier commands are fully executed, effectively breaking all assumptions on command executed context.

Proof of Concept

The _execute function and its wrapper execute are both reentrant.

    function execute(bytes calldata input) external override;
    function _execute(bytes memory data, bytes[] memory signatures) internal;

Thus if an attacker manages to reenter the _execute function with the same batch of commands and signatures, previously successfully executed and ongoing commands will be skipped due to premature marking of the success flag.

        if (isCommandExecuted(commandId)) continue; /* Ignore if duplicate commandId received */

This allows later commands to be executed before the current ongoing command is finished. The reentrant attack can be nested to perform further reordering of commands.

Generally speaking, other unrelated batches of signed commands can only be executed, but since the assumption of ordering is most likely stronger within a single batch, we focus on illustrating the single batch scenario above.

Tools Used

vim, ganache-cli

Recommended Mitigation Steps

Make execute nonReentrant

Add an ever increasing nonce to signatures to prevent replay

    function execute(bytes calldata input) nonReentrant external override {
        ...
    }

deluca-mike (Axelar) acknowledged, but disagreed with High severity and commented:

Axelar and the gateways make no concrete guarantees about command execution order, so the idea of “reordering” is moot. Currently, the only commands that call out are:

  • deploy a token (so its order is irrelevant)
  • minting a token (and thus a call to the token contract will not re-enter, since it is either one the gateway deployed, or the gateway onboarded a malicious external ERC2, which still has no effect on the other tokens)
  • burn a token (same as above)

As with the other issue, while we do acknowledge that the contestant has correctly pointed out how the gateway handles (and can re-handle) commands, this is a low-risk (or no-risk) issue, since no actual risk has been demonstrated apart from “maybe, somehow, possibly, it could be abused”. We’d need at least some feasible and concrete hypothetical or example.

0xean (judge) decreased severity to Medium and commented:

I am going to side with the warden on this but downgrade to medium severity. The transaction ordering is not the high risk issue, but the ability for re-entrancy and thus replay presents a risk that should be mitigated.

Looking at other recent hacks ( for example - https://rekt.news/agave-hundred-rekt/ ), new environments pose new risks for re-entrancy to appear and with the point of this protocol being to extend across many chains, added additional measures to avoid re-entrancy and the replay that could occur as a result seems like a very logical choice. 2 — Med: Assets not at direct risk, but the function of the protocol or its availability could be impacted, or leak value with a hypothetical attack path with stated assumptions, but external requirements.


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

The execute function lacks a reentrancy guard, allowing it to be called again before completion and causing commands to be skipped or reordered.

Impact

An attacker could reorder commands within a batch, potentially replaying commands or breaking execution order assumptions, though the protocol does not guarantee order and no concrete exploit was demonstrated.

What the attacker needed

Attacker can call execute; attacker can reenter during execution

The fix

The execute function should be made non-reentrant, for example by adding a nonReentrant modifier, and signatures should include an increasing nonce to prevent replay.

How it was found

  1. An attacker calls execute with a batch of commands.
  2. During execution, the attacker reenters execute with the same batch.
  3. The reentrant call skips already executed commands and executes later ones first.
  4. The attacker can nest reentrant calls to further reorder commands.

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 smart contract function can be reentered if it calls another contract before finishing its own work. Here, an attacker could call the execute function again while it is still running, causing commands to run out of order. This could let someone replay commands or skip steps, though the impact is limited because the protocol does not guarantee order.

What is Race condition?

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.

More by rayn

View all

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

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.