Skip to content

bpolania/NEAR-Cosmos-SDK

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

133 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Proxima SDK

Version Build Status Tests License

Bridging NEAR and Cosmos ecosystems

Version 1.0.0 - Production Ready Modular Architecture with CosmWasm Support

Proxima is a complete Cosmos SDK runtime implemented as NEAR smart contracts with full IBC (Inter-Blockchain Communication) infrastructure, CosmWasm compatibility, and a production-ready off-chain relayer for cross-chain communication between NEAR and Cosmos chains.

Current Release

Version 1.0.0 represents the first stable release with modular architecture and full CosmWasm support:

Component Version Status Tests
Router Contract 1.0.0 Deployed to Testnet 230+ tests passing
WASM Module 1.0.0 Deployed to Testnet 60+ tests passing
IBC Relayer 1.0.0 Production Ready 350+ tests passing
Overall System 1.0.0 Production Ready 640+ total tests
Documentation 1.0.0 Production Ready Comprehensive guides

Key Achievements:

  • Modular Architecture: Separated router and module contracts for better scalability
  • CosmWasm Compatibility: Full support for running CosmWasm contracts on NEAR
  • CW20 Token Support: Complete implementation and testing of CW20 token standard
  • Off-Chain Relayer: Wasmer-based execution with transaction signing
  • Cosmos Address System: Native support for Cosmos-style addresses with 'proxima' prefix
  • Enterprise Security: AES-256-GCM encryption with VSA-2022-103 patches
  • Comprehensive Testing: 640+ tests with 100% success rate across all components
  • Live Testnet Deployment: Both router and WASM module contracts deployed and operational

Overview

Proxima implements a modular architecture with separate contracts for routing and module execution:

Core Components

Router Contract (cosmos-router.cuteharbor3573.testnet):

  • Module registration and management
  • Cross-contract call routing
  • Unified interface for all Cosmos SDK modules

WASM Module (wasm-module.cuteharbor3573.testnet):

  • CosmWasm contract storage and execution
  • CW20 token standard support
  • Cosmos address system with 'proxima' prefix
  • Off-chain execution queue for relayer integration

IBC Infrastructure:

  • IBC Light Client: Tendermint light client (ICS-07)
  • IBC Connection Module: Connection handshake protocol (ICS-03)
  • IBC Channel Module: Packet-based messaging (ICS-04)
  • IBC Token Transfer: Cross-chain token transfers (ICS-20)

Off-Chain Relayer:

  • Wasmer-based CosmWasm execution
  • Transaction signing and broadcasting
  • Execution queue processing
  • Key management with secp256k1 support

All persistent state lives in NEAR's key-value store, namespaced by module with proper isolation.

Version History & Changelog

Version 1.0.0 (2025-08-23) - Stable Release with Modular Architecture

Major Features:

  • Modular Architecture: Complete separation of router and module contracts for improved scalability and maintainability
  • Router Contract: Central hub for module registration and cross-contract routing
  • WASM Module Contract: Standalone CosmWasm execution environment with full CW20 support
  • Off-Chain Relayer: Wasmer-based execution with transaction signing and queue processing
  • Cosmos Address System: Full implementation of Cosmos-style addresses with 'proxima' prefix
  • Permission System: Original caller tracking for proper authorization through router
  • CW20 Token Deployment: Successfully deployed and tested CW20 tokens on testnet

Technical Improvements:

  • Fixed all test failures across the entire codebase (640+ tests passing)
  • Added JsonSchema support for ABI generation
  • Improved cross-contract call interfaces
  • Enhanced error handling and type safety
  • Removed obsolete scripts and test files
  • Updated Docker configuration for wasmd testnet

Deployments:

  • Router Contract: cosmos-router.cuteharbor3573.testnet
  • WASM Module: wasm-module.cuteharbor3573.testnet
  • Both contracts fully operational on NEAR testnet

Version 0.9.0-beta (2025-08-05) - CosmWasm Compatibility Release

Latest Major Feature - CosmWasm Runtime Compatibility:

  • CosmWasm API Layer: Complete implementation of CosmWasm standard types, storage, and cryptographic APIs
  • Contract Migration Support: Existing CosmWasm contracts can run on Proxima with minimal changes
  • Storage Compatibility: Range queries, prefix iterations, and efficient key management
  • Memory Management: Bridge between CosmWasm allocation model and NEAR's register system
  • Response Processing: Full translation of CosmWasm responses to NEAR actions and events
  • Ecosystem Access: Direct access to hundreds of proven, audited CosmWasm contracts

Previous Major Features Completed:

  • Complete IBC Infrastructure: Full implementation of ICS-07 (Light Client), ICS-03 (Connection), ICS-04 (Channel), and ICS-20 (Token Transfer)
  • Production IBC Relayer: Full-featured relayer with packet scanning, proof generation, timeout detection, and bidirectional relay
  • Local Development Environment: Docker-based wasmd testnet with automated setup and configuration
  • Comprehensive Testing: 226+ tests passing across all components with full integration coverage
  • Secure Keystore: AES-256-GCM encrypted key management with secp256k1 (Cosmos) and ed25519 (NEAR) support
  • Rate Limit Handling: Robust error handling with exponential backoff for external API rate limits
  • Testnet Deployment: Live infrastructure deployed on NEAR testnet with automated deployment scripts
  • Cross-Chain Key Management: Fixed testnet key format compatibility and environment variable isolation

Core Components:

  • Smart Contract: Unified Cosmos SDK runtime with Bank, Staking, Governance, full IBC stack, and CosmWasm compatibility
  • CosmWasm Runtime: Complete compatibility layer enabling existing Cosmos smart contracts to run on NEAR
  • IBC Relayer: Production-ready relayer with enhanced packet processing and state management
  • Deployment Scripts: Automated IBC infrastructure setup and validation scripts
  • Configuration System: Flexible TOML-based multi-chain configuration with secure key management

