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 shifted commitments functionality (part 2) #14656

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
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
7 changes: 3 additions & 4 deletions docs/specs/types_and_structures/common.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ Variable length vector of type `T`

### `PolyComm<T>`

| Field | Type | Description |
| ----------- | ----------- | ----------- |
| `unshifted` | `Vector<T>` | |
| `shifted` | `Option<T>` | |
| Field | Type | Description |
| ------- | ----------- | ----------- |
| `elems` | `Vector<T>` | |

### `CamlPlonkDomain<Fr>`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ module Make (Inputs : Inputs_intf) = struct
match Inputs.Poly_comm.of_backend_without_degree_bound c with
| `Without_degree_bound x ->
x.(0)
| `With_degree_bound _ ->
assert false
in
{ sigma_comm =
Pickles_types.Vector.init Pickles_types.Plonk_types.Permuts.n
Expand All @@ -232,8 +230,6 @@ module Make (Inputs : Inputs_intf) = struct
match Inputs.Poly_comm.of_backend_without_degree_bound c with
| `Without_degree_bound x ->
x
| `With_degree_bound _ ->
assert false
in
let lookup f =
let open Option.Let_syntax in
Expand Down
7 changes: 1 addition & 6 deletions src/lib/crypto/kimchi_backend/common/plonk_dlog_proof.ml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ module type Inputs_intf = sig
type t = Curve.Affine.Backend.t Kimchi_types.poly_comm
end

val of_backend_with_degree_bound : Backend.t -> t

val of_backend_without_degree_bound : Backend.t -> t

val to_backend : t -> Backend.t
Expand Down Expand Up @@ -484,10 +482,7 @@ module Make (Inputs : Inputs_intf) = struct
Array.of_list_map chal_polys
~f:(fun { Challenge_polynomial.commitment = x, y; challenges } ->
{ Kimchi_types.chals = challenges
; comm =
{ Kimchi_types.shifted = None
; unshifted = [| Kimchi_types.Finite (x, y) |]
}
; comm = { elems = [| Kimchi_types.Finite (x, y) |] }
} )
}

Expand Down
66 changes: 15 additions & 51 deletions src/lib/crypto/kimchi_backend/common/poly_comm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,14 @@ module type Inputs_intf = sig
module Backend : sig
type t

val make :
Curve.Affine.Backend.t array -> Curve.Affine.Backend.t option -> t
val make : Curve.Affine.Backend.t array -> t

val shifted : t -> Curve.Affine.Backend.t option

val unshifted : t -> Curve.Affine.Backend.t array
val elems : t -> Curve.Affine.Backend.t array
end
end

