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

Add Ligero univariate and multilinear PCS #132

Merged
merged 68 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
f13a576
added hyrax PCS
Antonio95 Oct 25, 2023
fba3d80
Add univariate and multilinear Ligero PCS
mmagician Oct 25, 2023
e00d5b0
adapt the scheme to https://github.com/arkworks-rs/algebra/issues/691
mmagician Oct 26, 2023
9d5119b
move tests shared across univariate and ML ligero to utils
mmagician Oct 26, 2023
86a322f
remove unused no-std import
mmagician Oct 26, 2023
69896d4
adapt the scheme to https://github.com/arkworks-rs/algebra/issues/691
mmagician Oct 26, 2023
ecf73f4
remove unused code in hyrax
mmagician Oct 26, 2023
234e049
Improve the choice of dimensions for polynomial matrix
Antonio95 Oct 20, 2023
dd281f1
Update comments
autquis Oct 26, 2023
14f80fd
parallelised row encoding and col-to-leaf hashing; significant perfor…
Antonio95 Oct 26, 2023
f424c48
expanded on Future Optimisations section
Antonio95 Oct 26, 2023
0628824
fixed GH action failures: formatted and added feature flag
Antonio95 Oct 26, 2023
0a2b119
Merge branch 'master' into ligero-uni-and-ml
mmagician Oct 28, 2023
0d8dc45
remove Prepared data types from `PolynomialCommitment` trait
mmagician Oct 28, 2023
dd58a1a
Merge branch 'master' into hyrax-pcs
mmagician Oct 28, 2023
06c59e9
Remove Prepared data types from `PolynomialCommitment` trait impl
mmagician Oct 28, 2023
a845018
merged master including new crate and directory structure
Antonio95 Oct 30, 2023
12afb33
added necessary dependencies overwritten by previous merge commit
Antonio95 Oct 30, 2023
9b48223
merged master including new crate and directory structure
Antonio95 Oct 30, 2023
5e955bc
fixed hashbrown version
Antonio95 Oct 30, 2023
3b0c371
Add back the cfg dependency for no-std build
mmagician Oct 30, 2023
6967c28
fixed hashbrown version
Antonio95 Oct 30, 2023
dd82dbc
pulled
Antonio95 Oct 30, 2023
a029081
created separate benchmark files
Antonio95 Oct 30, 2023
a7f465a
fixed duplicate dependency to match other branches
Antonio95 Oct 30, 2023
c010663
patched bn254 dep
Antonio95 Oct 30, 2023
d415053
restructured benchmark macros to accept ML schemes; benches working
Antonio95 Oct 31, 2023
acb65ec
moved hashing structures to bench-templates crate, started ligero ben…
Antonio95 Oct 31, 2023
80410d0
completed ligero benchmarks
Antonio95 Oct 31, 2023
25c34aa
added ligero benchmark file
Antonio95 Oct 31, 2023
3ef7309
Hyrax fix bench (#42)
mmagician Nov 13, 2023
370e77c
Ligero fix benches (#40)
mmagician Nov 13, 2023
cc1f75a
Hyrax parallel `commit` (#39)
mmagician Nov 13, 2023
7c7328d
Make Hyrax hiding again (#43)
Antonio95 Nov 13, 2023
2bcff80
Fix tests: sponge config for univariate ligero
autquis Jan 9, 2024
55d7b58
Delete `IOPTranscript`, update with master (#50) (aka Hyrax++)
autquis Jan 18, 2024
d13296c
Merge branch 'master' into hyrax-pcs
autquis Jan 18, 2024
044d74a
Delete `IOPTranscript`, update with master (#51) (aka Ligero++)
autquis Jan 18, 2024
d5c6039
Merge branch 'master' into ligero-uni-and-ml
autquis Jan 18, 2024
1f988ac
Add a few comments and update `Cargo.toml`
autquis Jan 18, 2024
5677c5b
Remove extra `cfg_iter!`
autquis Jan 22, 2024
c2e6412
Change `pedersen_commit` and add `cfg_into_iter!`
autquis Jan 22, 2024
ac4a14c
Hash and absorb
autquis Jan 23, 2024
265e261
added Sync trait bound
Antonio95 Jun 3, 2024
a5cf4cf
removed TODO
Antonio95 Jun 3, 2024
8d356db
Fixed error whereby boolean value returned by path.verify was neglected
Antonio95 Jun 3, 2024
61d9a76
removed unnecessary qualification which linter didn't like
Antonio95 Jun 3, 2024
6c5e096
changed potential panic to returning Err, stopping early
Antonio95 Jun 4, 2024
18a3d84
removed unnecessary function defined inside check()
Antonio95 Jun 4, 2024
f3495d0
various minor fixes
Antonio95 Jun 6, 2024
f66901b
Add `ark-std` to patch
autquis Jun 9, 2024
103669f
Reorder Hyrax checks
Cesar199999 Jun 10, 2024
eee8e0b
Add `ark-std` to patch
autquis Jun 9, 2024
65ef67c
Downgrade `hashbrown`
autquis Oct 21, 2024
67ddd9c
Fix breaking change from algebra/poly (#72)
Cesar199999 Jun 28, 2024
175a610
Reorder deps
autquis Oct 21, 2024
d3e3808
Add dummy doc for nightly
autquis Oct 21, 2024
0858433
Fix `hashbrown` + Replace Blake2 by Blake3
autquis Oct 24, 2024
c2ba181
Revert to Blake2
autquis Oct 25, 2024
9e310f5
Merge branch 'master' into hyrax-pcs
autquis Oct 25, 2024
9b03b60
Fix merging issues
autquis Oct 25, 2024
f5924ee
Test if CI is happy
autquis Oct 25, 2024
cb20740
Revert and cleanup
autquis Oct 25, 2024
5239162
Delete dummy doc
autquis Oct 25, 2024
552163a
Merge branch 'hyrax-pcs' into ligero-uni-and-ml
autquis Oct 25, 2024
921d8ca
Bring back `num_traits`
autquis Oct 25, 2024
621f0b5
Merge branch 'master' into ligero-uni-and-ml
autquis Oct 25, 2024
127370e
Add `/` to Cargo.toml
autquis Oct 25, 2024
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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ark-ec = { git = "https://github.com/arkworks-rs/algebra/" }
ark-serialize = { git = "https://github.com/arkworks-rs/algebra/" }
ark-poly = { git = "https://github.com/arkworks-rs/algebra/" }

ark-crypto-primitives = { git = "https://github.com/arkworks-rs/crypto-primitives" }
ark-crypto-primitives = { git = "https://github.com/arkworks-rs/crypto-primitives/" }
ark-r1cs-std = { git = "https://github.com/arkworks-rs/r1cs-std/" }

ark-bls12-377 = { git = "https://github.com/arkworks-rs/algebra/" }
Expand Down
72 changes: 66 additions & 6 deletions bench-templates/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
use ark_crypto_primitives::sponge::{
poseidon::{PoseidonConfig, PoseidonSponge},
CryptographicSponge,
use ark_crypto_primitives::{
crh::{sha256::digest::Digest, CRHScheme},
sponge::{
poseidon::{PoseidonConfig, PoseidonSponge},
CryptographicSponge,
},
};
use ark_ff::PrimeField;
use ark_poly::Polynomial;
use ark_serialize::{CanonicalSerialize, Compress};
use ark_std::{test_rng, UniformRand};
use rand_chacha::{rand_core::SeedableRng, ChaCha20Rng};
use rand_chacha::{
rand_core::{RngCore, SeedableRng},
ChaCha20Rng,
};

use core::time::Duration;
use std::time::Instant;
use std::{borrow::Borrow, marker::PhantomData, time::Instant};

use ark_poly_commit::{LabeledPolynomial, PolynomialCommitment};
use ark_poly_commit::{to_bytes, LabeledPolynomial, PolynomialCommitment};

pub use criterion::*;
pub use paste::paste;
Expand Down Expand Up @@ -276,3 +282,57 @@ macro_rules! bench {
}
};
}

/**** Auxiliary methods for linear-code-based PCSs ****/

/// Needed for benches and tests.
pub struct LeafIdentityHasher;

impl CRHScheme for LeafIdentityHasher {
type Input = Vec<u8>;
type Output = Vec<u8>;
type Parameters = ();

fn setup<R: RngCore>(_: &mut R) -> Result<Self::Parameters, ark_crypto_primitives::Error> {
Ok(())
}

fn evaluate<T: Borrow<Self::Input>>(
_: &Self::Parameters,
input: T,
) -> Result<Self::Output, ark_crypto_primitives::Error> {
Ok(input.borrow().to_vec().into())
}
}

/// Needed for benches and tests.
pub struct FieldToBytesColHasher<F, D>
where
F: PrimeField + CanonicalSerialize,
D: Digest,
{
_phantom: PhantomData<(F, D)>,
}

impl<F, D> CRHScheme for FieldToBytesColHasher<F, D>
where
F: PrimeField + CanonicalSerialize,
D: Digest,
{
type Input = Vec<F>;
type Output = Vec<u8>;
type Parameters = ();

fn setup<R: RngCore>(_rng: &mut R) -> Result<Self::Parameters, ark_crypto_primitives::Error> {
Ok(())
}

fn evaluate<T: Borrow<Self::Input>>(
_parameters: &Self::Parameters,
input: T,
) -> Result<Self::Output, ark_crypto_primitives::Error> {
let mut dig = D::new();
dig.update(to_bytes!(input.borrow()).unwrap());
Ok(dig.finalize().to_vec())
}
}
11 changes: 10 additions & 1 deletion poly-commit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,19 @@ ark-r1cs-std = { version = "^0.4.0", default-features = false, optional = true }
hashbrown = { version = "0.15", default-features = false, features = ["inline-more", "allocator-api2"], optional = true }
rand = { version = "0.8.0", optional = true }
rayon = { version = "1", optional = true }
merlin = { version = "3.0.0", default-features = false }

[[bench]]
name = "ipa_times"
path = "benches/ipa_times.rs"
harness = false

[[bench]]
name = "ligero_ml_times"
path = "benches/ligero_ml_times.rs"
harness = false


[[bench]]
name = "hyrax_times"
path = "benches/hyrax_times.rs"
Expand All @@ -53,10 +60,12 @@ ark-ed-on-bls12-381 = { version = "^0.4.0", default-features = false }
ark-bls12-381 = { version = "^0.4.0", default-features = false, features = [ "curve" ] }
ark-bls12-377 = { version = "^0.4.0", default-features = false, features = [ "curve" ] }
ark-bn254 = { version = "^0.4.0", default-features = false, features = [ "curve" ] }

rand_chacha = { version = "0.3.0", default-features = false }
ark-pcs-bench-templates = { path = "../bench-templates" }

[target.'cfg(target_arch = "aarch64")'.dependencies]
num-traits = { version = "0.2", default-features = false, features = ["libm"] }

[features]
default = [ "std", "parallel" ]
std = [ "ark-ff/std", "ark-ec/std", "ark-poly/std", "ark-std/std", "ark-relations/std", "ark-serialize/std", "ark-crypto-primitives/std"]
Expand Down
55 changes: 55 additions & 0 deletions poly-commit/benches/ligero_ml_times.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use ark_crypto_primitives::{
crh::{sha256::Sha256, CRHScheme, TwoToOneCRHScheme},
merkle_tree::{ByteDigestConverter, Config},
};
use ark_pcs_bench_templates::*;
use ark_poly::{DenseMultilinearExtension, MultilinearExtension};

use ark_bn254::Fr;
use ark_ff::PrimeField;

use ark_poly_commit::linear_codes::{LinearCodePCS, MultilinearLigero};
use blake2::Blake2s256;
use rand_chacha::ChaCha20Rng;

// Ligero PCS over BN254
struct MerkleTreeParams;
type LeafH = LeafIdentityHasher;
type CompressH = Sha256;
impl Config for MerkleTreeParams {
type Leaf = Vec<u8>;

type LeafDigest = <LeafH as CRHScheme>::Output;
type LeafInnerDigestConverter = ByteDigestConverter<Self::LeafDigest>;
type InnerDigest = <CompressH as TwoToOneCRHScheme>::Output;

type LeafHash = LeafH;
type TwoToOneHash = CompressH;
}

pub type MLE<F> = DenseMultilinearExtension<F>;
type MTConfig = MerkleTreeParams;
type ColHasher<F> = FieldToBytesColHasher<F, Blake2s256>;
type Ligero<F> = LinearCodePCS<
MultilinearLigero<F, MTConfig, MLE<F>, ColHasher<F>>,
F,
MLE<F>,
MTConfig,
ColHasher<F>,
>;

fn rand_poly_ligero_ml<F: PrimeField>(
num_vars: usize,
rng: &mut ChaCha20Rng,
) -> DenseMultilinearExtension<F> {
DenseMultilinearExtension::rand(num_vars, rng)
}

fn rand_point_ligero_ml<F: PrimeField>(num_vars: usize, rng: &mut ChaCha20Rng) -> Vec<F> {
(0..num_vars).map(|_| F::rand(rng)).collect()
}

const MIN_NUM_VARS: usize = 12;
const MAX_NUM_VARS: usize = 22;

bench!(Ligero<Fr>, rand_poly_ligero_ml, rand_point_ligero_ml);
15 changes: 5 additions & 10 deletions poly-commit/src/ipa_pc/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
BTreeMap, BTreeSet, BatchLCProof, DenseUVPolynomial, Error, Evaluations, LabeledCommitment,
LabeledPolynomial, LinearCombination, PCCommitmentState, PCCommitterKey, PCUniversalParams,
PolynomialCommitment, QuerySet, CHALLENGE_SIZE,
utils::inner_product, BTreeMap, BTreeSet, BatchLCProof, DenseUVPolynomial, Error, Evaluations,
LabeledCommitment, LabeledPolynomial, LinearCombination, PCCommitmentState, PCCommitterKey,
PCUniversalParams, PolynomialCommitment, QuerySet, CHALLENGE_SIZE,
};
use ark_crypto_primitives::sponge::CryptographicSponge;
use ark_ec::{AffineRepr, CurveGroup, VariableBaseMSM};
Expand Down Expand Up @@ -86,11 +86,6 @@ where
challenge.unwrap()
}

#[inline]
fn inner_product(l: &[G::ScalarField], r: &[G::ScalarField]) -> G::ScalarField {
ark_std::cfg_iter!(l).zip(r).map(|(li, ri)| *li * ri).sum()
}

/// The succinct portion of `PC::check`. This algorithm runs in time
/// O(log d), where d is the degree of the committed polynomials.
fn succinct_check<'a>(
Expand Down Expand Up @@ -674,10 +669,10 @@ where
let (key_proj_l, _) = key_proj.split_at_mut(n / 2);

let l = Self::cm_commit(key_l, coeffs_r, None, None)
+ &h_prime.mul(Self::inner_product(coeffs_r, z_l));
+ &h_prime.mul(inner_product(coeffs_r, z_l));

let r = Self::cm_commit(key_r, coeffs_l, None, None)
+ &h_prime.mul(Self::inner_product(coeffs_l, z_r));
+ &h_prime.mul(inner_product(coeffs_l, z_r));

let lr = G::Group::normalize_batch(&[l, r]);
l_vec.push(lr[0]);
Expand Down
5 changes: 5 additions & 0 deletions poly-commit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ pub use marlin::marlin_pst13_pc;
/// [bdfg]: https://eprint.iacr.org/2020/081.pdf
pub mod streaming_kzg;

/// Scheme based on the Ligero construction in [[Ligero]][ligero].
///
/// [ligero]: https://eprint.iacr.org/2022/1608
pub mod linear_codes;

/// A polynomial commitment scheme based on the hardness of the
/// discrete logarithm problem in prime-order groups. This is a
/// Fiat-Shamired version of the PCS described in the Hyrax paper
Expand Down
124 changes: 124 additions & 0 deletions poly-commit/src/linear_codes/data_structures.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
use crate::{utils::Matrix, PCCommitment, PCCommitmentState};
use ark_crypto_primitives::{
crh::CRHScheme,
merkle_tree::{Config, LeafParam, Path, TwoToOneParam},
};
use ark_ff::PrimeField;
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;
use ark_std::{marker::PhantomData, rand::RngCore};

#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(Clone(bound = ""), Debug(bound = ""))]
/// The public parameters for Ligero PCS.
pub struct LigeroPCParams<F: PrimeField, C: Config, H: CRHScheme> {
pub(crate) _field: PhantomData<F>,
/// The security parameter
pub(crate) sec_param: usize,
/// The inverse of the code rate.
pub(crate) rho_inv: usize,
/// This is a flag which determines if the random linear combination is done.
pub(crate) check_well_formedness: bool,
/// Parameters for hash function of Merkle tree leaves
#[derivative(Debug = "ignore")]
pub(crate) leaf_hash_param: LeafParam<C>,
/// Parameters for hash function of Merke tree combining two nodes into one
#[derivative(Debug = "ignore")]
pub(crate) two_to_one_hash_param: TwoToOneParam<C>,
// Parameters for obtaining leaf digest from leaf value.
#[derivative(Debug = "ignore")]
pub(crate) col_hash_params: H::Parameters,
}

#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(Default(bound = ""), Clone(bound = ""), Debug(bound = ""))]
pub(crate) struct Metadata {
pub(crate) n_rows: usize,
pub(crate) n_cols: usize,
pub(crate) n_ext_cols: usize,
}

/// The commitment to a polynomial is a root of the merkle tree,
/// where each node is a hash of the column of the encoded coefficient matrix U.
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(Default(bound = ""), Clone(bound = ""), Debug(bound = ""))]
pub struct LinCodePCCommitment<C: Config> {
// number of rows resp. columns of the square matrix containing the coefficients of the polynomial
pub(crate) metadata: Metadata,
pub(crate) root: C::InnerDigest,
}

impl<C: Config> PCCommitment for LinCodePCCommitment<C> {
fn empty() -> Self {
LinCodePCCommitment::default()
}

fn has_degree_bound(&self) -> bool {
false
}
}

#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(Default(bound = ""), Clone(bound = ""), Debug(bound = ""))]
pub struct LinCodePCCommitmentState<F, H>
where
F: PrimeField,
H: CRHScheme,
{
pub(crate) mat: Matrix<F>,
pub(crate) ext_mat: Matrix<F>,
pub(crate) leaves: Vec<H::Output>,
}

impl<F, H> PCCommitmentState for LinCodePCCommitmentState<F, H>
where
F: PrimeField,
H: CRHScheme,
{
type Randomness = ();
fn empty() -> Self {
unimplemented!()
}

fn rand<R: RngCore>(
_num_queries: usize,
_has_degree_bound: bool,
_num_vars: Option<usize>,
_rng: &mut R,
) -> Self::Randomness {
unimplemented!()
}
}

/// Proof of an individual linear code well-formedness check or opening
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(Default(bound = ""), Clone(bound = ""), Debug(bound = ""))]
pub(crate) struct LinCodePCProofSingle<F, C>
where
F: PrimeField,
C: Config,
{
/// For each of the indices in q, `paths` contains the path from the root of the merkle tree to the leaf
pub(crate) paths: Vec<Path<C>>,

/// v, s.t. E(v) = w
pub(crate) v: Vec<F>,

pub(crate) columns: Vec<Vec<F>>,
}

/// The Proof type for linear code PCS, which amounts to an array of individual proofs
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(Default(bound = ""), Clone(bound = ""), Debug(bound = ""))]
pub struct LinCodePCProof<F, C>
where
F: PrimeField,
C: Config,
{
pub(crate) opening: LinCodePCProofSingle<F, C>,
pub(crate) well_formedness: Option<Vec<F>>,
}

// Multiple poly at one point
pub(crate) type LPCPArray<F, C> = Vec<LinCodePCProof<F, C>>;
Loading
Loading