Technical Achievements:

  • 322+ Tests Passing: Comprehensive test coverage including unit, integration, and live testnet validation
  • Thread-Safe Architecture: Resolved all Send + Sync trait bounds for production deployment
  • Network Resilience: Enhanced error recovery with exponential backoff and circuit breaker patterns
  • Security Hardened: VSA-2022-103 critical security patches and comprehensive input validation
  • Local Testnet Infrastructure: Complete Docker-based wasmd setup for reliable local development
  • Key Manager Compatibility: Fixed testnet key format issues and environment variable contamination

Production Infrastructure:

  • Contract: cosmos-sdk-demo.testnet with complete Cosmos SDK module implementation
  • IBC Client: 07-tendermint-0 ready for cross-chain verification
  • IBC Connection: connection-0 established for handshake completion
  • IBC Channel: channel-0 configured for ICS-20 token transfers

Version 0.9.0 (2025-01-29) - IBC Relayer Implementation

Added:

  • Complete IBC relayer architecture with chain abstraction
  • NEAR chain integration with real RPC calls and packet queries
  • Enhanced Cosmos chain support with Tendermint RPC integration
  • Packet relay engine with lifecycle tracking and state management
  • Secure keystore management with dual cryptography support
  • Comprehensive test suite with 168+ integration tests

Version 0.8.0 (2025-01-28) - IBC Token Transfer Module

Added:

  • Complete ICS-20 fungible token transfer implementation
  • Bidirectional token transfers with escrow/mint mechanics
  • Denomination tracing and multi-hop transfer support
  • 17 comprehensive tests covering all transfer scenarios

Version 0.7.0 (2025-01-27) - IBC Infrastructure Completion

Added:

  • IBC Channel Module (ICS-04) with complete packet lifecycle
  • Multi-store proof verification for cross-chain state validation
  • Enhanced IBC Connection Module with handshake automation
  • Production-ready cryptographic verification with security patches

Version 0.6.0 (2025-01-26) - IBC Light Client

Added:

  • Complete IBC Light Client implementation (ICS-07)
  • Tendermint header verification with Ed25519 signature validation
  • ICS-23 IAVL Merkle proof verification with batch operations
  • Security hardening with VSA-2022-103 patches

Earlier Versions (0.1.0 - 0.5.0)

Foundation (0.1.0 - 0.3.0):

  • Basic Cosmos SDK module structure (Bank, Staking, Governance)
  • NEAR SDK integration with proper WASM compilation
  • Initial testing framework with near-workspaces

IBC Foundation (0.4.0 - 0.5.0):

  • IBC Connection Module basic implementation
  • Initial cross-chain communication framework
  • Test suite expansion and integration testing

Architecture

Proxima/                           # Modular Cosmos SDK on NEAR
├── crates/
│   ├── cosmos-sdk-contract/      # Router Contract
│   │   ├── src/
│   │   │   ├── lib.rs            # Router entry point
│   │   │   └── modules/          # Module interfaces
│   │   ├── tests/                # Router tests (230+ tests)
│   │   └── target/near/          # Compiled WASM
│   ├── wasm-module-contract/     # WASM Module Contract
│   │   ├── src/
│   │   │   ├── lib.rs            # WASM module entry
│   │   │   ├── execution_queue.rs# Off-chain execution
│   │   │   └── address.rs        # Cosmos addresses
│   │   ├── tests/                # Module tests (60+ tests)
│   │   └── target/near/          # Compiled WASM
│   └── ibc-relayer/              # Off-Chain Relayer
│       ├── src/
│       │   ├── main.rs           # CLI interface
│       │   ├── cosmwasm/         # Wasmer execution
│       │   ├── chains/           # NEAR + Cosmos
│       │   ├── relay/            # Core relay engine
│       │   └── keystore/         # Key management
│       ├── tests/                # Relayer tests (350+ tests)
│       └── docker/               # Local testnet setup
├── Cargo.toml                    # Workspace configuration
└── README.md                     # This documentation

Requirements

  • Rust 1.86.0 (for NEAR-compatible WASM compilation)
  • cargo-near (for proper NEAR contract building)
  • near-cli (for deployment)

Building

Router Contract

# Build the router contract
cd crates/cosmos-sdk-contract
cargo near build

# Output: target/near/cosmos_sdk_contract.wasm

WASM Module Contract

# Build the WASM module
cd crates/wasm-module-contract
cargo near build

# Output: target/near/wasm_module_contract.wasm

IBC Relayer

# Build the relayer
cd crates/ibc-relayer
cargo build --release

# Run tests
cargo test

# Start relayer with Wasmer execution
cargo run -- start

Deployment

Contract Deployment

Deploy Router Contract

cd crates/cosmos-sdk-contract
cargo near build
near deploy --accountId cosmos-router.testnet --wasmFile target/near/cosmos_sdk_contract.wasm

Deploy WASM Module

cd crates/wasm-module-contract
cargo near build
near deploy --accountId wasm-module.testnet --wasmFile target/near/wasm_module_contract.wasm

# Initialize with router
near call wasm-module.testnet new '{"owner": "admin.testnet", "router": "cosmos-router.testnet"}' --accountId admin.testnet

Register Module with Router

near call cosmos-router.testnet register_module '{"module_type": "wasm", "contract_id": "wasm-module.testnet", "version": "1.0.0"}' --accountId admin.testnet

Deploy CW20 Token

# Store CW20 contract code
near call wasm-module.testnet store_code '{"wasm_byte_code": "<base64_encoded_cw20_wasm>"}' --accountId admin.testnet

