Skip to content

Commit

Permalink
Improvements from review; renamed sighash::Hash to SigHash
Browse files Browse the repository at this point in the history
  • Loading branch information
conradoplg committed Jul 6, 2021
1 parent 4a27490 commit 32e2278
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
8 changes: 3 additions & 5 deletions zebra-chain/src/primitives/zcash_primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ use crate::{
amount::{Amount, NonNegative},
parameters::NetworkUpgrade,
serialization::ZcashSerialize,
transaction::HashType,
transaction::SignatureHash,
transaction::Transaction,
transaction::{HashType, SigHash, Transaction},
transparent::{self, Script},
};

Expand Down Expand Up @@ -90,7 +88,7 @@ pub(crate) fn sighash(
hash_type: HashType,
network_upgrade: NetworkUpgrade,
input: Option<(&transparent::Output, &transparent::Input, usize)>,
) -> SignatureHash {
) -> SigHash {
let alt_tx = convert_tx_to_librustzcash(trans, network_upgrade)
.expect("zcash_primitives and Zebra transaction formats must be compatible");

Expand All @@ -116,7 +114,7 @@ pub(crate) fn sighash(
.deref()
.digest(zcash_primitives::transaction::txid::TxIdDigester);

SignatureHash(
SigHash(
*zcash_primitives::transaction::sighash::signature_hash(
alt_tx.deref(),
hash_type.bits(),
Expand Down
4 changes: 2 additions & 2 deletions zebra-chain/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub use joinsplit::JoinSplitData;
pub use lock_time::LockTime;
pub use memo::Memo;
pub use sapling::FieldNotPresent;
pub use sighash::Hash as SignatureHash;
pub use sighash::HashType;
pub use sighash::SigHash;

use crate::{
amount, block, orchard,
Expand Down Expand Up @@ -147,7 +147,7 @@ impl Transaction {
network_upgrade: NetworkUpgrade,
hash_type: sighash::HashType,
input: Option<(u32, transparent::Output)>,
) -> SignatureHash {
) -> SigHash {
sighash::SigHasher::new(self, hash_type, network_upgrade, input).sighash()
}

Expand Down
14 changes: 7 additions & 7 deletions zebra-chain/src/transaction/sighash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ impl HashType {

/// A Signature Hash (or SIGHASH) as specified in
/// https://zips.z.cash/protocol/protocol.pdf#sighash
#[derive(Copy, Clone, Eq, PartialEq, Hash, Serialize, Deserialize, Debug)]
pub struct Hash(pub [u8; 32]);
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub struct SigHash(pub [u8; 32]);

impl AsRef<[u8; 32]> for Hash {
impl AsRef<[u8; 32]> for SigHash {
fn as_ref(&self) -> &[u8; 32] {
&self.0
}
}

impl AsRef<[u8]> for Hash {
impl AsRef<[u8]> for SigHash {
fn as_ref(&self) -> &[u8] {
&self.0
}
Expand Down Expand Up @@ -100,7 +100,7 @@ impl<'a> SigHasher<'a> {
}
}

pub(super) fn sighash(self) -> Hash {
pub(super) fn sighash(self) -> SigHash {
use NetworkUpgrade::*;
let mut hash = blake2b_simd::Params::new()
.hash_length(32)
Expand All @@ -118,7 +118,7 @@ impl<'a> SigHasher<'a> {
Nu5 => return self.hash_sighash_zip244(),
}

Hash(hash.finalize().as_ref().try_into().unwrap())
SigHash(hash.finalize().as_ref().try_into().unwrap())
}

fn consensus_branch_id(&self) -> ConsensusBranchId {
Expand Down Expand Up @@ -550,7 +550,7 @@ impl<'a> SigHasher<'a> {
}

/// Compute a signature hash for V5 transactions according to ZIP-244.
fn hash_sighash_zip244(&self) -> Hash {
fn hash_sighash_zip244(&self) -> SigHash {
let input = self
.input
.as_ref()
Expand Down
6 changes: 3 additions & 3 deletions zebra-consensus/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use zebra_chain::{
parameters::{Network, NetworkUpgrade},
primitives::Groth16Proof,
sapling,
transaction::{self, HashType, SignatureHash, Transaction},
transaction::{self, HashType, SigHash, Transaction},
transparent,
};

Expand Down Expand Up @@ -398,7 +398,7 @@ where
/// Verifies a transaction's Sprout shielded join split data.
fn verify_sprout_shielded_data(
joinsplit_data: &Option<transaction::JoinSplitData<Groth16Proof>>,
shielded_sighash: &SignatureHash,
shielded_sighash: &SigHash,
) -> AsyncChecks {
let mut checks = AsyncChecks::new();

Expand Down Expand Up @@ -434,7 +434,7 @@ where
/// Verifies a transaction's Sapling shielded data.
fn verify_sapling_shielded_data<A>(
sapling_shielded_data: &Option<sapling::ShieldedData<A>>,
shielded_sighash: &SignatureHash,
shielded_sighash: &SigHash,
) -> Result<AsyncChecks, TransactionError>
where
A: sapling::AnchorVariant + Clone,
Expand Down

0 comments on commit 32e2278

Please sign in to comment.