Skip to content

Commit

Permalink
Debugging combined inner product computation
Browse files Browse the repository at this point in the history
  • Loading branch information
jspada committed Feb 13, 2024
1 parent 1c48c81 commit c056836
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/lib/pickles/plonk_checks/gen_scalars/gen_scalars.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 2 additions & 4 deletions src/lib/pickles/plonk_checks/plonk_checks.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand All @@ -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 ->
Expand All @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,22 +209,22 @@ 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
in
false
with _ -> true
in
assert test_failed
assert test_failed *)
(* Customised as Conditional gate; invalid witness *)
(* let test_failed =
try
Expand Down
3 changes: 1 addition & 2 deletions src/lib/pickles/wrap.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
102 changes: 99 additions & 3 deletions src/lib/pickles/wrap_verifier.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c056836

Please sign in to comment.