Skip to content

Commit

Permalink
Merge pull request #14636 from MinaProtocol/rb/pickles-alcotest-step_…
Browse files Browse the repository at this point in the history
…verifier

Pickles: use Alcotest for unit tests in module `Step_verifier`
  • Loading branch information
dannywillems authored Nov 29, 2023
2 parents bb274b1 + 4ec7b13 commit 03644c5
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 33 deletions.
36 changes: 4 additions & 32 deletions src/lib/pickles/step_verifier.ml
Original file line number Diff line number Diff line change
Expand Up @@ -682,38 +682,6 @@ struct
in
domain ~max:(Domain.log2_size max_domains.h)

let%test_module "side loaded domains" =
( module struct
let run k =
let y =
run_and_check (fun () ->
let y = k () in
fun () -> As_prover.read_var y )
|> Or_error.ok_exn
in
y

let%test_unit "side loaded domains" =
let open Side_loaded_verification_key in
let domains = [ { Domains.h = 10 }; { h = 15 } ] in
let pt = Field.Constant.random () in
List.iter domains ~f:(fun ds ->
let d_unchecked =
Plonk_checks.domain
(module Field.Constant)
(Pow_2_roots_of_unity ds.h) ~shifts:Common.tick_shifts
~domain_generator:Backend.Tick.Field.domain_generator
in
let checked_domain () =
side_loaded_domain ~log2_size:(Field.of_int ds.h)
in
[%test_eq: Field.Constant.t]
(d_unchecked#vanishing_polynomial pt)
(run (fun () ->
(checked_domain ())#vanishing_polynomial (Field.constant pt) )
) )
end )

(* module Split_evaluations = struct
open Plonk_types
Expand Down Expand Up @@ -1253,3 +1221,7 @@ struct
end

include Make (Step_main_inputs)

module For_tests_only = struct
let side_loaded_domain = side_loaded_domain
end
11 changes: 11 additions & 0 deletions src/lib/pickles/step_verifier.mli
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,14 @@ val verify :
Import.Types.Step.Proof_state.Per_proof.In_circuit.t
(* unfinalized *)
-> Step_main_inputs.Impl.Boolean.var

module For_tests_only : sig
type field := Step_main_inputs.Impl.Field.t

val side_loaded_domain :
log2_size:field
-> < generator : field
; log2_size : field
; shifts : field Pickles_types.Plonk_types.Shifts.t
; vanishing_polynomial : field -> field >
end
3 changes: 2 additions & 1 deletion src/lib/pickles/test/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ let () =
let tests =
Test_impls.tests @ Test_opt_sponge.tests @ Test_plonk_curve_ops.tests
@ Test_sponge.tests @ Test_step.tests @ Test_scalar_challenge.tests
@ Test_side_loaded_verification_key.tests @ Test_wrap_hack.tests
@ Test_side_loaded_verification_key.tests @ Test_step_verifier.tests
@ Test_wrap_hack.tests
in
Alcotest.run "Pickles" tests
51 changes: 51 additions & 0 deletions src/lib/pickles/test/test_step_verifier.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
(* Testing
-------
Component: Pickles
Subject: Test Step_verifier
Invocation: \
dune exec src/lib/pickles/test/main.exe -- test "Step verifier"
*)

module Step_main_inputs = Pickles__Step_main_inputs
open Step_main_inputs.Impl

let run k =
let y =
run_and_check (fun () ->
let y = k () in
fun () -> As_prover.read_var y )
|> Or_error.ok_exn
in
y

let test_side_loaded_domains () =
let module O = One_hot_vector.Make (Impl) in
let open Pickles__Side_loaded_verification_key in
let domains = [ { Domains.h = 10 }; { h = 15 } ] in
let pt = Field.Constant.random () in
List.iter domains ~f:(fun ds ->
let d_unchecked =
Plonk_checks.domain
(module Field.Constant)
(Pow_2_roots_of_unity ds.h) ~shifts:Common.tick_shifts
~domain_generator:Backend.Tick.Field.domain_generator
in
let checked_domain () =
Pickles__Step_verifier.For_tests_only.side_loaded_domain
~log2_size:(Field.of_int ds.h)
in
let pp ppf cst =
Format.pp_print_string ppf (Field.Constant.to_string cst)
in
(Alcotest.check (Alcotest.testable pp Field.Constant.equal))
"side loaded domains"
(d_unchecked#vanishing_polynomial pt)
(run (fun () ->
(checked_domain ())#vanishing_polynomial (Field.constant pt) ) ) )

let tests =
let open Alcotest in
[ ( "Step verifier"
, [ test_case "side loaded domains" `Quick test_side_loaded_domains ] )
]

0 comments on commit 03644c5

Please sign in to comment.