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

Impl From trait for Commitment #492

Merged
merged 3 commits into from
Apr 13, 2021
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Change 'from_projective' method for the implementation of the ::from trait. [#433] (https://github.com/dusk-network/plonk/issues/433)

## [0.7.0] - 06-04-21

### Added
Expand Down
7 changes: 4 additions & 3 deletions src/commitment_scheme/kzg10/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ impl CommitKey {
self.check_commit_degree_is_within_bounds(polynomial.degree())?;

// Compute commitment
let commitment =
msm_variable_base(&self.powers_of_g, &polynomial.coeffs);
Ok(Commitment::from_projective(commitment))
Ok(Commitment::from(msm_variable_base(
&self.powers_of_g,
&polynomial.coeffs,
)))
}

/// Computes a single witness for multiple polynomials at the same point, by
Expand Down
18 changes: 13 additions & 5 deletions src/commitment_scheme/kzg10/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl AggregateProof {
Proof {
commitment_to_witness: self.commitment_to_witness,
evaluated_point: flattened_poly_evaluations,
commitment_to_polynomial: Commitment::from_projective(
commitment_to_polynomial: Commitment::from(
flattened_poly_commitments,
),
}
Expand All @@ -102,6 +102,18 @@ pub(crate) struct Commitment(
pub(crate) G1Affine,
);

impl From<G1Affine> for Commitment {
fn from(point: G1Affine) -> Commitment {
Commitment(point)
}
}

impl From<G1Projective> for Commitment {
fn from(point: G1Projective) -> Commitment {
Commitment(point.into())
}
}

impl Serializable<{ G1Affine::SIZE }> for Commitment {
type Error = dusk_bytes::Error;

Expand All @@ -116,10 +128,6 @@ impl Serializable<{ G1Affine::SIZE }> for Commitment {
}

impl Commitment {
/// Builds a `Commitment` from a Bls12_381 `G1Projective` point.
pub(crate) fn from_projective(g: G1Projective) -> Self {
Self(g.into())
}
/// Builds an empty `Commitment` which is equivalent to the
/// `G1Affine` identity point in Bls12_381.
fn empty() -> Self {
Expand Down
13 changes: 7 additions & 6 deletions src/proof_system/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,12 @@ impl Proof {
let z_n = z_challenge.pow(&[n as u64, 0, 0, 0]);
let z_two_n = z_challenge.pow(&[2 * n as u64, 0, 0, 0]);
let z_three_n = z_challenge.pow(&[3 * n as u64, 0, 0, 0]);
let t_comm = self.t_1_comm.0
+ self.t_2_comm.0 * z_n
+ self.t_3_comm.0 * z_two_n
+ self.t_4_comm.0 * z_three_n;
Commitment::from_projective(t_comm)
Commitment::from(
self.t_1_comm.0
+ self.t_2_comm.0 * z_n
+ self.t_3_comm.0 * z_two_n
+ self.t_4_comm.0 * z_three_n,
)
}

// Commitment to [r]_1
Expand Down Expand Up @@ -424,7 +425,7 @@ impl Proof {
self.z_comm.0,
);

Commitment::from_projective(msm_variable_base(&points, &scalars))
Commitment::from(msm_variable_base(&points, &scalars))
}
}

Expand Down