Documentation

CslibFrontier.Computability.WordRAM.SymbolicExec.Frame

Register facts across calls #

A proof about a word-RAM program that calls subprograms carries the registers it still needs across each call: the specification of a call gives its result state y and a frame, a statement ∀ i, i ≠ r → … → y.regs i = x.regs i of the registers the call leaves alone, and the proof needs y.regs a = v for every register a the next call reads. Written by hand, each such fact names the frames it passes, proves each of their premises at a, and names the hypothesis that gives the value: (cf _ (by decide) (by decide)).trans ((bf _ (by decide)).trans ha).

regs_frame proves these facts from the hypotheses, without naming them, including across renamed register banks (Data.comap, Data.extend) and framed calls (Data.havoc). wram_exec * and wram_simp * use the same context scanner to supply register, frame, and memory-equality rewrites automatically during symbolic execution.

Main definitions #

A register frame: a proof of a statement ∀ xs, s'.regs i = s.regs i with i among xs.

The facts about registers and whole-memory / cell equalities among the hypotheses.

The parts (r, s, i) of a read s.regs i of a register of s : Data r.

The key of the register name i : Fin r: its value if it evaluates to a literal, so that Reg.levels and (3 : Fin 64) are the same register, and otherwise the name itself.

The facts about registers among the hypotheses.

A proof of Function.Injective f for a register map f : Fin r → Fin s: checks local context, standard Fin embeddings (castAdd, castLE, natAdd), linear Fin.mk definitions via omega on Fin.val, and closed decide.

@[reducible, inline]

The reads that could not be followed further, each with the frames of its state and the premise of each that could not be proved.

Reduce a single register read d.regs j across Data.extend:

Rewrite the reads of registers in e along the frames.

Split the goal into the components of conjunctions and Prop-valued structures.

Prove the equation g along the frames F, or return what is left of it.

Attempt to close g with regs_frame (including intros and structure splitting). Restores the state and returns false on failure.

Rewrite the leaf register and memory reads in e using F (register equations, frames, Exec/ExecWithin.regs_eq, Data.extend/Data.comap/Data.havoc, s'.mem = s.mem, and s.mem a = v).

wram_exec symbolically executes structured word-RAM code (Cslib.WordRAM.Code) on a goal ∃ y, ExecWithin w c x y T ∧ P y, ExecWithin w c x y T or Cslib.WordRAM.WP w c x Q. It runs the data instructions and conditionals of c in order, with the data in closed form, until the end of the program, where t ≤ T ∧ P y (respectively t ≤ T ∧ y' = y, or Q y t) remains for the data y and instruction count t reached; a leading bound t ≤ T is closed by omega when it can. It stops at a loop, a random sample or a program given by name, leaving WP w c' y Q': continue with refine WP.of_execWithin h ?_ from a specification h of c', then wram_exec again. Name a program among the hints to execute it instead.

On the exact-count goals ∃ y, Exec w c x y T ∧ P y, Exec w c x y T and Cslib.WordRAM.WP.Exact w c x Q it works the same way with the rules of WP.Exact: the count t = T is closed by omega when it can, and refine WP.Exact.of_exec h ?_ continues from an exact specification h at a stop.

  • wram_exec [h₁, h₂] adds simp lemmas for the values read, typically the contents of the registers of x, such as x.regs zeroP = 0, and the memory cells it reads. A definition of a program among them, as in wram_exec [program, h₁], is unfolded where execution reaches it; programs that are not listed stay closed. The hint opens the program in this call only, while unfold program rewrites the whole goal: a proof in which a later wram_exec or wram_call meets the same program again keeps the unfold.
  • wram_exec (disch := tac) sets the discharger, by default fits on a word-size bound and omega on anything else. It proves side conditions (Fits w v, b ≤ a for an exact subtraction, a nonzero divisor), decides conditions of branches, and decides whether two memory addresses are equal. Register names, and side conditions without free variables, are decided by evaluation, and a side condition that is a hypothesis is proved by it, before tac runs. A lemma such as hfit : ∀ v, v ≤ b → Fits w v among the given lemmas proves fitting conditions with tac.

A conditional neither simp nor the discharger decides splits into both alternatives, tagged pos and neg, with the hypothesis hc on the compared values; wram_exec -split stops at it instead, leaving WP w (.branch …) y Q', for instance to join the alternatives with WP.cut. Side conditions that remain are left as goals after the main ones, tagged by the premise they come from (hfit, hle, hb).

Extensions:

  • wram_exec * executes structured word-RAM code just like wram_exec, and additionally resolves register reads (s.regs i), frames (∀ i, ... → y.regs i = x.regs i, Exec/ExecWithin.regs_eq), bank views (Data.extend/Data.comap), Data.havoc, memory equalities (y.mem = x.mem), and pointwise memory facts (x.mem a = v) from the local context automatically, so callers need not list [h0, h1, h2, ...] by hand.

wram_simp [h₁, h₂] simplifies reads of registers and memory after Data.set and Data.write with the simp set of wram_exec, typically in the postcondition wram_exec leaves. wram_simp (disch := tac) sets the discharger, by default fits on a word-size bound and omega on anything else, and wram_simp at h works on hypotheses.

Extensions:

  • wram_simp * simplifies reads of registers and memory like wram_simp, also resolving local register facts, frames, Data.extend/Data.comap/Data.havoc, and s'.mem = s.mem chains automatically.

regs_frame proves a fact about the registers after a sequence of calls from the frames of the calls: an equation such as z.regs a = v, a conjunction or Prop-valued structure of such equations, such as Parameters L H z, or the frame ∀ i, i ≠ r → i ≠ r' → z.regs i = x.regs i of the sequence.

It follows each read z.regs a in the goal back to a hypothesis that states the value:

  • through a frame among the hypotheses, yf : ∀ i, i ≠ r → … → z.regs i = y.regs i, whose premises hold at a: by evaluation when they have no free variables (a predicate introduced by let is unfolded first), otherwise by a hypothesis;
  • through an execution he : ExecWithin w c y z T (or Exec, or any J with a lemma J.regs_eq), when the code c does not write a, decided in the kernel when c is closed and structurally when c contains parameters;
  • through Data.set, Data.write, Data.extend, Data.comap, Data.havoc, and the definition of a state introduced by let;
  • to the value given by h : x.regs a = v, or by a component of a conjunction or a field of a hypothesis hx : Parameters L H x.

When several frames of a state hold at a, the tactic follows the latest hypothesis among them and does not return to the others. A value stated only at an intermediate state that this frame skips is therefore not found, and the tactic fails with the error described below.

No hypothesis is named, and a value the goal leaves open is filled in, so that the facts a specification asks for can be given as exec_callee y (by regs_frame) (by regs_frame). When a read cannot be followed to the stated value, the error shows the equation that is left and, for each frame of the state it stopped at, the premise that does not hold at the register.