Consensus · Go

monadbft-go

Go implementation of Monad's pipelined two-phase BFT consensus algorithm. Pluggable consensus engine for Cosmos-EVM (evmd), maintaining behavioral parity with the original Rust codebase.

In Progress GitHub Docs
~60k
Lines of Go
27
Packages
5
Dependencies
2
Modules
01

Features

  • Pacemaker-driven round progression with two-chain commit safety rules
  • RaptorCast networking with RaptorQ erasure codes
  • Deferred-execution architecture (≥2 block lag)
  • Write-ahead logging with rotating event chunks
  • Pebble-backed block store with forkpoint tracking
  • Safety watermarks for double-sign prevention
  • ABCI bridge for Cosmos SDK compatibility
02

Architecture

Consensus Core
  • consensus/ — Pacemaker, VoteState, Safety rules, state machine
  • blocktree/ — Pending-block coherency, two-chain commit logic
  • validator/ — Stake-weighted ValidatorSet, epoch manager, leader election
  • crypto/ — secp256k1 + BLS12-381 with Monad signing domains
Networking
  • raptor/ — RFC 6330 RaptorQ codec (GF(256), LDPC+LT, systematic)
  • net/raptorcast/ — Chunk assignment, broadcast router, rebroadcast
  • net/dataplane/ — UDP batching, priority queues, TCP fallback
  • net/wireauth/ — Noise-based session authentication
Persistence
  • wal/ — Append-only RLP event log, rotating chunks, crash recovery
  • store/ — Pebble-backed block store, forkpoint tracking, fsync
  • monadstate/ — Live/Sync mode dispatcher, safety watermarks
Integration
  • bridge/ — ABCI adapter, FinalizeBlock/Commit translation
  • bridge/resultstore/ — Prunable tx indexes, RPC compatibility
  • glue/ — MonadEvent/Command contract types
03

Dependencies

  • go-ethereum — secp256k1 signing, RLP encoding, address derivation
  • supranational/blst — BLS12-381 for vote/timeout aggregation
  • cockroachdb/pebble — LSM block store with fsync guarantees
  • zeebo/blake3 — Fast hashing for block/tx digests
  • ericlagergren/aegis — AEGIS-128L authenticated encryption
04

Benchmarks

Serial EVM execution (512-tx blocks, secp256k1) ~2,400 tx/s
Per-transaction latency 246 µs
Empty-block commits ~1,200 blk/s
Consensus commit overhead ~1 ms
Worst-case round timeout (delta=400ms) ~1.9 s
05

Quick Start

# Clone repos side by side
git clone https://github.com/abhijitkrm/monadbft-go.git
git clone https://github.com/abhijitkrm/monad-evm.git

# Build and test
cd monadbft-go
go build ./... && go test ./...

# Run single node
cd ../monad-evm/evmd && go build -o evmd .
./evmd init mynode --chain-id monad-1
./evmd start --engine=monadbft

# Run 4-node devnet
cd ../../monadbft-go/bridge
go build -o devnet ./cmd/devnet
./devnet init-files -n 4 -o ./devnet-run -transport tcp
./devnet soak -o ./devnet-run -duration 3m -rate 200
06

Testing

Methodology
  • Byte-identical RLP encoding with Rust for cross-implementation conformance
  • Traced every state accumulator, RPC read path, and validation path against upstream monad-bft
  • Source verification against original Rust codebase for parity
Integration Tests
  • TestEvmIntegrityTransfers — 8-sender, 3-transfer scenario on 4-node TCP devnet
  • Validates inclusion, success results, gas accounting, recipient balances
  • Verifies sender nonces and cross-node apphash equality
  • Multi-node restart matrices across TCP and RaptorCast transports
  • Crash-window rejoin scenarios with WAL replay verification
Unit & Benchmark Tests
  • BenchmarkFinalizeBlockEvm — Serial FinalizeBlock+Commit throughput
  • BenchmarkConsensusCommit — Empty-block finalization rates
  • TestEngineConfigValidate — Configuration validation logic
  • TestRetentionFallback — Retention window behavior
  • Store window tests for block pruning boundaries
Coverage Areas
  • WAL rotation and replay filtering
  • RaptorCast quotas and timer cleanup
  • Blockbuffer pruning and vote/NE state management
  • Safety durability ordering and BlockStore guards
  • Statesync lifecycle and TCP authentication integrity
  • CometBFT RPC parity verification
07

Completed

Track A — Consensus + Integration
  • Crypto primitives — secp256k1/BLS12-381 with Monad signing domains
  • Consensus core — Pacemaker, VoteState, two-chain commit safety
  • Swarm simulator — Deterministic replay, Rust test vector parity
  • Persistence — WAL rotating chunks, Pebble store, forkpoints
  • ABCI bridge — FinalizeBlock/Commit, mempool routing, epochs
  • TCP transport — Noise auth, DomainTCPAuth-signed transcripts
  • Production pass — Memory bounds, RPC indexing, metrics
Track B — Networking
  • RaptorQ codec — RFC 6330, GF(256) arithmetic, systematic index
  • RaptorCast router — Chunk assignment, rebroadcast windows
  • Dataplane — UDP batching, priority queues, TCP fallback
  • Peer discovery — Signed name records, bootstrap
08

In Progress

  • Validator rotation — x/consensuskeys registry for epoch-boundary churn
  • Evidence emission — Slashing hooks for Byzantine behavior
  • WebSocket subscriptions — CometBFT-compatible event streaming
09

Planned

  • Parallel EVM — BlockSTM-style execution targeting 10K TPS
  • Key-file tooling — init command for validator key generation
  • Backup tooling — Snapshot export/import for node recovery
  • IBC exploration — Cross-chain message compatibility