Skip to content

Commit 22544f0

Browse files
committed
Fixed circuits being closed too soon
1 parent fd0bb84 commit 22544f0

5 files changed

Lines changed: 24 additions & 11 deletions

File tree

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
provers = pkgs.symlinkJoin {
134134
name = "provers";
135135
paths = [
136-
# altErgo
136+
altErgo
137137
z3
138138
# cvc4
139139
cvc5

src/ecCircuits.ml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ let circuit_of_form
587587
let t = doit st t_f in
588588
let f = doit st f_f in
589589
let c = doit st c_f in
590-
circuit_ite ~c ~t ~f
590+
circuit_ite ~strict:true ~c ~t ~f
591591

592592
| Flocal idn ->
593593
state_get st idn
@@ -769,6 +769,11 @@ let circuit_of_form
769769
EcPrinting.(pp_form ppe) f_
770770
(Printexc.to_string e);
771771
assert false
772+
| e ->
773+
Format.eprintf "Failed on %a with exception %s@."
774+
EcPrinting.(pp_form ppe) f_
775+
(Printexc.to_string e);
776+
assert false
772777

773778
and trans_iter (st: state) (hyps: hyps) (f: form) (fs: form list) : circuit =
774779
(* FIXME: move auxiliary function out of the definitions *)
@@ -961,11 +966,13 @@ let instrs_equiv
961966

962967
(* FIXME: remove variable list from the arguments *)
963968
(* FIXME: change memory -> memenv *)
964-
let state_of_prog ?me (hyps: hyps) (mem: memory) ?(st: state = empty_state) (proc: instr list) : state =
969+
let state_of_prog ?(close = false) ?me (hyps: hyps) (mem: memory) ?(st: state = empty_state) (proc: instr list) : state =
965970
let st =
966971
List.fold_left (fun st -> process_instr ?me hyps mem ~st) st proc
967972
in
973+
if close then
968974
close_circ_lambda st
975+
else st
969976

970977
let rec circ_simplify_form_bitstring_equality
971978
?(st: state = empty_state)

src/ecCircuits.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ val circ_simplify_form_bitstring_equality :
6969
?pres:circuit list -> hyps -> form -> form
7070

7171
(* Proc processors *)
72-
val state_of_prog : ?me:memenv -> hyps -> memory -> ?st:state -> instr list -> state
72+
val state_of_prog : ?close:bool -> ?me:memenv -> hyps -> memory -> ?st:state -> instr list -> state
7373
val instrs_equiv : hyps -> memenv -> ?keep:EcPV.PV.t -> ?st:state -> instr list -> instr list -> bool
7474
val process_instr : ?me:memenv -> hyps -> memory -> st:state -> instr -> state
7575
(* val pstate_of_memtype : ?pstate:pstate -> env -> memtype -> pstate * cinput list *)

src/ecLowCircuits.ml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ module type CircuitInterface = sig
569569
val circuit_is_free : circuit -> bool
570570

571571
(* Direct circuuit constructions *)
572-
val circuit_ite : c:circuit -> t:circuit -> f:circuit -> circuit
572+
val circuit_ite : ?strict:bool -> c:circuit -> t:circuit -> f:circuit -> circuit
573573
val circuit_eq : circuit -> circuit -> circuit
574574
val circuit_eqs : circuit -> circuit -> circuit list
575575

@@ -999,18 +999,22 @@ module MakeCircuitInterfaceFromCBackend(Backend: CBackend) : CircuitInterface =
999999

10001000
let circuit_is_free (f: circuit) : bool = List.is_empty @@ snd f
10011001

1002-
let circuit_ite ~(c: circuit) ~(t: circuit) ~(f: circuit) : circuit =
1003-
assert ((circuit_is_free t) && (circuit_is_free f) && (circuit_is_free c));
1002+
let circuit_ite ?(strict = false) ~(c: circuit) ~(t: circuit) ~(f: circuit) : circuit =
1003+
let inps = match c, t, f with
1004+
| (_, []), (_, []), (_, []) when strict -> []
1005+
| (_, cinps), (_, tinps), (_, finps) when (not strict) && cinps = tinps && cinps = finps -> cinps
1006+
| _ -> assert false
1007+
in
10041008
let c = match (fst c).type_ with
10051009
| CBool -> Backend.node_of_reg (fst c).reg
10061010
| _ -> assert false
10071011
in
10081012
let res_r = Backend.reg_ite c (fst t).reg (fst f).reg in
10091013
match ((fst t).type_, (fst f).type_) with
1010-
| CBitstring nt, CBitstring nf when nt = nf -> {reg = res_r; type_ = (fst t).type_}, []
1011-
| CArray {width=wt; count=nt}, CArray {width=wf; count=nf} when wt = wf && nt = nf -> {reg = res_r; type_ = (fst t).type_}, []
1012-
| CTuple szs_t, CTuple szs_f when List.all2 (=) szs_t szs_f -> {reg = res_r; type_ = (fst t).type_}, []
1013-
| CBool, CBool -> {reg = res_r; type_ = (fst t).type_}, []
1014+
| CBitstring nt, CBitstring nf when nt = nf -> {reg = res_r; type_ = (fst t).type_}, inps
1015+
| CArray {width=wt; count=nt}, CArray {width=wf; count=nf} when wt = wf && nt = nf -> {reg = res_r; type_ = (fst t).type_}, inps
1016+
| CTuple szs_t, CTuple szs_f when List.all2 (=) szs_t szs_f -> {reg = res_r; type_ = (fst t).type_}, inps
1017+
| CBool, CBool -> {reg = res_r; type_ = (fst t).type_}, inps
10141018
| _ -> raise CircConstructorInvalidArguments
10151019

10161020
(* TODO: type check? *)

src/phl/ecPhlBDep.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,10 @@ let t_bdep_solve
210210
let st, cpres = process_pre tc hs_pr in
211211
let tm = time (toenv hyps) tm "Done with precondition processing" in
212212

213+
(* Get open state *)
213214
let st = state_of_prog hyps (fst hs_m) ~st hs_s.s_node in
214215
let _tm = time (toenv hyps) tm "Done with program circuit gen" in
216+
215217
let res = solve_post ~st ~pres:cpres hyps hs_po in
216218
EcCircuits.clear_translation_caches ();
217219
if res then

0 commit comments

Comments
 (0)