The LockMint and BurnUnlock modes cannot be used
The settlement handler's receive function uses the wrong token operation for the LockMint and BurnUnlock modes, so these modes cannot work correctly. An attacker could not directly exploit this, but the protocol's cross-chain transfers would fail or behave incorrectly for those configurations.
shaflow2 Follow with Abdessamed and Daniel_eth
Originally disclosed on Code4rena
Submitted by shaflow2, also found by shaflow2 (1, 2), Abdessamed, Daniel_eth, and Emmanuel (1, 2)
Lines of code
Impact
LockMint and BurnUnlock modes refer to the following:
LockMint: Tokens are locked on the source chain and minted on the target chain.BurnUnlock: Tokens are burned on the source chain and unlocked on the target chain.
However, because the ChakraSettlementHandler protocol is responsible for both processing remote cross-chain messages and sending cross-chain messages to remote chains, a single mode setting cannot handle both tasks simultaneously. This results in one of the tasks’ functionalities being unavailable due to incorrect protocol implementation.
Proof of Concept
When the LockMint mode is used, it means that the source chain employs the LockUnlock mode. Therefore, during the receive cross-chain message, tokens should not be minted but rather unlocked.
Similarly, when the BurnUnlock mode is used, it means that the source chain employs the MintBurn mode. Thus, during the receive cross-chain message, tokens should not be unlocked but rather minted.
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) {
...
if (payload_type == PayloadType.ERC20) {
{
ERC20TransferPayload memory transfer_payload = codec
.deocde_transfer(msg_payload);
if (mode == SettlementMode.MintBurn) {
...
} else if (mode == SettlementMode.LockUnlock) {
...
} else if (mode == SettlementMode.LockMint) {
_erc20_mint(
AddressCast.to_address(transfer_payload.to),
transfer_payload.amount
);
return true;
} else if (mode == SettlementMode.BurnUnlock) {
_erc20_unlock(
AddressCast.to_address(transfer_payload.to),
transfer_payload.amount
);
return true;
}
}
}
...
}
In the Cairo program, the same issue also exists.
#[abi(embed_v0)]
impl ERC20HandlerImpl of IERC20Handler<ContractState> {
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{
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');
let message :Message= decode_message(payload);
let payload_type = message.payload_type;
assert(payload_type == PayloadType::ERC20, 'payload type not erc20');
let payload_transfer = message.payload;
let transfer = decode_transfer(payload_transfer);
assert(transfer.method_id == ERC20Method::TRANSFER, 'ERC20Method must TRANSFER');
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);
}
return true;
}
Recommended Mitigation Steps
The following is the correct logic:
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;
}
bytes calldata msg_payload = MessageV1Codec.payload(payload);
require(isValidPayloadType(payload_type), "Invalid payload type");
if (payload_type == PayloadType.ERC20) {
// Cross chain transfer
{
// Decode transfer payload
ERC20TransferPayload memory transfer_payload = codec
.deocde_transfer(msg_payload);
if (mode == SettlementMode.MintBurn) {
_erc20_mint(
AddressCast.to_address(transfer_payload.to),
transfer_payload.amount
);
return true;
} else if (mode == SettlementMode.LockUnlock) {
_erc20_unlock(
AddressCast.to_address(transfer_payload.to),
transfer_payload.amount
);
return true;
} else if (mode == SettlementMode.LockMint) {
- _erc20_mint(
- AddressCast.to_address(transfer_payload.to),
- transfer_payload.amount
- );
+ _erc20_unlock(
+ AddressCast.to_address(transfer_payload.to),
+ transfer_payload.amount
+ );
return true;
} else if (mode == SettlementMode.BurnUnlock) {
- _erc20_unlock(
- AddressCast.to_address(transfer_payload.to),
- transfer_payload.amount
- );
+ _erc20_mint(
+ AddressCast.to_address(transfer_payload.to),
+ transfer_payload.amount
+ );
return true;
}
}
}
return false;
}
In Cairo:
impl ERC20HandlerImpl of IERC20Handler<ContractState> {
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{
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');
let message :Message= decode_message(payload);
let payload_type = message.payload_type;
assert(payload_type == PayloadType::ERC20, 'payload type not erc20');
let payload_transfer = message.payload;
let transfer = decode_transfer(payload_transfer);
assert(transfer.method_id == ERC20Method::TRANSFER, 'ERC20Method must TRANSFER');
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);
+ token.transfer(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);
+ erc20.mint_to(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);
}
return true;
}
The Warden and its duplicates outline a design-related flaw that is shared across the Solidity and Cairo implementations in relation to how the
LockMintandBurnUnlocksystems are defined, disallowing certain configurations from ever functioning properly. These configurations are expected to be a normal likelihood event due to the system’s intents to be deployed across multiple chains, rendering this submission and its duplicates to be proper high-risk criticism of the system’s design.
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 receive function maps the LockMint and BurnUnlock modes to the opposite token operation (mint instead of unlock, and unlock instead of mint), because the same mode setting is reused for both sending and receiving messages.
Impact
The LockMint and BurnUnlock configurations cannot function properly, so cross-chain transfers using those modes would fail or produce incorrect token balances.
What the attacker needed
Protocol deployed with LockMint or BurnUnlock mode
The fix
The receive function should call unlock for LockMint and mint for BurnUnlock, in both the Solidity and Cairo implementations.
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 has four modes for how tokens are handled on each side. Two of those modes are wired backwards, so when someone tries to use them the tokens are minted or unlocked at the wrong time, breaking the transfer.
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.