Mathematical Foundations
Shamwari Network's security rests on NIST-standardized post-quantum cryptographic primitives built on lattice-based hardness problems, protecting against both classical and quantum computing threats.
Post-Quantum Threat Model
Classical public-key cryptography (RSA, ECDSA, ECDH) relies on the hardness of integer factorization and discrete logarithms, which will be completely broken by Cryptographically Relevant Quantum Computers (CRQCs) executing Shor's Algorithm. Additionally, Grover's Algorithm provides quadratic speedups for brute-force symmetric key and hash searches.
Financial platforms face an immediate operational risk from "Harvest Now, Decrypt Later" (HNDL) attacks, where adversarial entities capture encrypted traffic today to decrypt once quantum capabilities become available.
NIST PQC Standards (Finalized August 2024)
Shamwari natively integrates NIST's finalized post-quantum standards:
| Standard | Algorithm Family | Scheme Type | Shamwari Parameter Set | OID / Standard Identifier |
|---|---|---|---|---|
| FIPS 203 | Module-Lattice (MLWE) | ML-KEM | ML-KEM-512 (Kyber-512) | 2.16.840.1.101.3.4.4.1 |
| FIPS 204 | Module-Lattice (MLWE / SIS) | ML-DSA | ML-DSA-2 (Dilithium Level 2) | 1.3.6.1.4.1.22554.5.7.1 |
| FIPS 205 | Hash-Based | SLH-DSA | Researched / Future Agility | N/A |
Lattice-Based Cryptography
Lattice-based cryptography derives its security from the mathematical hardness of high-dimensional lattice problems, which remain intractable for both classical and quantum computers.
Learning With Errors (LWE)
Given a matrix and a vector , where is a secret vector and is a small error vector drawn from an error distribution, the LWE problem states that it is computationally infeasible to recover or distinguish from a uniform random vector.
Module Learning With Errors (MLWE)
MLWE generalizes LWE by replacing integers with polynomial rings , operating over modules of rank . This structure offers:
- Dramatically reduced key sizes
- Optimized polynomial multiplication via Number Theoretic Transform (NTT)
- High performance suitable for production financial workloads
Shamwari leverages MLWE for key encapsulation (ML-KEM-512, ) and digital signatures (ML-DSA-2, Level 2).
Key Derivation & Domain Separation Mathematics
Shamwari derives deterministic master seeds from human-readable passphrases using PBKDF2-HMAC-SHA512 with iterations and domain-separated application salts:
From the derived 32-byte seed , domain separation is applied using SHA3-256 to generate non-overlapping sub-seeds for the Kyber (ML-KEM) and Dilithium (ML-DSA) key generators:
Cryptographic Key Structure: ShamwariQKP
Shamwari introduces ShamwariQKP (Quantum Key Pair) as a composite key primitive pairing functionally distinct post-quantum keys:
- ML-KEM-512 (Kyber-512): Used for key encapsulation, symmetric session-key establishment, and payload confidentiality.
- ML-DSA Level 2 (Dilithium-2): Used for digital signatures across transactions, block generation, and identity certificates.
ShamwariQKP
├── ML-KEM-512 Key Pair (Confidentiality / Key Encapsulation)
└── ML-DSA-2 Key Pair (Authentication / Digital Signatures)
Key Sizes and Binary Representation
| Component Primitive | Public Key Size | Secret Key Size | Signature / Ciphertext Size |
|---|---|---|---|
| ML-KEM-512 | 800 bytes () | 1632 bytes () | 768 bytes (Ciphertext) |
| ML-DSA-2 | 1312 bytes | 2528 bytes | 2420 bytes (Signature) |
Combined (ShamwariQKP) | 2112 bytes | 4160 bytes | N/A |
All public components are encoded using standard ASN.1 X.509 SubjectPublicKeyInfo DER structures, while private components use ASN.1 PKCS#8 PrivateKeyInfo DER structures.
Symmetric Payload Encryption (HKDF-SHA256 & AES-256-GCM)
Confidential payloads (e.g., encrypted messages, private asset metadata) combine ML-KEM-512 key encapsulation with AES-256-GCM symmetric encryption.
The 32-byte symmetric key is derived from the ML-KEM shared secret using HKDF-SHA256, bound directly to the Kyber ciphertext as salt:
The resulting payload wire format is:
Consensus Mathematics: Balance-Weighted PoS
Shamwari uses a balance-weighted Proof-of-Stake (PoS) consensus mechanism ("forging") operating at a target block time of ~12 seconds (). The algorithm deterministically selects block generators based on an account's effective guaranteed balance and a cryptographic hit value derived from the prior block signature.
Hit Value Derivation
For each candidate forging account, a 64-bit unsigned Hit Value () is derived by hashing the previous block's generation signature and the candidate's composite public key using SHA-256:
The hit is extracted from the first 8 bytes (bytes through ) of , converted from little-endian byte ordering to a 64-bit unsigned integer:
Target & Hit Time Calculation
The effective target scales linearly with the forger's guaranteed effective FXT balance () and the network's current base target ():
The deterministic Hit Time ()—the point in time when a candidate forger becomes eligible to produce a block—is computed relative to the previous block's timestamp :
A block produced at timestamp is mathematically valid if and only if:
where represents the elapsed time in seconds since the previous block.
Dynamic Base Target Adjustment
To maintain the target block time of ~12 seconds, the base target adjusts dynamically every two blocks based on the 3-block moving average block time ():
- If , increases, making block forging easier for all participants.
- If , decreases, tightening the target threshold.
The adjustment is constrained within protocol boundary parameters:
Step adjustments per recalculation are bounded between and to suppress volatility and prevent dramatic swings in block interval timing.
Cumulative Difficulty & Fork Resolution
Each generated block contributes to the network's total cumulative difficulty:
The canonical chain is determined by the fork branch exhibiting the highest cumulative difficulty ().
Resource-Aware Forging Guard
To preserve node stability during periods of intense transaction throughput, Shamwari enforces a resource-aware guard function in Generator.java. The compute resources required to forge scale dynamically with mempool volume ():
where baseline thresholds are and . If host resources satisfy or , block generation is skipped for that 500ms forging cycle to protect system stability.
Pop-Off Mechanics & Reorganization
If a forger calculates a hit time earlier than the current tip block's timestamp , a block pop-off is triggered:
- The tip block is removed from the blockchain.
- Its transactions are returned to the unconfirmed mempool for re-evaluation.
- The forger generates the replacement block anchored directly to , ensuring the canonical chain continuously reflects optimal global forger ordering.
Cryptographic Hashes & Standards
| Algorithm | Provider / Class | Usage | Output Size |
|---|---|---|---|
| SHA-256 | MessageDigest | Block hashing, transaction IDs, Hit generation | 256 bits |
| SHA-512 | PBKDF2WithHmacSHA512 | Seed key derivation (100,000 iterations) | 512 bits |
| SHA3-256 | Keccak.Digest256 / SHA3_256 | Domain separation () & digest | 256 bits |
| RIPEMD-160 | RIPEMD160.Digest | Legacy address compatibility | 160 bits |
| HKDF-SHA256 | HKDFBytesGenerator | Key derivation for AES-256-GCM symmetric encryption | 256 bits |
| AES-256-GCM | GCMBlockCipher | Authenticated payload encryption (12-byte IV, 16-byte tag) | Variable |
Zero-Knowledge & Selective Disclosure
Shamwari incorporates privacy-preserving commitments and selective disclosure mechanisms:
- Phasing & Multi-Party Control: Time-locked puzzles and multi-signature threshold expressions (-of-) executed via protocol-native voting.
- W3C Verifiable Credentials: Selective disclosure of account identity and KYC attributes without exposing underlying personal data.