乐闻世界logo
搜索文章和话题

What is Cross-chain Technology? Detailed Explanation of Atomic Swaps, Relay Chains, and Bridge Solutions

3月6日 21:44

Background of Cross-chain Technology

Blockchain Island Problem: Different blockchain networks are independent and cannot directly communicate and exchange value, forming "value islands".

shell
Blockchain Islands: ┌──────────┐ ┌──────────┐ ┌──────────┐ │ Ethereum │ │ Bitcoin │ │ Solana │ │ Ecosystem│ × │Ecosystem │ × │Ecosystem │ │ ERC-20 │ │ BTC │ │ SPL │ └──────────┘ └──────────┘ └──────────┘ ↑ ↑ ↑ Cannot directly interoperate, need cross-chain bridges

Cross-chain Technology Categories

shell
Cross-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.

shell
Atomic 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

solidity
contract 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.

shell
Polkadot 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)

shell
Cross-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.

shell
Bridge 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

TypeMechanismRepresentativeSecurity
CustodialCentralized custodyWBTC⭐⭐
Multi-sigMulti-sig validator setRonin⭐⭐⭐
Light ClientOn-chain block header verificationRainbow Bridge⭐⭐⭐⭐
OptimisticFraud proof mechanismNomad⭐⭐⭐
ZK BridgeZero-knowledge proofzkBridge⭐⭐⭐⭐⭐

Cross-chain Bridge Security Incidents

TimeProjectLossCause
2022-03Ronin$625MPrivate key leak
2022-10BNB Chain$570MContract vulnerability
2021-08Poly Network$610MContract vulnerability (later returned)

4. LayerZero Omnichain Interoperability Protocol

Principle

Combine Oracle and Relayer to achieve trustless cross-chain communication.

shell
LayerZero 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

SolutionTrust ModelSpeedCostComplexityUse Case
HTLCTrustlessSlowLowHighP2P atomic swaps
Relay ChainShared securityFastMediumHighHomogeneous chain ecosystem
Custodial BridgeCentralizedFastLowLowSimple asset transfer
Multi-sig BridgeHonest majorityFastMediumMediumMainstream asset bridging
ZK BridgeCryptographicFastHighHighHigh security requirements
LayerZeroDual independentFastMediumMediumGeneral 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
标签:Blockchain