Forcing Starknet handlers to be whitelisted on the same chain allows exploit of BurnUnlock mode to drain handler funds
The Starknet handler contract requires that both the source and destination handlers be whitelisted, forcing the owner to whitelist the handler itself. An attacker can send cross-chain messages from Starknet to Starknet, causing the handler to unlock tokens to the attacker's address repeatedly, draining the handler's funds.
In Cairo contracts, when handling cross-chain messages or callbacks, the contract ensures that the handler on the same chain (Starknet) is whitelisted:
In this context, handlers on Starknet must whitelist themselves as supported handlers. However, this introduces a significant vulnerability: since handlers are self-whitelisted, a malicious user could send cross-chain messages to the same chain (Starknet to Starknet) and exploit the BurnUnlock mode as follows:
In BurnUnlock mode, when a cross-chain message is sent, the user’s tokens are burned, and when the message is received, the same amount of tokens is unlocked. This opens the door for malicious actors to repeatedly send cross-chain messages to themselves, resulting in a continuous unlock of tokens:
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{
// --SNIP
let erc20 = IERC20MintDispatcher{contract_address: self.token_address.read()};
let token = IERC20Dispatcher{contract_address: self.token_address.read()};
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);
}
}
By continuously sending cross-chain messages to the same chain, the malicious user can drain the handler’s funds by repeatedly unlocking tokens to their own address. As a result, other legitimate cross-chain ERC20 operations will fail due to the depletion of ERC20 tokens in the handler contract.
Recommended Mitigation Steps
The self-whitelisting of handlers introduces unnecessary risk and facilitates the aforementioned vulnerability. Consider removing the check that forces handlers to be self-whitelisted:
The Warden has attempted to formulate an exploitation path of a self-cross-chain transfer; however, the assumption that a handler can be arbitrarily introduced to the system is incorrect given that the relevant function enrolling them is owner-controlled.
“however, the assumption that a handler can be arbitrarily introduced to the system is incorrect given that the relevant function enrolling them is owner-controlled.”
This is an incorrect statement because, as seen on the receive_crosschain_msg, the function enforces that both to_chain and to_handler as well as from_chain and from_handler are supported:
assert(self.support_handler.read((from_chain, from_handler)) &&
self.support_handler.read((to_chain, contract_address_to_u256(to_handler))), "not support handler");
So, starknet handlers must be self-whitelisted. A malicious user can exploit this for handlers having the mode BurnLock and drain the handler’s funds via sending cross-chain messages from starknet to starknet to repeatedly unlock tokens to their own address, as explained in details on the report.
Hey @Abdessamed, thanks for your follow-up feedback. The term “self-whitelisted” is invalid as the contracts do not expose a mechanism for users to self-whitelist themselves. As whitelisting is an authoritative process (i.e. requires elevated privileges), we can safely assume that registered handlers are trusted implementations rather than arbitrary users.
Hi @0xsomeone - I see where the confusion is coming from. Let me reformulate:
In this function, it checks that both to_chain and to_handler as well as from_chain and from_handler are supported:
assert(self.support_handler.read((from_chain, from_handler)) &&
self.support_handler.read((to_chain, contract_address_to_u256(to_handler))), 'not support handler');
This forces the owner to already call set_support_handler to add Starknet handlers as supported on the Starknet handler. Otherwise, any call to handler_erc20::receive_cross_chain_msg will fail.
Now, given the above, an attacker makes use of that to make the attack described on the report.
Hey @Abdessamed, thanks for clarifying! I see what the outlined vulnerability presently is, and can confirm it is a valid issue. This is indeed a good finding! I have re-instated a high-risk rating for it, and appreciate the due diligence during the PJQA process.
To note, self-whitelisting is the act of whitelisting oneself; might be useful for future submissions!
Regarding comments about how the Chakra Network operates, in line with other rulings in the audit, we cannot make any assumptions as to what operations those nodes can and cannot filter, so we assume all operations are processed at “face-value” rendering this submission to be valid.
The original report as published on Code4rena, by Abdessamed. 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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
The contract requires the destination handler to be whitelisted, which forces the handler to whitelist itself, enabling same-chain messages that trigger token unlocks without corresponding burns.
Impact
The attacker could drain the handler's ERC20 token balance, causing legitimate cross-chain operations to fail due to lack of funds.
What the attacker needed
Handler in BurnUnlock mode; handler has token balance; attacker can send cross-chain messages
The fix
The check that forces handlers to be self-whitelisted should be removed.
How it was found
The attacker sends a cross-chain message from Starknet to Starknet, specifying the handler as both source and destination.
The handler processes the message and, in BurnUnlock mode, transfers tokens to the attacker's address.
The attacker repeats the process to drain the handler's token balance.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
A cross-chain bridge moves tokens between blockchains. In 'BurnUnlock' mode, tokens are burned on one chain and unlocked on another. The contract checks that both the sending and receiving handlers are approved. Because the contract must approve itself to receive messages, an attacker can send messages from the same chain to itself, making the contract unlock tokens repeatedly and drain its balance.
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.