zebra/zebra-chain/src/primitives/zcash_note_encryption.rs

58 lines
2.0 KiB
Rust
Raw Normal View History

//! Contains code that interfaces with the zcash_note_encryption crate from
//! librustzcash.
use crate::{
block::Height,
parameters::{Network, NetworkUpgrade},
primitives::zcash_primitives::convert_tx_to_librustzcash,
transaction::Transaction,
};
/// Returns true if all Sapling or Orchard outputs, if any, decrypt successfully with
/// an all-zeroes outgoing viewing key.
///
/// # Panics
///
/// If passed a network/height without matching consensus branch ID (pre-Overwinter),
/// since `librustzcash` won't be able to parse it.
pub fn decrypts_successfully(transaction: &Transaction, network: Network, height: Height) -> bool {
let network_upgrade = NetworkUpgrade::current(network, height);
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();
change(nu5): use new V5 transaction script verification API (#3799) * update librustzcash; adapt to new API * add ticket reference for removing zcash_proofs duplicated dependencies * update to new zcash_script V5 API * use zp_tx shorthand * update to Zcash 4.7.0 dependencies * update protocol versions * feat(rpc): Implement `getblockchaininfo` RPC method (#3891) * Implement `getblockchaininfo` RPC method * add a test for `get_blockchain_info` * fix tohex/fromhex * move comment * Update lightwalletd acceptance test for getblockchaininfo RPC (#3914) * change(rpc): Return getblockchaininfo network upgrades in height order (#3915) * Update lightwalletd acceptance test for getblockchaininfo RPC * Update some doc comments for network upgrades * List network upgrades in order in the getblockchaininfo RPC Also: - Use a constant for the "missing consensus branch ID" RPC value - Simplify fetching consensus branch IDs - Make RPC type derives consistent - Update RPC type documentation * Make RPC type derives consistent * Fix a confusing test comment * get hashand height at the same time * fix estimated_height * fix lint * add extra check Co-authored-by: Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com> * fix typo Co-authored-by: Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com> * split test Co-authored-by: Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com> * fix(rpc): ignore an expected error in the RPC acceptance tests (#3961) * Add ignored regexes to test command failure regex methods * Ignore empty chain error in getblockchaininfo We expect this error when zebrad starts up with an empty state. Co-authored-by: teor <teor@riseup.net> Co-authored-by: Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * Make sync error logs more user-friendly (#3944) - use info level, there is nothing the user needs to do, particularly for a single error - explain that the errors are temporary - hide backtraces, because they look like crashes * Update test.patch.yml with lightwalletd job (#3970) * Update test.patch.yml with lightwalletd job * Remove a workflow condition that will always be false In general, patch workflows need the opposite conditions to the original workflow. But in this case, we know the result of the condition will always be true, so we can just delete it. Co-authored-by: teor <teor@riseup.net> * fix(doc): Fix bugs in the lightwalletd database design (#3964) * Re-order column families in design in dependency order * Minor RFC design tweaks and fixes Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * Repoint zebra image links to our new zfnd.org site for now (#3949) * Repoint zebra image links to our new zfnd.org site for now * Remove images/ Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * Fix typos (#3956) Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: teor <teor@riseup.net> * bump database version to trigger testnet rollback * reduce minimum protocol version for now (will be changed later) * update dependencies * Apply suggestions from code review Co-authored-by: teor <teor@riseup.net> * update versions to match zcash 4.7.0 * deny.toml: update 'darling' Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com> Co-authored-by: teor <teor@riseup.net> Co-authored-by: Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Deirdre Connolly <durumcrustulum@gmail.com> Co-authored-by: Dimitris Apostolou <dimitris.apostolou@icloud.com>
2022-04-18 17:14:16 -07:00
let null_sapling_ovk = zcash_primitives::keys::OutgoingViewingKey([0u8; 32]);
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(
&<zcash_primitives::consensus::Network>::from(network),
alt_height,
&null_sapling_ovk,
output,
);
if recovery.is_none() {
return false;
}
}
}
if let Some(bundle) = alt_tx.orchard_bundle() {
for act in bundle.actions() {
if zcash_note_encryption::try_output_recovery_with_ovk(
&orchard::note_encryption::OrchardDomain::for_action(act),
&orchard::keys::OutgoingViewingKey::from([0u8; 32]),
act,
act.cv_net(),
&act.encrypted_note().out_ciphertext,
)
.is_none()
{
return false;
}
}
}
true
}