Skip to content

Commit

Permalink
refactor: remove proof/commitment types in favor of aliases (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobkaufmann authored Feb 9, 2024
1 parent 72be825 commit 6e939b2
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 63 deletions.
2 changes: 1 addition & 1 deletion src/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<const N: usize> Blob<N> {
const DOMAIN: &[u8; 16] = b"FSBLOBVERIFY_V1_";
let degree = (N as u128).to_be_bytes();

let comm = commitment.0.serialize();
let comm = commitment.serialize();

let mut data = Vec::with_capacity(8 + 16 + Commitment::BYTES + Self::BYTES);
data.extend_from_slice(DOMAIN);
Expand Down
22 changes: 0 additions & 22 deletions src/kzg/commitment.rs

This file was deleted.

7 changes: 3 additions & 4 deletions src/kzg/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use crate::bls;

mod commitment;
mod poly;
mod proof;
mod setup;

pub type Proof = bls::P1;
pub type Commitment = bls::P1;

pub enum Error {
Bls(bls::Error),
}

pub(crate) use poly::Polynomial;

pub use commitment::Commitment;
pub use proof::Proof;
pub use setup::Setup;
4 changes: 2 additions & 2 deletions src/kzg/poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
math::BitReversalPermutation,
};

use super::{proof::Proof, setup::Setup};
use super::{setup::Setup, Proof};

#[derive(Clone, Debug)]
pub(crate) struct Polynomial<'a, const N: usize>(pub(crate) &'a [Fr; N]);
Expand Down Expand Up @@ -71,6 +71,6 @@ impl<'a, const N: usize> Polynomial<'a, N> {
let g1_lagrange = BitReversalPermutation::new(setup.g1_lagrange.as_slice());
let lincomb = P1::lincomb(g1_lagrange.iter().zip(quotient_poly.iter()));

(eval, Proof(lincomb))
(eval, lincomb)
}
}
22 changes: 0 additions & 22 deletions src/kzg/proof.rs

This file was deleted.

18 changes: 6 additions & 12 deletions src/kzg/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ impl<const G1: usize, const G2: usize> Setup<G1, G2> {
point: &Fr,
eval: &Fr,
) -> bool {
let pairing1 = (proof.0, self.g2_monomial[1] + (P2::neg_generator() * point));
let pairing2 = (commitment.0 + (P1::neg_generator() * eval), P2::generator());
let pairing1 = (*proof, self.g2_monomial[1] + (P2::neg_generator() * point));
let pairing2 = (*commitment + (P1::neg_generator() * eval), P2::generator());
bls::verify_pairings(pairing1, pairing2)
}

Expand Down Expand Up @@ -126,15 +126,9 @@ impl<const G1: usize, const G2: usize> Setup<G1, G2> {
rpowers.push(r.pow(&Fr::from(i as u64)));
}

let proof_lincomb = P1::lincomb(
proofs
.as_ref()
.iter()
.map(|proof| &proof.0)
.zip(rpowers.iter()),
);
let proof_lincomb = P1::lincomb(proofs.as_ref().iter().zip(rpowers.iter()));
let proof_z_lincomb = P1::lincomb_owned(
proofs.as_ref().iter().map(|proof| proof.0).zip(
proofs.as_ref().iter().copied().zip(
points
.as_ref()
.iter()
Expand All @@ -147,7 +141,7 @@ impl<const G1: usize, const G2: usize> Setup<G1, G2> {
.as_ref()
.iter()
.zip(evals.as_ref().iter())
.map(|(comm, eval)| comm.0 + (P1::neg_generator() * eval));
.map(|(comm, eval)| *comm + (P1::neg_generator() * eval));
let comm_minus_eval_lincomb = P1::lincomb_owned(comm_minus_eval.zip(rpowers));

bls::verify_pairings(
Expand Down Expand Up @@ -492,7 +486,7 @@ mod tests {
let (_eval, proof) = poly.prove(input.z, &setup);

assert_eq!(eval, expected_eval);
assert_eq!(proof.0, expected_proof);
assert_eq!(proof, expected_proof);
}
Err(_) => {
assert!(case.output.is_none());
Expand Down

0 comments on commit 6e939b2

Please sign in to comment.