diff --git a/Verify/Infer/README.md b/Verify/Infer/README.md new file mode 100644 index 00000000..9bed15fa --- /dev/null +++ b/Verify/Infer/README.md @@ -0,0 +1,41 @@ +# Loop-invariant reconstruction: evidence + +What this directory shows: three loops' invariants, returned unedited by z3's Spacer engine, are +proved by the Lean kernel to satisfy initiation, preservation and use, with no axiom beyond +`propext`, `Classical.choice` and `Quot.sound`. Nothing here is built by `lake build`: the +default library roots are under `SolidCore`, and these files are checked on their own. + +## What is and is not proved + +- The Horn clauses (`chc/*.smt2`) and the Lean statements of each obligation were written by hand + from the Solidity source of each loop. They are **not** solar-verify's emitted verification + conditions, and nothing here proves that they match the EVM, the compiler or solar-verify's + encoding. Treat them as a reconstruction method, not as a certificate for any contract. +- The `*_u256` variants model Solidity 0.8 checked arithmetic as path guards: every arithmetic + result lies in `[0, 2^256)`, and a path that would overflow reverts and is dropped. They do not + prove that the loops never revert. The `*_int` variants use unbounded integers with the + `uint` inputs nonnegative; they say nothing about EVM words. +- Only the invariant is searched for by an untrusted solver; the proofs check it. + +Loops: `counter` (`for (i = 0; i < n; i++) count++` under `require(count + n <= limit)`, ensures +`count == old(count) + n && count <= limit`), `okwhile` (`i = 0; while (i < n) i++`, ensures +`i == n`), `drain` (`a = n; b = 0; while (a > 0) { a--; b++; }`, ensures `b == n`). + +## Files + +- `Reconstruct.lean`: Lean core only. Each `Inv_*` is generated by `smt2lean_inv.py` from the + Spacer model in `chc/*.spacer.out` (a 1:1 operator translation, `let` kept, no simplification), + and each obligation is closed by `simp only [Inv_*]; omega`. Generated by `gen_reconstruct.sh`. + Check with `lean Reconstruct.lean` on `leanprover/lean4:v4.35.0`: 18 theorems, 0.45 s, 480 MB + peak; output in `reconstruct-4.35.axioms.txt`. +- `SpacerPath.lean`: the same three loops through the `spacer` tactic of + [LeanHorn/Flex](https://github.com/LeanHorn/Flex) at `79bdae0d3d7069e5239174d52e1fc26fa035d249` + (it calls Spacer, imports the model, and certifies with `grind`). It needs Flex, so it does + not build here; output in `spacerpath-4.35.out` (6 theorems, 3.5 s, 1.95 GB). Flex builds on + 4.35.0 with the lakefile change in `flex-4.35-bump.diff` and no source change. Flex's + `flex_auto` (a trusted SMT axiom) was not used, and its own certificate check does not reject + `native_decide`, so every theorem was gated by `#print axioms`. Flex's `fix` path fails on + `counter` (recursion depth, then a heartbeat timeout), so it is not used. +- `chc/`: the Horn problems in SMT-LIB and Spacer's answers (z3 5.4.1). + +Checksums are in `SHA256SUMS`. diff --git a/Verify/Infer/Reconstruct.lean b/Verify/Infer/Reconstruct.lean new file mode 100644 index 00000000..93ad4f34 --- /dev/null +++ b/Verify/Infer/Reconstruct.lean @@ -0,0 +1,107 @@ +/-! Kernel-checked initiation / preservation / use for the three loops. + Each Inv_* below is generated by smt2lean_inv.py from the z3 Spacer model, unedited. + Only Lean core is imported (no Flex, no Mathlib). -/ +namespace FlexEval + +/-- Verbatim from chc/counter_int.spacer.out (z3 Spacer model for Inv). -/ +def Inv_counter_int (x_0 : Int) (x_1 : Int) (x_2 : Int) (x_3 : Int) (x_4 : Int) : Prop := + (let a_1 : Prop := (¬ ((x_0 + x_3 + ((-(1 : Int)) * x_4)) ≤ (-(1 : Int)))); (let a_2 : Prop := (¬ ((x_0 + x_1 + ((-(1 : Int)) * x_4)) ≤ (-(1 : Int)))); (let a_3 : Prop := (¬ ((x_0 + x_3 + ((-(1 : Int)) * x_4)) ≥ (1 : Int))); (let a_4 : Prop := (¬ ((x_1 + ((-(1 : Int)) * x_2) + ((-(1 : Int)) * x_3) + x_4) ≥ (1 : Int))); (a_1 ∧ a_2 ∧ a_3 ∧ a_4))))) + +/-- Verbatim from chc/counter_u256.spacer.out (z3 Spacer model for Inv). -/ +def Inv_counter_u256 (x_0 : Int) (x_1 : Int) (x_2 : Int) (x_3 : Int) (x_4 : Int) : Prop := + (let a_1 : Prop := (¬ ((x_0 + x_3 + ((-(1 : Int)) * x_4)) ≤ (-(1 : Int)))); (let a_2 : Prop := (¬ ((x_0 + x_1 + ((-(1 : Int)) * x_4)) ≤ (-(1 : Int)))); (let a_3 : Prop := (¬ ((x_0 + x_3 + ((-(1 : Int)) * x_4)) ≥ (1 : Int))); (let a_4 : Prop := (¬ ((x_1 + ((-(1 : Int)) * x_2) + ((-(1 : Int)) * x_3) + x_4) ≥ (1 : Int))); (a_1 ∧ a_2 ∧ a_3 ∧ a_4))))) + +/-- Verbatim from chc/okwhile_int.spacer.out (z3 Spacer model for Inv). -/ +def Inv_okwhile_int (x_0 : Int) (x_1 : Int) : Prop := + (¬ ((x_0 + ((-(1 : Int)) * x_1)) ≤ (-(1 : Int)))) + +/-- Verbatim from chc/okwhile_u256.spacer.out (z3 Spacer model for Inv). -/ +def Inv_okwhile_u256 (x_0 : Int) (x_1 : Int) : Prop := + (¬ ((x_0 + ((-(1 : Int)) * x_1)) ≤ (-(1 : Int)))) + +/-- Verbatim from chc/drain_int.spacer.out (z3 Spacer model for Inv). -/ +def Inv_drain_int (x_0 : Int) (x_1 : Int) (x_2 : Int) : Prop := + (let a_1 : Prop := (¬ ((x_0 + ((-(1 : Int)) * x_1) + ((-(1 : Int)) * x_2)) ≤ (-(1 : Int)))); (let a_2 : Prop := (¬ ((x_0 + ((-(1 : Int)) * x_2)) ≤ (-(1 : Int)))); (let a_3 : Prop := (¬ ((x_0 + ((-(1 : Int)) * x_1) + ((-(1 : Int)) * x_2)) ≥ (1 : Int))); (a_1 ∧ a_2 ∧ a_3)))) + +/-- Verbatim from chc/drain_u256.spacer.out (z3 Spacer model for Inv). -/ +def Inv_drain_u256 (x_0 : Int) (x_1 : Int) (x_2 : Int) : Prop := + (let a_1 : Prop := (¬ ((x_0 + ((-(1 : Int)) * x_1) + ((-(1 : Int)) * x_2)) ≤ (-(1 : Int)))); (let a_2 : Prop := (¬ ((x_0 + ((-(1 : Int)) * x_2)) ≤ (-(1 : Int)))); (let a_3 : Prop := (¬ ((x_0 + ((-(1 : Int)) * x_1) + ((-(1 : Int)) * x_2)) ≥ (1 : Int))); (a_1 ∧ a_2 ∧ a_3)))) + +/-! ## (a) Counter.bump — vars (c0 = old count, n, lim, i, c = count) -/ + +-- mathematical Int (uint inputs nonnegative, no overflow guards) +theorem counter_int_init : ∀ c0 n lim : Int, + 0 ≤ c0 → 0 ≤ n → 0 ≤ lim → c0 ≤ lim → c0 + n ≤ lim → Inv_counter_int c0 n lim 0 c0 := by + intros; simp only [Inv_counter_int]; omega +theorem counter_int_pres : ∀ c0 n lim i c : Int, + Inv_counter_int c0 n lim i c → i < n → Inv_counter_int c0 n lim (i + 1) (c + 1) := by + intros; simp only [Inv_counter_int] at *; omega +theorem counter_int_use : ∀ c0 n lim i c : Int, + Inv_counter_int c0 n lim i c → ¬ (i < n) → c = c0 + n ∧ c ≤ lim := by + intros; simp only [Inv_counter_int] at *; omega + +-- uint256 with Solidity 0.8 checked arithmetic: every op result must lie in [0, 2^256) +theorem counter_u256_init : ∀ c0 n lim : Int, + 0 ≤ c0 → c0 < 115792089237316195423570985008687907853269984665640564039457584007913129639936 → 0 ≤ n → n < 115792089237316195423570985008687907853269984665640564039457584007913129639936 → 0 ≤ lim → lim < 115792089237316195423570985008687907853269984665640564039457584007913129639936 → c0 ≤ lim → + 0 ≤ c0 + n → c0 + n < 115792089237316195423570985008687907853269984665640564039457584007913129639936 → c0 + n ≤ lim → Inv_counter_u256 c0 n lim 0 c0 := by + intros; simp only [Inv_counter_u256]; omega +theorem counter_u256_pres : ∀ c0 n lim i c : Int, + Inv_counter_u256 c0 n lim i c → i < n → + 0 ≤ c + 1 → c + 1 < 115792089237316195423570985008687907853269984665640564039457584007913129639936 → 0 ≤ i + 1 → i + 1 < 115792089237316195423570985008687907853269984665640564039457584007913129639936 → + Inv_counter_u256 c0 n lim (i + 1) (c + 1) := by + intros; simp only [Inv_counter_u256] at *; omega +theorem counter_u256_use : ∀ c0 n lim i c : Int, + Inv_counter_u256 c0 n lim i c → ¬ (i < n) → c = c0 + n ∧ c ≤ lim := by + intros; simp only [Inv_counter_u256] at *; omega + +/-! ## (b) ok_while — vars (n, i) -/ +theorem okwhile_int_init : ∀ n : Int, 0 ≤ n → Inv_okwhile_int n 0 := by + intros; simp only [Inv_okwhile_int]; omega +theorem okwhile_int_pres : ∀ n i : Int, Inv_okwhile_int n i → i < n → Inv_okwhile_int n (i + 1) := by + intros; simp only [Inv_okwhile_int] at *; omega +theorem okwhile_int_use : ∀ n i : Int, Inv_okwhile_int n i → ¬ (i < n) → i = n := by + intros; simp only [Inv_okwhile_int] at *; omega + +theorem okwhile_u256_init : ∀ n : Int, 0 ≤ n → n < 115792089237316195423570985008687907853269984665640564039457584007913129639936 → Inv_okwhile_u256 n 0 := by + intros; simp only [Inv_okwhile_u256]; omega +theorem okwhile_u256_pres : ∀ n i : Int, Inv_okwhile_u256 n i → i < n → + 0 ≤ i + 1 → i + 1 < 115792089237316195423570985008687907853269984665640564039457584007913129639936 → Inv_okwhile_u256 n (i + 1) := by + intros; simp only [Inv_okwhile_u256] at *; omega +theorem okwhile_u256_use : ∀ n i : Int, Inv_okwhile_u256 n i → ¬ (i < n) → i = n := by + intros; simp only [Inv_okwhile_u256] at *; omega + +/-! ## (c) drain — vars (n, a, b) -/ +theorem drain_int_init : ∀ n : Int, 0 ≤ n → Inv_drain_int n n 0 := by + intros; simp only [Inv_drain_int]; omega +theorem drain_int_pres : ∀ n a b : Int, Inv_drain_int n a b → a > 0 → Inv_drain_int n (a - 1) (b + 1) := by + intros; simp only [Inv_drain_int] at *; omega +theorem drain_int_use : ∀ n a b : Int, Inv_drain_int n a b → ¬ (a > 0) → b = n := by + intros; simp only [Inv_drain_int] at *; omega + +theorem drain_u256_init : ∀ n : Int, 0 ≤ n → n < 115792089237316195423570985008687907853269984665640564039457584007913129639936 → Inv_drain_u256 n n 0 := by + intros; simp only [Inv_drain_u256]; omega +theorem drain_u256_pres : ∀ n a b : Int, Inv_drain_u256 n a b → a > 0 → + 0 ≤ a - 1 → a - 1 < 115792089237316195423570985008687907853269984665640564039457584007913129639936 → 0 ≤ b + 1 → b + 1 < 115792089237316195423570985008687907853269984665640564039457584007913129639936 → Inv_drain_u256 n (a - 1) (b + 1) := by + intros; simp only [Inv_drain_u256] at *; omega +theorem drain_u256_use : ∀ n a b : Int, Inv_drain_u256 n a b → ¬ (a > 0) → b = n := by + intros; simp only [Inv_drain_u256] at *; omega + +end FlexEval +#print axioms FlexEval.counter_int_init +#print axioms FlexEval.counter_int_pres +#print axioms FlexEval.counter_int_use +#print axioms FlexEval.counter_u256_init +#print axioms FlexEval.counter_u256_pres +#print axioms FlexEval.counter_u256_use +#print axioms FlexEval.okwhile_int_init +#print axioms FlexEval.okwhile_int_pres +#print axioms FlexEval.okwhile_int_use +#print axioms FlexEval.okwhile_u256_init +#print axioms FlexEval.okwhile_u256_pres +#print axioms FlexEval.okwhile_u256_use +#print axioms FlexEval.drain_int_init +#print axioms FlexEval.drain_int_pres +#print axioms FlexEval.drain_int_use +#print axioms FlexEval.drain_u256_init +#print axioms FlexEval.drain_u256_pres +#print axioms FlexEval.drain_u256_use diff --git a/Verify/Infer/SHA256SUMS b/Verify/Infer/SHA256SUMS new file mode 100644 index 00000000..d113db79 --- /dev/null +++ b/Verify/Infer/SHA256SUMS @@ -0,0 +1,19 @@ +673aca7661560d45057a06403d02a3a16feca2b1f637dfcee3372ec514e0e1fd Reconstruct.lean +efca9dbbff32afbb2573d138cb1e0e3a38ec56e456172a191d604ebc731b5c90 SpacerPath.lean +157f485074857d8e11eca42524f1116a2b795cc1404e90b845f989246971ae31 smt2lean_inv.py +6a4bb9a858e3e460bcfc250a2972c7b39cad4fbdc9ac845a7eba86b954416583 gen_reconstruct.sh +293cfc981e4fbd1b05d625905bdf6d92b7358bf9f0bc7dbe58e96af84f2c60ff flex-4.35-bump.diff +08369f395413723dccd13dfe9ceb297229dd514f5eac12dc501b5467e33aff3a reconstruct-4.35.axioms.txt +9141801fdacc2936d9133ffc03f3dd6dc84614a4d9ae6dcd643900a6f58794df spacerpath-4.35.out +cc3ee632f13e149b021c78b773c52a9863018b22ec6c13731500ea25f227e396 chc/counter_int.smt2 +4d40ed36d01ce06f15ffa4beabb178d857919ce05cb835121c0e69eded24a9c4 chc/counter_int.spacer.out +7040ff503425ed654fc6be72d31722d752b1918f0aaea19dd4a3c5f7e6985371 chc/counter_u256.smt2 +4d40ed36d01ce06f15ffa4beabb178d857919ce05cb835121c0e69eded24a9c4 chc/counter_u256.spacer.out +a9ca18a4324f01aa5a9db43137178ddc756ef43a2f3c8e81b877c66229496360 chc/drain_int.smt2 +c01c2caa8918b8778822d969b8635241f08b89073c0ab7b866236cb9aa496fce chc/drain_int.spacer.out +0af97cde8a836def4b7789e30bda1cd52a9b424dbae81b0d0479ca7686c18478 chc/drain_u256.smt2 +c01c2caa8918b8778822d969b8635241f08b89073c0ab7b866236cb9aa496fce chc/drain_u256.spacer.out +6e1eb36aaa4cc820b6fdf8c846cf5ef5389cd121cab826cf08086ba1fb4d8c3a chc/okwhile_int.smt2 +a294c8fda0224319cae15af3ddb21f63d69933d769fae83390c0976e7cb6384b chc/okwhile_int.spacer.out +21c65b3c859069bdd10f084da85aefdcc64753dc4f88909fd3fa3637fe1d7ceb chc/okwhile_u256.smt2 +a294c8fda0224319cae15af3ddb21f63d69933d769fae83390c0976e7cb6384b chc/okwhile_u256.spacer.out diff --git a/Verify/Infer/SpacerPath.lean b/Verify/Infer/SpacerPath.lean new file mode 100644 index 00000000..fbcd4695 --- /dev/null +++ b/Verify/Infer/SpacerPath.lean @@ -0,0 +1,64 @@ +import Flex.Tactic.Tactics.Spacer +/-! Flex's spacer path: export CHC to z3 Spacer, import its model, instantiate the invariant, + certify predicate heads (init/step) with grind; the remaining query VC (use) is closed by grind. + No invariant is written by hand. -/ +namespace FlexEval.SpacerPath + +theorem counter_int : + ∃ inv : Int → Int → Int → Int → Int → Prop, + (∀ c0 n lim, 0 ≤ c0 → 0 ≤ n → 0 ≤ lim → c0 ≤ lim → c0 + n ≤ lim → inv c0 n lim 0 c0) ∧ + (∀ c0 n lim i c, inv c0 n lim i c → i < n → inv c0 n lim (i + 1) (c + 1)) ∧ + (∀ c0 n lim i c, inv c0 n lim i c → ¬ (i < n) → c = c0 + n ∧ c ≤ lim) := by + spacer + grind + +theorem counter_u256 : + ∃ inv : Int → Int → Int → Int → Int → Prop, + (∀ c0 n lim, 0 ≤ c0 → c0 < 115792089237316195423570985008687907853269984665640564039457584007913129639936 → 0 ≤ n → n < 115792089237316195423570985008687907853269984665640564039457584007913129639936 → 0 ≤ lim → lim < 115792089237316195423570985008687907853269984665640564039457584007913129639936 → c0 ≤ lim → + 0 ≤ c0 + n → c0 + n < 115792089237316195423570985008687907853269984665640564039457584007913129639936 → c0 + n ≤ lim → inv c0 n lim 0 c0) ∧ + (∀ c0 n lim i c, inv c0 n lim i c → i < n → + 0 ≤ c + 1 → c + 1 < 115792089237316195423570985008687907853269984665640564039457584007913129639936 → 0 ≤ i + 1 → i + 1 < 115792089237316195423570985008687907853269984665640564039457584007913129639936 → inv c0 n lim (i + 1) (c + 1)) ∧ + (∀ c0 n lim i c, inv c0 n lim i c → ¬ (i < n) → c = c0 + n ∧ c ≤ lim) := by + spacer + grind + +theorem okwhile_int : + ∃ inv : Int → Int → Prop, + (∀ n, 0 ≤ n → inv n 0) ∧ + (∀ n i, inv n i → i < n → inv n (i + 1)) ∧ + (∀ n i, inv n i → ¬ (i < n) → i = n) := by + spacer + grind + +theorem okwhile_u256 : + ∃ inv : Int → Int → Prop, + (∀ n, 0 ≤ n → n < 115792089237316195423570985008687907853269984665640564039457584007913129639936 → inv n 0) ∧ + (∀ n i, inv n i → i < n → 0 ≤ i + 1 → i + 1 < 115792089237316195423570985008687907853269984665640564039457584007913129639936 → inv n (i + 1)) ∧ + (∀ n i, inv n i → ¬ (i < n) → i = n) := by + spacer + grind + +theorem drain_int : + ∃ inv : Int → Int → Int → Prop, + (∀ n, 0 ≤ n → inv n n 0) ∧ + (∀ n a b, inv n a b → a > 0 → inv n (a - 1) (b + 1)) ∧ + (∀ n a b, inv n a b → ¬ (a > 0) → b = n) := by + spacer + grind + +theorem drain_u256 : + ∃ inv : Int → Int → Int → Prop, + (∀ n, 0 ≤ n → n < 115792089237316195423570985008687907853269984665640564039457584007913129639936 → inv n n 0) ∧ + (∀ n a b, inv n a b → a > 0 → 0 ≤ a - 1 → a - 1 < 115792089237316195423570985008687907853269984665640564039457584007913129639936 → 0 ≤ b + 1 → b + 1 < 115792089237316195423570985008687907853269984665640564039457584007913129639936 → + inv n (a - 1) (b + 1)) ∧ + (∀ n a b, inv n a b → ¬ (a > 0) → b = n) := by + spacer + grind + +end FlexEval.SpacerPath +#print axioms FlexEval.SpacerPath.counter_int +#print axioms FlexEval.SpacerPath.counter_u256 +#print axioms FlexEval.SpacerPath.okwhile_int +#print axioms FlexEval.SpacerPath.okwhile_u256 +#print axioms FlexEval.SpacerPath.drain_int +#print axioms FlexEval.SpacerPath.drain_u256 diff --git a/Verify/Infer/chc/counter_int.smt2 b/Verify/Infer/chc/counter_int.smt2 new file mode 100644 index 00000000..38b66168 --- /dev/null +++ b/Verify/Infer/chc/counter_int.smt2 @@ -0,0 +1,21 @@ +; Counter.bump CHC, mathematical Int (uint params >= 0, no overflow guards) semantics +; vars: c0 = old(count), n, lim = limit, i, c = count +(set-logic HORN) +(declare-fun Inv (Int Int Int Int Int) Bool) +; init: entry state satisfies param ranges, contract invariant c0 <= lim, require(count + n <= limit) (checked add), i = 0, count = c0 +(assert (forall ((c0 Int) (n Int) (lim Int)) + (=> (and (<= 0 c0) (<= 0 n) (<= 0 lim) (<= c0 lim) + (<= (+ c0 n) lim)) + (Inv c0 n lim 0 c0)))) +; step: body count++ (checked) then i++ (checked); a reverting op drops the path +(assert (forall ((c0 Int) (n Int) (lim Int) (i Int) (c Int)) + (=> (and (Inv c0 n lim i c) (< i n) + ) + (Inv c0 n lim (+ i 1) (+ c 1))))) +; safety: on exit, ensures count == old(count) + n and contract invariant count <= limit +(assert (forall ((c0 Int) (n Int) (lim Int) (i Int) (c Int)) + (=> (and (Inv c0 n lim i c) (not (< i n)) + (not (and (= c (+ c0 n)) (<= c lim)))) + false))) +(check-sat) +(get-model) diff --git a/Verify/Infer/chc/counter_int.spacer.out b/Verify/Infer/chc/counter_int.spacer.out new file mode 100644 index 00000000..716e2ad9 --- /dev/null +++ b/Verify/Infer/chc/counter_int.spacer.out @@ -0,0 +1,9 @@ +sat +( + (define-fun Inv ((x!0 Int) (x!1 Int) (x!2 Int) (x!3 Int) (x!4 Int)) Bool + (let ((a!1 (not (<= (+ x!0 x!3 (* (- 1) x!4)) (- 1)))) + (a!2 (not (<= (+ x!0 x!1 (* (- 1) x!4)) (- 1)))) + (a!3 (not (>= (+ x!0 x!3 (* (- 1) x!4)) 1))) + (a!4 (not (>= (+ x!1 (* (- 1) x!2) (* (- 1) x!3) x!4) 1)))) + (and a!1 a!2 a!3 a!4))) +) diff --git a/Verify/Infer/chc/counter_u256.smt2 b/Verify/Infer/chc/counter_u256.smt2 new file mode 100644 index 00000000..cacc17cf --- /dev/null +++ b/Verify/Infer/chc/counter_u256.smt2 @@ -0,0 +1,21 @@ +; Counter.bump CHC, uint256 checked-arithmetic semantics +; vars: c0 = old(count), n, lim = limit, i, c = count +(set-logic HORN) +(declare-fun Inv (Int Int Int Int Int) Bool) +; init: entry state satisfies param ranges, contract invariant c0 <= lim, require(count + n <= limit) (checked add), i = 0, count = c0 +(assert (forall ((c0 Int) (n Int) (lim Int)) + (=> (and (and (<= 0 c0) (< c0 115792089237316195423570985008687907853269984665640564039457584007913129639936)) (and (<= 0 n) (< n 115792089237316195423570985008687907853269984665640564039457584007913129639936)) (and (<= 0 lim) (< lim 115792089237316195423570985008687907853269984665640564039457584007913129639936)) (<= c0 lim) + (and (<= 0 (+ c0 n)) (< (+ c0 n) 115792089237316195423570985008687907853269984665640564039457584007913129639936)) (<= (+ c0 n) lim)) + (Inv c0 n lim 0 c0)))) +; step: body count++ (checked) then i++ (checked); a reverting op drops the path +(assert (forall ((c0 Int) (n Int) (lim Int) (i Int) (c Int)) + (=> (and (Inv c0 n lim i c) (< i n) + (and (<= 0 (+ c 1)) (< (+ c 1) 115792089237316195423570985008687907853269984665640564039457584007913129639936)) (and (<= 0 (+ i 1)) (< (+ i 1) 115792089237316195423570985008687907853269984665640564039457584007913129639936))) + (Inv c0 n lim (+ i 1) (+ c 1))))) +; safety: on exit, ensures count == old(count) + n and contract invariant count <= limit +(assert (forall ((c0 Int) (n Int) (lim Int) (i Int) (c Int)) + (=> (and (Inv c0 n lim i c) (not (< i n)) + (not (and (= c (+ c0 n)) (<= c lim)))) + false))) +(check-sat) +(get-model) diff --git a/Verify/Infer/chc/counter_u256.spacer.out b/Verify/Infer/chc/counter_u256.spacer.out new file mode 100644 index 00000000..716e2ad9 --- /dev/null +++ b/Verify/Infer/chc/counter_u256.spacer.out @@ -0,0 +1,9 @@ +sat +( + (define-fun Inv ((x!0 Int) (x!1 Int) (x!2 Int) (x!3 Int) (x!4 Int)) Bool + (let ((a!1 (not (<= (+ x!0 x!3 (* (- 1) x!4)) (- 1)))) + (a!2 (not (<= (+ x!0 x!1 (* (- 1) x!4)) (- 1)))) + (a!3 (not (>= (+ x!0 x!3 (* (- 1) x!4)) 1))) + (a!4 (not (>= (+ x!1 (* (- 1) x!2) (* (- 1) x!3) x!4) 1)))) + (and a!1 a!2 a!3 a!4))) +) diff --git a/Verify/Infer/chc/drain_int.smt2 b/Verify/Infer/chc/drain_int.smt2 new file mode 100644 index 00000000..6d260420 --- /dev/null +++ b/Verify/Infer/chc/drain_int.smt2 @@ -0,0 +1,10 @@ +; Drain.drain (a = n; b = 0; while (a > 0) { a--; b++; } return b; ensures result == n) CHC, mathematical Int (uint param >= 0, no overflow guards) semantics +(set-logic HORN) +(declare-fun Inv (Int Int Int) Bool) +(assert (forall ((n Int)) (=> (<= 0 n) (Inv n n 0)))) +(assert (forall ((n Int) (a Int) (b Int)) + (=> (and (Inv n a b) (> a 0) ) (Inv n (- a 1) (+ b 1))))) +(assert (forall ((n Int) (a Int) (b Int)) + (=> (and (Inv n a b) (not (> a 0)) (not (= b n))) false))) +(check-sat) +(get-model) diff --git a/Verify/Infer/chc/drain_int.spacer.out b/Verify/Infer/chc/drain_int.spacer.out new file mode 100644 index 00000000..f0a0494d --- /dev/null +++ b/Verify/Infer/chc/drain_int.spacer.out @@ -0,0 +1,8 @@ +sat +( + (define-fun Inv ((x!0 Int) (x!1 Int) (x!2 Int)) Bool + (let ((a!1 (not (<= (+ x!0 (* (- 1) x!1) (* (- 1) x!2)) (- 1)))) + (a!2 (not (<= (+ x!0 (* (- 1) x!2)) (- 1)))) + (a!3 (not (>= (+ x!0 (* (- 1) x!1) (* (- 1) x!2)) 1)))) + (and a!1 a!2 a!3))) +) diff --git a/Verify/Infer/chc/drain_u256.smt2 b/Verify/Infer/chc/drain_u256.smt2 new file mode 100644 index 00000000..bc04675a --- /dev/null +++ b/Verify/Infer/chc/drain_u256.smt2 @@ -0,0 +1,10 @@ +; Drain.drain (a = n; b = 0; while (a > 0) { a--; b++; } return b; ensures result == n) CHC, uint256 checked-arithmetic semantics +(set-logic HORN) +(declare-fun Inv (Int Int Int) Bool) +(assert (forall ((n Int)) (=> (and (<= 0 n) (< n 115792089237316195423570985008687907853269984665640564039457584007913129639936)) (Inv n n 0)))) +(assert (forall ((n Int) (a Int) (b Int)) + (=> (and (Inv n a b) (> a 0) (and (<= 0 (- a 1)) (< (- a 1) 115792089237316195423570985008687907853269984665640564039457584007913129639936)) (and (<= 0 (+ b 1)) (< (+ b 1) 115792089237316195423570985008687907853269984665640564039457584007913129639936))) (Inv n (- a 1) (+ b 1))))) +(assert (forall ((n Int) (a Int) (b Int)) + (=> (and (Inv n a b) (not (> a 0)) (not (= b n))) false))) +(check-sat) +(get-model) diff --git a/Verify/Infer/chc/drain_u256.spacer.out b/Verify/Infer/chc/drain_u256.spacer.out new file mode 100644 index 00000000..f0a0494d --- /dev/null +++ b/Verify/Infer/chc/drain_u256.spacer.out @@ -0,0 +1,8 @@ +sat +( + (define-fun Inv ((x!0 Int) (x!1 Int) (x!2 Int)) Bool + (let ((a!1 (not (<= (+ x!0 (* (- 1) x!1) (* (- 1) x!2)) (- 1)))) + (a!2 (not (<= (+ x!0 (* (- 1) x!2)) (- 1)))) + (a!3 (not (>= (+ x!0 (* (- 1) x!1) (* (- 1) x!2)) 1)))) + (and a!1 a!2 a!3))) +) diff --git a/Verify/Infer/chc/okwhile_int.smt2 b/Verify/Infer/chc/okwhile_int.smt2 new file mode 100644 index 00000000..60a1a33f --- /dev/null +++ b/Verify/Infer/chc/okwhile_int.smt2 @@ -0,0 +1,10 @@ +; Control.ok_no_invariant (ok_while) CHC, mathematical Int (uint param >= 0, no overflow guards) semantics +(set-logic HORN) +(declare-fun Inv (Int Int) Bool) +(assert (forall ((n Int)) (=> (<= 0 n) (Inv n 0)))) +(assert (forall ((n Int) (i Int)) + (=> (and (Inv n i) (< i n) ) (Inv n (+ i 1))))) +(assert (forall ((n Int) (i Int)) + (=> (and (Inv n i) (not (< i n)) (not (= i n))) false))) +(check-sat) +(get-model) diff --git a/Verify/Infer/chc/okwhile_int.spacer.out b/Verify/Infer/chc/okwhile_int.spacer.out new file mode 100644 index 00000000..1442c652 --- /dev/null +++ b/Verify/Infer/chc/okwhile_int.spacer.out @@ -0,0 +1,5 @@ +sat +( + (define-fun Inv ((x!0 Int) (x!1 Int)) Bool + (not (<= (+ x!0 (* (- 1) x!1)) (- 1)))) +) diff --git a/Verify/Infer/chc/okwhile_u256.smt2 b/Verify/Infer/chc/okwhile_u256.smt2 new file mode 100644 index 00000000..4967d69e --- /dev/null +++ b/Verify/Infer/chc/okwhile_u256.smt2 @@ -0,0 +1,10 @@ +; Control.ok_no_invariant (ok_while) CHC, uint256 checked-arithmetic semantics +(set-logic HORN) +(declare-fun Inv (Int Int) Bool) +(assert (forall ((n Int)) (=> (and (<= 0 n) (< n 115792089237316195423570985008687907853269984665640564039457584007913129639936)) (Inv n 0)))) +(assert (forall ((n Int) (i Int)) + (=> (and (Inv n i) (< i n) (and (<= 0 (+ i 1)) (< (+ i 1) 115792089237316195423570985008687907853269984665640564039457584007913129639936))) (Inv n (+ i 1))))) +(assert (forall ((n Int) (i Int)) + (=> (and (Inv n i) (not (< i n)) (not (= i n))) false))) +(check-sat) +(get-model) diff --git a/Verify/Infer/chc/okwhile_u256.spacer.out b/Verify/Infer/chc/okwhile_u256.spacer.out new file mode 100644 index 00000000..1442c652 --- /dev/null +++ b/Verify/Infer/chc/okwhile_u256.spacer.out @@ -0,0 +1,5 @@ +sat +( + (define-fun Inv ((x!0 Int) (x!1 Int)) Bool + (not (<= (+ x!0 (* (- 1) x!1)) (- 1)))) +) diff --git a/Verify/Infer/flex-4.35-bump.diff b/Verify/Infer/flex-4.35-bump.diff new file mode 100644 index 00000000..ed2760eb --- /dev/null +++ b/Verify/Infer/flex-4.35-bump.diff @@ -0,0 +1,216 @@ +diff --git a/lake-manifest.json b/lake-manifest.json +index 30aaa280..e05df5e1 100644 +--- a/lake-manifest.json ++++ b/lake-manifest.json +@@ -1,7 +1,17 @@ +-{"version": "1.2.0", ++{"version": "1.3.0", + "packagesDir": ".lake/packages", + "packages": +- [{"url": "https://github.com/LeanHorn/SMTLib-to-Lean.git", ++ [{"url": "https://github.com/leanprover-community/mathlib4", ++ "type": "git", ++ "subDir": null, ++ "scope": "", ++ "rev": "56a005855ea17e0b0958f73ec801ae140b0a1679", ++ "name": "mathlib", ++ "manifestFile": "lake-manifest.json", ++ "inputRev": "v4.35.0", ++ "inherited": false, ++ "configFile": "lakefile.lean"}, ++ {"url": "https://github.com/LeanHorn/SMTLib-to-Lean.git", + "type": "git", + "subDir": null, + "scope": "", +@@ -11,71 +21,51 @@ + "inputRev": "89667053aa420284b6794b6d6caabd551c1f7c79", + "inherited": false, + "configFile": "lakefile.toml"}, +- {"url": "https://github.com/ufmg-smite/lean-smt.git", ++ {"url": "https://github.com/abdoo8080/lean-cvc5.git", + "type": "git", + "subDir": null, + "scope": "", +- "rev": "79ef7b3d5e06608d031d75b6d015949b90016875", +- "name": "smt", ++ "rev": "d19a134c237ec7f0cb86c2027062eedeb577a9a9", ++ "name": "cvc5", + "manifestFile": "lake-manifest.json", +- "inputRev": "79ef7b3d5e06608d031d75b6d015949b90016875", ++ "inputRev": "d19a134c237ec7f0cb86c2027062eedeb577a9a9", + "inherited": false, + "configFile": "lakefile.lean"}, +- {"url": "https://github.com/leanprover-community/lean-auto.git", ++ {"url": "https://github.com/ufmg-smite/lean-smt.git", + "type": "git", + "subDir": null, + "scope": "", +- "rev": "92d628ba41801bd12c9d81f9be12fde97f0ad177", +- "name": "auto", ++ "rev": "cbec5bd226c79d80ce0c2d2ea28e1e6359c5f207", ++ "name": "smt", + "manifestFile": "lake-manifest.json", +- "inputRev": "92d628ba41801bd12c9d81f9be12fde97f0ad177", ++ "inputRev": "cbec5bd226c79d80ce0c2d2ea28e1e6359c5f207", + "inherited": false, + "configFile": "lakefile.lean"}, +- {"url": "https://github.com/leanprover-community/aesop", ++ {"url": "https://github.com/leanprover-community/lean-auto.git", + "type": "git", + "subDir": null, + "scope": "", +- "rev": "355695d523e41d0554926416cba2a2b3544fbbc9", +- "name": "aesop", ++ "rev": "30f46ddb9a68d6878f5a1337eb2565ba4e70126b", ++ "name": "auto", + "manifestFile": "lake-manifest.json", +- "inputRev": "355695d523e41d0554926416cba2a2b3544fbbc9", ++ "inputRev": "v4.35.0", + "inherited": false, +- "configFile": "lakefile.toml"}, +- {"url": "https://github.com/leanprover-community/mathlib4.git", +- "type": "git", +- "subDir": null, +- "scope": "", +- "rev": "5ed2965256430c3649e86755f9576b54eca72435", +- "name": "mathlib", +- "manifestFile": "lake-manifest.json", +- "inputRev": "v4.34.0", +- "inherited": true, + "configFile": "lakefile.lean"}, +- {"url": "https://github.com/abdoo8080/lean-cvc5.git", ++ {"url": "https://github.com/leanprover-community/aesop", + "type": "git", + "subDir": null, + "scope": "", +- "rev": "41e47796d4d15712e6064b064ca5d251a1283955", +- "name": "cvc5", ++ "rev": "4a174c490d8707121c4a9290800489f105d85e07", ++ "name": "aesop", + "manifestFile": "lake-manifest.json", +- "inputRev": "41e47796d4d15712e6064b064ca5d251a1283955", ++ "inputRev": "v4.35.0", + "inherited": false, +- "configFile": "lakefile.lean"}, +- {"url": "https://github.com/leanprover-community/batteries", +- "type": "git", +- "subDir": null, +- "scope": "leanprover-community", +- "rev": "f2effa3d803fda822b1f97b806c47cf2adfbcbc2", +- "name": "batteries", +- "manifestFile": "lake-manifest.json", +- "inputRev": "main", +- "inherited": true, + "configFile": "lakefile.toml"}, + {"url": "https://github.com/leanprover-community/plausible", + "type": "git", + "subDir": null, + "scope": "leanprover-community", +- "rev": "118aa17ee84656b8bd727fef7c458ee8c833385c", ++ "rev": "dfa4f38190d07c37e315953e08b90fe2d95b3c24", + "name": "plausible", + "manifestFile": "lake-manifest.json", + "inputRev": "main", +@@ -85,7 +75,7 @@ + "type": "git", + "subDir": null, + "scope": "leanprover-community", +- "rev": "ddf04cf3949fa556442341e87d47f9f6e6074707", ++ "rev": "d6b4c7be5be75ec4917c873ac50c756dc1436372", + "name": "LeanSearchClient", + "manifestFile": "lake-manifest.json", + "inputRev": "main", +@@ -95,7 +85,7 @@ + "type": "git", + "subDir": null, + "scope": "leanprover-community", +- "rev": "e928b72544873815af278d38681b31c0293588e3", ++ "rev": "a41f0e9a4dea23188ea9cc1c41ac9f8bbafe0b93", + "name": "importGraph", + "manifestFile": "lake-manifest.json", + "inputRev": "main", +@@ -105,7 +95,7 @@ + "type": "git", + "subDir": null, + "scope": "leanprover-community", +- "rev": "106ff4fafc74ef4ac99d81dbf3ab399118f497a5", ++ "rev": "df72b022e558978a1c50264cfc4d7fec86fa8e04", + "name": "proofwidgets", + "manifestFile": "lake-manifest.json", + "inputRev": "main", +@@ -115,20 +105,30 @@ + "type": "git", + "subDir": null, + "scope": "leanprover-community", +- "rev": "6a489d9af5d0c47e5b259e2e8bcdfc1811b5a259", ++ "rev": "dce0ad79c486cb1fb504af04f953c3466b0c6db8", + "name": "Qq", + "manifestFile": "lake-manifest.json", + "inputRev": "master", + "inherited": true, + "configFile": "lakefile.toml"}, ++ {"url": "https://github.com/leanprover-community/batteries", ++ "type": "git", ++ "subDir": null, ++ "scope": "leanprover-community", ++ "rev": "66e469188fe07963e5cf666c7d4433f45b8131c5", ++ "name": "batteries", ++ "manifestFile": "lake-manifest.json", ++ "inputRev": "main", ++ "inherited": true, ++ "configFile": "lakefile.toml"}, + {"url": "https://github.com/leanprover/lean4-cli", + "type": "git", + "subDir": null, + "scope": "leanprover", +- "rev": "e92c9f15fdfacc8536f31cfb3b7ad26c3c8cd204", ++ "rev": "c24fe6078c630e89b489bffe59b3e20ac30d12c8", + "name": "Cli", + "manifestFile": "lake-manifest.json", +- "inputRev": "v4.34.0", ++ "inputRev": "v4.35.0", + "inherited": true, + "configFile": "lakefile.toml"}], + "name": "Flex", +diff --git a/lakefile.lean b/lakefile.lean +index 2a8d92ac..bccb3cf2 100644 +--- a/lakefile.lean ++++ b/lakefile.lean +@@ -10,21 +10,26 @@ package «Flex» where + -- mathlib as a transitive package dependency but its `Smt` import does not use it. + -- Keep these pins aligned with lean-smt's Lean v4.34.0 dependency set. + require aesop from git +- "https://github.com/leanprover-community/aesop" @ "355695d523e41d0554926416cba2a2b3544fbbc9" ++ "https://github.com/leanprover-community/aesop" @ "v4.35.0" + + require auto from git +- "https://github.com/leanprover-community/lean-auto.git" @ "92d628ba41801bd12c9d81f9be12fde97f0ad177" ++ "https://github.com/leanprover-community/lean-auto.git" @ "v4.35.0" + + require smt from git +- "https://github.com/ufmg-smite/lean-smt.git" @ "79ef7b3d5e06608d031d75b6d015949b90016875" ++ "https://github.com/ufmg-smite/lean-smt.git" @ "cbec5bd226c79d80ce0c2d2ea28e1e6359c5f207" + + -- CHC model import uses the same cvc5 parser as the SMT integration. + require cvc5 from git +- "https://github.com/abdoo8080/lean-cvc5.git" @ "41e47796d4d15712e6064b064ca5d251a1283955" ++ "https://github.com/abdoo8080/lean-cvc5.git" @ "d19a134c237ec7f0cb86c2027062eedeb577a9a9" + + require smt2lean from git + "https://github.com/LeanHorn/SMTLib-to-Lean.git" @ "89667053aa420284b6794b6d6caabd551c1f7c79" + ++-- flex-eval: pin mathlib to the v4.35.0 tag; declared last so Lake resolves it first ++-- (otherwise smt2lean's manifest drags in mathlib v4.33.0 and its deps). ++require mathlib from git ++ "https://github.com/leanprover-community/mathlib4" @ "v4.35.0" ++ + @[default_target] + lean_lib «Flex» where + +diff --git a/lean-toolchain b/lean-toolchain +index 12359f92..a6aff065 100644 +--- a/lean-toolchain ++++ b/lean-toolchain +@@ -1 +1 @@ +-leanprover/lean4:v4.34.0 ++leanprover/lean4:v4.35.0 diff --git a/Verify/Infer/gen_reconstruct.sh b/Verify/Infer/gen_reconstruct.sh new file mode 100755 index 00000000..86e0c072 --- /dev/null +++ b/Verify/Infer/gen_reconstruct.sh @@ -0,0 +1,82 @@ +#!/bin/sh +# Generates Reconstruct.lean: invariants pasted mechanically from z3 Spacer models; CHC clauses as stated in chc/*.smt2. +set -eu +cd "$(dirname "$0")" +W=115792089237316195423570985008687907853269984665640564039457584007913129639936 +out=Reconstruct.lean +{ +echo '/-! Kernel-checked initiation / preservation / use for the three loops.' +echo ' Each Inv_* below is generated by smt2lean_inv.py from the z3 Spacer model, unedited.' +echo ' Only Lean core is imported (no Flex, no Mathlib). -/' +echo 'namespace FlexEval' +echo +for v in counter_int counter_u256 okwhile_int okwhile_u256 drain_int drain_u256; do + python3 smt2lean_inv.py chc/$v.spacer.out Inv_$v; echo +done +cat < 0 → Inv_drain_int n (a - 1) (b + 1) := by + intros; simp only [Inv_drain_int] at *; omega +theorem drain_int_use : ∀ n a b : Int, Inv_drain_int n a b → ¬ (a > 0) → b = n := by + intros; simp only [Inv_drain_int] at *; omega + +theorem drain_u256_init : ∀ n : Int, 0 ≤ n → n < $W → Inv_drain_u256 n n 0 := by + intros; simp only [Inv_drain_u256]; omega +theorem drain_u256_pres : ∀ n a b : Int, Inv_drain_u256 n a b → a > 0 → + 0 ≤ a - 1 → a - 1 < $W → 0 ≤ b + 1 → b + 1 < $W → Inv_drain_u256 n (a - 1) (b + 1) := by + intros; simp only [Inv_drain_u256] at *; omega +theorem drain_u256_use : ∀ n a b : Int, Inv_drain_u256 n a b → ¬ (a > 0) → b = n := by + intros; simp only [Inv_drain_u256] at *; omega + +end FlexEval +EOF +for v in counter_int counter_u256 okwhile_int okwhile_u256 drain_int drain_u256; do + for k in init pres use; do echo "#print axioms FlexEval.${v}_$k"; done +done +} > $out +echo generated $out diff --git a/Verify/Infer/reconstruct-4.35.axioms.txt b/Verify/Infer/reconstruct-4.35.axioms.txt new file mode 100644 index 00000000..5b420058 --- /dev/null +++ b/Verify/Infer/reconstruct-4.35.axioms.txt @@ -0,0 +1,18 @@ +'FlexEval.counter_int_init' depends on axioms: [propext, Classical.choice, Quot.sound] +'FlexEval.counter_int_pres' depends on axioms: [propext, Classical.choice, Quot.sound] +'FlexEval.counter_int_use' depends on axioms: [propext, Classical.choice, Quot.sound] +'FlexEval.counter_u256_init' depends on axioms: [propext, Classical.choice, Quot.sound] +'FlexEval.counter_u256_pres' depends on axioms: [propext, Classical.choice, Quot.sound] +'FlexEval.counter_u256_use' depends on axioms: [propext, Classical.choice, Quot.sound] +'FlexEval.okwhile_int_init' depends on axioms: [propext, Quot.sound] +'FlexEval.okwhile_int_pres' depends on axioms: [propext, Quot.sound] +'FlexEval.okwhile_int_use' depends on axioms: [propext, Quot.sound] +'FlexEval.okwhile_u256_init' depends on axioms: [propext, Quot.sound] +'FlexEval.okwhile_u256_pres' depends on axioms: [propext, Quot.sound] +'FlexEval.okwhile_u256_use' depends on axioms: [propext, Quot.sound] +'FlexEval.drain_int_init' depends on axioms: [propext, Classical.choice, Quot.sound] +'FlexEval.drain_int_pres' depends on axioms: [propext, Classical.choice, Quot.sound] +'FlexEval.drain_int_use' depends on axioms: [propext, Quot.sound] +'FlexEval.drain_u256_init' depends on axioms: [propext, Classical.choice, Quot.sound] +'FlexEval.drain_u256_pres' depends on axioms: [propext, Classical.choice, Quot.sound] +'FlexEval.drain_u256_use' depends on axioms: [propext, Quot.sound] diff --git a/Verify/Infer/smt2lean_inv.py b/Verify/Infer/smt2lean_inv.py new file mode 100644 index 00000000..d3c26837 --- /dev/null +++ b/Verify/Infer/smt2lean_inv.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +"""Mechanical translation of a z3 Spacer model (define-fun Inv ...) into a Lean 4 def. +No simplification or editing: each SMT-LIB operator maps 1:1 to a Lean operator, let stays let.""" +import sys, re + +def tokenize(s): + return re.findall(r'\(|\)|[^\s()]+', s) + +def parse(toks, i=0): + if toks[i] == '(': + out = []; i += 1 + while toks[i] != ')': + x, i = parse(toks, i); out.append(x) + return out, i + 1 + return toks[i], i + 1 + +def ident(x): + return x.replace('!', '_') + +def is_bool(v): + return isinstance(v, list) and v[0] in ('not', 'and', 'or', '=>', '<=', '>=', '<', '>', '=') + +def lean(e): + if isinstance(e, str): + if re.fullmatch(r'\d+', e): return '(' + e + ' : Int)' + if e == 'true': return 'True' + if e == 'false': return 'False' + return ident(e) + op, *args = e + if op == 'let': + binds, body = args + s = lean(body) + for name, val in reversed(binds): + ty = 'Prop' if is_bool(val) else 'Int' + s = '(let ' + ident(name) + ' : ' + ty + ' := ' + lean(val) + '; ' + s + ')' + return s + a = [lean(x) for x in args] + if op == 'not': return '(¬ ' + a[0] + ')' + if op == 'and': return '(' + ' ∧ '.join(a) + ')' if a else 'True' + if op == 'or': return '(' + ' ∨ '.join(a) + ')' if a else 'False' + if op == '=>': return '(' + a[0] + ' → ' + a[1] + ')' + if op == '-' and len(a) == 1: return '(-' + a[0] + ')' + if op in ('+', '-', '*'): return '(' + (' ' + op + ' ').join(a) + ')' + if op in ('<=', '>=', '<', '>'): + m = {'<=': '≤', '>=': '≥', '<': '<', '>': '>'}[op] + return '(' + a[0] + ' ' + m + ' ' + a[1] + ')' + if op == '=': return '(' + a[0] + ' = ' + a[1] + ')' + if op == 'ite': return '(if ' + a[0] + ' then ' + a[1] + ' else ' + a[2] + ')' + raise SystemExit('unsupported operator: ' + op) + +text = open(sys.argv[1]).read() +name = sys.argv[2] +toks = tokenize(text[text.index('(define-fun'):]) +d, _ = parse(toks) +_, fname, params, ret, body = d +binders = ' '.join('(' + ident(p) + ' : Int)' for p, _t in params) +print('/-- Verbatim from ' + sys.argv[1] + ' (z3 Spacer model for ' + fname + '). -/') +print('def ' + name + ' ' + binders + ' : Prop :=') +print(' ' + lean(body)) diff --git a/Verify/Infer/spacerpath-4.35.out b/Verify/Infer/spacerpath-4.35.out new file mode 100644 index 00000000..ca95dd61 --- /dev/null +++ b/Verify/Infer/spacerpath-4.35.out @@ -0,0 +1,21 @@ +spacer: instantiated invariants + inv := fun (a a_1 a_2 a_3 a_4 : Int) => + ¬a + a_3 + -1 * a_4 ≤ -1 ∧ ¬1 ≤ a + a_3 + -1 * a_4 ∧ ¬a + a_1 + -1 * a_4 ≤ -1 ∧ ¬1 ≤ a_1 + -1 * a_2 + -1 * a_3 + a_4 +spacer: instantiated invariants + inv := fun (a a_1 a_2 a_3 a_4 : Int) => + ¬a + a_3 + -1 * a_4 ≤ -1 ∧ ¬a + a_1 + -1 * a_4 ≤ -1 ∧ ¬1 ≤ a + a_3 + -1 * a_4 ∧ ¬1 ≤ a_1 + -1 * a_2 + -1 * a_3 + a_4 +spacer: instantiated invariants + inv := fun (a a_1 : Int) => ¬a + -1 * a_1 ≤ -1 +spacer: instantiated invariants + inv := fun (a a_1 : Int) => ¬a + -1 * a_1 ≤ -1 +spacer: instantiated invariants + inv := fun (a a_1 a_2 : Int) => ¬a + -1 * a_1 + -1 * a_2 ≤ -1 ∧ ¬a + -1 * a_2 ≤ -1 ∧ ¬1 ≤ a + -1 * a_1 + -1 * a_2 +spacer: instantiated invariants + inv := fun (a a_1 a_2 : Int) => ¬a + -1 * a_1 + -1 * a_2 ≤ -1 ∧ ¬a + -1 * a_2 ≤ -1 ∧ ¬1 ≤ a + -1 * a_1 + -1 * a_2 +'FlexEval.SpacerPath.counter_int' depends on axioms: [propext, Classical.choice, Quot.sound] +'FlexEval.SpacerPath.counter_u256' depends on axioms: [propext, Classical.choice, Quot.sound] +'FlexEval.SpacerPath.okwhile_int' depends on axioms: [propext, Classical.choice, Quot.sound] +'FlexEval.SpacerPath.okwhile_u256' depends on axioms: [propext, Classical.choice, Quot.sound] +'FlexEval.SpacerPath.drain_int' depends on axioms: [propext, Classical.choice, Quot.sound] +'FlexEval.SpacerPath.drain_u256' depends on axioms: [propext, Classical.choice, Quot.sound] +wall=3.52 s maxrss=1950308 KB