# Instantiate CW20 token
near call wasm-module.testnet instantiate '{
  "code_id": 1,
  "msg": "{\"name\":\"Test Token\",\"symbol\":\"TEST\",\"decimals\":6,\"initial_balances\":[]}",
  "label": "test-token",
  "admin": "admin.testnet"
}' --accountId admin.testnet

Live Testnet Infrastructure

The project has deployed infrastructure on NEAR testnet:

  • Router Contract: cosmos-router.cuteharbor3573.testnet
  • WASM Module: wasm-module.cuteharbor3573.testnet
  • CW20 Tokens: Successfully deployed and tested
  • Account: cuteharbor3573.testnet (deployment account)

Note: This project uses the official NEAR SDK for Rust with cargo-near for reliable WASM compilation and deployment.

Testing

Run all tests across the workspace:

# Run all 640+ tests
cargo test --workspace

# Test specific components
cd crates/cosmos-sdk-contract && cargo test    # Router tests (230+)
cd crates/wasm-module-contract && cargo test   # WASM module tests (60+)
cd crates/ibc-relayer && cargo test           # Relayer tests (350+)

Key Features

Modular Architecture

  • Router Pattern: Central contract routes calls to specialized modules
  • Module Isolation: Each module operates independently with its own storage
  • Cross-Contract Calls: Efficient promise-based communication between contracts
  • Permission System: Original caller tracking for proper authorization

CosmWasm Compatibility

  • Full API Support: Complete CosmWasm standard library implementation
  • CW20 Tokens: Successfully deployed and tested CW20 token contracts
  • Wasmer Execution: Off-chain execution with transaction signing
  • Storage Compatibility: Range queries and prefix iterations

Cosmos Address System

  • Native Format: 'proxima1' prefix for all addresses
  • Conversion: Automatic conversion between NEAR and Cosmos addresses
  • Compatibility: Works with existing Cosmos tooling

Module Details

Bank Module

  • Balance struct with efficient binary serialization
  • Transfer(sender, receiver, amount) - Transfer tokens between accounts
  • Mint(receiver, amount) - Create new tokens
  • All operations emit NEAR logs via custom runtime bindings

Staking Module

  • Validator registration and delegation tracking
  • 100-block unbonding period for undelegations
  • 5% flat reward percentage distributed per block
  • BeginBlock and EndBlock hooks for processing

Governance Module

  • Parameter store for on-chain configuration
  • 50-block voting periods
  • 50% quorum threshold for proposal passage
  • Parameter changes applied automatically on successful votes

Block Processing

  • ProcessBlock() function increments block height counter
  • Calls BeginBlock and EndBlock hooks for all modules
  • Designed for cron.cat integration for regular execution

Cosmos Transaction Processing (Phase 2)

  • Complete Cosmos SDK Compatibility: Full support for CosmosTx, TxBody, AuthInfo, and Fee structures
  • Signature Verification: secp256k1 signature validation with replay protection via sequence numbers
  • Account Management: Cosmos-style account numbers and sequences with NEAR account ID compatibility
  • Fee Processing: Automatic conversion of Cosmos denominations to NEAR gas with multi-token support
  • ABCI Response Formatting: Complete ABCI-compatible transaction responses with standardized error codes
  • Transaction Simulation: Full transaction simulation with gas estimation and validation
  • Multi-Message Support: Complex transactions with multiple message types and proper event aggregation
  • Public API Interface: Complete Cosmos SDK RPC-compatible API for transaction broadcasting and management

Public API Methods (Week 4.1 Complete)

  • broadcast_tx_sync(): Submit Cosmos SDK transactions with immediate ABCI-compatible responses
  • simulate_tx(): Simulate transactions for gas estimation and validation without execution
  • broadcast_tx_async(): Async transaction broadcasting with immediate response
  • broadcast_tx_commit(): Transaction broadcasting with block commitment and height inclusion
  • get_tx(): Transaction lookup by hash with proper error handling
  • update_tx_config(): Runtime configuration management for chain parameters and gas limits
  • get_tx_config(): Retrieve current transaction processing configuration

Documentation Suite (Phase 2 Week 4.3 Complete)

  • API_REFERENCE.md: Complete API reference for all 7 public methods with parameters, responses, error codes, and performance characteristics
  • TRANSACTION_GUIDE.md: Comprehensive transaction building guide with complete structure, step-by-step construction, message types, and validation rules
  • ERROR_HANDLING.md: Complete error handling reference with all ABCI error codes, common scenarios, solutions, and debugging checklist
  • INTEGRATION_EXAMPLES.md: Multi-language integration examples (JavaScript/TypeScript, Go, Python, Rust) with complete implementations
  • CONFIGURATION.md: Complete configuration management guide with runtime parameters, monitoring strategies, and operational procedures
  • GAS_OPTIMIZATION.md: Comprehensive gas estimation and optimization guide with strategies, techniques, and analytics
  • PERFORMANCE.md: Complete performance tuning guide with contract-level optimizations and infrastructure best practices

IBC Light Client Module (ICS-07)

  • 07-tendermint Light Client: Complete IBC light client implementation for cross-chain communication
  • Client State Management: Create and update Tendermint light clients with trust parameters
  • Consensus State Tracking: Store and retrieve consensus states at verified heights
  • Cryptographic Verification: Full Ed25519 signature verification and complete ICS-23 IAVL Merkle proof verification
  • Batch Proof Verification: Efficient verification of multiple key-value pairs in single operations for improved performance
  • Range Proof Verification: Efficient verification of consecutive key ranges for packet sequences and sequential state updates
  • Security Hardened: VSA-2022-103 critical security patches implemented to prevent proof forgery attacks
  • Canonical JSON Signing: Proper Tendermint canonical JSON format for signature verification
  • Header Validation: Comprehensive signature verification, voting power validation, and timestamp checks
  • Production Ready: All TODOs completed, security patched, deployed and tested on NEAR testnet

