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:
Signature Verification: Multi-signature validation from relayer network
Replay Protection: Command IDs prevent duplicate execution
Source Verification: Validates the actual source contract
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
Validate Destinations: Ensure target contracts exist and are correct
Optimize Payload: Minimize payload size to reduce gas costs
Handle Failures: Implement proper error handling for failed calls
Gas Management: Provide adequate gas for execution
For Receivers
Implement Security: Always verify message sources
Idempotent Operations: Design functions to handle potential replays
Gas Efficiency: Optimize execution to minimize gas usage
State Management: Properly manage state changes from cross-chain calls
General Guidelines
Testing: Thoroughly test cross-chain interactions on testnets
Monitoring: Implement monitoring for cross-chain message status
Documentation: Document cross-chain integration clearly
Upgradability: Consider upgrade paths for cross-chain contracts
Integration Examples
Simple Cross-Chain Counter
Cross-Chain Token Vault
Resources
Last updated

