Does not check if to_chain and to_handler is whitelisted in cross_chain_erc20_settlement
The cross-chain settlement function does not check that the destination chain and handler are whitelisted, so a user can send tokens to an invalid handler. The transaction then fails on the destination chain and the failure callback is ignored, leaving the funds stuck.
Submitted by klau5, also found by Moksha, fyamf, NexusAudits, Abdessamed, gajiknownnothing, Tigerfrake, ABAIKUNANBAEV, 0xAsen, pwnforce, Daniel_eth, atoko, avoloder, AllTooWell, 0xNirix, SBSecurity, Draiakoo, peanuts, rbserver, haxatron, said, mojito_auditor, shaflow2, bhilare_, kutugu, devival, Shaheen, and Breeje
Impact
The handler does not prevent tokens from being sent to incorrect chains and handlers. If a message is sent to an incorrect handler, the failure cannot be handled through receive_cross_chain_callback.
Proof of Concept
Handler.cross_chain_erc20_settlement does not check if to_chain and to_handler are whitelisted. Therefore, it’s possible to send messages to any chains and handlers that aren’t paired with this handler.
function cross_chain_erc20_settlement(
string memory to_chain,
uint256 to_handler,
uint256 to_token,
uint256 to,
uint256 amount
) external {
require(amount > 0, "Amount must be greater than 0");
require(to != 0, "Invalid to address");
@> require(to_handler != 0, "Invalid to handler address");
require(to_token != 0, "Invalid to token address");
if (mode == SettlementMode.MintBurn) {
_erc20_lock(msg.sender, address(this), amount);
} else if (mode == SettlementMode.LockUnlock) {
_erc20_lock(msg.sender, address(this), amount);
} else if (mode == SettlementMode.LockMint) {
_erc20_lock(msg.sender, address(this), amount);
} else if (mode == SettlementMode.BurnUnlock) {
_erc20_burn(msg.sender, amount);
}
...
}
If a non-contract address is set as to_handler, the transaction will revert when trying to call Handler.receive_cross_chain_msg on the destination chain. As a result, it’s impossible to emit an event to signal the failure, making failure handling impossible.
// Settlement.receive_cross_chain_msg
function receive_cross_chain_msg(
uint256 txid,
string memory from_chain,
uint256 from_address,
uint256 from_handler,
address to_handler,
PayloadType payload_type,
bytes calldata payload,
uint8 sign_type, // validators signature type / multisig or bls sr25519
bytes calldata signatures // signature array
) external {
...
@> bool result = ISettlementHandler(to_handler).receive_cross_chain_msg( // this will be reverted
txid,
from_chain,
from_address,
from_handler,
payload_type,
payload,
sign_type,
signatures
);
CrossChainMsgStatus status = CrossChainMsgStatus.Failed;
if (result == true) {
status = CrossChainMsgStatus.Success;
receive_cross_txs[txid].status = CrossChainMsgStatus.Success;
} else {
@> receive_cross_txs[txid].status = CrossChainMsgStatus.Failed;
}
emit CrossChainHandleResult(
txid,
@> status,
contract_chain_name,
from_chain,
address(to_handler),
from_handler,
payload_type
);
}
There’s another problem. If a non-whitelisted handler requests a message, Handler.receive_cross_chain_msg will return false to indicate failure. Validators listen for the CrossChainHandleResult event to notify the source chain of the failure through receive_cross_chain_callback, allowing the handler to process the failure.
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) {
// from_handler need in whitelist
@> if (is_valid_handler(from_chain, from_handler) == false) {
@> return false;
}
...
}
However, Handler.receive_cross_chain_callback only allows callback messages from whitelisted chains and handlers. This means that when a message is sent to an incorrect handler and fails, the callback notifies of the failure, but the source chain’s handler ignores and cannot handle the failure caused by the incorrect handler.
function receive_cross_chain_callback(
uint256 txid,
string memory from_chain,
uint256 from_handler,
CrossChainMsgStatus status,
uint8 /* sign_type */, // validators signature type / multisig or bls sr25519
bytes calldata /* signatures */
) external onlySettlement returns (bool) {
// from_handler need in whitelist
@> if (is_valid_handler(from_chain, from_handler) == false) {
@> return false;
}
require(
create_cross_txs[txid].status == CrossChainTxStatus.Pending,
"invalid CrossChainTxStatus"
);
if (status == CrossChainMsgStatus.Success) {
if (mode == SettlementMode.MintBurn) {
_erc20_burn(address(this), create_cross_txs[txid].amount);
}
create_cross_txs[txid].status = CrossChainTxStatus.Settled;
}
if (status == CrossChainMsgStatus.Failed) {
create_cross_txs[txid].status = CrossChainTxStatus.Failed;
}
return true;
}
Therefore, Handler.cross_chain_erc20_settlement should check that to_chain and to_handler are whitelisted to prevent message transmission to incorrect handlers in the first place.
Recommended Mitigation Steps
function cross_chain_erc20_settlement(
string memory to_chain,
uint256 to_handler,
uint256 to_token,
uint256 to,
uint256 amount
) external {
require(amount > 0, "Amount must be greater than 0");
require(to != 0, "Invalid to address");
require(to_handler != 0, "Invalid to handler address");
require(to_token != 0, "Invalid to token address");
+ require(is_valid_handler(to_chain, to_handler), "not valid destination");
if (mode == SettlementMode.MintBurn) {
_erc20_lock(msg.sender, address(this), amount);
} else if (mode == SettlementMode.LockUnlock) {
_erc20_lock(msg.sender, address(this), amount);
} else if (mode == SettlementMode.LockMint) {
_erc20_lock(msg.sender, address(this), amount);
} else if (mode == SettlementMode.BurnUnlock) {
_erc20_burn(msg.sender, amount);
}
...
}
The submission and its duplicates detail how a cross-chain message does not validate that the
to_handleris a valid address on theto_chain, causing transactions to be permanently stuck in a pending state and thus leading to fund loss.I believe a medium-severity rating is appropriate given that the user would have to make a mistake when submitting their transaction, however, the documentation of the system and Cairo implementation indicate that validation should occur.
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 settlement function only checks that the handler address is non-zero, not that it is a valid, whitelisted handler for the destination chain.
Impact
Tokens sent to an invalid handler are permanently stuck, causing fund loss, though the user must make a mistake when submitting the transaction.
What the attacker needed
User submits a transaction with a wrong handler; no whitelist check on destination
The fix
The settlement function should check that the destination chain and handler are whitelisted before locking or burning tokens.
How it was found
- Call cross_chain_erc20_settlement with a to_chain and to_handler that are not whitelisted.
- The function locks or burns the tokens and emits a cross-chain message.
- On the destination chain, the settlement contract tries to call the invalid handler and the call reverts.
- No failure event is emitted, so the source chain never learns the transfer failed.
- The tokens remain locked or burned with no way to recover them.
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.
This is a smart contract that moves tokens between blockchains. It lets you name any destination handler, even one that does not exist or is not approved. If you make a typo, your tokens are locked and the system cannot send them back.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.