From 1c48c81b421d8e5d81f6f4034d5eb2511b074b3d Mon Sep 17 00:00:00 2001 From: Joseph Spadavecchia Date: Thu, 1 Feb 2024 12:08:07 +0000 Subject: [PATCH] =?UTF-8?q?Fixed=20Cell=20evaluation=20issue=20and=20field?= =?UTF-8?q?=20type=20generic=20issue=C2=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/pickles/plonk_checks/dune | 2 + .../plonk_checks/gen_scalars/gen_scalars.ml | 15 +- src/lib/pickles/plonk_checks/plonk_checks.ml | 263 +++++++----------- src/lib/pickles/plonk_checks/plonk_checks.mli | 32 ++- src/lib/pickles/plonk_checks/scalars.ml | 15 +- src/lib/pickles/step_verifier.ml | 18 +- .../test/rpn_gatedef/test_rpn_gatedef.ml | 147 +++++++--- src/lib/pickles/wrap.ml | 26 +- 8 files changed, 274 insertions(+), 244 deletions(-) diff --git a/src/lib/pickles/plonk_checks/dune b/src/lib/pickles/plonk_checks/dune index 354b6b351de..3dc99acbb9e 100644 --- a/src/lib/pickles/plonk_checks/dune +++ b/src/lib/pickles/plonk_checks/dune @@ -20,6 +20,8 @@ pickles_base pickles.backend pickles.composition_types + kimchi_backend.pasta.basic + kimchi_backend.pasta kimchi_backend kimchi_types snarky.backendless 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 f5a7c654d9e..e8dede6bffc 100644 --- a/src/lib/pickles/plonk_checks/gen_scalars/gen_scalars.ml +++ b/src/lib/pickles/plonk_checks/gen_scalars/gen_scalars.ml @@ -14,8 +14,7 @@ let () = (* turn off fragile pattern-matching warning from sexp ppx *) [@@@warning "-4"] -type curr_or_next = Curr | Next -[@@deriving hash, eq, compare, sexp] +type curr_or_next = Kimchi_types.curr_or_next = Curr | Next [@@deriving hash, eq, compare, sexp] module Gate_type = struct module T = struct @@ -60,19 +59,19 @@ module Lookup_pattern = struct end module Column = struct - open Core_kernel - module T = struct - type t = + type t = Kimchi_types.column = | Witness of int - | Index of Gate_type.t - | Coefficient of int - | LookupTable + | Z | LookupSorted of int | LookupAggreg + | LookupTable | LookupKindIndex of Lookup_pattern.t | LookupRuntimeSelector | LookupRuntimeTable + | Index of Gate_type.t + | Coefficient of int + | Permutation of int [@@deriving hash, eq, compare, sexp] end diff --git a/src/lib/pickles/plonk_checks/plonk_checks.ml b/src/lib/pickles/plonk_checks/plonk_checks.ml index 395f98201f0..412465801ff 100644 --- a/src/lib/pickles/plonk_checks/plonk_checks.ml +++ b/src/lib/pickles/plonk_checks/plonk_checks.ml @@ -48,6 +48,14 @@ module type Field_intf = sig val inv : t -> t val negate : t -> t + (* + module Constant : sig + (** The finite field over which the R1CS operates. *) + type t = field [@@deriving bin_io, sexp, hash, compare] + + (** Return a constraint system constant representing the given value. *) + val constant : ('var, 'value) Typ.t -> 'value -> 'var + end *) end module type Field_with_if_intf = sig @@ -197,6 +205,10 @@ let scalars_env (type boolean t) (module B : Bool_intf with type t = boolean) i () | Coefficient i -> get_eval coefficients.(i) + | Permutation _i -> + failwith "Not implemented" + | Z -> + failwith "Not implemented" | LookupTable -> get_eval (Opt.value_exn e.lookup_table) | LookupSorted i -> @@ -339,20 +351,86 @@ let scalars_env (type boolean t) (module B : Bool_intf with type t = boolean) let perm_alpha0 : int = 21 module Make (Shifted_value : Shifted_value.S) (Sc : Scalars.S) = struct + let evaluate_rpn (type t u) (module F : Field_intf with type t = t) + ~(* (module U : Field_intf with type t = u) *) (env : t Scalars.Env.t) + ~(gate_rpn : u Kimchi_types.polish_token array) + ~(* ~(gate_rpn : Kimchi_pasta_basic.Fp.t Kimchi_types.polish_token array) *) + map_constant = + (* ~(_evals : (_ * _, _) Plonk_types.Evals.In_circuit.t) *) + (* ~(gate_rpn : Kimchi_pasta_basic.Fp.t Kimchi_types.polish_token array) = *) + printf "HI\n" ; + + let stack = Stack.create () in + Array.iteri gate_rpn ~f:(fun _idx token -> + Kimchi_types.( + match token with + | Alpha -> + Stack.push stack @@ env.alpha_pow 1 + (* JES: CHECK: Where just plain alpha? *) + | Beta -> + Stack.push stack env.beta + | Gamma -> + Stack.push stack env.gamma + | JointCombiner -> + Stack.push stack env.joint_combiner + | EndoCoefficient -> + Stack.push stack env.endo_coefficient + | Mds mds -> + Stack.push stack @@ env.mds (mds.row, mds.col) + (* JES: CHECK: is this (row, col) format *) + | VanishesOnZeroKnowledgeAndPreviousRows -> + Stack.push stack env.vanishes_on_zero_knowledge_and_previous_rows + | UnnormalizedLagrangeBasis i -> + Stack.push stack + @@ env.unnormalized_lagrange_basis + (i.zk_rows, Int32.to_int_exn i.offset) + | Literal x -> + Stack.push stack @@ map_constant x + | Dup -> + Stack.(push stack @@ top_exn stack) + | Cell v -> + Stack.push stack @@ env.var (v.col, v.row) + | Pow n -> + Stack.( + push stack + @@ pow2pow (module F) (top_exn stack) (Int32.to_int_exn n)) + (* JES: CHECK: Correct way to pow here? *) + | Add -> + Stack.(push stack @@ F.( + ) (pop_exn stack) (pop_exn stack)) + | Mul -> + Stack.(push stack @@ F.( * ) (pop_exn stack) (pop_exn stack)) + | Sub -> + Stack.(push stack @@ F.( - ) (pop_exn stack) (pop_exn stack)) + | Store -> + failwith "Unsupported RPN token: Store" + | Load _ -> + failwith "Unsupported RPN token: Load" + | SkipIf _ -> + failwith "Unsupported RPN token: SkipIf" + | SkipIfNot _ -> + failwith "Unsupported RPN token: SkipIfNot") ) ; + + Stack.pop_exn stack + (** Computes the ft evaluation at zeta. (see https://o1-labs.github.io/mina-book/crypto/plonk/maller_15.html#the-evaluation-of-l) *) - let ft_eval0 (type t) (module F : Field_intf with type t = t) ~domain - ~(env : t Scalars.Env.t) - ({ alpha = _ - ; beta - ; gamma - ; zeta - ; joint_combiner = _ - ; feature_flags = _ - ; _ - } : - _ Minimal.t ) (e : (_ * _, _) Plonk_types.Evals.In_circuit.t) p_eval0 = + let ft_eval0 (type t) (* (type u) *) (module F : Field_intf with type t = t) + ~(* (module U : Field_intf with type t = u) *) domain + ~(env : t Scalars.Env.t) ?custom_gate_type ?map_constant + (* ~(const_map : 'a -> 'b) *) + (* ~(custom_gate_type : Kimchi_pasta_basic.Fp.t Kimchi_types.polish_token array option) *) + (* ?custom_gate_type *) + ({ alpha = _ + ; beta + ; gamma + ; zeta + ; joint_combiner = _ + ; feature_flags = _ + ; _ + } : + _ Minimal.t ) (e : (_ * _, _) Plonk_types.Evals.In_circuit.t) p_eval0 + = let open Plonk_types.Evals.In_circuit in let e0 field = fst (field e) in let e1 field = snd (field e) in @@ -401,6 +479,21 @@ module Make (Shifted_value : Shifted_value.S) (Sc : Scalars.S) = struct (* (1) Create ScalarsMinus, without ffAdd *) let constant_term = Sc.constant_term env + + + match custom_gate_type with + | Some custom_gate_type -> ( + match map_constant with + | Some map_constant -> + evaluate_rpn + (module F) + ~env ~gate_rpn:custom_gate_type ~map_constant + | None -> + failwith "Need constant mapping function" + (* evaluate_rpn + (module F) + ~env ~gate_rpn:custom_gate_type ~map_constant:Fn.id *) ) + | None -> + F.zero (* (2) ~override_ffadd: optional... Sc.evaluate_custom_gate ~env ~polish_gate *) in ft_eval0 - constant_term @@ -478,152 +571,4 @@ module Make (Shifted_value : Shifted_value.S) (Sc : Scalars.S) = struct ~f:(fun f -> Shifted_value.equal Field.equal (f plonk) (f actual)) [ perm ] ) |> Boolean.all ) - - (* let evaluate_rpn (type t) (module F : Field_intf with type t = t) (* ~(_env : t Scalars.Env.t) *) ~(_rpn_gate : t Kimchi_types.polish_token array) = - F.zero *) - - (* let evaluate_rpn (type t) (module F : Field_intf with type t = t) (* ~(_env : t Scalars.Env.t) *) ~(_rpn_gate : t Kimchi_types.polish_token array) = - F.zero *) - - (* let evaluate_rpn (type t) (module F : Field_intf with type t = t) ~(_env : t Scalars.Env.t) ~(_rpn_gate : F.t Kimchi_types.polish_token array) = - F.zero *) - - (* WORKING: let evaluate_rpn (type t) (module F: Field_intf with type t = t) (* ~(_env : t Scalars.Env.t) *) ~(_rpn_gate : t Kimchi_types.polish_token array) = - F.zero *) - - let evaluate_rpn (type t) (module F : Field_intf with type t = t) - ~(_env : t Scalars.Env.t) - ~(_evals : (_ * _, _) Plonk_types.Evals.In_circuit.t) - ~(gate_rpn : t Kimchi_types.polish_token array) = - (* let rec evaluate ~stack ~(_rpn_gate : t Kimchi_types.polish_token array) idx : F.t = - if Array.length rpn_gate = 0 then - Stack.pop_exn stack - else - let elt = Array.get rpn_gate idx in - match elt with - | _ -> F.zero *) - let evaluate_cell (evals : (_ * _, _) Plonk_types.Evals.In_circuit.t) - (var : Kimchi_types.variable) = - (* Kimchi_types.( *) - let witness = Vector.to_array evals.w in - let coefficients = Vector.to_array evals.coefficients in - let permutation_column = Vector.to_array evals.s in - let get_eval = match var.row with Curr -> fst | Next -> snd in - match[@warning "-4"] var.col with - | Witness i -> - get_eval witness.(i) - | Z -> - get_eval evals.z - | LookupSorted i -> - get_eval - (Opt.value_exn - (Option.value_exn (Vector.nth evals.lookup_sorted i)) ) - | LookupAggreg -> - get_eval (Opt.value_exn evals.lookup_aggregation) - | LookupTable -> - get_eval (Opt.value_exn evals.lookup_table) - | LookupRuntimeTable -> - get_eval (Opt.value_exn evals.runtime_lookup_table) - | Index Poseidon -> - get_eval evals.poseidon_selector - | Index Generic -> - get_eval evals.generic_selector - | Index CompleteAdd -> - get_eval evals.complete_add_selector - | Index VarBaseMul -> - get_eval evals.mul_selector - | Index EndoMul -> - get_eval evals.emul_selector - | Index EndoMulScalar -> - get_eval evals.endomul_scalar_selector - | Index RangeCheck0 -> - get_eval (Opt.value_exn evals.range_check0_selector) - | Index RangeCheck1 -> - get_eval (Opt.value_exn evals.range_check1_selector) - | Index ForeignFieldAdd -> - get_eval (Opt.value_exn evals.foreign_field_add_selector) - | Index ForeignFieldMul -> - get_eval (Opt.value_exn evals.foreign_field_mul_selector) - | Index Xor16 -> - get_eval (Opt.value_exn evals.xor_selector) - | Index Rot64 -> - get_eval (Opt.value_exn evals.rot_selector) - | Index i -> - failwithf - !"Index %{sexp:Scalars.Gate_type.t}\n\ - %! should have been linearized away" - i () - | Permutation i -> - get_eval permutation_column.(i) - | Coefficient i -> - get_eval coefficients.(i) - | LookupKindIndex Lookup -> - get_eval (Opt.value_exn evals.lookup_gate_lookup_selector) - | LookupKindIndex Xor -> - get_eval (Opt.value_exn evals.xor_lookup_selector) - | LookupKindIndex RangeCheck -> - get_eval (Opt.value_exn evals.range_check_lookup_selector) - | LookupKindIndex ForeignFieldMul -> - get_eval (Opt.value_exn evals.foreign_field_mul_lookup_selector) - | LookupRuntimeSelector -> - get_eval (Opt.value_exn evals.runtime_lookup_table_selector) - in - - let stack = Stack.create () in - Array.iteri gate_rpn ~f:(fun _idx token -> - Kimchi_types.( - match token with - | Alpha -> - Stack.push stack @@ _env.alpha_pow 1 - (* JES: CHECK: Where just plain alpha? *) - | Beta -> - Stack.push stack _env.beta - | Gamma -> - Stack.push stack _env.gamma - | JointCombiner -> - Stack.push stack _env.joint_combiner - | EndoCoefficient -> - Stack.push stack _env.endo_coefficient - | Mds mds -> - Stack.push stack @@ _env.mds (mds.row, mds.col) - (* JES: CHECK: is this (row, col) format *) - | VanishesOnZeroKnowledgeAndPreviousRows -> - Stack.push stack _env.vanishes_on_zero_knowledge_and_previous_rows - | UnnormalizedLagrangeBasis i -> - Stack.push stack - @@ _env.unnormalized_lagrange_basis - (i.zk_rows, Int32.to_int_exn i.offset) - | Literal x -> - Stack.push stack x - | Dup -> - Stack.(push stack @@ top_exn stack) - | Cell v -> - Stack.push stack @@ evaluate_cell _evals v - (* JES: TODO: would be nice to instead somehow do - Stack.push stack @@ _env.var (v.col, v.row) *) - (* JES: CHECK: How to v.evaluate here? *) - | Pow n -> - Stack.( - push stack - @@ pow2pow (module F) (top_exn stack) (Int32.to_int_exn n)) - (* JES: CHECK: Correct way to pow here? *) - | Add -> - Stack.(push stack @@ F.( + ) (pop_exn stack) (pop_exn stack)) - | Mul -> - Stack.(push stack @@ F.( * ) (pop_exn stack) (pop_exn stack)) - | Sub -> - Stack.(push stack @@ F.( - ) (pop_exn stack) (pop_exn stack)) - | Store -> - failwith "Unsupported RPN token: Store" - | Load _ -> - failwith "Unsupported RPN token: Load" - | SkipIf _ -> - failwith "Unsupported RPN token: SkipIf" - | SkipIfNot _ -> - failwith "Unsupported RPN token: SkipIfNot") ) ; - - Stack.pop_exn stack - - (* let evaluate_rpn (* ~(_env : Backend.Tick.Field.t Scalars.Env.t) *) ~(_rpn_gate : t Kimchi_types.polish_token array) = - F.zero *) end diff --git a/src/lib/pickles/plonk_checks/plonk_checks.mli b/src/lib/pickles/plonk_checks/plonk_checks.mli index 04bcecab18d..6734f75fdb0 100644 --- a/src/lib/pickles/plonk_checks/plonk_checks.mli +++ b/src/lib/pickles/plonk_checks/plonk_checks.mli @@ -89,11 +89,27 @@ val scalars_env : -> 't Scalars.Env.t module Make (Shifted_value : Pickles_types.Shifted_value.S) (_ : Scalars.S) : sig + val evaluate_rpn : + (module Field_intf with type t = 't) + (* -> (module Field_intf with type t = 'u) *) + -> env:'t Scalars.Env.t + (* -> _evals:('t * 't, 'a) Pickles_types.Plonk_types.Evals.In_circuit.t *) + (* -> gate_rpn:Kimchi_pasta_basic.Fp.t Kimchi_types.polish_token array *) + -> gate_rpn:'u Kimchi_types.polish_token array + -> map_constant:('u -> 't) + -> (* -> map_constant:(Kimchi_pasta_basic.Fp.t -> 't) *) + 't + val ft_eval0 : - 't field - -> domain:< shifts : 't array ; .. > + 't field (* -> 'u field *) + -> domain:< shifts : 't array ; .. > (* -> const_map:('a -> 'b) *) -> env:'t Scalars.Env.t - -> ( 't + (* -> ?custom_gate_type:Kimchi_pasta_basic.Fp.t Kimchi_types.polish_token array *) + -> ?custom_gate_type:'u Kimchi_types.polish_token array + -> ?map_constant:('u -> 't) + -> (* -> ?map_constant:(Kimchi_pasta_basic.Fp.t -> 't) *) + (* -> ?custom_gate_type:Kimchi_pasta_basic.Fp.t Kimchi_types.polish_token array *) + ( 't , 't , 'b ) Composition_types.Wrap.Proof_state.Deferred_values.Plonk.Minimal.t @@ -138,16 +154,6 @@ module Make (Shifted_value : Pickles_types.Shifted_value.S) (_ : Scalars.S) : si , 'a ) Pickles_types.Plonk_types.Evals.In_circuit.t -> 't Snarky_backendless.Cvar.t Snarky_backendless.Boolean.t - - val evaluate_rpn : - (module Field_intf with type t = 't) - (* 't field *) - (* 't *) - (* (module Internal_Basic.field with type t = 't) *) - -> _env:'t Scalars.Env.t - -> _evals:('t * 't, 'a) Pickles_types.Plonk_types.Evals.In_circuit.t - -> gate_rpn:'t Kimchi_types.polish_token array - -> 't end (** [Domain] is re-exported from library Pickles_base *) diff --git a/src/lib/pickles/plonk_checks/scalars.ml b/src/lib/pickles/plonk_checks/scalars.ml index cd69d3c48d7..d8e6b792c90 100644 --- a/src/lib/pickles/plonk_checks/scalars.ml +++ b/src/lib/pickles/plonk_checks/scalars.ml @@ -3,7 +3,8 @@ (* turn off fragile pattern-matching warning from sexp ppx *) [@@@warning "-4"] -type curr_or_next = Curr | Next [@@deriving hash, eq, compare, sexp] +type curr_or_next = Kimchi_types.curr_or_next = Curr | Next +[@@deriving hash, eq, compare, sexp] module Gate_type = struct module T = struct @@ -48,19 +49,19 @@ module Lookup_pattern = struct end module Column = struct - open Core_kernel - module T = struct - type t = + type t = Kimchi_types.column = | Witness of int - | Index of Gate_type.t - | Coefficient of int - | LookupTable + | Z | LookupSorted of int | LookupAggreg + | LookupTable | LookupKindIndex of Lookup_pattern.t | LookupRuntimeSelector | LookupRuntimeTable + | Index of Gate_type.t + | Coefficient of int + | Permutation of int [@@deriving hash, eq, compare, sexp] end diff --git a/src/lib/pickles/step_verifier.ml b/src/lib/pickles/step_verifier.ml index 337f07f87fc..7fa886c8dd3 100644 --- a/src/lib/pickles/step_verifier.ml +++ b/src/lib/pickles/step_verifier.ml @@ -1034,14 +1034,16 @@ struct in let ft_eval0 : Field.t = with_label "ft_eval0" (fun () -> - if Option.is_some custom_gate_type then - Plonk_checks.Type1Minus.ft_eval0 - (module Field) - ~env ~domain plonk_minimal combined_evals evals1.public_input - else - Plonk_checks.Type1.ft_eval0 - (module Field) - ~env ~domain plonk_minimal combined_evals evals1.public_input ) + match custom_gate_type with + | Some custom_gate_type -> + Plonk_checks.Type1Minus.ft_eval0 + (module Field) + ~env ~custom_gate_type ~map_constant:Field.constant ~domain + plonk_minimal combined_evals evals1.public_input + | None -> + Plonk_checks.Type1.ft_eval0 + (module Field) + ~env ~domain plonk_minimal combined_evals evals1.public_input ) in print_fp "ft_eval0" ft_eval0 ; diff --git a/src/lib/pickles/test/rpn_gatedef/test_rpn_gatedef.ml b/src/lib/pickles/test/rpn_gatedef/test_rpn_gatedef.ml index dc4a266f4ff..58f45ff3f37 100644 --- a/src/lib/pickles/test/rpn_gatedef/test_rpn_gatedef.ml +++ b/src/lib/pickles/test/rpn_gatedef/test_rpn_gatedef.ml @@ -1,48 +1,120 @@ -(* open Core_kernel *) -(* open Kimchi_types *) +open Core_kernel open Plonk_checks open Pickles_types -(* open Pickles.Impls.Step *) +(* open Base *) +(* open Composition_types *) module Type1 = Plonk_checks.Make (Shifted_value.Type1) (Scalars.Tick) let () = Pickles.Backend.Tick.Keypair.set_urs_info [] let () = - (* let env = - let module Env_bool = struct - include Boolean - - type t = Boolean.var - end in - let module Env_field = struct - include Field - - type bool = Env_bool.t - - let if_ (b : bool) ~then_ ~else_ = - match Impl.Field.to_constant (b :> t) with - | Some x -> - (* We have a constant, only compute the branch we care about. *) - if Impl.Field.Constant.(equal one) x then then_ () else else_ () - | None -> - if_ b ~then_:(then_ ()) ~else_:(else_ ()) - end in - Plonk_checks.scalars_env - (module Env_bool) - (module Env_field) - ~srs_length_log2:Common.Max_degree.wrap_log2 ~zk_rows:3 - ~endo:(Impl.Field.constant Endo.Wrap_inner_curve.base) - ~mds:sponge_params.mds - ~field_of_hex:(fun s -> - Kimchi_pasta.Pasta.Bigint256.of_hex_string s - |> Kimchi_pasta.Pasta.Fq.of_bigint |> Field.constant ) - ~domain plonk_minimal combined_evals - in *) - - (* Type1.evaluate_rpn (module Kimchi_pasta.Vesta_based_plonk.Field) ~_rpn_gate:[||] *) - (* Type1.evaluate_rpn (module Field) ~_rpn_gate:[||] *) - (* Type1.evaluate_rpn (module Backend.Tick.Field) ~_rpn_gate:[||] *) + (* let domain = Domain.Pow_2_roots_of_unity 32 in + let alpha = Backend.Tick.Field.of_int 1 in + let beta = Backend.Tick.Field.of_int 1 in + let gamma = Backend.Tick.Field.of_int 1 in + let joint_combiner = Some (Backend.Tick.Field.of_int 1) in + let zeta = Backend.Tick.Field.of_int 1 in + let zetaw = + Backend.Tick.Field.( + zeta * domain_generator ~log2_size:(Domain.log2_size domain)) + in *) + + (* let to_field = + Pickles.Scalar_challenge.to_field_constant + (module Backend.Tick.Field) + ~endo:Pickles.Endo.Wrap_inner_curve.scalar + in + *) + + (* let prev_evals = + let e = + Plonk_types.Evals.map Evaluation_lengths.default ~f:(fun n -> + (tick_arr n, tick_arr n) ) + in + let ex = + { Plonk_types.All_evals.With_public_input.public_input = ([||], [||]) + ; evals = e + } + in + { ft_eval1 = tick (); evals = ex } + in + *) + + (* + let prev_evals = + let tick_arr len = Array.init len ~f:(fun _ -> tick ()) in + let e = + Plonk_types.Evals.map Evaluation_lengths.default ~f:(fun n -> + (tick_arr n, tick_arr n) ) + in + let ex = + { Plonk_types.All_evals.With_public_input.public_input = ([||], [||]) + ; evals = e + } + in + { Plonk_types.All_evals.ft_eval1 = tick (); evals = ex } + in + + let combined_evals = + Plonk_checks.evals_of_split_evals + (module Backend.Tick.Field) + t.prev_evals.evals.evals + ~rounds:(Nat.to_int Backend.Tick.Rounds.n) + ~zeta ~zetaw + |> Plonk_types.Evals.to_in_circuit + in + + let plonk_minimal = + { Composition_types.Wrap.Proof_state.Deferred_values.Plonk.Minimal.zeta + ; alpha + ; beta + ; gamma + ; joint_combiner + ; feature_flags = Pickles_types.Plonk_types.Features.none_bool + } + in + + let env = + let module Env_bool = struct + type t = bool + + let true_ = true + + let false_ = false + + let ( &&& ) = ( && ) + + let ( ||| ) = ( || ) + + let any = List.exists ~f:Fn.id + end in + + let module Env_field = struct + include Backend.Tick.Field + + type bool = Env_bool.t + + let if_ (b : bool) ~then_ ~else_ = if b then then_ () else else_ () + end in + + Plonk_checks.scalars_env + (module Env_bool) + (module Env_field) + ~srs_length_log2:Pickles.Common.Max_degree.step_log2 + ~zk_rows:3 (* JES: CHECK 3 OK for test? *) + ~endo:Pickles.Endo.Step_inner_curve.base + ~mds:Pickles.Tick_field_sponge.params.mds + ~field_of_hex:(fun s -> + Kimchi_pasta.Pasta.Bigint256.of_hex_string s + |> Kimchi_pasta.Pasta.Fp.of_bigint ) + ~domain: + (Plonk_checks.domain + (module Backend.Tick.Field) + ~shifts:Pickles.Common.tick_shifts domain + ~domain_generator:Backend.Tick.Field.domain_generator ) + plonk_minimal combined_evals + in *) let conditional_gate = Kimchi_types. [| Cell { col = Index ForeignFieldAdd; row = Curr } @@ -69,6 +141,7 @@ let () = ; Mul |] in + printf "Evaluating...\n" ; let _x = Type1.evaluate_rpn (module Pickles.Backend.Tick.Field) diff --git a/src/lib/pickles/wrap.ml b/src/lib/pickles/wrap.ml index 0a7ec731c67..07c397b4239 100644 --- a/src/lib/pickles/wrap.ml +++ b/src/lib/pickles/wrap.ml @@ -51,18 +51,20 @@ let combined_inner_product (type actual_proofs_verified) ~env ~domain ~ft_eval1 ~rounds:tick_rounds e.evals in let ft_eval0 : Tick.Field.t = - if Option.is_some custom_gate_type then - Type1Minus.ft_eval0 - (module Tick.Field) - plonk ~env ~domain - (Plonk_types.Evals.to_in_circuit combined_evals) - (fst e.public_input) - else - Type1.ft_eval0 - (module Tick.Field) - plonk ~env ~domain - (Plonk_types.Evals.to_in_circuit combined_evals) - (fst e.public_input) + match custom_gate_type with + | Some custom_gate_type -> + Type1Minus.ft_eval0 + (module Tick.Field) + plonk ~env ~custom_gate_type (* ~map_constant:Fn.id *) + ~domain + (Plonk_types.Evals.to_in_circuit combined_evals) + (fst e.public_input) + | None -> + Type1.ft_eval0 + (module Tick.Field) + plonk ~env ~domain + (Plonk_types.Evals.to_in_circuit combined_evals) + (fst e.public_input) in let T = AB.eq in let challenge_polys =