Verify A Hash-Chained Chain Of Custody Audit Log
Last updated: November 29, 2026
Quick Overview
Each audit entry stores prev_hash, actor, action, timestamp and its own SHA-256 hash over those fields. Write a function that returns the index of the first entry that breaks the chain, or -1 if the log is intact.
Axon
November 29, 20260
0
0 solved
Each audit entry stores prev_hash, actor, action, timestamp and its own SHA-256 hash over those fields. Write a function that returns the index of the first entry that breaks the chain, or -1 if the log is intact.
Digital evidence only holds up in court if every view, share and export is recorded and tamper evident, which is why audit trails are central to Axon Evidence. This question checks that a candidate understands hash chaining, deterministic serialization and what a verifier can and cannot prove.
What the Interviewer Expects
- Recompute each hash from the previous verified hash, not the stored one
- Check both the prev_hash link and the entry's own hash
- Use an unambiguous, deterministic serialization
- Explain that truncation of the tail is not detected by the chain alone
- Return the first failing index
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you detect someone deleting the last ten entries?
- How would you verify a billion-entry log without rereading it every time?
- Why is a field separator important in the hashed payload?
- Where would you anchor periodic checkpoints so an insider cannot rewrite them?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
Input: an ordered list of entries, each a dict with prev_hash, actor, action, ts, hash. The first entry's prev_hash must equal a known genesis value. Output: first broken index or -1. Hash...
High-Level Design
Walk the log keeping prev, the last hash I have verified myself. For each entry, the stored prev_hash must equal prev (detects reordering or insertion) and the stored hash must equal my recomp...