Skip to content

Commit 06e4ee7

Browse files
authored
Merge pull request #1776 from GaloisInc/saw-core-coq/lia-support-take-two
`saw-core-coq`: Rudimentary `lia` support for bitvectors
2 parents a636afc + 05ce949 commit 06e4ee7

16 files changed

+589
-156
lines changed

heapster-saw/examples/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ rust_lifetimes.bc: rust_lifetimes.rs
3434
rustc --crate-type=lib --emit=llvm-bc rust_lifetimes.rs
3535

3636
# Lists all the Mr Solver tests, without their ".saw" suffix
37-
MR_SOLVER_TESTS = arrays_mr_solver linked_list_mr_solver sha512_mr_solver
37+
MR_SOLVER_TESTS = # arrays_mr_solver linked_list_mr_solver sha512_mr_solver
3838

3939
.PHONY: mr-solver-tests $(MR_SOLVER_TESTS)
4040
mr-solver-tests: $(MR_SOLVER_TESTS)

heapster-saw/examples/arrays_proofs.v

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Proof.
4141
there are multiple. For this poof though, it doesn't. *)
4242
all: try assumption.
4343
(* Proving that the loop invariant holds inductively: *)
44+
- discriminate e_maybe.
4445
- transitivity a2.
4546
+ assumption.
4647
+ apply isBvsle_suc_r; eauto.
@@ -251,6 +252,7 @@ Proof.
251252
rewrite <- e_assuming; reflexivity.
252253
- (* (e_if4 is a contradiction) *)
253254
admit.
255+
- admit.
254256
- rewrite e_assuming.
255257
change (intToBv 64 2) with (bvAdd 64 (intToBv 64 1) (intToBv 64 1)).
256258
rewrite <- bvAdd_assoc.

heapster-saw/examples/linked_list_proofs.v

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ Section any.
169169
(returnM (intToBv 64 0))
170170
(fun y l' rec =>
171171
f y >>= fun call_ret_val =>
172-
if not (bvEq 64 call_ret_val (intToBv 64 0))
172+
if negb (bvEq 64 call_ret_val (intToBv 64 0))
173173
then returnM (intToBv 64 1) else rec).
174174

175175
Lemma any_fun_ref : refinesFun any any_fun.

saw-core-coq/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
*.v.d
44
*.vok
55
*.vos
6+
.lia.cache

saw-core-coq/coq/_CoqProject

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ handwritten/CryptolToCoq/CompMExtra.v
99
handwritten/CryptolToCoq/CoqVectorsExtra.v
1010
handwritten/CryptolToCoq/CryptolPrimitivesForSAWCoreExtra.v
1111
handwritten/CryptolToCoq/SAWCoreBitvectors.v
12+
handwritten/CryptolToCoq/SAWCoreBitvectorsZifyU64.v
1213
handwritten/CryptolToCoq/SAWCorePrelude_proofs.v
1314
handwritten/CryptolToCoq/SAWCorePreludeExtra.v
1415
handwritten/CryptolToCoq/SAWCoreScaffolding.v

saw-core-coq/coq/handwritten/CryptolToCoq/CompMExtra.v

+4-7
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,12 @@ Tactic Notation "dependent" "destruction" ident(H) :=
2323
(* match goal with H: _ |- _ => constr:(H) end. *)
2424

2525
Tactic Notation "unfold_projs" :=
26-
unfold SAWCoreScaffolding.fst, SAWCoreScaffolding.snd;
2726
cbn [ Datatypes.fst Datatypes.snd projT1 ].
2827

2928
Tactic Notation "unfold_projs" "in" constr(N) :=
30-
unfold SAWCoreScaffolding.fst, SAWCoreScaffolding.snd in N;
3129
cbn [ Datatypes.fst Datatypes.snd projT1 ] in N.
3230

3331
Tactic Notation "unfold_projs" "in" "*" :=
34-
unfold SAWCoreScaffolding.fst, SAWCoreScaffolding.snd in *;
3532
cbn [ Datatypes.fst Datatypes.snd projT1 ] in *.
3633

