Move Jubjub, Pedersen hash and primitives into zcash_primitives

This commit is contained in:
Jack Grigg 2019-08-06 10:46:40 +01:00
parent b8af749b40
commit 5fb9b86ba0
No known key found for this signature in database
GPG Key ID: 9E8255172BBF9898
42 changed files with 99 additions and 94 deletions

8
Cargo.lock generated
View File

@ -57,7 +57,7 @@ name = "bellman"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"bit-vec 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "crossbeam 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"ff 0.4.0", "ff 0.4.0",
@ -313,7 +313,6 @@ dependencies = [
"pairing 0.14.2", "pairing 0.14.2",
"rand_core 0.5.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_os 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"sapling-crypto 0.0.1",
"zcash_primitives 0.0.0", "zcash_primitives 0.0.0",
"zcash_proofs 0.0.0", "zcash_proofs 0.0.0",
] ]
@ -536,7 +535,6 @@ dependencies = [
"pairing 0.14.2", "pairing 0.14.2",
"rand_core 0.5.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)", "rand_xorshift 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sapling-crypto 0.0.1",
"zcash_primitives 0.0.0", "zcash_primitives 0.0.0",
] ]
@ -546,18 +544,19 @@ version = "0.0.0"
dependencies = [ dependencies = [
"aes 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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)", "crypto_api_chachapoly 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"ff 0.4.0", "ff 0.4.0",
"fpe 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "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 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)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pairing 0.14.2", "pairing 0.14.2",
"rand 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "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_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_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)", "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)", "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_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_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)", "rand_xorshift 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sapling-crypto 0.0.1",
"zcash_primitives 0.0.0", "zcash_primitives 0.0.0",
] ]

View File

@ -24,6 +24,5 @@ lazy_static = "1"
byteorder = "1" byteorder = "1"
rand_core = "0.5" rand_core = "0.5"
rand_os = "0.2" rand_os = "0.2"
sapling-crypto = { path = "../sapling-crypto" }
zcash_primitives = { path = "../zcash_primitives" } zcash_primitives = { path = "../zcash_primitives" }
zcash_proofs = { path = "../zcash_proofs" } zcash_proofs = { path = "../zcash_proofs" }

View File

