From 145d1a57f7fc3e6af1d9594c9f350c5d882b0a80 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Thu, 23 Dec 2021 13:52:30 -0700 Subject: [PATCH] Make transparent signatures commit to all input amounts & scripts. Transparent UTXOs are referred as pair of previous txid and index. In order to verify UTXO's amount in HWW (hardware wallet), whole previous transaction containing this UTXO must be streamed into the device. This increases complexity of signing process significantly. zcash/zips#574 identifies this problem and suggests a modification to ZIP-244 to resolve this issue, by adding three new fields to section S.2 of the signature hash. --- .../src/transaction/components/sprout.rs | 2 +- .../components/transparent/builder.rs | 60 +++-- zcash_primitives/src/transaction/mod.rs | 5 +- zcash_primitives/src/transaction/sighash.rs | 125 +++------- .../src/transaction/sighash_v4.rs | 24 +- .../src/transaction/sighash_v5.rs | 219 ++++++++++-------- zcash_primitives/src/transaction/tests.rs | 151 +++++++++--- zcash_primitives/src/transaction/txid.rs | 36 +-- 8 files changed, 367 insertions(+), 255 deletions(-) diff --git a/zcash_primitives/src/transaction/components/sprout.rs b/zcash_primitives/src/transaction/components/sprout.rs index b1f3215a5..79f563330 100644 --- a/zcash_primitives/src/transaction/components/sprout.rs +++ b/zcash_primitives/src/transaction/components/sprout.rs @@ -10,7 +10,7 @@ const PHGR_PROOF_SIZE: usize = 33 + 33 + 65 + 33 + 33 + 33 + 33 + 33; const ZC_NUM_JS_INPUTS: usize = 2; const ZC_NUM_JS_OUTPUTS: usize = 2; -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct Bundle { pub joinsplits: Vec, pub joinsplit_pubkey: [u8; 32], diff --git a/zcash_primitives/src/transaction/components/transparent/builder.rs b/zcash_primitives/src/transaction/components/transparent/builder.rs index da202f690..d9cd11603 100644 --- a/zcash_primitives/src/transaction/components/transparent/builder.rs +++ b/zcash_primitives/src/transaction/components/transparent/builder.rs @@ -6,22 +6,22 @@ use std::fmt; use blake2b_simd::Hash as Blake2bHash; use crate::{ - legacy::TransparentAddress, - transaction::components::{ - amount::Amount, - transparent::{self, Authorization, Authorized, Bundle, TxIn, TxOut}, + legacy::{Script, TransparentAddress}, + transaction::{ + components::{ + amount::Amount, + transparent::{self, Authorization, Authorized, Bundle, TxIn, TxOut}, + }, + sighash::TransparentAuthorizingContext, }, }; #[cfg(feature = "transparent-inputs")] -use crate::{ - legacy::Script, - transaction::{ - self as tx, - components::OutPoint, - sighash::{signature_hash, SignableInput, SIGHASH_ALL}, - TransactionData, TxDigests, - }, +use crate::transaction::{ + self as tx, + components::OutPoint, + sighash::{signature_hash, SignableInput, SIGHASH_ALL}, + TransactionData, TxDigests, }; #[derive(Debug, PartialEq)] @@ -188,6 +188,36 @@ impl TxIn { } } +#[cfg(not(feature = "transparent-inputs"))] +impl TransparentAuthorizingContext for Unauthorized { + fn input_amounts(&self) -> Vec { + vec![] + } + + fn input_scripts(&self) -> Vec