Background of Cross-chain Technology
Blockchain Island Problem: Different blockchain networks are independent and cannot directly communicate and exchange value, forming "value islands".
shellBlockchain Islands: ┌──────────┐ ┌──────────┐ ┌──────────┐ │ Ethereum │ │ Bitcoin │ │ Solana │ │ Ecosystem│ × │Ecosystem │ × │Ecosystem │ │ ERC-20 │ │ BTC │ │ SPL │ └──────────┘ └──────────┘ └──────────┘ ↑ ↑ ↑ Cannot directly interoperate, need cross-chain bridges
Cross-chain Technology Categories
shellCross-chain Technology ├── Homogeneous Cross-chain (Same type blockchains) │ ├── Relay Chain │ └── Sidechain Bridge │ └── Heterogeneous Cross-chain (Different type blockchains) ├── HTLC (Hash Time-Locked Contracts) ├── Notary Mechanism ├── Sidechain/Relay Chain └── Cross-chain Bridge
1. HTLC (Hash Time-Locked Contracts)
Principle
Use hash locks and time locks to achieve trustless atomic swaps.
shellAtomic Swap Process (Alice exchanges BTC for Bob's ETH): Step 1: Alice generates random number S, calculates hash H = hash(S) Step 2: Alice creates BTC contract ┌─────────────────────────────────────┐ │ Lock 1 BTC, conditions: │ │ • Know S where hash(S) = H │ │ • Or refund to Alice after 24h │ └─────────────────────────────────────┘ Step 3: Bob sees H, creates ETH contract ┌─────────────────────────────────────┐ │ Lock equivalent ETH, conditions: │ │ • Know S where hash(S) = H │ │ • Or refund to Bob after 12h │ └─────────────────────────────────────┘ (Time must be shorter than Alice's contract) Step 4: Alice unlocks Bob's ETH with S Step 5: Bob sees S, unlocks Alice's BTC Result: Either both succeed in exchange, or both fail (atomicity)
Code Example
soliditycontract HTLC { address public alice; address public bob; bytes32 public hashLock; uint256 public timeout; bool public claimed; constructor(address _bob, bytes32 _hashLock, uint256 _timeout) payable { alice = msg.sender; bob = _bob; hashLock = _hashLock; timeout = _timeout; } // Bob unlocks with preimage function claim(string memory secret) public { require(msg.sender == bob, "Not bob"); require(keccak256(abi.encodePacked(secret)) == hashLock, "Invalid secret"); require(!claimed, "Already claimed"); claimed = true; payable(bob).transfer(address(this).balance); } // Alice refunds after timeout function refund() public { require(msg.sender == alice, "Not alice"); require(block.timestamp >= timeout, "Not timed out"); require(!claimed, "Already claimed"); payable(alice).transfer(address(this).balance); } }
Pros:
- ✅ No trusted third party needed
- ✅ Atomicity guarantee
Cons:
- ❌ Both parties need to be online simultaneously
- ❌ Only supports chains with same hash algorithm
- ❌ Complex user experience
2. Relay Chain
Principle
Connect multiple parachains through a dedicated relay chain to achieve cross-chain communication.
shellPolkadot Architecture Example: ┌───────────────┐ │ Relay Chain │ │ │ │ • Consensus │ │ Security │ │ • Cross-chain │ │ Message │ │ Routing │ └───────┬───────┘ │ ┌───────────────────┼───────────────────┐ │ │ │ ┌────┴────┐ ┌────┴────┐ ┌────┴────┐ │Parachain│ │Parachain│ │Parachain│ │ A │ │ B │ │ C │ │ │ │ │ │ │ │ DeFi │←───────→│ NFT │←───────→│ Game │ │ App │ XCMP │ Marketplace│ XCMP │ App │ └─────────┘ └─────────┘ └─────────┘
XCMP (Cross-chain Message Passing)
shellCross-chain Message Flow: Parachain A ──┬── Generate cross-chain message ├── Submit to relay chain ├── Relay chain validates and routes ├── Parachain B receives message └── Execute corresponding action
Representative Projects: Polkadot, Cosmos (IBC Protocol)
Pros:
- ✅ High security (shared relay chain security)
- ✅ Good scalability
Cons:
- ❌ Complex architecture
- ❌ Only supports homogeneous chains
3. Cross-chain Bridge
Principle
Achieve cross-chain assets through Lock-Mint or Burn-Unlock mechanism.
shellBridge Workflow (Ethereum → BSC): 1. Lock Phase User ──Send 10 ETH──→ Ethereum Bridge Contract ↓ Lock ETH ↓ Generate lock proof 2. Relay Phase Validators/Relayers ──Monitor and relay proof──→ BSC Bridge Contract 3. Mint Phase BSC Bridge Contract ──Verify proof──→ Mint 10 Wrapped ETH (WETH) ↓ Send to user Reverse Process (BSC → Ethereum): Burn WETH ──→ Release original ETH
Bridge Types
| Type | Mechanism | Representative | Security |
|---|---|---|---|
| Custodial | Centralized custody | WBTC | ⭐⭐ |
| Multi-sig | Multi-sig validator set | Ronin | ⭐⭐⭐ |
| Light Client | On-chain block header verification | Rainbow Bridge | ⭐⭐⭐⭐ |
| Optimistic | Fraud proof mechanism | Nomad | ⭐⭐⭐ |
| ZK Bridge | Zero-knowledge proof | zkBridge | ⭐⭐⭐⭐⭐ |
Cross-chain Bridge Security Incidents
| Time | Project | Loss | Cause |
|---|---|---|---|
| 2022-03 | Ronin | $625M | Private key leak |
| 2022-10 | BNB Chain | $570M | Contract vulnerability |
| 2021-08 | Poly Network | $610M | Contract vulnerability (later returned) |
4. LayerZero Omnichain Interoperability Protocol
Principle
Combine Oracle and Relayer to achieve trustless cross-chain communication.
shellLayerZero Architecture: Chain A LayerZero Chain B ┌─────────┐ ┌───────────┐ ┌─────────┐ │ App │──────────→│ Endpoint │ │ Endpoint│ │ Contract│ │ Contract │ │ Contract│ └────┬────┘ └─────┬─────┘ └────┬────┘ │ │ │ │ ┌────────────┼────────────┐ │ │ ↓ ↓ ↓ │ │ ┌────────┐ ┌────────┐ ┌────────┐ │ └───→│ Oracle │ │Relayer │ │ Verify │←──┘ │(Chainlink)│(Independent)│ │ Contract│ └────────┘ └────────┘ └────────┘
Core Innovation:
- Oracle provides block headers
- Relayer provides transaction proofs
- Both are independent, preventing collusion
Cross-chain Solutions Comparison
| Solution | Trust Model | Speed | Cost | Complexity | Use Case |
|---|---|---|---|---|---|
| HTLC | Trustless | Slow | Low | High | P2P atomic swaps |
| Relay Chain | Shared security | Fast | Medium | High | Homogeneous chain ecosystem |
| Custodial Bridge | Centralized | Fast | Low | Low | Simple asset transfer |
| Multi-sig Bridge | Honest majority | Fast | Medium | Medium | Mainstream asset bridging |
| ZK Bridge | Cryptographic | Fast | High | High | High security requirements |
| LayerZero | Dual independent | Fast | Medium | Medium | General message passing |
Interview Key Points
- Understand the essence of blockchain island problem
- Master HTLC atomic swap principles
- Understand relay chain working mechanisms
- Familiar with bridge Lock-Mint model
- Know trade-offs of different cross-chain solutions
- Understand cross-chain bridge security risks
- Able to analyze architecture of mainstream cross-chain projects