Skip to content
Open
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
15 changes: 7 additions & 8 deletions src/experimental/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ where
type M = Message;
type PKG = PublicKey<E>;

type PKnM = ::core::iter::Once<(Message, PublicKey<E>)>;

fn messages_and_publickeys(self) -> Self::PKnM {
fn messages_and_publickeys(
self,
) -> impl Iterator<Item = (Message, PublicKey<E>)> + ExactSizeIterator {
let mut publickey = E::PublicKeyGroup::zero();
for i in 0..8 * self.signers.borrow().len() {
if self.signers.borrow()[i / 8] & (1 << (i % 8)) != 0 {
Expand Down Expand Up @@ -380,9 +380,9 @@ where
type M = Message;
type PKG = PublicKey<E>;

type PKnM = ::core::iter::Once<(Message, PublicKey<E>)>;

fn messages_and_publickeys(self) -> Self::PKnM {
fn messages_and_publickeys(
self,
) -> impl Iterator<Item = (Message, PublicKey<E>)> + ExactSizeIterator {
let mut publickey = E::PublicKeyGroup::zero();
for signers in self.signers.iter().rev().map(|signers| signers.borrow()) {
publickey.double_in_place();
Expand Down Expand Up @@ -660,8 +660,7 @@ mod tests {
assert!(bitsig1.merge(&bitsig2).is_err());

let mut multimsg =
crate::multi_pop_aggregator::MultiMessageSignatureAggregatorAssumingPoP::<ZBLS>::new(
);
crate::multi_pop_aggregator::MultiMessageSignatureAggregatorAssumingPoP::<ZBLS>::new();
multimsg.aggregate(&bitsig1);
multimsg.aggregate(&bitsig2);
assert!(multimsg.verify()); // verifiers::verify_with_distinct_messages(&dms,true)
Expand Down
5 changes: 3 additions & 2 deletions src/experimental/delinear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ impl<'a, E: EngineBLS> Signed for &'a Delinearized<E> {

type M = &'a Message;
type PKG = &'a PublicKey<Self::E>;
type PKnM = ::std::collections::hash_map::Iter<'a, Message, PublicKey<E>>;

fn messages_and_publickeys(self) -> Self::PKnM {
fn messages_and_publickeys(
self,
) -> impl Iterator<Item = (&'a Message, &'a PublicKey<E>)> + ExactSizeIterator {
self.messages_n_publickeys.iter()
}

Expand Down
5 changes: 3 additions & 2 deletions src/experimental/distinct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ impl<'a, E: EngineBLS> Signed for &'a DistinctMessages<E> {

type M = &'a Message;
type PKG = &'a PublicKey<Self::E>;
type PKnM = ::std::collections::hash_map::Iter<'a, Message, PublicKey<E>>;

fn messages_and_publickeys(self) -> Self::PKnM {
fn messages_and_publickeys(
self,
) -> impl Iterator<Item = (&'a Message, &'a PublicKey<E>)> + ExactSizeIterator {
self.messages_n_publickeys.iter()
}

Expand Down
20 changes: 5 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
#[cfg(doctest)]
pub struct ReadmeDoctests;


extern crate ark_serialize;
extern crate ark_serialize_derive;

Expand Down Expand Up @@ -253,29 +252,20 @@ impl<'a> From<&'a [u8]> for Message {
/// We shall make `messages_and_publickeys` take `&sefl` and
/// remove these limitations in the future once ATCs stabalize,
/// thus removing `PKG`. See [Rust RFC 1598](https://github.com/rust-lang/rfcs/blob/master/text/1598-generic_associated_types.md)
/// We shall eventually remove MnPK entirely whenever `-> impl Trait`
/// in traits gets stabalized. See [Rust RFCs 1522, 1951, and 2071](https://github.com/rust-lang/rust/issues/34511
pub trait Signed: Sized {
type E: EngineBLS;

/// Return the aggregated signature
fn signature(&self) -> Signature<Self::E>;

type M: Borrow<Message>; // = Message;
type PKG: Borrow<PublicKey<Self::E>>; // = PublicKey<Self::E>;

/// Iterator over, messages and public key reference pairs.
type PKnM: Iterator<Item = (Self::M, Self::PKG)> + ExactSizeIterator;
// type PKnM<'a>: Iterator<Item = (
// &'a <<Self as Signed<'a>>::E as EngineBLS>::PublicKeyGroup,
// &'a Self::M,
// )> + DoubleEndedIterator + ExactSizeIterator + 'a;
type M: Borrow<Message>;
type PKG: Borrow<PublicKey<Self::E>>;

/// Returns an iterator over messages and public key reference for
/// pairings, often only partially aggregated.
fn messages_and_publickeys(self) -> Self::PKnM;
// fn messages_and_publickeys<'a>(&'s self) -> PKnM<'a>
// -> impl Iterator<Item = (&'a Self::M, &'a Self::E::PublicKeyGroup)> + 'a;
fn messages_and_publickeys(
self,
) -> impl Iterator<Item = (Self::M, Self::PKG)> + ExactSizeIterator;

/// Appropriate BLS signature verification for the `Self` type.
///
Expand Down
54 changes: 32 additions & 22 deletions src/multi_pop_aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
// https://twitter.com/btcVeg/status/1085490561082183681

use core::borrow::Borrow; // BorrowMut
// We use BTreeMap instead of BTreeMap for no_std compatibility.
// We use BTreeMap instead of BTreeMap for no_std compatibility.
use alloc::collections::BTreeMap;

use ark_ff::Zero;
Expand Down Expand Up @@ -134,9 +134,10 @@ impl<'a, E: EngineBLS> Signed for &'a MultiMessageSignatureAggregatorAssumingPoP

type M = &'a Message;
type PKG = &'a PublicKey<Self::E>;
type PKnM = alloc::collections::btree_map::Iter<'a, Message, PublicKey<E>>;

fn messages_and_publickeys(self) -> Self::PKnM {
fn messages_and_publickeys(
self,
) -> impl Iterator<Item = (&'a Message, &'a PublicKey<E>)> + ExactSizeIterator {
self.messages_n_publickeys.iter()
}

Expand All @@ -161,8 +162,8 @@ mod tests {
use crate::Keypair;
use crate::Message;
use crate::UsualBLS;
use rand::SeedableRng;
use rand::rngs::StdRng;
use rand::SeedableRng;

use ark_bls12_381::Bls12_381;

Expand All @@ -172,8 +173,9 @@ mod tests {
fn verify_aggregate_single_message_single_signer() {
let good = Message::new(b"ctx", b"test message");

let mut keypair =
Keypair::<UsualBLS<Bls12_381, ark_bls12_381::Config>>::generate(StdRng::from_seed([0u8; 32]));
let mut keypair = Keypair::<UsualBLS<Bls12_381, ark_bls12_381::Config>>::generate(
StdRng::from_seed([0u8; 32]),
);
let good_sig0 = keypair.sign(&good);
assert!(good_sig0.verify(&good, &keypair.public));
}
Expand All @@ -182,12 +184,14 @@ mod tests {
fn verify_aggregate_single_message_multi_signers() {
let good = Message::new(b"ctx", b"test message");

let mut keypair0 =
Keypair::<UsualBLS<Bls12_381, ark_bls12_381::Config>>::generate(StdRng::from_seed([0u8; 32]));
let mut keypair0 = Keypair::<UsualBLS<Bls12_381, ark_bls12_381::Config>>::generate(
StdRng::from_seed([0u8; 32]),
);
let good_sig0 = keypair0.sign(&good);

let mut keypair1 =
Keypair::<UsualBLS<Bls12_381, ark_bls12_381::Config>>::generate(StdRng::from_seed([1u8; 32]));
let mut keypair1 = Keypair::<UsualBLS<Bls12_381, ark_bls12_381::Config>>::generate(
StdRng::from_seed([1u8; 32]),
);
let good_sig1 = keypair1.sign(&good);

let mut aggregated_sigs = MultiMessageSignatureAggregatorAssumingPoP::<
Expand All @@ -210,8 +214,9 @@ mod tests {
let good0 = Message::new(b"ctx", b"Tab over Space");
let good1 = Message::new(b"ctx", b"Space over Tab");

let mut keypair =
Keypair::<UsualBLS<Bls12_381, ark_bls12_381::Config>>::generate(StdRng::from_seed([0u8; 32]));
let mut keypair = Keypair::<UsualBLS<Bls12_381, ark_bls12_381::Config>>::generate(
StdRng::from_seed([0u8; 32]),
);

let good_sig0 = keypair.sign(&good0);
let good_sig1 = keypair.sign(&good1);
Expand All @@ -236,12 +241,14 @@ mod tests {
let good0 = Message::new(b"ctx", b"in the beginning");
let good1 = Message::new(b"ctx", b"there was a flying spaghetti monster");

let mut keypair0 =
Keypair::<UsualBLS<Bls12_381, ark_bls12_381::Config>>::generate(StdRng::from_seed([0u8; 32]));
let mut keypair0 = Keypair::<UsualBLS<Bls12_381, ark_bls12_381::Config>>::generate(
StdRng::from_seed([0u8; 32]),
);
let good_sig0 = keypair0.sign(&good0);

let mut keypair1 =
Keypair::<UsualBLS<Bls12_381, ark_bls12_381::Config>>::generate(StdRng::from_seed([1u8; 32]));
let mut keypair1 = Keypair::<UsualBLS<Bls12_381, ark_bls12_381::Config>>::generate(
StdRng::from_seed([1u8; 32]),
);
let good_sig1 = keypair1.sign(&good1);

let mut aggregated_sigs = MultiMessageSignatureAggregatorAssumingPoP::<
Expand All @@ -263,8 +270,9 @@ mod tests {
fn verify_aggregate_single_message_repetative_signers() {
let good = Message::new(b"ctx", b"test message");

let mut keypair =
Keypair::<UsualBLS<Bls12_381, ark_bls12_381::Config>>::generate(StdRng::from_seed([0u8; 32]));
let mut keypair = Keypair::<UsualBLS<Bls12_381, ark_bls12_381::Config>>::generate(
StdRng::from_seed([0u8; 32]),
);
let good_sig = keypair.sign(&good);

let mut aggregated_sigs = MultiMessageSignatureAggregatorAssumingPoP::<
Expand All @@ -287,12 +295,14 @@ mod tests {
let good0 = Message::new(b"ctx", b"Space over Tab");
let bad1 = Message::new(b"ctx", b"Tab over Space");

let mut keypair0 =
Keypair::<UsualBLS<Bls12_381, ark_bls12_381::Config>>::generate(StdRng::from_seed([0u8; 32]));
let mut keypair0 = Keypair::<UsualBLS<Bls12_381, ark_bls12_381::Config>>::generate(
StdRng::from_seed([0u8; 32]),
);
let good_sig0 = keypair0.sign(&good0);

let mut keypair1 =
Keypair::<UsualBLS<Bls12_381, ark_bls12_381::Config>>::generate(StdRng::from_seed([1u8; 32]));
let mut keypair1 = Keypair::<UsualBLS<Bls12_381, ark_bls12_381::Config>>::generate(
StdRng::from_seed([1u8; 32]),
);
let bad_sig1 = keypair1.sign(&bad1);

let mut aggregated_sigs = MultiMessageSignatureAggregatorAssumingPoP::<
Expand Down
12 changes: 5 additions & 7 deletions src/nugget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ use digest::FixedOutputReset;
use sha2::Sha256;

use crate::broken_derives;
use crate::chaum_pedersen_signature::DLEQProof;
use crate::chaum_pedersen_signature::{ChaumPedersenSigner, ChaumPedersenVerifier};
use crate::dual_scalar_mul::DualScalarMultiplication;
use crate::chaum_pedersen_signature::DLEQProof;
use crate::serialize::SerializableToBytes;
use crate::single::{Keypair, KeypairVT, PublicKey, SecretKeyVT, Signature};
use crate::{EngineBLS, Message, Signed};
Expand All @@ -34,8 +34,6 @@ use crate::{EngineBLS, Message, Signed};
pub struct PublicKeyInSignatureGroup<E: EngineBLS>(pub E::SignatureGroup);
broken_derives!(PublicKeyInSignatureGroup); // Actually the derive works for this one, not sure why.

//TODO: Make a type for a sister group. This makes sense because SisterGroup it doesn't mean on itself
// SisterGroup<E: EngineBLS> = CurveGroup + PrimeGroup<ScalarField = E::Scalar> + SerializableToBytes
/// Wrapper for a point in the third curve sister group which is supposed to
/// have the same logarithm as the public key in the public key group
#[derive(Debug, Clone, Copy, PartialEq, Eq, CanonicalDeserialize)]
Expand Down Expand Up @@ -218,10 +216,10 @@ where
type M = Message;
type PKG = PublicKey<E>;

type PKnM = ::core::iter::Once<(Message, PublicKey<E>)>;

fn messages_and_publickeys(self) -> Self::PKnM {
once((self.message.clone(), self.publickey.into_bls_public_key())) // TODO: Avoid clone
fn messages_and_publickeys(
self,
) -> impl Iterator<Item = (Message, PublicKey<E>)> + ExactSizeIterator {
once((self.message.clone(), self.publickey.into_bls_public_key()))
}

fn signature(&self) -> Signature<E> {
Expand Down
Loading