Production engineering guide for cross chain bridges in Web3 and blockchain systems.
Cross-chain bridges enable the transfer of assets, data, and messages between distinct blockchains. They are essential when a dApp spans multiple chains—such as a token minted on Ethereum and used in a layer-2 rollup on Arbitrum, with settlement and governance on Solana. Bridges become critical during network congestion, cross-chain liquidity events, and when users or contracts require atomicity across chains.
Transferring assets across chains is the most common bridge use case. A user sends ETH from Ethereum to a Polygon-based application, requiring the bridge to lock ETH on Ethereum and mint equivalent wETH on Polygon.
To move 10 ETH from Ethereum to Polygon:
The bridge contract on Ethereum uses the deposit function with value and recipient:
function deposit(
address token,
uint256 amount,
address recipient,
uint256 minOut,
bytes32 data
) external payable returns (uint256 outAmount);
The data field may include a bridgeId and timestamp, enabling later cross-chain message routing.
On Polygon, the mint function accepts a proof from Ethereum’s state root:
function mint(
address token,
uint256 amount,
bytes32 proof,
uint256 blockNumber
) external;
The proof is a Merkle proof that the deposit transaction is included in a block.
Relayers monitor the Ethereum chain for new deposits. Each relayer runs a service that polls for new events from the bridge contract using eth_getLogs, with filters:
{
"method": "eth_getLogs",
"params": [
{
"address": "0x...bridge",
"topics": [
"0x...DepositEvent"
],
"fromBlock": "0x123456",
"toBlock": "latest"
}
],
"id": 1,
"jsonrpc": "2.0"
}
Relayers submit proofs to Polygon via eth_sendTransaction, with a gasLimit of 150000 and value of 0.01 ETH per transaction.
A common failure mode: a relayer misses a block due to network latency. The bridge assumes a finalityThreshold of 30 blocks on Ethereum, but the relayer only waits 20 blocks. When the next deposit arrives, the relayer submits a proof for block 20, but the bridge expects 30. The bridge rejects the proof, and users receive their assets late.
When a bridge fails to confirm a deposit:
deposit transaction is mined on Ethereum.mint transaction is submitted on Polygon.mint transaction fails due to gas, and the proof is invalid.Error logs on Polygon show:
Error: Invalid proof for block 20
at function mint
at contract 0x...bridge
at tx 0x...tx
at block 1024567
at proof: 0x...
The proof is validated using a verifyMerkleProof function that checks:
leaf is the deposit event.path matches the Merkle root from Ethereum’s stateRoot.blockNumber is correct.A mismatched blockNumber or corrupted proof leads to a MerkleProofInvalid error.
Bridges are not limited to tokens. They enable cross-chain messaging, where a contract on Ethereum triggers a function on Solana, or a state update on Optimism is reflected in a data feed on Avalanche.
A message consists of:
sourceChain (e.g., "ethereum")destinationChain (e.g., "solana")sender (address on source chain)payload (ABI-encoded data)nonce (unique identifier per sender)On the source chain, the send function is called:
function send(
bytes32 destinationChain,
address receiver,
bytes calldata payload,
uint256 fee,
uint256 nonce
) external payable returns (uint256 messageId);
On the destination chain, a receive function processes the message:
function receive(
bytes32 sourceChain,
address sender,
bytes calldata payload,
uint256 nonce,
bytes32 proof
) external;
The proof is a Merkle proof of the message inclusion in a message root stored on the destination chain.
Messages may be received out of order or duplicated. The nonce field ensures idempotency.
A common failure: a message is sent from Ethereum to Solana with nonce = 100. The Solana bridge contract receives it and processes it. But the message is re-submitted due to a relayer crash.
The Solana contract checks:
if (seenMessages[sender][nonce]) {
emit MessageAlreadyProcessed(sender, nonce);
return;
}
seenMessages[sender][nonce] = true;
If the seenMessages mapping is not updated before processing, a second receipt leads to double execution.
Another failure: a relayer submits a proof for a message, but the proof is missing a branch. The verifyMerkleProof function returns false, and the message is dropped.
Bridges are deployed as smart contracts on multiple chains. Their configuration is stored in a bridgeConfig.json file, used during deployment and runtime.
{
"bridgeId": "0x123456789abcdef",
"name": "UniversalBridge",
"version": "1.2.0",
"chains": {
"ethereum": {
"rpcUrl": "https://mainnet.infura.io/v3/abc123",
"contractAddress": "0x0123456789abcdef0123456789abcdef01234567",
"chainId": 1,
"finalityThreshold": 30,
"messageRootStorage": "0x...",
"relayerFee": "0.001",
"gasLimit": 150000
},
"polygon": {
"rpcUrl": "https://polygon-mainnet.g.alchemy.com/v2/xyz789",
"contractAddress": "0x...",
"chainId": 137,
"finalityThreshold": 10,
"messageRootStorage": "0x...",
"relayerFee": "0.0005",
"gasLimit": 120000
}
},
"relayers": [
{
"address": "0x1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b",
"fee": "0.0001",
"priority": 1
},
{
"address": "0x2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c",
"fee": "0.0002",
"priority": 2
}
],
"messageTimeout": 600000,
"maxBatchSize": 100
}
This config is used by:
deploy-bridge.js)run-relayers.sh)bridge-monitor.yaml)run-relayers.sh#!/bin/bash
set -e
export BRIDGE_CONFIG=/etc/bridge/bridgeConfig.json
export RELAYER_LOG=/var/log/relayers.log
while true; do
# Poll Ethereum for new deposits
curl -s -X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_getLogs",
"params": [
{
"address": "0x0123456789abcdef0123456789abcdef01234567",
"topics": [
"0x...DepositEvent"
],
"fromBlock": "0x123456",
"toBlock": "latest"
}
],
"id": 1
}' \
"https://mainnet.infura.io/v3/abc123" \
| jq -r '.result[] | select(.data != "0x") | .data' \
| while read data; do
# Decode deposit
decoded=$(abigen --abi deposit.abi --bin deposit.bin --out ./decoded.json <<< "$data")
# Generate Merkle proof
proof=$(create-proof --block-number "$blockNumber" --data "$data")
# Submit to destination chain
curl -s -X POST \
-H "Content-Type: application/json" \
-d "{
\"to\": \"0x...polygonBridge\",
\"data\": \"0x$(hexencode $proof)\",
\"value\": \"0x$(ethToWei 0.01)\"
}" \
"https://polygon-mainnet.g.alchemy.com/v2/xyz789" \
| jq -r '.result.transactionHash'
echo "$(date): Submitted proof for block $blockNumber" >> $RELAYER_LOG
done
sleep 5
done
A bridge health check includes:
bridge_status endpoint returning:{
"bridgeId": "0x123456789abcdef",
"chains": {
"ethereum": {
"lastBlock": 1234567,
"synced": true,
"finality": 28,
"relayerCount": 3,
"messageQueueSize": 24,
"pendingDeposits": 12
},
"polygon": {
"lastBlock": 3456789,
"synced": true,
"finality": 9,
"relayerCount": 2,
"messageQueueSize": 18,
"pendingDeposits": 8
}
},
"totalMessagesSent": 1024,
"totalMessagesReceived": 987,
"uptime": "99.8%",
"lastError": "MerkleProofInvalid"
}
An error occurs when finality is less than finalityThreshold for more than 30 minutes. The lastError is logged and triggers an alert.
nonce = 100 arrives before nonce = 99. The receiver assumes nonce is monotonically increasing, but it is not. The nonce = 99 message is processed, then 100, but 99 is not marked as seen.gasLimit = 150000 for a transaction, but the actual gas used is 160000. The transaction reverts due to out of gas, and the proof is not recorded.leaf is not correctly positioned. The verifyMerkleProof function returns false, but the error is not logged.Bridges rely on cryptographic integrity across chains. The Merkle root of the message tree is stored on the destination chain and updated periodically.
A bridge updates the message root in a updateMessageRoot transaction:
function updateMessageRoot(
bytes32 root,
uint256 blockNumber,
bytes32[] memory proofs
) external;
The proofs array contains Merkle proofs for each message in the batch.
The root is validated using a verifyRoot function:
function verifyRoot(
bytes32 root,
bytes32[] memory path,
bytes32 leaf
) public pure returns (bool) {
bytes32 computed = leaf;
for (uint i = 0; i < path.length; i++) {
computed = keccak256(abi.encodePacked(computed, path[i]));
}
return computed == root;
}
If the path is incorrect or the leaf is mismatched, the root is invalid, and the bridge rejects the update.
Cross-chain bridges are not plug-and-play. They require careful configuration, monitoring, and understanding of failure modes. The lock-and-mint pattern is straightforward but fragile. Message passing introduces ordering and idempotency challenges. Configuration is central: a single misconfigured finalityThreshold or messageTimeout can cause days of delays. Engineers must understand the full data flow: from deposit to proof to message processing, and the failure modes at each stage.
This page was rewritten on 18 October 2026. It replaced a templated version that was not specific to its own title. How these pages are written and checked. If anything here is wrong, tell us at [email protected] and we will correct it.
We use cookies for analytics (Google Analytics) and advertising (Google AdSense) to improve your experience and support free content. Privacy Policy