Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions test-vectors/json/orchard_zsa_digests.json

Large diffs are not rendered by default.

3,273 changes: 1,837 additions & 1,436 deletions test-vectors/rust/orchard_zsa_digests.rs

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions test-vectors/zcash/orchard_zsa_digests.json

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions zcash_test_vectors/orchard_zsa/digests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def orchard_zsa_digest(tx):

if len(tx.vActionGroupsOrchard) > 0:
digest.update(orchard_zsa_action_groups_digest(tx))
digest.update(struct.pack('<Q', tx.valueBalanceOrchard))
digest.update(struct.pack('<q', tx.valueBalanceOrchard))

return digest.digest()

Expand All @@ -27,6 +27,7 @@ def orchard_zsa_action_groups_digest(tx):
if len(tx.vActionGroupsOrchard) > 0:
for ag in tx.vActionGroupsOrchard:
digest.update(orchard_zsa_actions_compact_digest(ag))
# TODO remove memo digests once the new memo bundles are implemented (ZIP-231)
digest.update(orchard_zsa_actions_memos_digest(ag))
digest.update(orchard_zsa_actions_noncompact_digest(ag))
digest.update(struct.pack('<B', ag.flagsOrchard))
Expand Down Expand Up @@ -64,7 +65,7 @@ def orchard_zsa_action_groups_auth_digest(tx):


def orchard_zsa_actions_compact_digest(ag):
digest = blake2b(digest_size=32, person=b'ZTxIdOrcActCHash')
digest = blake2b(digest_size=32, person=b'ZTxId6OActC_Hash')
for desc in ag.vActionsOrchard:
digest.update(bytes(desc.nullifier))
digest.update(bytes(desc.cmx))
Expand All @@ -83,10 +84,11 @@ def orchard_zsa_actions_memos_digest(ag):


def orchard_zsa_actions_noncompact_digest(ag):
digest = blake2b(digest_size=32, person=b'ZTxIdOrcActNHash')
digest = blake2b(digest_size=32, person=b'ZTxId6OActN_Hash')
for desc in ag.vActionsOrchard:
digest.update(bytes(desc.cv))
digest.update(bytes(desc.rk))
# TODO remove encCiphertext[596:] once the new memo bundles are implemented (ZIP-231)
digest.update(desc.encCiphertext[596:])
digest.update(desc.outCiphertext)

Expand All @@ -108,8 +110,9 @@ def issuance_digest(tx):
digest = blake2b(digest_size=32, person=b'ZTxIdSAIssueHash')

if len(tx.vIssueActions) > 0:
digest.update(issue_actions_digest(tx))
digest.update(write_compact_size(len(tx.issuer)))
digest.update(tx.issuer)
digest.update(issue_actions_digest(tx))

return digest.digest()

Expand All @@ -119,6 +122,7 @@ def issuance_auth_digest(tx):
if len(tx.vIssueActions) > 0:
digest.update(write_compact_size(len(tx.issueAuthSigInfo)))
digest.update(bytes(tx.issueAuthSigInfo))
digest.update(write_compact_size(len(tx.issueAuthSig)))
digest.update(tx.issueAuthSig)
return digest.digest()

Expand All @@ -127,8 +131,8 @@ def issue_actions_digest(tx):
digest = blake2b(digest_size=32, person=b'ZTxIdIssuActHash')

for action in tx.vIssueActions:
digest.update(issue_notes_digest(action))
digest.update(action.asset_desc_hash)
digest.update(issue_notes_digest(action))
digest.update(struct.pack('<B', action.flagsIssuance))

return digest.digest()
Expand All @@ -140,7 +144,6 @@ def issue_notes_digest(action):
for note in action.vNotes:
digest.update(bytes(note.recipient))
digest.update(struct.pack('<Q', note.value))
digest.update(bytes(note.assetBase))
digest.update(bytes(note.rho))
digest.update(note.rseed)

Expand Down
2 changes: 1 addition & 1 deletion zcash_test_vectors/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ def __bytes__(self):
for desc in self.vActionsOrchard:
ret += bytes(desc) # Excludes spendAuthSig
ret += struct.pack('B', self.flagsOrchard)
ret += struct.pack('<Q', self.valueBalanceOrchard)
ret += struct.pack('<q', self.valueBalanceOrchard)
ret += bytes(self.anchorOrchard)
ret += write_compact_size(len(self.proofsOrchard))
ret += self.proofsOrchard
Expand Down
31 changes: 17 additions & 14 deletions zcash_test_vectors/transaction_v6.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ def __bytes__(self):


