In settlement.cairo::receive_cross_chain_msg - the message will always be marked with Status::SUCCESS
The settlement contract marks every cross-chain message as successful because the handler's receive function always returns true. An attacker could send a corrupted message that still gets recorded as successful, breaking the protocol's status tracking invariant.
0xAsen Follow with shaflow2, ABAIKUNANBAEV and 2 others
Originally disclosed on Code4rena
Submitted by 0xAsen, also found by shaflow2, ABAIKUNANBAEV, SBSecurity, and Sabit
Impact
When receiving a message via the settlement.cairo::receive_cross_chain_msg() function, a call is made to handler.receive_cross_chain_msg and the return value of that call is used to mark the message with status SUCCESS or FAILED
However, the way that the handler.receive_cross_chain_msg function is implemented, it’ll always return true, therefore marking every message as successful even if the message for some reason was a corrupted one.
And breaking one of the main invariants that states the message statuses should be tracked correctly.
Proof of Concept
Let’s take a look at the code of the receive_cross_chain_msg function on the settlement.cairo contract, and specifically at the part where the call to handler.receive_cross_chain_msg is made:
fn receive_cross_chain_msg(/*params*/) -> bool {
//rest of the code
let success = handler.receive_cross_chain_msg(
cross_chain_msg_id,
from_chain, //from_chain
to_chain, //to_chain
from_handler, //from_handler
to_handler , //to_handler
payload //payload
);
let mut status = CrossChainMsgStatus::SUCCESS;
if success{
status = CrossChainMsgStatus::SUCCESS;
}else{
status = CrossChainMsgStatus::FAILED;
}
}
As you can see, the status of the messages is based on the return value of this line: success = handler.receive_cross_chain_msg.
Let’s see the handler.receive_cross_chain_msg function:
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,
payload: Array<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');
//i.e (from_chain, to_handler)
let message :Message= decode_message(payload);
let payload_type = message.payload_type;
assert(payload_type == PayloadType::ERC20, 'payload type not erc20');
let payload_transfer = message.payload;
let transfer = decode_transfer(payload_transfer);
assert(transfer.method_id == ERC20Method::TRANSFER, 'ERC20Method must TRANSFER');
let erc20 = IERC20MintDispatcher{contract_address: self.token_address.read()};
let token = IERC20Dispatcher{contract_address: self.token_address.read()};
// Handle the cross-chain transfer according to the settlement mode set in the contract.
if self.mode.read() == SettlementMode::MintBurn{
erc20.mint_to(u256_to_contract_address(transfer.to), transfer.amount);
}else if self.mode.read() == SettlementMode::LockMint{
erc20.mint_to(u256_to_contract_address(transfer.to), transfer.amount);
}else if self.mode.read() == SettlementMode::BurnUnlock{
token.transfer(u256_to_contract_address(transfer.to), transfer.amount);
}else if self.mode.read() == SettlementMode::LockUnlock{
token.transfer(u256_to_contract_address(transfer.to), transfer.amount);
}
return true;
}
As you can see, as long as the function doesn’t revert, it’ll always return true.
This shouldn’t be the case and if for some reason the message is a corrupted one, it should get marked as FAILED as intended by the protocol.
The functionality is correctly implemented in the solidity version:
function receive_cross_chain_msg(
uint256 /**txid */,
string memory from_chain,
uint256 /**from_address */,
uint256 from_handler,
PayloadType payload_type,
bytes calldata payload,
uint8 /**sign type */,
bytes calldata /**signaturs */
) external onlySettlement returns (bool) {
if (is_valid_handler(from_chain, from_handler) == false) {
return false;
}
bytes calldata msg_payload = MessageV1Codec.payload(payload);
require(isValidPayloadType(payload_type), "Invalid payload type");
if (payload_type == PayloadType.ERC20) {
{
ERC20TransferPayload memory transfer_payload = codec
.deocde_transfer(msg_payload);
if (mode == SettlementMode.MintBurn) {
_erc20_mint(
AddressCast.to_address(transfer_payload.to),
transfer_payload.amount
);
return true;
} else if (mode == SettlementMode.LockUnlock) {
_erc20_unlock(
AddressCast.to_address(transfer_payload.to),
transfer_payload.amount
);
return true;
} else if (mode == SettlementMode.LockMint) {
_erc20_mint(
AddressCast.to_address(transfer_payload.to),
transfer_payload.amount
);
return true;
} else if (mode == SettlementMode.BurnUnlock) {
_erc20_unlock(
AddressCast.to_address(transfer_payload.to),
transfer_payload.amount
);
return true;
}
}
}
return false;
}
Recommended Mitigation Steps
Implement the functionality like in the solidity handler function so it returns false if something goes wrong.
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 handler's receive_cross_chain_msg function unconditionally returns true after its assertions pass, so the settlement contract never sees a failure return value.
Impact
Corrupted or invalid messages could be marked as successful, breaking the invariant that message statuses are tracked correctly.
What the attacker needed
Ability to submit a cross-chain message
The fix
The handler should return false when something goes wrong, following the Solidity implementation, so the settlement contract can mark the message as failed.
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 cross-chain bridge moves messages between blockchains. The settlement contract asks a handler to process each message and uses the handler's answer to decide if the message succeeded or failed. Here the handler always says 'yes' even when something is wrong, so failed messages are recorded as successful.
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.