# What is cross-chain message validation?

URL: https://shield.quillaudits.com/learn/vulnerabilities/cross-chain-message-validation/

Cross-chain message validation is the set of checks a contract runs before it acts on a message from another chain: that the bridge delivered it, that the trusted contract on the source chain sent it, that it hasn't been processed before and that its payload makes sense. Skip one, and anyone who can get a message onto the bridge can make your contract mint, release funds or call functions as if your own contract on the other chain had asked. Run every check in the receiving function before any state changes, and never let a zero value count as trusted.

Last updated 3 December 2026. 6 minute read. By the QuillAudits Team.

## What does a receiving contract have to check?

A message passes two layers. The bridge, or messaging protocol, proves that the message was emitted on the source chain, with signatures, a light client or a proof against a trusted root. Your contract then decides whether it should act on that message. A gap in either layer lets a forged or unwanted message through, and each layer tends to assume the other one checked.

| Check | What it stops | How it fails |
| --- | --- | --- |
| The caller is the endpoint | Anyone calling the receive function directly | No `msg.sender` check, or an endpoint address that the wrong account can change |
| The source chain and sender are trusted | Messages from other contracts that use the same bridge | Only the endpoint is checked, or an unset trusted sender reads as zero and a zero sender matches it |
| The message is new | The same message processed twice | No record of processed message ids, or an id that leaves out the source chain |
| The payload is valid | Calls and amounts the sender never meant | The payload names a target and calldata to execute, or the amount and recipient go unchecked |
| The proof is valid (bridge code) | Messages that were never sent | A trusted root, signer set or default value that every unproven message also matches |

## What does vulnerable code look like?

This receiver mints tokens for messages from a bridge endpoint. It checks the endpoint and nothing else.

**Vulnerable: the endpoint is checked, the sender on the source chain is not (illustrative, not audited code)** `MintOnMessage.sol`

```
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

contract MintOnMessage {
    address public immutable endpoint; // the bridge contract that delivers messages on this chain
    mapping(address => uint256) public balanceOf;
    uint256 public totalSupply;

    constructor(address endpoint_) {
        endpoint = endpoint_;
    }

    // The endpoint calls this with the source chain, the contract that sent the
    // message on that chain, and the payload.
    function receiveMessage(uint32 /* srcChainId */, bytes32 /* srcSender */, bytes calldata payload) external {
        require(msg.sender == endpoint, "only endpoint");
        // The source is never checked, so any contract on any connected chain
        // can send a payload through the same endpoint and mint here.
        (address to, uint256 amount) = abi.decode(payload, (address, uint256));
        balanceOf[to] += amount;
        totalSupply += amount;
    }
}
```

The endpoint is shared. Any contract on any chain the bridge connects can send a message addressed to this receiver, and the endpoint delivers it faithfully, with an honest `srcSender` that the receiver never reads. An attacker deploys a contract on a connected chain, sends a payload that mints to themselves, and the bridge does exactly what it was built to do.

## How do you fix it?

**Fixed: endpoint, a trusted peer per chain, processed message ids and payload checks (illustrative, not audited code)** `PeerCheckedMint.sol`

```
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

contract PeerCheckedMint {
    address public immutable endpoint;
    address public immutable owner; // a multisig behind a timelock: setting a peer is as strong as minting
    mapping(uint32 => bytes32) public peers; // source chain => the one contract trusted there
    mapping(bytes32 => bool) public processed;
    mapping(address => uint256) public balanceOf;
    uint256 public totalSupply;

    event PeerSet(uint32 indexed chainId, bytes32 peer);

    constructor(address endpoint_, address owner_) {
        endpoint = endpoint_;
        owner = owner_;
    }

    function setPeer(uint32 chainId, bytes32 peer) external {
        require(msg.sender == owner, "only owner");
        peers[chainId] = peer;
        emit PeerSet(chainId, peer); // monitoring should alert on every change
    }

    function receiveMessage(uint32 srcChainId, bytes32 srcSender, bytes calldata payload) external {
        require(msg.sender == endpoint, "only endpoint");
        // An unset peer reads as zero, so a zero sender must never count as a match.
        require(srcSender != bytes32(0) && srcSender == peers[srcChainId], "untrusted source");
        (uint64 nonce, address to, uint256 amount) = abi.decode(payload, (uint64, address, uint256));
        bytes32 id = keccak256(abi.encode(srcChainId, srcSender, nonce));
        require(!processed[id], "already processed");
        processed[id] = true;
        require(to != address(0) && amount > 0, "bad payload");
        balanceOf[to] += amount;
        totalSupply += amount;
    }
}
```

- Check the sender on the source chain, per chain. Keep one trusted peer for each source chain and compare it with the `srcSender` the endpoint authenticated, never with an address taken from the payload.
- Never let zero match. A mapping returns zero for a chain you never configured. The fixed receiver rejects a zero sender, so an unset peer can't be matched by a message that carries zero.
- Record processed messages. The id covers the source chain, the sender and a nonce, so a message delivered twice, by a retry or a second route, is processed once.
- Validate the payload, and never execute it. Decode fixed fields and check them. A receiver that calls whatever target and calldata a message names lends its own permissions to every sender.
- Protect the configuration. Setting a peer is as powerful as minting, so the owner should be a multisig behind a timelock, and every peer change should emit an event that someone watches.

