Skip to content
Business logic Audit finding Intermediate

There is no refund mechanism in ChakraSettlement.processCrossChainCallback or ChakraSettlementHandler.receive_cross_chain_callback function

The cross-chain ERC20 settlement contracts lack a refund mechanism when a settlement fails, for example if the source handler is removed from the destination whitelist after the message is sent. The caller loses the tokens they transferred to the source handler or burned on the source chain.

rbserver Follow with 0xastronatey, gajiknownnothing and 34 others

Originally disclosed on Code4rena

Submitted by rbserver, also found by 0xastronatey, Abdessamed (1, 2), gajiknownnothing, abhishek_thaku_r, Drynooo (1, 2), ABAIKUNANBAEV, Inspecktor, Decap, 0xSolus, Daniel_eth, mjcpwns, 0xHelium, kutugu, Trooper (1, 2), pwnforce, blackpanther (1, 2), Brene, avoloder (1, 2), AllTooWell, bhilare_, 0xNirix, DPS, SBSecurity, Draiakoo, Audinarey, Tonchi (1, 2, 3), Tumelo_Crypto (1, 2), jesjupyter, franfran20 (1, 2, 3, 4), Respx, 0x18a6, 0xDemon, Emmanuel, Bauchibred, Breeje (1, 2), agent3bood, MrPotatoMagic, b0g0, haxatron, said, shaflow2 (1, 2), mojito_auditor, klau5, fyamf, gesha17, and ZdravkoHr

Impact

Because there is no refund mechanism in the ChakraSettlement.processCrossChainCallback or ChakraSettlementHandler.receive_cross_chain_callback function, when the cross-chain ERC20 settlement fails, such as due to that the source chain’s handler can be removed from the whitelist for the destination chain after the corresponding cross-chain message is initiated on the source chain and before such message is received on the destination chain, the ChakraSettlementHandler.cross_chain_erc20_settlement function caller cannot get back and loses the tokens that have been transferred to the source chain’s handler or burned on the source chain by such caller.

Proof of Concept

When the ChakraSettlementHandler.cross_chain_erc20_settlement function is called to initiate a cross-chain ERC20 settlement, the function caller can check to ensure that the handler on the source chain is whitelisted on the destination chain. After such function call, the function caller has transferred tokens to the handler on the source chain under the MintBurn, LockUnlock, or LockMint mode or burned tokens on the source chain under the BurnUnlock mode.

https://github.com/code-423n4/2024-08-chakra/blob/f61c899c22492bdf5bdcb07cdb62ea9b4cd38825/solidity/handler/contracts/ChakraSettlementHandler.sol#L111-L223

    function cross_chain_erc20_settlement(
        string memory to_chain,
        uint256 to_handler,
        uint256 to_token,
        uint256 to,
        uint256 amount
    ) external {
        require(amount > 0, "Amount must be greater than 0");
        require(to != 0, "Invalid to address");
        require(to_handler != 0, "Invalid to handler address");
        require(to_token != 0, "Invalid to token address");

@>      if (mode == SettlementMode.MintBurn) {
@>          _erc20_lock(msg.sender, address(this), amount);
@>      } else if (mode == SettlementMode.LockUnlock) {
@>          _erc20_lock(msg.sender, address(this), amount);
@>      } else if (mode == SettlementMode.LockMint) {
@>          _erc20_lock(msg.sender, address(this), amount);
@>      } else if (mode == SettlementMode.BurnUnlock) {
@>          _erc20_burn(msg.sender, amount);
@>      }

        ...
    }

Yet, after the corresponding cross-chain message is initiated on the source chain and before such message is received on the destination chain, it is possible that the ChakraSettlementHandler.remove_handler function is called on the destination chain, which removes the source chain’s handler from the whitelist for the destination chain. This is beyond the control of the ChakraSettlementHandler.cross_chain_erc20_settlement function caller because such function caller cannot know this in advance.

https://github.com/code-423n4/2024-08-chakra/blob/f61c899c22492bdf5bdcb07cdb62ea9b4cd38825/solidity/handler/contracts/ChakraSettlementHandler.sol#L65-L70

    function remove_handler(
        string memory chain_name,
        uint256 handler
    ) external onlyOwner {
@>      handler_whitelist[chain_name][handler] = false;
    }

When the corresponding cross-chain message is received on the destination chain, since the handler on the source chain has been changed to be not whitelisted on the destination chain, the ChakraSettlementHandler.receive_cross_chain_msg function would return false, which marks the status and receive_cross_txs[txid].status corresponding to the cross-chain message as failed in the ChakraSettlement.receive_cross_chain_msg function.

