Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edition 2018 clean up #113

Merged
merged 20 commits into from
Aug 23, 2019
Merged
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
1 change: 1 addition & 0 deletions bellman/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ license = "MIT/Apache-2.0"
name = "bellman"
repository = "https://github.com/ebfull/bellman"
version = "0.1.0"
edition = "2018"

[dependencies]
bit-vec = "0.4.4"
Expand Down
4 changes: 2 additions & 2 deletions bellman/src/gadgets/uint32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ mod test {
]);

for _ in 0..1000 {
let mut v = (0..32)
let v = (0..32)
.map(|_| Boolean::constant(rng.next_u32() % 2 != 0))
.collect::<Vec<_>>();

Expand Down Expand Up @@ -436,7 +436,7 @@ mod test {
]);

for _ in 0..1000 {
let mut v = (0..32)
let v = (0..32)
.map(|_| Boolean::constant(rng.next_u32() % 2 != 0))
.collect::<Vec<_>>();

Expand Down
6 changes: 3 additions & 3 deletions bellman/src/groth16/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use pairing::Engine;

use super::{Parameters, VerifyingKey};

use {Circuit, ConstraintSystem, Index, LinearCombination, SynthesisError, Variable};
use crate::{Circuit, ConstraintSystem, Index, LinearCombination, SynthesisError, Variable};

use domain::{EvaluationDomain, Scalar};
use crate::domain::{EvaluationDomain, Scalar};

use multicore::Worker;
use crate::multicore::Worker;

/// Generates a random common reference string for
/// a circuit.
Expand Down
6 changes: 3 additions & 3 deletions bellman/src/groth16/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use group::{CurveAffine, EncodedPoint};
use pairing::{Engine, PairingCurveAffine};

use SynthesisError;
use crate::SynthesisError;

use crate::multiexp::SourceBuilder;
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use multiexp::SourceBuilder;
use std::io::{self, Read, Write};
use std::sync::Arc;

Expand Down Expand Up @@ -465,7 +465,7 @@ impl<'a, E: Engine> ParameterSource<E> for &'a Parameters<E> {
#[cfg(test)]
mod test_with_bls12_381 {
use super::*;
use {Circuit, ConstraintSystem, SynthesisError};
use crate::{Circuit, ConstraintSystem, SynthesisError};

use ff::Field;
use pairing::bls12_381::{Bls12, Fr};
Expand Down
8 changes: 4 additions & 4 deletions bellman/src/groth16/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ use pairing::Engine;

use super::{ParameterSource, Proof};

use {Circuit, ConstraintSystem, Index, LinearCombination, SynthesisError, Variable};
use crate::{Circuit, ConstraintSystem, Index, LinearCombination, SynthesisError, Variable};

use domain::{EvaluationDomain, Scalar};
use crate::domain::{EvaluationDomain, Scalar};

use multiexp::{multiexp, DensityTracker, FullDensity};
use crate::multiexp::{multiexp, DensityTracker, FullDensity};

use multicore::Worker;
use crate::multicore::Worker;

fn eval<E: Engine>(
lc: &LinearCombination<E>,
Expand Down
4 changes: 2 additions & 2 deletions bellman/src/groth16/tests/dummy_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const MODULUS_R: Wrapping<u32> = Wrapping(64513);
pub struct Fr(Wrapping<u32>);

impl fmt::Display for Fr {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!(f, "{}", (self.0).0)
}
}
Expand Down Expand Up @@ -149,7 +149,7 @@ impl PartialOrd for FrRepr {
}

impl fmt::Display for FrRepr {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!(f, "{}", (self.0)[0])
}
}
Expand Down
2 changes: 1 addition & 1 deletion bellman/src/groth16/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use self::dummy_engine::*;

use std::marker::PhantomData;

use {Circuit, ConstraintSystem, SynthesisError};
use crate::{Circuit, ConstraintSystem, SynthesisError};

use super::{create_proof, generate_parameters, prepare_verifying_key, verify_proof};

Expand Down
2 changes: 1 addition & 1 deletion bellman/src/groth16/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use pairing::{Engine, PairingCurveAffine};

use super::{PreparedVerifyingKey, Proof, VerifyingKey};

use SynthesisError;
use crate::SynthesisError;

pub fn prepare_verifying_key<E: Engine>(vk: &VerifyingKey<E>) -> PreparedVerifyingKey<E> {
let mut gamma = vk.gamma_g2;
Expand Down
24 changes: 3 additions & 21 deletions bellman/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
extern crate ff;
extern crate group;
#[cfg(feature = "pairing")]
extern crate pairing;
extern crate rand_core;

extern crate bit_vec;
extern crate blake2s_simd;
extern crate byteorder;
extern crate futures;

#[cfg(feature = "multicore")]
extern crate crossbeam;
#[cfg(feature = "multicore")]
extern crate futures_cpupool;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this multicore-conditional extern crate disappear, but not the other two?

Copy link
Contributor

Choose a reason for hiding this comment

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

extern crate hex_literal stays as expected because of the #[macro_use].


#[cfg(feature = "multicore")]
extern crate num_cpus;

Expand All @@ -23,12 +11,6 @@ extern crate hex_literal;
#[cfg(test)]
extern crate rand;

#[cfg(test)]
extern crate rand_xorshift;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this test-conditional extern crate disappear, but not the extern crate rand?


#[cfg(test)]
extern crate sha2;

pub mod domain;
pub mod gadgets;
#[cfg(feature = "groth16")]
Expand Down Expand Up @@ -230,7 +212,7 @@ impl Error for SynthesisError {
}

impl fmt::Display for SynthesisError {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
if let &SynthesisError::IoError(ref e) = self {
write!(f, "I/O error: ")?;
e.fmt(f)
Expand Down Expand Up @@ -309,7 +291,7 @@ pub trait ConstraintSystem<E: ScalarEngine>: Sized {

/// This is a "namespaced" constraint system which borrows a constraint system (pushing
/// a namespace context) and, when dropped, pops out of the namespace context.
pub struct Namespace<'a, E: ScalarEngine, CS: ConstraintSystem<E> + 'a>(&'a mut CS, PhantomData<E>);
pub struct Namespace<'a, E: ScalarEngine, CS: ConstraintSystem<E>>(&'a mut CS, PhantomData<E>);

impl<'cs, E: ScalarEngine, CS: ConstraintSystem<E>> ConstraintSystem<E> for Namespace<'cs, E, CS> {
type Root = CS::Root;
Expand Down
4 changes: 2 additions & 2 deletions bellman/src/multiexp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ fn multiexp_inner<Q, D, G, S>(
mut skip: u32,
c: u32,
handle_trivial: bool,
) -> Box<Future<Item = <G as CurveAffine>::Projective, Error = SynthesisError>>
) -> Box<dyn Future<Item = <G as CurveAffine>::Projective, Error = SynthesisError>>
where
for<'a> &'a Q: QueryDensity,
D: Send + Sync + 'static + Clone + AsRef<Q>,
Expand Down Expand Up @@ -256,7 +256,7 @@ pub fn multiexp<Q, D, G, S>(
bases: S,
density_map: D,
exponents: Arc<Vec<<<G::Engine as ScalarEngine>::Fr as PrimeField>::Repr>>,
) -> Box<Future<Item = <G as CurveAffine>::Projective, Error = SynthesisError>>
) -> Box<dyn Future<Item = <G as CurveAffine>::Projective, Error = SynthesisError>>
where
for<'a> &'a Q: QueryDensity,
D: Send + Sync + 'static + Clone + AsRef<Q>,
Expand Down
13 changes: 4 additions & 9 deletions bellman/tests/mimc.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
extern crate bellman;
extern crate ff;
extern crate pairing;
extern crate rand;

// For randomness (during paramgen and proof generation)
use rand::thread_rng;

Expand Down Expand Up @@ -90,12 +85,12 @@ impl<'a, E: Engine> Circuit<E> for MiMCDemo<'a, E> {
let cs = &mut cs.namespace(|| format!("round {}", i));

// tmp = (xL + Ci)^2
let mut tmp_value = xl_value.map(|mut e| {
let tmp_value = xl_value.map(|mut e| {
e.add_assign(&self.constants[i]);
e.square();
e
});
let mut tmp = cs.alloc(
let tmp = cs.alloc(
|| "tmp",
|| tmp_value.ok_or(SynthesisError::AssignmentMissing),
)?;
Expand All @@ -110,14 +105,14 @@ impl<'a, E: Engine> Circuit<E> for MiMCDemo<'a, E> {
// new_xL = xR + (xL + Ci)^3
// new_xL = xR + tmp * (xL + Ci)
// new_xL - xR = tmp * (xL + Ci)
let mut new_xl_value = xl_value.map(|mut e| {
let new_xl_value = xl_value.map(|mut e| {
e.add_assign(&self.constants[i]);
e.mul_assign(&tmp_value.unwrap());
e.add_assign(&xr_value.unwrap());
e
});

let mut new_xl = if i == (MIMC_ROUNDS - 1) {
let new_xl = if i == (MIMC_ROUNDS - 1) {
// This is the last round, xL is our image and so
// we allocate a public input.
cs.alloc_input(
Expand Down
1 change: 1 addition & 0 deletions ff/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ documentation = "https://docs.rs/ff/"
homepage = "https://github.com/ebfull/ff"
license = "MIT/Apache-2.0"
repository = "https://github.com/ebfull/ff"
edition = "2018"

[dependencies]
byteorder = "1"
Expand Down
1 change: 1 addition & 0 deletions ff/ff_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ documentation = "https://docs.rs/ff/"
homepage = "https://github.com/ebfull/ff"
license = "MIT/Apache-2.0"
repository = "https://github.com/ebfull/ff"
edition = "2018"

[lib]
proc-macro = true
Expand Down
8 changes: 4 additions & 4 deletions ff/ff_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ fn prime_field_repr_impl(repr: &syn::Ident, limbs: usize) -> proc_macro2::TokenS
impl ::std::fmt::Debug for #repr
{
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
try!(write!(f, "0x"));
write!(f, "0x")?;
for i in self.0.iter().rev() {
try!(write!(f, "{:016x}", *i));
write!(f, "{:016x}", *i)?;
}

Ok(())
Expand All @@ -133,9 +133,9 @@ fn prime_field_repr_impl(repr: &syn::Ident, limbs: usize) -> proc_macro2::TokenS

impl ::std::fmt::Display for #repr {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
try!(write!(f, "0x"));
write!(f, "0x")?;
for i in self.0.iter().rev() {
try!(write!(f, "{:016x}", *i));
write!(f, "{:016x}", *i)?;
}

Ok(())
Expand Down
7 changes: 2 additions & 5 deletions ff/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#![allow(unused_imports)]

extern crate byteorder;
extern crate rand_core;

#[cfg(feature = "derive")]
#[macro_use]
extern crate ff_derive;
Expand Down Expand Up @@ -210,7 +207,7 @@ impl Error for PrimeFieldDecodingError {
}

impl fmt::Display for PrimeFieldDecodingError {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match *self {
PrimeFieldDecodingError::NotInField(ref repr) => {
write!(f, "{} is not an element of the field", repr)
Expand Down Expand Up @@ -266,7 +263,7 @@ pub trait PrimeField: Field {
}

/// Convert this prime field element into a biginteger representation.
fn from_repr(Self::Repr) -> Result<Self, PrimeFieldDecodingError>;
fn from_repr(_: Self::Repr) -> Result<Self, PrimeFieldDecodingError>;

/// Convert a biginteger representation into a prime field element, if
/// the number is an element of the field.
Expand Down
1 change: 1 addition & 0 deletions group/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ description = "Elliptic curve group traits and utilities"
documentation = "https://docs.rs/group/"
homepage = "https://github.com/ebfull/group"
repository = "https://github.com/ebfull/group"
edition = "2018"

[dependencies]
ff = { path = "../ff" }
Expand Down
6 changes: 1 addition & 5 deletions group/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
extern crate ff;
extern crate rand;
extern crate rand_xorshift;

use ff::{PrimeField, PrimeFieldDecodingError, ScalarEngine, SqrtField};
use rand::RngCore;
use std::error::Error;
Expand Down Expand Up @@ -180,7 +176,7 @@ impl Error for GroupDecodingError {
}

impl fmt::Display for GroupDecodingError {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match *self {
GroupDecodingError::CoordinateDecodingError(description, ref err) => {
write!(f, "{} decoding error: {}", description, err)
Expand Down
4 changes: 2 additions & 2 deletions group/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ff::{Field, PrimeField};
use rand::SeedableRng;
use rand_xorshift::XorShiftRng;

use {CurveAffine, CurveProjective, EncodedPoint};
use crate::{CurveAffine, CurveProjective, EncodedPoint};

pub fn curve_tests<G: CurveProjective>() {
let mut rng = XorShiftRng::from_seed([
Expand Down Expand Up @@ -71,7 +71,7 @@ pub fn curve_tests<G: CurveProjective>() {
}

fn random_wnaf_tests<G: CurveProjective>() {
use wnaf::*;
use crate::wnaf::*;

let mut rng = XorShiftRng::from_seed([
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
Expand Down
3 changes: 2 additions & 1 deletion librustzcash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ authors = [
"Jack Grigg <[email protected]>",
"Jay Graber <[email protected]>",
"Simon Liu <[email protected]>"
]
]
edition = "2018"

[lib]
name = "rustzcash"
Expand Down
14 changes: 1 addition & 13 deletions librustzcash/src/rustzcash.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
extern crate bellman;
extern crate blake2b_simd;
extern crate blake2s_simd;
extern crate byteorder;
extern crate ff;
extern crate libc;
extern crate pairing;
extern crate rand_core;
extern crate rand_os;
extern crate zcash_primitives;
extern crate zcash_proofs;

extern crate lazy_static;
use lazy_static;

use ff::{PrimeField, PrimeFieldRepr};
use pairing::bls12_381::{Bls12, Fr, FrRepr};
Expand Down
2 changes: 1 addition & 1 deletion librustzcash/src/tests/key_agreement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rand_os::OsRng;
use zcash_primitives::jubjub::{edwards, JubjubBls12};
use zcash_primitives::primitives::{Diversifier, ViewingKey};

use {
use crate::{
librustzcash_sapling_generate_r, librustzcash_sapling_ka_agree,
librustzcash_sapling_ka_derivepublic,
};
Expand Down
2 changes: 1 addition & 1 deletion librustzcash/src/tests/key_components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use zcash_primitives::{

use super::JUBJUB;

use {
use crate::{
librustzcash_ask_to_ak, librustzcash_check_diversifier, librustzcash_crh_ivk,
librustzcash_ivk_to_pkd, librustzcash_nsk_to_nk,
};
Expand Down
4 changes: 2 additions & 2 deletions librustzcash/src/tests/notes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use librustzcash_sapling_compute_cm;
use librustzcash_sapling_compute_nf;
use crate::librustzcash_sapling_compute_cm;
use crate::librustzcash_sapling_compute_nf;

#[test]
fn notes() {
Expand Down
1 change: 1 addition & 0 deletions pairing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ description = "Pairing-friendly elliptic curve library"
documentation = "https://docs.rs/pairing/"
homepage = "https://github.com/ebfull/pairing"
repository = "https://github.com/ebfull/pairing"
edition ="2018"

[dependencies]
byteorder = "1"
Expand Down
Loading