Verification
Trailproof’sverify() method walks the entire hash chain, recomputing every hash and comparing it to the stored value. Any mismatch indicates tampering.
How Verification Works
The verifier starts at the genesis hash and walks forward through every event:- Set
expected_prev = "0" × 64(genesis hash) - For each event at index
i:- Recompute
expected_hash = SHA-256(expected_prev + canonical_json(event)) - If
event.hash != expected_hash, additobroken - Set
expected_prev = event.hash(always advance — detect cascading breaks)
- Recompute
- Return
VerifyResult { intact, total, broken }
Basic Usage
Cascading Breaks
When one event is tampered, every subsequent event also appears broken. This is by design — each event’s hash depends on the previous event’s hash. If someone modifies event 2 in a chain of 5:- Event 2: hash mismatch (the tampered event)
- Event 3:
prev_hashno longer matches event 2’s new hash - Events 3–5: all broken due to cascading failure
Empty Chain
Verifying an empty chain returns a clean result:Python
Verification does not throw exceptions on broken chains — it returns the result. Always check
result.intact to determine chain validity.JSONL Store Verification
Verification works the same regardless of store type. The JSONL store reads all events from disk and verifies the chain:Python
broken.
Next Steps
Hash Chain
Understand the cryptographic linking mechanism.
HMAC Signing
Add provenance on top of chain integrity.