From 233220ace077fc01d88fb238ccff96b8bb613eee Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Tue, 25 Oct 2022 00:23:50 -0300 Subject: [PATCH] remove dead code from zebra-chain (#5464) Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- zebra-chain/src/block/commitment.rs | 4 ++-- zebra-chain/src/block/error.rs | 2 +- zebra-chain/src/orchard/keys.rs | 22 ------------------ zebra-chain/src/orchard/note.rs | 1 - zebra-chain/src/orchard/note/nullifiers.rs | 1 - .../orchard/tests/vectors/key_components.rs | 1 - zebra-chain/src/primitives/zcash_history.rs | 21 ----------------- .../src/sapling/commitment/test_vectors.rs | 2 -- zebra-chain/src/sapling/keys.rs | 20 ---------------- zebra-chain/src/sapling/note.rs | 1 - zebra-chain/src/sapling/note/nullifiers.rs | 1 - zebra-chain/src/sprout/note.rs | 1 - zebra-chain/src/sprout/note/nullifiers.rs | 2 -- zebra-chain/src/transaction.rs | 23 ------------------- 14 files changed, 3 insertions(+), 99 deletions(-) diff --git a/zebra-chain/src/block/commitment.rs b/zebra-chain/src/block/commitment.rs index f8a9fa12b..f5fc62257 100644 --- a/zebra-chain/src/block/commitment.rs +++ b/zebra-chain/src/block/commitment.rs @@ -125,7 +125,7 @@ impl Commitment { } /// Returns the serialized bytes for this Commitment. - #[allow(dead_code)] + #[cfg(test)] pub(super) fn to_bytes(self) -> [u8; 32] { use Commitment::*; @@ -220,7 +220,7 @@ impl ChainHistoryBlockTxAuthCommitmentHash { /// all possible verification failures enumerates the consensus rules we /// implement, and ensures that we don't reject blocks or transactions /// for a non-enumerated reason. -#[allow(dead_code, missing_docs)] +#[allow(missing_docs)] #[derive(Error, Debug, PartialEq, Eq)] pub enum CommitmentError { #[error( diff --git a/zebra-chain/src/block/error.rs b/zebra-chain/src/block/error.rs index ced7d4911..1981cfe60 100644 --- a/zebra-chain/src/block/error.rs +++ b/zebra-chain/src/block/error.rs @@ -2,7 +2,7 @@ use thiserror::Error; -#[allow(dead_code, missing_docs)] +#[allow(missing_docs)] #[derive(Error, Debug, PartialEq, Eq)] pub enum BlockError { #[error("transaction has wrong consensus branch id for block network upgrade")] diff --git a/zebra-chain/src/orchard/keys.rs b/zebra-chain/src/orchard/keys.rs index 7f1899b03..2ae959733 100644 --- a/zebra-chain/src/orchard/keys.rs +++ b/zebra-chain/src/orchard/keys.rs @@ -2,7 +2,6 @@ //! //! #![allow(clippy::fallible_impl_from)] -#![allow(dead_code)] #[cfg(test)] mod tests; @@ -76,27 +75,6 @@ pub fn prf_expand(sk: [u8; 32], t: Vec<&[u8]>) -> [u8; 64] { *state.finalize().as_array() } -/// Used to derive the outgoing cipher key _ock_ used to encrypt an encrypted -/// output note from an Action. -/// -/// PRF^ock(ovk, cv, cm_x, ephemeralKey) := BLAKE2b-256(“Zcash_Orchardock”, ovk || cv || cm_x || ephemeralKey) -/// -/// -/// -fn prf_ock(ovk: [u8; 32], cv: [u8; 32], cm_x: [u8; 32], ephemeral_key: [u8; 32]) -> [u8; 32] { - let hash = blake2b_simd::Params::new() - .hash_length(32) - .personal(b"Zcash_Orchardock") - .to_state() - .update(&ovk) - .update(&cv) - .update(&cm_x) - .update(&ephemeral_key) - .finalize(); - - hash.as_bytes().try_into().expect("32 byte array") -} - /// Used to derive a diversified base point from a diversifier value. /// /// DiversifyHash^Orchard(d) := {︃ GroupHash^P("z.cash:Orchard-gd",""), if P = 0_P diff --git a/zebra-chain/src/orchard/note.rs b/zebra-chain/src/orchard/note.rs index 3a4787063..811639b13 100644 --- a/zebra-chain/src/orchard/note.rs +++ b/zebra-chain/src/orchard/note.rs @@ -1,7 +1,6 @@ //! Orchard notes #![allow(clippy::unit_arg)] -#![allow(dead_code)] use group::{ff::PrimeField, GroupEncoding}; use halo2::{arithmetic::FieldExt, pasta::pallas}; diff --git a/zebra-chain/src/orchard/note/nullifiers.rs b/zebra-chain/src/orchard/note/nullifiers.rs index 5f05b5366..d739fda0e 100644 --- a/zebra-chain/src/orchard/note/nullifiers.rs +++ b/zebra-chain/src/orchard/note/nullifiers.rs @@ -1,5 +1,4 @@ #![allow(clippy::unit_arg)] -#![allow(dead_code)] use std::{ convert::TryFrom, diff --git a/zebra-chain/src/orchard/tests/vectors/key_components.rs b/zebra-chain/src/orchard/tests/vectors/key_components.rs index c7a2606b0..9945f6fb4 100644 --- a/zebra-chain/src/orchard/tests/vectors/key_components.rs +++ b/zebra-chain/src/orchard/tests/vectors/key_components.rs @@ -4,7 +4,6 @@ //! Produced by #![allow(dead_code)] - pub struct TestVector { pub(crate) sk: [u8; 32], pub(crate) ask: [u8; 32], diff --git a/zebra-chain/src/primitives/zcash_history.rs b/zebra-chain/src/primitives/zcash_history.rs index 3d20a0426..82cd4ff11 100644 --- a/zebra-chain/src/primitives/zcash_history.rs +++ b/zebra-chain/src/primitives/zcash_history.rs @@ -2,7 +2,6 @@ //! librustzcash. // TODO: remove after this module gets to be used -#![allow(dead_code)] #![allow(missing_docs)] mod tests; @@ -210,26 +209,6 @@ impl Tree { } Ok(new_nodes) } - - /// Append multiple blocks to the tree. - fn append_leaf_iter( - &mut self, - vals: impl Iterator, sapling::tree::Root, orchard::tree::Root)>, - ) -> Result, zcash_history::Error> { - let mut new_nodes = Vec::new(); - for (block, sapling_root, orchard_root) in vals { - new_nodes.append(&mut self.append_leaf(block, &sapling_root, &orchard_root)?); - } - Ok(new_nodes) - } - - /// Remove the last leaf (block) from the tree. - /// - /// Returns the number of nodes removed from the tree after the operation. - fn truncate_leaf(&mut self) -> Result { - self.inner.truncate_leaf() - } - /// Return the root hash of the tree, i.e. `hashChainHistoryRoot`. pub fn hash(&self) -> ChainHistoryMmrRootHash { // Both append_leaf() and truncate_leaf() leave a root node, so it should diff --git a/zebra-chain/src/sapling/commitment/test_vectors.rs b/zebra-chain/src/sapling/commitment/test_vectors.rs index b6f93e35f..b33c6a810 100644 --- a/zebra-chain/src/sapling/commitment/test_vectors.rs +++ b/zebra-chain/src/sapling/commitment/test_vectors.rs @@ -9,8 +9,6 @@ // librustzcash, they match their Display impl to match the Python hex strings // and that's what they compare in their unit tests, not the bytes. -#![allow(dead_code)] - use bitvec::prelude::*; use lazy_static::lazy_static; diff --git a/zebra-chain/src/sapling/keys.rs b/zebra-chain/src/sapling/keys.rs index 041dca535..548c66486 100644 --- a/zebra-chain/src/sapling/keys.rs +++ b/zebra-chain/src/sapling/keys.rs @@ -9,7 +9,6 @@ //! [3.1]: https://zips.z.cash/protocol/protocol.pdf#addressesandkeys #![allow(clippy::unit_arg)] #![allow(clippy::fallible_impl_from)] -#![allow(dead_code)] #[cfg(test)] mod test_vectors; @@ -65,25 +64,6 @@ fn prf_expand(sk: [u8; 32], t: &[u8]) -> [u8; 64] { *hash.as_array() } -/// Used to derive the outgoing cipher key _ock_ used to encrypt an Output ciphertext. -/// -/// PRF^ock(ovk, cv, cm_u, ephemeralKey) := BLAKE2b-256(“Zcash_Derive_ock”, ovk || cv || cm_u || ephemeralKey) -/// -/// -fn prf_ock(ovk: [u8; 32], cv: [u8; 32], cm_u: [u8; 32], ephemeral_key: [u8; 32]) -> [u8; 32] { - let hash = blake2b_simd::Params::new() - .hash_length(32) - .personal(b"Zcash_Derive_ock") - .to_state() - .update(&ovk) - .update(&cv) - .update(&cm_u) - .update(&ephemeral_key) - .finalize(); - - <[u8; 32]>::try_from(hash.as_bytes()).expect("32 byte array") -} - /// Invokes Blake2s-256 as _CRH^ivk_, to derive the IncomingViewingKey /// bytes from an AuthorizingKey and NullifierDerivingKey. /// diff --git a/zebra-chain/src/sapling/note.rs b/zebra-chain/src/sapling/note.rs index 2a83514e8..72f67bc02 100644 --- a/zebra-chain/src/sapling/note.rs +++ b/zebra-chain/src/sapling/note.rs @@ -1,7 +1,6 @@ //! Sapling notes #![allow(clippy::unit_arg)] -#![allow(dead_code)] mod ciphertexts; mod nullifiers; diff --git a/zebra-chain/src/sapling/note/nullifiers.rs b/zebra-chain/src/sapling/note/nullifiers.rs index ba0b2c2d2..7cb4776a3 100644 --- a/zebra-chain/src/sapling/note/nullifiers.rs +++ b/zebra-chain/src/sapling/note/nullifiers.rs @@ -1,5 +1,4 @@ #![allow(clippy::unit_arg)] -#![allow(dead_code)] use super::super::{ commitment::{pedersen_hashes::mixing_pedersen_hash, NoteCommitment}, diff --git a/zebra-chain/src/sprout/note.rs b/zebra-chain/src/sprout/note.rs index df5f3df78..3ea5c7d43 100644 --- a/zebra-chain/src/sprout/note.rs +++ b/zebra-chain/src/sprout/note.rs @@ -1,7 +1,6 @@ //! Sprout notes #![allow(clippy::unit_arg)] -#![allow(dead_code)] #[cfg(any(test, feature = "proptest-impl"))] mod arbitrary; diff --git a/zebra-chain/src/sprout/note/nullifiers.rs b/zebra-chain/src/sprout/note/nullifiers.rs index 164f3b798..c3f8549ba 100644 --- a/zebra-chain/src/sprout/note/nullifiers.rs +++ b/zebra-chain/src/sprout/note/nullifiers.rs @@ -1,5 +1,3 @@ -#![allow(dead_code)] - use byteorder::{ByteOrder, LittleEndian}; use serde::{Deserialize, Serialize}; use sha2::digest::generic_array::{typenum::U64, GenericArray}; diff --git a/zebra-chain/src/transaction.rs b/zebra-chain/src/transaction.rs index 0dc4b4b93..48660a8e4 100644 --- a/zebra-chain/src/transaction.rs +++ b/zebra-chain/src/transaction.rs @@ -975,29 +975,6 @@ impl Transaction { .map_err(ValueBalanceError::Transparent) } - /// Return the transparent value balance, - /// the change in the value of the transaction value pool. - /// - /// The sum of the UTXOs spent by transparent inputs in `tx_in` fields, - /// minus the sum of the newly created outputs in `tx_out` fields. - /// - /// Positive values are added to this transaction's value pool, - /// and removed from the transparent chain value pool. - /// Negative values are removed from the transparent chain value pool, - /// and added to this transaction. - /// - /// - /// - /// `utxos` must contain the utxos of every input in the transaction, - /// including UTXOs created by earlier transactions in this block. - #[allow(dead_code)] - fn transparent_value_balance( - &self, - utxos: &HashMap, - ) -> Result, ValueBalanceError> { - self.transparent_value_balance_from_outputs(&outputs_from_utxos(utxos.clone())) - } - /// Modify the transparent output values of this transaction, regardless of version. #[cfg(any(test, feature = "proptest-impl"))] pub fn output_values_mut(&mut self) -> impl Iterator> {