◇ OpenCyber Academy
Engineering · Chapter 30 · English

Chapter 30 — Verification laboratory I

Open, free learning for anyone who wants to protect people and technology. No account is required to read this text or its worked answers.

Chapter 30 — Verification laboratory I

Lesson map

Lesson 30 published. Map, example, EX088.

flowchart TD
  N0["Learning outcomes"]
  N1["30.1 Why reconcile"]
  N2["30.2 The reconciliation script"]
  N3["Lab — Database and ledger reconciliation"]
  N4["30.3 Investigating mismatches"]
  N5["Synthesis"]
  N0 --> N1 --> N2 --> N3 --> N4 --> N5
  N5 --> EX["Worked example"]
  EX --> Q["Exercise EX088"]

Logical drawing

flowchart LR
  N0["Learning outcomes"]
  N1["30.1 Why reconcile"]
  N2["30.2 The reconciliation script"]
  N3["Lab — Database and ledger reconciliation"]
  N4["30.3 Investigating mismatches"]
  N5["Synthesis"]
  N0 --> N1 --> N2 --> N3 --> N4 --> N5 --> Q["EX088"]
[Learning outcomes]
    |
    v
[30.1 Why reconcile]
    |
    v
[30.2 The reconciliation script]
    |
    v
[Lab — Database and ledger reconciliation]
    |
    v
[30.3 Investigating mismatches]
    |
    v
[Synthesis]
    |
    v
[Worked example] --> [Exercise EX088]

Learning outcomes

You will (1) verify system consistency through reconciliation; (2) investigate mismatches; (3) record verification evidence.

30.1 Why reconcile

The cooperative keeps member account records in its database and balances on the ledger. They should agree; if they do not, statements to members may be wrong. Reconciliation compares the two systematically. Jonas explains that reconciliation verifies the integration between systems, not the contract alone, and catches problems such as missed events, failed database writes or accounts created in one place but not the other. In financial systems, regular reconciliation is a basic control that auditors expect. Brightwater schedules reconciliation weekly.

30.2 The reconciliation script

Jonas writes a standard-library script that reads a synthetic database snapshot and a synthetic ledger snapshot, compares balances per account, and prints mismatches and totals. It reads only the two synthetic files and changes nothing. He tests it on a pair of identical snapshots, which must report zero mismatches, before using it on the verification lab data. He also tests it on a pair that differs in exactly one account, which must report exactly one mismatch. Both tests pass. The script prints mismatches sorted by account so the output can be compared between weeks, and it saves the results with the snapshot dates for the verification record.

Lab — Database and ledger reconciliation

"""Reconcile an off-chain account database with an on-chain balance snapshot (synthetic, read-only)."""
DB = {"h01": 150, "h02": 20, "h03": 0, "h04": 60, "h05": 100, "h06": 25}
CHAIN = {"h01": 150, "h02": 20, "h04": 60, "h05": 90, "h07": 10}

def main():
    keys = sorted(set(DB) | set(CHAIN))
    diffs = [(k, DB.get(k), CHAIN.get(k)) for k in keys if DB.get(k, 0) != CHAIN.get(k, 0)]
    print(f"accounts compared {len(keys)}, mismatches {len(diffs)}")
    for k, d, c in diffs:
        print(f"  {k}: db={d} chain={c}")
    print(f"totals db={sum(DB.values())} chain={sum(CHAIN.values())}")

if __name__ == "__main__":
    main()

Run with python3 lab_reconcile.py. Verified output:

accounts compared 7, mismatches 3
  h05: db=100 chain=90
  h06: db=25 chain=None
  h07: db=None chain=10
totals db=355 chain=330

30.3 Investigating mismatches

The run compares seven accounts and finds three mismatches: h05 shows 100 in the database but 90 on the ledger; h06 exists only in the database with 25; and h07 exists only on the ledger with 10. Totals are 355 and 330. Jonas investigates each: h05's difference matches a transfer the database missed during a gateway restart; h06 is a new member whose wallet was not yet created; h07 is a test account left on the network. Each finding becomes a fix and a test.

Worked example

Reconciliation of seven accounts finds three mismatches, traced to a missed event during a gateway restart, an unfinished onboarding and a leftover test account.

Synthetic case. Snapshots and accounts are synthetic.

Errors and limits

Assuming database and ledger always agree leaves member statements unchecked.

Exercises

Synthesis

Regular reconciliation verifies integration between systems and reveals hidden operational faults.

Continue studying — chapter 30 of 50

← Chapter 29 (draft) · Course chapter index · Chapter 31 (draft) →