IBC Connection Module (ICS-03)

  • Connection Handshake: Complete 4-step connection handshake protocol implementation
  • State Management: Connection state transitions (Uninitialized → Init → TryOpen → Open)
  • Proof Verification: Comprehensive proof validation for all handshake steps (ConnOpenTry, ConnOpenAck, ConnOpenConfirm)
  • Security Validation: Input validation, proof integrity checks, and error prevention
  • Counterparty Information: Store client IDs, connection IDs, and commitment prefixes
  • Version Negotiation: Support for connection version selection and feature negotiation
  • Cross-Chain Authentication: Establishes authenticated connections between NEAR and Cosmos chains
  • Storage Optimization: Efficient LookupMap-based storage with proper key prefixing

IBC Channel Module (ICS-04)

  • Channel Handshake: Complete 4-step channel handshake protocol (ChanOpenInit, ChanOpenTry, ChanOpenAck, ChanOpenConfirm)
  • Packet Transmission: Full packet lifecycle (SendPacket, RecvPacket, AcknowledgePacket) with sequence management
  • Timeout Mechanisms: Height and timestamp-based packet timeout validation and cleanup
  • Channel Types: Support for both ordered and unordered channel communication patterns
  • State Management: Channel state transitions (Uninitialized → Init → TryOpen → Open → Closed)
  • Proof Verification: Cryptographic validation of packet commitments, receipts, and acknowledgements
  • Cross-Chain Messaging: Reliable packet delivery with acknowledgements and error handling
  • Storage Efficiency: Optimized LookupMap storage for channels, packets, and sequence tracking
  • Application Integration: Ready for ICS-20 token transfers and custom application protocols

Multi-Store Proof Verification Support

  • Cross-Chain State Queries: Verify actual Cosmos SDK chain state across different modules (bank, staking, governance)
  • Two-Stage Verification: Store existence proof + key-value proof within store for complete validation
  • Batch Operations: Efficient verification of multiple stores in single operation for performance optimization
  • Real Cosmos SDK Compatibility: Can interact with actual Cosmos chains (Cosmos Hub, Osmosis, Juno, etc.)
  • ICS-20 Foundation: Complete foundation ready for cross-chain token transfer implementation
  • Security Compliance: All proofs follow ICS-23 specification with VSA-2022-103 security patches
  • Production APIs:
    • ibc_verify_multistore_membership() - Single store verification
    • ibc_verify_multistore_batch() - Multiple store batch verification
  • Cross-Chain DeFi Ready: Enables NEAR DeFi protocols to access and verify Cosmos SDK chain state

IBC Token Transfer Module (ICS-20) 🆕

  • Cross-Chain Token Transfers: Complete implementation of ICS-20 specification for fungible token transfers
  • Bidirectional Transfers: Send and receive tokens between NEAR and any Cosmos SDK chain
  • Token Escrow/Mint Mechanics: Native token escrow for outgoing transfers, voucher token minting for incoming transfers
  • Denomination Tracing: Full path tracking for multi-hop transfers with SHA256 hash-based IBC denominations
  • Source Zone Detection: Automatic detection of token origin for proper escrow/burn logic
  • Comprehensive Error Handling: Robust validation, timeout handling, and refund mechanisms
  • Production APIs:
    • ibc_transfer() - Send cross-chain token transfers
    • ibc_get_denom_trace() - Query denomination path information
    • ibc_get_escrowed_amount() - Check escrowed token balances
    • ibc_get_voucher_supply() - Check voucher token supply
    • ibc_register_denom_trace() - Register new token denominations
  • Integration Ready: Seamlessly integrates with existing Bank Module and IBC infrastructure
  • Test Coverage: 17 comprehensive tests covering all transfer scenarios and edge cases

CosmWasm Runtime Compatibility 🆕

Complete smart contract migration support enabling existing Cosmos ecosystem contracts to run natively on Proxima:

  • Full API Compatibility: Complete implementation of CosmWasm standard types, storage abstraction, and cryptographic APIs
  • Storage Layer: Efficient range queries, prefix iterations, and sorted key management using NEAR collections
  • Memory Management: Bridge between CosmWasm's allocation model and NEAR's register system for seamless compatibility
  • Response Processing: Automatic translation of CosmWasm responses to NEAR actions, events, and cross-contract calls
  • Address Support: Multi-format address validation supporting NEAR, Cosmos, and Proxima address schemes
  • Cryptographic Functions: Ed25519 signature verification using NEAR native functions, secp256k1 support ready
  • Integration Hooks: Direct integration with Proxima's Bank, Staking, Governance, and IBC modules

Production APIs:

  • Contract Lifecycle: instantiate, execute, query, and migrate entry points
  • Storage Operations: Compatible get, set, remove, and range query operations
  • Cross-Contract Calls: Sub-message handling with proper reply and callback support
  • Event System: CosmWasm event emission translated to NEAR logging format

Migration Benefits:

  • No Code Changes: Existing CosmWasm contracts run without modification
  • Performance Gains: 2-3 second finality vs Cosmos's 6+ seconds, significantly lower transaction costs
  • Ecosystem Access: Integration with NEAR's native DeFi protocols and developer tools
  • Proven Security: Access to hundreds of audited CosmWasm contracts from the Cosmos ecosystem

Developer Experience:

  • Familiar APIs: Same development patterns and APIs as traditional CosmWasm
  • Testing Support: Full test compatibility with existing CosmWasm test suites
  • Documentation: Complete migration guides and integration examples
  • Counter Contract Demo: Working example demonstrating full compatibility

Technical Implementation

Testing Strategy

The contract includes comprehensive integration testing using near-workspaces - the Rust equivalent of Hardhat for NEAR contracts.

Automated Integration Tests

Run the complete test suite with:

cd cosmos_sdk_near
cargo test

Modular Test Structure (12 test files, 96+ tests total):

Core Module Tests (12 tests, all passing):

  • Bank Module (bank_integration_tests.rs): Token minting, transfers, balance validation, error handling (3 tests)
  • Staking Module (staking_integration_tests.rs): Validator management, delegation, undelegation, reward distribution (3 tests)
  • Governance Module (governance_integration_tests.rs): Proposal submission, voting, parameter management (3 tests)
  • Block Processing (block_integration_tests.rs): Single and multiple block advancement with cross-module integration (2 tests)
  • End-to-End (e2e_integration_tests.rs): Complete multi-module workflow with realistic reward calculations (1 test)

IBC Module Tests (43+ tests, all passing):

  • IBC Client (ICS-07): Client management, cryptographic verification, batch proof verification, range proof verification, state tracking, proof validation (20 tests)
  • IBC Connection (ICS-03): Connection handshake flows, state transitions, error handling (4 tests)
  • IBC Channel (ICS-04): Channel handshake, packet transmission, timeout handling, both channel types (5 tests)
  • IBC Multi-Store (ICS-23): Multi-store proof verification, batch operations, error handling, API validation (3 tests)
  • IBC Token Transfer (ICS-20): Cross-chain token transfers, escrow/mint mechanics, denomination tracing, packet processing, error handling (17 tests)

CosmWasm x/wasm Module Tests (41+ tests, all passing):

  • Unit Tests (30 tests): Complete coverage of all module functionality with 100% success rate
    • Types Tests (6 tests): Structure validation and type conversion testing
    • Storage Tests (8 tests): Code storage, contract instantiation, and data management
    • Access Control Tests (5 tests): Permission enforcement and security validation
    • Lifecycle Tests (7 tests): Complete contract lifecycle and state management
    • Helper Tests (4 tests): Edge cases and utility function validation
  • Integration Tests (7 tests): Real deployment scenarios with NEAR Workspaces simulation
    • Basic Functionality: Complete store → instantiate → query flow
    • Multi-Contract Deployment: Multiple contracts from same and different codes
    • Error Scenarios: Oversized code rejection, invalid operations, access control
    • Stress Testing: Bulk operations (25 codes, 100 contracts), pagination, boundaries
    • Advanced Permissions: Nobody/OnlyAddress/AnyOfAddresses enforcement
  • Performance Tests (4 tests): Bulk operations, concurrent access, and scalability validation
    • Bulk Code Storage: 5-20 codes with <10s per operation validation
    • Contract Instantiation: 5-15 contracts with <15s per operation validation
    • Query Performance: Large datasets (25 codes) with <5s response time validation
    • Concurrent Access: 5 concurrent users with unique ID/address generation

Test Environment

  • Real NEAR Sandbox: Tests run on actual NEAR blockchain environment
  • Embedded Contract: Uses compiled WASM for authentic testing
  • Live Testnet Tests: Direct RPC integration tests against deployed contract
  • State Validation: Verifies all balance changes, delegations, and governance state
  • Error Testing: Includes negative test cases for proper error handling

Production Validation

The unified Cosmos SDK NEAR contract has been successfully tested on live NEAR testnet:

  • Unified Contract: All modules (Bank, Staking, Gov, IBC) functioning correctly
  • Deployment Target: Ready for deployment with new unified structure

NEAR Gas Considerations

  • Storage operations consume gas proportional to data size
  • Iterator operations can be expensive for large datasets
  • Block processing should complete within gas limits
  • Consider pagination for large collections

Development Notes

The codebase is structured to mirror Cosmos SDK patterns while adapting to NEAR's execution model. Key differences:

  1. ABCI-Compatible Responses: ABCI-compatible transaction responses without full ABCI message protocol
  2. Single Contract: All modules in one contract vs. separate modules
  3. NEAR Storage: Key-value store instead of IAVL trees
  4. Block Simulation: Manual block increment vs. Tendermint consensus

Current Status

Version 0.9.0-beta - Production Ready Beta

Proxima has reached production readiness with complete IBC infrastructure:

Core Infrastructure (100% Complete):

  • Cosmos SDK Modules: Bank, Staking, Governance modules fully operational
  • IBC Stack: Complete implementation of ICS-07, ICS-03, ICS-04, and ICS-20 protocols
  • Production Relayer: Full-featured packet relay with timeout detection and bidirectional support
  • Security: VSA-2022-103 patches, AES-256-GCM encryption, comprehensive input validation

Testing & Quality Assurance (100% Complete):

  • 322 Tests Passing: All unit, integration, and live testnet tests successful
  • Network Resilience: Rate limiting, exponential backoff, and error recovery implemented
  • Thread Safety: All Send + Sync trait bounds resolved for production deployment
  • Security Validation: Complete security audit with vulnerability patches applied

Production Deployment (100% Complete):

  • Live Testnet: cosmos-sdk-demo.testnet with full IBC infrastructure
  • IBC Infrastructure: Client, Connection, and Channel established and operational
  • Automated Scripts: Complete deployment automation with validation
  • Monitoring: Prometheus metrics and health checking systems

Future Roadmap (v1.1.0+)

Medium Priority Enhancements:

  • Light Client Updates: Automatic header submission and client synchronization
  • Enhanced Error Recovery: Advanced circuit breaker patterns and retry logic
  • Performance Optimization: Batch processing and async optimization improvements
  • Mainnet Preparation: Production hardening and mainnet deployment readiness

Long-term Vision:

  • Multi-Chain Support: Additional Cosmos SDK chain integrations
  • Advanced IBC Applications: Custom IBC application protocols beyond token transfers
  • Governance Integration: Cross-chain governance and parameter updates
  • DeFi Primitives: Cross-chain DeFi protocols and liquidity management

