-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch from ark-bn254 to matterlabs/pairing (BFT-325) (#28)
Switching [bn254](#11) implementation from [crates/ark-bn254](https://crates.io/crates/ark-bn254) to [matter-labs/pairing](https://github.com/matter-labs/pairing) due to compatibility issues of [zksync-era](https://github.com/matter-labs/zksync-era) with the former. ### Notes: * `bn254::tests::byte_fmt_correctness` tests were added, previously not covered
- Loading branch information
Showing
8 changed files
with
253 additions
and
273 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,50 @@ | ||
//! Random key generation, intended for use in testing | ||
use super::{AggregateSignature, PublicKey, SecretKey, Signature}; | ||
use rand::{distributions::Standard, prelude::Distribution, Rng}; | ||
use pairing::bn256::{Fr, G1, G2}; | ||
use rand::{distributions::Standard, prelude::Distribution, Rng, RngCore}; | ||
use rand04::Rand; | ||
|
||
struct RngWrapper<R>(R); | ||
|
||
impl<R: RngCore> rand04::Rng for RngWrapper<R> { | ||
fn next_u32(&mut self) -> u32 { | ||
self.0.next_u32() | ||
} | ||
|
||
fn next_u64(&mut self) -> u64 { | ||
self.0.next_u64() | ||
} | ||
} | ||
|
||
/// Generates a random SecretKey. This is meant for testing purposes. | ||
impl Distribution<SecretKey> for Standard { | ||
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> SecretKey { | ||
let rand = ark_bn254::Fr::new(rng.gen()); | ||
SecretKey(rand) | ||
let scalar = Fr::rand(&mut RngWrapper(rng)); | ||
SecretKey(scalar) | ||
} | ||
} | ||
|
||
/// Generates a random PublicKey. This is meant for testing purposes. | ||
impl Distribution<PublicKey> for Standard { | ||
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> PublicKey { | ||
PublicKey(rng.gen()) | ||
let p = G2::rand(&mut RngWrapper(rng)); | ||
PublicKey(p) | ||
} | ||
} | ||
|
||
/// Generates a random Signature. This is meant for testing purposes. | ||
impl Distribution<Signature> for Standard { | ||
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Signature { | ||
Signature(rng.gen()) | ||
let p = G1::rand(&mut RngWrapper(rng)); | ||
Signature(p) | ||
} | ||
} | ||
|
||
/// Generates a random AggregateSignature. This is meant for testing purposes. | ||
impl Distribution<AggregateSignature> for Standard { | ||
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> AggregateSignature { | ||
AggregateSignature(rng.gen()) | ||
let p = G1::rand(&mut RngWrapper(rng)); | ||
AggregateSignature(p) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters