-
Notifications
You must be signed in to change notification settings - Fork 0
Minimal traits for ADKG #59
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
Open
GarryFCR
wants to merge
9
commits into
dev
Choose a base branch
from
adkg
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d72b872
add free functions & delete unnecessary ManuallyDrop
LYC386 81fa3a7
types-preprocess (#44)
GarryFCR 17affd0
add some improvements to dev
de229b5
Initial trait for the adkg functions
GarryFCR 4e25c3e
add some improvements to dev
7e054ab
Initial trait for the adkg functions
GarryFCR 12bcd6f
Merge remote-tracking branch 'origin/adkg' into adkg
hdvanegasm 61fccc1
feat(acss): implemented Pedersen commitments with basic tests.
hdvanegasm 244acee
fix(acss): minor import changes in Pedersen
hdvanegasm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| /// Implementation of Pedersen commitments. | ||
| pub mod pedersen; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| use ark_ec::CurveGroup; | ||
| use ark_ff::FftField; | ||
| use ark_std::rand::Rng; | ||
|
|
||
| /// Public parameters for Pedersen commitment to polynomials. | ||
| pub struct PedersenPolyCommParams<F, G> | ||
| where | ||
| G: CurveGroup<ScalarField = F>, | ||
| F: FftField, | ||
| { | ||
| /// Base point g. | ||
| pub g: G, | ||
| /// Base point h. | ||
| /// | ||
| /// # Security requirement | ||
| /// | ||
| /// This point should be such that nobody knows `log_g(h)`. | ||
| pub h: G, | ||
| } | ||
|
|
||
| impl<F, G> PedersenPolyCommParams<F, G> | ||
| where | ||
| G: CurveGroup<ScalarField = F>, | ||
| F: FftField, | ||
| { | ||
| /// Creates a new parameter set for Pedersen commitments. | ||
| pub fn new(g: G, h: G) -> Self { | ||
| Self { g, h } | ||
| } | ||
| } | ||
|
|
||
| /// Pedersen commitments for a polynomial. | ||
| /// | ||
| /// The commitment is a collection of individual Pedersen commitments to each coefficient of the | ||
| /// polynomial. | ||
| pub struct PedersenPolyCommitment<F, G> | ||
| where | ||
| G: CurveGroup<ScalarField = F>, | ||
| F: FftField, | ||
| { | ||
| /// Public parameters used for this commitment. | ||
| pub public_params: PedersenPolyCommParams<F, G>, | ||
| /// Commitments to the polynomial coefficients. | ||
| pub coeff_commitments: Vec<G>, | ||
| } | ||
|
|
||
| impl<F, G> PedersenPolyCommitment<F, G> | ||
| where | ||
| G: CurveGroup<ScalarField = F>, | ||
| F: FftField, | ||
| { | ||
| /// Computes the commitment to a polynomial. | ||
| pub fn commit( | ||
| public_params: PedersenPolyCommParams<F, G>, | ||
| poly_coeffs: &[F], | ||
| rng: &mut impl Rng, | ||
| ) -> (Self, Vec<F>) { | ||
| let random_t: Vec<F> = (0..poly_coeffs.len()).map(|_| F::rand(rng)).collect(); | ||
| let coeff_commitments = poly_coeffs | ||
| .iter() | ||
| .zip(random_t.clone()) | ||
| .map(|(coeff, t)| public_params.g.mul(*coeff).add(public_params.h.mul(t))) | ||
| .collect(); | ||
| ( | ||
| PedersenPolyCommitment { | ||
| public_params, | ||
| coeff_commitments, | ||
| }, | ||
| random_t, | ||
| ) | ||
| } | ||
|
|
||
| /// Verifies the polynomial commitment. | ||
| pub fn verify(&self, poly_coeffs: &[F], random_t: &[F]) -> bool { | ||
| self.coeff_commitments | ||
| .iter() | ||
| .zip(poly_coeffs.iter()) | ||
| .zip(random_t.iter()) | ||
| .all(|((&commitment, &coeff), &random_t)| { | ||
| commitment == self.public_params.g.mul(coeff) + self.public_params.h.mul(random_t) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| mod tests { | ||
| use crate::common::acss::pedersen::{PedersenPolyCommParams, PedersenPolyCommitment}; | ||
| use ark_bls12_381::Fr; | ||
| use ark_poly::univariate::DensePolynomial; | ||
| use ark_poly::DenseUVPolynomial; | ||
| use ark_std::UniformRand; | ||
| use std::ops::Add; | ||
|
|
||
| #[test] | ||
| fn commitment_verifies_with_correct_coeffs() { | ||
| let mut rng = ark_std::test_rng(); | ||
| let g = ark_bls12_381::G1Projective::rand(&mut rng); | ||
| let h = ark_bls12_381::G1Projective::rand(&mut rng); | ||
| let public_params = PedersenPolyCommParams::new(g, h); | ||
| let polynomial = DensePolynomial::rand(100, &mut rng); | ||
| let (commitment, random_t) = | ||
| PedersenPolyCommitment::commit(public_params, &polynomial.coeffs, &mut rng); | ||
| assert!(commitment.verify(&polynomial.coeffs, &random_t)) | ||
| } | ||
|
|
||
| #[test] | ||
| fn commitment_does_not_verify_with_wrong_coeffs() { | ||
| let mut rng = ark_std::test_rng(); | ||
| let g = ark_bls12_381::G1Projective::rand(&mut rng); | ||
| let h = ark_bls12_381::G1Projective::rand(&mut rng); | ||
| let public_params = PedersenPolyCommParams::new(g, h); | ||
| let polynomial = DensePolynomial::rand(100, &mut rng); | ||
| let (commitment, random_t) = | ||
| PedersenPolyCommitment::commit(public_params, &polynomial.coeffs, &mut rng); | ||
| let modified_coeffs: Vec<Fr> = polynomial | ||
| .coeffs | ||
| .iter() | ||
| .map(|coeff| coeff.add(&ark_bls12_381::Fr::from(1))) | ||
| .collect(); | ||
| assert!(!commitment.verify(&modified_coeffs, &random_t)) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are using the existing preprocessing_materials for rand, we'll need to carefully track the usage of rand vs mul to ensure that there are enough preprocessing materials. I would expect some of this functionality to be done on the VM side (cc'ing @gabearro)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, there will be automatic calculation of the needed amount and yes the approx. number needed will be decided from @gabearro's side