Skip to content

Commit

Permalink
based on review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vivek-arte committed Sep 19, 2024
1 parent 737b366 commit ff64cde
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion zcash_test_vectors/orchard_zsa/digests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

NU7_VERSION_GROUP_ID = 0x124A69F8
NU7_TX_VERSION = 6

NU7_TX_VERSION_BYTES = NU7_TX_VERSION | (1 << 31)

def orchard_zsa_burn_digest(tx):
digest = blake2b(digest_size=32, person=b'ZTxIdOrcBurnHash')
Expand Down
3 changes: 2 additions & 1 deletion zcash_test_vectors/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

NU5_VERSION_GROUP_ID = 0x26A7270A
NU5_TX_VERSION = 5
NU5_TX_VERSION_BYTES = NU5_TX_VERSION | (1 << 31)

# Sapling note magic values, copied from src/zcash/Zcash.h
NOTEENCRYPTION_AUTH_BYTES = 16
Expand Down Expand Up @@ -561,7 +562,7 @@ def __init__(self, rand, consensus_branch_id):

@staticmethod
def version_bytes():
return NU5_TX_VERSION | (1 << 31)
return NU5_TX_VERSION_BYTES

def __bytes__(self):
ret = b''
Expand Down
4 changes: 2 additions & 2 deletions zcash_test_vectors/transaction_zsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .orchard.key_components import FullViewingKey, SpendingKey
from .orchard.pallas import Point
from .orchard_zsa.key_components import IssuanceKeys
from .orchard_zsa.digests import NU7_VERSION_GROUP_ID, NU7_TX_VERSION
from .orchard_zsa.digests import NU7_VERSION_GROUP_ID, NU7_TX_VERSION_BYTES
from .orchard_zsa.asset_base import zsa_value_base, asset_digest, encode_asset_id, get_random_unicode_bytes
from .zc_utils import write_compact_size
from .transaction import (
Expand Down Expand Up @@ -123,7 +123,7 @@ def __init__(self, rand, consensus_branch_id, have_orchard_zsa=True, have_burn=T

@staticmethod
def version_bytes():
return NU7_TX_VERSION | (1 << 31)
return NU7_TX_VERSION_BYTES

def orchard_zsa_burn_field_bytes(self):
ret = b''
Expand Down
29 changes: 13 additions & 16 deletions zcash_test_vectors/zip_0244.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
assert sys.version_info[0] >= 3, "Python 3 required."

from hashlib import blake2b
from collections import namedtuple
import struct

from .orchard_zsa.digests import NU7_TX_VERSION, orchard_zsa_burn_digest, issuance_digest, issuance_auth_digest
from .orchard_zsa.digests import NU7_TX_VERSION_BYTES, orchard_zsa_burn_digest, issuance_digest, issuance_auth_digest
from .transaction import (
MAX_MONEY,
Script,
TransactionV5,
NU5_TX_VERSION,
NU5_TX_VERSION_BYTES,
)
from .output import render_args, render_tv
from .rand import Rand
Expand Down Expand Up @@ -138,7 +139,7 @@ def orchard_digest(tx):
digest.update(orchard_actions_compact_digest(tx))
digest.update(orchard_actions_memos_digest(tx))
digest.update(orchard_actions_noncompact_digest(tx))
if tx.version_bytes() == NU7_TX_VERSION | (1 << 31):
if tx.version_bytes() == NU7_TX_VERSION_BYTES:
digest.update(orchard_zsa_burn_digest(tx))
digest.update(struct.pack('<B', tx.flagsOrchard))
digest.update(struct.pack('<Q', tx.valueBalanceOrchard))
Expand All @@ -158,19 +159,15 @@ def orchard_auth_digest(tx):
return digest.digest()


# - helpers for Actions functions
class Offsets:
def __init__(self, compact_end, memo_end):
self.compact_end = compact_end
self.memo_end = memo_end

# - helper for Actions functions
def ciphertext_offset(tx_version_bytes):
if tx_version_bytes == NU5_TX_VERSION | (1 << 31):
Offsets = namedtuple('Offsets', ['compact_end', 'memo_end'])
if tx_version_bytes == NU5_TX_VERSION_BYTES:
# Compact ends at 52, Memo ends at 564 for V5
return Offsets(52, 564)
elif tx_version_bytes == NU7_TX_VERSION | (1 << 31):
return Offsets(compact_end=52, memo_end=564)
elif tx_version_bytes == NU7_TX_VERSION_BYTES:
# Compact ends at 84, Memo ends at 596 for V6
return Offsets(84, 596)
return Offsets(compact_end=84, memo_end=596)
else:
raise ValueError("Unsupported transaction version")

Expand Down Expand Up @@ -226,7 +223,7 @@ def txid_digest(tx):
digest.update(transparent_digest(tx))
digest.update(sapling_digest(tx))
digest.update(orchard_digest(tx))
if tx.version_bytes() == NU7_TX_VERSION | (1 << 31):
if tx.version_bytes() == NU7_TX_VERSION_BYTES:
digest.update(issuance_digest(tx))

return digest.digest()
Expand All @@ -242,7 +239,7 @@ def auth_digest(tx):
digest.update(transparent_scripts_digest(tx))
digest.update(sapling_auth_digest(tx))
digest.update(orchard_auth_digest(tx))
if tx.version_bytes() == NU7_TX_VERSION | (1 << 31):
if tx.version_bytes() == NU7_TX_VERSION_BYTES:
digest.update(issuance_auth_digest(tx))

return digest.digest()
Expand All @@ -265,7 +262,7 @@ def signature_digest(tx, t_inputs, nHashType, txin):
digest.update(transparent_sig_digest(tx, t_inputs, nHashType, txin))
digest.update(sapling_digest(tx))
digest.update(orchard_digest(tx))
if tx.version_bytes() == NU7_TX_VERSION | (1 << 31):
if tx.version_bytes() == NU7_TX_VERSION_BYTES:
digest.update(issuance_digest(tx))

return digest.digest()
Expand Down

0 comments on commit ff64cde

Please sign in to comment.