Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove hardcoded values for zk_rows and num_chunks in Pickles code #16092

Merged
merged 6 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/lib/pickles/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ struct
~storables:
{ step_storable; step_vk_storable; wrap_storable; wrap_vk_storable }
~proof_cache ?disk_keys ?override_wrap_domain ?override_wrap_main
?(num_chunks = 1) ~branches:(module Branches) ~max_proofs_verified ~name
?(num_chunks = Plonk_checks.num_chunks_by_default)
~branches:(module Branches) ~max_proofs_verified ~name
?constraint_constants ~public_input ~auxiliary_typ ~choices () ->
let snark_keys_header kind constraint_system_hash =
let constraint_constants : Snark_keys_header.Constraint_constants.t =
Expand Down Expand Up @@ -877,8 +878,8 @@ struct
; num_chunks
; zk_rows =
( match num_chunks with
| 1 ->
3
| 1 (* cannot match with Plonk_checks.num_chunks_by_default *) ->
Plonk_checks.zk_rows_by_default
| num_chunks ->
let permuts = 7 in
((2 * (permuts + 1) * num_chunks) - 2 + permuts) / permuts )
Expand Down Expand Up @@ -932,8 +933,8 @@ module Side_loaded = struct
; branches = Verification_key.Max_branches.n
; feature_flags =
Plonk_types.Features.to_full ~or_:Opt.Flag.( ||| ) feature_flags
; num_chunks = 1
; zk_rows = 3
; num_chunks = Plonk_checks.num_chunks_by_default
; zk_rows = Plonk_checks.zk_rows_by_default
}

module Proof = struct
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 @@ -254,8 +254,8 @@ module Make_str (_ : Wire_types.Concrete) = struct
; branches = Verification_key.Max_branches.n
; feature_flags =
Plonk_types.(Features.to_full ~or_:Opt.Flag.( ||| ) feature_flags)
; num_chunks = 1
; zk_rows = 3
; num_chunks = Plonk_checks.num_chunks_by_default
; zk_rows = Plonk_checks.zk_rows_by_default
}

module Proof = struct
Expand Down Expand Up @@ -1834,8 +1834,8 @@ module Make_str (_ : Wire_types.Concrete) = struct
Lazy.map wrap_vk ~f:(Promise.map ~f:Verification_key.index)
; wrap_domains
; step_domains
; num_chunks = 1
; zk_rows = 3
; num_chunks = Plonk_checks.num_chunks_by_default
; zk_rows = Plonk_checks.zk_rows_by_default
}
in
Types_map.add_exn self data ;
Expand Down
6 changes: 5 additions & 1 deletion src/lib/pickles/plonk_checks/plonk_checks.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ module Scalars = Scalars
module Domain = Domain
module Opt = Opt

let num_chunks_by_default = 1

let zk_rows_by_default = 3

