From 7ea6d10480795f60ade4041963b3f51f1ebc9472 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Sat, 4 May 2019 17:47:18 +0100 Subject: [PATCH 1/6] Move redjubjub into zcash_primitives --- Cargo.lock | 1 + librustzcash/src/rustzcash.rs | 2 +- librustzcash/src/tests/signatures.rs | 6 ++---- sapling-crypto/src/lib.rs | 2 -- zcash_primitives/Cargo.toml | 3 +++ zcash_primitives/src/lib.rs | 5 +++++ zcash_primitives/src/prover.rs | 4 ++-- {sapling-crypto => zcash_primitives}/src/redjubjub.rs | 9 +++++---- zcash_primitives/src/sapling.rs | 2 +- zcash_primitives/src/transaction/builder.rs | 2 +- zcash_primitives/src/transaction/components.rs | 6 ++---- zcash_primitives/src/transaction/mod.rs | 2 +- zcash_primitives/src/transaction/tests.rs | 6 ++---- {sapling-crypto => zcash_primitives}/src/util.rs | 3 +-- zcash_proofs/src/prover.rs | 2 +- zcash_proofs/src/sapling/prover.rs | 6 ++++-- zcash_proofs/src/sapling/verifier.rs | 6 ++++-- 17 files changed, 36 insertions(+), 31 deletions(-) rename {sapling-crypto => zcash_primitives}/src/redjubjub.rs (98%) rename {sapling-crypto => zcash_primitives}/src/util.rs (84%) diff --git a/Cargo.lock b/Cargo.lock index 3ca7b39..53bc275 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -552,6 +552,7 @@ dependencies = [ "rand 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_os 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_xorshift 0.2.0 (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)", ] diff --git a/librustzcash/src/rustzcash.rs b/librustzcash/src/rustzcash.rs index 99c3187..bff8093 100644 --- a/librustzcash/src/rustzcash.rs +++ b/librustzcash/src/rustzcash.rs @@ -24,7 +24,6 @@ use sapling_crypto::{ fs::{Fs, FsRepr}, FixedGenerators, JubjubEngine, JubjubParams, PrimeOrder, ToUniform, Unknown, }, - redjubjub::{self, Signature}, }; use sapling_crypto::circuit::sapling::TREE_DEPTH as SAPLING_TREE_DEPTH; @@ -62,6 +61,7 @@ use sapling_crypto::primitives::{ProofGenerationKey, ViewingKey}; use zcash_primitives::{ merkle_tree::CommitmentTreeWitness, note_encryption::sapling_ka_agree, + redjubjub::{self, Signature}, sapling::{merkle_hash, spend_sig}, transaction::components::Amount, zip32, JUBJUB, diff --git a/librustzcash/src/tests/signatures.rs b/librustzcash/src/tests/signatures.rs index 2b28437..034b05a 100644 --- a/librustzcash/src/tests/signatures.rs +++ b/librustzcash/src/tests/signatures.rs @@ -1,9 +1,7 @@ use ff::{PrimeField, PrimeFieldRepr}; use pairing::bls12_381::Bls12; -use sapling_crypto::{ - jubjub::{FixedGenerators, JubjubEngine}, - redjubjub::{PrivateKey, PublicKey, Signature}, -}; +use sapling_crypto::jubjub::{FixedGenerators, JubjubEngine}; +use zcash_primitives::redjubjub::{PrivateKey, PublicKey, Signature}; use super::JUBJUB; diff --git a/sapling-crypto/src/lib.rs b/sapling-crypto/src/lib.rs index 14e713d..3662629 100644 --- a/sapling-crypto/src/lib.rs +++ b/sapling-crypto/src/lib.rs @@ -23,5 +23,3 @@ pub mod circuit; pub mod pedersen_hash; pub mod primitives; pub mod constants; -pub mod redjubjub; -pub mod util; diff --git a/zcash_primitives/Cargo.toml b/zcash_primitives/Cargo.toml index ba724be..49b1b7d 100644 --- a/zcash_primitives/Cargo.toml +++ b/zcash_primitives/Cargo.toml @@ -20,3 +20,6 @@ rand_core = "0.5" rand_os = "0.2" sapling-crypto = { path = "../sapling-crypto" } sha2 = "0.8" + +[dev-dependencies] +rand_xorshift = "0.2" diff --git a/zcash_primitives/src/lib.rs b/zcash_primitives/src/lib.rs index a95d000..771f13d 100644 --- a/zcash_primitives/src/lib.rs +++ b/zcash_primitives/src/lib.rs @@ -15,6 +15,9 @@ extern crate rand_os; extern crate sapling_crypto; extern crate sha2; +#[cfg(test)] +extern crate rand_xorshift; + use sapling_crypto::jubjub::JubjubBls12; pub mod block; @@ -23,9 +26,11 @@ pub mod legacy; pub mod merkle_tree; pub mod note_encryption; pub mod prover; +pub mod redjubjub; pub mod sapling; mod serialize; pub mod transaction; +mod util; pub mod zip32; #[cfg(test)] diff --git a/zcash_primitives/src/prover.rs b/zcash_primitives/src/prover.rs index 1d40965..a4af8d4 100644 --- a/zcash_primitives/src/prover.rs +++ b/zcash_primitives/src/prover.rs @@ -4,11 +4,11 @@ use pairing::bls12_381::{Bls12, Fr}; use sapling_crypto::{ jubjub::{edwards, fs::Fs, Unknown}, primitives::{Diversifier, PaymentAddress, ProofGenerationKey}, - redjubjub::{PublicKey, Signature}, }; use crate::{ merkle_tree::CommitmentTreeWitness, + redjubjub::{PublicKey, Signature}, sapling::Node, transaction::components::{Amount, GROTH_PROOF_SIZE}, }; @@ -78,11 +78,11 @@ pub(crate) mod mock { use sapling_crypto::{ jubjub::{edwards, fs::Fs, FixedGenerators, Unknown}, primitives::{Diversifier, PaymentAddress, ProofGenerationKey, ValueCommitment}, - redjubjub::{PublicKey, Signature}, }; use crate::{ merkle_tree::CommitmentTreeWitness, + redjubjub::{PublicKey, Signature}, sapling::Node, transaction::components::{Amount, GROTH_PROOF_SIZE}, JUBJUB, diff --git a/sapling-crypto/src/redjubjub.rs b/zcash_primitives/src/redjubjub.rs similarity index 98% rename from sapling-crypto/src/redjubjub.rs rename to zcash_primitives/src/redjubjub.rs index cd02347..955c7e3 100644 --- a/sapling-crypto/src/redjubjub.rs +++ b/zcash_primitives/src/redjubjub.rs @@ -3,10 +3,12 @@ use ff::{Field, PrimeField, PrimeFieldRepr}; use rand_core::RngCore; +use sapling_crypto::jubjub::{ + edwards::Point, FixedGenerators, JubjubEngine, JubjubParams, Unknown, +}; use std::io::{self, Read, Write}; -use jubjub::{FixedGenerators, JubjubEngine, JubjubParams, Unknown, edwards::Point}; -use util::{hash_to_scalar}; +use util::hash_to_scalar; fn read_scalar(reader: R) -> io::Result { let mut s_repr = ::Repr::default(); @@ -208,8 +210,7 @@ mod tests { use pairing::bls12_381::Bls12; use rand_core::SeedableRng; use rand_xorshift::XorShiftRng; - - use jubjub::{JubjubBls12, fs::Fs, edwards}; + use sapling_crypto::jubjub::{edwards, fs::Fs, JubjubBls12}; use super::*; diff --git a/zcash_primitives/src/sapling.rs b/zcash_primitives/src/sapling.rs index bd981e6..002cc1a 100644 --- a/zcash_primitives/src/sapling.rs +++ b/zcash_primitives/src/sapling.rs @@ -7,11 +7,11 @@ use sapling_crypto::{ jubjub::{fs::Fs, FixedGenerators, JubjubBls12}, pedersen_hash::{pedersen_hash, Personalization}, primitives::Note, - redjubjub::{PrivateKey, PublicKey, Signature}, }; use std::io::{self, Read, Write}; use crate::merkle_tree::Hashable; +use crate::redjubjub::{PrivateKey, PublicKey, Signature}; use JUBJUB; pub(crate) const SAPLING_COMMITMENT_TREE_DEPTH: usize = diff --git a/zcash_primitives/src/transaction/builder.rs b/zcash_primitives/src/transaction/builder.rs index a3134c3..792582d 100644 --- a/zcash_primitives/src/transaction/builder.rs +++ b/zcash_primitives/src/transaction/builder.rs @@ -6,7 +6,6 @@ use rand::{rngs::OsRng, seq::SliceRandom, CryptoRng, RngCore}; use sapling_crypto::{ jubjub::fs::Fs, primitives::{Diversifier, Note, PaymentAddress}, - redjubjub::PrivateKey, }; use zip32::ExtendedSpendingKey; @@ -16,6 +15,7 @@ use crate::{ merkle_tree::{CommitmentTreeWitness, IncrementalWitness}, note_encryption::{generate_esk, Memo, SaplingNoteEncryption}, prover::TxProver, + redjubjub::PrivateKey, sapling::{spend_sig, Node}, transaction::{ components::{amount::DEFAULT_FEE, Amount, OutputDescription, SpendDescription, TxOut}, diff --git a/zcash_primitives/src/transaction/components.rs b/zcash_primitives/src/transaction/components.rs index d50b4fb..1785344 100644 --- a/zcash_primitives/src/transaction/components.rs +++ b/zcash_primitives/src/transaction/components.rs @@ -1,13 +1,11 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use ff::{PrimeField, PrimeFieldRepr}; use pairing::bls12_381::{Bls12, Fr, FrRepr}; -use sapling_crypto::{ - jubjub::{edwards, Unknown}, - redjubjub::{PublicKey, Signature}, -}; +use sapling_crypto::jubjub::{edwards, Unknown}; use std::io::{self, Read, Write}; use legacy::Script; +use redjubjub::{PublicKey, Signature}; use JUBJUB; pub mod amount; diff --git a/zcash_primitives/src/transaction/mod.rs b/zcash_primitives/src/transaction/mod.rs index a8ecb17..6e2d15f 100644 --- a/zcash_primitives/src/transaction/mod.rs +++ b/zcash_primitives/src/transaction/mod.rs @@ -1,11 +1,11 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use hex; -use sapling_crypto::redjubjub::Signature; use sha2::{Digest, Sha256}; use std::fmt; use std::io::{self, Read, Write}; use std::ops::Deref; +use redjubjub::Signature; use serialize::Vector; pub mod builder; diff --git a/zcash_primitives/src/transaction/tests.rs b/zcash_primitives/src/transaction/tests.rs index 4cd5d72..041ac21 100644 --- a/zcash_primitives/src/transaction/tests.rs +++ b/zcash_primitives/src/transaction/tests.rs @@ -1,13 +1,11 @@ use ff::Field; use pairing::bls12_381::Bls12; use rand_os::OsRng; -use sapling_crypto::{ - jubjub::{fs::Fs, FixedGenerators}, - redjubjub::PrivateKey, -}; +use sapling_crypto::jubjub::{fs::Fs, FixedGenerators}; use super::{components::Amount, sighash::signature_hash, Transaction, TransactionData}; use legacy::Script; +use redjubjub::PrivateKey; use JUBJUB; #[test] diff --git a/sapling-crypto/src/util.rs b/zcash_primitives/src/util.rs similarity index 84% rename from sapling-crypto/src/util.rs rename to zcash_primitives/src/util.rs index 1e759ba..f46e0a2 100644 --- a/sapling-crypto/src/util.rs +++ b/zcash_primitives/src/util.rs @@ -1,6 +1,5 @@ use blake2b_simd::Params; - -use jubjub::{JubjubEngine, ToUniform}; +use sapling_crypto::jubjub::{JubjubEngine, ToUniform}; pub fn hash_to_scalar(persona: &[u8], a: &[u8], b: &[u8]) -> E::Fs { let mut hasher = Params::new().hash_length(64).personal(persona).to_state(); diff --git a/zcash_proofs/src/prover.rs b/zcash_proofs/src/prover.rs index 4b5b0f4..c59ba62 100644 --- a/zcash_proofs/src/prover.rs +++ b/zcash_proofs/src/prover.rs @@ -6,12 +6,12 @@ use pairing::bls12_381::{Bls12, Fr}; use sapling_crypto::{ jubjub::{edwards, fs::Fs, Unknown}, primitives::{Diversifier, PaymentAddress, ProofGenerationKey}, - redjubjub::{PublicKey, Signature}, }; use std::path::Path; use zcash_primitives::{ merkle_tree::CommitmentTreeWitness, prover::TxProver, + redjubjub::{PublicKey, Signature}, sapling::Node, transaction::components::{Amount, GROTH_PROOF_SIZE}, JUBJUB, diff --git a/zcash_proofs/src/sapling/prover.rs b/zcash_proofs/src/sapling/prover.rs index 4b5a5f4..3d30524 100644 --- a/zcash_proofs/src/sapling/prover.rs +++ b/zcash_proofs/src/sapling/prover.rs @@ -11,10 +11,12 @@ use sapling_crypto::{ }, jubjub::{edwards, fs::Fs, FixedGenerators, JubjubBls12, Unknown}, primitives::{Diversifier, Note, PaymentAddress, ProofGenerationKey, ValueCommitment}, - redjubjub::{PrivateKey, PublicKey, Signature}, }; use zcash_primitives::{ - merkle_tree::CommitmentTreeWitness, sapling::Node, transaction::components::Amount, + merkle_tree::CommitmentTreeWitness, + redjubjub::{PrivateKey, PublicKey, Signature}, + sapling::Node, + transaction::components::Amount, }; use super::compute_value_balance; diff --git a/zcash_proofs/src/sapling/verifier.rs b/zcash_proofs/src/sapling/verifier.rs index 47fc9fe..ac4f3f7 100644 --- a/zcash_proofs/src/sapling/verifier.rs +++ b/zcash_proofs/src/sapling/verifier.rs @@ -4,9 +4,11 @@ use pairing::bls12_381::{Bls12, Fr}; use sapling_crypto::{ circuit::multipack, jubjub::{edwards, FixedGenerators, JubjubBls12, Unknown}, - redjubjub::{PublicKey, Signature}, }; -use zcash_primitives::transaction::components::Amount; +use zcash_primitives::{ + redjubjub::{PublicKey, Signature}, + transaction::components::Amount, +}; use super::compute_value_balance; From 2ae5804a679aea51128050ab3f5aa94e770fbd98 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Mon, 5 Aug 2019 22:45:12 +0100 Subject: [PATCH 2/6] Move Sprout and Sapling circuits into zcash_proofs --- Cargo.lock | 2 + librustzcash/src/rustzcash.rs | 4 +- sapling-crypto/src/circuit/mod.rs | 6 +- zcash_primitives/src/sapling.rs | 3 +- zcash_proofs/Cargo.toml | 4 ++ .../examples/bench.rs | 3 +- zcash_proofs/src/circuit.rs | 2 + .../src/circuit/sapling.rs | 52 ++++++++++-------- .../src/circuit/sprout/commitment.rs | 4 +- .../src/circuit/sprout/input.rs | 4 +- .../src/circuit/sprout/mod.rs | 8 +-- .../src/circuit/sprout/output.rs | 2 +- .../src/circuit/sprout/prfs.rs | 4 +- .../src/circuit/sprout/test_vectors.dat | Bin zcash_proofs/src/lib.rs | 7 +++ zcash_proofs/src/sapling/prover.rs | 6 +- 16 files changed, 63 insertions(+), 48 deletions(-) rename {sapling-crypto => zcash_proofs}/examples/bench.rs (97%) create mode 100644 zcash_proofs/src/circuit.rs rename sapling-crypto/src/circuit/sapling/mod.rs => zcash_proofs/src/circuit/sapling.rs (95%) rename {sapling-crypto => zcash_proofs}/src/circuit/sprout/commitment.rs (92%) rename {sapling-crypto => zcash_proofs}/src/circuit/sprout/input.rs (98%) rename {sapling-crypto => zcash_proofs}/src/circuit/sprout/mod.rs (98%) rename {sapling-crypto => zcash_proofs}/src/circuit/sprout/output.rs (95%) rename {sapling-crypto => zcash_proofs}/src/circuit/sprout/prfs.rs (95%) rename {sapling-crypto => zcash_proofs}/src/circuit/sprout/test_vectors.dat (100%) diff --git a/Cargo.lock b/Cargo.lock index 53bc275..3bc3137 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -567,7 +567,9 @@ dependencies = [ "directories 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "ff 0.4.0", "pairing 0.14.2", + "rand_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_os 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_xorshift 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "sapling-crypto 0.0.1", "zcash_primitives 0.0.0", ] diff --git a/librustzcash/src/rustzcash.rs b/librustzcash/src/rustzcash.rs index bff8093..92f8d04 100644 --- a/librustzcash/src/rustzcash.rs +++ b/librustzcash/src/rustzcash.rs @@ -26,8 +26,8 @@ use sapling_crypto::{ }, }; -use sapling_crypto::circuit::sapling::TREE_DEPTH as SAPLING_TREE_DEPTH; -use sapling_crypto::circuit::sprout::{self, TREE_DEPTH as SPROUT_TREE_DEPTH}; +use zcash_proofs::circuit::sapling::TREE_DEPTH as SAPLING_TREE_DEPTH; +use zcash_proofs::circuit::sprout::{self, TREE_DEPTH as SPROUT_TREE_DEPTH}; use bellman::groth16::{ create_random_proof, verify_proof, Parameters, PreparedVerifyingKey, Proof, diff --git a/sapling-crypto/src/circuit/mod.rs b/sapling-crypto/src/circuit/mod.rs index fe0fe50..4902f67 100644 --- a/sapling-crypto/src/circuit/mod.rs +++ b/sapling-crypto/src/circuit/mod.rs @@ -1,4 +1,3 @@ -#[cfg(test)] pub mod test; pub mod boolean; @@ -12,9 +11,6 @@ pub mod pedersen_hash; pub mod multipack; pub mod sha256; -pub mod sapling; -pub mod sprout; - use bellman::{ SynthesisError }; @@ -25,7 +21,7 @@ use bellman::{ /// This basically is just an extension to `Option` /// which allows for a convenient mapping to an /// error on `None`. -trait Assignment { +pub trait Assignment { fn get(&self) -> Result<&T, SynthesisError>; } diff --git a/zcash_primitives/src/sapling.rs b/zcash_primitives/src/sapling.rs index 002cc1a..0b94e4e 100644 --- a/zcash_primitives/src/sapling.rs +++ b/zcash_primitives/src/sapling.rs @@ -14,8 +14,7 @@ use crate::merkle_tree::Hashable; use crate::redjubjub::{PrivateKey, PublicKey, Signature}; use JUBJUB; -pub(crate) const SAPLING_COMMITMENT_TREE_DEPTH: usize = - sapling_crypto::circuit::sapling::TREE_DEPTH; +pub const SAPLING_COMMITMENT_TREE_DEPTH: usize = 32; /// Compute a parent node in the Sapling commitment tree given its two children. pub fn merkle_hash(depth: usize, lhs: &FrRepr, rhs: &FrRepr) -> FrRepr { diff --git a/zcash_proofs/Cargo.toml b/zcash_proofs/Cargo.toml index 598e013..fdb0bf8 100644 --- a/zcash_proofs/Cargo.toml +++ b/zcash_proofs/Cargo.toml @@ -16,6 +16,10 @@ rand_os = "0.2" sapling-crypto = { path = "../sapling-crypto" } zcash_primitives = { path = "../zcash_primitives" } +[dev-dependencies] +rand_core = "0.5" +rand_xorshift = "0.2" + [features] default = ["local-prover"] local-prover = ["directories"] diff --git a/sapling-crypto/examples/bench.rs b/zcash_proofs/examples/bench.rs similarity index 97% rename from sapling-crypto/examples/bench.rs rename to zcash_proofs/examples/bench.rs index e9ffc13..9adf028 100644 --- a/sapling-crypto/examples/bench.rs +++ b/zcash_proofs/examples/bench.rs @@ -4,6 +4,7 @@ extern crate bellman; extern crate pairing; extern crate rand_core; extern crate rand_xorshift; +extern crate zcash_proofs; use ff::Field; use std::time::{Duration, Instant}; @@ -12,7 +13,7 @@ use sapling_crypto::jubjub::{ edwards, fs, }; -use sapling_crypto::circuit::sapling::{ +use zcash_proofs::circuit::sapling::{ Spend }; use sapling_crypto::primitives::{ diff --git a/zcash_proofs/src/circuit.rs b/zcash_proofs/src/circuit.rs new file mode 100644 index 0000000..85fa1cf --- /dev/null +++ b/zcash_proofs/src/circuit.rs @@ -0,0 +1,2 @@ +pub mod sapling; +pub mod sprout; diff --git a/sapling-crypto/src/circuit/sapling/mod.rs b/zcash_proofs/src/circuit/sapling.rs similarity index 95% rename from sapling-crypto/src/circuit/sapling/mod.rs rename to zcash_proofs/src/circuit/sapling.rs index 469ab2e..64bf163 100644 --- a/sapling-crypto/src/circuit/sapling/mod.rs +++ b/zcash_proofs/src/circuit/sapling.rs @@ -6,28 +6,28 @@ use bellman::{ Circuit }; -use jubjub::{ +use sapling_crypto::jubjub::{ JubjubEngine, FixedGenerators }; -use constants; +use sapling_crypto::constants; -use primitives::{ +use sapling_crypto::primitives::{ ValueCommitment, ProofGenerationKey, PaymentAddress }; -use super::Assignment; -use super::boolean; -use super::ecc; -use super::pedersen_hash; -use super::blake2s; -use super::num; -use super::multipack; +use sapling_crypto::circuit::Assignment; +use sapling_crypto::circuit::boolean; +use sapling_crypto::circuit::ecc; +use sapling_crypto::circuit::pedersen_hash; +use sapling_crypto::circuit::blake2s; +use sapling_crypto::circuit::num; +use sapling_crypto::circuit::multipack; -pub const TREE_DEPTH: usize = 32; +pub const TREE_DEPTH: usize = zcash_primitives::sapling::SAPLING_COMMITMENT_TREE_DEPTH; /// This is an instance of the `Spend` circuit. pub struct Spend<'a, E: JubjubEngine> { @@ -602,9 +602,12 @@ fn test_input_circuit_with_bls12_381() { use pairing::bls12_381::*; use rand_core::{RngCore, SeedableRng}; use rand_xorshift::XorShiftRng; - - use ::circuit::test::*; - use jubjub::{JubjubBls12, fs, edwards}; + use sapling_crypto::{ + circuit::test::*, + jubjub::{JubjubBls12, fs, edwards}, + pedersen_hash, + primitives::{Diversifier, Note, ProofGenerationKey}, + }; let params = &JubjubBls12::new(); let rng = &mut XorShiftRng::from_seed([ @@ -623,7 +626,7 @@ fn test_input_circuit_with_bls12_381() { let nsk = fs::Fs::random(rng); let ak = edwards::Point::rand(rng, params).mul_by_cofactor(params); - let proof_generation_key = ::primitives::ProofGenerationKey { + let proof_generation_key = ProofGenerationKey { ak: ak.clone(), nsk: nsk.clone() }; @@ -636,7 +639,7 @@ fn test_input_circuit_with_bls12_381() { let diversifier = { let mut d = [0; 11]; rng.fill_bytes(&mut d); - ::primitives::Diversifier(d) + Diversifier(d) }; if let Some(p) = viewing_key.into_payment_address( @@ -657,7 +660,7 @@ fn test_input_circuit_with_bls12_381() { { let rk = viewing_key.rk(ar, params).into_xy(); let expected_value_cm = value_commitment.cm(params).into_xy(); - let note = ::primitives::Note { + let note = Note { value: value_commitment.value, g_d: g_d.clone(), pk_d: payment_address.pk_d.clone(), @@ -685,8 +688,8 @@ fn test_input_circuit_with_bls12_381() { lhs.reverse(); rhs.reverse(); - cur = ::pedersen_hash::pedersen_hash::( - ::pedersen_hash::Personalization::MerkleTree(i), + cur = pedersen_hash::pedersen_hash::( + pedersen_hash::Personalization::MerkleTree(i), lhs.into_iter() .take(Fr::NUM_BITS as usize) .chain(rhs.into_iter().take(Fr::NUM_BITS as usize)), @@ -743,8 +746,11 @@ fn test_output_circuit_with_bls12_381() { use pairing::bls12_381::*; use rand_core::{RngCore, SeedableRng}; use rand_xorshift::XorShiftRng; - use ::circuit::test::*; - use jubjub::{JubjubBls12, fs, edwards}; + use sapling_crypto::{ + circuit::test::*, + jubjub::{JubjubBls12, fs, edwards}, + primitives::{Diversifier, ProofGenerationKey}, + }; let params = &JubjubBls12::new(); let rng = &mut XorShiftRng::from_seed([ @@ -761,7 +767,7 @@ fn test_output_circuit_with_bls12_381() { let nsk = fs::Fs::random(rng); let ak = edwards::Point::rand(rng, params).mul_by_cofactor(params); - let proof_generation_key = ::primitives::ProofGenerationKey { + let proof_generation_key = ProofGenerationKey { ak: ak.clone(), nsk: nsk.clone() }; @@ -774,7 +780,7 @@ fn test_output_circuit_with_bls12_381() { let diversifier = { let mut d = [0; 11]; rng.fill_bytes(&mut d); - ::primitives::Diversifier(d) + Diversifier(d) }; if let Some(p) = viewing_key.into_payment_address( diff --git a/sapling-crypto/src/circuit/sprout/commitment.rs b/zcash_proofs/src/circuit/sprout/commitment.rs similarity index 92% rename from sapling-crypto/src/circuit/sprout/commitment.rs rename to zcash_proofs/src/circuit/sprout/commitment.rs index a32f05c..4d9f00b 100644 --- a/sapling-crypto/src/circuit/sprout/commitment.rs +++ b/zcash_proofs/src/circuit/sprout/commitment.rs @@ -1,9 +1,9 @@ use pairing::{Engine}; use bellman::{ConstraintSystem, SynthesisError}; -use circuit::sha256::{ +use sapling_crypto::circuit::sha256::{ sha256 }; -use circuit::boolean::{ +use sapling_crypto::circuit::boolean::{ Boolean }; diff --git a/sapling-crypto/src/circuit/sprout/input.rs b/zcash_proofs/src/circuit/sprout/input.rs similarity index 98% rename from sapling-crypto/src/circuit/sprout/input.rs rename to zcash_proofs/src/circuit/sprout/input.rs index ce69bc0..e12723a 100644 --- a/sapling-crypto/src/circuit/sprout/input.rs +++ b/zcash_proofs/src/circuit/sprout/input.rs @@ -1,9 +1,9 @@ use pairing::{Engine}; use bellman::{ConstraintSystem, SynthesisError}; -use circuit::sha256::{ +use sapling_crypto::circuit::sha256::{ sha256_block_no_padding }; -use circuit::boolean::{ +use sapling_crypto::circuit::boolean::{ AllocatedBit, Boolean }; diff --git a/sapling-crypto/src/circuit/sprout/mod.rs b/zcash_proofs/src/circuit/sprout/mod.rs similarity index 98% rename from sapling-crypto/src/circuit/sprout/mod.rs rename to zcash_proofs/src/circuit/sprout/mod.rs index 7027b4a..db2ea0d 100644 --- a/sapling-crypto/src/circuit/sprout/mod.rs +++ b/zcash_proofs/src/circuit/sprout/mod.rs @@ -1,11 +1,11 @@ use ff::Field; use pairing::Engine; use bellman::{ConstraintSystem, SynthesisError, Circuit, LinearCombination}; -use circuit::boolean::{ +use sapling_crypto::circuit::boolean::{ AllocatedBit, Boolean }; -use circuit::multipack::pack_into_inputs; +use sapling_crypto::circuit::multipack::pack_into_inputs; mod prfs; mod commitment; @@ -355,7 +355,7 @@ fn witness_u252( #[test] fn test_sprout_constraints() { use pairing::bls12_381::{Bls12}; - use ::circuit::test::*; + use sapling_crypto::circuit::test::*; use byteorder::{WriteBytesExt, ReadBytesExt, LittleEndian}; @@ -479,7 +479,7 @@ fn test_sprout_constraints() { expected_inputs.write_u64::(vpub_old.unwrap()).unwrap(); expected_inputs.write_u64::(vpub_new.unwrap()).unwrap(); - use circuit::multipack; + use sapling_crypto::circuit::multipack; let expected_inputs = multipack::bytes_to_bits(&expected_inputs); let expected_inputs = multipack::compute_multipacking::(&expected_inputs); diff --git a/sapling-crypto/src/circuit/sprout/output.rs b/zcash_proofs/src/circuit/sprout/output.rs similarity index 95% rename from sapling-crypto/src/circuit/sprout/output.rs rename to zcash_proofs/src/circuit/sprout/output.rs index 9cdbf52..65bcd49 100644 --- a/sapling-crypto/src/circuit/sprout/output.rs +++ b/zcash_proofs/src/circuit/sprout/output.rs @@ -1,6 +1,6 @@ use pairing::{Engine}; use bellman::{ConstraintSystem, SynthesisError}; -use circuit::boolean::{Boolean}; +use sapling_crypto::circuit::boolean::{Boolean}; use super::*; use super::prfs::*; diff --git a/sapling-crypto/src/circuit/sprout/prfs.rs b/zcash_proofs/src/circuit/sprout/prfs.rs similarity index 95% rename from sapling-crypto/src/circuit/sprout/prfs.rs rename to zcash_proofs/src/circuit/sprout/prfs.rs index fff8648..53f65a0 100644 --- a/sapling-crypto/src/circuit/sprout/prfs.rs +++ b/zcash_proofs/src/circuit/sprout/prfs.rs @@ -1,9 +1,9 @@ use pairing::{Engine}; use bellman::{ConstraintSystem, SynthesisError}; -use circuit::sha256::{ +use sapling_crypto::circuit::sha256::{ sha256_block_no_padding }; -use circuit::boolean::{ +use sapling_crypto::circuit::boolean::{ Boolean }; diff --git a/sapling-crypto/src/circuit/sprout/test_vectors.dat b/zcash_proofs/src/circuit/sprout/test_vectors.dat similarity index 100% rename from sapling-crypto/src/circuit/sprout/test_vectors.dat rename to zcash_proofs/src/circuit/sprout/test_vectors.dat diff --git a/zcash_proofs/src/lib.rs b/zcash_proofs/src/lib.rs index d2dc877..2a3c8f2 100644 --- a/zcash_proofs/src/lib.rs +++ b/zcash_proofs/src/lib.rs @@ -10,12 +10,19 @@ extern crate zcash_primitives; #[cfg(feature = "local-prover")] extern crate directories; +#[cfg(test)] +extern crate rand_core; + +#[cfg(test)] +extern crate rand_xorshift; + use bellman::groth16::{prepare_verifying_key, Parameters, PreparedVerifyingKey, VerifyingKey}; use pairing::bls12_381::Bls12; use std::fs::File; use std::io::{self, BufReader}; use std::path::Path; +pub mod circuit; mod hashreader; pub mod sapling; diff --git a/zcash_proofs/src/sapling/prover.rs b/zcash_proofs/src/sapling/prover.rs index 3d30524..78958ad 100644 --- a/zcash_proofs/src/sapling/prover.rs +++ b/zcash_proofs/src/sapling/prover.rs @@ -5,10 +5,7 @@ use ff::Field; use pairing::bls12_381::{Bls12, Fr}; use rand_os::OsRng; use sapling_crypto::{ - circuit::{ - multipack, - sapling::{Output, Spend}, - }, + circuit::multipack, jubjub::{edwards, fs::Fs, FixedGenerators, JubjubBls12, Unknown}, primitives::{Diversifier, Note, PaymentAddress, ProofGenerationKey, ValueCommitment}, }; @@ -20,6 +17,7 @@ use zcash_primitives::{ }; use super::compute_value_balance; +use crate::circuit::sapling::{Output, Spend}; /// A context object for creating the Sapling components of a Zcash transaction. pub struct SaplingProvingContext { From 61c633db1e3098071d4b9167874686a711501649 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 6 Aug 2019 00:48:36 +0100 Subject: [PATCH 3/6] Move Jubjub and Pedersen hash gadgets into zcash_proofs These are currently too Zcash-specific to be generalized, and need some targeted refactoring. --- sapling-crypto/src/circuit/mod.rs | 2 -- zcash_proofs/src/circuit.rs | 3 ++ .../src/circuit/ecc.rs | 19 +++++++------ .../src/circuit/pedersen_hash.rs | 28 +++++++++---------- zcash_proofs/src/circuit/sapling.rs | 4 +-- 5 files changed, 28 insertions(+), 28 deletions(-) rename {sapling-crypto => zcash_proofs}/src/circuit/ecc.rs (99%) rename {sapling-crypto => zcash_proofs}/src/circuit/pedersen_hash.rs (90%) diff --git a/sapling-crypto/src/circuit/mod.rs b/sapling-crypto/src/circuit/mod.rs index 4902f67..016f33e 100644 --- a/sapling-crypto/src/circuit/mod.rs +++ b/sapling-crypto/src/circuit/mod.rs @@ -6,8 +6,6 @@ pub mod uint32; pub mod blake2s; pub mod num; pub mod lookup; -pub mod ecc; -pub mod pedersen_hash; pub mod multipack; pub mod sha256; diff --git a/zcash_proofs/src/circuit.rs b/zcash_proofs/src/circuit.rs index 85fa1cf..ac7e74c 100644 --- a/zcash_proofs/src/circuit.rs +++ b/zcash_proofs/src/circuit.rs @@ -1,2 +1,5 @@ +pub mod ecc; +pub mod pedersen_hash; + pub mod sapling; pub mod sprout; diff --git a/sapling-crypto/src/circuit/ecc.rs b/zcash_proofs/src/circuit/ecc.rs similarity index 99% rename from sapling-crypto/src/circuit/ecc.rs rename to zcash_proofs/src/circuit/ecc.rs index 9b4dbbc..e6cba96 100644 --- a/sapling-crypto/src/circuit/ecc.rs +++ b/zcash_proofs/src/circuit/ecc.rs @@ -6,27 +6,27 @@ use bellman::{ ConstraintSystem }; -use super::{ +use sapling_crypto::circuit::{ Assignment }; -use super::num::{ +use sapling_crypto::circuit::num::{ AllocatedNum, Num }; -use ::jubjub::{ +use sapling_crypto::jubjub::{ edwards, JubjubEngine, JubjubParams, FixedGenerators }; -use super::lookup::{ +use sapling_crypto::circuit::lookup::{ lookup3_xy }; -use super::boolean::Boolean; +use sapling_crypto::circuit::boolean::Boolean; #[derive(Clone)] pub struct EdwardsPoint { @@ -753,22 +753,23 @@ mod test { use rand_core::{RngCore, SeedableRng}; use rand_xorshift::XorShiftRng; - use ::circuit::test::*; - use ::jubjub::{ + use sapling_crypto::circuit::test::*; + use sapling_crypto::jubjub::{ montgomery, edwards, JubjubBls12, JubjubParams, FixedGenerators }; - use ::jubjub::fs::Fs; + use sapling_crypto::jubjub::fs::Fs; + use super::{ MontgomeryPoint, EdwardsPoint, AllocatedNum, fixed_base_multiplication }; - use super::super::boolean::{ + use sapling_crypto::circuit::boolean::{ Boolean, AllocatedBit }; diff --git a/sapling-crypto/src/circuit/pedersen_hash.rs b/zcash_proofs/src/circuit/pedersen_hash.rs similarity index 90% rename from sapling-crypto/src/circuit/pedersen_hash.rs rename to zcash_proofs/src/circuit/pedersen_hash.rs index dd000d3..bbaf999 100644 --- a/sapling-crypto/src/circuit/pedersen_hash.rs +++ b/zcash_proofs/src/circuit/pedersen_hash.rs @@ -1,23 +1,20 @@ -use super::*; use super::ecc::{ MontgomeryPoint, EdwardsPoint }; -use super::boolean::Boolean; -use ::jubjub::*; +use sapling_crypto::circuit::boolean::Boolean; +use sapling_crypto::jubjub::*; use bellman::{ - ConstraintSystem + ConstraintSystem, SynthesisError }; -use super::lookup::*; -pub use pedersen_hash::Personalization; +use sapling_crypto::circuit::lookup::*; +pub use sapling_crypto::pedersen_hash::Personalization; -impl Personalization { - fn get_constant_bools(&self) -> Vec { - self.get_bits() +fn get_constant_bools(person: &Personalization) -> Vec { + person.get_bits() .into_iter() .map(|e| Boolean::constant(e)) .collect() - } } pub fn pedersen_hash( @@ -28,7 +25,7 @@ pub fn pedersen_hash( ) -> Result, SynthesisError> where CS: ConstraintSystem { - let personalization = personalization.get_constant_bools(); + let personalization = get_constant_bools(&personalization); assert_eq!(personalization.len(), 6); let mut edwards_result = None; @@ -113,8 +110,9 @@ pub fn pedersen_hash( #[cfg(test)] mod test { use super::*; - use ::circuit::test::*; - use ::circuit::boolean::{Boolean, AllocatedBit}; + use sapling_crypto::circuit::test::*; + use sapling_crypto::circuit::boolean::{Boolean, AllocatedBit}; + use sapling_crypto::pedersen_hash; use ff::PrimeField; use pairing::bls12_381::{Bls12, Fr}; use rand_core::{RngCore, SeedableRng}; @@ -177,7 +175,7 @@ mod test { assert!(cs.is_satisfied()); - let expected = ::pedersen_hash::pedersen_hash::( + let expected = pedersen_hash::pedersen_hash::( Personalization::MerkleTree(1), input.clone().into_iter(), params @@ -187,7 +185,7 @@ mod test { assert_eq!(res.get_y().get_value().unwrap(), expected.1); // Test against the output of a different personalization - let unexpected = ::pedersen_hash::pedersen_hash::( + let unexpected = pedersen_hash::pedersen_hash::( Personalization::MerkleTree(0), input.into_iter(), params diff --git a/zcash_proofs/src/circuit/sapling.rs b/zcash_proofs/src/circuit/sapling.rs index 64bf163..1fc6e6c 100644 --- a/zcash_proofs/src/circuit/sapling.rs +++ b/zcash_proofs/src/circuit/sapling.rs @@ -21,8 +21,8 @@ use sapling_crypto::primitives::{ use sapling_crypto::circuit::Assignment; use sapling_crypto::circuit::boolean; -use sapling_crypto::circuit::ecc; -use sapling_crypto::circuit::pedersen_hash; +use super::ecc; +use super::pedersen_hash; use sapling_crypto::circuit::blake2s; use sapling_crypto::circuit::num; use sapling_crypto::circuit::multipack; From b8af749b4019da2cb1b85d797f9b7b10f5f13e4b Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 6 Aug 2019 01:13:35 +0100 Subject: [PATCH 4/6] Move generic circuit gadgets into bellman --- Cargo.lock | 4 ++++ bellman/Cargo.toml | 4 ++++ .../src/circuit/mod.rs => bellman/src/gadgets.rs | 2 +- .../src/circuit => bellman/src/gadgets}/blake2s.rs | 8 ++++---- .../src/circuit => bellman/src/gadgets}/boolean.rs | 6 +++--- .../src/circuit => bellman/src/gadgets}/lookup.rs | 6 +++--- .../src/circuit => bellman/src/gadgets}/multieq.rs | 2 +- .../circuit => bellman/src/gadgets}/multipack.rs | 6 +++--- .../src/circuit => bellman/src/gadgets}/num.rs | 6 +++--- .../src/circuit => bellman/src/gadgets}/sha256.rs | 6 +++--- .../circuit => bellman/src/gadgets}/test/mod.rs | 2 +- .../src/circuit => bellman/src/gadgets}/uint32.rs | 10 +++++----- bellman/src/lib.rs | 12 ++++++++++++ librustzcash/src/rustzcash.rs | 2 +- sapling-crypto/src/lib.rs | 1 - zcash_proofs/src/circuit/ecc.rs | 12 ++++++------ zcash_proofs/src/circuit/pedersen_hash.rs | 8 ++++---- zcash_proofs/src/circuit/sapling.rs | 14 +++++++------- zcash_proofs/src/circuit/sprout/commitment.rs | 4 ++-- zcash_proofs/src/circuit/sprout/input.rs | 4 ++-- zcash_proofs/src/circuit/sprout/mod.rs | 8 ++++---- zcash_proofs/src/circuit/sprout/output.rs | 2 +- zcash_proofs/src/circuit/sprout/prfs.rs | 4 ++-- zcash_proofs/src/sapling/prover.rs | 8 +++++--- zcash_proofs/src/sapling/verifier.rs | 10 +++++----- 25 files changed, 86 insertions(+), 65 deletions(-) rename sapling-crypto/src/circuit/mod.rs => bellman/src/gadgets.rs (97%) rename {sapling-crypto/src/circuit => bellman/src/gadgets}/blake2s.rs (99%) rename {sapling-crypto/src/circuit => bellman/src/gadgets}/boolean.rs (99%) rename {sapling-crypto/src/circuit => bellman/src/gadgets}/lookup.rs (98%) rename {sapling-crypto/src/circuit => bellman/src/gadgets}/multieq.rs (99%) rename {sapling-crypto/src/circuit => bellman/src/gadgets}/multipack.rs (96%) rename {sapling-crypto/src/circuit => bellman/src/gadgets}/num.rs (99%) rename {sapling-crypto/src/circuit => bellman/src/gadgets}/sha256.rs (98%) rename {sapling-crypto/src/circuit => bellman/src/gadgets}/test/mod.rs (99%) rename {sapling-crypto/src/circuit => bellman/src/gadgets}/uint32.rs (99%) diff --git a/Cargo.lock b/Cargo.lock index 3bc3137..670966e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -57,16 +57,20 @@ name = "bellman" version = "0.1.0" dependencies = [ "bit-vec 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "blake2s_simd 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "ff 0.4.0", "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "group 0.1.0", + "hex-literal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "pairing 0.14.2", "rand 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_xorshift 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/bellman/Cargo.toml b/bellman/Cargo.toml index b15671e..70521e7 100644 --- a/bellman/Cargo.toml +++ b/bellman/Cargo.toml @@ -10,6 +10,7 @@ version = "0.1.0" [dependencies] bit-vec = "0.4.4" +blake2s_simd = "0.5" ff = { path = "../ff" } futures = "0.1" futures-cpupool = { version = "0.1", optional = true } @@ -21,7 +22,10 @@ rand_core = "0.5" byteorder = "1" [dev-dependencies] +hex-literal = "0.1" rand = "0.7" +rand_xorshift = "0.2" +sha2 = "0.8" [features] groth16 = ["pairing"] diff --git a/sapling-crypto/src/circuit/mod.rs b/bellman/src/gadgets.rs similarity index 97% rename from sapling-crypto/src/circuit/mod.rs rename to bellman/src/gadgets.rs index 016f33e..6c4b09c 100644 --- a/sapling-crypto/src/circuit/mod.rs +++ b/bellman/src/gadgets.rs @@ -9,7 +9,7 @@ pub mod lookup; pub mod multipack; pub mod sha256; -use bellman::{ +use crate::{ SynthesisError }; diff --git a/sapling-crypto/src/circuit/blake2s.rs b/bellman/src/gadgets/blake2s.rs similarity index 99% rename from sapling-crypto/src/circuit/blake2s.rs rename to bellman/src/gadgets/blake2s.rs index 8627dc0..cef50eb 100644 --- a/sapling-crypto/src/circuit/blake2s.rs +++ b/bellman/src/gadgets/blake2s.rs @@ -2,7 +2,7 @@ use pairing::{ Engine, }; -use bellman::{ +use crate::{ SynthesisError, ConstraintSystem }; @@ -325,10 +325,10 @@ mod test { use rand_core::{RngCore, SeedableRng}; use rand_xorshift::XorShiftRng; - use ::circuit::boolean::{Boolean, AllocatedBit}; - use ::circuit::test::TestConstraintSystem; + use crate::gadgets::boolean::{Boolean, AllocatedBit}; + use crate::gadgets::test::TestConstraintSystem; use super::blake2s; - use bellman::{ConstraintSystem}; + use crate::{ConstraintSystem}; #[test] fn test_blank_hash() { diff --git a/sapling-crypto/src/circuit/boolean.rs b/bellman/src/gadgets/boolean.rs similarity index 99% rename from sapling-crypto/src/circuit/boolean.rs rename to bellman/src/gadgets/boolean.rs index 2fe6ef1..f6c11b6 100644 --- a/sapling-crypto/src/circuit/boolean.rs +++ b/bellman/src/gadgets/boolean.rs @@ -1,7 +1,7 @@ use ff::{BitIterator, Field, PrimeField}; use pairing::Engine; -use bellman::{ +use crate::{ ConstraintSystem, SynthesisError, LinearCombination, @@ -801,10 +801,10 @@ impl From for Boolean { #[cfg(test)] mod test { - use bellman::{ConstraintSystem}; + use crate::{ConstraintSystem}; use ff::{Field, PrimeField}; use pairing::bls12_381::{Bls12, Fr}; - use ::circuit::test::*; + use crate::gadgets::test::*; use super::{ AllocatedBit, Boolean, diff --git a/sapling-crypto/src/circuit/lookup.rs b/bellman/src/gadgets/lookup.rs similarity index 98% rename from sapling-crypto/src/circuit/lookup.rs rename to bellman/src/gadgets/lookup.rs index d57f17c..86ab10f 100644 --- a/sapling-crypto/src/circuit/lookup.rs +++ b/bellman/src/gadgets/lookup.rs @@ -7,7 +7,7 @@ use super::num::{ Num }; use super::boolean::Boolean; -use bellman::{ +use crate::{ ConstraintSystem }; @@ -197,8 +197,8 @@ pub fn lookup3_xy_with_conditional_negation( #[cfg(test)] mod test { use super::*; - use ::circuit::test::*; - use ::circuit::boolean::{Boolean, AllocatedBit}; + use crate::gadgets::test::*; + use crate::gadgets::boolean::{Boolean, AllocatedBit}; use pairing::bls12_381::{Bls12, Fr}; use rand_core::{RngCore, SeedableRng}; use rand_xorshift::XorShiftRng; diff --git a/sapling-crypto/src/circuit/multieq.rs b/bellman/src/gadgets/multieq.rs similarity index 99% rename from sapling-crypto/src/circuit/multieq.rs rename to bellman/src/gadgets/multieq.rs index 4cfc3b8..b1dfd7c 100644 --- a/sapling-crypto/src/circuit/multieq.rs +++ b/bellman/src/gadgets/multieq.rs @@ -1,7 +1,7 @@ use ff::{Field, PrimeField}; use pairing::Engine; -use bellman::{ +use crate::{ SynthesisError, ConstraintSystem, LinearCombination, diff --git a/sapling-crypto/src/circuit/multipack.rs b/bellman/src/gadgets/multipack.rs similarity index 96% rename from sapling-crypto/src/circuit/multipack.rs rename to bellman/src/gadgets/multipack.rs index fdecd34..b9b5877 100644 --- a/sapling-crypto/src/circuit/multipack.rs +++ b/bellman/src/gadgets/multipack.rs @@ -1,6 +1,6 @@ use ff::{Field, PrimeField}; use pairing::Engine; -use bellman::{ConstraintSystem, SynthesisError}; +use crate::{ConstraintSystem, SynthesisError}; use super::boolean::{Boolean}; use super::num::Num; use super::Assignment; @@ -80,12 +80,12 @@ pub fn compute_multipacking( #[test] fn test_multipacking() { - use bellman::{ConstraintSystem}; + use crate::{ConstraintSystem}; use pairing::bls12_381::{Bls12}; use rand_core::{RngCore, SeedableRng}; use rand_xorshift::XorShiftRng; - use ::circuit::test::*; + use crate::gadgets::test::*; use super::boolean::{AllocatedBit, Boolean}; let mut rng = XorShiftRng::from_seed([ diff --git a/sapling-crypto/src/circuit/num.rs b/bellman/src/gadgets/num.rs similarity index 99% rename from sapling-crypto/src/circuit/num.rs rename to bellman/src/gadgets/num.rs index 1cdfe22..077301f 100644 --- a/sapling-crypto/src/circuit/num.rs +++ b/bellman/src/gadgets/num.rs @@ -1,7 +1,7 @@ use ff::{BitIterator, Field, PrimeField, PrimeFieldRepr}; use pairing::Engine; -use bellman::{ +use crate::{ SynthesisError, ConstraintSystem, LinearCombination, @@ -455,13 +455,13 @@ impl Num { #[cfg(test)] mod test { - use bellman::{ConstraintSystem}; + use crate::{ConstraintSystem}; use ff::{BitIterator, Field, PrimeField}; use pairing::bls12_381::{Bls12, Fr}; use rand_core::SeedableRng; use rand_xorshift::XorShiftRng; - use ::circuit::test::*; + use crate::gadgets::test::*; use super::{AllocatedNum, Boolean}; #[test] diff --git a/sapling-crypto/src/circuit/sha256.rs b/bellman/src/gadgets/sha256.rs similarity index 98% rename from sapling-crypto/src/circuit/sha256.rs rename to bellman/src/gadgets/sha256.rs index 3b32282..2e4669e 100644 --- a/sapling-crypto/src/circuit/sha256.rs +++ b/bellman/src/gadgets/sha256.rs @@ -1,7 +1,7 @@ use super::uint32::UInt32; use super::multieq::MultiEq; use super::boolean::Boolean; -use bellman::{ConstraintSystem, SynthesisError}; +use crate::{ConstraintSystem, SynthesisError}; use pairing::Engine; const ROUND_CONSTANTS: [u32; 64] = [ @@ -305,9 +305,9 @@ fn sha256_compression_function( #[cfg(test)] mod test { use super::*; - use circuit::boolean::AllocatedBit; + use crate::gadgets::boolean::AllocatedBit; use pairing::bls12_381::Bls12; - use circuit::test::TestConstraintSystem; + use crate::gadgets::test::TestConstraintSystem; use rand_core::{RngCore, SeedableRng}; use rand_xorshift::XorShiftRng; diff --git a/sapling-crypto/src/circuit/test/mod.rs b/bellman/src/gadgets/test/mod.rs similarity index 99% rename from sapling-crypto/src/circuit/test/mod.rs rename to bellman/src/gadgets/test/mod.rs index 79d128a..dc6adbf 100644 --- a/sapling-crypto/src/circuit/test/mod.rs +++ b/bellman/src/gadgets/test/mod.rs @@ -1,7 +1,7 @@ use ff::{Field, PrimeField, PrimeFieldRepr}; use pairing::Engine; -use bellman::{ +use crate::{ LinearCombination, SynthesisError, ConstraintSystem, diff --git a/sapling-crypto/src/circuit/uint32.rs b/bellman/src/gadgets/uint32.rs similarity index 99% rename from sapling-crypto/src/circuit/uint32.rs rename to bellman/src/gadgets/uint32.rs index 939b544..90f8d7e 100644 --- a/sapling-crypto/src/circuit/uint32.rs +++ b/bellman/src/gadgets/uint32.rs @@ -1,7 +1,7 @@ use ff::{Field, PrimeField}; use pairing::Engine; -use bellman::{ +use crate::{ SynthesisError, ConstraintSystem, LinearCombination @@ -409,13 +409,13 @@ impl UInt32 { #[cfg(test)] mod test { - use ::circuit::boolean::{Boolean}; + use crate::gadgets::boolean::{Boolean}; use super::{UInt32}; use ff::Field; use pairing::bls12_381::{Bls12}; - use ::circuit::test::*; - use bellman::{ConstraintSystem}; - use circuit::multieq::MultiEq; + use crate::gadgets::test::*; + use crate::{ConstraintSystem}; + use crate::gadgets::multieq::MultiEq; use rand_core::{RngCore, SeedableRng}; use rand_xorshift::XorShiftRng; diff --git a/bellman/src/lib.rs b/bellman/src/lib.rs index bf9a4e1..ee6bb88 100644 --- a/bellman/src/lib.rs +++ b/bellman/src/lib.rs @@ -6,6 +6,7 @@ extern crate rand_core; extern crate futures; extern crate bit_vec; +extern crate blake2s_simd; extern crate byteorder; #[cfg(feature = "multicore")] @@ -15,9 +16,20 @@ extern crate futures_cpupool; #[cfg(feature = "multicore")] extern crate num_cpus; +#[cfg(test)] +#[macro_use] +extern crate hex_literal; + #[cfg(test)] extern crate rand; +#[cfg(test)] +extern crate rand_xorshift; + +#[cfg(test)] +extern crate sha2; + +pub mod gadgets; pub mod multicore; mod multiexp; pub mod domain; diff --git a/librustzcash/src/rustzcash.rs b/librustzcash/src/rustzcash.rs index 92f8d04..a05d8ef 100644 --- a/librustzcash/src/rustzcash.rs +++ b/librustzcash/src/rustzcash.rs @@ -17,7 +17,6 @@ use ff::{PrimeField, PrimeFieldRepr}; use pairing::bls12_381::{Bls12, Fr, FrRepr}; use sapling_crypto::{ - circuit::multipack, constants::CRH_IVK_PERSONALIZATION, jubjub::{ edwards, @@ -29,6 +28,7 @@ use sapling_crypto::{ use zcash_proofs::circuit::sapling::TREE_DEPTH as SAPLING_TREE_DEPTH; use zcash_proofs::circuit::sprout::{self, TREE_DEPTH as SPROUT_TREE_DEPTH}; +use bellman::gadgets::multipack; use bellman::groth16::{ create_random_proof, verify_proof, Parameters, PreparedVerifyingKey, Proof, }; diff --git a/sapling-crypto/src/lib.rs b/sapling-crypto/src/lib.rs index 3662629..4e944e0 100644 --- a/sapling-crypto/src/lib.rs +++ b/sapling-crypto/src/lib.rs @@ -19,7 +19,6 @@ extern crate sha2; pub mod jubjub; pub mod group_hash; -pub mod circuit; pub mod pedersen_hash; pub mod primitives; pub mod constants; diff --git a/zcash_proofs/src/circuit/ecc.rs b/zcash_proofs/src/circuit/ecc.rs index e6cba96..cb11eb6 100644 --- a/zcash_proofs/src/circuit/ecc.rs +++ b/zcash_proofs/src/circuit/ecc.rs @@ -6,11 +6,11 @@ use bellman::{ ConstraintSystem }; -use sapling_crypto::circuit::{ +use bellman::gadgets::{ Assignment }; -use sapling_crypto::circuit::num::{ +use bellman::gadgets::num::{ AllocatedNum, Num }; @@ -22,11 +22,11 @@ use sapling_crypto::jubjub::{ FixedGenerators }; -use sapling_crypto::circuit::lookup::{ +use bellman::gadgets::lookup::{ lookup3_xy }; -use sapling_crypto::circuit::boolean::Boolean; +use bellman::gadgets::boolean::Boolean; #[derive(Clone)] pub struct EdwardsPoint { @@ -753,7 +753,7 @@ mod test { use rand_core::{RngCore, SeedableRng}; use rand_xorshift::XorShiftRng; - use sapling_crypto::circuit::test::*; + use bellman::gadgets::test::*; use sapling_crypto::jubjub::{ montgomery, edwards, @@ -769,7 +769,7 @@ mod test { AllocatedNum, fixed_base_multiplication }; - use sapling_crypto::circuit::boolean::{ + use bellman::gadgets::boolean::{ Boolean, AllocatedBit }; diff --git a/zcash_proofs/src/circuit/pedersen_hash.rs b/zcash_proofs/src/circuit/pedersen_hash.rs index bbaf999..30a948f 100644 --- a/zcash_proofs/src/circuit/pedersen_hash.rs +++ b/zcash_proofs/src/circuit/pedersen_hash.rs @@ -2,12 +2,12 @@ use super::ecc::{ MontgomeryPoint, EdwardsPoint }; -use sapling_crypto::circuit::boolean::Boolean; +use bellman::gadgets::boolean::Boolean; use sapling_crypto::jubjub::*; use bellman::{ ConstraintSystem, SynthesisError }; -use sapling_crypto::circuit::lookup::*; +use bellman::gadgets::lookup::*; pub use sapling_crypto::pedersen_hash::Personalization; fn get_constant_bools(person: &Personalization) -> Vec { @@ -110,8 +110,8 @@ pub fn pedersen_hash( #[cfg(test)] mod test { use super::*; - use sapling_crypto::circuit::test::*; - use sapling_crypto::circuit::boolean::{Boolean, AllocatedBit}; + use bellman::gadgets::test::*; + use bellman::gadgets::boolean::{Boolean, AllocatedBit}; use sapling_crypto::pedersen_hash; use ff::PrimeField; use pairing::bls12_381::{Bls12, Fr}; diff --git a/zcash_proofs/src/circuit/sapling.rs b/zcash_proofs/src/circuit/sapling.rs index 1fc6e6c..e381240 100644 --- a/zcash_proofs/src/circuit/sapling.rs +++ b/zcash_proofs/src/circuit/sapling.rs @@ -19,13 +19,13 @@ use sapling_crypto::primitives::{ PaymentAddress }; -use sapling_crypto::circuit::Assignment; -use sapling_crypto::circuit::boolean; +use bellman::gadgets::Assignment; +use bellman::gadgets::boolean; use super::ecc; use super::pedersen_hash; -use sapling_crypto::circuit::blake2s; -use sapling_crypto::circuit::num; -use sapling_crypto::circuit::multipack; +use bellman::gadgets::blake2s; +use bellman::gadgets::num; +use bellman::gadgets::multipack; pub const TREE_DEPTH: usize = zcash_primitives::sapling::SAPLING_COMMITMENT_TREE_DEPTH; @@ -598,12 +598,12 @@ impl<'a, E: JubjubEngine> Circuit for Output<'a, E> { #[test] fn test_input_circuit_with_bls12_381() { + use bellman::gadgets::test::*; use ff::{BitIterator, Field}; use pairing::bls12_381::*; use rand_core::{RngCore, SeedableRng}; use rand_xorshift::XorShiftRng; use sapling_crypto::{ - circuit::test::*, jubjub::{JubjubBls12, fs, edwards}, pedersen_hash, primitives::{Diversifier, Note, ProofGenerationKey}, @@ -742,12 +742,12 @@ fn test_input_circuit_with_bls12_381() { #[test] fn test_output_circuit_with_bls12_381() { + use bellman::gadgets::test::*; use ff::Field; use pairing::bls12_381::*; use rand_core::{RngCore, SeedableRng}; use rand_xorshift::XorShiftRng; use sapling_crypto::{ - circuit::test::*, jubjub::{JubjubBls12, fs, edwards}, primitives::{Diversifier, ProofGenerationKey}, }; diff --git a/zcash_proofs/src/circuit/sprout/commitment.rs b/zcash_proofs/src/circuit/sprout/commitment.rs index 4d9f00b..ba889a3 100644 --- a/zcash_proofs/src/circuit/sprout/commitment.rs +++ b/zcash_proofs/src/circuit/sprout/commitment.rs @@ -1,9 +1,9 @@ use pairing::{Engine}; use bellman::{ConstraintSystem, SynthesisError}; -use sapling_crypto::circuit::sha256::{ +use bellman::gadgets::sha256::{ sha256 }; -use sapling_crypto::circuit::boolean::{ +use bellman::gadgets::boolean::{ Boolean }; diff --git a/zcash_proofs/src/circuit/sprout/input.rs b/zcash_proofs/src/circuit/sprout/input.rs index e12723a..a84e3a6 100644 --- a/zcash_proofs/src/circuit/sprout/input.rs +++ b/zcash_proofs/src/circuit/sprout/input.rs @@ -1,9 +1,9 @@ use pairing::{Engine}; use bellman::{ConstraintSystem, SynthesisError}; -use sapling_crypto::circuit::sha256::{ +use bellman::gadgets::sha256::{ sha256_block_no_padding }; -use sapling_crypto::circuit::boolean::{ +use bellman::gadgets::boolean::{ AllocatedBit, Boolean }; diff --git a/zcash_proofs/src/circuit/sprout/mod.rs b/zcash_proofs/src/circuit/sprout/mod.rs index db2ea0d..c28b8d7 100644 --- a/zcash_proofs/src/circuit/sprout/mod.rs +++ b/zcash_proofs/src/circuit/sprout/mod.rs @@ -1,11 +1,11 @@ use ff::Field; use pairing::Engine; use bellman::{ConstraintSystem, SynthesisError, Circuit, LinearCombination}; -use sapling_crypto::circuit::boolean::{ +use bellman::gadgets::boolean::{ AllocatedBit, Boolean }; -use sapling_crypto::circuit::multipack::pack_into_inputs; +use bellman::gadgets::multipack::pack_into_inputs; mod prfs; mod commitment; @@ -355,7 +355,7 @@ fn witness_u252( #[test] fn test_sprout_constraints() { use pairing::bls12_381::{Bls12}; - use sapling_crypto::circuit::test::*; + use bellman::gadgets::test::*; use byteorder::{WriteBytesExt, ReadBytesExt, LittleEndian}; @@ -479,7 +479,7 @@ fn test_sprout_constraints() { expected_inputs.write_u64::(vpub_old.unwrap()).unwrap(); expected_inputs.write_u64::(vpub_new.unwrap()).unwrap(); - use sapling_crypto::circuit::multipack; + use bellman::gadgets::multipack; let expected_inputs = multipack::bytes_to_bits(&expected_inputs); let expected_inputs = multipack::compute_multipacking::(&expected_inputs); diff --git a/zcash_proofs/src/circuit/sprout/output.rs b/zcash_proofs/src/circuit/sprout/output.rs index 65bcd49..f2e504a 100644 --- a/zcash_proofs/src/circuit/sprout/output.rs +++ b/zcash_proofs/src/circuit/sprout/output.rs @@ -1,6 +1,6 @@ use pairing::{Engine}; use bellman::{ConstraintSystem, SynthesisError}; -use sapling_crypto::circuit::boolean::{Boolean}; +use bellman::gadgets::boolean::{Boolean}; use super::*; use super::prfs::*; diff --git a/zcash_proofs/src/circuit/sprout/prfs.rs b/zcash_proofs/src/circuit/sprout/prfs.rs index 53f65a0..0b3e42c 100644 --- a/zcash_proofs/src/circuit/sprout/prfs.rs +++ b/zcash_proofs/src/circuit/sprout/prfs.rs @@ -1,9 +1,9 @@ use pairing::{Engine}; use bellman::{ConstraintSystem, SynthesisError}; -use sapling_crypto::circuit::sha256::{ +use bellman::gadgets::sha256::{ sha256_block_no_padding }; -use sapling_crypto::circuit::boolean::{ +use bellman::gadgets::boolean::{ Boolean }; diff --git a/zcash_proofs/src/sapling/prover.rs b/zcash_proofs/src/sapling/prover.rs index 78958ad..7ca8bce 100644 --- a/zcash_proofs/src/sapling/prover.rs +++ b/zcash_proofs/src/sapling/prover.rs @@ -1,11 +1,13 @@ -use bellman::groth16::{ - create_random_proof, verify_proof, Parameters, PreparedVerifyingKey, Proof, +use bellman::{ + gadgets::multipack, + groth16::{ + create_random_proof, verify_proof, Parameters, PreparedVerifyingKey, Proof, + }, }; use ff::Field; use pairing::bls12_381::{Bls12, Fr}; use rand_os::OsRng; use sapling_crypto::{ - circuit::multipack, jubjub::{edwards, fs::Fs, FixedGenerators, JubjubBls12, Unknown}, primitives::{Diversifier, Note, PaymentAddress, ProofGenerationKey, ValueCommitment}, }; diff --git a/zcash_proofs/src/sapling/verifier.rs b/zcash_proofs/src/sapling/verifier.rs index ac4f3f7..01cba0c 100644 --- a/zcash_proofs/src/sapling/verifier.rs +++ b/zcash_proofs/src/sapling/verifier.rs @@ -1,10 +1,10 @@ -use bellman::groth16::{verify_proof, PreparedVerifyingKey, Proof}; +use bellman::{ + gadgets::multipack, + groth16::{verify_proof, PreparedVerifyingKey, Proof}, +}; use ff::Field; use pairing::bls12_381::{Bls12, Fr}; -use sapling_crypto::{ - circuit::multipack, - jubjub::{edwards, FixedGenerators, JubjubBls12, Unknown}, -}; +use sapling_crypto::jubjub::{edwards, FixedGenerators, JubjubBls12, Unknown}; use zcash_primitives::{ redjubjub::{PublicKey, Signature}, transaction::components::Amount, From 5fb9b86ba01df08179ee1c297e158ddfdcb28557 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 6 Aug 2019 10:46:40 +0100 Subject: [PATCH 5/6] Move Jubjub, Pedersen hash and primitives into zcash_primitives --- Cargo.lock | 8 +++--- librustzcash/Cargo.toml | 1 - librustzcash/src/rustzcash.rs | 27 ++++++++++--------- librustzcash/src/tests/key_agreement.rs | 4 +-- librustzcash/src/tests/key_components.rs | 2 +- librustzcash/src/tests/mod.rs | 2 +- librustzcash/src/tests/signatures.rs | 2 +- sapling-crypto/src/lib.rs | 6 ----- zcash_client_backend/Cargo.toml | 1 - zcash_client_backend/src/encoding.rs | 24 ++++++++--------- zcash_primitives/Cargo.toml | 3 ++- .../benches/pedersen_hash.rs | 16 ++++++----- .../src/constants.rs | 0 .../src/group_hash.rs | 0 .../src/jubjub/edwards.rs | 0 .../src/jubjub/fs.rs | 0 .../src/jubjub/mod.rs | 0 .../src/jubjub/montgomery.rs | 0 .../src/jubjub/tests.rs | 0 zcash_primitives/src/keys.rs | 4 +-- zcash_primitives/src/lib.rs | 15 ++++++++--- zcash_primitives/src/note_encryption.rs | 12 ++++----- .../src/pedersen_hash.rs | 0 .../src/primitives.rs | 0 zcash_primitives/src/prover.rs | 5 ++-- zcash_primitives/src/redjubjub.rs | 5 ++-- zcash_primitives/src/sapling.rs | 2 +- zcash_primitives/src/transaction/builder.rs | 5 ++-- .../src/transaction/components.rs | 2 +- zcash_primitives/src/transaction/tests.rs | 3 ++- zcash_primitives/src/util.rs | 3 ++- zcash_primitives/src/zip32.rs | 3 ++- zcash_proofs/Cargo.toml | 1 - zcash_proofs/examples/bench.rs | 6 ++--- zcash_proofs/src/circuit/ecc.rs | 6 ++--- zcash_proofs/src/circuit/pedersen_hash.rs | 6 ++--- zcash_proofs/src/circuit/sapling.rs | 10 +++---- zcash_proofs/src/lib.rs | 1 - zcash_proofs/src/prover.rs | 2 +- zcash_proofs/src/sapling/mod.rs | 2 +- zcash_proofs/src/sapling/prover.rs | 2 +- zcash_proofs/src/sapling/verifier.rs | 2 +- 42 files changed, 99 insertions(+), 94 deletions(-) rename {sapling-crypto => zcash_primitives}/benches/pedersen_hash.rs (50%) rename {sapling-crypto => zcash_primitives}/src/constants.rs (100%) rename {sapling-crypto => zcash_primitives}/src/group_hash.rs (100%) rename {sapling-crypto => zcash_primitives}/src/jubjub/edwards.rs (100%) rename {sapling-crypto => zcash_primitives}/src/jubjub/fs.rs (100%) rename {sapling-crypto => zcash_primitives}/src/jubjub/mod.rs (100%) rename {sapling-crypto => zcash_primitives}/src/jubjub/montgomery.rs (100%) rename {sapling-crypto => zcash_primitives}/src/jubjub/tests.rs (100%) rename {sapling-crypto => zcash_primitives}/src/pedersen_hash.rs (100%) rename sapling-crypto/src/primitives/mod.rs => zcash_primitives/src/primitives.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 670966e..ef4f552 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -57,7 +57,7 @@ name = "bellman" version = "0.1.0" dependencies = [ "bit-vec 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", - "blake2s_simd 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", + "blake2s_simd 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "ff 0.4.0", @@ -313,7 +313,6 @@ dependencies = [ "pairing 0.14.2", "rand_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_os 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "sapling-crypto 0.0.1", "zcash_primitives 0.0.0", "zcash_proofs 0.0.0", ] @@ -536,7 +535,6 @@ dependencies = [ "pairing 0.14.2", "rand_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_xorshift 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sapling-crypto 0.0.1", "zcash_primitives 0.0.0", ] @@ -546,18 +544,19 @@ version = "0.0.0" dependencies = [ "aes 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "blake2b_simd 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "blake2s_simd 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "crypto_api_chachapoly 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "ff 0.4.0", "fpe 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "hex-literal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "pairing 0.14.2", "rand 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_os 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_xorshift 0.2.0 (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)", ] @@ -574,7 +573,6 @@ dependencies = [ "rand_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_os 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_xorshift 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sapling-crypto 0.0.1", "zcash_primitives 0.0.0", ] diff --git a/librustzcash/Cargo.toml b/librustzcash/Cargo.toml index ffc38fa..3256d14 100644 --- a/librustzcash/Cargo.toml +++ b/librustzcash/Cargo.toml @@ -24,6 +24,5 @@ lazy_static = "1" byteorder = "1" rand_core = "0.5" rand_os = "0.2" -sapling-crypto = { path = "../sapling-crypto" } zcash_primitives = { path = "../zcash_primitives" } zcash_proofs = { path = "../zcash_proofs" } diff --git a/librustzcash/src/rustzcash.rs b/librustzcash/src/rustzcash.rs index a05d8ef..b1e0a30 100644 --- a/librustzcash/src/rustzcash.rs +++ b/librustzcash/src/rustzcash.rs @@ -7,7 +7,6 @@ extern crate libc; extern crate pairing; extern crate rand_core; extern crate rand_os; -extern crate sapling_crypto; extern crate zcash_primitives; extern crate zcash_proofs; @@ -16,7 +15,7 @@ extern crate lazy_static; use ff::{PrimeField, PrimeFieldRepr}; use pairing::bls12_381::{Bls12, Fr, FrRepr}; -use sapling_crypto::{ +use zcash_primitives::{ constants::CRH_IVK_PERSONALIZATION, jubjub::{ edwards, @@ -57,10 +56,12 @@ use std::ffi::OsString; #[cfg(target_os = "windows")] use std::os::windows::ffi::OsStringExt; -use sapling_crypto::primitives::{ProofGenerationKey, ViewingKey}; use zcash_primitives::{ merkle_tree::CommitmentTreeWitness, note_encryption::sapling_ka_agree, + primitives::{ + Diversifier, Note, PaymentAddress, ProofGenerationKey, ViewingKey, + }, redjubjub::{self, Signature}, sapling::{merkle_hash, spend_sig}, transaction::components::Amount, @@ -236,7 +237,7 @@ fn init_zksnark_params( #[no_mangle] pub extern "system" fn librustzcash_tree_uncommitted(result: *mut [c_uchar; 32]) { - let tmp = sapling_crypto::primitives::Note::::uncommitted().into_repr(); + let tmp = Note::::uncommitted().into_repr(); // Should be okay, caller is responsible for ensuring the pointer // is a valid pointer to 32 bytes that can be mutated. @@ -341,7 +342,7 @@ pub extern "system" fn librustzcash_crh_ivk( #[no_mangle] pub extern "system" fn librustzcash_check_diversifier(diversifier: *const [c_uchar; 11]) -> bool { - let diversifier = sapling_crypto::primitives::Diversifier(unsafe { *diversifier }); + let diversifier = Diversifier(unsafe { *diversifier }); diversifier.g_d::(&JUBJUB).is_some() } @@ -352,7 +353,7 @@ pub extern "system" fn librustzcash_ivk_to_pkd( result: *mut [c_uchar; 32], ) -> bool { let ivk = read_fs(unsafe { &*ivk }); - let diversifier = sapling_crypto::primitives::Diversifier(unsafe { *diversifier }); + let diversifier = Diversifier(unsafe { *diversifier }); if let Some(g_d) = diversifier.g_d::(&JUBJUB) { let pk_d = g_d.mul(ivk, &JUBJUB); @@ -407,8 +408,8 @@ fn priv_get_note( pk_d: *const [c_uchar; 32], value: u64, r: *const [c_uchar; 32], -) -> Result, ()> { - let diversifier = sapling_crypto::primitives::Diversifier(unsafe { *diversifier }); +) -> Result, ()> { + let diversifier = Diversifier(unsafe { *diversifier }); let g_d = match diversifier.g_d::(&JUBJUB) { Some(g_d) => g_d, None => return Err(()), @@ -430,7 +431,7 @@ fn priv_get_note( Err(_) => return Err(()), }; - let note = sapling_crypto::primitives::Note { + let note = Note { value, g_d, pk_d, @@ -539,7 +540,7 @@ pub extern "system" fn librustzcash_sapling_ka_derivepublic( esk: *const [c_uchar; 32], result: *mut [c_uchar; 32], ) -> bool { - let diversifier = sapling_crypto::primitives::Diversifier(unsafe { *diversifier }); + let diversifier = Diversifier(unsafe { *diversifier }); // Compute g_d from the diversifier let g_d = match diversifier.g_d::(&JUBJUB) { @@ -940,7 +941,7 @@ pub extern "system" fn librustzcash_sapling_output_proof( }; // Grab the diversifier from the caller. - let diversifier = sapling_crypto::primitives::Diversifier(unsafe { *diversifier }); + let diversifier = Diversifier(unsafe { *diversifier }); // Grab pk_d from the caller. let pk_d = match edwards::Point::::read(&(unsafe { &*pk_d })[..], &JUBJUB) { @@ -955,7 +956,7 @@ pub extern "system" fn librustzcash_sapling_output_proof( }; // Construct a payment address - let payment_address = sapling_crypto::primitives::PaymentAddress { + let payment_address = PaymentAddress { pk_d: pk_d, diversifier: diversifier, }; @@ -1086,7 +1087,7 @@ pub extern "system" fn librustzcash_sapling_spend_proof( }; // Grab the diversifier from the caller - let diversifier = sapling_crypto::primitives::Diversifier(unsafe { *diversifier }); + let diversifier = Diversifier(unsafe { *diversifier }); // The caller chooses the note randomness let rcm = match Fs::from_repr(read_fs(&(unsafe { &*rcm })[..])) { diff --git a/librustzcash/src/tests/key_agreement.rs b/librustzcash/src/tests/key_agreement.rs index 412ecc3..ab1cc84 100644 --- a/librustzcash/src/tests/key_agreement.rs +++ b/librustzcash/src/tests/key_agreement.rs @@ -2,8 +2,8 @@ use ff::{PrimeField, PrimeFieldRepr}; use pairing::bls12_381::Bls12; use rand_core::RngCore; use rand_os::OsRng; -use sapling_crypto::jubjub::{edwards, JubjubBls12}; -use sapling_crypto::primitives::{Diversifier, ViewingKey}; +use zcash_primitives::jubjub::{edwards, JubjubBls12}; +use zcash_primitives::primitives::{Diversifier, ViewingKey}; use { librustzcash_sapling_generate_r, librustzcash_sapling_ka_agree, diff --git a/librustzcash/src/tests/key_components.rs b/librustzcash/src/tests/key_components.rs index 5f332e9..99d3f52 100644 --- a/librustzcash/src/tests/key_components.rs +++ b/librustzcash/src/tests/key_components.rs @@ -1,6 +1,6 @@ use ff::{PrimeField, PrimeFieldRepr}; use pairing::bls12_381::Bls12; -use sapling_crypto::{ +use zcash_primitives::{ jubjub::{fs::FsRepr, FixedGenerators, JubjubEngine, JubjubParams}, primitives::{Diversifier, ProofGenerationKey}, }; diff --git a/librustzcash/src/tests/mod.rs b/librustzcash/src/tests/mod.rs index a8cdcb7..dba7387 100644 --- a/librustzcash/src/tests/mod.rs +++ b/librustzcash/src/tests/mod.rs @@ -1,4 +1,4 @@ -use sapling_crypto::jubjub::{FixedGenerators, JubjubParams}; +use zcash_primitives::jubjub::{FixedGenerators, JubjubParams}; use super::JUBJUB; diff --git a/librustzcash/src/tests/signatures.rs b/librustzcash/src/tests/signatures.rs index 034b05a..68ac799 100644 --- a/librustzcash/src/tests/signatures.rs +++ b/librustzcash/src/tests/signatures.rs @@ -1,6 +1,6 @@ use ff::{PrimeField, PrimeFieldRepr}; use pairing::bls12_381::Bls12; -use sapling_crypto::jubjub::{FixedGenerators, JubjubEngine}; +use zcash_primitives::jubjub::{FixedGenerators, JubjubEngine}; use zcash_primitives::redjubjub::{PrivateKey, PublicKey, Signature}; use super::JUBJUB; diff --git a/sapling-crypto/src/lib.rs b/sapling-crypto/src/lib.rs index 4e944e0..af5dbb1 100644 --- a/sapling-crypto/src/lib.rs +++ b/sapling-crypto/src/lib.rs @@ -16,9 +16,3 @@ extern crate rand_xorshift; #[cfg(test)] extern crate sha2; - -pub mod jubjub; -pub mod group_hash; -pub mod pedersen_hash; -pub mod primitives; -pub mod constants; diff --git a/zcash_client_backend/Cargo.toml b/zcash_client_backend/Cargo.toml index 31fba49..9996a47 100644 --- a/zcash_client_backend/Cargo.toml +++ b/zcash_client_backend/Cargo.toml @@ -9,7 +9,6 @@ edition = "2018" [dependencies] bech32 = "0.7" pairing = { path = "../pairing" } -sapling-crypto = { path = "../sapling-crypto" } zcash_primitives = { path = "../zcash_primitives" } [dev-dependencies] diff --git a/zcash_client_backend/src/encoding.rs b/zcash_client_backend/src/encoding.rs index 0c0a50b..e84defa 100644 --- a/zcash_client_backend/src/encoding.rs +++ b/zcash_client_backend/src/encoding.rs @@ -5,7 +5,7 @@ use bech32::{self, Error, FromBase32, ToBase32}; use pairing::bls12_381::Bls12; -use sapling_crypto::{ +use zcash_primitives::{ jubjub::edwards, primitives::{Diversifier, PaymentAddress}, }; @@ -98,15 +98,15 @@ pub fn decode_extended_full_viewing_key( /// use pairing::bls12_381::Bls12; /// use rand_core::SeedableRng; /// use rand_xorshift::XorShiftRng; -/// use sapling_crypto::{ -/// jubjub::edwards, -/// primitives::{Diversifier, PaymentAddress}, -/// }; /// use zcash_client_backend::{ /// constants::testnet::HRP_SAPLING_PAYMENT_ADDRESS, /// encoding::encode_payment_address, /// }; -/// use zcash_primitives::JUBJUB; +/// use zcash_primitives::{ +/// jubjub::edwards, +/// primitives::{Diversifier, PaymentAddress}, +/// JUBJUB, +/// }; /// /// let rng = &mut XorShiftRng::from_seed([ /// 0x59, 0x62, 0xbe, 0x3d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, @@ -138,15 +138,15 @@ pub fn encode_payment_address(hrp: &str, addr: &PaymentAddress) -> String /// use pairing::bls12_381::Bls12; /// use rand_core::SeedableRng; /// use rand_xorshift::XorShiftRng; -/// use sapling_crypto::{ -/// jubjub::edwards, -/// primitives::{Diversifier, PaymentAddress}, -/// }; /// use zcash_client_backend::{ /// constants::testnet::HRP_SAPLING_PAYMENT_ADDRESS, /// encoding::decode_payment_address, /// }; -/// use zcash_primitives::JUBJUB; +/// use zcash_primitives::{ +/// jubjub::edwards, +/// primitives::{Diversifier, PaymentAddress}, +/// JUBJUB, +/// }; /// /// let rng = &mut XorShiftRng::from_seed([ /// 0x59, 0x62, 0xbe, 0x3d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, @@ -187,7 +187,7 @@ mod tests { use pairing::bls12_381::Bls12; use rand_core::SeedableRng; use rand_xorshift::XorShiftRng; - use sapling_crypto::{ + use zcash_primitives::{ jubjub::edwards, primitives::{Diversifier, PaymentAddress}, }; diff --git a/zcash_primitives/Cargo.toml b/zcash_primitives/Cargo.toml index 49b1b7d..b3173b7 100644 --- a/zcash_primitives/Cargo.toml +++ b/zcash_primitives/Cargo.toml @@ -8,6 +8,7 @@ authors = [ [dependencies] aes = "0.3" blake2b_simd = "0.5" +blake2s_simd = "0.5" byteorder = "1" crypto_api_chachapoly = "0.2.1" ff = { path = "../ff" } @@ -18,8 +19,8 @@ pairing = { path = "../pairing" } rand = "0.7" rand_core = "0.5" rand_os = "0.2" -sapling-crypto = { path = "../sapling-crypto" } sha2 = "0.8" [dev-dependencies] +hex-literal = "0.1" rand_xorshift = "0.2" diff --git a/sapling-crypto/benches/pedersen_hash.rs b/zcash_primitives/benches/pedersen_hash.rs similarity index 50% rename from sapling-crypto/benches/pedersen_hash.rs rename to zcash_primitives/benches/pedersen_hash.rs index c5968de..a8f944e 100644 --- a/sapling-crypto/benches/pedersen_hash.rs +++ b/zcash_primitives/benches/pedersen_hash.rs @@ -1,20 +1,22 @@ #![feature(test)] -extern crate rand; +extern crate rand_core; +extern crate rand_os; extern crate test; extern crate pairing; -extern crate sapling_crypto; +extern crate zcash_primitives; -use rand::{Rand, thread_rng}; +use rand_core::RngCore; +use rand_os::OsRng; use pairing::bls12_381::Bls12; -use sapling_crypto::jubjub::JubjubBls12; -use sapling_crypto::pedersen_hash::{pedersen_hash, Personalization}; +use zcash_primitives::jubjub::JubjubBls12; +use zcash_primitives::pedersen_hash::{pedersen_hash, Personalization}; #[bench] fn bench_pedersen_hash(b: &mut test::Bencher) { let params = JubjubBls12::new(); - let rng = &mut thread_rng(); - let bits = (0..510).map(|_| bool::rand(rng)).collect::>(); + let rng = &mut OsRng; + let bits = (0..510).map(|_| (rng.next_u32() % 2) != 0).collect::>(); let personalization = Personalization::MerkleTree(31); b.iter(|| { diff --git a/sapling-crypto/src/constants.rs b/zcash_primitives/src/constants.rs similarity index 100% rename from sapling-crypto/src/constants.rs rename to zcash_primitives/src/constants.rs diff --git a/sapling-crypto/src/group_hash.rs b/zcash_primitives/src/group_hash.rs similarity index 100% rename from sapling-crypto/src/group_hash.rs rename to zcash_primitives/src/group_hash.rs diff --git a/sapling-crypto/src/jubjub/edwards.rs b/zcash_primitives/src/jubjub/edwards.rs similarity index 100% rename from sapling-crypto/src/jubjub/edwards.rs rename to zcash_primitives/src/jubjub/edwards.rs diff --git a/sapling-crypto/src/jubjub/fs.rs b/zcash_primitives/src/jubjub/fs.rs similarity index 100% rename from sapling-crypto/src/jubjub/fs.rs rename to zcash_primitives/src/jubjub/fs.rs diff --git a/sapling-crypto/src/jubjub/mod.rs b/zcash_primitives/src/jubjub/mod.rs similarity index 100% rename from sapling-crypto/src/jubjub/mod.rs rename to zcash_primitives/src/jubjub/mod.rs diff --git a/sapling-crypto/src/jubjub/montgomery.rs b/zcash_primitives/src/jubjub/montgomery.rs similarity index 100% rename from sapling-crypto/src/jubjub/montgomery.rs rename to zcash_primitives/src/jubjub/montgomery.rs diff --git a/sapling-crypto/src/jubjub/tests.rs b/zcash_primitives/src/jubjub/tests.rs similarity index 100% rename from sapling-crypto/src/jubjub/tests.rs rename to zcash_primitives/src/jubjub/tests.rs diff --git a/zcash_primitives/src/keys.rs b/zcash_primitives/src/keys.rs index fca31ed..ae2c77a 100644 --- a/zcash_primitives/src/keys.rs +++ b/zcash_primitives/src/keys.rs @@ -4,7 +4,7 @@ use blake2b_simd::{Hash as Blake2bHash, Params as Blake2bParams}; use ff::{PrimeField, PrimeFieldRepr}; -use sapling_crypto::{ +use crate::{ jubjub::{edwards, FixedGenerators, JubjubEngine, JubjubParams, ToUniform, Unknown}, primitives::{ProofGenerationKey, ViewingKey}, }; @@ -188,7 +188,7 @@ impl FullViewingKey { #[cfg(test)] mod tests { use pairing::bls12_381::Bls12; - use sapling_crypto::jubjub::{edwards, FixedGenerators, JubjubParams, PrimeOrder}; + use crate::jubjub::{edwards, FixedGenerators, JubjubParams, PrimeOrder}; use std::error::Error; use super::FullViewingKey; diff --git a/zcash_primitives/src/lib.rs b/zcash_primitives/src/lib.rs index 771f13d..1d4806e 100644 --- a/zcash_primitives/src/lib.rs +++ b/zcash_primitives/src/lib.rs @@ -3,6 +3,7 @@ extern crate lazy_static; extern crate aes; extern crate blake2b_simd; +extern crate blake2s_simd; extern crate byteorder; extern crate crypto_api_chachapoly; extern crate ff; @@ -12,19 +13,25 @@ extern crate pairing; extern crate rand; extern crate rand_core; extern crate rand_os; -extern crate sapling_crypto; extern crate sha2; +#[cfg(test)] +#[macro_use] +extern crate hex_literal; + #[cfg(test)] extern crate rand_xorshift; -use sapling_crypto::jubjub::JubjubBls12; - pub mod block; +pub mod constants; +pub mod group_hash; +pub mod jubjub; pub mod keys; pub mod legacy; pub mod merkle_tree; pub mod note_encryption; +pub mod pedersen_hash; +pub mod primitives; pub mod prover; pub mod redjubjub; pub mod sapling; @@ -36,6 +43,8 @@ pub mod zip32; #[cfg(test)] mod test_vectors; +use jubjub::JubjubBls12; + lazy_static! { pub static ref JUBJUB: JubjubBls12 = { JubjubBls12::new() }; } diff --git a/zcash_primitives/src/note_encryption.rs b/zcash_primitives/src/note_encryption.rs index d6b66ce..e6804cf 100644 --- a/zcash_primitives/src/note_encryption.rs +++ b/zcash_primitives/src/note_encryption.rs @@ -6,7 +6,7 @@ use crypto_api_chachapoly::{ChaCha20Ietf, ChachaPolyIetf}; use ff::{PrimeField, PrimeFieldRepr}; use pairing::bls12_381::{Bls12, Fr}; use rand_core::{CryptoRng, RngCore}; -use sapling_crypto::{ +use crate::{ jubjub::{ edwards, fs::{Fs, FsRepr}, @@ -211,18 +211,16 @@ fn prf_ock( /// extern crate ff; /// extern crate pairing; /// extern crate rand_os; -/// extern crate sapling_crypto; +/// extern crate zcash_primitives; /// /// use ff::Field; /// use pairing::bls12_381::Bls12; /// use rand_os::OsRng; -/// use sapling_crypto::{ -/// jubjub::fs::Fs, -/// primitives::{Diversifier, PaymentAddress, ValueCommitment}, -/// }; /// use zcash_primitives::{ +/// jubjub::fs::Fs, /// keys::OutgoingViewingKey, /// note_encryption::{Memo, SaplingNoteEncryption}, +/// primitives::{Diversifier, PaymentAddress, ValueCommitment}, /// JUBJUB, /// }; /// @@ -551,7 +549,7 @@ mod tests { use pairing::bls12_381::{Bls12, Fr, FrRepr}; use rand_core::{CryptoRng, RngCore}; use rand_os::OsRng; - use sapling_crypto::{ + use crate::{ jubjub::{ edwards, fs::{Fs, FsRepr}, diff --git a/sapling-crypto/src/pedersen_hash.rs b/zcash_primitives/src/pedersen_hash.rs similarity index 100% rename from sapling-crypto/src/pedersen_hash.rs rename to zcash_primitives/src/pedersen_hash.rs diff --git a/sapling-crypto/src/primitives/mod.rs b/zcash_primitives/src/primitives.rs similarity index 100% rename from sapling-crypto/src/primitives/mod.rs rename to zcash_primitives/src/primitives.rs diff --git a/zcash_primitives/src/prover.rs b/zcash_primitives/src/prover.rs index a4af8d4..a434b4e 100644 --- a/zcash_primitives/src/prover.rs +++ b/zcash_primitives/src/prover.rs @@ -1,7 +1,7 @@ //! Abstractions over the proving system and parameters. use pairing::bls12_381::{Bls12, Fr}; -use sapling_crypto::{ +use crate::{ jubjub::{edwards, fs::Fs, Unknown}, primitives::{Diversifier, PaymentAddress, ProofGenerationKey}, }; @@ -75,7 +75,8 @@ pub(crate) mod mock { use ff::Field; use pairing::bls12_381::{Bls12, Fr}; use rand_os::OsRng; - use sapling_crypto::{ + + use crate::{ jubjub::{edwards, fs::Fs, FixedGenerators, Unknown}, primitives::{Diversifier, PaymentAddress, ProofGenerationKey, ValueCommitment}, }; diff --git a/zcash_primitives/src/redjubjub.rs b/zcash_primitives/src/redjubjub.rs index 955c7e3..b709419 100644 --- a/zcash_primitives/src/redjubjub.rs +++ b/zcash_primitives/src/redjubjub.rs @@ -3,7 +3,7 @@ use ff::{Field, PrimeField, PrimeFieldRepr}; use rand_core::RngCore; -use sapling_crypto::jubjub::{ +use crate::jubjub::{ edwards::Point, FixedGenerators, JubjubEngine, JubjubParams, Unknown, }; use std::io::{self, Read, Write}; @@ -210,7 +210,8 @@ mod tests { use pairing::bls12_381::Bls12; use rand_core::SeedableRng; use rand_xorshift::XorShiftRng; - use sapling_crypto::jubjub::{edwards, fs::Fs, JubjubBls12}; + + use crate::jubjub::{edwards, fs::Fs, JubjubBls12}; use super::*; diff --git a/zcash_primitives/src/sapling.rs b/zcash_primitives/src/sapling.rs index 0b94e4e..4590c79 100644 --- a/zcash_primitives/src/sapling.rs +++ b/zcash_primitives/src/sapling.rs @@ -3,7 +3,7 @@ use ff::{BitIterator, PrimeField, PrimeFieldRepr}; use pairing::bls12_381::{Bls12, Fr, FrRepr}; use rand_core::{CryptoRng, RngCore}; -use sapling_crypto::{ +use crate::{ jubjub::{fs::Fs, FixedGenerators, JubjubBls12}, pedersen_hash::{pedersen_hash, Personalization}, primitives::Note, diff --git a/zcash_primitives/src/transaction/builder.rs b/zcash_primitives/src/transaction/builder.rs index 792582d..f32af7a 100644 --- a/zcash_primitives/src/transaction/builder.rs +++ b/zcash_primitives/src/transaction/builder.rs @@ -3,7 +3,7 @@ use ff::Field; use pairing::bls12_381::{Bls12, Fr}; use rand::{rngs::OsRng, seq::SliceRandom, CryptoRng, RngCore}; -use sapling_crypto::{ +use crate::{ jubjub::fs::Fs, primitives::{Diversifier, Note, PaymentAddress}, }; @@ -534,7 +534,8 @@ impl Builder { mod tests { use ff::{Field, PrimeField}; use rand::rngs::OsRng; - use sapling_crypto::jubjub::fs::Fs; + + use crate::jubjub::fs::Fs; use super::{Builder, Error}; use crate::{ diff --git a/zcash_primitives/src/transaction/components.rs b/zcash_primitives/src/transaction/components.rs index 1785344..c8cfadc 100644 --- a/zcash_primitives/src/transaction/components.rs +++ b/zcash_primitives/src/transaction/components.rs @@ -1,7 +1,7 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use ff::{PrimeField, PrimeFieldRepr}; use pairing::bls12_381::{Bls12, Fr, FrRepr}; -use sapling_crypto::jubjub::{edwards, Unknown}; +use crate::jubjub::{edwards, Unknown}; use std::io::{self, Read, Write}; use legacy::Script; diff --git a/zcash_primitives/src/transaction/tests.rs b/zcash_primitives/src/transaction/tests.rs index 041ac21..7c770c5 100644 --- a/zcash_primitives/src/transaction/tests.rs +++ b/zcash_primitives/src/transaction/tests.rs @@ -1,7 +1,8 @@ use ff::Field; use pairing::bls12_381::Bls12; use rand_os::OsRng; -use sapling_crypto::jubjub::{fs::Fs, FixedGenerators}; + +use crate::jubjub::{fs::Fs, FixedGenerators}; use super::{components::Amount, sighash::signature_hash, Transaction, TransactionData}; use legacy::Script; diff --git a/zcash_primitives/src/util.rs b/zcash_primitives/src/util.rs index f46e0a2..1fdcde7 100644 --- a/zcash_primitives/src/util.rs +++ b/zcash_primitives/src/util.rs @@ -1,5 +1,6 @@ use blake2b_simd::Params; -use sapling_crypto::jubjub::{JubjubEngine, ToUniform}; + +use crate::jubjub::{JubjubEngine, ToUniform}; pub fn hash_to_scalar(persona: &[u8], a: &[u8], b: &[u8]) -> E::Fs { let mut hasher = Params::new().hash_length(64).personal(persona).to_state(); diff --git a/zcash_primitives/src/zip32.rs b/zcash_primitives/src/zip32.rs index 0c60cf2..44b55f5 100644 --- a/zcash_primitives/src/zip32.rs +++ b/zcash_primitives/src/zip32.rs @@ -4,7 +4,8 @@ use byteorder::{ByteOrder, LittleEndian, ReadBytesExt, WriteBytesExt}; use ff::Field; use fpe::ff1::{BinaryNumeralString, FF1}; use pairing::bls12_381::Bls12; -use sapling_crypto::{ + +use crate::{ jubjub::{fs::Fs, FixedGenerators, JubjubEngine, JubjubParams, ToUniform}, primitives::{Diversifier, PaymentAddress, ViewingKey}, }; diff --git a/zcash_proofs/Cargo.toml b/zcash_proofs/Cargo.toml index fdb0bf8..b7fa659 100644 --- a/zcash_proofs/Cargo.toml +++ b/zcash_proofs/Cargo.toml @@ -13,7 +13,6 @@ directories = { version = "1", optional = true } ff = { path = "../ff" } pairing = { path = "../pairing" } rand_os = "0.2" -sapling-crypto = { path = "../sapling-crypto" } zcash_primitives = { path = "../zcash_primitives" } [dev-dependencies] diff --git a/zcash_proofs/examples/bench.rs b/zcash_proofs/examples/bench.rs index 9adf028..a187ec6 100644 --- a/zcash_proofs/examples/bench.rs +++ b/zcash_proofs/examples/bench.rs @@ -1,14 +1,14 @@ extern crate ff; -extern crate sapling_crypto; extern crate bellman; extern crate pairing; extern crate rand_core; extern crate rand_xorshift; +extern crate zcash_primitives; extern crate zcash_proofs; use ff::Field; use std::time::{Duration, Instant}; -use sapling_crypto::jubjub::{ +use zcash_primitives::jubjub::{ JubjubBls12, edwards, fs, @@ -16,7 +16,7 @@ use sapling_crypto::jubjub::{ use zcash_proofs::circuit::sapling::{ Spend }; -use sapling_crypto::primitives::{ +use zcash_primitives::primitives::{ Diversifier, ProofGenerationKey, ValueCommitment diff --git a/zcash_proofs/src/circuit/ecc.rs b/zcash_proofs/src/circuit/ecc.rs index cb11eb6..593c57d 100644 --- a/zcash_proofs/src/circuit/ecc.rs +++ b/zcash_proofs/src/circuit/ecc.rs @@ -15,7 +15,7 @@ use bellman::gadgets::num::{ Num }; -use sapling_crypto::jubjub::{ +use zcash_primitives::jubjub::{ edwards, JubjubEngine, JubjubParams, @@ -754,14 +754,14 @@ mod test { use rand_xorshift::XorShiftRng; use bellman::gadgets::test::*; - use sapling_crypto::jubjub::{ + use zcash_primitives::jubjub::{ montgomery, edwards, JubjubBls12, JubjubParams, FixedGenerators }; - use sapling_crypto::jubjub::fs::Fs; + use zcash_primitives::jubjub::fs::Fs; use super::{ MontgomeryPoint, diff --git a/zcash_proofs/src/circuit/pedersen_hash.rs b/zcash_proofs/src/circuit/pedersen_hash.rs index 30a948f..0b67597 100644 --- a/zcash_proofs/src/circuit/pedersen_hash.rs +++ b/zcash_proofs/src/circuit/pedersen_hash.rs @@ -3,12 +3,12 @@ use super::ecc::{ EdwardsPoint }; use bellman::gadgets::boolean::Boolean; -use sapling_crypto::jubjub::*; +use zcash_primitives::jubjub::*; use bellman::{ ConstraintSystem, SynthesisError }; use bellman::gadgets::lookup::*; -pub use sapling_crypto::pedersen_hash::Personalization; +pub use zcash_primitives::pedersen_hash::Personalization; fn get_constant_bools(person: &Personalization) -> Vec { person.get_bits() @@ -112,7 +112,7 @@ mod test { use super::*; use bellman::gadgets::test::*; use bellman::gadgets::boolean::{Boolean, AllocatedBit}; - use sapling_crypto::pedersen_hash; + use zcash_primitives::pedersen_hash; use ff::PrimeField; use pairing::bls12_381::{Bls12, Fr}; use rand_core::{RngCore, SeedableRng}; diff --git a/zcash_proofs/src/circuit/sapling.rs b/zcash_proofs/src/circuit/sapling.rs index e381240..1349c8c 100644 --- a/zcash_proofs/src/circuit/sapling.rs +++ b/zcash_proofs/src/circuit/sapling.rs @@ -6,14 +6,14 @@ use bellman::{ Circuit }; -use sapling_crypto::jubjub::{ +use zcash_primitives::jubjub::{ JubjubEngine, FixedGenerators }; -use sapling_crypto::constants; +use zcash_primitives::constants; -use sapling_crypto::primitives::{ +use zcash_primitives::primitives::{ ValueCommitment, ProofGenerationKey, PaymentAddress @@ -603,7 +603,7 @@ fn test_input_circuit_with_bls12_381() { use pairing::bls12_381::*; use rand_core::{RngCore, SeedableRng}; use rand_xorshift::XorShiftRng; - use sapling_crypto::{ + use zcash_primitives::{ jubjub::{JubjubBls12, fs, edwards}, pedersen_hash, primitives::{Diversifier, Note, ProofGenerationKey}, @@ -747,7 +747,7 @@ fn test_output_circuit_with_bls12_381() { use pairing::bls12_381::*; use rand_core::{RngCore, SeedableRng}; use rand_xorshift::XorShiftRng; - use sapling_crypto::{ + use zcash_primitives::{ jubjub::{JubjubBls12, fs, edwards}, primitives::{Diversifier, ProofGenerationKey}, }; diff --git a/zcash_proofs/src/lib.rs b/zcash_proofs/src/lib.rs index 2a3c8f2..3851481 100644 --- a/zcash_proofs/src/lib.rs +++ b/zcash_proofs/src/lib.rs @@ -4,7 +4,6 @@ extern crate byteorder; extern crate ff; extern crate pairing; extern crate rand_os; -extern crate sapling_crypto; extern crate zcash_primitives; #[cfg(feature = "local-prover")] diff --git a/zcash_proofs/src/prover.rs b/zcash_proofs/src/prover.rs index c59ba62..1c1a972 100644 --- a/zcash_proofs/src/prover.rs +++ b/zcash_proofs/src/prover.rs @@ -3,7 +3,7 @@ use bellman::groth16::{Parameters, PreparedVerifyingKey}; use directories::BaseDirs; use pairing::bls12_381::{Bls12, Fr}; -use sapling_crypto::{ +use zcash_primitives::{ jubjub::{edwards, fs::Fs, Unknown}, primitives::{Diversifier, PaymentAddress, ProofGenerationKey}, }; diff --git a/zcash_proofs/src/sapling/mod.rs b/zcash_proofs/src/sapling/mod.rs index 98c4ba3..9aa62f1 100644 --- a/zcash_proofs/src/sapling/mod.rs +++ b/zcash_proofs/src/sapling/mod.rs @@ -1,5 +1,5 @@ use pairing::bls12_381::Bls12; -use sapling_crypto::jubjub::{ +use zcash_primitives::jubjub::{ edwards, fs::FsRepr, FixedGenerators, JubjubBls12, JubjubParams, Unknown, }; use zcash_primitives::transaction::components::Amount; diff --git a/zcash_proofs/src/sapling/prover.rs b/zcash_proofs/src/sapling/prover.rs index 7ca8bce..e914171 100644 --- a/zcash_proofs/src/sapling/prover.rs +++ b/zcash_proofs/src/sapling/prover.rs @@ -7,7 +7,7 @@ use bellman::{ use ff::Field; use pairing::bls12_381::{Bls12, Fr}; use rand_os::OsRng; -use sapling_crypto::{ +use zcash_primitives::{ jubjub::{edwards, fs::Fs, FixedGenerators, JubjubBls12, Unknown}, primitives::{Diversifier, Note, PaymentAddress, ProofGenerationKey, ValueCommitment}, }; diff --git a/zcash_proofs/src/sapling/verifier.rs b/zcash_proofs/src/sapling/verifier.rs index 01cba0c..0801023 100644 --- a/zcash_proofs/src/sapling/verifier.rs +++ b/zcash_proofs/src/sapling/verifier.rs @@ -4,7 +4,7 @@ use bellman::{ }; use ff::Field; use pairing::bls12_381::{Bls12, Fr}; -use sapling_crypto::jubjub::{edwards, FixedGenerators, JubjubBls12, Unknown}; +use zcash_primitives::jubjub::{edwards, FixedGenerators, JubjubBls12, Unknown}; use zcash_primitives::{ redjubjub::{PublicKey, Signature}, transaction::components::Amount, From 1b865ecfdf3d6743fa2e044b77f273db0e28cb9d Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 6 Aug 2019 10:52:04 +0100 Subject: [PATCH 6/6] Remove sapling-crypto --- Cargo.lock | 17 --- Cargo.toml | 1 - sapling-crypto/.gitignore | 3 - sapling-crypto/COPYRIGHT | 14 --- sapling-crypto/Cargo.toml | 27 ----- sapling-crypto/LICENSE-APACHE | 201 ---------------------------------- sapling-crypto/LICENSE-MIT | 23 ---- sapling-crypto/README.md | 23 ---- sapling-crypto/src/lib.rs | 18 --- 9 files changed, 327 deletions(-) delete mode 100644 sapling-crypto/.gitignore delete mode 100644 sapling-crypto/COPYRIGHT delete mode 100644 sapling-crypto/Cargo.toml delete mode 100644 sapling-crypto/LICENSE-APACHE delete mode 100644 sapling-crypto/LICENSE-MIT delete mode 100644 sapling-crypto/README.md delete mode 100644 sapling-crypto/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index ef4f552..d6f658a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -460,23 +460,6 @@ dependencies = [ "rand_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "sapling-crypto" -version = "0.0.1" -dependencies = [ - "bellman 0.1.0", - "blake2b_simd 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", - "blake2s_simd 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", - "ff 0.4.0", - "hex-literal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "pairing 0.14.2", - "rand_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_xorshift 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "sha2" version = "0.8.0" diff --git a/Cargo.toml b/Cargo.toml index c5e2257..69639cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,6 @@ members = [ "group", "librustzcash", "pairing", - "sapling-crypto", "zcash_client_backend", "zcash_primitives", "zcash_proofs", diff --git a/sapling-crypto/.gitignore b/sapling-crypto/.gitignore deleted file mode 100644 index 6aa1064..0000000 --- a/sapling-crypto/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/target/ -**/*.rs.bk -Cargo.lock diff --git a/sapling-crypto/COPYRIGHT b/sapling-crypto/COPYRIGHT deleted file mode 100644 index f2c6a3b..0000000 --- a/sapling-crypto/COPYRIGHT +++ /dev/null @@ -1,14 +0,0 @@ -Copyrights in the "sapling-crypto" library are retained by their contributors. No -copyright assignment is required to contribute to the "sapling-crypto" library. - -The "sapling-crypto" library is licensed under either of - - * Apache License, Version 2.0, (see ./LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) - * MIT license (see ./LICENSE-MIT or http://opensource.org/licenses/MIT) - -at your option. - -Unless you explicitly state otherwise, any contribution intentionally -submitted for inclusion in the work by you, as defined in the Apache-2.0 -license, shall be dual licensed as above, without any additional terms or -conditions. diff --git a/sapling-crypto/Cargo.toml b/sapling-crypto/Cargo.toml deleted file mode 100644 index c3aedd3..0000000 --- a/sapling-crypto/Cargo.toml +++ /dev/null @@ -1,27 +0,0 @@ -[package] -authors = ["Sean Bowe "] -description = "Cryptographic library for Zcash Sapling" -documentation = "https://github.com/zcash-hackworks/sapling" -homepage = "https://github.com/zcash-hackworks/sapling" -license = "MIT/Apache-2.0" -name = "sapling-crypto" -repository = "https://github.com/zcash-hackworks/sapling" -version = "0.0.1" - -[dependencies.pairing] -path = "../pairing" -features = ["expose-arith"] - -[dependencies] -bellman = { path = "../bellman" } -blake2b_simd = "0.5" -blake2s_simd = "0.5" -ff = { path = "../ff" } -rand_core = "0.5" -digest = "0.8" -byteorder = "1" - -[dev-dependencies] -hex-literal = "0.1" -rand_xorshift = "0.2" -sha2 = "0.8" diff --git a/sapling-crypto/LICENSE-APACHE b/sapling-crypto/LICENSE-APACHE deleted file mode 100644 index 16fe87b..0000000 --- a/sapling-crypto/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/sapling-crypto/LICENSE-MIT b/sapling-crypto/LICENSE-MIT deleted file mode 100644 index 31aa793..0000000 --- a/sapling-crypto/LICENSE-MIT +++ /dev/null @@ -1,23 +0,0 @@ -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/sapling-crypto/README.md b/sapling-crypto/README.md deleted file mode 100644 index f5d3bce..0000000 --- a/sapling-crypto/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# sapling-crypto - -This repository contains a (work-in-progress) implementation of Zcash's "Sapling" cryptography. - -## Security Warnings - -This library is currently under development and has not been reviewed. - -## License - -Licensed under either of - - * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) - * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) - -at your option. - -### Contribution - -Unless you explicitly state otherwise, any contribution intentionally -submitted for inclusion in the work by you, as defined in the Apache-2.0 -license, shall be dual licensed as above, without any additional terms or -conditions. diff --git a/sapling-crypto/src/lib.rs b/sapling-crypto/src/lib.rs deleted file mode 100644 index af5dbb1..0000000 --- a/sapling-crypto/src/lib.rs +++ /dev/null @@ -1,18 +0,0 @@ -extern crate pairing; -extern crate bellman; -extern crate blake2b_simd; -extern crate blake2s_simd; -extern crate digest; -extern crate ff; -extern crate rand_core; -extern crate byteorder; - -#[cfg(test)] -#[macro_use] -extern crate hex_literal; - -#[cfg(test)] -extern crate rand_xorshift; - -#[cfg(test)] -extern crate sha2;