Skip to content
Business logic Audit finding Intermediate

Refunds to EOAs on unsuccessful cross-chain messages fail, leaving users’ funds stuck in the gateway

When a cross-chain transfer message sent by an externally owned account fails, the refund path tries to call the sender as if it were a contract, which reverts for plain accounts. The refund therefore never reaches the user and the funds stay trapped in the gateway contract.

muellerberndt Follow

Originally disclosed on Code4rena

Submitted by muellerberndt

https://github.com/code-423n4/2025-02-recall/blob/ab5f90b9b0322016ecce6dd71c528a935544bec5/contracts/contracts/lib/CrossMsgHelper.sol#L173-L208

https://github.com/code-423n4/2025-02-recall/blob/ab5f90b9b0322016ecce6dd71c528a935544bec5/contracts/contracts/lib/AssetHelper.sol#L100-L120

https://github.com/code-423n4/2025-02-recall/blob/ab5f90b9b0322016ecce6dd71c528a935544bec5/contracts/contracts/lib/AssetHelper.sol#L162-L178

Finding description and impact

In IPC, EOAs send funds between subnets using the fund and fundWithToken functions which produce IpcMsgKind.Transfer messages. When a cross-net message fails, an error receipt is propagated back to the originating subnet, and the message value is refunded. However, the refund mechanism fails to refund EOAs when their cross-chain messages fail.

A sendReceipt function comment in LibGateway.sol reads:

/// Only `Call` messages trigger a receipt. Transfer messages should be directly
/// handled by the peer client to return the funds to the from address in the
/// failing network.

However, the actual code contradicts this. Both Call and Transfer messages trigger a receipt on failure.

function sendReceipt(IpcEnvelope memory original, OutcomeType outcomeType, bytes memory ret) internal {
    if (original.isEmpty()) {
        // This should not happen as previous validation should prevent empty messages arriving here.
        // If it does, we simply ignore.
        return;
    }

    // if we get a `Receipt` do nothing, no need to send receipts.
    // - And sending a `Receipt` to a `Receipt` could lead to amplification loops.
    if (original.kind == IpcMsgKind.Result) {
        return;
    }

    // commit the receipt for propagation
    // slither-disable-next-line unused-return
    commitValidatedCrossMessage(original.createResultMsg(outcomeType, ret));
}

We also don’t see an alternative mechanism for refunding users anywhere in the code. Another comment in CrossMsgHelper.sol says:

// 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 gives it control so it can handle the result

But the actual implementation uses AssetHelper.sol calls functionCallWithValue() to send tokens back to the original sender. This function reverts if the target address is not a contract. If the original sender is an EOA, the refund silently fails, leaving funds permanently trapped in the gateway contract.

Proof of Concept

The following test demonstrates the issue:

/// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity ^0.8.23;

import "forge-std/Test.sol";
import {IntegrationTestBase} from "./IntegrationTestBase.sol";
import {TestUtils} from "./helpers/TestUtils.sol";
import {BottomUpCheckpoint, IpcEnvelope, IpcMsgKind, CallMsg, OutcomeType, ResultMsg} from "../contracts/structs/CrossNet.sol";
import {ActivityHelper} from "./helpers/ActivityHelper.sol";
import {SubnetID, Subnet, IPCAddress, Asset, AssetKind} from "../contracts/structs/Subnet.sol";
import {SubnetIDHelper} from "../contracts/lib/SubnetIDHelper.sol";
import {FvmAddressHelper} from "../contracts/lib/FvmAddressHelper.sol";
import {GatewayFacetsHelper} from "./helpers/GatewayFacetsHelper.sol";
import {METHOD_SEND, EMPTY_BYTES} from "../contracts/constants/Constants.sol";
import {CrossMsgHelper} from "../contracts/lib/CrossMsgHelper.sol";

// Minimal subnet actor implementation for testing refunds
contract MinimalSubnetActor {
    function supplySource() external pure returns (Asset memory) {
        return Asset({kind: AssetKind.Native, tokenAddress: address(0)});
    }

    function collateralSource() external pure returns (Asset memory) {
        return Asset({kind: AssetKind.Native, tokenAddress: address(0)});
    }

    receive() external payable {}
}

