Remove rand 0.7 usage

Upstream redjubjub (on which our reddsa dependency is based) has
migrated to rand 0.8.
This commit is contained in:
Jack Grigg 2021-05-09 07:51:55 +12:00
parent 3117187280
commit 012d14073d
5 changed files with 15 additions and 22 deletions

View File

@ -27,7 +27,6 @@ fpe = "0.4"
group = "0.9" group = "0.9"
proptest = { version = "1.0.0", optional = true } proptest = { version = "1.0.0", optional = true }
rand = "0.8" rand = "0.8"
rand_7 = { package = "rand", version = "0.7" }
nonempty = "0.6" nonempty = "0.6"
subtle = "2.3" subtle = "2.3"
@ -41,7 +40,7 @@ rev = "b55a6960dfafd7f767e2820ddf1adaa499322f98"
[dependencies.reddsa] [dependencies.reddsa]
git = "https://github.com/str4d/redjubjub.git" git = "https://github.com/str4d/redjubjub.git"
rev = "f1e76dbc9abf2b68cc609e874fe39f2a15b75b12" rev = "daab5355bf8e85289aa37804656bf85182df9eea"
[dev-dependencies] [dev-dependencies]
criterion = "0.3" criterion = "0.3"

View File

@ -6,7 +6,7 @@ use std::iter;
use ff::Field; use ff::Field;
use nonempty::NonEmpty; use nonempty::NonEmpty;
use pasta_curves::pallas; use pasta_curves::pallas;
use rand::RngCore; use rand::{CryptoRng, RngCore};
use crate::{ use crate::{
address::Address, address::Address,
@ -371,7 +371,7 @@ impl<V> Bundle<Unauthorized, V> {
/// Loads the sighash into this bundle, preparing it for signing. /// Loads the sighash into this bundle, preparing it for signing.
/// ///
/// This API ensures that all signatures are created over the same sighash. /// This API ensures that all signatures are created over the same sighash.
pub fn prepare<R: rand_7::RngCore + rand_7::CryptoRng>( pub fn prepare<R: RngCore + CryptoRng>(
self, self,
mut rng: R, mut rng: R,
sighash: [u8; 32], sighash: [u8; 32],
@ -394,7 +394,7 @@ impl<V> Bundle<Unauthorized, V> {
} }
/// Applies signatures to this bundle, in order to authorize it. /// Applies signatures to this bundle, in order to authorize it.
pub fn apply_signatures<R: rand_7::RngCore + rand_7::CryptoRng>( pub fn apply_signatures<R: RngCore + CryptoRng>(
self, self,
mut rng: R, mut rng: R,
sighash: [u8; 32], sighash: [u8; 32],
@ -413,11 +413,7 @@ impl<V> Bundle<PartiallyAuthorized, V> {
/// Signs this bundle with the given [`SpendAuthorizingKey`]. /// Signs this bundle with the given [`SpendAuthorizingKey`].
/// ///
/// This will apply signatures for all notes controlled by this spending key. /// This will apply signatures for all notes controlled by this spending key.
pub fn sign<R: rand_7::RngCore + rand_7::CryptoRng>( pub fn sign<R: RngCore + CryptoRng>(self, mut rng: R, ask: &SpendAuthorizingKey) -> Self {
self,
mut rng: R,
ask: &SpendAuthorizingKey,
) -> Self {
let expected_ak = ask.into(); let expected_ak = ask.into();
self.authorize( self.authorize(
&mut rng, &mut rng,
@ -492,16 +488,15 @@ pub mod testing {
/// from these inputs, but using a `ValueBalance` implementation that /// from these inputs, but using a `ValueBalance` implementation that
/// is defined by the end user. /// is defined by the end user.
#[derive(Debug)] #[derive(Debug)]
struct ArbitraryBundleInputs<R, R7> { struct ArbitraryBundleInputs<R> {
rng: R, rng: R,
rng_7: R7,
sk: SpendingKey, sk: SpendingKey,
anchor: Anchor, anchor: Anchor,
notes: Vec<Note>, notes: Vec<Note>,
recipient_amounts: Vec<(Address, NoteValue)>, recipient_amounts: Vec<(Address, NoteValue)>,
} }
impl<R: RngCore + CryptoRng, R7: rand_7::RngCore + rand_7::CryptoRng> ArbitraryBundleInputs<R, R7> { impl<R: RngCore + CryptoRng> ArbitraryBundleInputs<R> {
/// Create a bundle from the set of arbitrary bundle inputs. /// Create a bundle from the set of arbitrary bundle inputs.
fn into_bundle<V: TryFrom<i64>>(mut self) -> Bundle<Authorized, V> { fn into_bundle<V: TryFrom<i64>>(mut self) -> Bundle<Authorized, V> {
let fvk = FullViewingKey::from(&self.sk); let fvk = FullViewingKey::from(&self.sk);
@ -523,8 +518,8 @@ pub mod testing {
builder builder
.build(&mut self.rng, &pk) .build(&mut self.rng, &pk)
.unwrap() .unwrap()
.prepare(&mut self.rng_7, [0; 32]) .prepare(&mut self.rng, [0; 32])
.sign(&mut self.rng_7, &SpendAuthorizingKey::from(&self.sk)) .sign(&mut self.rng, &SpendAuthorizingKey::from(&self.sk))
.finalize() .finalize()
.unwrap() .unwrap()
} }
@ -552,10 +547,9 @@ pub mod testing {
n_recipients as usize n_recipients as usize
), ),
rng_seed in prop::array::uniform32(prop::num::u8::ANY) rng_seed in prop::array::uniform32(prop::num::u8::ANY)
) -> ArbitraryBundleInputs<StdRng, rand_7::rngs::StdRng> { ) -> ArbitraryBundleInputs<StdRng> {
ArbitraryBundleInputs { ArbitraryBundleInputs {
rng: StdRng::from_seed(rng_seed), rng: StdRng::from_seed(rng_seed),
rng_7: <rand_7::rngs::StdRng as rand_7::SeedableRng>::from_seed(rng_seed),
sk: sk.clone(), sk: sk.clone(),
anchor, anchor,
notes, notes,
@ -608,7 +602,7 @@ mod tests {
let bundle: Bundle<Authorized, i64> = dbg!(builder let bundle: Bundle<Authorized, i64> = dbg!(builder
.build(&mut rng, &pk) .build(&mut rng, &pk)
.unwrap() .unwrap()
.prepare(rand_7::rngs::OsRng, [0; 32])) .prepare(&mut rng, [0; 32]))
.finalize() .finalize()
.unwrap(); .unwrap();
assert_eq!(bundle.value_balance(), &(-5000)) assert_eq!(bundle.value_balance(), &(-5000))

View File

@ -355,7 +355,7 @@ pub struct BundleAuthorizingCommitment;
#[cfg(any(test, feature = "test-dependencies"))] #[cfg(any(test, feature = "test-dependencies"))]
pub mod testing { pub mod testing {
use nonempty::NonEmpty; use nonempty::NonEmpty;
use rand_7::{rngs::StdRng, SeedableRng}; use rand::{rngs::StdRng, SeedableRng};
use reddsa::orchard::SpendAuth; use reddsa::orchard::SpendAuth;
use proptest::collection::vec; use proptest::collection::vec;

View File

@ -8,7 +8,7 @@ use fpe::ff1::{BinaryNumeralString, FF1};
use group::GroupEncoding; use group::GroupEncoding;
use halo2::arithmetic::FieldExt; use halo2::arithmetic::FieldExt;
use pasta_curves::pallas; use pasta_curves::pallas;
use rand::RngCore; use rand::{CryptoRng, RngCore};
use subtle::CtOption; use subtle::CtOption;
use crate::{ use crate::{
@ -77,7 +77,7 @@ impl SpendAuthorizingKey {
} }
/// Creates a spend authorization signature over the given message. /// Creates a spend authorization signature over the given message.
pub fn sign<R: rand_7::RngCore + rand_7::CryptoRng>( pub fn sign<R: RngCore + CryptoRng>(
&self, &self,
rng: R, rng: R,
msg: &[u8], msg: &[u8],

View File

@ -3,7 +3,7 @@
use std::convert::{TryFrom, TryInto}; use std::convert::{TryFrom, TryInto};
use pasta_curves::pallas; use pasta_curves::pallas;
use rand_7::{CryptoRng, RngCore}; use rand::{CryptoRng, RngCore};
/// A RedPallas signature type. /// A RedPallas signature type.
pub trait SigType: reddsa::SigType + private::Sealed {} pub trait SigType: reddsa::SigType + private::Sealed {}