Skip to content
DoS Audit finding Advanced

Cross msg recipient can block checkpoint submission

A cross-message recipient contract can return a very large amount of data from a low-level call, causing the caller to copy it into memory and consume all available gas. This can block checkpoint submission entirely.

SBSecurity Follow

Originally disclosed on Code4rena

Submitted by SBSecurity

As mentioned in the natspec of LibGateway::executeCrossMsg:

/// @dev Execute the cross message using low level `call` method. This way ipc will
    ///      catch contract revert messages as well. We need this because in `CrossMsgHelper.execute`
    ///      there are `require` and `revert` calls, without reflexive call, the execution will
    ///      revert and block the checkpoint submission process.

However there’s a still way to block the checkpoint submission entirely. Since the low level call is used, the returndata of the call can be used from the target to return gas bomb the execution of all the messages entirely. As we know, it’s impossible to have blockchain without gas limit as this will break the Turing Completeness. With that in mind, the attacker can construct various payloads, depending on the gas limit of chain and deplete it entirely.

Proof of Concept

Let’s take a look at how low level call is done in Recall. We have LibGateway::executeCrossMsg, which does delegate call to CrossMsgHelper::execute and when the IpcMsgKind is Call recipient is called:

CrossMsgHelper.sol

function execute(
        IpcEnvelope calldata crossMsg,
        Asset memory supplySource
    ) public returns (bool success, bytes memory ret) {
        if (isEmpty(crossMsg)) {
            revert CannotExecuteEmptyEnvelope();
        }

        address recipient = crossMsg.to.rawAddress.extractEvmAddress().normalize();
        if (crossMsg.kind == IpcMsgKind.Transfer) {
            return supplySource.transferFunds({recipient: payable(recipient), value: crossMsg.value});
        } else if (crossMsg.kind == IpcMsgKind.Call || crossMsg.kind == IpcMsgKind.Result) {
            // For a Result message, the idea is to perform a call as this returns control back to the caller.
            // If it's an account, there will be no code to invoke, so this will behave like a bare transfer.
            // But if the original caller was a contract, this give it control so it can handle the result

            // send the envelope directly to the entrypoint
            // use supplySource so the tokens in the message are handled successfully
            // and by the right supply source
            return
                supplySource.performCall(
                    payable(recipient),
                    abi.encodeCall(IIpcHandler.handleIpcMessage, (crossMsg)),
                    crossMsg.value
                );
        }
        return (false, EMPTY_BYTES);
    }

AssetHelper.sol

function performCall(
        Asset memory asset,
        address payable target,
        bytes memory data,
        uint256 value
    ) internal returns (bool success, bytes memory ret) {
        // If value is zero, we can just go ahead and call the function.
        if (value == 0) {
            return functionCallWithValue(target, data, 0);
        }

        // Otherwise, we need to do something different.
        if (asset.kind == AssetKind.Native) {
            // Use the optimized path to send value along with the call.
            (success, ret) = functionCallWithValue({target: target, data: data, value: value});
        } else if (asset.kind == AssetKind.ERC20) {
            (success, ret) = functionCallWithERC20Value({asset: asset, target: target, data: data, value: value});
        }
        return (success, ret);
    }

    /// @dev Performs the function call with ERC20 value atomically
function functionCallWithERC20Value(
        Asset memory asset,
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bool success, bytes memory ret) {
        // Transfer the tokens first, _then_ perform the call.
        (success, ret) = ierc20Transfer(asset, target, value);

        if (success) {
            // Perform the call only if the ERC20 was successful.
            (success, ret) = functionCallWithValue(target, data, 0);
        }

        if (!success) {
            // following the implementation of `openzeppelin-contracts/utils/Address.sol`
            if (ret.length > 0) {
                assembly {
                    let returndata_size := mload(ret)
                    // see https://ethereum.stackexchange.com/questions/133748/trying-to-understand-solidity-assemblys-revert-function
                    revert(add(32, ret), returndata_size)
                }
            }
            // disable solhint as the failing call does not have return data as well.
            /* solhint-disable reason-string */
            revert();
        }
        return (success, ret);
    }

function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bool success, bytes memory) {
        if (address(this).balance < value) {
            revert NotEnoughBalance();
        }

        if (!isContract(target)) {
            revert InvalidSubnetActor();
        }

        return target.call{value: value}(data);
    }

As we see, there’s no restriction on the returndata size and it’s always being loaded into memory, no matter the outcome.

When the msg kind is Transfer, the attack is even easier, since native supply source is sent directly to the contract and the attacker can have custom logic in his receive function to scale and return the payload which is guaranteed to consume all the gas up to the limit.

AssetHelper.sol

function transferFunds(
        Asset memory asset,
        address payable recipient,
        uint256 value
    ) internal returns (bool success, bytes memory ret) {
        if (asset.kind == AssetKind.Native) {
            success = sendValue(payable(recipient), value);
            return (success, EMPTY_BYTES);
        } else if (asset.kind == AssetKind.ERC20) {
            return ierc20Transfer(asset, recipient, value);
        }
    }

function sendValue(address payable recipient, uint256 value) internal returns (bool) {
        if (address(this).balance < value) {
            revert NotEnoughBalance();
        }
        (bool success, ) = recipient.call{value: value}("");
        return success;
    }

The caveat here is that no matter the return value is omitted, it’s still getting loaded into memory implicitly. Only assembly calls won’t load it into memory, unless not manually.

Recommended mitigation steps

Consider using ExcessivelySafeCall for all the low level calls and restrict them.

Recall disputed


The original report as published on Code4rena, by SBSecurity. 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 low-level call copies the full return data into memory without limiting its size, so a recipient can force excessive memory expansion and gas consumption.

Impact

A cross-message recipient could block checkpoint submission by exhausting gas, though the report notes that only assembly calls avoid loading return data into memory.

What the attacker needed

Attacker controls a cross-message recipient contract; recipient can return large data or consume gas

The fix

The report recommends using a safe-call library such as ExcessivelySafeCall for all low-level calls and restricting the return data size.

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.

When one smart contract calls another, the called contract can send back data. If the caller copies all of that data into its own memory without a size limit, a malicious contract can send back so much data that the caller runs out of gas and fails. Here, that failure stops the whole checkpoint from being submitted.

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 SBSecurity

View all

8 more disclosed reports, best first.

More from Recall

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.