mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-02-12 18:15:49 +00:00
Use ff crate for Field traits
This commit is contained in:
parent
10c5010fd9
commit
718b25c949
@ -11,12 +11,16 @@ version = "0.1.0"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
rand = "0.4"
|
rand = "0.4"
|
||||||
bit-vec = "0.4.4"
|
bit-vec = "0.4.4"
|
||||||
|
ff = "0.4"
|
||||||
futures = "0.1"
|
futures = "0.1"
|
||||||
futures-cpupool = "0.1"
|
futures-cpupool = "0.1"
|
||||||
num_cpus = "1"
|
num_cpus = "1"
|
||||||
crossbeam = "0.3"
|
crossbeam = "0.3"
|
||||||
pairing = "0.14"
|
|
||||||
byteorder = "1"
|
byteorder = "1"
|
||||||
|
|
||||||
|
[dependencies.pairing]
|
||||||
|
git = "https://github.com/ebfull/pairing"
|
||||||
|
rev = "183a64b08e9dc7067f78624ec161371f1829623e"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
|
@ -10,10 +10,9 @@
|
|||||||
//! This allows us to perform polynomial operations in O(n)
|
//! This allows us to perform polynomial operations in O(n)
|
||||||
//! by performing an O(n log n) FFT over such a domain.
|
//! by performing an O(n log n) FFT over such a domain.
|
||||||
|
|
||||||
|
use ff::{Field, PrimeField};
|
||||||
use pairing::{
|
use pairing::{
|
||||||
Engine,
|
Engine,
|
||||||
Field,
|
|
||||||
PrimeField,
|
|
||||||
CurveProjective
|
CurveProjective
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2,10 +2,9 @@ use rand::Rng;
|
|||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use ff::{Field, PrimeField};
|
||||||
use pairing::{
|
use pairing::{
|
||||||
Engine,
|
Engine,
|
||||||
PrimeField,
|
|
||||||
Field,
|
|
||||||
Wnaf,
|
Wnaf,
|
||||||
CurveProjective,
|
CurveProjective,
|
||||||
CurveAffine
|
CurveAffine
|
||||||
|
@ -486,8 +486,8 @@ mod test_with_bls12_381 {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use {Circuit, SynthesisError, ConstraintSystem};
|
use {Circuit, SynthesisError, ConstraintSystem};
|
||||||
|
|
||||||
|
use ff::Field;
|
||||||
use rand::{Rand, thread_rng};
|
use rand::{Rand, thread_rng};
|
||||||
use pairing::{Field};
|
|
||||||
use pairing::bls12_381::{Bls12, Fr};
|
use pairing::bls12_381::{Bls12, Fr};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -4,10 +4,9 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
|
|
||||||
|
use ff::{Field, PrimeField};
|
||||||
use pairing::{
|
use pairing::{
|
||||||
Engine,
|
Engine,
|
||||||
PrimeField,
|
|
||||||
Field,
|
|
||||||
CurveProjective,
|
CurveProjective,
|
||||||
CurveAffine
|
CurveAffine
|
||||||
};
|
};
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
|
use ff::{
|
||||||
|
Field, LegendreSymbol, PrimeField, PrimeFieldDecodingError,
|
||||||
|
PrimeFieldRepr, ScalarEngine, SqrtField};
|
||||||
use pairing::{
|
use pairing::{
|
||||||
Engine,
|
Engine,
|
||||||
PrimeField,
|
|
||||||
PrimeFieldRepr,
|
|
||||||
Field,
|
|
||||||
SqrtField,
|
|
||||||
LegendreSymbol,
|
|
||||||
CurveProjective,
|
CurveProjective,
|
||||||
CurveAffine,
|
CurveAffine,
|
||||||
PrimeFieldDecodingError,
|
|
||||||
GroupDecodingError,
|
GroupDecodingError,
|
||||||
EncodedPoint
|
EncodedPoint
|
||||||
};
|
};
|
||||||
@ -263,8 +260,11 @@ impl PrimeField for Fr {
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct DummyEngine;
|
pub struct DummyEngine;
|
||||||
|
|
||||||
impl Engine for DummyEngine {
|
impl ScalarEngine for DummyEngine {
|
||||||
type Fr = Fr;
|
type Fr = Fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Engine for DummyEngine {
|
||||||
type G1 = Fr;
|
type G1 = Fr;
|
||||||
type G1Affine = Fr;
|
type G1Affine = Fr;
|
||||||
type G2 = Fr;
|
type G2 = Fr;
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
use pairing::{
|
use ff::{Field, PrimeField};
|
||||||
Engine,
|
use pairing::Engine;
|
||||||
Field,
|
|
||||||
PrimeField
|
|
||||||
};
|
|
||||||
|
|
||||||
mod dummy_engine;
|
mod dummy_engine;
|
||||||
use self::dummy_engine::*;
|
use self::dummy_engine::*;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
use ff::PrimeField;
|
||||||
use pairing::{
|
use pairing::{
|
||||||
Engine,
|
Engine,
|
||||||
CurveProjective,
|
CurveProjective,
|
||||||
CurveAffine,
|
CurveAffine,
|
||||||
PrimeField
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
extern crate ff;
|
||||||
extern crate pairing;
|
extern crate pairing;
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
extern crate num_cpus;
|
extern crate num_cpus;
|
||||||
@ -12,7 +13,8 @@ mod multiexp;
|
|||||||
pub mod domain;
|
pub mod domain;
|
||||||
pub mod groth16;
|
pub mod groth16;
|
||||||
|
|
||||||
use pairing::{Engine, Field};
|
use ff::Field;
|
||||||
|
use pairing::Engine;
|
||||||
|
|
||||||
use std::ops::{Add, Sub};
|
use std::ops::{Add, Sub};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
|
use ff::{Field, PrimeField, PrimeFieldRepr, ScalarEngine};
|
||||||
use pairing::{
|
use pairing::{
|
||||||
CurveAffine,
|
CurveAffine,
|
||||||
CurveProjective,
|
CurveProjective,
|
||||||
Engine,
|
|
||||||
PrimeField,
|
|
||||||
Field,
|
|
||||||
PrimeFieldRepr
|
|
||||||
};
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::io;
|
use std::io;
|
||||||
@ -141,7 +138,7 @@ fn multiexp_inner<Q, D, G, S>(
|
|||||||
pool: &Worker,
|
pool: &Worker,
|
||||||
bases: S,
|
bases: S,
|
||||||
density_map: D,
|
density_map: D,
|
||||||
exponents: Arc<Vec<<<G::Engine as Engine>::Fr as PrimeField>::Repr>>,
|
exponents: Arc<Vec<<<G::Engine as ScalarEngine>::Fr as PrimeField>::Repr>>,
|
||||||
mut skip: u32,
|
mut skip: u32,
|
||||||
c: u32,
|
c: u32,
|
||||||
handle_trivial: bool
|
handle_trivial: bool
|
||||||
@ -167,8 +164,8 @@ fn multiexp_inner<Q, D, G, S>(
|
|||||||
// Create space for the buckets
|
// Create space for the buckets
|
||||||
let mut buckets = vec![<G as CurveAffine>::Projective::zero(); (1 << c) - 1];
|
let mut buckets = vec![<G as CurveAffine>::Projective::zero(); (1 << c) - 1];
|
||||||
|
|
||||||
let zero = <G::Engine as Engine>::Fr::zero().into_repr();
|
let zero = <G::Engine as ScalarEngine>::Fr::zero().into_repr();
|
||||||
let one = <G::Engine as Engine>::Fr::one().into_repr();
|
let one = <G::Engine as ScalarEngine>::Fr::one().into_repr();
|
||||||
|
|
||||||
// Sort the bases into buckets
|
// Sort the bases into buckets
|
||||||
for (&exp, density) in exponents.iter().zip(density_map.as_ref().iter()) {
|
for (&exp, density) in exponents.iter().zip(density_map.as_ref().iter()) {
|
||||||
@ -211,7 +208,7 @@ fn multiexp_inner<Q, D, G, S>(
|
|||||||
|
|
||||||
skip += c;
|
skip += c;
|
||||||
|
|
||||||
if skip >= <G::Engine as Engine>::Fr::NUM_BITS {
|
if skip >= <G::Engine as ScalarEngine>::Fr::NUM_BITS {
|
||||||
// There isn't another region.
|
// There isn't another region.
|
||||||
Box::new(this)
|
Box::new(this)
|
||||||
} else {
|
} else {
|
||||||
@ -238,7 +235,7 @@ pub fn multiexp<Q, D, G, S>(
|
|||||||
pool: &Worker,
|
pool: &Worker,
|
||||||
bases: S,
|
bases: S,
|
||||||
density_map: D,
|
density_map: D,
|
||||||
exponents: Arc<Vec<<<G::Engine as Engine>::Fr as PrimeField>::Repr>>
|
exponents: Arc<Vec<<<G::Engine as ScalarEngine>::Fr as PrimeField>::Repr>>
|
||||||
) -> Box<Future<Item=<G as CurveAffine>::Projective, Error=SynthesisError>>
|
) -> Box<Future<Item=<G as CurveAffine>::Projective, Error=SynthesisError>>
|
||||||
where for<'a> &'a Q: QueryDensity,
|
where for<'a> &'a Q: QueryDensity,
|
||||||
D: Send + Sync + 'static + Clone + AsRef<Q>,
|
D: Send + Sync + 'static + Clone + AsRef<Q>,
|
||||||
@ -280,12 +277,12 @@ fn test_with_bls12() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
use rand::{self, Rand};
|
use rand::{self, Rand};
|
||||||
use pairing::bls12_381::Bls12;
|
use pairing::{bls12_381::Bls12, Engine};
|
||||||
|
|
||||||
const SAMPLES: usize = 1 << 14;
|
const SAMPLES: usize = 1 << 14;
|
||||||
|
|
||||||
let rng = &mut rand::thread_rng();
|
let rng = &mut rand::thread_rng();
|
||||||
let v = Arc::new((0..SAMPLES).map(|_| <Bls12 as Engine>::Fr::rand(rng).into_repr()).collect::<Vec<_>>());
|
let v = Arc::new((0..SAMPLES).map(|_| <Bls12 as ScalarEngine>::Fr::rand(rng).into_repr()).collect::<Vec<_>>());
|
||||||
let g = Arc::new((0..SAMPLES).map(|_| <Bls12 as Engine>::G1::rand(rng).into_affine()).collect::<Vec<_>>());
|
let g = Arc::new((0..SAMPLES).map(|_| <Bls12 as Engine>::G1::rand(rng).into_affine()).collect::<Vec<_>>());
|
||||||
|
|
||||||
let naive = naive_multiexp(g.clone(), v.clone());
|
let naive = naive_multiexp(g.clone(), v.clone());
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
extern crate bellman;
|
extern crate bellman;
|
||||||
|
extern crate ff;
|
||||||
extern crate pairing;
|
extern crate pairing;
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
|
|
||||||
@ -9,10 +10,8 @@ use rand::{thread_rng, Rng};
|
|||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
// Bring in some tools for using pairing-friendly curves
|
// Bring in some tools for using pairing-friendly curves
|
||||||
use pairing::{
|
use ff::Field;
|
||||||
Engine,
|
use pairing::Engine;
|
||||||
Field
|
|
||||||
};
|
|
||||||
|
|
||||||
// We're going to use the BLS12-381 pairing-friendly elliptic curve.
|
// We're going to use the BLS12-381 pairing-friendly elliptic curve.
|
||||||
use pairing::bls12_381::{
|
use pairing::bls12_381::{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user