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

Feat(zeromorph): Add Zeromorph PCS #66

Closed
wants to merge 21 commits into from
Closed
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
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,20 @@ ark-std = { version = "0.4.0", default-features = false }
ark-serialize = { version = "0.4.2", default-features = false, features = [
"derive",
] }
ark-poly-commit = { version = "0.4.0", default-features = false }

# ark-bls12-381 = { version = "^0.4.0", default-features = false, features = [ "curve" ] }
criterion = { version = "0.3.1", features = ["html_reports"] }
num-integer = "0.1.45"
seq-macro = "0.3.3"
ark-curve25519 = "0.4.0"
ark-bn254 = "0.4.0"
tracing = "0.1.37"
tracing-subscriber = "0.3.17"
tracing-texray = "0.2.0"
clap = { version = "4.3.10", features = ["derive"] }
hashbrown = "0.14.0"
lazy_static = "1.4.0"

[dev-dependencies]
criterion = "0.3.1"
Expand Down
79 changes: 79 additions & 0 deletions src/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,96 @@ macro_rules! single_pass_lasso {
pub enum BenchType {
JoltDemo,
Halo2Comparison,
Zeromorph,
}

#[allow(unreachable_patterns)] // good errors on new BenchTypes
pub fn benchmarks(bench_type: BenchType) -> Vec<(tracing::Span, fn())> {
match bench_type {
BenchType::JoltDemo => jolt_demo_benchmarks(),
BenchType::Halo2Comparison => halo2_comparison_benchmarks(),
BenchType::Zeromorph => zeromorph(),
_ => panic!("BenchType does not have a mapping"),
}
}

fn zeromorph() -> Vec<(tracing::Span, fn())> {
vec![
single_pass_lasso!(
"And(2^10)",
Fr,
EdwardsProjective,
AndSubtableStrategy,
/* C= */ 1,
/* M= */ 1 << 16,
/* S= */ 1 << 10
),
single_pass_lasso!(
"And(2^12)",
Fr,
EdwardsProjective,
AndSubtableStrategy,
/* C= */ 1,
/* M= */ 1 << 16,
/* S= */ 1 << 12
),
single_pass_lasso!(
"And(2^14)",
Fr,
EdwardsProjective,
AndSubtableStrategy,
/* C= */ 1,
/* M= */ 1 << 16,
/* S= */ 1 << 14
),
single_pass_lasso!(
"And(2^16)",
Fr,
EdwardsProjective,
AndSubtableStrategy,
/* C= */ 1,
/* M= */ 1 << 16,
/* S= */ 1 << 16
),
single_pass_lasso!(
"And(2^18)",
Fr,
EdwardsProjective,
AndSubtableStrategy,
/* C= */ 1,
/* M= */ 1 << 16,
/* S= */ 1 << 18
),
single_pass_lasso!(
"And(2^20)",
Fr,
EdwardsProjective,
AndSubtableStrategy,
/* C= */ 1,
/* M= */ 1 << 16,
/* S= */ 1 << 20
),
single_pass_lasso!(
"And(2^22)",
Fr,
EdwardsProjective,
AndSubtableStrategy,
/* C= */ 1,
/* M= */ 1 << 16,
/* S= */ 1 << 22
),
single_pass_lasso!(
"And(2^24)",
Fr,
EdwardsProjective,
AndSubtableStrategy,
/* C= */ 1,
/* M= */ 1 << 16,
/* S= */ 1 << 24
),
]
}

fn jolt_demo_benchmarks() -> Vec<(tracing::Span, fn())> {
vec![
single_pass_lasso!(
Expand Down
10 changes: 4 additions & 6 deletions src/e2e_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ use crate::{
lasso::{
densified::DensifiedRepresentation,
surge::{SparsePolyCommitmentGens, SparsePolynomialEvaluationProof},
},
subtables::{
}, subprotocols::{traits::PolynomialCommitmentScheme, hyrax::Hyrax}, subtables::{
and::AndSubtableStrategy, lt::LTSubtableStrategy, range_check::RangeCheckSubtableStrategy,
SubtableStrategy,
},
utils::math::Math,
utils::random::RandomTape,
}, utils::math::Math, utils::random::RandomTape
};

macro_rules! e2e_test {
Expand All @@ -36,7 +33,7 @@ macro_rules! e2e_test {
DensifiedRepresentation::from_lookup_indices(&nz, log_M);
let gens =
SparsePolyCommitmentGens::<$G>::new(b"gens_sparse_poly", C, $sparsity, NUM_MEMORIES, log_M);
let commitment = dense.commit::<$G>(&gens);
let commitment = dense.commit(&gens);

let r: Vec<$F> = gen_random_point(log_s);

Expand All @@ -61,6 +58,7 @@ macro_rules! e2e_test {
};
}

/// Hyrax
e2e_test!(
prove_4d_lt,
LTSubtableStrategy,
Expand Down
19 changes: 13 additions & 6 deletions src/lasso/densified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use ark_ff::PrimeField;

use super::surge::{SparsePolyCommitmentGens, SparsePolynomialCommitment};
use crate::poly::dense_mlpoly::DensePolynomial;
use crate::subprotocols::hyrax::Hyrax;
use crate::subprotocols::traits::PolynomialCommitmentScheme;
use crate::utils::math::Math;

pub struct DensifiedRepresentation<F: PrimeField, const C: usize> {
Expand Down Expand Up @@ -74,17 +76,22 @@ impl<F: PrimeField, const C: usize> DensifiedRepresentation<F, C> {
}
}

//TODO: make this a commitment generic over
#[tracing::instrument(skip_all, name = "DensifiedRepresentation.commit")]
pub fn commit<G: CurveGroup<ScalarField = F>>(
&self,
gens: &SparsePolyCommitmentGens<G>,
) -> SparsePolynomialCommitment<G> {
let (l_variate_polys_commitment, _) = self
.combined_l_variate_polys
.commit(&gens.gens_combined_l_variate, None);
let (log_m_variate_polys_commitment, _) = self
.combined_log_m_variate_polys
.commit(&gens.gens_combined_log_m_variate, None);
let (l_variate_polys_commitment, _) = Hyrax::<G>::commit(
&self.combined_l_variate_polys,
(gens.gens_combined_l_variate.clone(), None),
)
.unwrap();
let (log_m_variate_polys_commitment, _) = Hyrax::<G>::commit(
&self.combined_log_m_variate_polys,
(gens.gens_combined_log_m_variate.clone(), None),
)
.unwrap();

SparsePolynomialCommitment {
l_variate_polys_commitment,
Expand Down
50 changes: 29 additions & 21 deletions src/lasso/memory_checking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
#![allow(clippy::type_complexity)]
use crate::lasso::densified::DensifiedRepresentation;
use crate::lasso::surge::{SparsePolyCommitmentGens, SparsePolynomialCommitment};
use crate::poly::dense_mlpoly::{DensePolynomial, PolyEvalProof};
use crate::poly::dense_mlpoly::DensePolynomial;
use crate::poly::identity_poly::IdentityPolynomial;
use crate::subprotocols::grand_product::{BatchedGrandProductArgument, GrandProductCircuit};
use crate::subprotocols::hyrax::Hyrax;
use crate::subprotocols::traits::PolynomialCommitmentScheme;
use crate::subprotocols::{
grand_product::{BatchedGrandProductArgument, GrandProductCircuit},
hyrax::PolyEvalProof,
};
use crate::subtables::{
CombinedTableCommitment, CombinedTableEvalProof, SubtableStrategy, Subtables,
};
Expand Down Expand Up @@ -36,8 +41,12 @@ pub struct MemoryCheckingProof<
proof_hash_layer: HashLayerProof<G, C, M, S>,
}

impl<G: CurveGroup, const C: usize, const M: usize, S: SubtableStrategy<G::ScalarField, C, M> + Sync>
MemoryCheckingProof<G, C, M, S>
impl<
G: CurveGroup,
const C: usize,
const M: usize,
S: SubtableStrategy<G::ScalarField, C, M> + Sync,
> MemoryCheckingProof<G, C, M, S>
where
[(); S::NUM_SUBTABLES]: Sized,
[(); S::NUM_MEMORIES]: Sized,
Expand Down Expand Up @@ -282,15 +291,18 @@ impl<F: PrimeField> GrandProducts<F> {
#[cfg(not(feature = "multicore"))]
let num_ops = 0..dim_i.len();
let grand_product_input_read = DensePolynomial::new(
num_ops.clone().map(|i| {
num_ops
.clone()
.map(|i| {
// addr is given by dim_i, value is given by eval_table, and ts is given by read_ts
hash_func(&dim_i[i], &eval_table[dim_i_usize[i]], &read_i[i])
})
.collect::<Vec<F>>()
.collect::<Vec<F>>(),
);
// write: s hash evaluation => log(s)-variate polynomial
let grand_product_input_write = DensePolynomial::new(
num_ops.map(|i| {
num_ops
.map(|i| {
// addr is given by dim_i, value is given by eval_table, and ts is given by write_ts = read_ts + 1
hash_func(
&dim_i[i],
Expand Down Expand Up @@ -399,16 +411,14 @@ where
&joint_claim_eval_ops,
);

let (proof_ops, _) = PolyEvalProof::prove(
let (proof_ops, _) = Hyrax::prove(
&dense.combined_l_variate_polys,
None,
&Some(joint_claim_eval_ops),
&r_joint_ops,
&joint_claim_eval_ops,
None,
&gens.gens_combined_l_variate,
(None, None, &gens.gens_combined_l_variate, random_tape),
transcript,
random_tape,
);
)
.unwrap();

<Transcript as ProofTranscript<G>>::append_scalars(transcript, b"claim_evals_mem", &eval_final);
let challenges_mem = <Transcript as ProofTranscript<G>>::challenge_vector(
Expand Down Expand Up @@ -437,16 +447,14 @@ where
&joint_claim_eval_mem,
);

let (proof_mem, _) = PolyEvalProof::prove(
let (proof_mem, _) = Hyrax::prove(
&dense.combined_log_m_variate_polys,
None,
&Some(joint_claim_eval_mem),
&r_joint_mem,
&joint_claim_eval_mem,
None,
&gens.gens_combined_log_m_variate,
(None, None, &gens.gens_combined_log_m_variate, random_tape),
transcript,
random_tape,
);
)
.unwrap();

HashLayerProof {
eval_dim,
Expand Down
19 changes: 15 additions & 4 deletions src/lasso/surge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

use crate::lasso::densified::DensifiedRepresentation;
use crate::lasso::memory_checking::MemoryCheckingProof;
use crate::poly::dense_mlpoly::{DensePolynomial, PolyCommitment, PolyCommitmentGens};
use crate::poly::dense_mlpoly::DensePolynomial;
use crate::poly::eq_poly::EqPolynomial;
use crate::subprotocols::sumcheck::SumcheckInstanceProof;
use crate::subprotocols::{
hyrax::{PolyCommitment, PolyCommitmentGens},
sumcheck::SumcheckInstanceProof,
};
use crate::subtables::{
CombinedTableCommitment, CombinedTableEvalProof, SubtableStrategy, Subtables,
};
Expand All @@ -22,6 +25,8 @@ use ark_std::log2;
use merlin::Transcript;
use std::marker::Sync;

// Public Params
#[derive(Clone)]
pub struct SparsePolyCommitmentGens<G> {
pub gens_combined_l_variate: PolyCommitmentGens<G>,
pub gens_combined_log_m_variate: PolyCommitmentGens<G>,
Expand Down Expand Up @@ -89,6 +94,8 @@ struct PrimarySumcheck<G: CurveGroup, const ALPHA: usize> {
proof_derefs: CombinedTableEvalProof<G, ALPHA>,
}

// TODO Implement trait interface for this:
// DensifiedRepresentation ->
#[derive(Debug, CanonicalSerialize, CanonicalDeserialize)]
pub struct SparsePolynomialEvaluationProof<
G: CurveGroup,
Expand All @@ -103,8 +110,12 @@ pub struct SparsePolynomialEvaluationProof<
memory_check: MemoryCheckingProof<G, C, M, S>,
}

impl<G: CurveGroup, const C: usize, const M: usize, S: SubtableStrategy<G::ScalarField, C, M> + Sync>
SparsePolynomialEvaluationProof<G, C, M, S>
impl<
G: CurveGroup,
const C: usize,
const M: usize,
S: SubtableStrategy<G::ScalarField, C, M> + Sync,
> SparsePolynomialEvaluationProof<G, C, M, S>
where
[(); S::NUM_SUBTABLES]: Sized,
[(); S::NUM_MEMORIES]: Sized,
Expand Down
2 changes: 1 addition & 1 deletion src/poly/commitments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ark_ec::VariableBaseMSM;
#[cfg(not(feature = "ark-msm"))]
use crate::msm::VariableBaseMSM;

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct MultiCommitGens<G> {
pub n: usize,
pub G: Vec<G>,
Expand Down
Loading
Loading