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

Integrate with sponge & Add multivariate challenge strategy #82

Merged
merged 25 commits into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ark-serialize = { version = "^0.3.0", default-features = false, features = [ "de
ark-ff = { version = "^0.3.0", default-features = false }
ark-ec = { version = "^0.3.0", default-features = false }
ark-poly = {version = "^0.3.0", default-features = false }
ark-sponge = {version = "^0.3.0", default-feautres = false}

ark-std = { version = "^0.3.0", default-features = false }
ark-relations = { version = "^0.3.0", default-features = false, optional = true }
Expand Down Expand Up @@ -58,7 +59,7 @@ debug = true

[features]
default = [ "std", "parallel" ]
std = [ "ark-ff/std", "ark-ec/std", "ark-nonnative-field/std", "ark-poly/std", "ark-std/std", "ark-relations/std", "ark-serialize/std" ]
r1cs = [ "ark-relations", "ark-r1cs-std", "ark-nonnative-field", "hashbrown" ]
std = [ "ark-ff/std", "ark-ec/std", "ark-nonnative-field/std", "ark-poly/std", "ark-std/std", "ark-relations/std", "ark-serialize/std", "ark-sponge/std"]
r1cs = [ "ark-relations", "ark-r1cs-std", "ark-nonnative-field", "hashbrown", "ark-sponge/r1cs"]
print-trace = [ "ark-std/print-trace" ]
parallel = [ "std", "ark-ff/parallel", "ark-ec/parallel", "ark-poly/parallel", "ark-std/parallel", "rayon" ]
57 changes: 57 additions & 0 deletions src/challenge.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use ark_ff::PrimeField;
use ark_sponge::FieldBasedCryptographicSponge;

/// State stored for univariate generator
pub struct UnivariateGeneratorState<F: PrimeField> {
gen: F,
next: F,
}

impl<F: PrimeField> UnivariateGeneratorState<F> {
fn new(gen: F) -> Self {
Self { gen, next: gen }
}

fn get_next(&mut self) -> F {
let result = self.next;
self.next *= self.gen;
result
}
}
tsunrise marked this conversation as resolved.
Show resolved Hide resolved

// TODO: Copy and Clone trait cannot be derived
tsunrise marked this conversation as resolved.
Show resolved Hide resolved
/// Challenge Generator (todo doc)
pub enum ChallengeGenerator<'a, F: PrimeField, S: 'a + FieldBasedCryptographicSponge<F>> {
/// todo: doc
Multivariate(&'a mut S),
/// todo: doc
Univariate(UnivariateGeneratorState<F>),
}

impl<'a, F: PrimeField, S: 'a + FieldBasedCryptographicSponge<F>> ChallengeGenerator<'a, F, S> {
/// Returns a challenge generator with multivariate strategy. Each challenge is freshly squeezed
/// from a sponge.
pub fn new_multivariate(sponge: &'a mut S) -> Self {
Self::Multivariate(sponge)
}

/// Returns a challenge generator with univariate strategy. Each challenge is a power of one
/// squeezed element from sponge.
pub fn new_univariate(sponge: &mut S) -> Self {
let gen = sponge.squeeze_native_field_elements(1)[0];
let univariate_state = UnivariateGeneratorState::new(gen);
Self::Univariate(univariate_state)
}

/// Returns the next challenge generated.
pub fn next_challenge(&mut self) -> F {
if let Self::Multivariate(s) = self {
s.squeeze_native_field_elements(1)[0]
} else if let Self::Univariate(s) = self {
s.get_next()
} else {
// should not happen
panic!()
}
tsunrise marked this conversation as resolved.
Show resolved Hide resolved
}
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ pub mod sonic_pc;
/// [pcdas]: https://eprint.iacr.org/2020/499
pub mod ipa_pc;

/// Defines the challenge strategies and challenge generator.
pub mod challenge;
/// A multilinear polynomial commitment scheme that converts n-variate multilinear polynomial into
/// n quotient UV polynomial. This scheme is based on hardness of the discrete logarithm
/// in prime-order groups. Construction is detailed in [[XZZPD19]][xzzpd19] and [[ZGKPP18]][zgkpp18]
Expand Down