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>)>;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you explain me that how is replacing Once with ExactSizeIterator works?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

PKnM is removed from the trait definition and as the bound there was PKnM: Iterator<Item = (Self::M, Self::PKG)> + ExactSizeIterator we can use this bound as return type for messages_and_publickeys, while the actual return type will stay ::core::iter::Once<(Message, PublicKey<E>)> which implements both Iterator and ExactSizeIterator


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 @@ -659,8 +659,7 @@ mod tests {
}
assert!(bitsig1.merge(&bitsig2).is_err());

let mut multimsg =
crate::pop_aggregator::SignatureAggregatorAssumingPoP::<ZBLS>::new();
let mut multimsg = crate::pop_aggregator::SignatureAggregatorAssumingPoP::<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>>;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I believe the explicit use of hash_map was intentional to impose the hash_map's orders, do we know for sure if we remove the hash_map we get the same ordering?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The type of the value returned from messages_and_publickeys will stay the same (it just won't be explicitly stated in the associated type), so the iteration order will stay the same


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
24 changes: 8 additions & 16 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 @@ -161,7 +160,9 @@ impl<E: EngineBLS> GeneralizedBLSPublicKey<E> for PublicKey<E> {
}
}

impl<E: EngineBLS> GeneralizedBLSPublicKey<E> for (PublicKey<E>, nugget::PublicKeyInSignatureGroup<E>) {
impl<E: EngineBLS> GeneralizedBLSPublicKey<E>
for (PublicKey<E>, nugget::PublicKeyInSignatureGroup<E>)
{
fn public_key(&self) -> PublicKey<E> {
self.0
}
Expand Down Expand Up @@ -295,29 +296,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: GeneralizedBLSPublicKey<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: GeneralizedBLSPublicKey<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
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, SecretKey, 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 @@ -238,10 +236,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