diff --git a/src/apps/wallet/sign_tx/overwinter_zip143.py b/src/apps/wallet/sign_tx/overwinter_zip143.py index 81eeb88e5..4489685dc 100644 --- a/src/apps/wallet/sign_tx/overwinter_zip143.py +++ b/src/apps/wallet/sign_tx/overwinter_zip143.py @@ -38,13 +38,13 @@ class Zip143: write_tx_output(self.h_outputs, txo_bin) def get_prevouts_hash(self) -> bytes: - return get_tx_hash(self.h_prevouts, False) + return get_tx_hash(self.h_prevouts) def get_sequence_hash(self) -> bytes: - return get_tx_hash(self.h_sequence, False) + return get_tx_hash(self.h_sequence) def get_outputs_hash(self) -> bytes: - return get_tx_hash(self.h_outputs, False) + return get_tx_hash(self.h_outputs) def preimage_hash(self, coin: CoinInfo, tx: SignTx, txi: TxInputType, pubkeyhash: bytes, sighash: int) -> bytes: h_preimage = HashWriter(blake2b, b'', 32, b'ZcashSigHash\x19\x1b\xa8\x5b') # BRANCH_ID = 0x5ba81b19 @@ -72,7 +72,7 @@ class Zip143: write_uint32(h_preimage, txi.sequence) # 10d. nSequence - return get_tx_hash(h_preimage, False) + return get_tx_hash(h_preimage) # see https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki#specification # item 5 for details diff --git a/src/apps/wallet/sign_tx/segwit_bip143.py b/src/apps/wallet/sign_tx/segwit_bip143.py index fd8fff88f..d56c2ec54 100644 --- a/src/apps/wallet/sign_tx/segwit_bip143.py +++ b/src/apps/wallet/sign_tx/segwit_bip143.py @@ -33,13 +33,13 @@ class Bip143: write_tx_output(self.h_outputs, txo_bin) def get_prevouts_hash(self) -> bytes: - return get_tx_hash(self.h_prevouts, True) + return get_tx_hash(self.h_prevouts, double=True) def get_sequence_hash(self) -> bytes: - return get_tx_hash(self.h_sequence, True) + return get_tx_hash(self.h_sequence, double=True) def get_outputs_hash(self) -> bytes: - return get_tx_hash(self.h_outputs, True) + return get_tx_hash(self.h_outputs, double=True) def preimage_hash(self, coin: CoinInfo, tx: SignTx, txi: TxInputType, pubkeyhash: bytes, sighash: int) -> bytes: h_preimage = HashWriter(sha256) @@ -63,7 +63,7 @@ class Bip143: write_uint32(h_preimage, tx.lock_time) # nLockTime write_uint32(h_preimage, sighash) # nHashType - return get_tx_hash(h_preimage, True) + return get_tx_hash(h_preimage, double=True) # see https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki#specification # item 5 for details diff --git a/src/apps/wallet/sign_tx/signing.py b/src/apps/wallet/sign_tx/signing.py index db22584f7..bd4e2b180 100644 --- a/src/apps/wallet/sign_tx/signing.py +++ b/src/apps/wallet/sign_tx/signing.py @@ -299,7 +299,7 @@ async def sign_tx(tx: SignTx, root: bip32.HDNode): write_uint32(h_sign, get_hash_type(coin)) # check the control digests - if get_tx_hash(h_first, False) != get_tx_hash(h_second, False): + if get_tx_hash(h_first, False) != get_tx_hash(h_second): raise SigningError(FailureType.ProcessError, 'Transaction has changed during signing') @@ -308,7 +308,7 @@ async def sign_tx(tx: SignTx, root: bip32.HDNode): multisig_pubkey_index(txi_sign.multisig, key_sign_pub) # compute the signature from the tx digest - signature = ecdsa_sign(key_sign, get_tx_hash(h_sign, True)) + signature = ecdsa_sign(key_sign, get_tx_hash(h_sign, double=True)) tx_ser.signature_index = i_sign tx_ser.signature = signature @@ -433,7 +433,7 @@ async def get_prevtx_output_value(coin: CoinInfo, tx_req: TxRequest, prev_hash: write_bytes(txh, data) ofs += len(data) - if get_tx_hash(txh, True, True) != prev_hash: + if get_tx_hash(txh, double=True, reverse=True) != prev_hash: raise SigningError(FailureType.ProcessError, 'Encountered invalid prev_hash') diff --git a/src/apps/wallet/sign_tx/writers.py b/src/apps/wallet/sign_tx/writers.py index 279118579..fae6724cf 100644 --- a/src/apps/wallet/sign_tx/writers.py +++ b/src/apps/wallet/sign_tx/writers.py @@ -109,7 +109,7 @@ def bytearray_with_cap(cap: int) -> bytearray: # === -def get_tx_hash(w, double: bool, reverse: bool=False) -> bytes: +def get_tx_hash(w, double: bool=False, reverse: bool=False) -> bytes: d = w.get_digest() if double: d = sha256(d).digest()