type 'a t =
[ `With_degree_bound of
('a * 'a) Pickles_types.Or_infinity.t
Pickles_types.Plonk_types.Poly_comm.With_degree_bound.t
| `Without_degree_bound of
[ `Without_degree_bound of
('a * 'a) Pickles_types.Plonk_types.Poly_comm.Without_degree_bound.t ]

module Make (Inputs : Inputs_intf) = struct
Expand Down Expand Up @@ -70,45 +64,18 @@ module Make (Inputs : Inputs_intf) = struct
| Finite (x, y) ->
Finite (x, y)

let with_degree_bound_to_backend
(commitment :
(Base_field.t * Base_field.t) Pickles_types.Or_infinity.t
Pickles_types.Plonk_types.Poly_comm.With_degree_bound.t ) : Backend.t =
Backend.make
(Array.map ~f:or_infinity_to_backend commitment.unshifted)
(Some (or_infinity_to_backend commitment.shifted))

let without_degree_bound_to_backend
(commitment :
(Base_field.t * Base_field.t)
Pickles_types.Plonk_types.Poly_comm.Without_degree_bound.t ) : Backend.t
=
Backend.make
(Array.map ~f:(fun x -> Kimchi_types.Finite (fst x, snd x)) commitment)
None

let to_backend (t : t) : Backend.t =
match t with
| `With_degree_bound t ->
with_degree_bound_to_backend t
| `Without_degree_bound t ->
without_degree_bound_to_backend t

let of_backend' (t : Backend.t) =
( Backend.unshifted t
, Option.map (Backend.shifted t) ~f:Curve.Affine.of_backend )
match t with `Without_degree_bound t -> without_degree_bound_to_backend t

let of_backend_with_degree_bound (t : Backend.t) : t =
let open Pickles_types.Plonk_types.Poly_comm in
match Backend.shifted t with
| None ->
assert false
| Some shifted ->
let shifted = or_infinity_of_backend shifted in
let unshifted =
Backend.unshifted t |> Array.map ~f:or_infinity_of_backend
in
`With_degree_bound { unshifted; shifted }
let of_backend' (t : Backend.t) = Backend.elems t

(*
type 'a t =
Expand All @@ -120,19 +87,16 @@ module Make (Inputs : Inputs_intf) = struct
]
*)

(* TODO @volhovm Is this even used? It's not part of of_backend' *)
let of_backend_without_degree_bound (t : Backend.t) =
let open Pickles_types.Plonk_types.Poly_comm in
let unshifted = Backend.unshifted t in
match Backend.shifted t with
| None ->
`Without_degree_bound
(Array.map unshifted ~f:(function
| Infinity ->
failwith
"Pickles cannot handle point at infinity. Commitments must \
be representable in affine coordinates"
| Finite (x, y) ->
(x, y) ) )
| _ ->
assert false
let elems = Backend.elems t in
`Without_degree_bound
(Array.map elems ~f:(function
| Infinity ->
failwith
"Pickles cannot handle point at infinity. Commitments must be \
representable in affine coordinates"
| Finite (x, y) ->
(x, y) ) )
end
16 changes: 4 additions & 12 deletions src/lib/crypto/kimchi_backend/pasta/basic/kimchi_pasta_basic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,9 @@ module Fq_poly_comm = Kimchi_backend_common.Poly_comm.Make (struct
module Backend = struct
type t = Curve.Affine.Backend.t Kimchi_types.poly_comm

let shifted ({ shifted; _ } : t) = shifted
let elems ({ elems; _ } : t) = elems

let unshifted ({ unshifted; _ } : t) = unshifted

let make :
Curve.Affine.Backend.t array -> Curve.Affine.Backend.t option -> t =
fun unshifted shifted : t -> { shifted; unshifted }
let make : Curve.Affine.Backend.t array -> t = fun elems : t -> { elems }
end
end)

Expand All @@ -138,13 +134,9 @@ module Fp_poly_comm = Kimchi_backend_common.Poly_comm.Make (struct
module Backend = struct
type t = Curve.Affine.Backend.t Kimchi_types.poly_comm

let shifted ({ shifted; _ } : t) = shifted

let unshifted ({ unshifted; _ } : t) = unshifted
let elems ({ elems; _ } : t) = elems

let make :
Curve.Affine.Backend.t array -> Curve.Affine.Backend.t option -> t =
fun unshifted shifted : t -> { shifted; unshifted }
let make : Curve.Affine.Backend.t array -> t = fun elems : t -> { elems }
end
end)

Expand Down
7 changes: 3 additions & 4 deletions src/lib/crypto/kimchi_bindings/js/test/bindings_js_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,7 @@ let _ =
end )

let eq_poly_comm ~field_equal (x : _ poly_comm) (y : _ poly_comm) =
Array.for_all2 (eq_affine ~field_equal) x.unshifted y.unshifted
&& Option.equal (eq_affine ~field_equal) x.shifted y.shifted
Array.for_all2 (eq_affine ~field_equal) x.elems y.elems

module Backend = Kimchi_backend.Pasta.Pallas_based_plonk

Expand Down Expand Up @@ -700,7 +699,7 @@ let _ =
let inputs2 = Array.init 64 Pasta_fp.of_int in
let affines =
Array.init 16 (fun i ->
try lcomm1.unshifted.(i)
try lcomm1.elems.(i)
with _ -> Pasta_vesta.random () |> Pasta_vesta.to_affine )
in
let res = batch_accumulator_check second affines inputs2 in
Expand Down Expand Up @@ -732,7 +731,7 @@ let _ =
let inputs2 = Array.init 64 Pasta_fq.of_int in
let affines =
Array.init 16 (fun i ->
try lcomm1.unshifted.(i)
try lcomm1.elems.(i)
with _ -> Pasta_pallas.random () |> Pasta_pallas.to_affine )
in
let res = batch_accumulator_check second affines inputs2 in
Expand Down
3 changes: 1 addition & 2 deletions src/lib/crypto/kimchi_bindings/stubs/kimchi_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ type nonrec 'caml_f proof_evaluations =
; foreign_field_mul_lookup_selector : 'caml_f array point_evaluations option
}

type nonrec 'caml_g poly_comm =
{ unshifted : 'caml_g array; shifted : 'caml_g option }
type nonrec 'caml_g poly_comm = { elems : 'caml_g array } [@@boxed]

type nonrec ('caml_g, 'caml_f) recursion_challenge =
{ chals : 'caml_f array; comm : 'caml_g poly_comm }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ pub fn caml_pasta_fp_plonk_proof_create(
.iter()
.map(Into::<Fp>::into)
.collect();
let comm = PolyComm::<Vesta> {
unshifted: vec![sg],
shifted: None,
};
let comm = PolyComm::<Vesta> { elems: vec![sg] };
RecursionChallenge { chals, comm }
})
.collect()
Expand Down Expand Up @@ -130,10 +127,7 @@ pub fn caml_pasta_fp_plonk_proof_create_and_verify(
.iter()
.map(Into::<Fp>::into)
.collect();
let comm = PolyComm::<Vesta> {
unshifted: vec![sg],
shifted: None,
};
let comm = PolyComm::<Vesta> { elems: vec![sg] };
RecursionChallenge { chals, comm }
})
.collect()
Expand Down Expand Up @@ -975,8 +969,7 @@ pub fn caml_pasta_fp_plonk_proof_dummy() -> CamlProofWithPublic<CamlGVesta, Caml
fn comm() -> PolyComm<Vesta> {
let g = Vesta::prime_subgroup_generator();
PolyComm {
shifted: Some(g),
unshifted: vec![g, g, g],
elems: vec![g, g, g],
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ impl From<CamlPastaFpPlonkVerifierIndex> for VerifierIndex<Vesta, OpeningProof<V
};

// TODO dummy_lookup_value ?
let (linearization, powers_of_alpha) =
expr_linearization(Some(&feature_flags), true);
let (linearization, powers_of_alpha) = expr_linearization(Some(&feature_flags), true);

VerifierIndex::<Vesta, OpeningProof<Vesta>> {
domain,
Expand Down Expand Up @@ -244,8 +243,7 @@ pub fn caml_pasta_fp_plonk_verifier_index_dummy() -> CamlPastaFpPlonkVerifierInd
fn comm() -> CamlPolyComm<CamlGVesta> {
let g: CamlGVesta = Vesta::prime_subgroup_generator().into();
CamlPolyComm {
shifted: Some(g),
unshifted: vec![g, g, g],
elems: vec![g, g, g],
}
}
fn vec_comm(num: usize) -> Vec<CamlPolyComm<CamlGVesta>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ pub fn caml_pasta_fq_plonk_proof_create(
.iter()
.map(Into::<Fq>::into)
.collect();
let comm = PolyComm::<Pallas> {
unshifted: vec![sg],
shifted: None,
};
let comm = PolyComm::<Pallas> { elems: vec![sg] };
RecursionChallenge { chals, comm }
})
.collect()
Expand Down Expand Up @@ -161,8 +158,7 @@ pub fn caml_pasta_fq_plonk_proof_dummy() -> CamlProofWithPublic<CamlGPallas, Cam
fn comm() -> PolyComm<Pallas> {
let g = Pallas::prime_subgroup_generator();
PolyComm {
shifted: Some(g),
unshifted: vec![g, g, g],
elems: vec![g, g, g],
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ impl From<CamlPastaFqPlonkVerifierIndex> for VerifierIndex<Pallas, OpeningProof<
};

// TODO dummy_lookup_value ?
let (linearization, powers_of_alpha) =
expr_linearization(Some(&feature_flags), true);
let (linearization, powers_of_alpha) = expr_linearization(Some(&feature_flags), true);

VerifierIndex::<Pallas, OpeningProof<Pallas>> {
domain,
Expand Down Expand Up @@ -243,8 +242,7 @@ pub fn caml_pasta_fq_plonk_verifier_index_dummy() -> CamlPastaFqPlonkVerifierInd
fn comm() -> CamlPolyComm<CamlGPallas> {
let g: CamlGPallas = Pallas::prime_subgroup_generator().into();
CamlPolyComm {
shifted: Some(g),
unshifted: vec![g, g, g],
elems: vec![g, g, g],
}
}
fn vec_comm(num: usize) -> Vec<CamlPolyComm<CamlGPallas>> {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/crypto/kimchi_bindings/stubs/src/srs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ macro_rules! impl_srs {
let evals = evals.into_iter().map(Into::into).collect();
let p = Evaluations::<$F>::from_vec_and_domain(evals, x_domain).interpolate();

Ok(srs.commit_non_hiding(&p, 1, None).into())
Ok(srs.commit_non_hiding(&p, 1).into())
}

#[ocaml_gen::func]
Expand All @@ -135,7 +135,7 @@ macro_rules! impl_srs {
let coeffs = b_poly_coefficients(&chals);
let p = DensePolynomial::<$F>::from_coefficients_vec(coeffs);

Ok(srs.commit_non_hiding(&p, 1, None).into())
Ok(srs.commit_non_hiding(&p, 1).into())
}

#[ocaml_gen::func]
Expand Down
6 changes: 2 additions & 4 deletions src/lib/crypto/kimchi_bindings/wasm/src/plonk_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,7 @@ macro_rules! impl_proof {
.map(|a| a.clone().into())
.collect();
let comm = PolyComm::<$G> {
unshifted: vec![sg],
shifted: None,
elems: vec![sg],
};
RecursionChallenge { chals, comm }
})
Expand Down Expand Up @@ -785,8 +784,7 @@ macro_rules! impl_proof {
fn comm() -> PolyComm<$G> {
let g = $G::prime_subgroup_generator();
PolyComm {
shifted: Some(g),
unshifted: vec![g, g, g],
elems: vec![g, g, g],
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -956,8 +956,7 @@ macro_rules! impl_verification_key {
fn comm() -> $WasmPolyComm {
let g: $WasmG = $G::prime_subgroup_generator().into();
$WasmPolyComm {
shifted: None,
unshifted: vec![g].into(),
elems: vec![g].into(),
}
}
fn vec_comm(num: usize) -> WasmVector<$WasmPolyComm> {
Expand Down
Loading