Production Status Summary

Proxima v0.9.0-beta provides a complete, production-ready IBC infrastructure enabling:

  • Cross-chain token transfers between NEAR and Cosmos chains
  • Secure key management with enterprise-grade encryption
  • Reliable packet relay with comprehensive error handling
  • Full testnet validation with real blockchain integration
  • Automated deployment with infrastructure-as-code approach

This represents a fully functional bridge between NEAR Protocol and the Cosmos ecosystem, ready for production use and mainnet deployment.

IBC Relayer

Monorepo Structure

This repository now serves as a complete monorepo containing both the Cosmos SDK smart contract and IBC relayer:

Proxima/
├── crates/
│   ├── cosmos-sdk-contract/    # NEAR smart contract (moved from root)
│   └── ibc-relayer/           # IBC relayer implementation (NEW)
├── Cargo.toml                 # Workspace configuration
└── README.md                  # This file

IBC Relayer Implementation

A production-ready IBC relayer that bridges NEAR and Cosmos chains:

Architecture

  • NEAR Chain Integration: IMPLEMENTED - Direct integration with deployed cosmos-sdk-demo.testnet contract
  • Cosmos Chain Support: IN PROGRESS - Tendermint RPC integration framework ready
  • Event-Driven Engine: Packet detection and relay state machine with comprehensive tracking
  • Async Chain Abstraction: Unified Chain trait supporting any blockchain with IBC operations
  • Configuration System: COMPLETE - Flexible TOML-based multi-chain configuration
  • Metrics & Monitoring: COMPLETE - Prometheus metrics and health checking

Key Features Implemented

  • NearChain: Full async implementation with packet queries and event monitoring
  • Relay Engine: Event-driven architecture with packet tracking and state management
  • Configuration: Production-ready TOML configuration with chain-specific settings
  • Testing: Comprehensive test suite with 14 passing integration tests
  • Error Handling: Type-safe error propagation with network failure recovery
  • Development Tools: Examples, documentation, and development workflow support

Usage

# Navigate to relayer
cd crates/ibc-relayer

# Build the relayer
cargo build

# Run tests (168 comprehensive tests with real NEAR integration)
cargo test

# Set up secure keystore for chain signing
cargo run --bin key-manager add cosmoshub-testnet --key-type cosmos
cargo run --bin key-manager add near-testnet --key-type near

# Start the relayer with keystore integration
cargo run -- start

# Create a new connection
cargo run -- create-connection near-testnet cosmoshub-testnet

# Create a new channel
cargo run -- create-channel connection-0 transfer

# Check relayer status
cargo run -- status

Implementation Status

NEAR Chain Integration: COMPLETE

  • Fully implemented NearChain with async trait methods

Handshake Automation Framework: COMPLETE

  • Fixed thread safety issues with Send + Sync trait bounds
  • All 10 handshake automation tests passing
  • Connection and channel handshake coordination fully functional
  • Production-ready error handling and state management

IBC Infrastructure Deployment: COMPLETE

  • IBC Client 07-tendermint-0 deployed on NEAR testnet
  • IBC Connection connection-0 established in INIT state
  • IBC Channel channel-0 created for token transfers
  • Automated deployment scripts with comprehensive validation

Test Coverage: COMPREHENSIVE

  • 168+ tests across all components
  • Real NEAR testnet integration testing
  • Mock chain implementations for isolated testing
  • Script validation and safety verification
  • Connected to deployed cosmos-sdk-demo.testnet contract
  • Real NEAR RPC integration with production-ready contract calls
  • Packet state queries (commitments, acknowledgments, receipts)
  • Event monitoring and transaction submission framework
  • Comprehensive test coverage and error handling

NEAR State Proof Generation: COMPLETE

  • Real NEAR blockchain state proof generation for IBC packet verification
  • Production-ready NearProofGenerator with cryptographic state proofs
  • Support for packet commitment, acknowledgment, and timeout proofs
  • IBC-compatible proof formatting with SHA256 integrity verification
  • Integration with NEAR's merkle proof system for tamper-proof verification
  • Resolved NEAR dependency version conflicts (v0.30.3 compatibility)

Cosmos Chain Integration: COMPLETE

  • Enhanced CosmosChain implementation with full Tendermint RPC integration
  • Production-ready transaction building with proper Cosmos SDK structure
  • IBC transaction methods: submit_recv_packet_tx, submit_ack_packet_tx, submit_timeout_packet_tx
  • Account configuration, gas estimation, and fee calculation
  • Real-time event monitoring and parsing capabilities
  • Health checks and connectivity verification with live Cosmos networks

Enhanced Inter-Chain Relay Processing: COMPLETE

  • Specialized NEAR→Cosmos packet processing with state machine tracking
  • Complete packet lifecycle: Detection → Proof Generation → Submission → Confirmation
  • Enhanced packet processor with bidirectional relay capabilities
  • Real-time event monitoring system for both NEAR and Cosmos chains
  • Comprehensive error recovery and retry mechanisms

Secure Keystore Management: COMPLETE

  • Production Keystore: Complete encrypted key management system with AES-256-GCM encryption
  • Dual Cryptography Support: secp256k1 for Cosmos chains, ed25519 for NEAR
  • CLI Tools: Key addition, export, import, and management utilities (cargo run --bin key-manager)
  • Environment Variables: Secure key loading for containerized deployments
  • Integration Ready: Seamless integration with both NEAR and Cosmos chain implementations
  • 100% Test Coverage: 113 comprehensive tests validating all security and operational aspects

Test Suite

