Skip to content
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
2 changes: 1 addition & 1 deletion w3f-ring-proof/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ mod tests {
fn setup<R: Rng, CS: PCS<Fq>>(
rng: &mut R,
domain_size: usize,
) -> (CS::Params, PiopParams<Fq, BandersnatchConfig>) {
) -> (CS::Params, PiopParams<EdwardsAffine>) {
let setup_degree = 3 * domain_size;
let pcs_params = CS::setup(setup_degree, rng);

Expand Down
2 changes: 1 addition & 1 deletion w3f-ring-proof/src/piop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl<E: Pairing> VerifierKey<E::ScalarField, KZG<E>> {

pub fn index<F: PrimeField, CS: PCS<F>, Curve: TECurveConfig<BaseField = F>>(
pcs_params: &CS::Params,
piop_params: &PiopParams<F, Curve>,
piop_params: &PiopParams<Affine<Curve>>,
keys: &[Affine<Curve>],
) -> (ProverKey<F, CS, Affine<Curve>>, VerifierKey<F, CS>) {
let pcs_ck = pcs_params.ck();
Expand Down
44 changes: 19 additions & 25 deletions w3f-ring-proof/src/piop/params.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use ark_ec::twisted_edwards::{Affine, TECurveConfig};
use ark_ec::{AdditiveGroup, AffineRepr, CurveGroup};
use ark_ff::{BigInteger, PrimeField};
use ark_ff::{BigInteger, One, PrimeField, Zero};
use ark_std::{vec, vec::Vec};

use w3f_plonk_common::domain::Domain;
Expand All @@ -10,22 +9,22 @@ use crate::piop::FixedColumns;

/// Plonk Interactive Oracle Proofs (PIOP) parameters.
#[derive(Clone)]
pub struct PiopParams<F: PrimeField, Curve: TECurveConfig<BaseField = F>> {
pub struct PiopParams<G: AffineRepr<BaseField: PrimeField>> {
/// Domain over which the piop is represented.
pub domain: Domain<F>,
pub domain: Domain<G::BaseField>,
/// Number of bits used to represent a jubjub scalar.
pub scalar_bitlen: usize,
/// Length of the part of the column representing the public keys (including the padding).
pub keyset_part_size: usize,
/// Blinding base point.
pub h: Affine<Curve>,
pub h: G,
/// Summation base point.
pub seed: Affine<Curve>,
pub seed: G,
/// The point used to pad the list of public keys.
pub padding: Affine<Curve>,
pub padding: G,
}

impl<F: PrimeField, Curve: TECurveConfig<BaseField = F>> PiopParams<F, Curve> {
impl<G: AffineRepr<BaseField: PrimeField>> PiopParams<G> {
/// Initialize PIOP parameters.
///
/// - `domain`: polynomials evaluation domain.
Expand All @@ -34,13 +33,8 @@ impl<F: PrimeField, Curve: TECurveConfig<BaseField = F>> PiopParams<F, Curve> {
/// - `padding`: The point used to pad the list of public keys.
///
/// All points should be of an unknown discrete log.
pub fn setup(
domain: Domain<F>,
h: Affine<Curve>,
seed: Affine<Curve>,
padding: Affine<Curve>,
) -> Self {
let scalar_bitlen = Curve::ScalarField::MODULUS_BIT_SIZE as usize;
pub fn setup(domain: Domain<G::BaseField>, h: G, seed: G, padding: G) -> Self {
let scalar_bitlen = G::ScalarField::MODULUS_BIT_SIZE as usize;
// 1 accounts for the last cells of the points and bits columns that remain unconstrained
let keyset_part_size = domain.capacity - scalar_bitlen - 1;
Self {
Expand All @@ -53,7 +47,7 @@ impl<F: PrimeField, Curve: TECurveConfig<BaseField = F>> PiopParams<F, Curve> {
}
}

pub fn fixed_columns(&self, keys: &[Affine<Curve>]) -> FixedColumns<F, Affine<Curve>> {
pub fn fixed_columns(&self, keys: &[G]) -> FixedColumns<G::BaseField, G> {
let ring_selector = self.keyset_part_selector();
let ring_selector = self.domain.public_column(ring_selector);
let points = self.points_column(&keys);
Expand All @@ -63,7 +57,7 @@ impl<F: PrimeField, Curve: TECurveConfig<BaseField = F>> PiopParams<F, Curve> {
}
}

pub fn points_column(&self, keys: &[Affine<Curve>]) -> AffineColumn<F, Affine<Curve>> {
pub fn points_column(&self, keys: &[G]) -> AffineColumn<G::BaseField, G> {
assert!(keys.len() <= self.keyset_part_size);
let padding_len = self.keyset_part_size - keys.len();
let padding = vec![self.padding; padding_len];
Expand All @@ -72,7 +66,7 @@ impl<F: PrimeField, Curve: TECurveConfig<BaseField = F>> PiopParams<F, Curve> {
AffineColumn::public_column(points, &self.domain)
}

pub fn power_of_2_multiples_of_h(&self) -> Vec<Affine<Curve>> {
pub fn power_of_2_multiples_of_h(&self) -> Vec<G> {
let mut h = self.h.into_group();
let mut multiples = Vec::with_capacity(self.scalar_bitlen);
multiples.push(h);
Expand All @@ -83,29 +77,29 @@ impl<F: PrimeField, Curve: TECurveConfig<BaseField = F>> PiopParams<F, Curve> {
CurveGroup::normalize_batch(&multiples)
}

pub fn scalar_part(&self, e: Curve::ScalarField) -> Vec<bool> {
pub fn scalar_part(&self, e: G::ScalarField) -> Vec<bool> {
let bits_with_trailing_zeroes = e.into_bigint().to_bits_le();
let significant_bits = &bits_with_trailing_zeroes[..self.scalar_bitlen];
significant_bits.to_vec()
}

pub fn keyset_part_selector(&self) -> Vec<F> {
pub fn keyset_part_selector(&self) -> Vec<G::BaseField> {
[
vec![F::one(); self.keyset_part_size],
vec![F::zero(); self.scalar_bitlen],
vec![G::BaseField::one(); self.keyset_part_size],
vec![G::BaseField::zero(); self.scalar_bitlen],
]
.concat()
}

pub fn blind_pk(&self, pk_k: Affine<Curve>, blinding: Curve::ScalarField) -> Affine<Curve> {
pub fn blind_pk(&self, pk_k: G, blinding: G::ScalarField) -> G {
let blinded_pk = pk_k + self.h * blinding;
blinded_pk.into_affine()
}
}

#[cfg(test)]
mod tests {
use ark_ed_on_bls12_381_bandersnatch::{BandersnatchConfig, EdwardsAffine, Fq, Fr};
use ark_ed_on_bls12_381_bandersnatch::{EdwardsAffine, Fr};
use ark_std::ops::Mul;
use ark_std::{test_rng, UniformRand};

Expand All @@ -122,7 +116,7 @@ mod tests {
let padding = EdwardsAffine::rand(rng);
let domain = Domain::new(1024, false);

let params = PiopParams::<Fq, BandersnatchConfig>::setup(domain, h, seed, padding);
let params = PiopParams::<EdwardsAffine>::setup(domain, h, seed, padding);
let t = Fr::rand(rng);
let t_bits = params.scalar_part(t);
let th = cond_sum(&t_bits, &params.power_of_2_multiples_of_h());
Expand Down
4 changes: 2 additions & 2 deletions w3f-ring-proof/src/piop/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub struct PiopProver<F: PrimeField, Curve: TECurveConfig<BaseField = F>> {

impl<F: PrimeField, Curve: TECurveConfig<BaseField = F>> PiopProver<F, Curve> {
pub fn build(
params: &PiopParams<F, Curve>,
params: &PiopParams<Affine<Curve>>,
fixed_columns: FixedColumns<F, Affine<Curve>>,
prover_index_in_keys: usize,
secret: Curve::ScalarField,
Expand Down Expand Up @@ -73,7 +73,7 @@ impl<F: PrimeField, Curve: TECurveConfig<BaseField = F>> PiopProver<F, Curve> {

// TODO: move to params?
fn bits_column(
params: &PiopParams<F, Curve>,
params: &PiopParams<Affine<Curve>>,
index_in_keys: usize,
secret: Curve::ScalarField,
) -> BitColumn<F> {
Expand Down
6 changes: 3 additions & 3 deletions w3f-ring-proof/src/ring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl<
/// - `srs`: Should return `srs[range]` for `range = (piop_params.keyset_part_size..domain_size)`
/// - `g`: Generator used in the SRS
pub fn empty(
piop_params: &PiopParams<F, VrfCurveConfig>,
piop_params: &PiopParams<Affine<VrfCurveConfig>>,
srs: impl Fn(Range<usize>) -> Result<Vec<KzgCurve::G1Affine>, ()>,
g: KzgCurve::G1,
) -> Self {
Expand Down Expand Up @@ -162,7 +162,7 @@ impl<
/// - `piop_params`: SNARK parameters.
/// - `srs`: full-size Lagrangian SRS.
pub fn with_keys(
piop_params: &PiopParams<F, VrfCurveConfig>,
piop_params: &PiopParams<Affine<VrfCurveConfig>>,
keys: &[Affine<VrfCurveConfig>],
srs: &RingBuilderKey<F, KzgCurve>,
) -> Self {
Expand Down Expand Up @@ -329,7 +329,7 @@ mod tests {

fn get_monomial_commitment(
pcs_params: &URS<Bls12_381>,
piop_params: &PiopParams<Fr, BandersnatchConfig>,
piop_params: &PiopParams<EdwardsAffine>,
keys: &[EdwardsAffine],
) -> (G1Affine, G1Affine) {
let (_, verifier_key) =
Expand Down
6 changes: 3 additions & 3 deletions w3f-ring-proof/src/ring_prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ where
Curve: TECurveConfig<BaseField = F>,
T: PlonkTranscript<F, CS>,
{
piop_params: PiopParams<F, Curve>,
piop_params: PiopParams<Affine<Curve>>,
fixed_columns: FixedColumns<F, Affine<Curve>>,
// TODO: We could have a prover that as an optimization stores the commitment to the part of the trace
// TODO: that depends on the prover's index but not the blinding. That would save some computation,
Expand All @@ -35,7 +35,7 @@ where
{
pub fn init(
prover_key: ProverKey<F, CS, Affine<Curve>>,
piop_params: PiopParams<F, Curve>,
piop_params: PiopParams<Affine<Curve>>,
k: usize,
empty_transcript: T,
) -> Self {
Expand Down Expand Up @@ -75,7 +75,7 @@ where
(blinded_pk, proof)
}

pub fn piop_params(&self) -> &PiopParams<F, Curve> {
pub fn piop_params(&self) -> &PiopParams<Affine<Curve>> {
&self.piop_params
}
}
6 changes: 3 additions & 3 deletions w3f-ring-proof/src/ring_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ where
Jubjub: TECurveConfig<BaseField = F>,
T: PlonkTranscript<F, CS>,
{
pub(crate) piop_params: PiopParams<F, Jubjub>,
pub(crate) piop_params: PiopParams<Affine<Jubjub>>,
pub(crate) fixed_columns_committed: FixedColumnsCommitted<F, CS::C>,
pub(crate) plonk_verifier: PlonkVerifier<F, CS, T>,
}
Expand All @@ -35,7 +35,7 @@ where
{
pub fn init(
verifier_key: VerifierKey<F, CS>,
piop_params: PiopParams<F, Jubjub>,
piop_params: PiopParams<Affine<Jubjub>>,
empty_transcript: T,
) -> Self {
let pcs_vk = verifier_key.pcs_raw_vk.prepare();
Expand Down Expand Up @@ -72,7 +72,7 @@ where
.verify(piop, proof, challenges, &mut transcript.to_rng())
}

pub fn piop_params(&self) -> &PiopParams<F, Jubjub> {
pub fn piop_params(&self) -> &PiopParams<Affine<Jubjub>> {
&self.piop_params
}

Expand Down
Loading