Metakit / What a proof of one step cannot check

Check what a proof of one step cannot

With @doeixd/metakit you wrote a withdrawal as data and had Prove.machine show that it never overdraws an account. Then two withdrawals arrive at the same moment. Each reads a balance of 100, each takes 80, and the account ends at -60. Nothing in the proof was wrong: it showed that one step, started from a valid account, leaves a valid account. It said nothing about two steps reading the same account before either wrote, and nothing about a reply that arrives after a later one.

Two things decide whether the rule still holds, and neither is in the rule:

  • How the database runs concurrent writes. If it runs them one at a time, the second withdrawal reads 20 and is refused.
  • The order events arrive in. If a page applies an old reply over a newer one, it shows a state no single step produced.

This guide shows how to turn the first into an error when the server starts, and the second into a list of tests still to write, with a function that runs your steps in many orders for you. It assumes you have read the tutorial; the account here is a smaller one with only a balance. Install @doeixd/metakit and effect; the proof step needs z3-solver only if one of your transitions is one the built-in checks cannot decide. The code blocks below continue one file as an ES module (they use top-level await); the comment under each is its result.