The relayer includes a comprehensive test suite:

  • 322+ Integration Tests: All passing with real blockchain integrations and local testnet support
  • Test Coverage:
    • Keystore Security: 113+ comprehensive tests for secure key management
      • Cosmos key cryptography (secp256k1) - 13 tests
      • NEAR key management (ed25519) - 19 tests
      • CLI tools and workflows - 10 tests
      • Integration with chain implementations - 10 tests
      • Environment variable key loading and isolation - Multiple tests
      • AES-256-GCM encryption with Argon2 key derivation
    • Core relay engine with packet lifecycle tracking (23 tests)
    • NEAR chain integration with real RPC calls (8 tests)
    • Cosmos chain integration with transaction building (12 tests)
    • Enhanced packet processing and state management (9 tests)
    • Event monitoring and parsing systems (8 tests)
    • Configuration, metrics, and proof generation (8+ tests)
    • Local Testnet Integration: Docker-based wasmd testnet validation (5 tests)
    • Testnet Deployment: Complete deployment workflow validation (9 tests)
  • Real Blockchain Testing: Production NEAR testnet and local wasmd integration
  • Complete Flow Testing: Full NEAR↔Cosmos packet relay validation with Docker testnet
  • Error Handling: Comprehensive network failure and recovery testing
  • Production Security: Complete keystore implementation with encrypted key storage
  • Development Environment: Fully functional local testnet with automated setup

Configuration

The relayer uses config/relayer.toml for chain configuration:

[chains.near-testnet.config]
type = "near"
contract_id = "cosmos-sdk-demo.testnet"  # Our deployed contract
rpc_endpoint = "https://rpc.testnet.near.org"

[chains.cosmoshub-testnet.config]
type = "cosmos"
rpc_endpoint = "https://rpc.testnet.cosmos.network"
address_prefix = "cosmos"

This relayer implementation enables real-world cross-chain communication between NEAR and Cosmos chains, completing the full IBC infrastructure.

Local Testnet Setup

wasmd Cosmos Testnet on Docker

The project includes a complete Docker-based wasmd testnet for local development and testing:

Docker Setup

# Navigate to the docker directory
cd crates/ibc-relayer/docker

# Start the wasmd testnet
docker-compose up -d

# Verify the testnet is running
docker-compose ps

Testnet Configuration

  • Chain ID: wasmd-testnet
  • RPC Endpoint: http://localhost:26657
  • REST API: http://localhost:1317
  • gRPC: localhost:9090

The testnet comes pre-configured with:

  • Validator nodes with proper key management
  • IBC relayer connectivity
  • Test accounts with sufficient balances
  • Automated initialization scripts

Process to Safely Stop and Restart Cosmos Testnet

Stopping the testnet:

# Stop all containers gracefully
docker-compose down

# Stop with volume cleanup (removes all data)
docker-compose down -v

Restarting the testnet:

# Start the testnet (will reinitialize if volumes were removed)
docker-compose up -d

# Check logs to ensure proper startup
docker-compose logs -f wasmd

# Verify chain is producing blocks
curl http://localhost:26657/status

Safe restart procedure:

  1. Stop packet relaying: cargo run -- stop
  2. Stop testnet: docker-compose down
  3. Start testnet: docker-compose up -d
  4. Wait for block production: Check curl http://localhost:26657/status
  5. Restart relayer: cargo run -- start

For more detailed information, see the docker README and project changelog.

DEPLOYMENT STATUS

Previous Deployments (Legacy Structure):

  • Original Contract: cuteharbor3573.testnet (Transaction)
  • IBC Light Client: demo.cuteharbor3573.testnet (Transaction)

Current Production Deployment:

  • Contract Account: cosmos-sdk-demo.testnet
  • Latest Deployment: (Transaction)
  • Initialization: (Transaction)
  • Deployment Date: July 23, 2025
  • Network: NEAR Testnet

Deployed Features:

  • Complete Cosmos SDK Modules: Bank, Staking, Governance
  • Full IBC Stack: Client (ICS-07), Connection (ICS-03), Channel (ICS-04)
  • Multi-Store Proof Verification: Cross-chain state queries
  • ICS-20 Token Transfer: Cross-chain fungible token transfers
  • 60+ Tests Passing: Comprehensive validation including live testnet tests

Available APIs:

  • Core Modules: 15+ functions for bank, staking, governance operations
  • IBC Infrastructure: 25+ functions for cross-chain communication
  • Token Transfers: 10+ functions for ICS-20 cross-chain token transfers
  • State Verification: Multi-store proof verification capabilities

Production Ready: The unified contract provides a complete Cosmos SDK runtime on NEAR with full cross-chain capabilities, ready for integration with IBC relayers and Cosmos ecosystem chains.

Testnet Deployment

Current IBC Infrastructure Status

The IBC relayer has successfully established the foundational infrastructure on NEAR testnet:

IBC Client Created: 07-tendermint-0

  • Light client for Cosmos provider chain verification
  • Successfully validates Tendermint headers and consensus states
  • Ready for cross-chain proof verification

IBC Connection Established: connection-0

  • Connection between NEAR and Cosmos provider testnet
  • State: Init (handshake ready for completion)
  • Proper counterparty configuration with IBC prefix

IBC Channel Created: channel-0

  • Transfer channel for ICS-20 token transfers
  • Port: transfer, Version: ics20-1, Order: Unordered
  • State: Init (ready for channel handshake completion)

Quick Setup Guide

# Navigate to relayer directory
cd crates/ibc-relayer

# Set up environment variables
cp .env.example .env
# Edit .env with your testnet keys

# Run deployment tests
cargo test testnet_deployment

# Start the relayer
./start_relayer.sh

# Verify IBC infrastructure
./scripts/check_deployment.sh

Created Infrastructure Scripts

The following scripts have been created and tested:

  1. scripts/create_simple_ibc_client.sh - Creates IBC Tendermint client
  2. scripts/create_ibc_connection.sh - Initializes IBC connection
  3. scripts/create_ibc_channel.sh - Creates IBC transfer channel

