Message Passing

IU2U Protocol implements a sophisticated message passing system that enables secure and reliable communication between smart contracts across different blockchain networks.

Overview

The message passing system allows smart contracts on one blockchain to call functions on smart contracts deployed on different blockchains, enabling true cross-chain smart contract interaction.

Message Structure

Basic Message Format

struct CrossChainMessage {
    bytes32 messageId;           // Unique message identifier
    string sourceChain;          // Source blockchain name
    string destinationChain;     // Target blockchain name
    address sourceAddress;       // Sender contract address
    string destinationAddress;   // Target contract address
    bytes payload;              // Function call data
    uint256 gasLimit;           // Gas limit for execution
    uint256 timestamp;          // Message creation time
    bytes32 payloadHash;        // Hash of the payload
}

Message Types

The protocol supports different types of cross-chain messages:

Message Lifecycle

Implementation

Sending Messages

To send a cross-chain message, contracts call the IU2U Gateway:

Example Usage

Receiving Messages

Contracts receiving cross-chain messages must implement the IU2UExecutable interface:

Example Implementation

Security Considerations

Message Validation

All cross-chain messages undergo rigorous validation:

  1. Signature Verification: Multi-signature validation from relayer network

  2. Replay Protection: Command IDs prevent duplicate execution

  3. Source Verification: Validates the actual source contract

  4. Payload Integrity: Hash verification ensures payload integrity

Access Control

Anti-Replay Mechanisms

Gas Management

Gas Estimation

The protocol provides gas estimation for cross-chain calls:

Gas Payment Models

1. Prepaid Gas

2. Token-Based Gas Payment

Error Handling

Execution Failures

Retry Mechanisms

Advanced Features

Conditional Execution

Batch Message Processing

Message Scheduling

Best Practices

For Senders

  1. Validate Destinations: Ensure target contracts exist and are correct

  2. Optimize Payload: Minimize payload size to reduce gas costs

  3. Handle Failures: Implement proper error handling for failed calls

  4. Gas Management: Provide adequate gas for execution

For Receivers

  1. Implement Security: Always verify message sources

  2. Idempotent Operations: Design functions to handle potential replays

  3. Gas Efficiency: Optimize execution to minimize gas usage

  4. State Management: Properly manage state changes from cross-chain calls

General Guidelines

  1. Testing: Thoroughly test cross-chain interactions on testnets

  2. Monitoring: Implement monitoring for cross-chain message status

  3. Documentation: Document cross-chain integration clearly

  4. Upgradability: Consider upgrade paths for cross-chain contracts

Integration Examples

Simple Cross-Chain Counter

Cross-Chain Token Vault

Resources

Last updated