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

draft version of pub key aggregation #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
21 changes: 21 additions & 0 deletions src/key.rs
Original file line number Diff line number Diff line change
@@ -4,6 +4,9 @@ use ff::{PrimeField, PrimeFieldBits};
use group::Curve;
use rand_core::{CryptoRng, RngCore};

#[cfg(feature = "multicore")]
use rayon::prelude::*;

#[cfg(feature = "pairing")]
use bls12_381::{hash_to_curve::HashToField, G1Affine, G1Projective, Scalar};
#[cfg(feature = "pairing")]
@@ -359,3 +362,21 @@ mod tests {
assert!(PublicKey::from_bytes(&[255u8; 48]).is_err());
}
}

pub fn aggregate_public_keys(public_keys: &[PublicKey]) -> Result<PublicKey, Error> {

if public_keys.is_empty() {
return Err(Error::ZeroSizedInput);
}

let res = public_keys
.into_par_iter()
.fold(G1Projective::identity, |mut acc, public_key| {
acc += &public_key.0;
acc
})
.reduce(G1Projective::identity, |acc, val| acc + val);

Ok(PublicKey(res.into()))
}

2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ mod signature;

pub use self::error::Error;
pub use self::key::{PrivateKey, PublicKey, Serialize};
pub use self::signature::{aggregate, hash, verify, verify_messages, Signature};
pub use self::signature::{aggregate, hash, verify, verify_messages, verify_agg_signatures_on_same_hash, Signature};

#[cfg(test)]
#[macro_use]
8 changes: 8 additions & 0 deletions src/signature.rs
Original file line number Diff line number Diff line change
@@ -179,6 +179,14 @@ pub fn verify(signature: &Signature, hashes: &[G2Projective], public_keys: &[Pub
ml.final_exponentiation() == Gt::identity()
}

pub fn verify_agg_signatures_on_same_hash(signature: &Signature, hash: &G2Projective, public_keys: &[PublicKey]) -> bool {
// Aggregate the public keys into a single public key
let pub_key_aggregated = aggregate_public_keys(public_keys).unwrap();

// Verify this as normal
verify(signature, std::slice::from_ref(hash), std::slice::from_ref(&pub_key_aggregated))
}

/// Verifies that the signature is the actual aggregated signature of messages - pubkeys.
/// Calculated by `e(g1, signature) == \prod_{i = 0}^n e(pk_i, hash_i)`.
#[cfg(feature = "pairing")]