Skip to content

Commit

Permalink
Rename r into evalscale
Browse files Browse the repository at this point in the history
  • Loading branch information
volhovm committed Nov 21, 2024
1 parent dd2e6bc commit 37a4f1b
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 56 deletions.
10 changes: 5 additions & 5 deletions src/lib/pickles/composition_types/composition_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ module Wrap = struct
.t =
{ plonk : 'plonk
; combined_inner_product : 'fp
(** combined_inner_product = sum_{i < num_evaluation_points} sum_{j < num_polys} r^i polyscale^j f_j(pt_i) *)
(** combined_inner_product = sum_{i < num_evaluation_points} sum_{j < num_polys} evalscale^i polyscale^j f_j(pt_i) *)
; b : 'fp
(** b = challenge_poly plonk.zeta + r * challenge_poly (domain_generrator * plonk.zeta)
(** b = challenge_poly plonk.zeta + evalscale * challenge_poly (domain_generrator * plonk.zeta)
where challenge_poly(x) = \prod_i (1 + bulletproof_challenges.(i) * x^{2^{k - 1 - i}})
*)
; polyscale : 'scalar_challenge
Expand Down Expand Up @@ -912,7 +912,7 @@ module Step = struct
type 'fq t =
{ b : 'fq
; combined_inner_product : 'fq
(* sum_i r^i sum_j polyscale^j f_j(pt_i) *)
(* sum_i evalscale^i sum_j polyscale^j f_j(pt_i) *)
}
[@@deriving hlist]
end
Expand Down Expand Up @@ -1087,13 +1087,13 @@ module Step = struct
type ('plonk, 'scalar_challenge, 'fq, 'bulletproof_challenges) t_ =
{ plonk : 'plonk
; combined_inner_product : 'fq
(** combined_inner_product = sum_{i < num_evaluation_points} sum_{j < num_polys} r^i polyscale^j f_j(pt_i) *)
(** combined_inner_product = sum_{i < num_evaluation_points} sum_{j < num_polys} evalscale^i polyscale^j f_j(pt_i) *)
; polyscale : 'scalar_challenge
(** The challenge used for combining polynomials *)
; bulletproof_challenges : 'bulletproof_challenges
(** The challenges from the inner-product argument that was partially verified. *)
; b : 'fq
(** b = challenge_poly plonk.zeta + r * challenge_poly (domain_generrator * plonk.zeta)
(** b = challenge_poly plonk.zeta + evalscale * challenge_poly (domain_generrator * plonk.zeta)
where challenge_poly(x) = \prod_i (1 + bulletproof_challenges.(i) * x^{2^{k - 1 - i}})
*)
}
Expand Down
8 changes: 4 additions & 4 deletions src/lib/pickles/composition_types/composition_types.mli
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ module Wrap : sig
.t =
{ plonk : 'plonk
; combined_inner_product : 'fp
(** combined_inner_product = sum_{i < num_evaluation_points} sum_{j < num_polys} r^i polyscale^j f_j(pt_i) *)
(** combined_inner_product = sum_{i < num_evaluation_points} sum_{j < num_polys} evalscale^i polyscale^j f_j(pt_i) *)
; b : 'fp
(** b = challenge_poly plonk.zeta + r * challenge_poly (domain_generrator * plonk.zeta)
(** b = challenge_poly plonk.zeta + evalscale * challenge_poly (domain_generator * plonk.zeta)
where challenge_poly(x) = \prod_i (1 + bulletproof_challenges.(i) * x^{2^{k - 1 - i}})
*)
; polyscale : 'scalar_challenge
Expand Down Expand Up @@ -1010,13 +1010,13 @@ module Step : sig
type ('plonk, 'scalar_challenge, 'fq, 'bulletproof_challenges) t_ =
{ plonk : 'plonk
; combined_inner_product : 'fq
(** combined_inner_product = sum_{i < num_evaluation_points} sum_{j < num_polys} r^i polyscale^j f_j(pt_i) *)
(** combined_inner_product = sum_{i < num_evaluation_points} sum_{j < num_polys} evalscale^i polyscale^j f_j(pt_i) *)
; polyscale : 'scalar_challenge
(** The challenge used for combining polynomials *)
; bulletproof_challenges : 'bulletproof_challenges
(** The challenges from the inner-product argument that was partially verified. *)
; b : 'fq
(** b = challenge_poly plonk.zeta + r * challenge_poly (domain_generrator * plonk.zeta)
(** b = challenge_poly plonk.zeta + evalscale * challenge_poly (domain_generrator * plonk.zeta)
where challenge_poly(x) = \prod_i (1 + bulletproof_challenges.(i) * x^{2^{k - 1 - i}})
*)
}
Expand Down
8 changes: 4 additions & 4 deletions src/lib/pickles/pickles.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1486,15 +1486,15 @@ module Make_str (_ : Wire_types.Concrete) = struct
; feature_flags = Plonk_types.Features.none_bool
}
in
let r = scalar_chal O.u in
let evalscale = scalar_chal O.u in
let polyscale = scalar_chal O.v in
let to_field =
SC.to_field_constant
(module Tick.Field)
~endo:Endo.Wrap_inner_curve.scalar
in
let module As_field = struct
let r = to_field r
let evalscale = to_field evalscale

let polyscale = to_field polyscale

Expand Down Expand Up @@ -1584,7 +1584,7 @@ module Make_str (_ : Wire_types.Concrete) = struct
(let x1, x2 = x_hat in
([| x1 |], [| x2 |]) )
}
~r ~polyscale ~zeta ~zetaw
~evalscale ~polyscale ~zeta ~zetaw
~old_bulletproof_challenges:prev_challenges
~env:tick_env ~domain:tick_domain
~ft_eval1:proof.proof.openings.ft_eval1
Expand All @@ -1611,7 +1611,7 @@ module Make_str (_ : Wire_types.Concrete) = struct
let b =
let open Tick.Field in
challenge_polynomial zeta
+ (r * challenge_polynomial zetaw)
+ (evalscale * challenge_polynomial zetaw)
in
let overwritten_prechals =
Array.map prechals
Expand Down
9 changes: 5 additions & 4 deletions src/lib/pickles/step.ml
Original file line number Diff line number Diff line change
Expand Up @@ -334,15 +334,15 @@ struct
}
in
let polyscale = scalar_chal O.v in
let r = scalar_chal O.u in
let evalscale = scalar_chal O.u in
let sponge_digest_before_evaluations = O.digest_before_evaluations o in
let to_field =
SC.to_field_constant
(module Tock.Field)
~endo:Endo.Step_inner_curve.scalar
in
let module As_field = struct
let r = to_field r
let evalscale = to_field evalscale

let polyscale = to_field polyscale

Expand All @@ -368,7 +368,7 @@ struct
let open As_field in
let b =
let open Tock.Field in
challenge_polynomial zeta + (r * challenge_polynomial zetaw)
challenge_polynomial zeta + (evalscale * challenge_polynomial zetaw)
in
let prechals =
Vector.of_list_and_length_exn
Expand Down Expand Up @@ -492,7 +492,8 @@ struct
in
let open Tock.Field in
combine ~which_eval:`Fst ~ft_eval:ft_eval0 As_field.zeta
+ (r * combine ~which_eval:`Snd ~ft_eval:proof.openings.ft_eval1 zetaw)
+ evalscale
* combine ~which_eval:`Snd ~ft_eval:proof.openings.ft_eval1 zetaw
in
let chal = Challenge.Constant.of_tock_field in
let plonk =
Expand Down
20 changes: 10 additions & 10 deletions src/lib/pickles/step_verifier.ml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ struct

let check_bulletproof ~pcs_batch ~(sponge : Sponge.t) ~polyscale
~(* Corresponds to y in figure 7 of WTS *)
(* sum_i r^i sum_j polyscale^j f_j(beta_i) *)
(* sum_i evalscale^i sum_j polyscale^j f_j(beta_i) *)
(advice : _ Bulletproof.Advice.t)
~polynomials:(without_degree_bound, with_degree_bound)
~opening:
Expand All @@ -231,8 +231,8 @@ struct
| Shifted_value.Type2.Shifted_value x ->
x ) ;
(* a_hat should be equal to
sum_i < t, r^i pows(beta_i) >
= sum_i r^i < t, pows(beta_i) > *)
sum_i < t, evalscale^i pows(beta_i) >
= sum_i evalscale^i < t, pows(beta_i) > *)
let u =
let t = Sponge.squeeze_field sponge in
group_map t
Expand Down Expand Up @@ -555,7 +555,7 @@ struct
let sponge_before_evaluations = Sponge.copy sponge in
let sponge_digest_before_evaluations = Sponge.squeeze_field sponge in

(* polyscale, r are sampled here using the other sponge. *)
(* polyscale, evalscale are sampled here using the other sponge. *)
(* No need to expose the polynomial evaluations as deferred values as they're
not needed here for the incremental verification. All we need is a_hat and
"combined_inner_product".
Expand Down Expand Up @@ -814,7 +814,7 @@ struct

(* This finalizes the "deferred values" coming from a previous proof over the same field.
It
1. Checks that [polyscale] and [r] where sampled correctly. I.e., by absorbing all the
1. Checks that [polyscale] and [evalscale] where sampled correctly. I.e., by absorbing all the
evaluation openings and then squeezing.
2. Checks that the "combined inner product" value used in the elliptic curve part of
the opening proof was computed correctly, in terms of the evaluation openings and the
Expand Down Expand Up @@ -948,15 +948,15 @@ struct
sponge.state <- sponge_state ;
let squeeze () = squeeze_challenge sponge in
let polyscale_actual = squeeze () in
let r_actual = squeeze () in
let evalscale_actual = squeeze () in
let polyscale_correct =
Field.equal polyscale_actual
( match polyscale with
| { Import.Scalar_challenge.inner = polyscale } ->
polyscale )
in
let polyscale = scalar polyscale in
let r = scalar (Import.Scalar_challenge.create r_actual) in
let evalscale = scalar (Import.Scalar_challenge.create evalscale_actual) in
let plonk_minimal =
Plonk.to_minimal plonk ~to_option:Opt.to_option_unsafe
in
Expand Down Expand Up @@ -1015,7 +1015,7 @@ struct
in
print_fp "ft_eval0" ft_eval0 ;
print_fp "ft_eval1" ft_eval1 ;
(* sum_i r^i sum_j polyscale^j f_j(beta_i) *)
(* sum_i evalscale^i sum_j polyscale^j f_j(beta_i) *)
let actual_combined_inner_product =
let combine ~ft ~sg_evals x_hat
(e : (Field.t array, _) Evals.In_circuit.t) =
Expand All @@ -1042,7 +1042,7 @@ struct
with_label "combine" (fun () ->
combine ~ft:ft_eval0 ~sg_evals:sg_evals1 evals1.public_input
evals1.evals
+ r
+ evalscale
* combine ~ft:ft_eval1 ~sg_evals:sg_evals2 evals2.public_input
evals2.evals )
in
Expand All @@ -1065,7 +1065,7 @@ struct
(challenge_polynomial (Vector.to_array bulletproof_challenges))
in
let b_actual =
challenge_poly plonk.zeta + (r * challenge_poly zetaw)
challenge_poly plonk.zeta + (evalscale * challenge_poly zetaw)
in
let b_used =
Shifted_value.Type1.to_field (module Field) ~shift:shift1 b
Expand Down
9 changes: 5 additions & 4 deletions src/lib/pickles/verify.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@ let verify_heterogenous (ts : Instance.t list) =
~metadata:[ ("count", `Int (List.length ts)) ] ;
let tick_field : _ Plonk_checks.field = (module Tick_field) in
let check, result =
let r = ref [] in
let list_ref = ref [] in
let result () =
match !r with
match !list_ref with
| [] ->
Ok ()
| _ ->
Error
( Error.tag ~tag:"Pickles.verify"
@@ Error.of_list
@@ List.map !r ~f:(fun lab -> Error.of_string (Lazy.force lab)) )
@@ List.map !list_ref ~f:(fun lab ->
Error.of_string (Lazy.force lab) ) )
in
((fun (lab, b) -> if not b then r := lab :: !r), result)
((fun (lab, b) -> if not b then list_ref := lab :: !list_ref), result)
in
[%log internal] "Compute_plonks_and_chals" ;
let _computed_bp_chals, deferred_values =
Expand Down
20 changes: 10 additions & 10 deletions src/lib/pickles/wrap.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ module Type1 =
let _vector_of_list (type a t)
(module V : Snarky_intf.Vector.S with type elt = a and type t = t)
(xs : a list) : t =
let r = V.create () in
List.iter xs ~f:(V.emplace_back r) ;
r
let res = V.create () in
List.iter xs ~f:(V.emplace_back res) ;
res

