Cosmos-EVM · Go

evm-hft

Cosmos-EVM port optimized for HFT trading. Custom HotStuff consensus engine with ~200ms block time, native CLOB module with parallel matching, trading mempool with P2P gossip, and EVM precompiles for order execution.

In Progress Private
103.6K
Peak TPS
~200ms
Block Time
80x
vs Baseline
~21µs
Per Order
01

Features

  • Pipelined 3-chain HotStuff consensus replacing CometBFT
  • Native x/clob module with FIFO matching engine
  • CLOB precompile for Solidity order execution
  • Trading mempool with parallel P2P gossip
  • Parallel per-pair matching with lane isolation
  • Gasless price-feed precompile via vote extensions
  • Reentrancy guards for deposit/withdraw
  • WAL persistence with crash recovery
02

Architecture

Consensus
  • 3-chain pipelined HotStuff (Aptos/Diem lineage)
  • Leader-centric O(n) gossip vs Tendermint's O(n²)
  • ABCI++ interface mapping (PrepareProposal, ProcessProposal, ExtendVote)
  • Pacemaker with exponential backoff (capped at 8x)
  • Vote keeper with quorum tracking (strict >2/3)
CLOB Module
  • In-memory B-tree order book with price-time priority
  • Parallel lane execution with journal-based merge
  • Settlement accumulator for atomic balance updates
  • Tick-size validation with configurable precision
  • Market maker bond system
Trading Mempool
  • Batch state machine with verified order tracking
  • Ed25519 signature cache with eviction budget
  • Rate limiting per trader/pair
  • P2P gossip via trading reactor
  • Preconf support for sub-block latency
EVM Integration
  • CLOB precompile: PlaceLimitOrder, PlaceMarketOrder, CancelOrder
  • Deposit/Withdraw with reentrancy protection
  • Query methods: GetOrderBook, GetOrder, GetUserOrders
  • Price precompile at 0x0...0888 (vote extension primary)
  • Gasless price writes via ante fee-waiver
03

Dependencies

  • Go 1.25 — runtime with CGO enabled
  • Cosmos SDK — store/v2 with ABCI++
  • go-ethereum — EVM + ABI encoding
  • RocksDB — LSM-tree persistent storage
  • gRPC / Protobuf — service definitions
  • golangci-lint v2.10.1 — static analysis
04

Benchmarks

Dev Era (1.3K → 5.4K)
Baseline 1.3K
#1 Gossip dedup — 28x fewer duplicates 2.4K
#2 Removed OptimisticExecution 4.3K
#3 committedCache — ref-livelock fix 4.7K
#4 Lock-free proposal build 5.4K
Box Era (42K → 103K)
Box baseline — HotStuff + RocksDB 42.3K
#2 Per-pair lane index overlays 47.9K
#4 Amortized sweep + prune-before-flush 48.4K
#6 Plan memo + %100 balance scan 52.1K
#8 Lock-free lane-overlay lookup 56.1K
#10 Plan memoization + u64 remaining 60.5K
#12 Lock-free verified-sig + alloc-free EIP-712 72.9K
#13 Stack-allocated stripe keys 75.3K
#21c Batch-verify cache — 61% process_ms removed 65.3K
#21d LANE_PROF off + GOMEMLIMIT 32G 103.6K
05

Block Timing

process_ms (total) 174 meanp50: 121 · p90: 384
place_ms 132 meanp50: 93 · p90: 312
lane_ms 105 meanp50: 74 · p90: 270
flush_ms 17 meanp50: 9 · p90: 30
prune_ms 16 meanp50: 2 · p90: 39
GC cycle 185 meanp90: 295
06

Per-Order Breakdown

Matching — matfill, matgath, matsetup 5.11
Merge pump — wait, lock, apply, rec 4.15
Window marking — wincall, winmark 3.07
Fill journaling — filljrn, filllegs, fillrem 2.59
Book mutation — bidx, blevel, bside 2.19
Persist — persist, perset, pernote 2.07
Planning — planres, plantrd, planval 1.81
Escrow — balance locking 1.68
Total lane (clean) ~21
07

Testing

  • Unit tests — keeper matching, settlement accumulator, balance integrity
  • Consensus tests — Byzantine fault, crash recovery, WAL replay
  • Fuzz tests — differential fuzz vs serial, wire message parsing
  • Integration — localnet multi-validator, Solidity precompile calls
  • System tests — Foundry, JSON-RPC compatibility
08

Security Audit

  • Vote signatures verified on receipt
  • QC signatures verified against validator set
  • 2/3+ voting power required (strict >2/3)
  • Vote equivocation detection + evidence
  • SafeNode predicate (locked QC check)
  • Reentrancy gate for Deposit/Withdraw (audit M2)
  • Parallel matching determinism (audit M1)
  • AppHash divergence detection
09

Completed

  • HotStuff consensus engine implementation
  • x/clob module with keeper + matching
  • CLOB precompile (limit, market, cancel, queries)
  • Trading mempool with batch state machine
  • Parallel per-pair matching (lane isolation)
  • WAL persistence + crash recovery
  • Localnet verified (in-memory benchmark passing)
10

In Progress

  • F5: Pointer-free order book — GC scanobject 52.7% → ~6%
  • F6: Index-permutation sort — sort_ms 14.5 → ~1ms
  • B2: Fused per-job stripe hold — pump wait+lock 2.6µs/order
  • F8/F9/F10: u128 balances, mempool lock + fairness
11

Planned

  • Production audit completion (audit008)
  • SIGTERM under load + restart recovery testing
  • Mainnet deployment