Submitted by fyamf, also found by AllTooWell, haxatron, ABAIKUNANBAEV, 0xb0k0, calc1f4r (1, 2), and Draiakoo
The from_address parameter in the events emitted when sending a cross-chain message from Starknet is set to the transaction origin (tx.origin) instead of the actual caller (msg.sender). This causes incorrect data to be emitted in the event.
When a cross-chain message is sent from Starknet using the function handler_erc20::cross_chain_erc20_settlement, the function settlement::send_cross_chain_msg is called:
Within this function, the CrossChainMsg event is emitted for validators to pick up:
https://github.com/code-423n4/2024-08-chakra/blob/main/cairo/handler/src/settlement.cairo#L299
The issue is that from_address is set to get_tx_info().unbox().account_contract_address, which represents The account contract from which this transaction originates. This is equivalent to tx.origin in EVM-based blockchains: https://github.com/starkware-libs/cairo/blob/main/corelib/src/starknet/info.cairo#L46
This is incorrect because the address of the original transaction sender is irrelevant. Instead, from_address should represent the caller of the handler_erc20::cross_chain_erc20_settlement function.
In contrast, the EVM-based code correctly sets from_address to the parameter forwarded by the ChakraSettlementHandler::cross_chain_erc20_settlement function, which is equivalent to msg.sender:
https://github.com/code-423n4/2024-08-chakra/blob/main/solidity/handler/contracts/ChakraSettlementHandler.sol#L205
https://github.com/code-423n4/2024-08-chakra/blob/main/solidity/settlement/contracts/ChakraSettlement.sol#L113
By using the transaction originators address (tx.origin) as from_address, the event may include an address that is irrelevant to the cross-chain transaction. This can result in misleading information for any third parties reading the events. Here are two scenarios where an incorrect from_address might be used:
Here is the simplified rephrased version of the report:
https://github.com/OpenZeppelin/cairo-contracts/blob/main/packages/token/src/erc721/erc721.cairo#L571
https://book.cairo-lang.org/ch16-04-L1-L2-messaging.html?highlight=%23%5Bl1_handler%5D#sending-messages-from-ethereum-to-starknet
https://docs.cairo-lang.org/hello_starknet/user_auth.html#getting-the-caller-address
https://cairopractice.com/posts/get_caller_address_zero/
Additionally, when a callback message is received, the CrossChainResult event will show from_address as get_tx_info().unbox().account_contract_address, which is also incorrect and misleading.
Following modifications are recommended:
zvlwwj (Chakra) confirmed
0xsomeone (judge) commented:
