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.
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_msgfunction before the Chakra off-chain system with all the right parameters except for thepayload_type - since the
payload_typeis 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_typeis 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.
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
- Observe a cross-chain transaction being processed.
- Call receive_cross_chain_msg with all correct parameters except a different payload_type.
- The signature verification passes because payload_type is not in the hash.
- 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.