ChakraSettlement.receive_cross_chain_msg and ChakraSettlement.receive_cross_chain_callback functions do not ensure that receiving ChakraSettlement contract’s contract_chain_name must match to_chain corresponding to respective txid input though they should
The ChakraSettlement contract's receive functions do not verify that the receiving chain matches the intended destination chain encoded in the transaction. An attacker could replay a signed cross-chain message on a different chain, causing tokens to be minted or burned incorrectly.
rbserver Follow with rbserver, jasonxiale and 15 others
Originally disclosed on Code4rena
Submitted by rbserver, also found by rbserver, jasonxiale, avoloder, Moksha, Coinymous, 0xNirix, SBSecurity, Respx, Emmanuel, said, haxatron, Shaheen, mojito_auditor, fyamf, klau5, ZdravkoHr, ABAIKUNANBAEV (1, 2), and Rhaydden
Impact
Because the ChakraSettlement.receive_cross_chain_msg function does not ensure that the receiving ChakraSettlement contract’s contract_chain_name must match the to_chain corresponding to its txid input, the signatures that should only be used for calling the ChakraSettlement.receive_cross_chain_msg function on to_chain A can also be allowed to be used on to_chain B. As a result, the handler on to_chain B can incorrectly mint or transfer tokens to recipients though such recipients should only receive such token amounts on to_chain A and not on to_chain B.
Similarly, since the ChakraSettlement.receive_cross_chain_callback function does not ensure that the receiving ChakraSettlement contract’s contract_chain_name must match the to_chain associated with its txid input, the signatures that should only be used for calling the ChakraSettlement.receive_cross_chain_callback function on to_chain A can also be allowed to be used on to_chain B. As a result, to_chain B’s handler’s receive_cross_chain_callback function logics can be incorrectly triggered, such as burning the corresponding token amount held by such handler on to_chain B under the MintBurn mode though such token amount should only be burned on to_chain A and not on to_chain B.
Proof of Concept
When a validator is deterministically deployed, it can have the same address on different chains. When a handler is deterministically deployed, it can have the same address on different chains. Therefore, it is possible that the validators have the same addresses on two different to_chain chains while the number of required validators are the same on both chains, and the handler has the same address on these two to_chain chains as well. Moreover, such handler can whitelist the same from_chain-from_handler combination on both to_chain chains.
Suppose such situation occurs for to_chain A and B, the validators on to_chain A can sign for a cross-chain message in which such signatures should only be used on to_chain A and should not be allowed to be used on to_chain B. However, since the ChakraSettlement.receive_cross_chain_msg function does not ensure that the receiving ChakraSettlement contract’s contract_chain_name must match the to_chain corresponding to its txid input, the ChakraSettlement.receive_cross_chain_msg function on to_chain B can be successfully called with the txid, from_chain, from_address, from_handler, to_handler, and payload, which were encoded in the signed message hash for the signatures that should only be used on to_chain A.
In this case:
signature_verifier.verify(message_hash, signatures, sign_type)would returntruebecause the corresponding validators, which signed the signatures forto_chainA, have the same addresses on bothto_chainA and B, and both chains have the same number of required validators;ISettlementHandler(to_handler).receive_cross_chain_msgwould be called successfully because the correspondingto_handlerthat is encoded for the signatures to be used onto_chainA also exists onto_chainB with the same address;is_valid_handler(from_chain, from_handler)would betruewhen further calling theChakraSettlementHandler.receive_cross_chain_msgfunction because thefrom_chain-from_handlercombination that is encoded for the signatures to be used onto_chainA is also whitelisted by suchto_handleronto_chainB.
Thus, such ChakraSettlement.receive_cross_chain_msg function call on to_chain B would be successful, which causes such signatures that should only be used for calling the ChakraSettlement.receive_cross_chain_msg function on to_chain A to also be allowed to be used on to_chain B.
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 {
{
// verify signature
@> bytes32 message_hash = keccak256(
@> abi.encodePacked(
@> txid,
@> from_chain,
@> from_address,
@> from_handler,
@> to_handler,
@> keccak256(payload)
@> )
@> );
@> require(
@> signature_verifier.verify(message_hash, signatures, sign_type),
@> "Invalid signature"
@> );
require(
receive_cross_txs[txid].status == CrossChainMsgStatus.Unknow,
"Invalid transaction status"
);
}
receive_cross_txs[txid] = ReceivedCrossChainTx(
txid,
from_chain,
contract_chain_name,
from_address,
from_handler,
address(this),
payload,
CrossChainMsgStatus.Pending
);
@> bool result = ISettlementHandler(to_handler).receive_cross_chain_msg(
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
);
}
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
);
return true;
} else if (mode == SettlementMode.BurnUnlock) {
_erc20_unlock(
AddressCast.to_address(transfer_payload.to),
transfer_payload.amount
);
return true;
}
}
}
return false;
}
Similarly, when the same situation occurs for to_chain A and B, the ChakraSettlement.receive_cross_chain_callback function on to_chain B can also be successfully called with the txid, from_handler, to_handler, and status, which were encoded in the signed message hash for the signatures that should only be used on to_chain A, because the ChakraSettlement.receive_cross_chain_callback function does not ensure that the receiving ChakraSettlement contract’s contract_chain_name must match the to_chain associated with its txid input.
For the same reasons described for the case involving the ChakraSettlement.receive_cross_chain_msg function, calling the ChakraSettlement.receive_cross_chain_callback function in this case would cause signature_verifier.verify(message_hash, signatures, sign_type) to return true, ISettlementHandler(to_handler).receive_cross_chain_callback to be called successfully, and is_valid_handler(from_chain, from_handler) to be true when further calling the ChakraSettlementHandler.processCrossChainCallback function. Hence, such ChakraSettlement.receive_cross_chain_callback function call on to_chain B would be successful, which causes such signatures that should only be used for calling the ChakraSettlement.receive_cross_chain_callback function on to_chain A to also be allowed to be used on to_chain B.
function receive_cross_chain_callback(
uint256 txid,
string memory from_chain,
uint256 from_handler,
address to_handler,
CrossChainMsgStatus status,
uint8 sign_type,
bytes calldata signatures
) external {
@> verifySignature(
txid,
from_handler,
to_handler,
status,
sign_type,
signatures
);
@> processCrossChainCallback(
txid,
from_chain,
from_handler,
to_handler,
status,
sign_type,
signatures
);
emitCrossChainResult(txid);
}
function verifySignature(
uint256 txid,
uint256 from_handler,
address to_handler,
CrossChainMsgStatus status,
uint8 sign_type,
bytes calldata signatures
) internal view {
bytes32 message_hash = keccak256(
@> abi.encodePacked(txid, from_handler, to_handler, status)
);
require(
@> signature_verifier.verify(message_hash, signatures, sign_type),
"Invalid signature"
);
}
function processCrossChainCallback(
uint256 txid,
string memory from_chain,
uint256 from_handler,
address to_handler,
CrossChainMsgStatus status,
uint8 sign_type,
bytes calldata signatures
) internal {
require(
create_cross_txs[txid].status == CrossChainMsgStatus.Pending,
"Invalid transaction status"
);
if (
@> ISettlementHandler(to_handler).receive_cross_chain_callback(
txid,
from_chain,
from_handler,
status,
sign_type,
signatures
)
) {
create_cross_txs[txid].status = status;
} else {
create_cross_txs[txid].status = CrossChainMsgStatus.Failed;
}
}
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;
}
Recommended Mitigation Steps
The ChakraSettlement.receive_cross_chain_msg and ChakraSettlement.receive_cross_chain_callback functions can be updated to check if the receiving ChakraSettlement contract’s contract_chain_name matches the to_chain associated with the respective txid input and revert if not matched.
0xsomeone (judge) increased severity to High and commented:
The Warden outlines that replay attacks are possible when receiving funds due to the absence of the
to_chainvariable’s validation. This allows the same payload signed by the Chakra validators to be replayed across multiple chains incorrectly, indicating a high-risk vulnerability.
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 include the destination chain identifier in the signed message hash or verify it against the contract's own chain name, allowing replay across chains with identical validator sets and handler addresses.
Impact
An attacker could cause tokens to be minted or transferred on the wrong chain, potentially leading to unintended token creation or loss, as the exploit requires specific conditions (same validator addresses, same handler addresses, and whitelisting) to be met.
What the attacker needed
Validators deployed at same addresses on two chains; handlers deployed at same addresses on two chains; same number of required validators on both chains; handler whitelists same from_chain-from_handler on both…
The fix
The contract should be updated to check that the receiving ChakraSettlement contract's contract_chain_name matches the to_chain associated with the txid input and revert if not matched.
How it was found
- Deploy validators and handlers with the same addresses on two different chains.
- Ensure both chains have the same number of required validators and the handler whitelists the same from_chain-from_handler combination.
- Obtain a valid signature for a cross-chain message intended for chain A.
- Call receive_cross_chain_msg on chain B with the same signed data.
- The signature verification passes because validators have the same addresses on both chains.
- The handler on chain B processes the message, minting or transferring tokens incorrectly.
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.
When a message is sent between blockchains, validators sign it to prove it is legitimate. The contract that receives the message should check that the message is meant for its own chain, but it does not. This means a message signed for one chain could be used on another chain, potentially creating or destroying tokens in the wrong place.
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.