Skip to content
Smart contracts Audit finding Intermediate

Settlement contract is mistakenly used for the handler contract when assigning ReceivedCrossChainTx struct

The settlement contract's receive_cross_chain_msg function stores the settlement contract's own address in the to_handler field of the ReceivedCrossChainTx struct instead of the intended handler address. This means the recorded cross-chain transaction data is wrong, though the text does not show a concrete exploit beyond the incorrect record.

ABAIKUNANBAEV Follow with AllTooWell, rbserver and 4 others

Originally disclosed on Code4rena

Submitted by ABAIKUNANBAEV, also found by AllTooWell, rbserver, said, Abdessamed, Draiakoo, and 0xNirix

Impact

receive_cross_chain_msg() is located in the Settlement contract and is called after the Chakra network signature verification process. However, when creating ReceivedCrossChainTx struct for the new receive_cross_txs[txid], the contract mistakenly uses address(this) instead of to_handler address.

Proof of Concept

Currently receive_cross_txs[txId] is assigned this way:

https://github.com/code-423n4/2024-08-chakra/blob/main/solidity/settlement/contracts/ChakraSettlement.sol#L205-214

 receive_cross_txs[txid] = ReceivedCrossChainTx(
            txid,
            from_chain,
            contract_chain_name,
            from_address,
            from_handler,
            address(this),
            payload,
            CrossChainMsgStatus.Pending
        );

However, address(this) should be replaced by to_handler:

https://github.com/code-423n4/2024-08-chakra/blob/main/solidity/settlement/contracts/ChakraSettlement.sol#L31-40

struct ReceivedCrossChainTx {
        uint256 txid;
        string from_chain;
        string to_chain;
        uint256 from_address;
        uint256 from_handler;
        address to_handler;
        bytes payload;
        CrossChainMsgStatus status;
    }

As you can see here, after from_handler, there is to_handler address but it’s mistakenly set as address(this) which is an address of the settlement contract in reality.

Therefore, receive_cross_txs[txid] has incorrect parameters when creating a new received transaction struct.

Recommended Mitigation Steps

Change address(this) on to_handler address in a receive_cross_txs[txid] mapping.

pidb (Chakra) confirmed

0xsomeone (judge) commented:

The Warden has identified that the ChakraSettlement::receive_cross_chain_msg function will improperly store a cross-chain message and will specifically store the to_handler address incorrectly.

The impact of this particular submission is not able to be identified properly and, given that the function appears to be invoked as the last step in a cross-chain process, a severity of medium is considered appropriate as it should not impact the actual processing of the cross-chain transaction.


The original report as published on Code4rena, by ABAIKUNANBAEV. 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 a copy-paste or argument-order mistake: the struct field for the destination handler was filled with the settlement contract's own address rather than the to_handler parameter.

Impact

The stored cross-chain transaction has an incorrect to_handler value; the judge notes the real impact could not be determined and rated it medium because the function runs as the last step of the process.

What the attacker needed

Cross-chain message reaches settlement contract

The fix

The mapping assignment should use the to_handler address instead of address(this).

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 smart contract keeps a record of each cross-chain message it receives. When filling in that record, the code put its own address where the address of the receiving handler should go. So the saved record points at the wrong contract, which could confuse anything that later reads it.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by ABAIKUNANBAEV

View all

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

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.