let tick_rounds = Nat.to_int Tick.Rounds.n

let combined_inner_product (type actual_proofs_verified) ~env ~domain ~ft_eval1
~actual_proofs_verified:
(module AB : Nat.Add.Intf with type n = actual_proofs_verified)
(e : (_ array * _ array, _) Plonk_types.All_evals.With_public_input.t)
~(old_bulletproof_challenges : (_, actual_proofs_verified) Vector.t) ~r
~plonk ~polyscale ~zeta ~zetaw =
~(old_bulletproof_challenges : (_, actual_proofs_verified) Vector.t)
~evalscale ~plonk ~polyscale ~zeta ~zetaw =
let combined_evals =
Plonk_checks.evals_of_split_evals ~zeta ~zetaw
(module Tick.Field)
Expand Down Expand Up @@ -70,7 +70,7 @@ let combined_inner_product (type actual_proofs_verified) ~env ~domain ~ft_eval1
in
let open Tick.Field in
combine ~which_eval:`Fst ~ft:ft_eval0 zeta
+ (r * combine ~which_eval:`Snd ~ft:ft_eval1 zetaw)
+ (evalscale * combine ~which_eval:`Snd ~ft:ft_eval1 zetaw)

module For_tests_only = struct
type shifted_tick_field =
Expand Down Expand Up @@ -139,15 +139,15 @@ module For_tests_only = struct
; feature_flags = actual_feature_flags
}
in
let r = scalar_chal O.u in
let evalscale = scalar_chal O.u in
let polyscale = scalar_chal O.v in
let module As_field = struct
let to_field =
SC.to_field_constant
(module Tick.Field)
~endo:Endo.Wrap_inner_curve.scalar

let r = to_field r
let evalscale = to_field evalscale

let polyscale = to_field polyscale

Expand Down Expand Up @@ -229,7 +229,7 @@ module For_tests_only = struct
let open As_field in
let b =
let open Tick.Field in
challenge_poly zeta + (r * challenge_poly zetaw)
challenge_poly zeta + (evalscale * challenge_poly zetaw)
in
let prechals = Array.map prechals ~f:Bulletproof_challenge.unpack in
(prechals, b)
Expand All @@ -250,7 +250,7 @@ module For_tests_only = struct
~actual_proofs_verified:
(Nat.Add.create actual_proofs_verified)
{ evals = proof.proof.openings.evals; public_input = x_hat }
~r ~polyscale ~zeta ~zetaw
~evalscale ~polyscale ~zeta ~zetaw
~old_bulletproof_challenges:prev_challenges ~env:tick_env
~domain:tick_domain ~ft_eval1:proof.proof.openings.ft_eval1
~plonk:tick_plonk_minimal)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pickles/wrap.mli
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ val combined_inner_product :
( (Backend.Tick.Field.t, 'a) Pickles_types.Vector.t
, 'actual_proofs_verified )
Pickles_types.Vector.t
-> r:Backend.Tick.Field.t
-> evalscale:Backend.Tick.Field.t
-> plonk:
( Backend.Tick.Field.t
, Backend.Tick.Field.t
Expand Down
8 changes: 4 additions & 4 deletions src/lib/pickles/wrap_deferred_values.ml
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ let expand_deferred (type n most_recent_width) ~zk_rows
Array.iter ~f:absorb x1 ; Array.iter ~f:absorb x2 ) ) ;
let polyscale_chal = squeeze () in
let polyscale = sc polyscale_chal in
let r_chal = squeeze () in
let r = sc r_chal in
let evalscale_chal = squeeze () in
let evalscale = sc evalscale_chal in
Timer.clock __LOC__ ;
(* TODO: The deferred values "bulletproof_challenges" should get routed
into a "batch dlog Tick acc verifier" *)
Expand All @@ -173,7 +173,7 @@ let expand_deferred (type n most_recent_width) ~zk_rows
Wrap.combined_inner_product ~env:tick_env ~plonk:tick_plonk_minimal
~domain:tick_domain ~ft_eval1:evals.ft_eval1
~actual_proofs_verified:(Nat.Add.create actual_proofs_verified)
evals.evals ~old_bulletproof_challenges ~r ~polyscale ~zeta ~zetaw
evals.evals ~old_bulletproof_challenges ~evalscale ~polyscale ~zeta ~zetaw
in
Timer.clock __LOC__ ;
let bulletproof_challenges =
Expand All @@ -185,7 +185,7 @@ let expand_deferred (type n most_recent_width) ~zk_rows
unstage
(Wrap.challenge_polynomial (Vector.to_array bulletproof_challenges))
in
Tick.Field.(challenge_poly zeta + (r * challenge_poly zetaw))
Tick.Field.(challenge_poly zeta + (evalscale * challenge_poly zetaw))
in
let to_shifted =
Shifted_value.Type1.of_field (module Tick.Field) ~shift:Shifts.tick1
Expand Down
Loading

0 comments on commit 37a4f1b

Please sign in to comment.