Skip to content
DoS Audit finding Intermediate

Bridged tokens would be lost if sender and receiver are contracts that don’t implement fallback/receive

The ERC20Vault contract always calls sendEther on the recipient address, even when the value is zero, causing a revert if the recipient is a contract without fallback or receive functions. This prevents bridged tokens from being received and also blocks recall attempts, leading to lost funds.

Shield Follow with Shield

Originally disclosed on Code4rena

Submitted by Shield, also found by Shield

When a bridged token is received on the dest chain, ERC20Vault.onMessageInvocation() is being called. onMessageInvocation() always calls to.sendEther(msg.value) even when the msg.value is zero. sendEther() would attempt to call the contract with the value supplied and empty data. If the to address ia a contract that doesn’t implement neither the fallback function nor receive then the entire transaction would revert.

The same issue occurs during recalling the message, if the sender is also a contract that doesn’t implement neither a fallback nor receive then the recalling would fail as well.

Impact

Funds would be lost, since the sending can’t be finalized and recovering would revert as well.

While this might be considered a user error when sending a value that’s greater than zero (they should’ve checked that the to address implements the receiver), this can’t be said about the case where the value is zero - the user won’t expect the vault to call the to contract with zero value.

Proof of Concept

Add the following PoC to test\tokenvault\ERC20Vault.t.sol:

Coded PoC

contract NoFallback{
    // other functions might be implemented here, but neither a fallback nor receive
}
    function test_noFallback()
        public
    {
        vm.startPrank(Alice);

        vm.chainId(destChainId);

        erc20.mint(address(erc20Vault));

        uint256 amount = 0;
        address to = address(new NoFallback());

        uint256 erc20VaultBalanceBefore = erc20.balanceOf(address(erc20Vault));
        uint256 toBalanceBefore = erc20.balanceOf(to);

        destChainIdBridge.sendReceiveERC20ToERC20Vault(
            erc20ToCanonicalERC20(destChainId),
            Alice,
            to,
            amount,
            bytes32(0),
            address(erc20Vault),
            srcChainId,
            0
        );

        uint256 erc20VaultBalanceAfter = erc20.balanceOf(address(erc20Vault));
        assertEq(erc20VaultBalanceBefore - erc20VaultBalanceAfter, amount);

        uint256 toBalanceAfter = erc20.balanceOf(to);
        assertEq(toBalanceAfter - toBalanceBefore, amount);
    }

    function test_20Vault_onMessageRecalled_20() public {
        Alice = address(new NoFallback());
        erc20.mint(Alice);

        vm.startPrank(Alice);

        uint256 amount = 2 wei;
        erc20.approve(address(erc20Vault), amount);

        uint256 aliceBalanceBefore = erc20.balanceOf(Alice);
        uint256 erc20VaultBalanceBefore = erc20.balanceOf(address(erc20Vault));

        IBridge.Message memory _messageToSimulateFail = erc20Vault.sendToken(
            ERC20Vault.BridgeTransferOp(
                destChainId, address(0), Bob, address(erc20), amount, 1_000_000, 0, Bob, ""
            )
        );

        uint256 aliceBalanceAfter = erc20.balanceOf(Alice);
        uint256 erc20VaultBalanceAfter = erc20.balanceOf(address(erc20Vault));

        assertEq(aliceBalanceBefore - aliceBalanceAfter, amount);
        assertEq(erc20VaultBalanceAfter - erc20VaultBalanceBefore, amount);

        // No need to imitate that it is failed because we have a mock SignalService
        bridge.recallMessage(_messageToSimulateFail, bytes(""));

        uint256 aliceBalanceAfterRecall = erc20.balanceOf(Alice);
        uint256 erc20VaultBalanceAfterRecall = erc20.balanceOf(address(erc20Vault));

        // Release -> original balance
        assertEq(aliceBalanceAfterRecall, aliceBalanceBefore);
        assertEq(erc20VaultBalanceAfterRecall, erc20VaultBalanceBefore);
    }

Output:

Failing tests:
Encountered 1 failing test in test/tokenvault/ERC20Vault.t.sol:TestERC20Vault
[FAIL. Reason: ETH_TRANSFER_FAILED()] test_20Vault_receive_erc20_canonical_to_dest_chain_transfers_from_canonical_token() (gas: 201153)

Failing tests:
Encountered 1 failing test in test/tokenvault/ERC20Vault.t.sol:TestERC20Vault
[FAIL. Reason: ETH_TRANSFER_FAILED()] test_20Vault_onMessageRecalled_20()

Recommended Mitigation Steps

  • Don’t call sendEther() when the value is zero

    • Or modify sendEther() to return when the value is zero
  • Find a solution for cases when the value is non-zero

    • This one is a bit more complicated, one way might be to allow the sender to request the ERC20 token while giving up on the ETH

dantaik (Taiko) confirmed and commented:

We have change the sendEther function such that if the amount is 0, there is no further action and the sendEther function simply returns.

If if default and receive functions are both unimplemented on the destination chain for the to address, then the owner can fail the message with retryMessage({…, _lastAttemp=true}); >or use failMessage(…) , then on the source chain, the owner can call recallMessage to get back his tokens.

At the end of the day, the user must trust the dapp that use our Bridge to set the right message parameters.


The original report as published on Code4rena, by Shield. 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 contract unconditionally calls sendEther on the recipient, even for zero value, without checking if the recipient can accept native currency.

Impact

Funds could be lost because the sending cannot be finalized and recovery would also revert.

What the attacker needed

Recipient is a contract without fallback/receive; sender is a contract without fallback/receive (for recall)

The fix

The sendEther function was changed to return immediately if the amount is zero, and the owner can fail the message and recall tokens on the source chain.

How it was found

  1. Deploy a contract without fallback or receive functions.
  2. Mint ERC20 tokens to the vault.
  3. Call sendReceiveERC20ToERC20Vault with the recipient as the contract and amount zero.
  4. Observe the transaction reverts with ETH_TRANSFER_FAILED.

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 you send tokens across chains, the receiving contract tries to send a small amount of the native currency (like ETH) to the recipient, even if that amount is zero. If the recipient is a smart contract that cannot accept native currency (because it lacks special functions to receive it), the whole transfer fails. This means the tokens get stuck and cannot be recovered.

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 Shield

View all

3 more disclosed reports, best first.

More from Taiko

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.