Current Configuration

  • NEAR Contract: cosmos-sdk-demo.testnet
  • NEAR Account: cuteharbor3573.testnet
  • Cosmos Provider: ICS provider testnet
  • Key Management: Environment variable based secure key loading

Next Steps for Full Cross-Chain Transfers

To complete the infrastructure for token transfers, the following components need implementation:

  1. Handshake Completion: Complete connection and channel handshakes (Try/Ack/Confirm steps)
  2. Cosmos Side Setup: Deploy corresponding IBC infrastructure on Cosmos provider chain
  3. Packet Relay Logic: Implement packet scanning, proof generation, and relay automation
  4. Token Integration: Add ICS-20 token escrow/mint logic for cross-chain transfers

Monitoring & Status

  • Health Check: cargo run -- status
  • View IBC State: Use near view cosmos-sdk-demo.testnet commands to inspect clients/connections/channels
  • Logs: Check relayer.log for detailed operation logs
  • Metrics: Prometheus metrics available at http://localhost:9090/metrics

The foundation for NEAR-Cosmos IBC communication is successfully established and operational!

CosmWasm Off-Chain Execution Architecture

Problem Solved: WASM-in-WASM Limitation

NEAR contracts run in WebAssembly and cannot execute nested WASM modules like Wasmer. Our solution implements an off-chain execution architecture where a relayer service executes CosmWasm contracts and submits results back to NEAR for consensus.

Current Implementation Status

Completed Components

  1. Execution Queue System: NEAR contract queues CosmWasm execution requests instead of immediate execution
  2. Off-Chain Relayer Service: Monitors NEAR for requests, executes via Wasmer, submits signed results
  3. Transaction Signing: Full NEAR transaction signing with secure key management
  4. State Synchronization: Bidirectional state management between relayer and NEAR
  5. Test Coverage: 28+ tests passing including execution queue and relayer integration tests

What You Can Do Now

# Deploy CosmWasm contracts (e.g., CW20 tokens)
near call wasm-module.test.near store_code '{"wasm": "<base64>"}' --accountId user.near

# Execute contracts (queued for relayer)
near call wasm-module.test.near execute '{"contract": "cw20.near", "msg": "{\"transfer\":{...}}"}' --accountId user.near

# Relayer processes automatically
./relayer start-cosmwasm --config config/cosmwasm.toml

Architecture Overview

User → NEAR Contract → Execution Queue → Relayer → Wasmer Execution → Signed Result → NEAR
  • On-Chain: Contract bytecode storage, execution queue, state persistence, result application
  • Off-Chain: Wasmer execution, result generation, transaction signing
  • Security: Multiple relayer consensus possible, slashing conditions can be added

Future Roadmap & Enhancements

Security & Decentralization

  • Multi-Relayer Consensus: M-of-N agreement on execution results
  • Zero-Knowledge Proofs: Trustless execution verification
  • Optimistic Rollups: Challenge period with fraud proofs
  • Slashing Mechanisms: Penalize incorrect execution submissions

Performance Optimizations

  • Batch Processing: Execute multiple requests in single operation
  • Parallel Execution: Process independent contracts simultaneously
  • State Compression: Merkle tree commitments and IPFS integration
  • Execution Caching: Reuse common execution patterns

Cross-Chain Features

  • NEAR ↔ Cosmos Bridge: Native asset bridging with wrapped tokens
  • EVM Compatibility: Execute Ethereum contracts via CosmWasm
  • Multi-Chain Router: Optimal chain routing for transactions
  • Universal Addresses: Chain-agnostic address system

Additional Modules

  • Full IBC Protocol: Complete IBC relayer network implementation
  • Staking Module: Proof-of-stake for relayer network
  • Governance Module: On-chain proposals and parameter updates
  • NFT Support (CW721): Full NFT standard with marketplace

Developer Experience

  • SDK Libraries: JavaScript, Python, Rust, Go SDKs
  • IDE Plugins: VS Code extension for NEAR-Cosmos development
  • Contract Templates: Ready-to-deploy DeFi primitives
  • Migration Tools: Automated Ethereum/Cosmos contract migration

Economic Model

  • Relayer Incentives: Fee market and performance rewards
  • Governance Token: Protocol governance and fee distribution
  • MEV Protection: Fair ordering and front-running prevention
  • Liquidity Mining: Incentivize cross-chain liquidity

Implementation Priorities

Phase 1 (Next 1-2 months):

  • Multi-relayer consensus mechanism
  • Complete IBC implementation
  • JavaScript/TypeScript SDK
  • Monitoring dashboard

Phase 2 (3-6 months):

  • Optimistic rollup implementation
  • Additional Cosmos modules
  • NEAR ↔ Cosmos bridge
  • DeFi protocol suite

Phase 3 (6+ months):

  • Zero-knowledge proof system
  • Native WASM-in-WASM research
  • Full Cosmos Hub compatibility
  • Production mainnet launch

Summary

Proxima has evolved into a comprehensive Cosmos SDK implementation on NEAR with:

Working Today:

  • Full Cosmos SDK modules (Bank, Staking, Governance)
  • Complete IBC infrastructure for cross-chain communication
  • CosmWasm contract execution via off-chain relayer
  • CW20 token deployments and transfers
  • Secure transaction signing and state management

Ready for Development:

  • Deploy and execute any CosmWasm contract
  • Build cross-chain DeFi applications
  • Test IBC token transfers
  • Integrate with existing NEAR dApps

Future Vision: Transform into a production-ready, decentralized cross-chain infrastructure serving as the foundation for interoperable applications between NEAR, Cosmos, and eventually EVM ecosystems.

The hybrid architecture provides a pragmatic solution bringing Cosmos smart contracts to NEAR today, while research continues on native WASM-in-WASM execution for the future.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •