A proof-of-concept blockchain engine built from scratch in Rust — featuring SHA-256 hashing, Proof of Work mining, and cryptographic tamper detection.
🚀 Starting Mini Blockchain
⛏️ Mining block 0...
✅ Block mined! Nonce: 203 | Hash: 0066ab8fabd9
⛏️ Mining block 1...
✅ Block mined! Nonce: 107 | Hash: 00d52fb99b10
⛏️ Mining block 2...
✅ Block mined! Nonce: 420 | Hash: 002c8391b69c
⛏️ Mining block 3...
✅ Block mined! Nonce: 89 | Hash: 00444e377e11
========== 🔗 BLOCKCHAIN ==========
📦 Block #1
Data : Alice sends 10 BTC to Bob
Nonce : 107
Prev Hash: 0066ab8fabd9...
Hash : 00d52fb99b10...
Time : 2026-08-10T03:11:19.456504700+00:00
... blocks #0, #2 and #3 omitted here for brevity ...
====================================
✅ Blockchain is valid!
🔧 Tampering with Block 1...
❌ Tampering detected: Block 1 has an invalid hash — data may have been tampered with
A blockchain is a linked list of blocks where each block contains a cryptographic hash of the one before it. Changing any block breaks all subsequent links — making fraud instantly detectable.
struct Block {
index: u64, // Position in the chain
timestamp: String, // RFC3339 creation time
data: String, // Transaction payload
previous_hash: String, // Hash of the previous block
hash: String, // SHA-256 fingerprint of this block
nonce: u64, // Value found during mining
}To add a block, the miner must find a nonce such that:
SHA256(index + timestamp + data + previous_hash + nonce)
must start with "00..." (configurable difficulty)
is_valid() checks three things for every block, the genesis block included:
- Hash integrity — recalculates and compares the stored hash
- Proof of work — confirms the hash really meets the difficulty target, so a hand-crafted block that was never mined cannot pass as genuine
- Chain linkage — verifies previous_hash matches the actual previous block
| Crate | Version | Purpose |
|---|---|---|
| sha2 | 0.10 | SHA-256 hashing |
| hex | 0.4 | Encode hash bytes as readable strings |
| serde + serde_json | 1.0 | Block serialization |
| chrono | 0.4 | RFC3339 timestamps |
Prerequisites: Rust 1.75+ (https://rustup.rs)
git clone https://github.com/vagif693/mini-blockchain.git
cd mini-blockchain/mini-blockchain
cargo runRun the test suite:
cargo test- SHA-256 block hashing
- Proof of Work mining with configurable difficulty
- Cryptographic chain validation
- Tamper detection demo
- Unit test suite and CI
- CLI interface with clap
- Persist chain to JSON file
- Wallet addresses and digital signatures
- Ownership & borrowing — Rust's core memory model used throughout
- Structs and impl blocks — clean OOP-style design in Rust
- Cryptographic hashing — real SHA-256 via the sha2 crate
- Iterators — chain validation using Rust iterators
MIT