Documentation

CslibFrontier.Computability.WordRAM.SymbolicExec.Havoc

Calls that keep the registers a routine does not write #

wram_call spec with y post continues from a routine's contract with data y about which only the contract's conclusion is known. A register the routine never writes keeps its contents (Cslib.WordRAM.ExecWithin.regs_eq), but the continuation does not see that: every contract restates the registers its caller still needs, and every caller passes them on by hand.

x.havoc c v m is the data reached from x by a run of c about which nothing else is known: the registers c does not write hold what they hold in x, the others hold v, and memory is m. Every run of c from x ends in such data (Cslib.WordRAM.ExecWithin.eq_havoc). Reading a register of it is decided by evaluating c.Preserves i, so wram_exec and wram_simp reduce a read of an unwritten register to the read in x, and through the earlier writes to its value, with the simp set they already use.

wram_call spec framed with v m post is wram_call with the data reached in this form (Cslib.WordRAM.WP.of_spec_havoc). The contract may leave its hypotheses out, as in wram_call (routine_spec a b ..) framed with v m post: each is simplified with wram_simp and the given lemmas and proved by a hypothesis, by fits or by omega, and those that remain follow the continuation as goals. The contract's conclusion is simplified in the same way before post names its parts, so that it speaks of v, m and the caller's data.

Main definitions #

Main results #

def Cslib.WordRAM.Data.havoc {B : Basis} {r : ℕ} (c : Code B r) (x : Data r) (v : Fin r → ℕ) (m : ℕ → ℕ) :

The data x after a run of c about which nothing else is known: the registers c does not write keep their contents, the others hold v, and memory is m.

theorem Cslib.WordRAM.Data.havoc_regs_of_preserves {B : Basis} {r : ℕ} {c : Code B r} {i : Fin r} (h : Code.Preserves i c) (x : Data r) (v : Fin r → ℕ) (m : ℕ → ℕ) :
(havoc c x v m).regs i = x.regs i

A register the program does not write keeps its contents.

theorem Cslib.WordRAM.Data.havoc_regs_of_not_preserves {B : Basis} {r : ℕ} {c : Code B r} {i : Fin r} (h : ¬Code.Preserves i c) (x : Data r) (v : Fin r → ℕ) (m : ℕ → ℕ) :
(havoc c x v m).regs i = v i

A register the program writes holds its new contents.

theorem Cslib.WordRAM.Data.havoc_mem {B : Basis} {r : ℕ} (c : Code B r) (x : Data r) (v : Fin r → ℕ) (m : ℕ → ℕ) :
(havoc c x v m).mem = m

The memory after the run.

theorem Cslib.WordRAM.Data.havoc_self {B : Basis} {r : ℕ} (c : Code B r) (x : Data r) :
havoc c x x.regs x.mem = x

Data is the data after a run that changes nothing.

theorem Cslib.WordRAM.Data.havoc_havoc {B : Basis} {r : ℕ} (c : Code B r) (x : Data r) (v v' : Fin r → ℕ) (m m' : ℕ → ℕ) :
havoc c (havoc c x v m) v' m' = havoc c x v' m'

A second run of the same program writes the same registers.

theorem Cslib.WordRAM.ExecWithin.eq_havoc {B : Basis} {r w T : ℕ} {c : Code B r} {x y : Data r} (h : ExecWithin w c x y T) :
y = Data.havoc c x y.regs y.mem

A run of c from x ends in x.havoc c v m, for the registers and memory reached.

theorem Cslib.WordRAM.WP.of_spec_havoc {B : Basis} {r w T : ℕ} {c : Code B r} {x : Data r} {P : Data r → Prop} {Q : Data r → ℕ → Prop} (h : ∃ (y : Data r), ExecWithin w c x y T ∧ P y) (hQ : ∀ (v : Fin r → ℕ) (m : ℕ → ℕ), P (Data.havoc c x v m) → Q (Data.havoc c x v m) T) :
WP w c x Q

Continue from a routine's contract at its instruction allowance. The data reached is the caller's with the registers the routine writes, and memory, replaced.

Apply a fixed-time, direct, or time-indexed routine contract and expose its continuation. Only bank-view projections are normalized; the callee program remains closed.

Extensions:

  • Direct wram_call h without with (for bare ExecWithin / Exec contracts), optional hint lemmas [h₁, …], and renamed bank forms.

  • Apply a routine contract and keep the registers the routine does not write: the data reached is the caller's data x with the registers the routine writes replaced by v and memory by m (x.havoc c v m), so wram_exec and wram_simp reduce later reads of the other registers to their values in x. Hypotheses the contract leaves out, as in (routine_spec a b ..), are simplified with wram_simp and the given lemmas and proved by a hypothesis, up to reducible unfolding, or by fits or omega; those that remain follow the continuation. The contract's conclusion is simplified in the same way before the patterns after v and m name its parts.