Merge pull request #34 from zcash-hackworks/33-zip-244-auth-digest
Add ZIP 244 auth digest test vectors
This commit is contained in:
commit
23f3d09f03
48
zip_0244.py
48
zip_0244.py
|
@ -33,6 +33,12 @@ def transparent_digest(tx):
|
||||||
|
|
||||||
return digest.digest()
|
return digest.digest()
|
||||||
|
|
||||||
|
def transparent_scripts_digest(tx):
|
||||||
|
digest = blake2b(digest_size=32, person=b'ZTxAuthTransHash')
|
||||||
|
for x in tx.vin:
|
||||||
|
digest.update(bytes(x.scriptSig))
|
||||||
|
return digest.digest()
|
||||||
|
|
||||||
# Sapling
|
# Sapling
|
||||||
|
|
||||||
def sapling_digest(tx):
|
def sapling_digest(tx):
|
||||||
|
@ -45,6 +51,20 @@ def sapling_digest(tx):
|
||||||
|
|
||||||
return digest.digest()
|
return digest.digest()
|
||||||
|
|
||||||
|
def sapling_auth_digest(tx):
|
||||||
|
digest = blake2b(digest_size=32, person=b'ZTxAuthSapliHash')
|
||||||
|
|
||||||
|
if len(tx.vSpendsSapling) + len(tx.vOutputsSapling) > 0:
|
||||||
|
for desc in tx.vSpendsSapling:
|
||||||
|
digest.update(bytes(desc.proof))
|
||||||
|
for desc in tx.vSpendsSapling:
|
||||||
|
digest.update(bytes(desc.spendAuthSig))
|
||||||
|
for desc in tx.vOutputsSapling:
|
||||||
|
digest.update(bytes(desc.proof))
|
||||||
|
digest.update(bytes(tx.bindingSigSapling))
|
||||||
|
|
||||||
|
return digest.digest()
|
||||||
|
|
||||||
# - Spends
|
# - Spends
|
||||||
|
|
||||||
def sapling_spends_digest(tx):
|
def sapling_spends_digest(tx):
|
||||||
|
@ -119,6 +139,17 @@ def orchard_digest(tx):
|
||||||
|
|
||||||
return digest.digest()
|
return digest.digest()
|
||||||
|
|
||||||
|
def orchard_auth_digest(tx):
|
||||||
|
digest = blake2b(digest_size=32, person=b'ZTxAuthOrchaHash')
|
||||||
|
|
||||||
|
if len(tx.vActionsOrchard) > 0:
|
||||||
|
digest.update(tx.proofsOrchard)
|
||||||
|
for desc in tx.vActionsOrchard:
|
||||||
|
digest.update(bytes(desc.spendAuthSig))
|
||||||
|
digest.update(bytes(tx.bindingSigOrchard))
|
||||||
|
|
||||||
|
return digest.digest()
|
||||||
|
|
||||||
# - Actions
|
# - Actions
|
||||||
|
|
||||||
def orchard_actions_compact_digest(tx):
|
def orchard_actions_compact_digest(tx):
|
||||||
|
@ -171,6 +202,20 @@ def txid_digest(tx):
|
||||||
|
|
||||||
return digest.digest()
|
return digest.digest()
|
||||||
|
|
||||||
|
# Authorizing Data Commitment
|
||||||
|
|
||||||
|
def auth_digest(tx):
|
||||||
|
digest = blake2b(
|
||||||
|
digest_size=32,
|
||||||
|
person=b'ZTxAuthHash_' + struct.pack('<I', tx.nConsensusBranchId),
|
||||||
|
)
|
||||||
|
|
||||||
|
digest.update(transparent_scripts_digest(tx))
|
||||||
|
digest.update(sapling_auth_digest(tx))
|
||||||
|
digest.update(orchard_auth_digest(tx))
|
||||||
|
|
||||||
|
return digest.digest()
|
||||||
|
|
||||||
# Signatures
|
# Signatures
|
||||||
|
|
||||||
class TransparentInput(object):
|
class TransparentInput(object):
|
||||||
|
@ -268,6 +313,7 @@ def main():
|
||||||
for _ in range(10):
|
for _ in range(10):
|
||||||
tx = TransactionV5(rand, consensusBranchId)
|
tx = TransactionV5(rand, consensusBranchId)
|
||||||
txid = txid_digest(tx)
|
txid = txid_digest(tx)
|
||||||
|
auth = auth_digest(tx)
|
||||||
|
|
||||||
# If there are any transparent inputs, derive a corresponding transparent sighash.
|
# If there are any transparent inputs, derive a corresponding transparent sighash.
|
||||||
if len(tx.vin) > 0:
|
if len(tx.vin) > 0:
|
||||||
|
@ -290,6 +336,7 @@ def main():
|
||||||
test_vectors.append({
|
test_vectors.append({
|
||||||
'tx': bytes(tx),
|
'tx': bytes(tx),
|
||||||
'txid': txid,
|
'txid': txid,
|
||||||
|
'auth_digest': auth,
|
||||||
'transparent_input': None if txin is None else txin.nIn,
|
'transparent_input': None if txin is None else txin.nIn,
|
||||||
'script_code': None if txin is None else txin.scriptCode.raw(),
|
'script_code': None if txin is None else txin.scriptCode.raw(),
|
||||||
'amount': None if txin is None else txin.amount,
|
'amount': None if txin is None else txin.amount,
|
||||||
|
@ -307,6 +354,7 @@ def main():
|
||||||
(
|
(
|
||||||
('tx', {'rust_type': 'Vec<u8>', 'bitcoin_flavoured': False}),
|
('tx', {'rust_type': 'Vec<u8>', 'bitcoin_flavoured': False}),
|
||||||
('txid', '[u8; 32]'),
|
('txid', '[u8; 32]'),
|
||||||
|
('auth_digest', '[u8; 32]'),
|
||||||
('transparent_input', {
|
('transparent_input', {
|
||||||
'rust_type': 'Option<u32>',
|
'rust_type': 'Option<u32>',
|
||||||
'rust_fmt': lambda x: None if x is None else Some(x),
|
'rust_fmt': lambda x: None if x is None else Some(x),
|
||||||
|
|
Loading…
Reference in New Issue