DelegusRequest early access

ReceiptsEssay

Proving Delegus Check

Team Delegus

  • 8 min read
The 24 checks of Delegus Check in their fixed order, with the three points where the service is touched: the issuer, the revocation state and the one-time pass. A seal over the row reads 197 theorems. Beneath: our engine and the Lean model agree on 52 of 52 published cases and 9,546 of 9,546 altered ones, with the repository address github.com/delegusai/delegus-check-lean.

Delegus Check is the part of EnterpriseWorld that checks every act an agent takes. Before a bill is paid or an order goes out, it answers one question for the system on the other side: is this agent really allowed to do this, right now, for this company? The answer comes from 24 checks run in a fixed order, written down in the Delegus Check v0.2 specification.

That specification makes promises. If anything is missing or broken the answer is no. The same inputs always give the same answer. A revoked permission stays revoked. A one-time pass works once. An old decision can be checked again years later and comes out the same.

Until now those promises rested on careful reading and a set of published test cases. A test case shows the rules work for that one case. It says nothing about the case nobody thought to write.

So we wrote the rules a second time in Lean, a language that checks mathematical proofs by machine. Then we proved the promises hold for every possible input. Lean won't accept a proof with a gap in it. Anyone can run the check again.

Why it matters#

An agent that pays a bill doesn't ask the bank for permission. It sends the request. Delegus Check is what stands between that request and the money. The bank or the supplier relies on its yes or no and acts on it straight away.

So the rules behind that yes have to be right every time, for every request anyone could ever send. A rule that's right in 99.9% of cases is wrong in exactly the case an attacker goes looking for. One gap at the edge of a time window is enough to let a pass be used twice. That could be a payment made twice.

Tests can't close that kind of gap. There are more possible requests than anyone could ever try. A proof covers all of them at once.

It also changes who has to be trusted. A bank, a supplier or an auditor doesn't have to take our word for any of this. They can read the rules, run the proof and re-check a receipt on their own machine.

How a proof works#

Lean is a programming language with one unusual habit: it checks proofs. We wrote the specification's 24 checks in it as a model, a small program that does what the specification says and nothing more. Then we wrote statements about that model and proved them.

Here is the simplest one, exactly as it appears in the repository:

lean
theorem allow_iff_all_pass (c : Checks) :
    (kernel c).decision = .allow ↔ ∀ k ∈ order, c.get k = .pass

Read it as: the decision is "allow" if and only if every check in the order passed. Not for one example request. For every possible set of check results.

Under each statement sits its proof, a few lines of steps. Lean follows them one by one. If a single step doesn't follow from the ones before it, Lean rejects the whole proof. There's no "probably" and no partial credit.

Here is a harder one, the promise that a one-time pass works once:

lean
theorem at_most_one_allow (st0 : ReplayStore) (v1 : RVerify) (mid : List RVerify) (v2 : RVerify)
    {p1 p2 : ProofF}
    (hp1 : parseProof v1.π v1.req.proof = some p1) (hp2 : parseProof v2.π v2.req.proof = some p2)
    (hrp : v1.req.rp = v2.req.rp) (hjti : p1.jti = p2.jti) (hiat : p1.iat = p2.iat)
    (hw : v2.req.windowS ≤ v1.req.windowS) :
    ¬ ((v1.eval st0).result.decision = .allow ∧
       (v2.eval (storeAfter (v1.after st0) mid)).result.decision = .allow)

In plain words: take two checks of the same pass at the same receiving service, with any number of other checks in between (mid). They can't both say yes. The lines starting with h are the conditions it holds under. They're written into the statement where anyone can see them. Two passes count as the same when they share their id (jti) and the time they were made (iat). The last condition says the service didn't widen its time window between the two checks.

A proof can't tell you it's proving the right thing. So every statement is written to say what the specification says. The model is also run against our engine on thousands of cases. More on that below.

What is proven#

