code4rena-2024-08-chakra-m05

[M-05] Settlement contract is mistakenly used for the handler contract when assigning ReceivedCrossChainTx struct

보고서

Summary

브릿지된 메시지를 수신한 후 저장할 때, 잘못된 값을 저장했다. 이 프로토콜이 브릿지이기에 잘못된 데이터 저장과 이벤트 발생은 중대한 문제이다.

Keyword

bridge, cross chain, wrong state

Vulnerability

브릿지에서 외부 메시지를 수신했을 시 to_handler 를 저장해야 하는 곳에 Settlement 컨트랙트 주소를 저장하였다.

struct ReceivedCrossChainTx {
    uint256 txid;
    string from_chain;
    string to_chain;
    uint256 from_address;
    uint256 from_handler;
@>  address to_handler;
    bytes payload;
    CrossChainMsgStatus status;
}
...
 
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 {
    ...
 
    receive_cross_txs[txid] = ReceivedCrossChainTx(
        txid,
        from_chain,
        contract_chain_name,
        from_address,
        from_handler,
@>      address(this),
        payload,
        CrossChainMsgStatus.Pending
    );

Impact

잘못된 상태를 저장한다. 브릿지가 잘못 작동할 수 있다.

Mitigation

address(this) 대신 to_hander 를 저장한다.


tags: bughunting, chakra, smart contract, starknet, solidity, bridge, cross chain, severity medium, wrong state