Skip to content
Business logic Audit finding Intermediate

A cross-chain message can be initiated with invalid parameters

The Cairo implementation of the cross-chain ERC20 settlement function lacks validation for the amount, recipient, handler, and token addresses, unlike its Solidity counterpart. An attacker could initiate settlements with zero or invalid parameters, wasting validator resources or causing transfers to revert.

Tigerfrake Follow with SBSecurity, 0xAsen and 12 others

Originally disclosed on Code4rena

Submitted by Tigerfrake, also found by SBSecurity, 0xAsen, blackpanther, Abdessamed, 0xb0k0, avoloder, DPS, agent3bood, ABAIKUNANBAEV, peanuts, calfun0x, ZdravkoHr, 0xNirix, and haxatron

Impact

Anyone can initiate a cross-chain ERC20 settlement with invalid parameters, breaking an invariant due to missing validations.

For example if these values are non-existent or zero values, it would boil down to the following:

  • zero amount ---> Only wastes validators resources by signing the msgHash at destination only for zero tokens to be minted/unlocked to the recipient
  • zero t0 ---> If this translates to address(0), the transfer mechanism used during unlocking will revert
  • zero to_token ---> Recipients will expect to receive tokens at destination but if this token specified is non-existent, they wont receive any.

Proof of Concept

One of the Main Invariants in Settlement Handler Contract is:

Cross-chain ERC20 settlements can only be initiated with a valid amount (greater than 0), a valid recipient address, a valid handler address, and a valid token address.

This is enforced in ChakraSettlementHandler::cross_chain_erc20_settlement() as follows:

        require(amount > 0, "Amount must be greater than 0");
        require(to != 0, "Invalid to address");
        require(to_handler != 0, "Invalid to handler address");
        require(to_token != 0, "Invalid to token address");

However, this is not enforced in handler_erc20::cross_chain_erc20_settlement():

        fn cross_chain_erc20_settlement(ref self: ContractState, to_chain: felt252, to_handler: u256, to_token: u256, to: u256, amount: u256) -> felt252{
            assert(self.support_handler.read((to_chain, to_handler)), 'not support handler');
            let settlement = IChakraSettlementDispatcher {contract_address: self.settlement_address.read()};
            let from_chain = settlement.chain_name();
            let token = IERC20Dispatcher{contract_address: self.token_address.read()};
            let token_burnable = IERC20MintDispatcher{contract_address: self.token_address.read()};
            if self.mode.read() == SettlementMode::MintBurn{
                token.transfer_from(get_caller_address(), get_contract_address(), amount);
            }else if self.mode.read() == SettlementMode::LockMint{
                token.transfer_from(get_caller_address(), get_contract_address(), amount);
            }else if self.mode.read() == SettlementMode::BurnUnlock{
                token_burnable.burn_from(get_caller_address(), amount);
            }else if self.mode.read() == SettlementMode::LockUnlock{
                token.transfer_from(get_caller_address(), get_contract_address(), amount);
            }

            ---SNIP---
        }

As seen, the function only checks for handler validity but performs no validations for to_token, to, and amount.

Recommended Mitigation Steps

Add the following checks to the cross_chain_erc20_settlement() function in handler_erc20:

+       assert(amount > 0, 'Amount must be greater than 0');
+       assert(to != 0, 'Invalid to address');
+       assert(to_handler != 0, 'Invalid to handler address');
+       assert(to_token != 0, 'Invalid to token address');

zvlwwj (Chakra) confirmed

0xsomeone (judge) commented:

The Warden has identified that the Cairo implementation of the cross-chain EIP-20 settlement function deviates from its specification and Solidity counterpart in the way it validates several input arguments.

I believe a medium-risk severity rating is appropriate given that no substantial impact has been demonstrated beyond a specification deviation.


The original report as published on Code4rena, by Tigerfrake. 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 Cairo implementation of cross_chain_erc20_settlement omits the input validation present in the Solidity version.

Impact

An attacker could initiate cross-chain settlements with invalid parameters, wasting validator resources or causing transfers to revert, though no substantial impact beyond a specification deviation was demonstrated.

What the attacker needed

None

The fix

Add checks to the Cairo function to ensure amount > 0, to != 0, to_handler != 0, and to_token != 0.

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.

This is a smart contract bug where one version of a function (written in Cairo) forgot to check that the amount and addresses are valid, while another version (in Solidity) does check them. Without these checks, someone could start a cross-chain transfer with zero tokens or a zero address, which wastes processing power or makes the transfer fail.

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 Tigerfrake

View all

4 more disclosed reports, best first.

More from Chakra

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.