diff --git a/Cargo.lock b/Cargo.lock index e393f2aad2d..df4b6a84a89 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5825,7 +5825,6 @@ dependencies = [ "ff", "fpe", "group", - "hdwallet", "hex", "incrementalmerkletree", "jubjub", @@ -5835,8 +5834,6 @@ dependencies = [ "orchard 0.6.0", "rand 0.8.5", "rand_core 0.6.4", - "ripemd", - "secp256k1", "sha2", "subtle", "zcash_address", @@ -6012,7 +6009,7 @@ dependencies = [ "jubjub", "lazy_static", "num-integer", - "orchard 0.6.0", + "orchard 0.7.1", "primitive-types", "proptest", "proptest-derive", @@ -6023,6 +6020,7 @@ dependencies = [ "reddsa", "redjubjub", "ripemd", + "sapling-crypto", "secp256k1", "serde", "serde-big-array", @@ -6042,7 +6040,7 @@ dependencies = [ "zcash_encoding", "zcash_history", "zcash_note_encryption", - "zcash_primitives 0.13.0", + "zcash_primitives 0.14.0", "zcash_protocol", "zebra-test", ] diff --git a/zebra-chain/Cargo.toml b/zebra-chain/Cargo.toml index 6deeff82e12..4a473669395 100644 --- a/zebra-chain/Cargo.toml +++ b/zebra-chain/Cargo.toml @@ -93,11 +93,12 @@ x25519-dalek = { version = "2.0.1", features = ["serde"] } # ECC deps halo2 = { package = "halo2_proofs", version = "0.3.0" } -orchard = "0.6.0" +orchard = "0.7.0" zcash_encoding = "0.2.0" zcash_history = "0.4.0" zcash_note_encryption = "0.4.0" -zcash_primitives = { version = "0.13.0", features = ["transparent-inputs"] } +zcash_primitives = { version = "0.14.0", features = ["transparent-inputs"] } +sapling = { package = "sapling-crypto", version = "0.1" } zcash_protocol = { version = "0.1.1" } zcash_address = { version = "0.3.2" } diff --git a/zebra-chain/src/parameters/network_upgrade.rs b/zebra-chain/src/parameters/network_upgrade.rs index 1cd2be65c38..3c6a0544f32 100644 --- a/zebra-chain/src/parameters/network_upgrade.rs +++ b/zebra-chain/src/parameters/network_upgrade.rs @@ -30,7 +30,7 @@ pub const NETWORK_UPGRADES_IN_ORDER: [NetworkUpgrade; 8] = [ /// /// Network upgrades can change the Zcash network protocol or consensus rules in /// incompatible ways. -#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] +#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, Ord, PartialOrd)] #[cfg_attr(any(test, feature = "proptest-impl"), derive(Arbitrary))] pub enum NetworkUpgrade { /// The Zcash protocol for a Genesis block. diff --git a/zebra-chain/src/primitives/address.rs b/zebra-chain/src/primitives/address.rs index 86d524b8dba..f076c0c3322 100644 --- a/zebra-chain/src/primitives/address.rs +++ b/zebra-chain/src/primitives/address.rs @@ -3,7 +3,6 @@ //! Usage: use zcash_address::unified::{self, Container}; -use zcash_primitives::sapling; use crate::{parameters::NetworkKind, transparent, BoxError}; diff --git a/zebra-chain/src/primitives/viewing_key/sapling.rs b/zebra-chain/src/primitives/viewing_key/sapling.rs index e8d423a7fc0..3e483def126 100644 --- a/zebra-chain/src/primitives/viewing_key/sapling.rs +++ b/zebra-chain/src/primitives/viewing_key/sapling.rs @@ -1,11 +1,11 @@ //! Defines types and implements methods for parsing Sapling viewing keys and converting them to `zebra-chain` types -use zcash_client_backend::encoding::decode_extended_full_viewing_key; -use zcash_primitives::{ - constants::*, - sapling::keys::{FullViewingKey as SaplingFvk, SaplingIvk}, - zip32::DiversifiableFullViewingKey as SaplingDfvk, +use sapling::keys::{FullViewingKey as SaplingFvk, SaplingIvk}; +use zcash_client_backend::{ + encoding::decode_extended_full_viewing_key, + keys::sapling::DiversifiableFullViewingKey as SaplingDfvk, }; +use zcash_primitives::constants::*; use crate::parameters::Network; diff --git a/zebra-chain/src/primitives/zcash_note_encryption.rs b/zebra-chain/src/primitives/zcash_note_encryption.rs index f8e47fbad47..06a43a70f21 100644 --- a/zebra-chain/src/primitives/zcash_note_encryption.rs +++ b/zebra-chain/src/primitives/zcash_note_encryption.rs @@ -20,16 +20,20 @@ pub fn decrypts_successfully(transaction: &Transaction, network: &Network, heigh let alt_tx = convert_tx_to_librustzcash(transaction, network_upgrade) .expect("zcash_primitives and Zebra transaction formats must be compatible"); - let alt_height = height.0.into(); - let null_sapling_ovk = zcash_primitives::keys::OutgoingViewingKey([0u8; 32]); + let null_sapling_ovk = sapling::keys::OutgoingViewingKey([0u8; 32]); + + let zip_212_enforcement = if network_upgrade >= NetworkUpgrade::Canopy { + sapling::note_encryption::Zip212Enforcement::On + } else { + sapling::note_encryption::Zip212Enforcement::Off + }; if let Some(bundle) = alt_tx.sapling_bundle() { for output in bundle.shielded_outputs().iter() { - let recovery = zcash_primitives::sapling::note_encryption::try_sapling_output_recovery( - network, - alt_height, + let recovery = sapling::note_encryption::try_sapling_output_recovery( &null_sapling_ovk, output, + zip_212_enforcement, ); if recovery.is_none() { return false; diff --git a/zebra-chain/src/primitives/zcash_primitives.rs b/zebra-chain/src/primitives/zcash_primitives.rs index 564afab095e..2e7aa339639 100644 --- a/zebra-chain/src/primitives/zcash_primitives.rs +++ b/zebra-chain/src/primitives/zcash_primitives.rs @@ -29,14 +29,14 @@ impl zp_tx::components::transparent::Authorization for TransparentAuth<'_> { // In this block we convert our Output to a librustzcash to TxOut. // (We could do the serialize/deserialize route but it's simple enough to convert manually) impl zp_tx::sighash::TransparentAuthorizingContext for TransparentAuth<'_> { - fn input_amounts(&self) -> Vec { + fn input_amounts(&self) -> Vec { self.all_prev_outputs .iter() .map(|prevout| { - zp_tx::components::amount::Amount::from_nonnegative_i64_le_bytes( - prevout.value.to_bytes(), - ) - .expect("will not fail since it was previously validated") + prevout + .value + .try_into() + .expect("will not fail since it was previously validated") }) .collect() } @@ -83,39 +83,31 @@ impl<'a> struct IdentityMap; -impl - zp_tx::components::sapling::MapAuth< - zp_tx::components::sapling::Authorized, - zp_tx::components::sapling::Authorized, - > for IdentityMap +impl zp_tx::components::sapling::MapAuth + for IdentityMap { fn map_spend_proof( - &self, - p: ::SpendProof, - ) -> ::SpendProof - { + &mut self, + p: ::SpendProof, + ) -> ::SpendProof { p } fn map_output_proof( - &self, - p: ::OutputProof, - ) -> ::OutputProof - { + &mut self, + p: ::OutputProof, + ) -> ::OutputProof { p } fn map_auth_sig( - &self, - s: ::AuthSig, - ) -> ::AuthSig{ + &mut self, + s: ::AuthSig, + ) -> ::AuthSig { s } - fn map_authorization( - &self, - a: zp_tx::components::sapling::Authorized, - ) -> zp_tx::components::sapling::Authorized { + fn map_authorization(&mut self, a: sapling::bundle::Authorized) -> sapling::bundle::Authorized { a } } @@ -141,7 +133,7 @@ struct PrecomputedAuth<'a> { impl<'a> zp_tx::Authorization for PrecomputedAuth<'a> { type TransparentAuth = TransparentAuth<'a>; - type SaplingAuth = zp_tx::components::sapling::Authorized; + type SaplingAuth = sapling::bundle::Authorized; type OrchardAuth = orchard::bundle::Authorized; } @@ -213,12 +205,12 @@ impl TryFrom for zp_tx::components::TxOut { } } -/// Convert a Zebra Amount into a librustzcash one. -impl TryFrom> for zp_tx::components::Amount { +/// Convert a Zebra non-negative Amount into a librustzcash one. +impl TryFrom> for zp_tx::components::amount::NonNegativeAmount { type Error = (); fn try_from(amount: Amount) -> Result { - zp_tx::components::Amount::from_u64(amount.into()) + zp_tx::components::amount::NonNegativeAmount::from_nonnegative_i64(amount.into()) } } @@ -327,10 +319,10 @@ pub(crate) fn transparent_output_address( let alt_addr = tx_out.recipient_address(); match alt_addr { - Some(zcash_primitives::legacy::TransparentAddress::PublicKey(pub_key_hash)) => Some( + Some(zcash_primitives::legacy::TransparentAddress::PublicKeyHash(pub_key_hash)) => Some( transparent::Address::from_pub_key_hash(network.kind(), pub_key_hash), ), - Some(zcash_primitives::legacy::TransparentAddress::Script(script_hash)) => Some( + Some(zcash_primitives::legacy::TransparentAddress::ScriptHash(script_hash)) => Some( transparent::Address::from_script_hash(network.kind(), script_hash), ), None => None, diff --git a/zebra-chain/src/transaction/serialize.rs b/zebra-chain/src/transaction/serialize.rs index 044db7d5109..2b3eafb8966 100644 --- a/zebra-chain/src/transaction/serialize.rs +++ b/zebra-chain/src/transaction/serialize.rs @@ -21,7 +21,7 @@ use crate::{ }; use super::*; -use sapling::{Output, SharedAnchor, Spend}; +use crate::sapling::{Output, SharedAnchor, Spend}; impl ZcashDeserialize for jubjub::Fq { fn zcash_deserialize(mut reader: R) -> Result { @@ -134,7 +134,7 @@ impl ZcashSerialize for sapling::ShieldedData { let (spend_prefixes, spend_proofs_sigs): (Vec<_>, Vec<_>) = self .spends() .cloned() - .map(sapling::Spend::::into_v5_parts) + .map(Spend::::into_v5_parts) .map(|(prefix, proof, sig)| (prefix, (proof, sig))) .unzip(); let (spend_proofs, spend_sigs) = spend_proofs_sigs.into_iter().unzip();