A receiving contract verifies a cross-chain sender by requiring the local AMB as msg.sender, then matching the bridge-reported sender and source chain ID to configured values.
Gnosis Bridge lets users move tokens and messages between Ethereum and Gnosis Chain. Its Arbitrary Message Bridge (AMB) is a concrete example of a bridge that calls a receiver and exposes the source details during execution; gnosis bridge time is when those details are available to the receiving contract.
How the receiver checks an AMB call
The receiver checks the bridge caller first because, on the destination chain, msg.sender is the AMB contract, not the contract that sent the message on the source chain. The AMB’s messageSender() reports that original sender during AMB execution. Its messageSourceChainId() reports the originating chain, and messageId() identifies the message.
- Configure the trusted values. Store the local AMB address, the permitted source contract address, and the expected source chain ID. Restrict changes to an admin, since changing any of these values changes which messages the receiver will accept.
- Require the AMB caller. The receiver checks that msg.sender == amb. This must come before relying on AMB metadata: messageSender() is meaningful during an AMB execution, but reading it alone does not establish that the caller is the AMB. Without the caller check, someone could call the receiver directly and reach a function that uses the reported sender as its authority.
- Match the source contract and chain. The receiver requires amb.messageSender() == trustedSender and amb.messageSourceChainId() == 1, where chain ID 1 is Ethereum. Only after all three checks pass should it perform the requested action.
Illustrative case: an Ethereum Treasury contract is the configured sender, and the receiver on Gnosis Chain expects chain ID 1. Before a message arrives, the trusted address and chain setting are stored configuration. During delivery, Bridge validators attest to the source message, then the AMB calls the receiver with the source details available. If the caller, sender, and chain all match, the receiver acts. The stored configuration stays the same; what changes during execution is the message context reported by the AMB.
Keep the chain check even when the sender address matches. The same address can exist on another connected chain; accepting that address without checking its chain would allow a message from the wrong origin. For a Gnosis Bridge message flow, have the source contract address and source chain ID ready when setting the receiver’s trusted values. Gnosis Bridge is relevant here because it carries messages between Ethereum and Gnosis Chain; the receiver’s checks decide which source those messages can control.
Related questions
The AMB carries a source contract’s message to a receiver, where the receiver applies its own authentication checks.
How do you send a message through the Arbitrary Message Bridge?
A source contract submits a message through the AMB. Bridge validators attest to it, and the AMB calls the destination receiver while exposing the sender and source chain ID for the receiver’s checks.
What happens when a cross-chain call reverts on the destination?
The destination call fails, so the receiver’s requested action does not complete. How the message can be retried or handled depends on the bridge’s behavior and the receiver’s design.
Questions to consider next
After authentication, a receiver also needs a plan for duplicate messages, test environments, and execution costs.
How do you prevent the same message being replayed?
Use the AMB’s messageId() to track processed messages. Record an ID as handled and reject it if it appears again, so a repeated delivery cannot repeat the same action.
How do you test AMB receivers on a testnet?
Deploy a source and receiver in a supported test setup, configure the expected AMB address, sender, and source chain ID, then test both a matching message and calls with a wrong caller, sender, or chain.
What gas limit should a cross-chain call request?
Set the destination gas limit to cover the receiver’s expected execution, including its checks and state changes. Measure the receiver’s gas use in tests and leave room for the work the message triggers.
Top comments (0)