3734
Ltac split_prod_hyps :=
@@ -769,11 +766,11 @@ Hint Extern 999 (refinesFun _ _) => shelve : refinesFun.
769766

770767
Definition refinesFun_multiFixM_fst' lrt (F:lrtPi (LRT_Cons lrt LRT_Nil)
771768
(lrtTupleType (LRT_Cons lrt LRT_Nil))) f
772-
(ref_f:refinesFun (SAWCoreScaffolding.fst (F f)) f) :
769+
(ref_f:refinesFun (fst (F f)) f) :
773770
refinesFun (fst (multiFixM F)) f := refinesFun_multiFixM_fst lrt F f ref_f.
774771

775772
Definition refinesFun_fst lrt B f1 (fs:B) f2 (r:@refinesFun lrt f1 f2) :
776-
refinesFun (SAWCoreScaffolding.fst (f1, fs)) f2 := r.
773+
refinesFun (fst (f1, fs)) f2 := r.
777774

778775
Hint Resolve refinesFun_fst | 1 : refinesFun.
779776
Hint Resolve refinesFun_multiFixM_fst' | 1 : refinesFun.
@@ -849,7 +846,7 @@ Ltac prove_refinement_core := prove_refinement_core with Default.
849846
form` P |= Q`, where P,Q may contain matching calls to `letRecM`. *)
850847

851848
Tactic Notation "prove_refinement" "with" constr(opts) :=
852-
unfold_projs; unfold Eq, Refl, SAWCoreScaffolding.Bool;
849+
unfold_projs;
853850
apply StartAutomation_fold;
854851
prove_refinement_core with opts.
855852

@@ -951,7 +948,7 @@ Module CompMExtraNotation.
951948
Declare Scope fun_syntax.
952949

953950

954-
Infix "&&" := SAWCoreScaffolding.and : fun_syntax.
951+
Infix "&&" := andb : fun_syntax.
955952
Infix "<=" := (SAWCoreVectorsAsCoqVectors.bvsle _) : fun_syntax.
956953
Notation " a <P b" := (SAWCorePrelude.bvultWithProof _ a b) (at level 98) : fun_syntax.
957954
Notation " a == b" := (SAWCorePrelude.bvEq _ a b) (at level 100) : fun_syntax.

saw-core-coq/coq/handwritten/CryptolToCoq/CryptolPrimitivesForSAWCoreExtra.v

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ Import ListNotations.
1818
(** It is annoying to have to wrap natural numbers into [TCNum] to use them at
1919
type [Num], so these coercions will do it for us.
2020
*)
21-
Coercion TCNum : Nat >-> Num.
21+
Coercion TCNum : nat >-> Num.
2222
Definition natToNat (n : nat) : Nat := n.
2323
Coercion natToNat : nat >-> Nat.
2424

25-
Theorem Eq_TCNum a b : a = b -> Eq _ (TCNum a) (TCNum b).
25+
Theorem Eq_TCNum a b : a = b -> eq (TCNum a) (TCNum b).
2626
Proof.
2727
intros EQ.
2828
apply f_equal.

saw-core-coq/coq/handwritten/CryptolToCoq/SAWCoreBitvectors.v

+24-35
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Ltac compute_bv_funs_tac H t compute_bv_binrel compute_bv_binop
8383

8484
Ltac unfold_bv_funs := unfold bvNat, bvultWithProof, bvuleWithProof,
8585
bvsge, bvsgt, bvuge, bvugt, bvSCarry, bvSBorrow,
86-
xor, xorb.
86+
xorb.
8787

8888
Tactic Notation "compute_bv_funs" :=
8989
unfold_bv_funs;
@@ -354,15 +354,15 @@ Proof. holds_for_bits_up_to_3. Qed.
354354
(** Lemmas about bitvector xor **)
355355

