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.
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:
- Transactions remaining in a Pending state indefinitely in the Cairo implementation
- Inconsistent transaction states across different chain implementations
- Potential blocking of cross-chain operations
- 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.
0xsomeone (judge) increased severity to High
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.