Skip to content

Commit

Permalink
Update to 2018 edition (#307)
Browse files Browse the repository at this point in the history
* cargo fix --edition

* Set edition in Cargo.toml

* cargo fix --edition-idioms

* Remove unused import.
  • Loading branch information
hdevalence authored and oleganza committed Dec 28, 2019
1 parent 468cc64 commit 3239bc9
Show file tree
Hide file tree
Showing 17 changed files with 59 additions and 84 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ repository = "https://github.com/dalek-cryptography/bulletproofs"
categories = ["cryptography"]
keywords = ["cryptography", "crypto", "ristretto", "zero-knowledge", "bulletproofs"]
description = "A pure-Rust implementation of Bulletproofs using Ristretto"
edition = "2018"

[dependencies]
curve25519-dalek = { version = "2", default-features = false, features = ["u64_backend", "nightly", "serde", "alloc"] }
Expand Down
1 change: 0 additions & 1 deletion benches/generators.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate bulletproofs;
use bulletproofs::{BulletproofGens, PedersenGens};

#[macro_use]
Expand Down
5 changes: 1 addition & 4 deletions benches/range_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
extern crate criterion;
use criterion::Criterion;

extern crate rand;
use rand;
use rand::Rng;

extern crate curve25519_dalek;
use curve25519_dalek::scalar::Scalar;

extern crate merlin;
use merlin::Transcript;

extern crate bulletproofs;
use bulletproofs::RangeProof;
use bulletproofs::{BulletproofGens, PedersenGens};

Expand Down
2 changes: 1 addition & 1 deletion src/generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl BulletproofGens {

/// Returns j-th share of generators, with an appropriate
/// slice of vectors G and H for the j-th range proof.
pub fn share(&self, j: usize) -> BulletproofGensShare {
pub fn share(&self, j: usize) -> BulletproofGensShare<'_> {
BulletproofGensShare {
gens: &self,
share: j,
Expand Down
10 changes: 5 additions & 5 deletions src/inner_product_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use curve25519_dalek::scalar::Scalar;
use curve25519_dalek::traits::VartimeMultiscalarMul;
use merlin::Transcript;

use errors::ProofError;
use transcript::TranscriptProtocol;
use crate::errors::ProofError;
use crate::transcript::TranscriptProtocol;

#[derive(Clone, Debug)]
pub struct InnerProductProof {
Expand Down Expand Up @@ -387,7 +387,7 @@ impl InnerProductProof {
return Err(ProofError::FormatError);
}

use util::read32;
use crate::util::read32;

let mut L_vec: Vec<CompressedRistretto> = Vec::with_capacity(lg_n);
let mut R_vec: Vec<CompressedRistretto> = Vec::with_capacity(lg_n);
Expand Down Expand Up @@ -427,13 +427,13 @@ pub fn inner_product(a: &[Scalar], b: &[Scalar]) -> Scalar {
mod tests {
use super::*;

use crate::util;
use sha3::Sha3_512;
use util;

fn test_helper_create(n: usize) {
let mut rng = rand::thread_rng();

use generators::BulletproofGens;
use crate::generators::BulletproofGens;
let bp_gens = BulletproofGens::new(n, 1);
let G: Vec<RistrettoPoint> = bp_gens.share(0).G(n).cloned().collect();
let H: Vec<RistrettoPoint> = bp_gens.share(0).H(n).cloned().collect();
Expand Down
34 changes: 7 additions & 27 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,14 @@
#![doc(include = "../README.md")]
#![doc(html_logo_url = "https://doc.dalek.rs/assets/dalek-logo-clear.png")]

extern crate byteorder;

extern crate alloc;

#[cfg(feature = "std")]
extern crate core;

#[cfg(feature = "std")]
extern crate rand;

extern crate digest;
extern crate rand_core;
extern crate sha3;

extern crate clear_on_drop;
extern crate curve25519_dalek;
extern crate merlin;
extern crate subtle;
#[macro_use]
extern crate serde_derive;
extern crate serde;

#[macro_use]
extern crate failure;

#[cfg(test)]
extern crate bincode;

mod util;

#[doc(include = "../docs/notes-intro.md")]
Expand All @@ -52,16 +32,16 @@ mod inner_product_proof;
mod range_proof;
mod transcript;

pub use errors::ProofError;
pub use generators::{BulletproofGens, BulletproofGensShare, PedersenGens};
pub use range_proof::RangeProof;
pub use crate::errors::ProofError;
pub use crate::generators::{BulletproofGens, BulletproofGensShare, PedersenGens};
pub use crate::range_proof::RangeProof;

#[doc(include = "../docs/aggregation-api.md")]
pub mod range_proof_mpc {
pub use errors::MPCError;
pub use range_proof::dealer;
pub use range_proof::messages;
pub use range_proof::party;
pub use crate::errors::MPCError;
pub use crate::range_proof::dealer;
pub use crate::range_proof::messages;
pub use crate::range_proof::party;
}

#[cfg(feature = "yoloproofs")]
Expand Down
2 changes: 1 addition & 1 deletion src/r1cs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ pub use self::proof::R1CSProof;
pub use self::prover::Prover;
pub use self::verifier::Verifier;

pub use errors::R1CSError;
pub use crate::errors::R1CSError;
6 changes: 3 additions & 3 deletions src/r1cs/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use curve25519_dalek::ristretto::CompressedRistretto;
use curve25519_dalek::scalar::Scalar;
use curve25519_dalek::traits::{Identity, IsIdentity};

use errors::R1CSError;
use inner_product_proof::InnerProductProof;
use util;
use crate::errors::R1CSError;
use crate::inner_product_proof::InnerProductProof;
use crate::util;

use serde::de::Visitor;
use serde::{self, Deserialize, Deserializer, Serialize, Serializer};
Expand Down
12 changes: 6 additions & 6 deletions src/r1cs/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use super::{
RandomizedConstraintSystem, Variable,
};

use errors::R1CSError;
use generators::{BulletproofGens, PedersenGens};
use inner_product_proof::InnerProductProof;
use transcript::TranscriptProtocol;
use crate::errors::R1CSError;
use crate::generators::{BulletproofGens, PedersenGens};
use crate::inner_product_proof::InnerProductProof;
use crate::transcript::TranscriptProtocol;

/// A [`ConstraintSystem`] implementation for use by the prover.
///
Expand Down Expand Up @@ -44,7 +44,7 @@ pub struct Prover<'t, 'g> {

/// This list holds closures that will be called in the second phase of the protocol,
/// when non-randomized variables are committed.
deferred_constraints: Vec<Box<Fn(&mut RandomizingProver<'t, 'g>) -> Result<(), R1CSError>>>,
deferred_constraints: Vec<Box<dyn Fn(&mut RandomizingProver<'t, 'g>) -> Result<(), R1CSError>>>,

/// Index of a pending multiplier that's not fully assigned yet.
pending_multiplier: Option<usize>,
Expand Down Expand Up @@ -378,8 +378,8 @@ impl<'t, 'g> Prover<'t, 'g> {

/// Consume this `ConstraintSystem` to produce a proof.
pub fn prove(mut self, bp_gens: &BulletproofGens) -> Result<R1CSProof, R1CSError> {
use crate::util;
use std::iter;
use util;

// Commit a length _suffix_ for the number of high-level variables.
// We cannot do this in advance because user can commit variables one-by-one,
Expand Down
12 changes: 6 additions & 6 deletions src/r1cs/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use super::{
RandomizedConstraintSystem, Variable,
};

use errors::R1CSError;
use generators::{BulletproofGens, PedersenGens};
use transcript::TranscriptProtocol;
use crate::errors::R1CSError;
use crate::generators::{BulletproofGens, PedersenGens};
use crate::transcript::TranscriptProtocol;

/// A [`ConstraintSystem`] implementation for use by the verifier.
///
Expand Down Expand Up @@ -42,7 +42,7 @@ pub struct Verifier<'t> {
/// when non-randomized variables are committed.
/// After that, the option will flip to None and additional calls to `randomize_constraints`
/// will invoke closures immediately.
deferred_constraints: Vec<Box<Fn(&mut RandomizingVerifier<'t>) -> Result<(), R1CSError>>>,
deferred_constraints: Vec<Box<dyn Fn(&mut RandomizingVerifier<'t>) -> Result<(), R1CSError>>>,

/// Index of a pending multiplier that's not fully assigned yet.
pending_multiplier: Option<usize>,
Expand Down Expand Up @@ -355,9 +355,9 @@ impl<'t> Verifier<'t> {
let padded_n = self.num_vars.next_power_of_two();
let pad = padded_n - n;

use inner_product_proof::inner_product;
use crate::inner_product_proof::inner_product;
use crate::util;
use std::iter;
use util;

if bp_gens.gens_capacity < padded_n {
return Err(R1CSError::InvalidGeneratorsLength);
Expand Down
12 changes: 6 additions & 6 deletions src/range_proof/dealer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ use curve25519_dalek::ristretto::RistrettoPoint;
use curve25519_dalek::scalar::Scalar;
use merlin::Transcript;

use errors::MPCError;
use generators::{BulletproofGens, PedersenGens};
use inner_product_proof;
use range_proof::RangeProof;
use transcript::TranscriptProtocol;
use crate::errors::MPCError;
use crate::generators::{BulletproofGens, PedersenGens};
use crate::inner_product_proof;
use crate::range_proof::RangeProof;
use crate::transcript::TranscriptProtocol;

use rand_core::{CryptoRng, RngCore};

use util;
use crate::util;

#[cfg(feature = "std")]
use rand::thread_rng;
Expand Down
7 changes: 4 additions & 3 deletions src/range_proof/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use alloc::vec::Vec;
use core::iter;
use curve25519_dalek::ristretto::{CompressedRistretto, RistrettoPoint};
use curve25519_dalek::scalar::Scalar;
use generators::{BulletproofGens, PedersenGens};

use crate::generators::{BulletproofGens, PedersenGens};

/// A commitment to the bits of a party's value.
#[derive(Serialize, Deserialize, Copy, Clone, Debug)]
Expand Down Expand Up @@ -92,8 +93,8 @@ impl ProofShare {
) -> Result<(), ()> {
use curve25519_dalek::traits::{IsIdentity, VartimeMultiscalarMul};

use inner_product_proof::inner_product;
use util;
use crate::inner_product_proof::inner_product;
use crate::util;

let n = self.l_vec.len();

Expand Down
20 changes: 10 additions & 10 deletions src/range_proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ use curve25519_dalek::scalar::Scalar;
use curve25519_dalek::traits::{IsIdentity, VartimeMultiscalarMul};
use merlin::Transcript;

use errors::ProofError;
use generators::{BulletproofGens, PedersenGens};
use inner_product_proof::InnerProductProof;
use transcript::TranscriptProtocol;
use util;
use crate::errors::ProofError;
use crate::generators::{BulletproofGens, PedersenGens};
use crate::inner_product_proof::InnerProductProof;
use crate::transcript::TranscriptProtocol;
use crate::util;

use rand_core::{CryptoRng, RngCore};
use serde::de::Visitor;
Expand Down Expand Up @@ -509,7 +509,7 @@ impl RangeProof {
return Err(ProofError::FormatError);
}

use util::read32;
use crate::util::read32;

let A = CompressedRistretto(read32(&slice[0 * 32..]));
let S = CompressedRistretto(read32(&slice[1 * 32..]));
Expand Down Expand Up @@ -557,7 +557,7 @@ impl<'de> Deserialize<'de> for RangeProof {
impl<'de> Visitor<'de> for RangeProofVisitor {
type Value = RangeProof;

fn expecting(&self, formatter: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
fn expecting(&self, formatter: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
formatter.write_str("a valid RangeProof")
}

Expand Down Expand Up @@ -589,7 +589,7 @@ fn delta(n: usize, m: usize, y: &Scalar, z: &Scalar) -> Scalar {
mod tests {
use super::*;

use generators::PedersenGens;
use crate::generators::PedersenGens;

#[test]
fn test_delta() {
Expand Down Expand Up @@ -721,7 +721,7 @@ mod tests {
use self::dealer::*;
use self::party::*;

use errors::MPCError;
use crate::errors::MPCError;

// Simulate four parties, two of which will be dishonest and use a 64-bit value.
let m = 4;
Expand Down Expand Up @@ -794,7 +794,7 @@ mod tests {
fn detect_dishonest_dealer_during_aggregation() {
use self::dealer::*;
use self::party::*;
use errors::MPCError;
use crate::errors::MPCError;

// Simulate one party
let m = 1;
Expand Down
7 changes: 4 additions & 3 deletions src/range_proof/party.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ use core::iter;
use curve25519_dalek::ristretto::{CompressedRistretto, RistrettoPoint};
use curve25519_dalek::scalar::Scalar;
use curve25519_dalek::traits::MultiscalarMul;
use errors::MPCError;
use generators::{BulletproofGens, PedersenGens};
use rand_core::{CryptoRng, RngCore};
use util;

use crate::errors::MPCError;
use crate::generators::{BulletproofGens, PedersenGens};
use crate::util;

#[cfg(feature = "std")]
use rand::thread_rng;
Expand Down
2 changes: 1 addition & 1 deletion src/transcript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use curve25519_dalek::ristretto::CompressedRistretto;
use curve25519_dalek::scalar::Scalar;
use merlin::Transcript;

use errors::ProofError;
use crate::errors::ProofError;

pub trait TranscriptProtocol {
/// Append a domain separator for an `n`-bit, `m`-party range proof.
Expand Down
3 changes: 2 additions & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use alloc::vec;
use alloc::vec::Vec;
use clear_on_drop::clear::Clear;
use curve25519_dalek::scalar::Scalar;
use inner_product_proof::inner_product;

use crate::inner_product_proof::inner_product;

/// Represents a degree-1 vector polynomial \\(\mathbf{a} + \mathbf{b} \cdot x\\).
pub struct VecPoly1(pub Vec<Scalar>, pub Vec<Scalar>);
Expand Down
7 changes: 1 addition & 6 deletions tests/range_proof.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
extern crate rand_core;
use rand_core::SeedableRng;

extern crate rand_chacha;
use rand_chacha::ChaChaRng;

extern crate curve25519_dalek;
use curve25519_dalek::ristretto::CompressedRistretto;
use curve25519_dalek::scalar::Scalar;

extern crate merlin;
use merlin::Transcript;

extern crate bulletproofs;
use bulletproofs::{BulletproofGens, PedersenGens, RangeProof};

extern crate hex;
use hex;

// Tests that proofs generated with v1.0.0 continue to verify in later versions.
#[test]
Expand Down

0 comments on commit 3239bc9

Please sign in to comment.