contract ResultMessageRefundFailureTest is IntegrationTestBase {
    using GatewayFacetsHelper for address;
    using SubnetIDHelper for SubnetID;
    using CrossMsgHelper for IpcEnvelope;

    address private user;
    uint256 private constant TEST_AMOUNT = 5 ether;
    MinimalSubnetActor private subnetActor;

    function setUp() public virtual override {
        super.setUp();

        // Create test accounts
        user = makeAddr("user");

        // Fund the gateway diamond
        vm.deal(address(gatewayDiamond), 100 ether);

        // Give the user some funds
        vm.deal(user, 2 ether);

        // Deploy subnet actor
        subnetActor = new MinimalSubnetActor();

        // Give the subnet actor enough funds to provide circulating supply
        vm.deal(address(subnetActor), TEST_AMOUNT);

        // Register the subnet actor with enough circulating supply
        uint256 genesisCircSupply = TEST_AMOUNT;
        uint256 collateral = 0;

        vm.prank(address(subnetActor));
        address(gatewayDiamond).manager().register{value: genesisCircSupply}(genesisCircSupply, collateral);
    }

    function test_ResultMessage_RefundFailsForEOA() public {
        // Get network information
        SubnetID memory networkName = address(gatewayDiamond).getter().getNetworkName();
        SubnetID memory subnetId = networkName.createSubnetId(address(subnetActor));

        console.log("Subnet actor registered:", address(subnetActor));
        console.log("EOA address that should receive refund:", user);

        // Step 1: Create an original transfer message that would have been sent
        IpcEnvelope memory originalMsg = IpcEnvelope({
            kind: IpcMsgKind.Transfer,
            from: IPCAddress({
                subnetId: networkName,
                rawAddress: FvmAddressHelper.from(user)  // EOA as sender
            }),
            to: IPCAddress({
                subnetId: subnetId,
                rawAddress: FvmAddressHelper.from(address(0x123))  // Random destination
            }),
            value: TEST_AMOUNT,
            message: EMPTY_BYTES,
            localNonce: 0,
            originalNonce: 0
        });

        // Step 2: Create a result message that should refund the funds to the EOA
        ResultMsg memory resultMsg = ResultMsg({
            id: CrossMsgHelper.toTracingId(originalMsg),
            outcome: OutcomeType.SystemErr,
            ret: bytes("Test error")
        });

        // Step 3: Create the result envelope
        IpcEnvelope[] memory msgs = new IpcEnvelope[](1);
        msgs[0] = IpcEnvelope({
            kind: IpcMsgKind.Result,
            from: originalMsg.to,           // From the destination of original msg
            to: originalMsg.from,           // To the sender of original msg (the EOA)
            value: TEST_AMOUNT,             // Refund the original value
            message: abi.encode(resultMsg),
            localNonce: 0,
            originalNonce: 0
        });

        // Step 4: Create a checkpoint with the result message
        BottomUpCheckpoint memory checkpoint = BottomUpCheckpoint({
            subnetID: subnetId,
            blockHeight: 1,
            blockHash: keccak256("result_test"),
            nextConfigurationNumber: 0,
            msgs: msgs,
            activity: ActivityHelper.newCompressedActivityRollup(1, 1, bytes32(uint256(0)))
        });

        // Record balances before
        uint256 userBalanceBefore = user.balance;
        uint256 gatewayBalanceBefore = address(gatewayDiamond).balance;

        console.log("EOA balance before:", userBalanceBefore);
        console.log("Gateway balance before:", gatewayBalanceBefore);

        // Step 5: Commit the checkpoint which should attempt to process the Result message
        vm.prank(address(subnetActor));
        address(gatewayDiamond).checkpointer().commitCheckpoint(checkpoint);

        // Record balances after
        uint256 userBalanceAfter = user.balance;
        uint256 gatewayBalanceAfter = address(gatewayDiamond).balance;

        console.log("EOA balance after:", userBalanceAfter);
        console.log("Gateway balance after:", gatewayBalanceAfter);

        // Verify the refund failed - user's balance should not increase
        assertEq(userBalanceAfter, userBalanceBefore, "EOA balance should not change");

        // The gateway should still have the funds (they never left)
        assertEq(gatewayBalanceAfter, gatewayBalanceBefore, "Gateway balance should not change");

        console.log("The refund failed as expected: funds are still in the gateway and did not reach the EOA");
    }
}

Recommended mitigation steps

To fix this issue, add a code path that handles refunds to EOAs.

Recall confirmed


The original report as published on Code4rena, by muellerberndt. 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 refund logic uses a contract-call helper that reverts when the recipient has no code, instead of a plain transfer for externally owned accounts.

Impact

Refunds for failed cross-chain transfers from externally owned accounts do not happen, so users' funds remain stuck in the gateway contract.

What the attacker needed

A failed cross-chain transfer; sender is an externally owned account

The fix

The code should add a separate path that refunds externally owned accounts directly rather than through a contract call.

How it was found

  1. Create a transfer message whose sender is an externally owned account.
  2. Build a result message with a system error outcome that should refund the original value to that sender.
  3. Place the result message in a bottom-up checkpoint.
  4. Commit the checkpoint so the gateway processes the result message.
  5. Observe that the user's balance is unchanged and the gateway still holds the funds.

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 user sends money from one blockchain network to another through a gateway contract. If the transfer fails, the gateway is supposed to send the money back. The code that returns the money assumes the user is a smart contract, so for a normal wallet the return step fails and the money stays stuck in the gateway.

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 muellerberndt

View all

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

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.