Hello, Qiita! 👋
I am Jefferson, a developer from Brazil.
Today I want to share a personal project I've been engineering to tackle a future problem: The Quantum Threat.
We all know that current cryptographic standards (like RSA and Elliptic Curves used in Bitcoin) are vulnerable to Shor's Algorithm once quantum computers become powerful enough.
Instead of waiting for "Q-Day", I decided to build a blockchain entirely in Rust focused on three pillars:
- Memory Safety: Leveraging Rust's ownership model.
- Absolute Scarcity: A hard cap of 18,000,000 coins.
- Persistence: A robust JSON-based ledger system.
Here is a look inside the code of Quantar Protocol (v1.4).
1. Why Rust? 🦀
In the crypto world, a generic C++ buffer overflow can cost millions of dollars. Rust guarantees memory safety at compile time, which makes it the perfect choice for the Aegis-Core engine.
2. The Architecture (Thread Safety)
One of the main challenges was making the Miner (CPU intensive) talk to the Wallet API (Web server) without crashing.
We used Arc (Atomic Reference Counting) and Mutex to safely share the blockchain state across threads:
use std::sync::{Arc, Mutex};
// The heart of the Blockchain
#[derive(Serialize, Deserialize, Clone, Debug)]
struct NodeStatus {
height: u64,
difficulty: usize,
last_hash: String, // SHA-256 Link
total_supply: f64,
reward: f64,
}
// Shared state between Miner and API
struct AppState {
status: Arc<Mutex<NodeStatus>>,
}
3. Persistence (The Ledger) 💾
A blockchain is useless if it forgets data when the power goes out. In version v1.4, I implemented a persistence layer using serde_json.
Every time a block is found, the node atomically writes the state to the disk:
Rust
const DATA_FILE: &str = "quantar_data.json";
fn save_data(status: &NodeStatus) {
// Serializes the struct to JSON and saves to HD
if let Ok(json) = serde_json::to_string_pretty(status) {
let _ = fs::write(DATA_FILE, json);
}
}
4. Tokenomics (Deflationary Logic) 💎
I wanted the asset to be scarcer than Bitcoin.
Bitcoin: 21,000,000 Max Supply.
Quantar: 18,000,000 Max Supply.
The code enforces a strict halving schedule:
Rust
const MAX_SUPPLY: f64 = 18_000_000.0;
const HALVING_INTERVAL: u64 = 180_000;
fn calculate_reward(height: u64) -> f64 {
let halvings = height / HALVING_INTERVAL;
let mut reward = INITIAL_REWARD;
// Bitwise shift or simple division for halving
for _ in 0..halvings {
reward /= 2.0;
}
if reward < 0.00000001 { 0.0 } else { reward }
}
5. Conclusion & Repository
The project has just reached Genesis Mainnet (v1.4). We are looking for Rustaceans and cryptographers to help us build the P2P networking layer next!
If you are interested in Post-Quantum Cryptography or just want to read the source code, check the repository below:https://github.com/chaveirobatelcuritiba/aegis-core