Lean has checked each of these for every possible request, every state of the service and every answer the cryptography could give:

  • There is no way to a yes except every check passing. One failed or skipped check means no.
  • The reason given is the first check that failed, in the specification's order. Every no has a reason.
  • Missing or broken means no. An issuer, revocation or replay store that can't be reached. Input that can't be read. A signature of the wrong kind. A rule the system doesn't know.
  • The same inputs give the same answer, on any machine.
  • A one-time pass is accepted at most once. A second use is refused, either because the first use's record is still there or because the store's clock is too far ahead to trust and the store records nothing.
  • "Revoked" means revoked. That reason is given only when a valid, signed revocation list really marks the permission. An unusable list gives "can't tell right now". It's still a no.
  • Once a revoke completes, every later check of that permission is no, on every server, whatever it has cached. Revoking twice changes nothing. Nothing un-revokes.
  • The service touches its stores in one fixed order: the issuer, then the revocation state, then the one-time pass. The pass is used up only after the first fourteen checks pass, so a revoked, forged or expired request never wastes one.
  • An old decision re-checks the same from its receipt and the documents it names. It uses the time the receipt records, not today's clock.

That's 197 theorems. None skips a step and none adds an assumption of its own. Each rests only on Lean's standard foundations. The proof uses Lean 4.36 and nothing else, no outside libraries. The only software you have to trust is Lean itself.

We didn't stop at Lean's own word. We checked it the way the Lean community checked this month's proof of the Riemann Hypothesis. The whole proof was exported to a plain file, the same file byte for byte on every run. Lean's own checker and four independent ones, each written separately from Lean, all accepted the proof. Two of those come with their own proof that they can't accept a false one. Separately, all 197 statements were written out again with their proofs removed. A tool confirmed that each proof proves exactly the statement as written. One script in the repository runs all of it.

Some rest on conditions about the outside world. Those are named in the theorem itself. The revocation and one-time-pass proofs assume each store keeps one order of events, as the specification requires. The one-time-pass proof also assumes the store keeps each record until it expires. The revocation proof assumes the revocation lists we publish are correct and current.

Tied to the real engine#

A proof about a model is only worth something if the model is the product. So the Lean model and our engine run the same 52 published test cases. They have to give the same answer on every one: the decision, the reason and all 24 checks. They do.

Then each case was altered about a hundred ways. The clock, the time window and the amounts changed. Requests were tampered with and re-signed. The same pass was used again at the very edges of its window, with the store's clock set anywhere from far behind to five seconds ahead. That made 9,546 cases. There's no expected answer for these. The model and the engine just have to agree, down to which store each one touched and in what order. They agree on all 9,546.

That's testing, not proof. It doesn't prove the engine's code equals the model. The repository says so.

What the proof caught#

Writing rules this precisely shows where they have gaps. The proof found four in our own rules. We fixed all four before publishing this. Each fix went into the specification as a numbered correction with its own test cases, so every implementation gets it. Then we fixed our engine and proved the corrected rules.

  1. A pass could slip through twice at the edge of its time window. The record that stops a pass being reused expired a set time after its first use. Network delay could let the same pass through a second time in its last milliseconds. This was the only finding that could turn a no into a yes. Now the record expires at a time fixed by the pass itself. The store's own clock is checked in the same step. If it runs more than four seconds ahead, the answer is "can't check right now" instead of a risky yes. That fix is what made the at-most-once proof possible.
  2. A revocation record that was there but unusable was reported as "revoked". It was a no either way. But the honest answer is "can't tell right now". That's what it gives now.
  3. A web address with an escape code in its site name (like %2F) had no single correct form under the rules. It never changed an answer. No real site name contains one. Such addresses are now refused outright.
  4. A receipt left out one setting needed to re-check it on its own: the time window the receiving service allowed. Without it, someone re-checking a decision had to be told the window separately. Receipts in the next version of the specification carry it. The proof covers that field.

What is not proven#

  • The cryptography itself. We assume signatures can't be forged and fingerprints don't collide. The proof shows the rules are right given that. It says so wherever it relies on it.
  • The live databases. The proofs assume the stores keep one order of events. They don't prove our hosted databases do. A check already running at the moment a revoke completes isn't covered either. The specification doesn't claim it is.
  • That the engine's code equals the model. It agrees on 52 published cases and 9,546 altered ones. That's strong evidence, not a proof.
  • The rest of the next version. The model covers version 0.2, plus the receipt's new time-window field from version 0.3. Nothing else from 0.3.

Proving the rules doesn't make an agent's choices wise. An order to the wrong supplier still passes if it's inside the limit. What the proof shows is narrower and harder. Under these rules an agent gets a yes only for what a person allowed. Anyone holding the receipt can check that afterwards.

The model, the proofs and the comparison scripts are at github.com/delegusai/delegus-check-lean. Clone it, run lake build, then lake test and count for yourself.