https://github.com/code-423n4/2024-08-chakra/blob/f61c899c22492bdf5bdcb07cdb62ea9b4cd38825/solidity/handler/contracts/ChakraSettlementHandler.sol#L300-L355

    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;
        }
        ...
    }

https://github.com/code-423n4/2024-08-chakra/blob/f61c899c22492bdf5bdcb07cdb62ea9b4cd38825/solidity/settlement/contracts/ChakraSettlement.sol#L170-L244

    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 {
        ...

@>      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
        );
    }

Back on the source chain, the ChakraSettlement.processCrossChainCallback and ChakraSettlementHandler.receive_cross_chain_callback functions are then called with the failed cross-chain message’s status. This notifies that the corresponding cross-chain ERC20 settlement has failed by marking the corresponding create_cross_txs[txid].status as failed in both the ChakraSettlement and ChakraSettlementHandler contracts. However, such ChakraSettlement.processCrossChainCallback and ChakraSettlementHandler.receive_cross_chain_callback function calls do not refund the caller of the ChakraSettlementHandler.cross_chain_erc20_settlement function the tokens that were transferred to the source chain’s handler or burned on the source chain by such caller.

https://github.com/code-423n4/2024-08-chakra/blob/f61c899c22492bdf5bdcb07cdb62ea9b4cd38825/solidity/settlement/contracts/ChakraSettlement.sol#L303-L331

    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;
        }
    }

https://github.com/code-423n4/2024-08-chakra/blob/f61c899c22492bdf5bdcb07cdb62ea9b4cd38825/solidity/handler/contracts/ChakraSettlementHandler.sol#L365-L396

    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 ChakraSettlementHandler.receive_cross_chain_callback function can be updated to transfer the failed cross-chain ERC20 settlement’s token amount to the corresponding caller of the ChakraSettlementHandler.cross_chain_erc20_settlement function under the MintBurn, LockUnlock, or LockMint mode. If possible, such function can also be updated to mint the failed cross-chain ERC20 settlement’s token amount to the corresponding caller of the ChakraSettlementHandler.cross_chain_erc20_settlement function under the BurnUnlock mode; otherwise, if the corresponding token cannot be minted by the protocol, the protocol needs to clearly communicate with its users about the inability of refunding the failed cross-chain ERC20 settlement’s token amount under the BurnUnlock mode.

0xsomeone (judge) commented:

The submission and all its duplicates concern various ways in which the cross-chain system of the Chakra protocol can fail transactions and does not expose a mechanism to issue refunds for those failed transactions.

This issue class is significantly large, and the lack of documentation as well as insight into the Chakra node system renders it impossible to judge fairly. I believe that a refund mechanism should be set in place, and thus consider all issues related to its missing functionality to be of high severity.

To note, I believe this is a flaw arising from the design of the system itself and thus have grouped these issues based on the design principle they are based on. The Sponsor has expressed that the callback function is not invoked in all cases and is solely invoked in the MintBurn mode, indicating that a solution based on the callback mode is not in line with the desires of the Sponsor and cannot be considered the “unopinionated way” to resolve this issue.

The lack of documentation renders granular judgments of issues outlining the absence of a refund mechanism impractical to perform as any such distinction would rely on assumptions about the system that cannot be validated.


The original report as published on Code4rena, by rbserver. 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.

How it worked

Root cause

Likely the callback functions that handle a failed cross-chain message only update the transaction status and do not return the locked or burned tokens to the original sender.

Impact

The caller loses the tokens transferred to the source handler or burned on the source chain when a cross-chain ERC20 settlement fails.

What the attacker needed

Cross-chain ERC20 settlement initiated; source handler removed from whitelist before receipt

The fix

The receive_cross_chain_callback function should refund the failed settlement's token amount to the caller for MintBurn, LockUnlock, and LockMint modes, and mint the amount for BurnUnlock mode if possible.

How it was found

  1. Call cross_chain_erc20_settlement, which locks or burns the caller's tokens on the source chain.
  2. Before the message is received on the destination chain, the owner calls remove_handler to remove the source handler from the whitelist.
  3. The destination handler rejects the message because the source handler is no longer whitelisted, and the settlement marks it as failed.
  4. The failure callback on the source chain marks the transaction as failed but does not refund the tokens.

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 you send tokens across chains, the tokens are first locked or burned on the source chain. If the destination chain later rejects the message, the contracts only mark the transfer as failed and never give the tokens back. This means your tokens are stuck with no way to recover 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.

More by rbserver

View all

51 more disclosed reports, best first.

More from Chakra

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.