From 012d14073d2ccf3a37da107e3f343ca509baeecb Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Sun, 9 May 2021 07:51:55 +1200 Subject: [PATCH] Remove rand 0.7 usage Upstream redjubjub (on which our reddsa dependency is based) has migrated to rand 0.8. --- Cargo.toml | 3 +-- src/builder.rs | 26 ++++++++++---------------- src/bundle.rs | 2 +- src/keys.rs | 4 ++-- src/primitives/redpallas.rs | 2 +- 5 files changed, 15 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d0ff6f78..d35b880d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,6 @@ fpe = "0.4" group = "0.9" proptest = { version = "1.0.0", optional = true } rand = "0.8" -rand_7 = { package = "rand", version = "0.7" } nonempty = "0.6" subtle = "2.3" @@ -41,7 +40,7 @@ rev = "b55a6960dfafd7f767e2820ddf1adaa499322f98" [dependencies.reddsa] git = "https://github.com/str4d/redjubjub.git" -rev = "f1e76dbc9abf2b68cc609e874fe39f2a15b75b12" +rev = "daab5355bf8e85289aa37804656bf85182df9eea" [dev-dependencies] criterion = "0.3" diff --git a/src/builder.rs b/src/builder.rs index 0ea87a63..0b106705 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -6,7 +6,7 @@ use std::iter; use ff::Field; use nonempty::NonEmpty; use pasta_curves::pallas; -use rand::RngCore; +use rand::{CryptoRng, RngCore}; use crate::{ address::Address, @@ -371,7 +371,7 @@ impl Bundle { /// Loads the sighash into this bundle, preparing it for signing. /// /// This API ensures that all signatures are created over the same sighash. - pub fn prepare( + pub fn prepare( self, mut rng: R, sighash: [u8; 32], @@ -394,7 +394,7 @@ impl Bundle { } /// Applies signatures to this bundle, in order to authorize it. - pub fn apply_signatures( + pub fn apply_signatures( self, mut rng: R, sighash: [u8; 32], @@ -413,11 +413,7 @@ impl Bundle { /// Signs this bundle with the given [`SpendAuthorizingKey`]. /// /// This will apply signatures for all notes controlled by this spending key. - pub fn sign( - self, - mut rng: R, - ask: &SpendAuthorizingKey, - ) -> Self { + pub fn sign(self, mut rng: R, ask: &SpendAuthorizingKey) -> Self { let expected_ak = ask.into(); self.authorize( &mut rng, @@ -492,16 +488,15 @@ pub mod testing { /// from these inputs, but using a `ValueBalance` implementation that /// is defined by the end user. #[derive(Debug)] - struct ArbitraryBundleInputs { + struct ArbitraryBundleInputs { rng: R, - rng_7: R7, sk: SpendingKey, anchor: Anchor, notes: Vec, recipient_amounts: Vec<(Address, NoteValue)>, } - impl ArbitraryBundleInputs { + impl ArbitraryBundleInputs { /// Create a bundle from the set of arbitrary bundle inputs. fn into_bundle>(mut self) -> Bundle { let fvk = FullViewingKey::from(&self.sk); @@ -523,8 +518,8 @@ pub mod testing { builder .build(&mut self.rng, &pk) .unwrap() - .prepare(&mut self.rng_7, [0; 32]) - .sign(&mut self.rng_7, &SpendAuthorizingKey::from(&self.sk)) + .prepare(&mut self.rng, [0; 32]) + .sign(&mut self.rng, &SpendAuthorizingKey::from(&self.sk)) .finalize() .unwrap() } @@ -552,10 +547,9 @@ pub mod testing { n_recipients as usize ), rng_seed in prop::array::uniform32(prop::num::u8::ANY) - ) -> ArbitraryBundleInputs { + ) -> ArbitraryBundleInputs { ArbitraryBundleInputs { rng: StdRng::from_seed(rng_seed), - rng_7: ::from_seed(rng_seed), sk: sk.clone(), anchor, notes, @@ -608,7 +602,7 @@ mod tests { let bundle: Bundle = dbg!(builder .build(&mut rng, &pk) .unwrap() - .prepare(rand_7::rngs::OsRng, [0; 32])) + .prepare(&mut rng, [0; 32])) .finalize() .unwrap(); assert_eq!(bundle.value_balance(), &(-5000)) diff --git a/src/bundle.rs b/src/bundle.rs index a0c717de..7b2c2b70 100644 --- a/src/bundle.rs +++ b/src/bundle.rs @@ -355,7 +355,7 @@ pub struct BundleAuthorizingCommitment; #[cfg(any(test, feature = "test-dependencies"))] pub mod testing { use nonempty::NonEmpty; - use rand_7::{rngs::StdRng, SeedableRng}; + use rand::{rngs::StdRng, SeedableRng}; use reddsa::orchard::SpendAuth; use proptest::collection::vec; diff --git a/src/keys.rs b/src/keys.rs index 58116f0e..da7c1677 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -8,7 +8,7 @@ use fpe::ff1::{BinaryNumeralString, FF1}; use group::GroupEncoding; use halo2::arithmetic::FieldExt; use pasta_curves::pallas; -use rand::RngCore; +use rand::{CryptoRng, RngCore}; use subtle::CtOption; use crate::{ @@ -77,7 +77,7 @@ impl SpendAuthorizingKey { } /// Creates a spend authorization signature over the given message. - pub fn sign( + pub fn sign( &self, rng: R, msg: &[u8], diff --git a/src/primitives/redpallas.rs b/src/primitives/redpallas.rs index 0a8ba3d7..1af3813f 100644 --- a/src/primitives/redpallas.rs +++ b/src/primitives/redpallas.rs @@ -3,7 +3,7 @@ use std::convert::{TryFrom, TryInto}; use pasta_curves::pallas; -use rand_7::{CryptoRng, RngCore}; +use rand::{CryptoRng, RngCore}; /// A RedPallas signature type. pub trait SigType: reddsa::SigType + private::Sealed {}