Skip to content

Commit

Permalink
Move 'TinyBLS' to zexe backend
Browse files Browse the repository at this point in the history
  • Loading branch information
drskalman committed Nov 30, 2020
1 parent 6356a8b commit 44ebfab
Showing 1 changed file with 51 additions and 42 deletions.
93 changes: 51 additions & 42 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,53 +252,62 @@ impl<E: PairingEngine> EngineBLS for UsualBLS<E> {
}


// /// Infrequently used BLS variant with tiny 48 byte signatures and 96 byte public keys,
// ///
// /// We recommend gainst this variant by default because verifiers
// /// always perform `O(signers)` additions on the `PublicKeyGroup`,
// /// or worse 128 bit scalar multiplications with delinearization.
// /// Yet, there are specific use cases where this variant performs
// /// better. We swapy two group roles relative to zcash here.
// #[derive(Default)]
// pub struct TinyBLS<E: PairingEngine>(pub E);
/// Infrequently used BLS variant with tiny 48 byte signatures and 96 byte public keys,
///
/// We recommend gainst this variant by default because verifiers
/// always perform `O(signers)` additions on the `PublicKeyGroup`,
/// or worse 128 bit scalar multiplications with delinearization.
/// Yet, there are specific use cases where this variant performs
/// better. We swapy two group roles relative to zcash here.
#[derive(Default)]
pub struct TinyBLS<E: PairingEngine>(pub E);

// impl<E: PairingEngine> EngineBLS for TinyBLS<E> {
// type Engine = E;
// type Scalar = <Self::Engine as PairingEngine>::Fr;
impl<E: PairingEngine> EngineBLS for TinyBLS<E> {
type Engine = E;
type Scalar = <Self::Engine as PairingEngine>::Fr;

// type SignatureGroup = E::G1Projective;
// type SignatureGroupAffine = E::G1Affine;
// type SignaturePrepared = E::G1Prepared;
// type SignatureGroupBaseField = <Self::Engine as PairingEngine>::Fq;
type SignatureGroup = E::G1Projective;
type SignatureGroupAffine = E::G1Affine;
type SignaturePrepared = E::G1Prepared;
type SignatureGroupBaseField = <Self::Engine as PairingEngine>::Fq;

// type PublicKeyGroup = E::G2Projective;
// type PublicKeyGroupAffine = E::G2Affine;
// type PublicKeyPrepared = E::G2Prepared;
// type PublicKeyGroupBaseField = <Self::Engine as PairingEngine>::Fqe;
type PublicKeyGroup = E::G2Projective;
type PublicKeyGroupAffine = E::G2Affine;
type PublicKeyPrepared = E::G2Prepared;
type PublicKeyGroupBaseField = <Self::Engine as PairingEngine>::Fqe;

// fn miller_loop<'a,I>(i: I) -> E::Fqk
// where
// I: IntoIterator<Item = (
// &'a Self::PublicKeyPrepared,
// &'a Self::SignaturePrepared,
// )>,
// {
// // We require an ugly unecessary allocation here because
// // zcash's pairing library cnsumes an iterator of references
// // to tuples of references, which always requires
// let i = i.into_iter().map(|(x,y)| (y,x))
// .collect::<Vec<(&Self::SignatureGroupPrepared, &Self::PublicKeyGroupPrepared)>>();
// E::miller_loop(&i)
// }
fn miller_loop<'a,I>(i: I) -> E::Fqk
where
I: IntoIterator<Item = &'a(
Self::PublicKeyPrepared,
Self::SignaturePrepared,
)>,
{
// We require an ugly unecessary allocation here because
// zcash's pairing library cnsumes an iterator of references
// to tuples of references, which always requires
let i = i.into_iter().map(|(x,y)| (y.clone(),x.clone()))
.collect::<Vec<(Self::SignaturePrepared, Self::PublicKeyPrepared)>>();

This comment has been minimized.

Copy link
@burdges

burdges Nov 30, 2020

Collaborator

I'd think (x,y).clone() and .collect::<Vec<(_,_)>>(); both work here since I enforces their types.

This comment has been minimized.

Copy link
@drskalman

drskalman Dec 1, 2020

Author Collaborator

.collect::<Vec<(_,_)>>() works fine but (x,y).clone() doesn't it. it clones it as (&Self::SignaturePrepared, &Self::PublicKeyPrepared) which is what the old interface was requiring but the new interface expect a reference to pair of objects.

This comment has been minimized.

Copy link
@burdges

burdges Dec 1, 2020

Collaborator

Odd since I specifies that type, but whatever.

E::miller_loop(&i)
}

// fn pairing<G2,G1>(p: G2, q: G1) -> E::Fqk
// where
// G1: Into<E::G1Affine>,
// G2: Into<E::G2Affine>,
// {
// E::pairing(q,p)
// }
// }
fn pairing<G2,G1>(p: G2, q: G1) -> E::Fqk
where
G1: Into<E::G1Affine>,
G2: Into<E::G2Affine>,
{
E::pairing(q,p)
}

/// Prepared negative of the generator of the public key curve.
fn public_key_minus_generator_prepared()
-> Self::PublicKeyPrepared
{
let mut g2_minus_generator = <Self::PublicKeyGroup as CurveProjective>::Affine::prime_subgroup_generator();
(-g2_minus_generator).into()
}

}


// /// Rogue key attack defence by proof-of-possession
Expand Down

0 comments on commit 44ebfab

Please sign in to comment.