Update the computation of ZIP 244 test vectors to match https://github.com/zcash/zips/pull/587 .

Co-authored-by: Kris Nuttycombe <kris@nutty.land>
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
Daira Hopwood 2022-01-27 22:49:38 +00:00
parent 0afbd1f240
commit ff9e171ff3
3 changed files with 15 additions and 5 deletions

View File

@ -69,7 +69,7 @@
],
transparent_input: None,
sighash_shielded: [
0xf2, 0x89, 0x61, 0x8d, 0x7f, 0x61, 0x53, 0x29, 0x3c, 0x4e, 0x24, 0xc2, 0x76, 0xa0, 0xa1, 0x5d, 0x56, 0x2d, 0x4e, 0x6c, 0x91, 0xde, 0x3e, 0x93, 0x10, 0x4d, 0x31, 0x65, 0x4e, 0x5d, 0x71, 0xc5
0x2f, 0x95, 0xe5, 0xa9, 0x5d, 0x20, 0x9e, 0x0a, 0x27, 0xd1, 0xfe, 0x66, 0x9a, 0x46, 0xf4, 0xa6, 0x44, 0xa3, 0x27, 0xd7, 0x9b, 0x84, 0x6e, 0x97, 0x92, 0x64, 0x18, 0x6a, 0xde, 0x04, 0x9b, 0xa0
],
sighash_all: None,
sighash_none: None,
@ -119,7 +119,7 @@
],
transparent_input: None,
sighash_shielded: [
0x6a, 0x58, 0x74, 0x54, 0xbd, 0x03, 0x12, 0x4b, 0x38, 0xe8, 0x0b, 0x46, 0xe4, 0x57, 0xcd, 0x7d, 0x5a, 0x0e, 0x8c, 0x92, 0x9b, 0x27, 0x56, 0xc1, 0xd6, 0x81, 0x7e, 0x7b, 0x53, 0xdb, 0xf3, 0x63
0x83, 0xc8, 0xe3, 0x41, 0x04, 0xf1, 0x8b, 0xdb, 0xe8, 0xbb, 0xf6, 0xf0, 0xb9, 0xba, 0x53, 0xb5, 0xc6, 0x69, 0x40, 0x61, 0x0c, 0x89, 0x4b, 0xc0, 0xa8, 0x4a, 0x16, 0xdc, 0x99, 0x51, 0x24, 0x74
],
sighash_all: None,
sighash_none: None,

View File

@ -423,6 +423,10 @@ class TransactionV5(object):
def version_bytes(self):
return NU5_TX_VERSION | (1 << 31)
def is_coinbase(self):
# <https://github.com/zcash/zcash/blob/d8c818bfa507adb845e527f5beb38345c490b330/src/primitives/transaction.h#L969-L972>
return len(self.vin) == 1 and bytes(self.vin[0].prevout.txid) == b'\x00'*32 and self.vin[0].prevout.n == 0xFFFFFFFF
# TODO: Update ZIP 225 to document endianness
def __bytes__(self):
ret = b''

View File

@ -240,9 +240,15 @@ def signature_digest(tx, t_inputs, nHashType, txin):
return digest.digest()
def transparent_sig_digest(tx, t_inputs, nHashType, txin):
digest = blake2b(digest_size=32, person=b'ZTxIdTranspaHash')
# If we are producing a hash for either a coinbase transaction, or a
# non-coinbase transaction that has no transparent inputs, the value of
# ``transparent_sig_digest`` is identical to the value specified in section
# T.2 <https://zips.z.cash/zip-0244#t-2-transparent-digest>.
if len(tx.vin) + len(tx.vout) > 0:
if tx.is_coinbase() or len(tx.vin) == 0:
return transparent_digest(tx)
else:
digest = blake2b(digest_size=32, person=b'ZTxIdTranspaHash')
digest.update(hash_type(tx, nHashType, txin))
digest.update(prevouts_sig_digest(tx, nHashType))
digest.update(amounts_sig_digest(t_inputs, nHashType))
@ -251,7 +257,7 @@ def transparent_sig_digest(tx, t_inputs, nHashType, txin):
digest.update(outputs_sig_digest(tx, nHashType, txin))
digest.update(txin_sig_digest(tx, txin))
return digest.digest()
return digest.digest()
def hash_type(tx, nHashType, txin):
if txin is None: