Skip to content

Commit 753431d

Browse files
committed
Support for uninitialized inputs and proper checking for their presence in bdep tactics
1 parent c9717f9 commit 753431d

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

src/ecCircuits.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2037,7 +2037,12 @@ let circuit_of_form
20372037
| PVloc v -> v
20382038
(* FIXME: Should globals be supported? *)
20392039
| _ -> raise (CircError "Global vars not supported")
2040-
in hyps, pstate_get pstate v
2040+
in
2041+
let v = match pstate_get_opt pstate v with
2042+
| Some v -> v
2043+
| None -> circuit_uninit env f_.f_ty (* Allow uninitialized program variables *)
2044+
in
2045+
hyps, v
20412046
| Fglob (id, mem) -> raise (CircError "glob not supported")
20422047
| Ftuple comps ->
20432048
let hyps, comps =
@@ -2279,6 +2284,7 @@ let pstate_get_all = fun pstate -> List.snd (pstate_get_all pstate)
22792284
let circuit_ueq = (fun c1 c2 -> (circuit_eq c1 c2 :> circuit))
22802285
let circuit_aggregate =
22812286
circuit_aggregate
2287+
let circuit_has_uninitialized = circuit_has_uninitialized
22822288

22832289
let circuit_aggregate_inps =
22842290
circuit_aggregate_inputs

src/ecCircuits.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,8 @@ val process_instr : hyps -> memory -> pstate -> instr -> pstate
6464
(* Temporary? *)
6565
val circuit_of_form_with_hyps : ?pstate:pstate -> ?cache:cache -> hyps -> form -> circuit
6666

67+
(* Check for uninitialized inputs *)
68+
val circuit_has_uninitialized : circuit -> bool
69+
6770
val circuit_slice : circuit -> int -> int -> circuit
6871
val circuit_align_inputs : circuit -> (int * int) option list -> circuit

src/phl/ecPhlBDep.ml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module HL = struct
3030
end
3131

3232
exception BDepError of string
33+
exception BDepUninitializedInputs
3334

3435

3536
let int_of_form (hyps: hyps) (f: form) : BI.zint =
@@ -106,7 +107,9 @@ let mapreduce
106107
| {v_name}, Some (sz, offset) ->
107108
circuit_slice (Option.get (pstate_get_opt pstate v_name)) sz offset
108109
)
109-
outvs in
110+
outvs
111+
in
112+
if not (List.for_all (fun c -> not (circuit_has_uninitialized c)) circs) then raise BDepUninitializedInputs;
110113

111114
(* This is required for now as we do not allow mapreduce with multiple arguments *)
112115
(* assert (Set.cardinal @@ Set.of_list @@ List.map (fun c -> c.inps) circs = 1); *)
@@ -197,7 +200,12 @@ let prog_equiv_prod
197200
(List.map (fun v -> v.v_name) outvs_l) in
198201
let circs_r = List.map (fun v -> pstate_get pstate_r v)
199202
(List.map (fun v -> v.v_name) outvs_r) in
200-
203+
204+
if not (
205+
(List.for_all (fun c -> not (circuit_has_uninitialized c)) circs_l) ||
206+
(List.for_all (fun c -> not (circuit_has_uninitialized c)) circs_r)
207+
) then raise BDepUninitializedInputs;
208+
201209
(*assert (Set.cardinal @@ Set.of_list @@ List.map (fun c -> c.inps) circs_l = 1); *)
202210
(*assert (Set.cardinal @@ Set.of_list @@ List.map (fun c -> c.inps) circs_r = 1);*)
203211
let c_l = try
@@ -326,6 +334,7 @@ let circ_form_eval_plus_equiv
326334
let f = EcPV.PVM.subst1 env (PVloc v.v_name) mem cur_val f in
327335
let pcond = match pstate_get_opt pstate v.v_name with
328336
| Some circ -> begin try
337+
if circuit_has_uninitialized circ then raise BDepUninitializedInputs;
329338
Some (circuit_ueq circ (circuit_of_form hyps cur_val))
330339
with CircError err ->
331340
raise (BDepError ("Failed to generate circuit for current value precondition with error:\n" ^ err))
@@ -377,6 +386,8 @@ let mapreduce_eval
377386
begin
378387
let circs = List.map (fun v -> pstate_get pstate v) (List.map (fun v -> v.v_name) outvs) in
379388

389+
if not (List.for_all (fun c -> not (circuit_has_uninitialized c)) circs) then raise BDepUninitializedInputs;
390+
380391
let c = try
381392
(circuit_aggregate circs)
382393
with CircError _err ->

0 commit comments

Comments
 (0)