@ -7,7 +7,6 @@ extern crate libc;
extern crate pairing; extern crate pairing;
extern crate rand_core; extern crate rand_core;
extern crate rand_os; extern crate rand_os;
extern crate sapling_crypto;
extern crate zcash_primitives; extern crate zcash_primitives;
extern crate zcash_proofs; extern crate zcash_proofs;
@ -16,7 +15,7 @@ extern crate lazy_static;
use ff::{PrimeField, PrimeFieldRepr}; use ff::{PrimeField, PrimeFieldRepr};
use pairing::bls12_381::{Bls12, Fr, FrRepr}; use pairing::bls12_381::{Bls12, Fr, FrRepr};
use sapling_crypto::{ use zcash_primitives::{
constants::CRH_IVK_PERSONALIZATION, constants::CRH_IVK_PERSONALIZATION,
jubjub::{ jubjub::{
edwards, edwards,
@ -57,10 +56,12 @@ use std::ffi::OsString;
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
use std::os::windows::ffi::OsStringExt; use std::os::windows::ffi::OsStringExt;
use sapling_crypto::primitives::{ProofGenerationKey, ViewingKey};
use zcash_primitives::{ use zcash_primitives::{
merkle_tree::CommitmentTreeWitness, merkle_tree::CommitmentTreeWitness,
note_encryption::sapling_ka_agree, note_encryption::sapling_ka_agree,
primitives::{
Diversifier, Note, PaymentAddress, ProofGenerationKey, ViewingKey,
},
redjubjub::{self, Signature}, redjubjub::{self, Signature},
sapling::{merkle_hash, spend_sig}, sapling::{merkle_hash, spend_sig},
transaction::components::Amount, transaction::components::Amount,
@ -236,7 +237,7 @@ fn init_zksnark_params(
#[no_mangle] #[no_mangle]
pub extern "system" fn librustzcash_tree_uncommitted(result: *mut [c_uchar; 32]) { pub extern "system" fn librustzcash_tree_uncommitted(result: *mut [c_uchar; 32]) {
let tmp = sapling_crypto::primitives::Note::<Bls12>::uncommitted().into_repr(); let tmp = Note::<Bls12>::uncommitted().into_repr();
// Should be okay, caller is responsible for ensuring the pointer // Should be okay, caller is responsible for ensuring the pointer
// is a valid pointer to 32 bytes that can be mutated. // is a valid pointer to 32 bytes that can be mutated.
@ -341,7 +342,7 @@ pub extern "system" fn librustzcash_crh_ivk(
#[no_mangle] #[no_mangle]
pub extern "system" fn librustzcash_check_diversifier(diversifier: *const [c_uchar; 11]) -> bool { 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::<Bls12>(&JUBJUB).is_some() diversifier.g_d::<Bls12>(&JUBJUB).is_some()
} }
@ -352,7 +353,7 @@ pub extern "system" fn librustzcash_ivk_to_pkd(
result: *mut [c_uchar; 32], result: *mut [c_uchar; 32],
) -> bool { ) -> bool {
let ivk = read_fs(unsafe { &*ivk }); 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::<Bls12>(&JUBJUB) { if let Some(g_d) = diversifier.g_d::<Bls12>(&JUBJUB) {
let pk_d = g_d.mul(ivk, &JUBJUB); let pk_d = g_d.mul(ivk, &JUBJUB);
@ -407,8 +408,8 @@ fn priv_get_note(
pk_d: *const [c_uchar; 32], pk_d: *const [c_uchar; 32],
value: u64, value: u64,
r: *const [c_uchar; 32], r: *const [c_uchar; 32],
) -> Result<sapling_crypto::primitives::Note<Bls12>, ()> { ) -> Result<Note<Bls12>, ()> {
let diversifier = sapling_crypto::primitives::Diversifier(unsafe { *diversifier }); let diversifier = Diversifier(unsafe { *diversifier });
let g_d = match diversifier.g_d::<Bls12>(&JUBJUB) { let g_d = match diversifier.g_d::<Bls12>(&JUBJUB) {
Some(g_d) => g_d, Some(g_d) => g_d,
None => return Err(()), None => return Err(()),
@ -430,7 +431,7 @@ fn priv_get_note(
Err(_) => return Err(()), Err(_) => return Err(()),
}; };
let note = sapling_crypto::primitives::Note { let note = Note {
value, value,
g_d, g_d,
pk_d, pk_d,
@ -539,7 +540,7 @@ pub extern "system" fn librustzcash_sapling_ka_derivepublic(
esk: *const [c_uchar; 32], esk: *const [c_uchar; 32],
result: *mut [c_uchar; 32], result: *mut [c_uchar; 32],
) -> bool { ) -> bool {
let diversifier = sapling_crypto::primitives::Diversifier(unsafe { *diversifier }); let diversifier = Diversifier(unsafe { *diversifier });
// Compute g_d from the diversifier // Compute g_d from the diversifier
let g_d = match diversifier.g_d::<Bls12>(&JUBJUB) { let g_d = match diversifier.g_d::<Bls12>(&JUBJUB) {
@ -940,7 +941,7 @@ pub extern "system" fn librustzcash_sapling_output_proof(
}; };
// Grab the diversifier from the caller. // 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. // Grab pk_d from the caller.
let pk_d = match edwards::Point::<Bls12, Unknown>::read(&(unsafe { &*pk_d })[..], &JUBJUB) { let pk_d = match edwards::Point::<Bls12, Unknown>::read(&(unsafe { &*pk_d })[..], &JUBJUB) {
@ -955,7 +956,7 @@ pub extern "system" fn librustzcash_sapling_output_proof(
}; };
// Construct a payment address // Construct a payment address
let payment_address = sapling_crypto::primitives::PaymentAddress { let payment_address = PaymentAddress {
pk_d: pk_d, pk_d: pk_d,
diversifier: diversifier, diversifier: diversifier,
}; };
@ -1086,7 +1087,7 @@ pub extern "system" fn librustzcash_sapling_spend_proof(
}; };
// Grab the diversifier from the caller // 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 // The caller chooses the note randomness
let rcm = match Fs::from_repr(read_fs(&(unsafe { &*rcm })[..])) { let rcm = match Fs::from_repr(read_fs(&(unsafe { &*rcm })[..])) {

View File

@ -2,8 +2,8 @@ use ff::{PrimeField, PrimeFieldRepr};
use pairing::bls12_381::Bls12; use pairing::bls12_381::Bls12;
use rand_core::RngCore; use rand_core::RngCore;
use rand_os::OsRng; use rand_os::OsRng;
use sapling_crypto::jubjub::{edwards, JubjubBls12}; use zcash_primitives::jubjub::{edwards, JubjubBls12};
use sapling_crypto::primitives::{Diversifier, ViewingKey}; use zcash_primitives::primitives::{Diversifier, ViewingKey};
use { use {
librustzcash_sapling_generate_r, librustzcash_sapling_ka_agree, librustzcash_sapling_generate_r, librustzcash_sapling_ka_agree,

View File

@ -1,6 +1,6 @@
use ff::{PrimeField, PrimeFieldRepr}; use ff::{PrimeField, PrimeFieldRepr};
use pairing::bls12_381::Bls12; use pairing::bls12_381::Bls12;
use sapling_crypto::{ use zcash_primitives::{
jubjub::{fs::FsRepr, FixedGenerators, JubjubEngine, JubjubParams}, jubjub::{fs::FsRepr, FixedGenerators, JubjubEngine, JubjubParams},
primitives::{Diversifier, ProofGenerationKey}, primitives::{Diversifier, ProofGenerationKey},
}; };

View File

@ -1,4 +1,4 @@
use sapling_crypto::jubjub::{FixedGenerators, JubjubParams}; use zcash_primitives::jubjub::{FixedGenerators, JubjubParams};
use super::JUBJUB; use super::JUBJUB;

View File

@ -1,6 +1,6 @@
use ff::{PrimeField, PrimeFieldRepr}; use ff::{PrimeField, PrimeFieldRepr};
use pairing::bls12_381::Bls12; 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 zcash_primitives::redjubjub::{PrivateKey, PublicKey, Signature};
use super::JUBJUB; use super::JUBJUB;

View File

@ -16,9 +16,3 @@ extern crate rand_xorshift;
#[cfg(test)] #[cfg(test)]
extern crate sha2; extern crate sha2;
pub mod jubjub;
pub mod group_hash;
pub mod pedersen_hash;
pub mod primitives;
pub mod constants;

View File

@ -9,7 +9,6 @@ edition = "2018"
[dependencies] [dependencies]
bech32 = "0.7" bech32 = "0.7"
pairing = { path = "../pairing" } pairing = { path = "../pairing" }
sapling-crypto = { path = "../sapling-crypto" }
zcash_primitives = { path = "../zcash_primitives" } zcash_primitives = { path = "../zcash_primitives" }
[dev-dependencies] [dev-dependencies]

View File

@ -5,7 +5,7 @@
use bech32::{self, Error, FromBase32, ToBase32}; use bech32::{self, Error, FromBase32, ToBase32};
use pairing::bls12_381::Bls12; use pairing::bls12_381::Bls12;
use sapling_crypto::{ use zcash_primitives::{
jubjub::edwards, jubjub::edwards,
primitives::{Diversifier, PaymentAddress}, primitives::{Diversifier, PaymentAddress},
}; };
@ -98,15 +98,15 @@ pub fn decode_extended_full_viewing_key(
/// use pairing::bls12_381::Bls12; /// use pairing::bls12_381::Bls12;
/// use rand_core::SeedableRng; /// use rand_core::SeedableRng;
/// use rand_xorshift::XorShiftRng; /// use rand_xorshift::XorShiftRng;
/// use sapling_crypto::{
/// jubjub::edwards,
/// primitives::{Diversifier, PaymentAddress},
/// };
/// use zcash_client_backend::{ /// use zcash_client_backend::{
/// constants::testnet::HRP_SAPLING_PAYMENT_ADDRESS, /// constants::testnet::HRP_SAPLING_PAYMENT_ADDRESS,
/// encoding::encode_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([ /// let rng = &mut XorShiftRng::from_seed([
/// 0x59, 0x62, 0xbe, 0x3d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, /// 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<Bls12>) -> String
/// use pairing::bls12_381::Bls12; /// use pairing::bls12_381::Bls12;
/// use rand_core::SeedableRng; /// use rand_core::SeedableRng;
/// use rand_xorshift::XorShiftRng; /// use rand_xorshift::XorShiftRng;
/// use sapling_crypto::{
/// jubjub::edwards,
/// primitives::{Diversifier, PaymentAddress},
/// };
/// use zcash_client_backend::{ /// use zcash_client_backend::{
/// constants::testnet::HRP_SAPLING_PAYMENT_ADDRESS, /// constants::testnet::HRP_SAPLING_PAYMENT_ADDRESS,
/// encoding::decode_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([ /// let rng = &mut XorShiftRng::from_seed([
/// 0x59, 0x62, 0xbe, 0x3d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, /// 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 pairing::bls12_381::Bls12;
use rand_core::SeedableRng; use rand_core::SeedableRng;
use rand_xorshift::XorShiftRng; use rand_xorshift::XorShiftRng;
use sapling_crypto::{ use zcash_primitives::{
jubjub::edwards, jubjub::edwards,
primitives::{Diversifier, PaymentAddress}, primitives::{Diversifier, PaymentAddress},
}; };

View File

@ -8,6 +8,7 @@ authors = [
[dependencies] [dependencies]
aes = "0.3" aes = "0.3"
blake2b_simd = "0.5" blake2b_simd = "0.5"
blake2s_simd = "0.5"
byteorder = "1" byteorder = "1"
crypto_api_chachapoly = "0.2.1" crypto_api_chachapoly = "0.2.1"
ff = { path = "../ff" } ff = { path = "../ff" }
@ -18,8 +19,8 @@ pairing = { path = "../pairing" }
rand = "0.7" rand = "0.7"
rand_core = "0.5" rand_core = "0.5"
rand_os = "0.2" rand_os = "0.2"
sapling-crypto = { path = "../sapling-crypto" }
sha2 = "0.8" sha2 = "0.8"
[dev-dependencies] [dev-dependencies]
hex-literal = "0.1"
rand_xorshift = "0.2" rand_xorshift = "0.2"

View File

@ -1,20 +1,22 @@
#![feature(test)] #![feature(test)]
extern crate rand; extern crate rand_core;
extern crate rand_os;
extern crate test; extern crate test;
extern crate pairing; 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 pairing::bls12_381::Bls12;
use sapling_crypto::jubjub::JubjubBls12; use zcash_primitives::jubjub::JubjubBls12;
use sapling_crypto::pedersen_hash::{pedersen_hash, Personalization}; use zcash_primitives::pedersen_hash::{pedersen_hash, Personalization};
#[bench] #[bench]
fn bench_pedersen_hash(b: &mut test::Bencher) { fn bench_pedersen_hash(b: &mut test::Bencher) {
let params = JubjubBls12::new(); let params = JubjubBls12::new();
let rng = &mut thread_rng(); let rng = &mut OsRng;
let bits = (0..510).map(|_| bool::rand(rng)).collect::<Vec<_>>(); let bits = (0..510).map(|_| (rng.next_u32() % 2) != 0).collect::<Vec<_>>();
let personalization = Personalization::MerkleTree(31); let personalization = Personalization::MerkleTree(31);
b.iter(|| { b.iter(|| {

View File

@ -4,7 +4,7 @@
use blake2b_simd::{Hash as Blake2bHash, Params as Blake2bParams}; use blake2b_simd::{Hash as Blake2bHash, Params as Blake2bParams};
use ff::{PrimeField, PrimeFieldRepr}; use ff::{PrimeField, PrimeFieldRepr};
use sapling_crypto::{ use crate::{
jubjub::{edwards, FixedGenerators, JubjubEngine, JubjubParams, ToUniform, Unknown}, jubjub::{edwards, FixedGenerators, JubjubEngine, JubjubParams, ToUniform, Unknown},
primitives::{ProofGenerationKey, ViewingKey}, primitives::{ProofGenerationKey, ViewingKey},
}; };
@ -188,7 +188,7 @@ impl<E: JubjubEngine> FullViewingKey<E> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use pairing::bls12_381::Bls12; 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 std::error::Error;
use super::FullViewingKey; use super::FullViewingKey;

View File

@ -3,6 +3,7 @@ extern crate lazy_static;
extern crate aes; extern crate aes;
extern crate blake2b_simd; extern crate blake2b_simd;
extern crate blake2s_simd;
extern crate byteorder; extern crate byteorder;
extern crate crypto_api_chachapoly; extern crate crypto_api_chachapoly;
extern crate ff; extern crate ff;
@ -12,19 +13,25 @@ extern crate pairing;
extern crate rand; extern crate rand;
extern crate rand_core; extern crate rand_core;
extern crate rand_os; extern crate rand_os;
extern crate sapling_crypto;
extern crate sha2; extern crate sha2;
#[cfg(test)]
#[macro_use]
extern crate hex_literal;
#[cfg(test)] #[cfg(test)]
extern crate rand_xorshift; extern crate rand_xorshift;
use sapling_crypto::jubjub::JubjubBls12;
pub mod block; pub mod block;
pub mod constants;
pub mod group_hash;
pub mod jubjub;
pub mod keys; pub mod keys;
pub mod legacy; pub mod legacy;
pub mod merkle_tree; pub mod merkle_tree;
pub mod note_encryption; pub mod note_encryption;
pub mod pedersen_hash;
pub mod primitives;
pub mod prover; pub mod prover;
pub mod redjubjub; pub mod redjubjub;
pub mod sapling; pub mod sapling;
@ -36,6 +43,8 @@ pub mod zip32;
#[cfg(test)] #[cfg(test)]
mod test_vectors; mod test_vectors;
use jubjub::JubjubBls12;
lazy_static! { lazy_static! {
pub static ref JUBJUB: JubjubBls12 = { JubjubBls12::new() }; pub static ref JUBJUB: JubjubBls12 = { JubjubBls12::new() };
} }

View File

@ -6,7 +6,7 @@ use crypto_api_chachapoly::{ChaCha20Ietf, ChachaPolyIetf};
use ff::{PrimeField, PrimeFieldRepr}; use ff::{PrimeField, PrimeFieldRepr};
use pairing::bls12_381::{Bls12, Fr}; use pairing::bls12_381::{Bls12, Fr};
use rand_core::{CryptoRng, RngCore}; use rand_core::{CryptoRng, RngCore};
use sapling_crypto::{ use crate::{
jubjub::{ jubjub::{
edwards, edwards,
fs::{Fs, FsRepr}, fs::{Fs, FsRepr},
@ -211,18 +211,16 @@ fn prf_ock(
/// extern crate ff; /// extern crate ff;
/// extern crate pairing; /// extern crate pairing;
/// extern crate rand_os; /// extern crate rand_os;
/// extern crate sapling_crypto; /// extern crate zcash_primitives;
/// ///
/// use ff::Field; /// use ff::Field;
/// use pairing::bls12_381::Bls12; /// use pairing::bls12_381::Bls12;
/// use rand_os::OsRng; /// use rand_os::OsRng;
/// use sapling_crypto::{
/// jubjub::fs::Fs,
/// primitives::{Diversifier, PaymentAddress, ValueCommitment},
/// };
/// use zcash_primitives::{ /// use zcash_primitives::{
/// jubjub::fs::Fs,
/// keys::OutgoingViewingKey, /// keys::OutgoingViewingKey,
/// note_encryption::{Memo, SaplingNoteEncryption}, /// note_encryption::{Memo, SaplingNoteEncryption},
/// primitives::{Diversifier, PaymentAddress, ValueCommitment},
/// JUBJUB, /// JUBJUB,
/// }; /// };
/// ///
@ -551,7 +549,7 @@ mod tests {
use pairing::bls12_381::{Bls12, Fr, FrRepr}; use pairing::bls12_381::{Bls12, Fr, FrRepr};
use rand_core::{CryptoRng, RngCore}; use rand_core::{CryptoRng, RngCore};
use rand_os::OsRng; use rand_os::OsRng;
use sapling_crypto::{ use crate::{
jubjub::{ jubjub::{
edwards, edwards,
fs::{Fs, FsRepr}, fs::{Fs, FsRepr},

View File

@ -1,7 +1,7 @@
//! Abstractions over the proving system and parameters. //! Abstractions over the proving system and parameters.
use pairing::bls12_381::{Bls12, Fr}; use pairing::bls12_381::{Bls12, Fr};
use sapling_crypto::{ use crate::{
jubjub::{edwards, fs::Fs, Unknown}, jubjub::{edwards, fs::Fs, Unknown},
primitives::{Diversifier, PaymentAddress, ProofGenerationKey}, primitives::{Diversifier, PaymentAddress, ProofGenerationKey},
}; };
@ -75,7 +75,8 @@ pub(crate) mod mock {
use ff::Field; use ff::Field;
use pairing::bls12_381::{Bls12, Fr}; use pairing::bls12_381::{Bls12, Fr};
use rand_os::OsRng; use rand_os::OsRng;
use sapling_crypto::{
use crate::{
jubjub::{edwards, fs::Fs, FixedGenerators, Unknown}, jubjub::{edwards, fs::Fs, FixedGenerators, Unknown},
primitives::{Diversifier, PaymentAddress, ProofGenerationKey, ValueCommitment}, primitives::{Diversifier, PaymentAddress, ProofGenerationKey, ValueCommitment},
}; };

View File

@ -3,7 +3,7 @@
use ff::{Field, PrimeField, PrimeFieldRepr}; use ff::{Field, PrimeField, PrimeFieldRepr};
use rand_core::RngCore; use rand_core::RngCore;
use sapling_crypto::jubjub::{ use crate::jubjub::{
edwards::Point, FixedGenerators, JubjubEngine, JubjubParams, Unknown, edwards::Point, FixedGenerators, JubjubEngine, JubjubParams, Unknown,
}; };
use std::io::{self, Read, Write}; use std::io::{self, Read, Write};
@ -210,7 +210,8 @@ mod tests {
use pairing::bls12_381::Bls12; use pairing::bls12_381::Bls12;
use rand_core::SeedableRng; use rand_core::SeedableRng;
use rand_xorshift::XorShiftRng; use rand_xorshift::XorShiftRng;
use sapling_crypto::jubjub::{edwards, fs::Fs, JubjubBls12};
use crate::jubjub::{edwards, fs::Fs, JubjubBls12};
use super::*; use super::*;

View File

@ -3,7 +3,7 @@
use ff::{BitIterator, PrimeField, PrimeFieldRepr}; use ff::{BitIterator, PrimeField, PrimeFieldRepr};
use pairing::bls12_381::{Bls12, Fr, FrRepr}; use pairing::bls12_381::{Bls12, Fr, FrRepr};
use rand_core::{CryptoRng, RngCore}; use rand_core::{CryptoRng, RngCore};
use sapling_crypto::{ use crate::{
jubjub::{fs::Fs, FixedGenerators, JubjubBls12}, jubjub::{fs::Fs, FixedGenerators, JubjubBls12},
pedersen_hash::{pedersen_hash, Personalization}, pedersen_hash::{pedersen_hash, Personalization},
primitives::Note, primitives::Note,

View File

@ -3,7 +3,7 @@
use ff::Field; use ff::Field;
use pairing::bls12_381::{Bls12, Fr}; use pairing::bls12_381::{Bls12, Fr};
use rand::{rngs::OsRng, seq::SliceRandom, CryptoRng, RngCore}; use rand::{rngs::OsRng, seq::SliceRandom, CryptoRng, RngCore};
use sapling_crypto::{ use crate::{
jubjub::fs::Fs, jubjub::fs::Fs,
primitives::{Diversifier, Note, PaymentAddress}, primitives::{Diversifier, Note, PaymentAddress},
}; };
@ -534,7 +534,8 @@ impl<R: RngCore + CryptoRng> Builder<R> {
mod tests { mod tests {
use ff::{Field, PrimeField}; use ff::{Field, PrimeField};
use rand::rngs::OsRng; use rand::rngs::OsRng;
use sapling_crypto::jubjub::fs::Fs;
use crate::jubjub::fs::Fs;
use super::{Builder, Error}; use super::{Builder, Error};
use crate::{ use crate::{

View File

@ -1,7 +1,7 @@
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use ff::{PrimeField, PrimeFieldRepr}; use ff::{PrimeField, PrimeFieldRepr};
use pairing::bls12_381::{Bls12, Fr, FrRepr}; 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 std::io::{self, Read, Write};
use legacy::Script; use legacy::Script;

View File

@ -1,7 +1,8 @@
use ff::Field; use ff::Field;
use pairing::bls12_381::Bls12; use pairing::bls12_381::Bls12;
use rand_os::OsRng; 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 super::{components::Amount, sighash::signature_hash, Transaction, TransactionData};
use legacy::Script; use legacy::Script;

View File

@ -1,5 +1,6 @@
use blake2b_simd::Params; use blake2b_simd::Params;
use sapling_crypto::jubjub::{JubjubEngine, ToUniform};
use crate::jubjub::{JubjubEngine, ToUniform};
pub fn hash_to_scalar<E: JubjubEngine>(persona: &[u8], a: &[u8], b: &[u8]) -> E::Fs { pub fn hash_to_scalar<E: JubjubEngine>(persona: &[u8], a: &[u8], b: &[u8]) -> E::Fs {
let mut hasher = Params::new().hash_length(64).personal(persona).to_state(); let mut hasher = Params::new().hash_length(64).personal(persona).to_state();

View File

@ -4,7 +4,8 @@ use byteorder::{ByteOrder, LittleEndian, ReadBytesExt, WriteBytesExt};
use ff::Field; use ff::Field;
use fpe::ff1::{BinaryNumeralString, FF1}; use fpe::ff1::{BinaryNumeralString, FF1};
use pairing::bls12_381::Bls12; use pairing::bls12_381::Bls12;
use sapling_crypto::{
use crate::{
jubjub::{fs::Fs, FixedGenerators, JubjubEngine, JubjubParams, ToUniform}, jubjub::{fs::Fs, FixedGenerators, JubjubEngine, JubjubParams, ToUniform},
primitives::{Diversifier, PaymentAddress, ViewingKey}, primitives::{Diversifier, PaymentAddress, ViewingKey},
}; };

View File

@ -13,7 +13,6 @@ directories = { version = "1", optional = true }
ff = { path = "../ff" } ff = { path = "../ff" }
pairing = { path = "../pairing" } pairing = { path = "../pairing" }
rand_os = "0.2" rand_os = "0.2"
sapling-crypto = { path = "../sapling-crypto" }
zcash_primitives = { path = "../zcash_primitives" } zcash_primitives = { path = "../zcash_primitives" }
[dev-dependencies] [dev-dependencies]

View File

@ -1,14 +1,14 @@
extern crate ff; extern crate ff;
extern crate sapling_crypto;
extern crate bellman; extern crate bellman;
extern crate pairing; extern crate pairing;
extern crate rand_core; extern crate rand_core;
extern crate rand_xorshift; extern crate rand_xorshift;
extern crate zcash_primitives;
extern crate zcash_proofs; extern crate zcash_proofs;
use ff::Field; use ff::Field;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use sapling_crypto::jubjub::{ use zcash_primitives::jubjub::{
JubjubBls12, JubjubBls12,
edwards, edwards,
fs, fs,
@ -16,7 +16,7 @@ use sapling_crypto::jubjub::{
use zcash_proofs::circuit::sapling::{ use zcash_proofs::circuit::sapling::{
Spend Spend
}; };
use sapling_crypto::primitives::{ use zcash_primitives::primitives::{
Diversifier, Diversifier,
ProofGenerationKey, ProofGenerationKey,
ValueCommitment ValueCommitment

View File

@ -15,7 +15,7 @@ use bellman::gadgets::num::{
Num Num
}; };
use sapling_crypto::jubjub::{ use zcash_primitives::jubjub::{
edwards, edwards,
JubjubEngine, JubjubEngine,
JubjubParams, JubjubParams,
@ -754,14 +754,14 @@ mod test {
use rand_xorshift::XorShiftRng; use rand_xorshift::XorShiftRng;
use bellman::gadgets::test::*; use bellman::gadgets::test::*;
use sapling_crypto::jubjub::{ use zcash_primitives::jubjub::{
montgomery, montgomery,
edwards, edwards,
JubjubBls12, JubjubBls12,
JubjubParams, JubjubParams,
FixedGenerators FixedGenerators
}; };
use sapling_crypto::jubjub::fs::Fs; use zcash_primitives::jubjub::fs::Fs;
use super::{ use super::{
MontgomeryPoint, MontgomeryPoint,

View File

@ -3,12 +3,12 @@ use super::ecc::{
EdwardsPoint EdwardsPoint
}; };
use bellman::gadgets::boolean::Boolean; use bellman::gadgets::boolean::Boolean;
use sapling_crypto::jubjub::*; use zcash_primitives::jubjub::*;
use bellman::{ use bellman::{
ConstraintSystem, SynthesisError ConstraintSystem, SynthesisError
}; };
use bellman::gadgets::lookup::*; 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<Boolean> { fn get_constant_bools(person: &Personalization) -> Vec<Boolean> {
person.get_bits() person.get_bits()
@ -112,7 +112,7 @@ mod test {
use super::*; use super::*;
use bellman::gadgets::test::*; use bellman::gadgets::test::*;
use bellman::gadgets::boolean::{Boolean, AllocatedBit}; use bellman::gadgets::boolean::{Boolean, AllocatedBit};
use sapling_crypto::pedersen_hash; use zcash_primitives::pedersen_hash;
use ff::PrimeField; use ff::PrimeField;
use pairing::bls12_381::{Bls12, Fr}; use pairing::bls12_381::{Bls12, Fr};
use rand_core::{RngCore, SeedableRng}; use rand_core::{RngCore, SeedableRng};

View File

@ -6,14 +6,14 @@ use bellman::{
Circuit Circuit
}; };
use sapling_crypto::jubjub::{ use zcash_primitives::jubjub::{
JubjubEngine, JubjubEngine,
FixedGenerators FixedGenerators
}; };
use sapling_crypto::constants; use zcash_primitives::constants;
use sapling_crypto::primitives::{ use zcash_primitives::primitives::{
ValueCommitment, ValueCommitment,
ProofGenerationKey, ProofGenerationKey,
PaymentAddress PaymentAddress
@ -603,7 +603,7 @@ fn test_input_circuit_with_bls12_381() {
use pairing::bls12_381::*; use pairing::bls12_381::*;
use rand_core::{RngCore, SeedableRng}; use rand_core::{RngCore, SeedableRng};
use rand_xorshift::XorShiftRng; use rand_xorshift::XorShiftRng;
use sapling_crypto::{ use zcash_primitives::{
jubjub::{JubjubBls12, fs, edwards}, jubjub::{JubjubBls12, fs, edwards},
pedersen_hash, pedersen_hash,
primitives::{Diversifier, Note, ProofGenerationKey}, primitives::{Diversifier, Note, ProofGenerationKey},
@ -747,7 +747,7 @@ fn test_output_circuit_with_bls12_381() {
use pairing::bls12_381::*; use pairing::bls12_381::*;
use rand_core::{RngCore, SeedableRng}; use rand_core::{RngCore, SeedableRng};
use rand_xorshift::XorShiftRng; use rand_xorshift::XorShiftRng;
use sapling_crypto::{ use zcash_primitives::{
jubjub::{JubjubBls12, fs, edwards}, jubjub::{JubjubBls12, fs, edwards},
primitives::{Diversifier, ProofGenerationKey}, primitives::{Diversifier, ProofGenerationKey},
}; };

View File

@ -4,7 +4,6 @@ extern crate byteorder;
extern crate ff; extern crate ff;
extern crate pairing; extern crate pairing;
extern crate rand_os; extern crate rand_os;
extern crate sapling_crypto;
extern crate zcash_primitives; extern crate zcash_primitives;
#[cfg(feature = "local-prover")] #[cfg(feature = "local-prover")]

View File

@ -3,7 +3,7 @@
use bellman::groth16::{Parameters, PreparedVerifyingKey}; use bellman::groth16::{Parameters, PreparedVerifyingKey};
use directories::BaseDirs; use directories::BaseDirs;
use pairing::bls12_381::{Bls12, Fr}; use pairing::bls12_381::{Bls12, Fr};
use sapling_crypto::{ use zcash_primitives::{
jubjub::{edwards, fs::Fs, Unknown}, jubjub::{edwards, fs::Fs, Unknown},
primitives::{Diversifier, PaymentAddress, ProofGenerationKey}, primitives::{Diversifier, PaymentAddress, ProofGenerationKey},
}; };

View File

@ -1,5 +1,5 @@
use pairing::bls12_381::Bls12; use pairing::bls12_381::Bls12;
use sapling_crypto::jubjub::{ use zcash_primitives::jubjub::{
edwards, fs::FsRepr, FixedGenerators, JubjubBls12, JubjubParams, Unknown, edwards, fs::FsRepr, FixedGenerators, JubjubBls12, JubjubParams, Unknown,
}; };
use zcash_primitives::transaction::components::Amount; use zcash_primitives::transaction::components::Amount;

View File

@ -7,7 +7,7 @@ use bellman::{
use ff::Field; use ff::Field;
use pairing::bls12_381::{Bls12, Fr}; use pairing::bls12_381::{Bls12, Fr};
use rand_os::OsRng; use rand_os::OsRng;
use sapling_crypto::{ use zcash_primitives::{
jubjub::{edwards, fs::Fs, FixedGenerators, JubjubBls12, Unknown}, jubjub::{edwards, fs::Fs, FixedGenerators, JubjubBls12, Unknown},
primitives::{Diversifier, Note, PaymentAddress, ProofGenerationKey, ValueCommitment}, primitives::{Diversifier, Note, PaymentAddress, ProofGenerationKey, ValueCommitment},
}; };

View File

@ -4,7 +4,7 @@ use bellman::{
}; };
use ff::Field; use ff::Field;
use pairing::bls12_381::{Bls12, Fr}; 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::{ use zcash_primitives::{
redjubjub::{PublicKey, Signature}, redjubjub::{PublicKey, Signature},
transaction::components::Amount, transaction::components::Amount,