Bridging from Starknet to Starknet causes mismatch between minted ckrBTC and BTC transferred to MuSig2
The Starknet handler allows bridging tokens from Starknet to Starknet, which causes the same tokens to be locked and then minted again, inflating the total supply of ckrBTC. An attacker could exploit this to increase the supply of ckrBTC without a corresponding increase in BTC backing.
Submitted by fyamf
Impact
It is possible to bridge assets from Starknet to Starknet by setting to_chain and to_handler to be the same as from_chain and from_handler. This violates the core rule of the protocol, which is “The contract maintains a consistent state between locking/burning tokens on the source chain and minting/unlocking on the destination chain, depending on the settlement mode.”
For example, this could result in the total supply of ckrBTC on Starknet being higher than the amount of BTC transferred to MuSig2 on the Bitcoin network.
Proof of Concept
When a message is received on Starknet, the handler_erc20::receive_cross_chain_msg function is called:
Link to code
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');
to_chain must be the Starknet chain name, and to_handler must be the contract address of handler_erc20.
This check forces the owner to already call set_support_handler to add support for to_chain and to_handler. Otherwise, any call to handler_erc20::receive_cross_chain_msg will fail:
fn set_support_handler(ref self: ContractState, chain_name: felt252, handler: u256, support: bool) {
self.ownable.assert_only_owner();
self.support_handler.write((chain_name, handler), support);
}
At first glance, this seems redundant. Why should the Starknet chain and its handler be added to the support_handler mapping within the same handler? For example, if the chain name is Starknet and the handler address is 0xaa, calling support_handler.read('Starknet', 0xaa) returns 1. This mapping should only record valid destination chains and handler addresses, not its own chain and handler.
This creates a potential attack:
-
The attacker sends a cross-chain message from Starknet and
handler_erc20to the same chain and handler. This means the source chain equals the destination chain, and the source handler equals the destination handler. The parameters forhandler_erc20::cross_chain_erc20_settlementwould be:to_chain: Starknetto_handler: the same address ashandler_erc20to_token: the same token address (ckrBTC)to: the recipient address (irrelevant for this vulnerability)amount: the token amount (irrelevant for this vulnerability)
-
During the bridging process, there is no check that
to_chainandto_handlerare different fromfrom_chainandfrom_handler. -
Once the validators sign the event (the validator implementation is out of scope), the message is received on Starknet, and
settlement::receive_cross_chain_msgis called. This function does not prevent the attack.
- Then,
receive_cross_chain_msg::handler_erc20is called: Link to code - This function checks if
to_chainandto_handlerare supported, and sinceto_chain = from_chainandto_handler = from_handler, it passes. Link to code - Finally, the transfer or mint occurs. If the settlement mode is
LockMint, the same amount ofckrBTCthat was locked on Starknet will be minted on Starknet again. In other words, because the source and destination are the same, the locked token on the source is minted again on the same source. For example, if the attacker bridges 1000ckrBTCfrom Starknet to Starknet, 1000ckrBTCis locked on Starknet, and then 1000ckrBTCis minted again, resulting in a total supply increase of 2000ckrBTCon Starknet (1000 locked and 1000 minted).
This contradicts the core logic of the protocol, as explained:
“In Chakra liquid staking, users first transfer Bitcoin to a multi-signature address supported by MuSig2. This event is captured by the indexer, which calls the on-chain contract to mint ckrBTC for the user. The Bitcoin in the multi-signature address is staked into Babylon. While holding ckrBTC, users continue to earn rewards from Babylon staking. When users want to end the staking, they can burn ckrBTC.”
This means that the amount of ckrBTC on Starknet is supposed to match the amount of BTC transferred to MuSig2. However, due to this attack, the amount of ckrBTC on Starknet can be maliciously increased and will not match the amount of BTC transferred to MuSig2.
Summary
Under normal conditions, a user locks ckrBTC on Starknet and receives tokens on another chain, enabling them to use Bitcoin-backed assets in DeFi protocols. But in this attack, the attacker locks ckrBTC on Starknet and bridges it to Starknet again to mint ckrBTC again. This causes the total supply of ckrBTC on Starknet to be higher than the amount of BTC in MuSig2, violating the core rule of the protocol.
Note
This vulnerability does not depend on owner mistakes. The owner must have already added the source chain and handler to the support_handler mapping; otherwise, any call to handler_erc20::receive_cross_chain_msg would fail. On the EVM-based code, however, the owner does not need to add the source chain and handler to the handler_whitelist mapping, since ChakraSettlementHandler::receive_cross_chain_msg only checks that from_chain and from_handler are whitelisted, not to_chain and to_handler.
if (is_valid_handler(from_chain, from_handler) == false) {
return false;
}
Proof of Concept (PoC)
In the following test, target_chain, target_token, and target_handler are all set to Starknet, ckrBTC, and erc20_handler on Starknet, respectively. This shows that the transaction executes successfully, contrary to expectations.
use core::option::OptionTrait;
use core::traits::TryInto;
use settlement_cairo::ckr_btc::IckrBTCDispatcherTrait;
use openzeppelin::token::erc20::interface::IERC20DispatcherTrait;
use core::result::ResultTrait;
use core::box::BoxTrait;
use snforge_std::{declare, ContractClassTrait, start_prank, CheatTarget, stop_prank};
use starknet::ContractAddress;
use starknet::{get_tx_info, get_caller_address};
use settlement_cairo::interfaces::{IERC20HandlerDispatcher, IERC20HandlerDispatcherTrait, IChakraSettlementDispatcher, IChakraSettlementDispatcherTrait};
use settlement_cairo::codec::{decode_transfer, encode_transfer, ERC20Transfer, Message, decode_message, encode_message};
use settlement_cairo::utils::{u256_to_contract_address, contract_address_to_u256, u256_to_u8_array};
use settlement_cairo::ckr_btc::{IckrBTCDispatcher};
use openzeppelin::token::erc20::interface::IERC20Dispatcher;
#[test]
fn test_lock_mint_self(){
let source_chain = 'Starknet';
let target_address = 1;
let amount = 1000;
let owner_address = 0x5a9bd6214db5b229bd17a4050585b21c87fc0cadf9871f89a099d27ef800a40;
let attacker_address = 0x00112233445566778899aabbccddeeff;
let attacker = attacker_address.try_into().unwrap();
let settlement_contract = declare("ChakraSettlement");
let settlement_address = settlement_contract.deploy(@array![owner_address, 1]).unwrap();
let ckrBTC_contract = declare("ckrBTC");
let ckrBTC_address = ckrBTC_contract.deploy(@array![owner_address]).unwrap();
let erc20_handler = declare("ERC20Handler");
let erc20_handler_address = erc20_handler.deploy(@array![settlement_address.into(),owner_address,ckrBTC_address.into(), 1]).unwrap();
let handler_dispath = IERC20HandlerDispatcher {contract_address: erc20_handler_address};
let ckrbtc_dispath = IckrBTCDispatcher{contract_address: ckrBTC_address};
let ckrbtc_erc20_dispath = IERC20Dispatcher{contract_address: ckrBTC_address};
// support handler
let owner = owner_address.try_into().unwrap();
start_prank(CheatTarget::One(erc20_handler_address), owner);
// add from_chain from_handler
handler_dispath.set_support_handler(source_chain, contract_address_to_u256(erc20_handler_address),true);
start_prank(CheatTarget::One(ckrBTC_address), owner);
ckrbtc_dispath.add_operator(erc20_handler_address);
ckrbtc_dispath.add_operator(owner);
// cross_chain_erc20_settlement
ckrbtc_dispath.mint_to(attacker, amount);
stop_prank(CheatTarget::One(ckrBTC_address));
////////////// attack starts here
start_prank(CheatTarget::One(ckrBTC_address), attacker);
ckrbtc_erc20_dispath.approve(erc20_handler_address, amount);
stop_prank(CheatTarget::One(ckrBTC_address));
start_prank(CheatTarget::One(erc20_handler_address), attacker);
let target_chain = 'Starknet'; // attacker sets the target chain as source chain
let target_token = contract_address_to_u256(ckrBTC_address); // attacker sets the target token as source token
let target_handler = contract_address_to_u256(erc20_handler_address); // attacker sets the target handler as source handler
handler_dispath.cross_chain_erc20_settlement(target_chain, target_handler, target_token, target_address, amount);
stop_prank(CheatTarget::One(erc20_handler_address));
assert(ckrbtc_erc20_dispath.balance_of(attacker) == 0, 'balance error after cross');
assert(ckrbtc_erc20_dispath.balance_of(erc20_handler_address) == amount, 'handler balance error');
// receive_cross_chain_msg
start_prank(CheatTarget::One(erc20_handler_address), settlement_address);
assert(ckrbtc_erc20_dispath.balance_of(u256_to_contract_address(0x70997970c51812dc3a010c7d01b50e0d17dc79c8)) == 0, 'to_address balance error');
let message_array_u8 = array! [1, 226, 26, 80, 2, 232, 11, 172, 207, 254, 0, 95, 72, 69, 136, 99, 38, 6, 228, 108, 177, 62, 5, 10, 125, 58, 52, 32, 110, 139, 85, 224, 141, 5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 243, 159, 214, 229, 26, 173, 136, 246, 244, 206, 106, 184, 130, 114, 121, 207, 255, 185, 34, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 112, 153, 121, 112, 197, 24, 18, 220, 58, 1, 12, 125, 1, 181, 14, 13, 23, 220, 121, 200, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 231, 241, 114, 94, 119, 52, 206, 40, 143, 131, 103, 225, 187, 20, 62, 144, 187, 63, 5, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 144, 247, 155, 246, 235, 44, 79, 135, 3, 101, 231, 133, 152, 46, 31, 16, 30, 147, 185, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 232];
handler_dispath.receive_cross_chain_msg(1, target_chain, source_chain, target_handler, erc20_handler_address, message_array_u8);
assert(ckrbtc_erc20_dispath.balance_of(u256_to_contract_address(0x70997970c51812dc3a010c7d01b50e0d17dc79c8)) == 1000, 'transfer error');
}
Recommended Mitigation Steps
When bridging from Starknet, it should ensure that the source and destination are different.
0xsomeone (judge) decreased severity to Medium and commented:
The Warden has identified a self-cross-chain-transfer exploitation path that will cause the
ckrBTCtoken to have an incorrect total supply.I believe a medium-risk severity level is better suited as no financial value can be exploited via the vulnerability described. I do commend the ingenuity!
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 contract does not check that the destination chain and handler are different from the source chain and handler, allowing a self-transfer that mints new tokens.
Impact
The total supply of ckrBTC on Starknet could become higher than the amount of BTC transferred to MuSig2, violating the protocol's core rule, though the judge noted no financial value can be exploited.
What the attacker needed
Owner has added source chain and handler to support_handler; attacker has ckrBTC on Starknet; validators sign the cross-chain message
The fix
The contract should ensure that the source and destination chains and handlers are different when bridging from Starknet.
How it was found
- The attacker calls cross_chain_erc20_settlement with to_chain and to_handler set to the same values as from_chain and from_handler.
- The validators sign the event and the message is received on Starknet.
- The settlement contract calls receive_cross_chain_msg on the handler.
- The handler checks that to_chain and to_handler are supported, which passes because they are the same as the source.
- The handler then locks the tokens and mints the same amount again, increasing the total supply.
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 bug in a cross-chain bridge that lets someone send tokens from a chain back to the same chain. Normally, bridging locks tokens on one chain and creates new ones on another, but here the same tokens get locked and then new ones are created on the same chain, increasing the total supply without new backing.
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.