Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
PayneJoe committed Nov 17, 2023
1 parent b038d04 commit 0568a80
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 44 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0"
ark-bls12-377 = "0.4.0"
ark-bls12-381 = "0.4.0"
ark-bn254 = "0.4.0"
ark-bw6-761 = "0.4.0"
ark-ec = "0.4"
ark-poly = "0.4"
jf_plonk = { git = "https://github.com/ZKMod-Lab/jellyfish", package = "jf-plonk", branch = "relaxed-stage-1" }
Expand Down
9 changes: 0 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,3 @@ pub mod circuit;
pub mod errors;
pub mod nifs;
pub mod plonk;

#[cfg(test)]
mod tests {

#[test]
fn test_add() {
assert_eq!(2, 1 + 1);
}
}
77 changes: 42 additions & 35 deletions src/plonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ pub struct PLONKShape<E: Pairing> {
// number of constrain or gate, row number
pub(crate) num_cons: usize,
// number of wire types, column number
// 5 for TurboPlonk and 6 for UltraPlonk
pub(crate) num_wire_types: usize,
// number of public input gate
pub(crate) num_public_input: usize,

// PLONK selectors
pub(crate) q_c: Vec<E::ScalarField>,
// with length 5 or 6
// with length 5
pub(crate) q_lc: Vec<Vec<E::ScalarField>>,
// with length 2
pub(crate) q_mul: Vec<Vec<E::ScalarField>>,
Expand Down Expand Up @@ -194,7 +195,7 @@ impl<E: Pairing> RelaxedPLONKWitness<E> {
/// Produces a default RelaxedPLONKWitness given an PLONKShape
pub fn default(S: &PLONKShape<E>) -> RelaxedPLONKWitness<E> {
RelaxedPLONKWitness {
W: vec![[E::ScalarField::ZERO; S.num_cons], S.num_wire_types],
W: vec![vec![E::ScalarField::ZERO; S.num_cons], S.num_wire_types],
E: vec![E::ScalarField::ZERO; S.num_cons],
}
}
Expand Down Expand Up @@ -234,11 +235,7 @@ impl<E: Pairing> RelaxedPLONKWitness<E> {
.map(|(a, b)| *a + *r * *b)
.collect::<Vec<E::ScalarField>>()
});
let E = E1.par_iter().zip(E2).map(|(e1, e2)| {
e1.zip(e2)
.map(|(a, b)| *a + *r * *b)
.collect::<Vec<E::ScalarField>>()
});
let E = E1.par_iter().zip(T).map(|(a, b)| *a + *r * *b).collect();
Ok(RelaxedPLONKWitness { W, E })
}

Expand Down Expand Up @@ -267,8 +264,8 @@ impl<E: Pairing> RelaxedPLONKInstance<E> {
RelaxedPLONKInstance {
comm_W,
comm_E,
u: G::ScalarField::ZERO,
X: vec![G::ScalarField::ZERO; S.num_public_input],
u: E::ScalarField::ZERO,
X: vec![E::ScalarField::ZERO; S.num_public_input],
}
}

Expand All @@ -288,12 +285,12 @@ impl<E: Pairing> RelaxedPLONKInstance<E> {
/// Initializes a new RelaxedPLONKInstance from an PLONKInstance
pub fn from_plonk_instance_unchecked(
comm_W: &[Commitment<E>],
X: &[G::ScalarField],
X: &[E::ScalarField],
) -> RelaxedPLONKInstance<E> {
RelaxedPLONKInstance {
comm_W: *comm_W,
comm_E: Commitment::<E>::default(),
u: G::ScalarField::ONE,
u: E::ScalarField::ONE,
X: X.to_vec(),
}
}
Expand All @@ -314,7 +311,7 @@ impl<E: Pairing> RelaxedPLONKInstance<E> {
.par_iter()
.zip(X2)
.map(|(a, b)| *a + *r * *b)
.collect::<Vec<G::ScalarField>>();
.collect::<Vec<E::ScalarField>>();
let comm_W = *comm_W_1 + *comm_W_2 * *r;
let comm_E = *comm_E_1 + *comm_T * *r;
let u = *u1 + *r;
Expand Down Expand Up @@ -358,33 +355,43 @@ impl<G: Pairing> AbsorbInROTrait<E> for RelaxedPLONKInstance<E> {
}

#[cfg(test)]
pub(crate) mod test {
mod tests {
use ark_bls12_381::Bls12_381;
use ark_ec::pairing::Pairing;
use jf_primitives::pcs::errors::PCSError;
use jf_utils::test_rng;

#[test]
fn end_to_end_test_template() -> Result<(), PCSError> {
let rng = &mut test_rng();
for _ in 0..100 {
let mut degree = 0;
while degree <= 1 {
degree = usize::rand(rng) % 20;
}
let pp = UnivariateKzgPCS::<E>::gen_srs_for_testing(rng, degree)?;
let (ck, vk) = pp.trim(degree)?;
let p = <DensePolynomial<E::ScalarField> as DenseUVPolynomial<E::ScalarField>>::rand(
degree, rng,
);
let comm = UnivariateKzgPCS::<E>::commit(&ck, &p)?;
let point = E::ScalarField::rand(rng);
let (proof, value) = UnivariateKzgPCS::<E>::open(&ck, &p, &point)?;
assert!(
UnivariateKzgPCS::<E>::verify(&vk, &comm, &point, &value, &proof)?,
"proof was incorrect for max_degree = {}, polynomial_degree = {}",
degree,
p.degree(),
);
}
fn end_to_end_test_template<E>() -> Result<(), PCSError>
where
E: Pairing,
{
// let rng = &mut test_rng();
// for _ in 0..100 {
// let mut degree = 0;
// while degree <= 1 {
// degree = usize::rand(rng) % 20;
// }
// let pp = UnivariateKzgPCS::<E>::gen_srs_for_testing(rng, degree)?;
// let (ck, vk) = pp.trim(degree)?;
// let p = <DensePolynomial<E::ScalarField> as DenseUVPolynomial<E::ScalarField>>::rand(
// degree, rng,
// );
// let comm = UnivariateKzgPCS::<E>::commit(&ck, &p)?;
// let point = E::ScalarField::rand(rng);
// let (proof, value) = UnivariateKzgPCS::<E>::open(&ck, &p, &point)?;
// assert!(
// UnivariateKzgPCS::<E>::verify(&vk, &comm, &point, &value, &proof)?,
// "proof was incorrect for max_degree = {}, polynomial_degree = {}",
// degree,
// p.degree(),
// );
// }
Ok(())
}

#[test]
fn end_to_end_test() {
end_to_end_test_template::<Bls12_381>().expect("test failed for bls12-381");
}
}

0 comments on commit 0568a80

Please sign in to comment.