1.12 Reversals and Adjustments: Exit Evidence
Evidence · Step: 1.12 Reversals and Adjustments
| Step | 1.12 Reversals and Adjustments |
| Date | 2026-11-12 |
| Database | PostgreSQL 18.6 (postgres:18-alpine) |
| Result | Passed |
Deliverables
Section titled “Deliverables”| Deliverable | File |
|---|---|
| Actors, reason codes, entry kinds, authorization rules | crates/core/src/authorization.rs (ActorId, ReasonCode, EntryKind, Authorization::check, REASON_CODES) |
| Corrections in the reference ledger | MemLedger::reverse(original, id, authorization), MemLedger::post_adjustment; INV-25 in check_invariants |
| Corrections in the engine | reverse_entry with a reason and requester; post_entry with an authorization posts an adjustment; PgStore implements both through the Ledger trait |
| Fingerprints | Reversals and adjustments include their reason and actors (reversal_fingerprint, adjustment_fingerprint) |
| Database | migrations/0003_corrections.{up,down}.sql: reason_codes, entry kind, reason_code, requested_by, approved_by, and the journal_entries_authorization CHECK |
| Rule for overdrawing reversals | ADR-0013 |
| Tests | crates/core/src/model/tests.rs, crates/core/src/authorization.rs, crates/engine/tests/corrections.rs; the differential test now includes random adjustments |
Implementation tasks
Section titled “Implementation tasks”| Task | Done |
|---|---|
reverse_entry(entry_id, reason, actor): mirrored lines, reverses_entry_id, the same idempotency semantics, no reversal of a reversal |
Yes. The reason and requester are part of the request fingerprint. |
| Reversals that would breach the non-negative rule: reject and require an adjustment, documented in an ADR | Yes: ADR-0013; E13’s open question now points to it |
Adjustments require reason_code, requested_by and approved_by, different from each other, enforced in the engine and by a DB CHECK |
Yes |
| A table of reason codes | Yes: 2 reversal reasons and 5 adjustment reasons, in mezgeb-core and seeded into the database; a test keeps the two equal. A reason can only be used for its own kind of entry (enforced by a composite foreign key). |
Testing requirements
Section titled “Testing requirements”| Requirement | Test | Result |
|---|---|---|
| Reverse → balances return exactly to their prior values | a_reversal_restores_balances_and_leaves_the_original_untouched |
Pass |
| A second reversal is rejected (engine and DB) | reversal_rules_hold; reversal_rules (tests/schema.rs) |
Pass: AlreadyReversed; 23505 from the database |
| Reversing a reversal is rejected | reversal_rules_hold; reversal_rules |
Pass: CannotReverseReversal; MZ003 from the database |
| A reversal that drives an account negative is rejected | a_reversal_that_would_overdraw_is_refused |
Pass: InsufficientFunds, nothing changed; the correction then goes through as an approved adjustment |
| An adjustment with the same maker and checker is rejected | adjustments_need_two_different_people |
Pass: MakerIsChecker from the engine; 23514 from the database when the engine is bypassed |
| Property: post then reverse leaves all balances unchanged | post_then_reverse_changes_nothing |
Pass |
Also: a reversal or adjustment with a reason of the wrong kind is refused
(engine, and 23503 from the database); an adjustment without an approver
is refused; reversals record their reason; the stored authorization reads
back exactly; INV-25 corruption is detected by check_invariants. All 13
schema tests, 8 idempotency tests, the concurrency tests and the
differential test still pass, the last now with random adjustments
(including self-approved ones and wrong reasons) compared between the
reference ledger and PostgreSQL.
Acceptance criteria
Section titled “Acceptance criteria”The original rows’ bytes are unchanged after reversal, verified by a
hash of each row (md5(row_to_json(...))) of the original entry and its
two lines, before and after the reversal:
original rows before and after reversal:["5fdd93488a5c83d1bc1b85256d078597", "d119779790dd4d574c7ba5ba3e04b3e3", "85c1f0730e033f75f7a80ab25a62b53a"]Identical before and after. Pass.
Exit gate
Section titled “Exit gate”Gate: the adjustment control is reviewed against the threat model’s insider-admin entries.
| Threat | What the adjustment controls now do | What is still open | Step |
|---|---|---|---|
| TM-12 An insider posts an adjustment crediting an account they control | An adjustment cannot post without a reason from the adjustment list and two different actors. Enforced by the engine and, independently, by a database CHECK and foreign key, so bypassing the engine does not help. The adjustment, its reason and both actors are recorded in the journal, which cannot be edited (INV-9). | Actor IDs are asserted by the client, not proven. A compromised client, or one person with access to it, can name two different actors. Proving identity, and checking that the approver is allowed to approve, is authentication and authorisation. No limits per person on how much one actor can propose or approve. No separate audit events beyond the journal row. | 2.08 (identity, roles, limits), 2.09 (audit events) |
| TM-12 Two insiders collude, one as maker and one as checker | Both names are recorded permanently with the entry, so collusion leaves evidence. | Two-person control cannot stop two people who agree to steal. Accepted risk, reduced by limits, alerts on adjustment volume and reconciliation. | 2.08, 2.15, 3.09 |
| TM-11 An insider edits or deletes the journal to hide an adjustment | Unchanged and still holding: journal rows cannot be updated or deleted (trigger and privileges). Verified again: a reversal leaves the original rows byte for byte unchanged. | The hash chain, so that even a superuser’s edit is detectable. | 2.09 |
| TM-13 An insider reopens a closed period to change an adjustment after the fact | Not affected yet: periods do not exist. | Closed periods and their maker-checker reopening. | 2.05, 2.08 |
| TM-15 An insider disables verification so a bad adjustment goes unnoticed | check_invariants (reference ledger) and the integrity report (database) already check INV-25 and the books; nothing runs them on a schedule yet. |
The verification job and its alert. | 1.13, 3.09 |
Conclusion. The ledger now refuses any adjustment that lacks a reason or a second, different approver, at two independent layers, and records who did what in an append-only journal. Within the ledger, a single actor cannot create money alone. What the ledger cannot yet guarantee is that the two names belong to two real, authorised people: that is the main remaining gap for TM-12, and step 2.08 closes it. The threat model’s TM-12 row now points to this review.
Result: passed.