class IssueActionDescription(object):
def __init__(self, rand, ik_encoding):
def __init__(self, rand):
self.assetDescSize = rand.u32() % 512 + 1
self.asset_desc_hash = asset_desc_digest(get_random_unicode_bytes(self.assetDescSize, rand))
self.vNotes = []
for _ in range(rand.u8() % 5):
self.vNotes.append(IssueNote(rand, ik_encoding, self.asset_desc_hash))
self.vNotes.append(IssueNoteDescription(rand))
self.flagsIssuance = rand.u8() & 1 # Only one bit is reserved for the finalize flag currently

def __bytes__(self):
Expand All @@ -69,23 +69,18 @@ def __bytes__(self):
return ret


class IssueNote(object):
def __init__(self, rand, ik_encoding, asset_desc_hash):
class IssueNoteDescription(object):
def __init__(self, rand):
fvk_r = FullViewingKey.from_spending_key(SpendingKey(rand.b(32)))
self.recipient = fvk_r.default_d() + bytes(fvk_r.default_pkd())
self.value = rand.u64()
asset_digest_bytes = asset_digest(
encode_asset_id(ik_encoding, asset_desc_hash)
)
self.assetBase = zsa_value_base(asset_digest_bytes)
self.rho = Point.rand(rand).extract()
self.rseed = rand.b(32)

def __bytes__(self):
ret = b''
ret += bytes(self.recipient)
ret += struct.pack('<Q', self.value)
ret += bytes(self.assetBase)
ret += bytes(self.rho)
ret += self.rseed

Expand Down Expand Up @@ -149,6 +144,9 @@ def __init__(self, rand, consensus_branch_id, sighash_info, have_orchard_zsa=Tru
# We cannot have burns without an OrchardZSA bundle.
assert have_orchard_zsa or not have_burn

# We cannot have issuance without an OrchardZSA bundle.
assert have_orchard_zsa or not have_issuance #TODO: VA: Combine this with the above?

# All Transparent, Sapling, and part of the Orchard Transaction Fields are initialized in the super class.
super().__init__(rand, have_orchard_zsa)
self.bindingSigOrchardInfo = sighash_info
Expand All @@ -166,11 +164,12 @@ def __init__(self, rand, consensus_branch_id, sighash_info, have_orchard_zsa=Tru

# OrchardZSA Issuance Fields
self.vIssueActions = []
self.issuer = []
if have_issuance:
self.isk = rand.b(32)
self.issuer = IssuanceKeys(self.isk).ik_encoding
for _ in range(rand.u8() % 5):
self.vIssueActions.append(IssueActionDescription(rand, self.issuer))
for _ in range(rand.u8() % 5 + 1):
self.vIssueActions.append(IssueActionDescription(rand))

t_inputs = [TransparentInput(nIn, rand) for nIn in range(len(self.vin))]
sighash = signature_digest(self, t_inputs, SIGHASH_ALL, None)
Expand All @@ -180,18 +179,22 @@ def __init__(self, rand, consensus_branch_id, sighash_info, have_orchard_zsa=Tru
schnorr_sign(sighash, self.isk, b'\0' * 32)
)

if len(self.vIssueActions) == 0:
assert len(self.issuer) == 0

@staticmethod
def version_bytes():
return NU7_TX_VERSION_BYTES

def issuance_field_bytes(self):
ret = b''
ret += write_compact_size(len(self.issuer))
if len(self.issuer) > 0:
ret += self.issuer
ret += write_compact_size(len(self.vIssueActions))
if len(self.vIssueActions) > 0:
for desc in self.vIssueActions:
ret += bytes(desc)
ret += write_compact_size(len(self.issuer))
ret += self.issuer
ret += write_compact_size(len(self.issueAuthSigInfo))
ret += bytes(self.issueAuthSigInfo)
ret += write_compact_size(len(self.issueAuthSig))
Expand All @@ -209,7 +212,7 @@ def __bytes__(self):
if len(self.vActionGroupsOrchard) > 0:
for ag in self.vActionGroupsOrchard:
ret += bytes(ag)
ret += struct.pack('<Q', self.valueBalanceOrchard)
ret += struct.pack('<q', self.valueBalanceOrchard)
ret += write_compact_size(len(self.bindingSigOrchardInfo))
ret += bytes(self.bindingSigOrchardInfo)
ret += bytes(self.bindingSigOrchard)
Expand Down
2 changes: 1 addition & 1 deletion zcash_test_vectors/zip_0244.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def orchard_digest(tx):
digest.update(orchard_actions_memos_digest(tx))
digest.update(orchard_actions_noncompact_digest(tx))
digest.update(struct.pack('<B', tx.flagsOrchard))
digest.update(struct.pack('<Q', tx.valueBalanceOrchard))
digest.update(struct.pack('<q', tx.valueBalanceOrchard))
digest.update(bytes(tx.anchorOrchard))

return digest.digest()
Expand Down