329 lines
9.2 KiB
Markdown
329 lines
9.2 KiB
Markdown
# Use Case 1: Cross-Chain Message Relay Network
|
|
|
|
## The Problem with Current Bridges
|
|
|
|
Traditional blockchain bridges face several critical issues:
|
|
|
|
### 1. **Central Points of Failure**
|
|
Most bridges rely on a central sequencer or small validator set that can:
|
|
- Be compromised or hacked (see Ronin, Wormhole, Nomad bridge hacks)
|
|
- Censor transactions
|
|
- Extract MEV by reordering messages
|
|
- Go offline, halting the entire bridge
|
|
|
|
### 2. **Consensus Overhead**
|
|
Bridges must achieve consensus on:
|
|
- The exact order of messages
|
|
- Which messages to include/exclude
|
|
- The state of source chains
|
|
This requires expensive consensus rounds that slow down message delivery.
|
|
|
|
### 3. **Limited Scalability**
|
|
- Sequential processing creates bottlenecks
|
|
- Adding more chains exponentially increases complexity
|
|
- Each message must wait for consensus before delivery
|
|
|
|
## The BFT-CRDT Solution
|
|
|
|
A BFT-CRDT relay network fundamentally reimagines cross-chain communication:
|
|
|
|
```
|
|
Traditional Architecture:
|
|
[Ethereum] → [Sequencer] → [Consensus] → [Polygon]
|
|
↓ ↓
|
|
[Can censor] [Slow, expensive]
|
|
|
|
BFT-CRDT Architecture:
|
|
[Ethereum] → [Relay Node 1] ↘
|
|
→ [Relay Node 2] → [CRDT Merge] → [Polygon orders by block height]
|
|
→ [Relay Node 3] ↗
|
|
↓
|
|
[No consensus needed]
|
|
```
|
|
|
|
### Key Innovation: Eventual Message Delivery Without Ordering
|
|
|
|
Instead of agreeing on THE order, the system guarantees:
|
|
1. All valid messages eventually reach all relayers
|
|
2. Destination chains deterministically order based on source chain state
|
|
3. No single relayer can censor messages
|
|
4. Byzantine relayers cannot forge messages
|
|
|
|
## Detailed Architecture
|
|
|
|
### Components
|
|
|
|
#### 1. **Source Chain Validators**
|
|
- Monitor source chain for cross-chain messages
|
|
- Sign messages with threshold signatures
|
|
- Broadcast to relay network
|
|
|
|
#### 2. **BFT-CRDT Relay Nodes**
|
|
- Receive signed messages from validators
|
|
- Merge messages using CRDT rules
|
|
- No need to agree on ordering
|
|
- Byzantine nodes can't forge due to signatures
|
|
|
|
#### 3. **Destination Chain Contracts**
|
|
- Collect messages from multiple relayers
|
|
- Order by (source_block_height, nonce)
|
|
- Execute in deterministic order
|
|
- Verify threshold signatures
|
|
|
|
### Message Structure
|
|
|
|
```rust
|
|
pub struct CrossChainMessage {
|
|
// Identity
|
|
pub id: Hash,
|
|
pub version: u32,
|
|
|
|
// Routing
|
|
pub source_chain: ChainId,
|
|
pub dest_chain: ChainId,
|
|
|
|
// Ordering hints (used by destination)
|
|
pub source_block: u64,
|
|
pub source_tx_index: u32,
|
|
pub nonce: u64,
|
|
|
|
// Payload
|
|
pub sender: Address,
|
|
pub receiver: Address,
|
|
pub data: Vec<u8>,
|
|
pub gas_limit: u64,
|
|
|
|
// Security
|
|
pub validator_signatures: Vec<ValidatorSig>,
|
|
pub merkle_proof: MerkleProof,
|
|
}
|
|
```
|
|
|
|
### CRDT Merge Rules
|
|
|
|
```rust
|
|
impl Merge for CrossChainRelay {
|
|
fn merge(&mut self, other: &Self) {
|
|
// 1. Add all messages we haven't seen
|
|
for (id, msg) in &other.messages {
|
|
if !self.messages.contains_key(id) {
|
|
if self.verify_message(msg) {
|
|
self.messages.insert(id.clone(), msg.clone());
|
|
}
|
|
}
|
|
}
|
|
|
|
// 2. Byzantine fault detection
|
|
for (id, msg) in &other.messages {
|
|
if let Some(our_msg) = self.messages.get(id) {
|
|
if !messages_equal(our_msg, msg) {
|
|
self.report_byzantine_behavior(id, our_msg, msg);
|
|
}
|
|
}
|
|
}
|
|
|
|
// 3. Merge delivery receipts
|
|
for (chain, receipts) in &other.delivery_receipts {
|
|
self.delivery_receipts
|
|
.entry(chain.clone())
|
|
.or_default()
|
|
.extend(receipts);
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
## Security Analysis
|
|
|
|
### 1. **Message Authenticity**
|
|
- Messages require threshold signatures from source chain validators
|
|
- Merkle proofs link messages to source chain blocks
|
|
- Byzantine relayers cannot forge messages
|
|
|
|
### 2. **Censorship Resistance**
|
|
- No single relayer can block messages
|
|
- Messages propagate through gossip network
|
|
- Even 1 honest relayer ensures delivery
|
|
|
|
### 3. **Delivery Guarantees**
|
|
- Eventual delivery for all valid messages
|
|
- Duplicate messages are idempotent
|
|
- Invalid messages cannot be delivered
|
|
|
|
### 4. **Byzantine Fault Tolerance**
|
|
- System operates correctly with up to f Byzantine nodes out of 3f+1
|
|
- Byzantine nodes can only:
|
|
- Refuse to relay (but others will)
|
|
- Send old messages (idempotent)
|
|
- Send invalid messages (rejected)
|
|
|
|
## Comparison with Existing Solutions
|
|
|
|
### vs. Centralized Bridges (e.g., Binance Bridge)
|
|
| Feature | Centralized Bridge | BFT-CRDT Relay |
|
|
|---------|-------------------|-----------------|
|
|
| Trust Model | Trust operator | Trustless |
|
|
| Censorship | Possible | Impossible |
|
|
| Speed | Fast | Fast |
|
|
| Availability | Single point of failure | High availability |
|
|
|
|
### vs. Consensus-Based Bridges (e.g., IBC)
|
|
| Feature | IBC | BFT-CRDT Relay |
|
|
|---------|-----|-----------------|
|
|
| Consensus Required | Yes | No |
|
|
| Message Ordering | Strict | Eventual |
|
|
| Complexity | High | Low |
|
|
| Gas Costs | High | Low |
|
|
|
|
### vs. Optimistic Bridges (e.g., Nomad)
|
|
| Feature | Optimistic Bridge | BFT-CRDT Relay |
|
|
|---------|------------------|-----------------|
|
|
| Finality | ~30 minutes | Instant |
|
|
| Security Model | Fraud proofs | Cryptographic |
|
|
| Capital Efficiency | Low | High |
|
|
|
|
## Real-World Scenarios
|
|
|
|
### Scenario 1: DEX Arbitrage
|
|
```
|
|
1. Price discrepancy detected on Ethereum
|
|
2. Arbitrageur sends message to execute on Polygon
|
|
3. Multiple relayers propagate message immediately
|
|
4. Polygon executes based on Ethereum block height
|
|
5. No MEV extraction by bridge operators
|
|
```
|
|
|
|
### Scenario 2: Cross-Chain Governance
|
|
```
|
|
1. DAO vote passes on Ethereum
|
|
2. Execution message sent to multiple L2s
|
|
3. Each L2 receives message through different relayers
|
|
4. All L2s execute in same relative order
|
|
5. No coordination needed between L2s
|
|
```
|
|
|
|
### Scenario 3: Emergency Pause
|
|
```
|
|
1. Security incident detected on one chain
|
|
2. Pause message broadcast to all chains
|
|
3. BFT-CRDT ensures delivery even if attackers control some relayers
|
|
4. All chains receive pause message eventually
|
|
5. Faster than waiting for consensus
|
|
```
|
|
|
|
## Implementation Guide
|
|
|
|
### Step 1: Deploy Relay Network
|
|
```bash
|
|
# Initialize relay nodes
|
|
./crdt-relay init --chain-config chains.yaml
|
|
./crdt-relay start --port 8545 --peers peers.txt
|
|
```
|
|
|
|
### Step 2: Deploy Source Chain Monitor
|
|
```solidity
|
|
contract SourceChainBridge {
|
|
event CrossChainMessage(
|
|
uint256 indexed nonce,
|
|
address indexed sender,
|
|
uint256 destChainId,
|
|
bytes data
|
|
);
|
|
|
|
function sendMessage(
|
|
uint256 destChainId,
|
|
address receiver,
|
|
bytes calldata data
|
|
) external payable {
|
|
uint256 nonce = _incrementNonce();
|
|
emit CrossChainMessage(nonce, msg.sender, destChainId, data);
|
|
}
|
|
}
|
|
```
|
|
|
|
### Step 3: Deploy Destination Chain Executor
|
|
```solidity
|
|
contract DestinationChainBridge {
|
|
mapping(bytes32 => bool) public executedMessages;
|
|
|
|
function executeMessage(
|
|
CrossChainMessage calldata message,
|
|
bytes[] calldata signatures
|
|
) external {
|
|
bytes32 messageId = keccak256(abi.encode(message));
|
|
require(!executedMessages[messageId], "Already executed");
|
|
require(verifySignatures(message, signatures), "Invalid sigs");
|
|
|
|
executedMessages[messageId] = true;
|
|
|
|
// Execute message
|
|
(bool success,) = message.receiver.call{
|
|
gas: message.gasLimit
|
|
}(message.data);
|
|
require(success, "Execution failed");
|
|
}
|
|
}
|
|
```
|
|
|
|
## Performance Characteristics
|
|
|
|
### Latency
|
|
- Message propagation: ~100ms between relayers
|
|
- Source chain finality: Varies by chain
|
|
- Destination execution: Next block after receipt
|
|
- Total: Source finality + ~1-2 blocks
|
|
|
|
### Throughput
|
|
- No consensus bottleneck
|
|
- Limited only by:
|
|
- Source chain event emission
|
|
- Destination chain execution capacity
|
|
- Can handle 1000s of messages/second
|
|
|
|
### Cost
|
|
- Source chain: Event emission gas
|
|
- Relay network: No fees (incentivized separately)
|
|
- Destination chain: Execution gas only
|
|
- No consensus overhead costs
|
|
|
|
## Future Enhancements
|
|
|
|
### 1. **Zero-Knowledge Message Privacy**
|
|
```rust
|
|
pub struct PrivateMessage {
|
|
pub commitment: Hash,
|
|
pub nullifier: Hash,
|
|
pub zk_proof: Proof,
|
|
// Encrypted payload revealed only to receiver
|
|
}
|
|
```
|
|
|
|
### 2. **Atomic Multi-Chain Execution**
|
|
```rust
|
|
pub struct AtomicBundle {
|
|
pub messages: Vec<CrossChainMessage>,
|
|
pub timeout: Timestamp,
|
|
pub rollback_data: Vec<RollbackInstruction>,
|
|
}
|
|
```
|
|
|
|
### 3. **Dynamic Relayer Sets**
|
|
- Stake-based relayer selection
|
|
- Automatic rotation
|
|
- Slashing for misbehavior
|
|
|
|
## Conclusion
|
|
|
|
BFT-CRDT relay networks represent a paradigm shift in cross-chain communication:
|
|
- **No consensus needed**: Messages flow freely
|
|
- **Censorship resistant**: No single point of control
|
|
- **Fast and cheap**: No consensus overhead
|
|
- **Highly available**: Continues working with node failures
|
|
|
|
This architecture is particularly suited for:
|
|
- High-frequency cross-chain operations
|
|
- Censorship-resistant message passing
|
|
- Multi-chain dApp coordination
|
|
- Emergency response systems
|
|
|
|
The key insight is that **destination chains can order messages themselves** - the relay layer just needs to guarantee eventual delivery of authenticated messages. |