mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-02-01 08:12:14 +00:00
Migrate zcash_primitives to rand 0.5
This commit is contained in:
parent
adfc88926b
commit
6149166ccb
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -594,7 +594,7 @@ dependencies = [
|
||||
"hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pairing 0.14.2",
|
||||
"rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sapling-crypto 0.0.1",
|
||||
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
@ -15,6 +15,6 @@ fpe = "0.1"
|
||||
hex = "0.3"
|
||||
lazy_static = "1"
|
||||
pairing = { path = "../pairing" }
|
||||
rand = "0.4"
|
||||
rand = "0.5"
|
||||
sapling-crypto = { path = "../sapling-crypto" }
|
||||
sha2 = "0.8"
|
||||
|
@ -200,12 +200,14 @@ impl<Node: Hashable> CommitmentTree<Node> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// extern crate ff;
|
||||
/// extern crate pairing;
|
||||
/// extern crate rand;
|
||||
/// extern crate zcash_primitives;
|
||||
///
|
||||
/// use pairing::bls12_381::FrRepr;
|
||||
/// use rand::{OsRng, Rand};
|
||||
/// use ff::{Field, PrimeField};
|
||||
/// use pairing::bls12_381::Fr;
|
||||
/// use rand::OsRng;
|
||||
/// use zcash_primitives::{
|
||||
/// merkle_tree::{CommitmentTree, IncrementalWitness},
|
||||
/// sapling::Node,
|
||||
@ -214,13 +216,13 @@ impl<Node: Hashable> CommitmentTree<Node> {
|
||||
/// let mut rng = OsRng::new().unwrap();
|
||||
/// let mut tree = CommitmentTree::<Node>::new();
|
||||
///
|
||||
/// tree.append(Node::new(FrRepr::rand(&mut rng)));
|
||||
/// tree.append(Node::new(FrRepr::rand(&mut rng)));
|
||||
/// tree.append(Node::new(Fr::random(&mut rng).into_repr()));
|
||||
/// tree.append(Node::new(Fr::random(&mut rng).into_repr()));
|
||||
/// let mut witness = IncrementalWitness::from_tree(&tree);
|
||||
/// assert_eq!(witness.position(), 1);
|
||||
/// assert_eq!(tree.root(), witness.root());
|
||||
///
|
||||
/// let cmu = Node::new(FrRepr::rand(&mut rng));
|
||||
/// let cmu = Node::new(Fr::random(&mut rng).into_repr());
|
||||
/// tree.append(cmu);
|
||||
/// witness.append(cmu);
|
||||
/// assert_eq!(tree.root(), witness.root());
|
||||
|
@ -211,12 +211,14 @@ fn prf_ock(
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// extern crate ff;
|
||||
/// extern crate pairing;
|
||||
/// extern crate rand;
|
||||
/// extern crate sapling_crypto;
|
||||
///
|
||||
/// use ff::Field;
|
||||
/// use pairing::bls12_381::Bls12;
|
||||
/// use rand::{OsRng, Rand};
|
||||
/// use rand::OsRng;
|
||||
/// use sapling_crypto::{
|
||||
/// jubjub::fs::Fs,
|
||||
/// primitives::{Diversifier, PaymentAddress, ValueCommitment},
|
||||
@ -238,7 +240,7 @@ fn prf_ock(
|
||||
/// let ovk = OutgoingViewingKey([0; 32]);
|
||||
///
|
||||
/// let value = 1000;
|
||||
/// let rcv = Fs::rand(&mut rng);
|
||||
/// let rcv = Fs::random(&mut rng);
|
||||
/// let cv = ValueCommitment::<Bls12> {
|
||||
/// value,
|
||||
/// randomness: rcv.clone(),
|
||||
@ -558,9 +560,9 @@ pub fn try_sapling_output_recovery(
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crypto_api_chachapoly::ChachaPolyIetf;
|
||||
use ff::{PrimeField, PrimeFieldRepr};
|
||||
use ff::{Field, PrimeField, PrimeFieldRepr};
|
||||
use pairing::bls12_381::{Bls12, Fr, FrRepr};
|
||||
use rand::{thread_rng, Rand, Rng};
|
||||
use rand::{thread_rng, RngCore};
|
||||
use sapling_crypto::{
|
||||
jubjub::{
|
||||
edwards,
|
||||
@ -692,8 +694,8 @@ mod tests {
|
||||
assert_eq!(Memo::default().to_utf8(), None);
|
||||
}
|
||||
|
||||
fn random_enc_ciphertext(
|
||||
mut rng: &mut Rng,
|
||||
fn random_enc_ciphertext<R: RngCore>(
|
||||
mut rng: &mut R,
|
||||
) -> (
|
||||
OutgoingViewingKey,
|
||||
Fs,
|
||||
@ -704,7 +706,7 @@ mod tests {
|
||||
[u8; OUT_CIPHERTEXT_SIZE],
|
||||
) {
|
||||
let diversifier = Diversifier([0; 11]);
|
||||
let ivk = Fs::rand(&mut rng);
|
||||
let ivk = Fs::random(&mut rng);
|
||||
let pk_d = diversifier.g_d::<Bls12>(&JUBJUB).unwrap().mul(ivk, &JUBJUB);
|
||||
let pa = PaymentAddress { diversifier, pk_d };
|
||||
|
||||
@ -712,11 +714,13 @@ mod tests {
|
||||
let value = 100;
|
||||
let value_commitment = ValueCommitment::<Bls12> {
|
||||
value,
|
||||
randomness: Fs::rand(&mut rng),
|
||||
randomness: Fs::random(&mut rng),
|
||||
};
|
||||
let cv = value_commitment.cm(&JUBJUB).into();
|
||||
|
||||
let note = pa.create_note(value, Fs::rand(&mut rng), &JUBJUB).unwrap();
|
||||
let note = pa
|
||||
.create_note(value, Fs::random(&mut rng), &JUBJUB)
|
||||
.unwrap();
|
||||
let cmu = note.cm(&JUBJUB);
|
||||
|
||||
let ovk = OutgoingViewingKey([0; 32]);
|
||||
@ -849,7 +853,7 @@ mod tests {
|
||||
let (_, _, _, cmu, epk, enc_ciphertext, _) = random_enc_ciphertext(&mut rng);
|
||||
|
||||
assert_eq!(
|
||||
try_sapling_note_decryption(&Fs::rand(&mut rng), &epk, &cmu, &enc_ciphertext),
|
||||
try_sapling_note_decryption(&Fs::random(&mut rng), &epk, &cmu, &enc_ciphertext),
|
||||
None
|
||||
);
|
||||
}
|
||||
@ -878,7 +882,7 @@ mod tests {
|
||||
let (_, ivk, _, _, epk, enc_ciphertext, _) = random_enc_ciphertext(&mut rng);
|
||||
|
||||
assert_eq!(
|
||||
try_sapling_note_decryption(&ivk, &epk, &Fr::rand(&mut rng), &enc_ciphertext),
|
||||
try_sapling_note_decryption(&ivk, &epk, &Fr::random(&mut rng), &enc_ciphertext),
|
||||
None
|
||||
);
|
||||
}
|
||||
@ -970,7 +974,7 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
try_sapling_compact_note_decryption(
|
||||
&Fs::rand(&mut rng),
|
||||
&Fs::random(&mut rng),
|
||||
&epk,
|
||||
&cmu,
|
||||
&enc_ciphertext[..COMPACT_NOTE_SIZE]
|
||||
@ -1006,7 +1010,7 @@ mod tests {
|
||||
try_sapling_compact_note_decryption(
|
||||
&ivk,
|
||||
&epk,
|
||||
&Fr::rand(&mut rng),
|
||||
&Fr::random(&mut rng),
|
||||
&enc_ciphertext[..COMPACT_NOTE_SIZE]
|
||||
),
|
||||
None
|
||||
@ -1137,7 +1141,7 @@ mod tests {
|
||||
try_sapling_output_recovery(
|
||||
&ovk,
|
||||
&cv,
|
||||
&Fr::rand(&mut rng),
|
||||
&Fr::random(&mut rng),
|
||||
&epk,
|
||||
&enc_ciphertext,
|
||||
&out_ciphertext
|
||||
|
@ -1,6 +1,10 @@
|
||||
use ff::Field;
|
||||
use pairing::bls12_381::Bls12;
|
||||
use rand::{thread_rng, Rng};
|
||||
use sapling_crypto::{jubjub::FixedGenerators, redjubjub::PrivateKey};
|
||||
use rand::thread_rng;
|
||||
use sapling_crypto::{
|
||||
jubjub::{fs::Fs, FixedGenerators},
|
||||
redjubjub::PrivateKey,
|
||||
};
|
||||
|
||||
use super::{
|
||||
components::{Amount, Script},
|
||||
@ -194,7 +198,7 @@ fn tx_write_rejects_unexpected_binding_sig() {
|
||||
// Fails with an unexpected binding signature
|
||||
{
|
||||
let rng = &mut thread_rng();
|
||||
let sk = PrivateKey::<Bls12>(rng.gen());
|
||||
let sk = PrivateKey::<Bls12>(Fs::random(rng));
|
||||
let sig = sk.sign(
|
||||
b"Foo bar",
|
||||
rng,
|
||||
|
Loading…
Reference in New Issue
Block a user