Skip to content
Business logic Audit finding Intermediate

In settlement.cairo::receive_cross_chain_msg - the payload_type can be passed by the user, confusing offchain systems

The receive_cross_chain_msg function in a Cairo settlement contract accepts a payload_type parameter that is not included in the signed message hash, so an attacker can call the function with a different payload_type while still passing signature verification. This causes off-chain systems that listen to the emitted event to receive incorrect information about the payload type.

0xAsen Follow with klau5 and fyamf

Originally disclosed on Code4rena

Submitted by 0xAsen, also found by klau5 and fyamf

Impact

In settlement.cairo::receive_cross_chain_msg - the payload_type can be passed by the user, confusing offchain systems.

The payload_type parameter is only used to emit events so that the Chakra nodes can detect and process them.

There is no validation for it and given that it is used in an event to which off-chain systems listen to, the payload_type values will be displayed in the explorer, and there may be other extensions in the future, according to the sponsor.

This can lead to incorrect data being displayed and undefined behavior in the future.

Proof of Concept

Let’s see the code of receive_cross_chain_msg:

            fn receive_cross_chain_msg(
                ref self: ContractState,
                cross_chain_msg_id: u256,
                from_chain: felt252,
                to_chain: felt252,
                from_handler: u256,
                to_handler: ContractAddress,
                sign_type: u8,
                signatures: Array<(felt252, felt252, bool)>,
                payload: Array<u8>,
                payload_type: u8, <---
            ) -> bool {
                assert(to_chain == self.chain_name.read(), 'error to_chain');

                // verify signatures
                let mut message_hash: felt252 = LegacyHash::hash(from_chain, (cross_chain_msg_id, to_chain, from_handler, to_handler));
                let payload_span = payload.span();
                let mut i = 0;
                loop {
                    if i > payload_span.len()-1{
                        break;
                    }
                    message_hash = LegacyHash::hash(message_hash, * payload_span.at(i));
                    i += 1;
                };
                self.check_chakra_signatures(message_hash, signatures);

                // call handler receive_cross_chain_msg
                let handler = IHandlerDispatcher{contract_address: to_handler};
                let success = handler.receive_cross_chain_msg(cross_chain_msg_id, from_chain, to_chain, from_handler, to_handler , payload);

                let mut status = CrossChainMsgStatus::SUCCESS;
                if success{
                    status = CrossChainMsgStatus::SUCCESS;
                }else{
                    status = CrossChainMsgStatus::FAILED;
                }

                self.received_tx.write(cross_chain_msg_id, ReceivedTx{
                    tx_id:cross_chain_msg_id,
                    from_chain: from_chain,
                    from_handler: from_handler,
                    to_chain: to_chain,
                    to_handler: to_handler,
                    tx_status: status
                });

                // emit event
                self.emit(CrossChainHandleResult{
                    cross_chain_settlement_id: cross_chain_msg_id,
                    from_chain: to_chain,
                    from_handler: to_handler,
                    to_chain: from_chain,
                    to_handler: from_handler,
                    cross_chain_msg_status: status,
                    payload_type: payload_type <---
                });
                return true;
            }

You can see that the payload_type parameter is not used anywhere in the function except for the emission of the event.

So what could happen is:

  • a user or a bot sees the transaction being processed
  • calls the receive_cross_chain_msg function before the Chakra off-chain system with all the right parameters except for the payload_type
  • since the payload_type is not used in the message hash generation, the signatures verification and every other check passes successfully
  • the off-chain systems pick up wrong information from the event leading to corrupted information

Recommended Mitigation Steps

Include the payload_type in the message hash generation thus making sure that it’s value cannot be altered.

zvlwwj (Chakra) disputed and commented:

Only validator can call this function.

0xsomeone (judge) increased severity to High and commented:

The Warden has identified a mechanism via which the payload_type is not properly validated as having been signed by the Chakra team, permitting cross-chain messages to be received with a different payload type than the actual one.

I believe that a severity of high is appropriate as it should (in theory) result in a transaction being processed by the Cairo code but considered unfinished by the validator system.


The original report as published on Code4rena, by 0xAsen. 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 payload_type parameter is not included in the message hash that is signed, so its value is not authenticated.

Impact

Off-chain systems could process incorrect payload type information, leading to corrupted data and undefined behaviour in future extensions.

What the attacker needed

Ability to call receive_cross_chain_msg; valid signatures for the message

The fix

The payload_type should be included in the message hash generation so that its value cannot be altered.

How it was found

  1. Observe a cross-chain transaction being processed.
  2. Call receive_cross_chain_msg with all correct parameters except a different payload_type.
  3. The signature verification passes because payload_type is not in the hash.
  4. Off-chain systems read the emitted event with the wrong payload_type.

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 function receives cross-chain messages and checks that they were signed by trusted validators. However, one piece of information (the payload type) is not covered by that signature, so someone can change it without breaking the signature check. This means the event that off-chain systems rely on can show a wrong payload type.

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

View all

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