Skip to content

Commit

Permalink
convert poseidon params from strings just once
Browse files Browse the repository at this point in the history
  • Loading branch information
mitschabaude committed Aug 16, 2023
1 parent 2c192f4 commit 8ee87dc
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,9 @@ module Fp_poly_comm = Kimchi_backend_common.Poly_comm.Make (struct
fun unshifted shifted : t -> { shifted; unshifted }
end
end)

(* poseidon params *)

let poseidon_params_fp = Sponge.Params.(map pasta_p_kimchi ~f:Fp.of_string)

let poseidon_params_fq = Sponge.Params.(map pasta_q_kimchi ~f:Fq.of_string)
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@ open Kimchi_pasta_basic
include
Plonk_constraint_system.Make (Fq) (Kimchi_bindings.Protocol.Gates.Vector.Fq)
(struct
let params =
Sponge.Params.(
map pasta_q_kimchi ~f:(fun x ->
Fq.of_bigint (Bigint256.of_decimal_string x) ))
let params = poseidon_params_fq
end)
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@ open Kimchi_pasta_basic
include
Plonk_constraint_system.Make (Fp) (Kimchi_bindings.Protocol.Gates.Vector.Fp)
(struct
let params =
Sponge.Params.(
map pasta_p_kimchi ~f:(fun x ->
Fp.of_bigint (Bigint256.of_decimal_string x) ))
let params = poseidon_params_fp
end)
3 changes: 1 addition & 2 deletions src/lib/pickles/step_main_inputs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ open Import

let high_entropy_bits = 128

let sponge_params_constant =
Sponge.Params.(map pasta_p_kimchi ~f:Impl.Field.Constant.of_string)
let sponge_params_constant = Kimchi_pasta_basic.poseidon_params_fp

let tick_field_random_oracle ?(length = Tick.Field.size_in_bits - 1) s =
Tick.Field.of_bits (Ro.bits_random_oracle ~length s)
Expand Down
9 changes: 1 addition & 8 deletions src/lib/pickles/tick_field_sponge.ml
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
include Make_sponge.Make (Backend.Tick.Field)

let params =
(* HACK *)
Sponge.Params.(
let testbit n i = Bigint.(equal (shift_right n i land one) one) in
map pasta_p_kimchi ~f:(fun s ->
Backend.Tick.Field.of_bits
(List.init Backend.Tick.Field.size_in_bits
(testbit (Bigint.of_string s)) ) ))
let params = Kimchi_pasta_basic.poseidon_params_fp
9 changes: 1 addition & 8 deletions src/lib/pickles/tock_field_sponge.ml
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
include Make_sponge.Make (Backend.Tock.Field)

let params =
(* HACK *)
Sponge.Params.(
let testbit n i = Bigint.(equal (shift_right n i land one) one) in
map pasta_q_kimchi ~f:(fun s ->
Backend.Tock.Field.of_bits
(List.init Backend.Tock.Field.size_in_bits
(testbit (Bigint.of_string s)) ) ))
let params = Kimchi_pasta_basic.poseidon_params_fq
3 changes: 1 addition & 2 deletions src/lib/pickles/wrap_main_inputs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ open Import

let high_entropy_bits = 128

let sponge_params_constant =
Sponge.Params.(map pasta_q_kimchi ~f:Impl.Field.Constant.of_string)
let sponge_params_constant = Kimchi_pasta_basic.poseidon_params_fq

let field_random_oracle ?(length = Me.Field.size_in_bits - 1) s =
Me.Field.of_bits (Ro.bits_random_oracle ~length s)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let block_cipher _params (s : Field.t array) =

let%test_unit "check rust implementation of block-cipher" =
let params' : Field.t Sponge.Params.t =
Sponge.Params.(map pasta_p_kimchi ~f:Field.of_string)
Kimchi_pasta_basic.poseidon_params_fp
in
let open Pickles.Impls.Step in
let module T = Internal_Basic in
Expand Down
3 changes: 1 addition & 2 deletions src/lib/random_oracle/random_oracle.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ end

module Input = Random_oracle_input

let params : Field.t Sponge.Params.t =
Sponge.Params.(map pasta_p_kimchi ~f:Field.of_string)
let params : Field.t Sponge.Params.t = Kimchi_pasta_basic.poseidon_params_fp

module Operations = struct
let add_assign ~state i x = Field.(state.(i) <- state.(i) + x)
Expand Down

0 comments on commit 8ee87dc

Please sign in to comment.