Introduction to Minichain
Minichain is a complete, single-node, account-based blockchain built entirely in Rust. It’s designed as an educational project to help developers understand blockchain internals without the complexity of production systems.This is a learning-focused implementation. It prioritizes clarity and completeness over optimization and production features.
What is Minichain?
Minichain is a fully-functional blockchain featuring:- Blake3 hashing for cryptographic operations
- Ed25519 signatures for transaction signing
- Register-based VM with 16 registers and gas metering
- Proof of Authority consensus with round-robin block production
- Custom assembly language with human-readable syntax
- Full-featured CLI for chain interaction
- Persistent storage using sled embedded database
- Merkle trees for efficient state verification
Key Features
Account-Based Model
Track accounts with balances, nonces, and contract code. Supports both externally-owned accounts (EOAs) and smart contracts.
Register-Based VM
Execute smart contracts using a 16-register virtual machine with 40+ opcodes covering arithmetic, logic, memory, storage, and control flow.
Gas System
Ethereum-inspired gas metering where storage operations cost ~100x more than arithmetic, preventing resource abuse.
Custom Assembly
Write smart contracts in human-readable assembly with labels, directives, and comments that compile to VM bytecode.
PoA Consensus
Proof of Authority with designated validators using round-robin block production and Ed25519 signatures.
Persistent Storage
All blockchain data persists to disk using the sled embedded database with atomic state updates.
Architecture Overview
Minichain is organized into modular crates, each responsible for a specific layer of the blockchain:Transaction Flow
The lifecycle of a transaction in Minichain:- CLI: User creates and signs transaction with Ed25519
- Blockchain: Validates signature and submits to mempool
- Mempool: Orders transactions by gas price (highest first)
- Block Production: Authority collects transactions for new block
- Executor: Executes each transaction in the VM
- VM: Runs bytecode with gas metering and register operations
- Storage: Persists state changes atomically to sled database
Core Components
Accounts & Balances
Minichain uses an account-based model similar to Ethereum:- Balance: Token amount held by the account
- Nonce: Transaction counter to prevent replay attacks
- Code Hash: Reference to deployed contract bytecode (contracts only)
- Storage Root: Merkle root of contract storage (contracts only)
Transactions
Three transaction types are supported:- Transfer: Send tokens between accounts
- Deploy: Deploy new smart contract bytecode
- Call: Execute existing smart contract
Virtual Machine
The VM is register-based (not stack-based like EVM) with:- 16 general-purpose registers (R0-R15) holding 64-bit values
- 40+ opcodes including:
- Arithmetic:
ADD,SUB,MUL,DIV,MOD - Logic:
AND,OR,XOR,NOT,SHL,SHR - Comparison:
EQ,LT,GT,LE,GE - Memory:
LOAD8,LOAD64,STORE8,STORE64 - Storage:
SLOAD,SSTORE - Control:
JUMP,JUMPI,CALL,RET,HALT - Context:
CALLER,CALLVALUE,ADDRESS,BLOCKNUMBER,TIMESTAMP
- Arithmetic:
Gas Metering
Gas costs are designed to reflect real computational and storage costs:| Operation | Gas Cost | Notes |
|---|---|---|
ADD, SUB, MOV | 2 | Basic register operations |
MUL | 3 | Multiplication |
DIV, MOD | 5 | Division operations |
LOAD64, STORE64 | 3 | Memory read/write |
SLOAD | 100 | Storage read (expensive) |
SSTORE | 5,000-20,000 | Storage write (very expensive) |
JUMP, JUMPI | 8 | Control flow |
Assembly Language
Write contracts in readable assembly that compiles to bytecode:- Labels for jump targets
- Comments with semicolons
.entrydirective to mark entry points- Immediate values with
LOADI - All VM opcodes supported
Block Production (PoA)
Proof of Authority consensus with simple round-robin:- Authority selection:
height % authority_count - Only designated authority can produce each block
- Authorities sign blocks with Ed25519
- Timestamp validation with configurable clock drift
- Automatic transaction inclusion from mempool
Why Minichain?
Minichain was built to answer the question: “How does a blockchain really work?” By implementing every component from scratch, you can:- ✅ See how transactions are validated and executed
- ✅ Understand how state is managed and persisted
- ✅ Learn how consensus mechanisms coordinate block production
- ✅ Explore how virtual machines execute smart contracts
- ✅ Study how gas metering prevents resource abuse
- ✅ Practice building modular Rust architectures
What’s Next?
Ready to get started? Here’s your path:Install Rust
Install Rust 1.70+ from rust-lang.org
Build Minichain
Follow the Installation guide to build from source
Run the Quickstart
Complete the Quickstart to initialize a chain, deploy a contract, and produce blocks
Project Status
✅ Complete Implementation- Core primitives (hash, crypto, accounts, transactions, blocks, merkle)
- Storage layer (persistent state with sled)
- Virtual machine (register-based VM with gas metering)
- Assembler (assembly → bytecode compiler)
- Consensus & chain (PoA, mempool, executor, validation)
- CLI (complete command-line interface)
- Documentation (comprehensive guides)
- Tests (26+ passing tests)
- Code quality (0 clippy warnings)