Skip to content
Business logic Audit finding Intermediate

Inconsistent Handler Validation Behavior in Cairo ERC20Handler’s Cross-Chain Callback

The Cairo ERC20Handler's cross-chain callback uses an assert to validate handlers, causing a revert if the handler is invalid or removed from the whitelist. This leaves transactions stuck in Pending, unlike the Solidity version which returns false and allows the settlement contract to mark the transaction as Failed.

0xNirix Follow with shaflow2, said and 2 others

Originally disclosed on Code4rena

Submitted by 0xNirix, also found by shaflow2, Draiakoo (1, 2), said, Abdessamed, and SBSecurity

Impact

The receive_cross_chain_callback function in the Cairo implementation of ERC20Handler uses an assert statement to validate handlers, which causes the function to revert if a handler is invalid or has been removed from the whitelist. This behavior differs from the Solidity implementation, which returns false for invalid handlers.

This vulnerability can lead to:

  1. Transactions remaining in a Pending state indefinitely in the Cairo implementation
  2. Inconsistent transaction states across different chain implementations
  3. Potential blocking of cross-chain operations
  4. Difficulty in handling and recovering from invalid handler scenarios

Proof of Concept

Cairo implementation:

    fn receive_cross_chain_callback(ref self: ContractState, cross_chain_msg_id: felt252, from_chain: felt252, to_chain: felt252,
        from_handler: u256, to_handler: ContractAddress, cross_chain_msg_status: u8) -> bool{
        assert(to_handler == get_contract_address(),'error to_handler');
        assert(self.settlement_address.read() == get_caller_address(), 'not settlement');
        assert(self.support_handler.read((from_chain, from_handler)) &&
                self.support_handler.read((to_chain, contract_address_to_u256(to_handler))), 'not support handler');

        // ... rest of the function
    }

Solidity implementation:

function receive_cross_chain_callback(
    uint256 txid,
    string memory from_chain,
    uint256 from_handler,
    CrossChainMsgStatus status,
    uint8 /* sign_type */,
    bytes calldata /* signatures */
) external onlySettlement returns (bool) {
    if (is_valid_handler(from_chain, from_handler) == false) {
        return false;
    }

    // ... rest of the function
}
  function processCrossChainCallback(
        uint256 txid,
        string memory from_chain,
        uint256 from_handler,
        address to_handler,
        CrossChainMsgStatus status,
        uint8 sign_type,
        bytes calldata signatures
    ) internal {
        require(
            create_cross_txs[txid].status == CrossChainMsgStatus.Pending,
            "Invalid transaction status"
        );

        if (
            ISettlementHandler(to_handler).receive_cross_chain_callback(
                txid,
                from_chain,
                from_handler,
                status,
                sign_type,
                signatures
            )
        ) {
            create_cross_txs[txid].status = status;
        } else {
            create_cross_txs[txid].status = CrossChainMsgStatus.Failed;
        }
    }

In the Cairo version, if a handler is invalid, the function will revert due to the assert statement, leaving the transaction in its current state (likely Pending). In contrast, the Solidity version returns false, allowing the calling Settlement contract to handle the invalid handler case appropriately.

Recommended Mitigation Steps

Update the Cairo implementation to check handler validity without using assert.

zvlwwj (Chakra) confirmed

0xsomeone (judge) increased severity to High


The original report as published on Code4rena, by 0xNirix. 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 uses an assert statement for handler validation, which reverts on failure, whereas the Solidity version returns false to signal invalid handlers without reverting.

Impact

Transactions may remain pending indefinitely, causing inconsistent states across chains and potentially blocking cross-chain operations.

What the attacker needed

Invalid or removed handler

The fix

The Cairo implementation should be updated to check handler validity without using assert, returning false instead.

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 a cross-chain message arrives, the handler checks if the sender and receiver are allowed. In the Cairo version, if they are not allowed, the whole check crashes (reverts) instead of politely saying 'no'. This means the transaction never gets marked as failed and stays pending forever, blocking further actions.

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 0xNirix

View all

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