diff --git a/src/lib/pickles/plonk_checks/gen_scalars/gen_scalars.ml b/src/lib/pickles/plonk_checks/gen_scalars/gen_scalars.ml index e8dede6bffc..340e1217c07 100644 --- a/src/lib/pickles/plonk_checks/gen_scalars/gen_scalars.ml +++ b/src/lib/pickles/plonk_checks/gen_scalars/gen_scalars.ml @@ -276,10 +276,10 @@ let () = a Env.t) = |ocaml} -external fp_linearization_minus : bool -> string * (string * string) array +external fp_linearization_minus : unit -> string * (string * string) array = "fp_linearization_strings_minus" -let fp_constant_term, fp_index_terms = fp_linearization_minus true +let fp_constant_term, fp_index_terms = fp_linearization_minus () let () = output_string fp_constant_term diff --git a/src/lib/pickles/plonk_checks/plonk_checks.ml b/src/lib/pickles/plonk_checks/plonk_checks.ml index 412465801ff..304463cdfa0 100644 --- a/src/lib/pickles/plonk_checks/plonk_checks.ml +++ b/src/lib/pickles/plonk_checks/plonk_checks.ml @@ -366,7 +366,6 @@ module Make (Shifted_value : Shifted_value.S) (Sc : Scalars.S) = struct match token with | Alpha -> Stack.push stack @@ env.alpha_pow 1 - (* JES: CHECK: Where just plain alpha? *) | Beta -> Stack.push stack env.beta | Gamma -> @@ -377,7 +376,7 @@ module Make (Shifted_value : Shifted_value.S) (Sc : Scalars.S) = struct Stack.push stack env.endo_coefficient | Mds mds -> Stack.push stack @@ env.mds (mds.row, mds.col) - (* JES: CHECK: is this (row, col) format *) + (* JES: CHECK this: is this (row, col) format *) | VanishesOnZeroKnowledgeAndPreviousRows -> Stack.push stack env.vanishes_on_zero_knowledge_and_previous_rows | UnnormalizedLagrangeBasis i -> @@ -393,8 +392,7 @@ module Make (Shifted_value : Shifted_value.S) (Sc : Scalars.S) = struct | Pow n -> Stack.( push stack - @@ pow2pow (module F) (top_exn stack) (Int32.to_int_exn n)) - (* JES: CHECK: Correct way to pow here? *) + @@ pow2pow (module F) (pop_exn stack) (Int32.to_int_exn n)) | Add -> Stack.(push stack @@ F.( + ) (pop_exn stack) (pop_exn stack)) | Mul -> diff --git a/src/lib/pickles/test/customizable_gate/test_customizable_gate.ml b/src/lib/pickles/test/customizable_gate/test_customizable_gate.ml index f56469d6e48..6ddbd6bc64d 100644 --- a/src/lib/pickles/test/customizable_gate/test_customizable_gate.ml +++ b/src/lib/pickles/test/customizable_gate/test_customizable_gate.ml @@ -209,14 +209,14 @@ let conditional_gate = let () = if perform_step_tests then ( (* Customised as ForeignFieldAdd gate; valid witness *) - test ~step_only:true ~custom_gate_type:None ~valid_witness:true ; + (* test ~step_only:true ~custom_gate_type:None ~valid_witness:true ; *) (* Customised as Conditional gate; valid witness *) (* Note: Requires Cache.Wrap.read_or_generate to have custom_gate_type passed to it *) - (* test ~step_only:true ~custom_gate_type:conditional_gate ~valid_witness:true ; *) + test ~step_only:true ~custom_gate_type:conditional_gate ~valid_witness:true ; (* Customised as ForeignFieldAdd gate; invalid witness *) - let test_failed = + (* let test_failed = try let _cs = test ~step_only:true ~custom_gate_type:None ~valid_witness:false @@ -224,7 +224,7 @@ let () = false with _ -> true in - assert test_failed + assert test_failed *) (* Customised as Conditional gate; invalid witness *) (* let test_failed = try diff --git a/src/lib/pickles/wrap.ml b/src/lib/pickles/wrap.ml index 07c397b4239..a16cf51d4cf 100644 --- a/src/lib/pickles/wrap.ml +++ b/src/lib/pickles/wrap.ml @@ -55,8 +55,7 @@ let combined_inner_product (type actual_proofs_verified) ~env ~domain ~ft_eval1 | Some custom_gate_type -> Type1Minus.ft_eval0 (module Tick.Field) - plonk ~env ~custom_gate_type (* ~map_constant:Fn.id *) - ~domain + plonk ~env ~custom_gate_type ~map_constant:Fn.id ~domain (Plonk_types.Evals.to_in_circuit combined_evals) (fst e.public_input) | None -> diff --git a/src/lib/pickles/wrap_verifier.ml b/src/lib/pickles/wrap_verifier.ml index 719cfd14126..e9741b0c940 100644 --- a/src/lib/pickles/wrap_verifier.ml +++ b/src/lib/pickles/wrap_verifier.ml @@ -545,32 +545,123 @@ struct let check_bulletproof ~pcs_batch ~(sponge : Sponge.t) ~(xi : Scalar_challenge.t) - ~(advice : - Other_field.Packed.t Shifted_value.Type1.t - Types.Step.Bulletproof.Advice.t ) + ~(* JES: pub input commitment *) + (advice : + Other_field.Packed.t Shifted_value.Type1.t + Types.Step.Bulletproof.Advice.t ) ~polynomials:(without_degree_bound, with_degree_bound) ~openings_proof: + (* JES: list of opening proof commitments *) ({ lr; delta; z_1; z_2; challenge_polynomial_commitment } : ( Inner_curve.t , Other_field.Packed.t Shifted_value.Type1.t ) Openings.Bulletproof.t ) = with_label __LOC__ (fun () -> + (* JES: sponge DEBUG *) + as_prover (fun () -> + let state = Sponge.state sponge in + printf "ocaml sponge_state = \n" ; + + Array.iter state ~f:(fun value -> + let value = As_prover.read Digest.typ value in + let value = Digest.Constant.to_tick_field value in + + printf " %s\n" @@ Backend.Tick.Bigint.to_hex + @@ Pasta_bindings.Fp.to_bigint value ) ) ; + + (* JES: combined_inner_product DEBUG *) + as_prover (fun () -> + let (Shifted_value.Type1.Shifted_value (value : Field.t)) = + advice.combined_inner_product + in + let value = As_prover.read Field.typ value in + + printf "ocaml combined_inner_product = %s\n" + @@ Backend.Tick.Bigint.to_hex @@ Bigint.of_field value ) ; + Other_field.Packed.absorb_shifted sponge advice.combined_inner_product ; + (* combined_inner_product should be equal to sum_i < t, r^i pows(beta_i) > = sum_i r^i < t, pows(beta_i) > That is checked later. *) + + (* JES: xi DEBUG *) + as_prover (fun () -> + let xi = As_prover.read Scalar_challenge.typ xi in + printf "ocaml xi = %s\n" @@ Backend.Tick.Bigint.to_hex + @@ Pasta_bindings.Fp.to_bigint + @@ Scalar_challenge.Constant.to_field xi ) ; + + (* JES: sponge DEBUG *) + as_prover (fun () -> + let state = Sponge.state sponge in + printf "ocaml sponge_state = \n" ; + + Array.iter state ~f:(fun value -> + let value = As_prover.read Digest.typ value in + let value = Digest.Constant.to_tick_field value in + + printf " %s\n" @@ Backend.Tick.Bigint.to_hex + @@ Pasta_bindings.Fp.to_bigint value ) ) ; + let u = let t = Sponge.squeeze_field sponge in group_map t in + + (* JES: u DEBUG *) + as_prover (fun () -> + let x = As_prover.read Field.typ (fst u) in + let y = As_prover.read Field.typ (snd u) in + printf "ocaml u = (%s, %s)\n" + (Backend.Tick.Bigint.to_hex @@ Bigint.of_field x) + (Backend.Tick.Bigint.to_hex @@ Bigint.of_field y) ) ; + + (* JES: delta DEBUG *) + as_prover (fun () -> + let delta = As_prover.read Inner_curve.typ delta in + let x, y = Inner_curve.Constant.to_affine_exn delta in + printf "ocaml delta = (%s, %s)\n" + (Backend.Tick.Bigint.to_hex @@ Bigint.of_field x) + (Backend.Tick.Bigint.to_hex @@ Bigint.of_field y) ) ; + + (* JES: challenge_polynomial_commitment DEBUG *) + as_prover (fun () -> + let challenge_polynomial_commitment = + As_prover.read Inner_curve.typ challenge_polynomial_commitment + in + let x, y = + Inner_curve.Constant.to_affine_exn challenge_polynomial_commitment + in + printf "ocaml challenge_polynomial_commitment = (%s, %s)\n" + (Backend.Tick.Bigint.to_hex @@ Bigint.of_field x) + (Backend.Tick.Bigint.to_hex @@ Bigint.of_field y) ) ; + let open Inner_curve in let combined_polynomial (* Corresponds to xi in figure 7 of WTS *) = Split_commitments.combine pcs_batch ~xi without_degree_bound with_degree_bound in + + (* JES: without_degree_bound DEBUG *) + Vector.iter without_degree_bound ~f:(fun data -> + Opt.iter data ~f:(fun comm -> + let p1 = + Inner_curve.to_field_elements + @@ Split_commitments.Point.underlying comm.(0) + in + let x = Option.value_exn @@ List.nth p1 0 in + let y = Option.value_exn @@ List.nth p1 1 in + as_prover (fun () -> + let x = As_prover.read Field.typ x in + let y = As_prover.read Field.typ y in + printf "ocaml = (%s, %s)\n" + (Backend.Tick.Bigint.to_hex @@ Bigint.of_field x) + (Backend.Tick.Bigint.to_hex @@ Bigint.of_field y) ) ) ) ; + let scale_fast = scale_fast ~num_bits:Other_field.Packed.Constant.size_in_bits in @@ -597,6 +688,11 @@ struct in z_1_g_plus_b_u + z2_h in + (* JES: DEBUG *) + as_prover (fun () -> + let success = equal_g lhs rhs in + let success = As_prover.read Boolean.typ success in + printf "ocaml bulletproof_success = %b\n" success ) ; (`Success (equal_g lhs rhs), challenges) ) module Opt = struct