type 'field plonk_domain =
< vanishing_polynomial : 'field -> 'field
; shifts : 'field Plonk_types.Shifts.t
Expand Down Expand Up @@ -248,7 +252,7 @@ let scalars_env (type boolean t) (module B : Bool_intf with type t = boolean)
let next_term = ref omega_to_minus_2 in
let omega_to_intermediate_powers =
Array.init
Stdlib.(zk_rows - 3)
Stdlib.(zk_rows - zk_rows_by_default)
~f:(fun _ ->
let term = !next_term in
next_term := term * omega_to_minus_1 ;
Expand Down
6 changes: 6 additions & 0 deletions src/lib/pickles/plonk_checks/plonk_checks.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
open Pickles_types

(** The default number of chunks in a circuit is one (< 2^16 rows) *)
val num_chunks_by_default : int

(** The number of rows required for zero knowledge in circuits with one single chunk *)
val zk_rows_by_default : int

type 'field plonk_domain =
< vanishing_polynomial : 'field -> 'field
; shifts : 'field Pickles_types.Plonk_types.Shifts.t
Expand Down
5 changes: 4 additions & 1 deletion src/lib/pickles/proof.ml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ let dummy (type w h r) (_w : w Nat.t) (h : h Nat.t)
let g0 = Tock.Curve.(to_affine_exn one) in
let g len = Array.create ~len g0 in
let tick_arr len = Array.init len ~f:(fun _ -> tick ()) in
let lengths = Commitment_lengths.default ~num_chunks:1 (* TODO *) in
let lengths =
Commitment_lengths.default
~num_chunks:Plonk_checks.num_chunks_by_default (* TODO *)
in
T
{ statement =
{ proof_state =
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pickles/side_loaded_verification_key.ml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ module Stable = struct
} )
; shifts = Common.tock_shifts ~log2_size
; lookup_index = None
; zk_rows = 3
; zk_rows = Plonk_checks.zk_rows_by_default
} )
in
{ Poly.max_proofs_verified
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pickles/step.ml
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ struct
(module Env_bool)
(module Env_field)
~domain:tock_domain ~srs_length_log2:Common.Max_degree.wrap_log2
~zk_rows:3
~zk_rows:Plonk_checks.zk_rows_by_default
~field_of_hex:(fun s ->
Kimchi_pasta.Pasta.Bigint256.of_hex_string s
|> Kimchi_pasta.Pasta.Fq.of_bigint )
Expand Down
4 changes: 2 additions & 2 deletions src/lib/pickles/step_branch_data.ml
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ let create
; num_chunks
; zk_rows =
( match num_chunks with
| 1 ->
3
| 1 (* cannot match with Plonk_checks.num_chunks_by_default *) ->
Plonk_checks.zk_rows_by_default
| num_chunks ->
let permuts = 7 in
((2 * (permuts + 1) * num_chunks) - 2 + permuts) / permuts )
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pickles/step_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ let step_main :
Req.Compute_prev_proof_parts previous_proof_statements )
in
let dlog_plonk_index =
let num_chunks = (* TODO *) 1 in
let num_chunks = (* TODO *) Plonk_checks.num_chunks_by_default in
exists
~request:(fun () -> Req.Wrap_index)
(Plonk_verification_key_evals.typ
Expand Down
3 changes: 2 additions & 1 deletion src/lib/pickles/unfinalized.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ module Constant = struct
Plonk_checks.scalars_env
(module Env_bool)
(module Env_field)
~srs_length_log2:Common.Max_degree.wrap_log2 ~zk_rows:3
~srs_length_log2:Common.Max_degree.wrap_log2
~zk_rows:Plonk_checks.zk_rows_by_default
~endo:Endo.Wrap_inner_curve.base ~mds:Tock_field_sponge.params.mds
~field_of_hex:
(Core_kernel.Fn.compose Tock.Field.of_bigint (fun x ->
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pickles/verification_key.ml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ module Stable = struct
} )
; shifts = Common.tock_shifts ~log2_size
; lookup_index = None
; zk_rows = 3
; zk_rows = Plonk_checks.zk_rows_by_default
}
in
{ commitments = c; data = d; index = t }
Expand Down
8 changes: 4 additions & 4 deletions src/lib/pickles/verify.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ let verify_heterogenous (ts : Instance.t list) =
Timer.start __LOC__ ;
let non_chunking, expected_num_chunks =
let expected_num_chunks =
Option.value_map ~default:1 chunking_data ~f:(fun x ->
x.Instance.num_chunks )
Option.value_map ~default:Plonk_checks.num_chunks_by_default
chunking_data ~f:(fun x -> x.Instance.num_chunks )
in
let exception Is_chunked in
match
Expand Down Expand Up @@ -117,8 +117,8 @@ let verify_heterogenous (ts : Instance.t list) =
Timer.clock __LOC__ ;
let deferred_values =
let zk_rows =
Option.value_map ~default:3 chunking_data ~f:(fun x ->
x.Instance.zk_rows )
Option.value_map ~default:Plonk_checks.zk_rows_by_default
chunking_data ~f:(fun x -> x.Instance.zk_rows )
in
Wrap_deferred_values.expand_deferred ~evals ~zk_rows
~old_bulletproof_challenges ~proof_state
Expand Down
4 changes: 3 additions & 1 deletion src/lib/pickles/wrap_domains.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ struct
lazy
(Promise.return
(Vector.init num_choices ~f:(fun _ ->
let num_chunks = (* TODO *) 1 in
let num_chunks =
(* TODO *) Plonk_checks.num_chunks_by_default
in
let g =
Array.init num_chunks ~f:(fun _ ->
Backend.Tock.Inner_curve.(to_affine_exn one) )
Expand Down
4 changes: 3 additions & 1 deletion src/lib/pickles/wrap_proof.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ let typ : (Checked.t, Constant.t) Typ.t =
(module Impl)
Inner_curve.typ Plonk_types.Features.Full.none ~bool:Boolean.typ
~dummy:Inner_curve.Params.one
~commitment_lengths:(Commitment_lengths.default ~num_chunks:1)
~commitment_lengths:
(Commitment_lengths.default
~num_chunks:Plonk_checks.num_chunks_by_default )
; Types.Step.Bulletproof.typ ~length:(Nat.to_int Tock.Rounds.n)
( Typ.transport Other_field.typ
~there:(fun x ->
Expand Down
7 changes: 5 additions & 2 deletions src/lib/pickles/wrap_verifier.ml
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ struct
Boolean.Unsafe.of_cvar Field.(add (b1 :> t) (b2 :> t)) )
in
let none_sum =
let num_chunks = (* TODO *) 1 in
let num_chunks =
(* TODO *) Plonk_checks.num_chunks_by_default
in
Option.map is_none ~f:(fun (b : Boolean.var) ->
Array.init num_chunks ~f:(fun _ ->
Double.map Inner_curve.one ~f:(( * ) (b :> t)) ) )
Expand Down Expand Up @@ -1576,7 +1578,8 @@ struct
Plonk_checks.scalars_env
(module Env_bool)
(module Env_field)
~srs_length_log2:Common.Max_degree.wrap_log2 ~zk_rows:3
~srs_length_log2:Common.Max_degree.wrap_log2
~zk_rows:Plonk_checks.zk_rows_by_default
~endo:(Impl.Field.constant Endo.Wrap_inner_curve.base)
~mds:sponge_params.mds
~field_of_hex:(fun s ->
Expand Down