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

a generic Trait for both ml and uni KZG #43

Merged
merged 18 commits into from
Jul 21, 2022
Merged

a generic Trait for both ml and uni KZG #43

merged 18 commits into from
Jul 21, 2022

Conversation

zhenfeizhang
Copy link
Contributor

No description provided.

@zhenfeizhang zhenfeizhang marked this pull request as ready for review July 20, 2022 18:35
@zhenfeizhang
Copy link
Contributor Author

Would also like some input from @alxiong on the APIs for PCS trait

Copy link
Collaborator

@chancharles92 chancharles92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhenfeizhang I only checked the multilinear KZG part, do I also need to check the univariate KZG part?

pcs/src/multilinear_kzg/batching.rs Outdated Show resolved Hide resolved
pcs/src/multilinear_kzg/batching.rs Outdated Show resolved Hide resolved
pcs/src/multilinear_kzg/batching.rs Outdated Show resolved Hide resolved
pcs/src/multilinear_kzg/batching.rs Show resolved Hide resolved
pcs/src/multilinear_kzg/batching.rs Outdated Show resolved Hide resolved
pcs/src/multilinear_kzg/mod.rs Outdated Show resolved Hide resolved
pcs/src/multilinear_kzg/mod.rs Outdated Show resolved Hide resolved
@zhenfeizhang
Copy link
Contributor Author

@zhenfeizhang I only checked the multilinear KZG part, do I also need to check the univariate KZG part?

Yes please.

pcs/src/multilinear_kzg/util.rs Outdated Show resolved Hide resolved
pcs/src/multilinear_kzg/util.rs Outdated Show resolved Hide resolved

/// Input a list of polynomials, and a same number of points,
/// compute a multi-opening for all the polynomials.
fn multi_open(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a naive approach, do we want to add a TODO to implement the more efficient batch opening algorithm? (e.g., the appendix C.4 in https://eprint.iacr.org/2020/1536.pdf)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we do (BTW our Jellyfish didn't use this either)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in ff2e7a9

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, can you also add an issue for this?

@zhenfeizhang zhenfeizhang merged commit 17cff52 into main Jul 21, 2022
@zhenfeizhang zhenfeizhang deleted the impl_kzg branch July 21, 2022 17:01
use ark_ec::{msm::FixedBaseMSM, AffineCurve, PairingEngine, ProjectiveCurve};
use ark_ff::{Field, PrimeField};
use ark_poly::DenseMultilinearExtension;
use ark_ec::{AffineCurve, PairingEngine};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we still keep this file param.rs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch. removed in #39

Comment on lines +6 to +9
pub struct Commitment<E: PairingEngine> {
/// the actual commitment is an affine point.
pub commitment: E::G1Affine,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I don't think defining this struct is necessary. (maybe just a matter of preference)

  • in xxx-kzg/mod.rs we could directly type Commitment = E::G1Affine. The indirection introduced by this struct is not useful

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good to me


/// Generate a commitment for a polynomial
fn commit(
prover_param: &Self::ProverParam,
poly: &impl MultilinearExtension<E::Fr>,
poly: &Self::Polynomial,
) -> Result<Self::Commitment, PCSErrors>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. We should have associated type Error instead of concrete PCSError
  2. Our enum PCSError::PolyIOPError(_) seems strange.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. It use PolyIOPError because IOPTranscript is implemented in PolyIOP. I now think we should have a separate crate and trait for Transcript and that should simplify things.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed with #46

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#46 only fixed the second point, right?

The first point is still yet to be addressed.

Comment on lines +15 to 18
// Parameters
type ProverParam;
type VerifierParam;
type SRS;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can shorten as type SRS: StructuredReferenceString<E> ?
and Self::ProverParam is just <Self::SRS as StructuredReferenceString>::ProverParam.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no we cannot.
SRS for multilinear KZG is a tuple (MultiliearUniversalParams, UnivariateUniversalParams) and it does not have <Self::SRS as StructuredReferenceString>::ProverParam


pub trait MultilinearCommitmentScheme<E: PairingEngine> {
/// This trait defines APIs for polynomial commitment schemes.
/// Note that for our usage of PCS, we do not require the hiding property.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, if we want a general API/traits, why not consider the cases where we do need hiding?

If we consider hiding, then two things:

  • our Polynomial better be a LabeledPolynomial (at least something of similar spirit?)
  • we need to pass in an rng to commit() etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can leave this as an TODO for future. We do not currently need hiding property.

/// WARNING: THIS FUNCTION IS FOR TESTING PURPOSE ONLY.
/// THE OUTPUT SRS SHOULD NOT BE USED IN PRODUCTION.
fn setup<R: RngCore>(rng: &mut R, num_vars: usize) -> Result<Self::SRS, PCSErrors>;
fn gen_srs_for_testing<R: RngCore>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Not sure why we use RngCore rather than Rng
  2. can provide a default implementation: by invoking SRS's gen_srs_for_testing

Copy link
Contributor Author

@zhenfeizhang zhenfeizhang Jul 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can provide a default implementation: by invoking SRS's gen_srs_for_testing

no. SRS may not be a single universal parameter.

// Polynomial and its associated types
type Polynomial;
type Point;
type Evaluation;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is type Evaluation necessary? isn't it always E::Fr?
especially when our verify() and batch_verify() taking a value: E::Fr or values: &[E::Fr] directly.

Comment on lines +82 to +88
fn batch_verify<R: RngCore>(
verifier_param: &Self::VerifierParam,
multi_commitment: &Self::Commitment,
points: &[&[E::Fr]],
multi_commitment: &Self::BatchCommitment,
points: &[Self::Point],
values: &[E::Fr],
batch_proof: &Self::BatchProof,
transcript: &mut IOPTranscript<E::Fr>,
rng: &mut R,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's strange to only have batch_verify() taking an rng as input.
imo either both verify() and batch_verify() takes an optional rng, or both takes rngs but not necessarily use it.

I understand that usually only during batching, you need a randomizer to combine all opening proofs/statements. But one could implement a deterministic batch verification just by verifying one by one as well.
Therefore imo, the two variants of verify API should resemble each other in this regard.

Copy link
Contributor

@alxiong alxiong Jul 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chancharles92 Can we remove rng and use FS to deterministically derive randomness?
it makes more sense to have deterministic verification algorithm.

@zhenfeizhang mentioned that altho heuristically it should be fine, we don't have a rigorous proof.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants