diff --git a/Cargo.toml b/Cargo.toml index 5a655aae..35fe2f86 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] } diff --git a/benches/generators.rs b/benches/generators.rs index 47af5b5a..0b2bbfdb 100644 --- a/benches/generators.rs +++ b/benches/generators.rs @@ -1,4 +1,3 @@ -extern crate bulletproofs; use bulletproofs::{BulletproofGens, PedersenGens}; #[macro_use] diff --git a/benches/range_proof.rs b/benches/range_proof.rs index fe3f82c0..5ab246ec 100644 --- a/benches/range_proof.rs +++ b/benches/range_proof.rs @@ -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}; diff --git a/src/generators.rs b/src/generators.rs index 1837b90f..6e936562 100644 --- a/src/generators.rs +++ b/src/generators.rs @@ -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, diff --git a/src/inner_product_proof.rs b/src/inner_product_proof.rs index 63af382d..5d1eb594 100644 --- a/src/inner_product_proof.rs +++ b/src/inner_product_proof.rs @@ -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 { @@ -387,7 +387,7 @@ impl InnerProductProof { return Err(ProofError::FormatError); } - use util::read32; + use crate::util::read32; let mut L_vec: Vec = Vec::with_capacity(lg_n); let mut R_vec: Vec = Vec::with_capacity(lg_n); @@ -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 = bp_gens.share(0).G(n).cloned().collect(); let H: Vec = bp_gens.share(0).H(n).cloned().collect(); diff --git a/src/lib.rs b/src/lib.rs index 2d18d359..111764d8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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")] @@ -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")] diff --git a/src/r1cs/mod.rs b/src/r1cs/mod.rs index 72f88606..cb140e09 100644 --- a/src/r1cs/mod.rs +++ b/src/r1cs/mod.rs @@ -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; diff --git a/src/r1cs/proof.rs b/src/r1cs/proof.rs index aa384e1d..b1ead97d 100644 --- a/src/r1cs/proof.rs +++ b/src/r1cs/proof.rs @@ -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}; diff --git a/src/r1cs/prover.rs b/src/r1cs/prover.rs index 1cc9d104..bee4a945 100644 --- a/src/r1cs/prover.rs +++ b/src/r1cs/prover.rs @@ -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. /// @@ -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) -> Result<(), R1CSError>>>, + deferred_constraints: Vec) -> Result<(), R1CSError>>>, /// Index of a pending multiplier that's not fully assigned yet. pending_multiplier: Option, @@ -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 { + 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, diff --git a/src/r1cs/verifier.rs b/src/r1cs/verifier.rs index 4a0f61bf..9e4aa411 100644 --- a/src/r1cs/verifier.rs +++ b/src/r1cs/verifier.rs @@ -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. /// @@ -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) -> Result<(), R1CSError>>>, + deferred_constraints: Vec) -> Result<(), R1CSError>>>, /// Index of a pending multiplier that's not fully assigned yet. pending_multiplier: Option, @@ -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); diff --git a/src/range_proof/dealer.rs b/src/range_proof/dealer.rs index 83714e77..00c6691e 100644 --- a/src/range_proof/dealer.rs +++ b/src/range_proof/dealer.rs @@ -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; diff --git a/src/range_proof/messages.rs b/src/range_proof/messages.rs index 504216c2..8a563fb0 100644 --- a/src/range_proof/messages.rs +++ b/src/range_proof/messages.rs @@ -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)] @@ -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(); diff --git a/src/range_proof/mod.rs b/src/range_proof/mod.rs index 8a38d692..13de40dd 100644 --- a/src/range_proof/mod.rs +++ b/src/range_proof/mod.rs @@ -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; @@ -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..])); @@ -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") } @@ -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() { @@ -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; @@ -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; diff --git a/src/range_proof/party.rs b/src/range_proof/party.rs index aaf2c8fe..ebb232cc 100644 --- a/src/range_proof/party.rs +++ b/src/range_proof/party.rs @@ -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; diff --git a/src/transcript.rs b/src/transcript.rs index 7b3d5447..639c7cf1 100644 --- a/src/transcript.rs +++ b/src/transcript.rs @@ -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. diff --git a/src/util.rs b/src/util.rs index ac5330ac..dd7ce2fe 100644 --- a/src/util.rs +++ b/src/util.rs @@ -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, pub Vec); diff --git a/tests/range_proof.rs b/tests/range_proof.rs index 3e60d7ad..57b0f653 100644 --- a/tests/range_proof.rs +++ b/tests/range_proof.rs @@ -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]