356356
Lemma bvXor_same n x :
357-
SAWCorePrelude.bvXor n x x = SAWCorePrelude.replicate n Bool false.
357+
SAWCorePrelude.bvXor n x x = SAWCorePrelude.replicate n bool false.
358358
Proof.
359359
unfold SAWCorePrelude.bvXor, SAWCorePrelude.bvZipWith, SAWCorePrelude.zipWith, SAWCorePrelude.replicate.
360360
induction x; auto; simpl; f_equal; auto.
361361
rewrite SAWCorePrelude.xor_same; auto.
362362
Qed.
363363

364364
Lemma bvXor_zero n x :
365-
SAWCorePrelude.bvXor n x (SAWCorePrelude.replicate n Bool false) = x.
365+
SAWCorePrelude.bvXor n x (SAWCorePrelude.replicate n bool false) = x.
366366
Proof.
367367
unfold SAWCorePrelude.bvXor, SAWCorePrelude.bvZipWith, SAWCorePrelude.zipWith, SAWCorePrelude.replicate.
368368
induction x; auto; simpl. f_equal; auto; cbn.
@@ -375,7 +375,7 @@ Lemma bvXor_assoc n x y z :
375375
Proof.
376376
unfold SAWCorePrelude.bvXor, SAWCorePrelude.bvZipWith, SAWCorePrelude.zipWith.
377377
induction n; auto; simpl. f_equal; auto; cbn.
378-
unfold xor. rewrite Bool.xorb_assoc_reverse. reflexivity.
378+
rewrite Bool.xorb_assoc_reverse. reflexivity.
379379
remember (S n).
380380
destruct x; try solve [inversion Heqn0; clear Heqn0; subst]. injection Heqn0.
381381
destruct y; try solve [inversion Heqn0; clear Heqn0; subst]. injection Heqn0.
@@ -388,7 +388,7 @@ Lemma bvXor_comm n x y :
388388
Proof.
389389
unfold SAWCorePrelude.bvXor, SAWCorePrelude.bvZipWith, SAWCorePrelude.zipWith.
390390
induction n; auto; simpl. f_equal; auto; cbn.
391-
unfold xor. apply Bool.xorb_comm.
391+
apply Bool.xorb_comm.
392392
remember (S n).
393393
destruct x; try solve [inversion Heqn0; clear Heqn0; subst]. injection Heqn0.
394394
destruct y; try solve [inversion Heqn0; clear Heqn0; subst]. injection Heqn0.
@@ -407,46 +407,46 @@ Proof. split; destruct a, b; easy. Qed.
407407
Lemma boolEq_refl a : boolEq a a = true.
408408
Proof. destruct a; easy. Qed.
409409

410-
Lemma and_bool_eq_true b c : and b c = true <-> (b = true) /\ (c = true).
410+
Lemma and_bool_eq_true b c : andb b c = true <-> (b = true) /\ (c = true).
411411
Proof.
412412
split.
413413
- destruct b, c; auto.
414414
- intro; destruct H; destruct b, c; auto.
415415
Qed.
416416

417-
Lemma and_bool_eq_false b c : and b c = false <-> (b = false) \/ (c = false).
417+
Lemma and_bool_eq_false b c : andb b c = false <-> (b = false) \/ (c = false).
418418
Proof.
419419
split.
420420
- destruct b, c; auto.
421421
- intro; destruct H; destruct b, c; auto.
422422
Qed.
423423

424-
Lemma or_bool_eq_true b c : or b c = true <-> (b = true) \/ (c = true).
424+
Lemma or_bool_eq_true b c : orb b c = true <-> (b = true) \/ (c = true).
425425
Proof.
426426
split.
427427
- destruct b, c; auto.
428428
- intro; destruct H; destruct b, c; auto.
429429
Qed.
430430

431-
Lemma or_bool_eq_false b c : or b c = false <-> (b = false) /\ (c = false).
431+
Lemma or_bool_eq_false b c : orb b c = false <-> (b = false) /\ (c = false).
432432
Proof.
433433
split.
434434
- destruct b, c; auto.
435435
- intro; destruct H; destruct b, c; auto.
436436
Qed.
437437

438-
Lemma not_bool_eq_true b : not b = true <-> b = false.
438+
Lemma not_bool_eq_true b : negb b = true <-> b = false.
439439
Proof. split; destruct b; auto. Qed.
440440

441-
Lemma not_bool_eq_false b : not b = false <-> b = true.
441+
Lemma not_bool_eq_false b : negb b = false <-> b = true.
442442
Proof. split; destruct b; auto. Qed.
443443

444444

445445
(** Lemmas about bitvector equality **)
446446

447447
Lemma bvEq_cons w h0 h1 a0 a1 :
448448
bvEq (S w) (VectorDef.cons _ h0 w a0) (VectorDef.cons _ h1 w a1) =
449-
and (boolEq h0 h1) (bvEq w a0 a1).
449+
andb (boolEq h0 h1) (bvEq w a0 a1).
450450
Proof. reflexivity. Qed.
451451

452452
Lemma bvEq_refl w a : bvEq w a a = true.
@@ -485,13 +485,6 @@ Qed.
485485

486486
Hint Extern 1 (StartAutomation _) => progress compute_bv_funs: refinesFun.
487487

488-
Lemma true_eq_scaffolding_true : Datatypes.true = SAWCoreScaffolding.true.
489-
Proof. reflexivity. Qed.
490-
Lemma false_eq_scaffolding_false : Datatypes.false = SAWCoreScaffolding.false.
491-
Proof. reflexivity. Qed.
492-
493-
Hint Rewrite true_eq_scaffolding_true false_eq_scaffolding_false : SAWCoreBitvectors_eqs.
494-
495488
Ltac FreshIntroArg_bv_eq T :=
496489
let e := fresh in
497490
IntroArg_intro e;
@@ -551,14 +544,14 @@ Proof. intros H eq; apply H; destruct b; easy. Qed.
551544

552545
Lemma IntroArg_and_bool_eq_true n (b c : bool) goal :
553546
IntroArg n (b = true) (fun _ => FreshIntroArg n (c = true) (fun _ => goal)) ->
554-
IntroArg n (and b c = true) (fun _ => goal).
547+
IntroArg n (andb b c = true) (fun _ => goal).
555548
Proof.
556549
intros H eq; apply H; apply and_bool_eq_true in eq; destruct eq; eauto.
557550
Qed.
558551
Lemma IntroArg_and_bool_eq_false n (b c : bool) goal :
559552
IntroArg n (b = false) (fun _ => goal) ->
560553
IntroArg n (c = false) (fun _ => goal) ->
561-
IntroArg n (and b c = false) (fun _ => goal).
554+
IntroArg n (andb b c = false) (fun _ => goal).
562555
Proof.
563556
intros Hl Hr eq; apply and_bool_eq_false in eq.
564557
destruct eq; [ apply Hl | apply Hr ]; eauto.
@@ -572,14 +565,14 @@ Qed.
572565
Lemma IntroArg_or_bool_eq_true n (b c : bool) goal :
573566
IntroArg n (b = true) (fun _ => goal) ->
574567
IntroArg n (c = true) (fun _ => goal) ->
575-
IntroArg n (or b c = true) (fun _ => goal).
568+
IntroArg n (orb b c = true) (fun _ => goal).
576569
Proof.
577570
intros Hl Hr eq; apply or_bool_eq_true in eq.
578571
destruct eq; [ apply Hl | apply Hr ]; eauto.
579572
Qed.
580573
Lemma IntroArg_or_bool_eq_false n (b c : bool) goal :
581574
IntroArg n (b = false) (fun _ => FreshIntroArg n (c = false) (fun _ => goal)) ->
582-
IntroArg n (or b c = false) (fun _ => goal).
575+
IntroArg n (orb b c = false) (fun _ => goal).
583576
Proof.
584577
intros H eq; apply H; apply or_bool_eq_false in eq; destruct eq; eauto.
585578
Qed.
@@ -591,11 +584,11 @@ Qed.
591584

