Permanent loss of user tokens on both chains if BurnUnlock mode fails because of flawed burning pattern
The BurnUnlock mode burns tokens on the source chain before confirming a successful unlock on the destination chain. If the destination transaction fails, the user's tokens are lost on both chains.
0x18a6 Follow with Abdessamed, mjcpwns and 1 other
Originally disclosed on Code4rena
Submitted by 0x18a6, also found by Abdessamed, mjcpwns, and jesjupyter
Impact
The BurnUnlock mode in the ChakraSettlementHandler contract has a critical flaw that causes token loss on both chains. This happens because tokens are burned on the source chain before ensuring a successful unlock on the destination chain. This high-risk vulnerability can lead to significant financial loss and damage trust in the cross-chain bridge system.
Note that the same issue persists in the Cairo code.
Vulnerability Details
In the ChakraSettlementHandler contract, we got two modes that burns tokens in the bridging process:
MintBurn: Tokens are burned on the source chain and minted on the destination chain. This mode is used when you want to permenantly move tokens from one chain to another.BurnUnlock: Tokens are burned on the source chain and unlocked on the destination chain. This mode is used when you want to move tokens from one chain to another and decrease the supply on the source chain.
We observe two distinct pattern of burning tokens in MintBurn vs BurnUnlock modes:
MintBurn mode
- Source chain (
cross_chain_erc20_settlement): Tokens are locked instead of burned initially.
solidity/handler/contracts/ChakraSettlementHandler.sol#L123-L124
if (mode == SettlementMode.MintBurn) {
_erc20_lock(msg.sender, address(this), amount);
}
- Destination chain (
receive_cross_chain_msg): Tokens are correctly minted on the destination chain. (the Cairo code is equivalent to this)
solidity/handler/contracts/ChakraSettlementHandler.sol#L325-L329
if (mode == SettlementMode.MintBurn) {
_erc20_mint(
AddressCast.to_address(transfer_payload.to),
transfer_payload.amount
);
return true;
}
- Callaback on the source chain: Tokens are burned only after a successful callback. This is a security measure to ensure that user tokens are only burned when the user has received their tokens on the destination chain. If tokens were burned initially and then the call on the destination chain failed, the user’s tokens would effectively be lost on both chains. More details on this will be provided later:
solidity/handler/contracts/ChakraSettlementHandler.sol#L383-L389
if (status == CrossChainMsgStatus.Success) {
if (mode == SettlementMode.MintBurn) {
_erc20_burn(address(this), create_cross_txs[txid].amount);
}
create_cross_txs[txid].status = CrossChainTxStatus.Settled;
}
BurnUnlock mode
- Source chain (
cross_chain_erc20_settlement): Tokens are immediately burned on the source chain.
solidity/handler/contracts/ChakraSettlementHandler.sol#L129-L130
if (mode == SettlementMode.BurnUnlock) {
_erc20_burn(msg.sender, amount);
}
- Destination chain (
receive_cross_chain_msg): Tokens are correctly unlocked
solidity/handler/contracts/ChakraSettlementHandler.sol#L344-L348
if (mode == SettlementMode.BurnUnlock) {
_erc20_unlock(
AddressCast.to_address(transfer_payload.to),
transfer_payload.amount
);
return true;
}
- Callback on the source chain: No specific action for
BurnUnlockmode in callback.
To summarize, the two distinct pattern for burning tokens is that: MintBurn follows a lock (source) -> mint (dest) -> burn (callback) and, BurnUnlock follows a burn (source) -> unlock (dest).
The problem is that in the BurnUnlock mode, if the execution on the destination chain fails (for instance, due to insufficient validator signatures), the user’s tokens are lost on both chains. This is because the tokens are burned on the source chain and remain locked on the destination chain, preventing the user from reclaiming them at first try, and preventing the user from reclaiming them at a latter try because user already burned their equivalant tokens in the source chain.
Note that the problem doesn’t exist in MintBurn mode (at least with this particular root cause) because we use the callback pattern. If the call to destination chain fails, the callback simply unlocks the tokens back on the source chain (which it doesn’t do in the current implementation, but is a subject of a distinct report since it’s a different root cause i.e, not implementing a callback pattern if bridging fails vs not unlocking the tokens back in the callback pattern if bridging fails).
Proof of Concept
Here’s a scenario to illustrate:
- Alice sends 1000 CHKR in
BurnUnlockmode. - 1000 CHKR is burned on source chain. Let’s assume Alice has 1000 CHKR locked on destination chain.
- Sending tokens fails for some reasons, e.g, due to insufficient validator signatures. We can even consider an adversarial point of view where a malicious validator intentionally not signing a valid message hash to make it not reach required threshold and fail, with the malicious intent of causing loss of user tokens on both chains. An alternative scenario of failing is when Alice doesn’t have enough tokens locked on destination chain (e.g, she sends 1000 CHKR tokens but she only has 800 CHKR tokens locked on destination chain).
- Because sending tokens failed, Alice now have 0 CHKR on source chain and 1000 CHKR still locked on the destination chain.
- Alice tries again to send 1000 CHKR in any mode. Because CHKR was initially burned in first try and is now 0, she doesn’t have the equivalent CHKR to unlock it on the destination chain and is effectively lost forever on both chains.
Recommended Mitigation Steps
- In my opinion, align the
BurnUnlockmode with theMintBurnmode by implementing a lock-then-burn pattern:
function cross_chain_erc20_settlement(
string memory to_chain,
uint256 to_handler,
uint256 to_token,
uint256 to,
uint256 amount
) external {
// ...
if (mode == SettlementMode.BurnUnlock) {
+ _erc20_lock(msg.sender, address(this), amount);
- _erc20_burn(msg.sender, address(this), amount);
}
// ...
}
- Implement the callback part, and don’t forget to unlock tokens back to the poor Alice on failure:
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 (status == CrossChainMsgStatus.Success) {
+ if (mode == SettlementMode.BurnUnlock) {
+ _erc20_burn(address(this), create_cross_txs[txid].amount);
+ }
create_cross_txs[txid].status = CrossChainTxStatus.Settled;
if (status == CrossChainMsgStatus.Failed) {
+ if (mode == SettlementMode.BurnUnlock) {
+ _erc20_unlock(create_cross_txs[txid].from, create_cross_txs[txid].amount);
+ }
create_cross_txs[txid].status = CrossChainTxStatus.Failed;
}
// ...
}
pidb (Chakra) disputed and commented:
Callback only works in MintBurn mode. For BurnUnLock, the token will be burned in the destination chain, so the suggestion here is wrong.
0xsomeone (judge) decreased severity to Medium and commented:
The Warden and its duplicates have identified that the
BurnUnlockmode is presently insecurely implemented, burning tokens prior to receiving confirmation that they have been unlocked on the destination chain.I do not agree with the Sponsor that the callback does not work on the
BurnUnlockmode as support for it should be introduced and the node system is out-of-scope of the audit. I believe a medium-risk rating is appropriate given that this issue should solely manifest in case the cross-chain transactions fail for one reason or another.
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 BurnUnlock mode burns tokens on the source chain before confirming that the unlock on the destination chain succeeded, unlike MintBurn which uses a lock-then-burn pattern with a callback.
Impact
If the destination transaction fails, the user's tokens are permanently lost on both chains; the judge rated this medium risk because it only manifests when cross-chain transactions fail.
What the attacker needed
BurnUnlock mode is used; Destination transaction fails
The fix
The BurnUnlock mode should be changed to lock tokens on the source chain first, then burn them only after a successful callback, and unlock them back if the callback reports failure.
How it was found
- Alice sends 1000 CHKR in BurnUnlock mode.
- 1000 CHKR is burned on the source chain.
- The destination chain transaction fails, for example due to insufficient validator signatures.
- Alice now has 0 CHKR on the source chain and 1000 CHKR still locked on the destination chain.
- Alice tries again but cannot reclaim the locked tokens because she no longer has equivalent CHKR to unlock 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.
In a cross-chain bridge, tokens move between two blockchains. In BurnUnlock mode, the bridge destroys tokens on the first chain immediately, then tries to release tokens on the second chain. If the second step fails, the tokens are gone from the first chain and still locked on the second, so the user loses them.
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.