code4rena-2022-04-axelar-m03

[M-03] _execute can potentially reorder a batch of commands while executing, breaking any assumptions on command orders

보고서

Summary

재진입을 통해 배치로 처리되는 작업의 실행 순서를 조작할 수 있다.

Keyword

reordering, reentrancy, replay attack, signature

Vulnerability

AxelarGatewayMultisig.execute 함수는 여러가지 커맨드를 배치로 실행한다.

각 커맨드는 고유한 commandId가 붙어있다. _execute 함수는 기존에 실행했던 commandId를 재시도하는 것을 허용한다(revert 하지 않는다).

if (isCommandExecuted(commandId)) continue; /* Ignore if duplicate commandId received */ 와 같이 이미 실행된 commandId를 그냥 넘기는 것을 볼 수 있다.

    function execute(bytes calldata input) external override {
        (bytes memory data, bytes[] memory signatures) = abi.decode(input, (bytes, bytes[]));
 
        _execute(data, signatures);
    }
 
    function _execute(bytes memory data, bytes[] memory signatures) internal {
        ...
 
        (
            uint256 chainId,
            Role signersRole,
            bytes32[] memory commandIds,
            string[] memory commands,
            bytes[] memory params
        ) = abi.decode(data, (uint256, Role, bytes32[], string[], bytes[]));
 
        ...
 
        for (uint256 i; i < commandsLength; i++) {
            bytes32 commandId = commandIds[i];
 
            if (isCommandExecuted(commandId)) continue; /* Ignore if duplicate commandId received */
 
            ...
 
            // Prevent a re-entrancy from executing this command before it can be marked as successful.
            _setCommandExecuted(commandId, true);
            (bool success, ) = address(this).call(abi.encodeWithSelector(commandSelector, params[i], commandId));
            _setCommandExecuted(commandId, success);
 
            if (success) {
                emit Executed(commandId);
            }
        }
    }

공격자는 배치 실행되는 커맨드의 실행 순서를 재배열할 수 있다. 재진입으로 execute 함수를 호출하면 원래 나중에 호출될 커맨드를 먼저 실행할 수 있다. 이를 통해 컨텍스트에 대한 가정(순서대로 실행될 것이란 가정)을 깨뜨릴 수 있다.

Impact

재진입을 통해 커맨드의 실행 순서를 조작할 수 있다.

Mitigation

execute 함수를 재진입 불가하게 한다. 또한 서명을 재전송할 수 없도록 nonce를 추가하라 했다.

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

Memo

High로 제출했지만 Medium으로 조정되었다.

주최자 측은 Axelar와 게이트웨이가 명령 실행 순서를 구체적으로 보장하지는 않으므로 순서를 섞는 취약점(reordering)이 논쟁의 여지가 있다 했다. 이를 악용하는 시나리오가 없기 때문에 Low 또는 non-risk 라고 주장했다.

심판은 위험도가 높은 문제는 아니지만, 재진입과 서명 재전송이 가능하기 때문에 이를 완화할 필요가 있다고 하며 Medium으로 낮췄다.


tags: bughunting, axelar, smart contract, solidity, reentrancy, replay attack, signature, severity medium