592585
Lemma IntroArg_not_bool_eq_true n (b : bool) goal :
593586
IntroArg n (b = false) (fun _ => goal) ->
594-
IntroArg n (not b = true) (fun _ => goal).
587+
IntroArg n (negb b = true) (fun _ => goal).
595588
Proof. intros H eq; apply H, not_bool_eq_true; eauto. Qed.
596589
Lemma IntroArg_not_bool_eq_false n (b : bool) goal :
597590
IntroArg n (b = true) (fun _ => goal) ->
598-
IntroArg n (not b = false) (fun _ => goal).
591+
IntroArg n (negb b = false) (fun _ => goal).
599592
Proof. intros H eq; apply H, not_bool_eq_false; eauto. Qed.
600593

601594
(* Hint Extern 1 (IntroArg _ (not _ = true) _) => *)
@@ -647,9 +640,9 @@ Hint Extern 1 (IntroArg _ (@eq bool ?x ?y) _) =>
647640
lazymatch y with
648641
| true => lazymatch x with
649642
| SAWCorePrelude.bvEq _ _ _ => simple apply IntroArg_bvEq_eq
650-
| and _ _ => simple apply IntroArg_and_bool_eq_true
651-
| or _ _ => simple apply IntroArg_or_bool_eq_true
652-
| not _ => simple apply IntroArg_not_bool_eq_true
643+
| andb _ _ => simple apply IntroArg_and_bool_eq_true
644+
| orb _ _ => simple apply IntroArg_or_bool_eq_true
645+
| negb _ => simple apply IntroArg_not_bool_eq_true
653646
| boolEq _ _ => simple apply IntroArg_boolEq_eq
654647
| if _ then true else false => simple apply IntroArg_bool_eq_if_true
655648
| if _ then 1%bool else 0%bool => simple apply IntroArg_bool_eq_if_true
@@ -658,9 +651,9 @@ Hint Extern 1 (IntroArg _ (@eq bool ?x ?y) _) =>
658651
end
659652
| false => lazymatch x with
660653
| SAWCorePrelude.bvEq _ _ _ => simple apply IntroArg_bvEq_neq
661-
| and _ _ => simple apply IntroArg_and_bool_eq_false
662-
| or _ _ => simple apply IntroArg_or_bool_eq_false
663-
| not _ => simple apply IntroArg_not_bool_eq_false
654+
| andb _ _ => simple apply IntroArg_and_bool_eq_false
655+
| orb _ _ => simple apply IntroArg_or_bool_eq_false
656+
| negb _ => simple apply IntroArg_not_bool_eq_false
664657
| boolEq _ _ => simple apply IntroArg_boolEq_neq
665658
| if _ then true else false => simple apply IntroArg_bool_eq_if_false
666659
| if _ then 1%bool else 0%bool => simple apply IntroArg_bool_eq_if_false
@@ -694,10 +687,6 @@ Proof. intros H eq; apply H; eauto. Qed.
694687
Hint Extern 1 (IntroArg _ (iteDep (fun _ => Maybe (Eq _ _ _)) true _ _ = _) _) =>
695688
simple apply IntroArg_iteDep_Maybe_Eq_true : refinesFun.
696689
Hint Extern 1 (IntroArg _ (iteDep (fun _ => Maybe (Eq _ _ _)) false _ _ = _) _) =>
697-
simple apply IntroArg_iteDep_Maybe_Eq_false : refinesFun.
698-
Hint Extern 1 (IntroArg _ (iteDep (fun _ => Maybe (Eq _ _ _)) Datatypes.true _ _ = _) _) =>
699-
simple apply IntroArg_iteDep_Maybe_Eq_true : refinesFun.
700-
Hint Extern 1 (IntroArg _ (iteDep (fun _ => Maybe (Eq _ _ _)) Datatypes.false _ _ = _) _) =>
701690
simple apply IntroArg_iteDep_Maybe_Eq_false : refinesFun.
702691

703692
Lemma IntroArg_isBvsle_def n w a b goal

0 commit comments

Comments
 (0)