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