In a Foundry test, the vulnerable receiver minted for a sender it had never heard of. The fixed one refused a zero sender on an unconfigured chain, refused an untrusted sender, minted for its peer and refused the same message a second time.

## How has cross-chain message validation failed in real exploits?

| Protocol | Nomad bridge |
| --- | --- |
| Date | 1 August 2022 |
| Chain | Cross-chain (Nomad bridge contracts) |
| Loss | about $190M |
| What happened | Nomad's bridge processed a message only if the root it was proven against was trusted. An earlier routine upgrade had marked the zero hash as a trusted root, and zero is also the value the contract returns for a message nobody has proven, so unproven messages passed the check. The bridge lost about $190M on 1 August 2022, according to [Immunefi's analysis](https://immunefi.com/blog/bug-fix-reviews/hack-analysis-nomad-bridge-august-2022/). |
| Sources | [Immunefi](https://immunefi.com/blog/bug-fix-reviews/hack-analysis-nomad-bridge-august-2022/) |

The lesson carries over to application code: a zero value that means unset in one mapping must never be accepted as a match in another. That is why the fixed receiver rejects a zero sender even though the bridge in front of it is assumed to be honest.

Poly Network's loss came through the payload. According to analyses by [SlowMist](https://slowmist.medium.com/the-root-cause-of-poly-network-being-hacked-ec2ee1b0c68f) and [CertiK](https://www.certik.com/blog/poly-network-exploit), its cross-chain manager executed the call a message named, and the manager owned the contract that stored the keepers' public keys. In August 2021 an attacker sent a message whose call replaced those keys, then moved about $610M. A receiver that only decodes fixed fields, like the fixed code above, gives a message no call to name.

## What should a reviewer check?

- Does every function a bridge or messenger calls check `msg.sender` against the endpoint, and who can change that endpoint?
- Are the source chain and source sender checked against a trusted peer for that chain, using the values the endpoint authenticated rather than fields in the payload?
- Can an unset peer, an empty signer set or any other default zero value ever count as a match?
- Are processed message ids recorded, and does each id include the source chain?
- Does any message name a target, calldata or token to act on, and is each one limited to a list you control?
- Who can change peers, endpoints and limits, and do those changes go through a multisig, a timelock and an event?
- Are there caps per message and per day, so one bad message can't take everything?
- In bridge code, does proof checking reject a root, signature set or hash that is zero or was never initialized?

## How does QuillShield check for cross-chain message validation?

A receiver is only as safe as its configuration, so write down which endpoint, chains and peers each contract should trust. Before an audit you can add context such as the whitepaper, trust assumptions, privileged roles and previous audit reports, and the trusted peers belong in the trust assumptions.

QuillShield runs a full audit of a Solidity codebase in a Foundry project. It builds a security graph of the code and lists the invariants the code must keep. A separate reviewer agent tries to disprove every finding before you see it, and each finding that holds up comes with the exact lines, the impact, a recommended fix and, on full audits, a proof of concept.

It then checks every pull request on GitHub or GitLab.com against that graph. A new chain, a new peer or a new message type is a small diff with a large blast radius, so none of them should merge unreviewed. Relayers, signers and their keys run off-chain, outside a Solidity audit, and need their own review.

[Run a full audit](https://shield.quillaudits.com/register) on your receivers and adapters, or [talk to an auditor](https://calendly.com/akshadh-a-quillaudits/30min) about a bridge launch. New accounts get $50 in credit, good for up to half of an order.

## FAQ

### Isn't validating messages the bridge's job?

Only half of it. The bridge proves that a message was sent on the source chain. Your contract decides whether it trusts the contract that sent it, whether it has seen the message before and whether the payload is one it should act on.

### What is a trusted peer?

The one contract on a given source chain that your receiver accepts messages from. It is stored per chain and compared with the sender the endpoint authenticated, never with an address inside the payload.

### Do I need replay protection if the bridge already has it?

Keep your own record whenever a message can reach you more than once, for example through a retry, a second bridge or a move to a new endpoint. A processed-id mapping costs one storage write per message.

### Do a rollup's own bridge messages need the same checks?

Yes, with details of their own. On Arbitrum, the sender you see for a message from an Ethereum contract is that contract's address offset by `0x1111000000000000000000000000000000001111`, and the [Arbitrum docs](https://docs.arbitrum.io/arbos/l1-to-l2-messaging) have the receiver remove the offset before comparing it with the contract it expects.

### Why reject a zero sender?

Because a mapping returns zero for any key you never set. Nomad's bridge lost about $190M in August 2022 after the zero hash was marked as a trusted root, the same value its contract returns for a message nobody has proven.

## Sources

- [Hack Analysis: Nomad Bridge, August 2022, Immunefi](https://immunefi.com/blog/bug-fix-reviews/hack-analysis-nomad-bridge-august-2022/) · checked 20 November 2026
- [The root cause of Poly Network being hacked, SlowMist](https://slowmist.medium.com/the-root-cause-of-poly-network-being-hacked-ec2ee1b0c68f) · checked 24 November 2026
- [Poly Network Exploit, CertiK](https://www.certik.com/blog/poly-network-exploit) · checked 24 November 2026
- [L1 to L2 messaging, Arbitrum docs](https://docs.arbitrum.io/arbos/l1-to-l2-messaging) · checked 3 December 2026
- [OWASP Smart Contract Top 10: 2026, OWASP](https://scs.owasp.org/sctop10/) · checked 3 December 2026
