The One Invariant
Everything in VerityDB derives from a single mathematical invariant.[1]
What This Means
- S
- Current state — what you query
- S0
- Initial state — empty or genesis
- L
- Log — ordered sequence of events
- A
- Apply function — deterministic state machine
Why It Matters
Log Structure
The append-only log is the foundation. Every entry is hash-chained and CRC-protected.
+------------------+
| Length (u32) | 4 bytes
+------------------+
| CRC32 (u32) | 4 bytes - covers payload
+------------------+
| Prev Hash (32) | 32 bytes - SHA-256
+------------------+
| Timestamp (u64) | 8 bytes - nanoseconds
+------------------+
| Type Tag (u8) | 1 byte
+------------------+
| Payload | Variable length
+------------------+
Integrity Layers
Two independent checks:
- CRC32 for corruption detection
- SHA-256 chain for tamper evidence
Ordering Guarantee
Hash chain enforces:
- Total order of events
- No gaps possible
- No reordering possible
Durability
Write path guarantees:
- fsync before ack
- Atomic append
- Recovery on crash
Dual-Hash Cryptography
We use two hash algorithms, each optimized for its purpose.[3][4]
SHA-256
ComplianceUsed where regulatory acceptance matters:
FIPS 180-4 compliant. Auditors recognize it.
BLAKE3
PerformanceUsed for internal hot paths:
10x faster than SHA-256 with SIMD.
/// Compile-time enforcement of hash algorithm selection.
pub enum HashPurpose {
/// External-facing, compliance-critical paths
Compliance, // Uses SHA-256
/// Internal hot paths where speed matters
Internal, // Uses BLAKE3
}
Functional Core / Imperative Shell
The kernel is a pure state machine. All I/O lives at the edges.[5]
/// Pure core: No I/O, no clocks, no randomness
fn apply_committed(
state: State,
cmd: Command
) -> Result<(State, Vec<Effect>)>
/// Impure shell: Executes effects, handles I/O
impl Runtime {
fn execute_effect(&mut self, effect: Effect) -> Result<()>
}
Benefits for Testing
- Deterministic simulation[6]
- Fast property-based tests
- Reproducible bug reports
- No mocking required
Benefits for Correctness
- State transitions are explicit
- Side effects are trackable
- Replay is trivial
- Reasoning is local
Design Constraints
Hard rules enforced across the codebase.
Code Quality
expect() with reason
Assertion Density
Every function should have 2+ assertions:
"Parse, don't validate" — validate at boundaries once.
References
-
1
Event Sourcing. 2005. martinfowler.com
- 2
-
3
FIPS 180-4: Secure Hash Standard (SHS). 2015. csrc.nist.gov
-
4
BLAKE3: One function, fast everywhere. 2020. blake3.pdf
- 5
-
6
Simulation Testing for Liveness. 2020. sled.rs
Explore the Code
The architecture is fully documented in code. Start with the kernel for the core state machine, or vdb-crypto for the cryptographic foundation.