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
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 chains 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 chains handler or burned on the source chain by such caller.
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
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 chains 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
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
https://github.com/code-423n4/2024-08-chakra/blob/f61c899c22492bdf5bdcb07cdb62ea9b4cd38825/solidity/settlement/contracts/ChakraSettlement.sol#L170-L244
Back on the source chain, the ChakraSettlement.processCrossChainCallback and ChakraSettlementHandler.receive_cross_chain_callback functions are then called with the failed cross-chain messages 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 chains 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
https://github.com/code-423n4/2024-08-chakra/blob/f61c899c22492bdf5bdcb07cdb62ea9b4cd38825/solidity/handler/contracts/ChakraSettlementHandler.sol#L365-L396
The ChakraSettlementHandler.receive_cross_chain_callback function can be updated to transfer the failed cross-chain ERC20 settlements 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 settlements 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 settlements token amount under the BurnUnlock mode.
0xsomeone (judge) commented:
