Compare commits

..

2 Commits

Author SHA1 Message Date
Kris Nuttycombe ef05109a32
Merge 439d5a3e12 into ddb3397f5e 2024-04-23 18:51:48 +00:00
Kris Nuttycombe 439d5a3e12 Add ZIP 320 test vectors. 2024-04-23 12:51:23 -06:00
7 changed files with 69 additions and 71 deletions

View File

@ -44,7 +44,7 @@ zip_0244 = "zcash_test_vectors.zip_0244:main"
# Transparent test vectors
bip_0032 = "zcash_test_vectors.transparent.bip_0032:main"
zip_0316 = "zcash_test_vectors.transparent.zip_0316:main"
zip_0320 = "zcash_test_vectors.zip_0320:main"
zip_0320 = "zcash_test_vectors.transparent.zip_0320:main"
# Sapling test vectors
sapling_generators = "zcash_test_vectors.sapling.generators:main"

View File

@ -1,5 +1,5 @@
[
["From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/unified_address.py"],
["From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/transparent/zip_0320.py"],
["t_addr, p2pkh_bytes, tex_addr, account, child_index"],
["t1V9mnyk5Z5cTNMCkLbaDwSskgJZucTLdgW", "7bb83570b8fae146e03c5331a020b1e0892f631d", "tex10wur2u9clts5dcpu2vc6qg93uzyj7cca2xm732", 0, 0],
["t1LZdE42PAt1wREUv1YMYRFwJDPHPW8toLL", "1d81e86791c72d292f906e7c039a729e4b1ff7fc", "tex1rkq7seu3cukjjtusde7q8xnjne93laluyvdxu7", 0, 1],

View File

@ -6,7 +6,7 @@
child_index: u32,
};
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/unified_address.py
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/transparent/zip_0320.py
let test_vectors = vec![
TestVector {
t_addr: "t1V9mnyk5Z5cTNMCkLbaDwSskgJZucTLdgW",

View File

@ -1,5 +1,5 @@
[
["From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/unified_address.py"],
["From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/transparent/zip_0320.py"],
["t_addr, p2pkh_bytes, tex_addr, account, child_index"],
["t1V9mnyk5Z5cTNMCkLbaDwSskgJZucTLdgW", "7bb83570b8fae146e03c5331a020b1e0892f631d", "tex10wur2u9clts5dcpu2vc6qg93uzyj7cca2xm732", 0, 0],
["t1LZdE42PAt1wREUv1YMYRFwJDPHPW8toLL", "1d81e86791c72d292f906e7c039a729e4b1ff7fc", "tex1rkq7seu3cukjjtusde7q8xnjne93laluyvdxu7", 0, 1],

View File

@ -1,7 +1,6 @@
# Common definitions for hierarchical derivation.
ZCASH_MAIN_COINTYPE = 133
ZCASH_TEST_COINTYPE = 1
def hardened(i):
assert 0 <= i and i < (1<<31)

View File

@ -1,4 +1,17 @@
#!/usr/bin/env python3
import sys; assert sys.version_info[0] >= 3, "Python 3 required."
import math
from random import Random
import struct
import base58
from ..bech32m import bech32_encode, bech32_decode, convertbits, Encoding
from ..output import render_args, render_tv, Some
from ..rand import Rand, randbytes
from ..hd_common import ZCASH_MAIN_COINTYPE, hardened
from .bip_0032 import ExtendedSecretKey
class HrpMismatch(Exception):
pass
@ -15,4 +28,55 @@ def decode(hrp_expected, tex_addr):
raise InvalidEncoding("ZIP 320 addresses must be encoded using Bech32m")
if hrp != hrp_expected:
raise HrpMismatch("Expected: " + hrp_expected + "; got " + hrp)
return bytes(convertbits(data, 6, 8, False))
return bytes(convertbits(data, 5, 8, False))
def main():
args = render_args()
rng = Random(0xabad533d)
rand = Rand(randbytes(rng))
seed = bytes(range(32))
t_root_key = ExtendedSecretKey.master(seed)
t_purpose_key = t_root_key.child(hardened(44))
t_coin_key = t_purpose_key.child(hardened(ZCASH_MAIN_COINTYPE))
test_vectors = []
for account in range(0, 5):
for j in range(0, 3):
t_account_key = t_coin_key.child(hardened(account))
t_external_key = t_account_key.child(0)
t_index_key = t_external_key.child(j)
t_index_pubkey = t_index_key.public_key()
p2pkh_bytes = t_index_pubkey.address()
t_addr = base58.b58encode_check(bytes([0x1c, 0xb8]) + p2pkh_bytes).decode('utf-8')
tex_addr = encode("tex", p2pkh_bytes)
p2pkh_bytes_decoded = decode("tex", tex_addr)
assert p2pkh_bytes_decoded == p2pkh_bytes
test_vectors.append({
't_addr': t_addr,
'p2pkh_bytes': p2pkh_bytes,
'tex_addr': tex_addr,
'account': account,
'child_index': j,
})
render_tv(
args,
'transparent/zip_0320',
(
('t_addr', {'rust_type': '&\'static str'}),
('p2pkh_bytes', '[u8; 20]'),
('tex_addr', {'rust_type': '&\'static str'}),
('account', 'u32'),
('child_index', 'u32'),
),
test_vectors,
)
if __name__ == "__main__":
main()

View File

@ -1,65 +0,0 @@
#!/usr/bin/env python3
import sys; assert sys.version_info[0] >= 3, "Python 3 required."
import math
from random import Random
import struct
import base58
from .bech32m import bech32_encode, bech32_decode, convertbits, Encoding
from .output import render_args, render_tv, Some
from .rand import Rand, randbytes
from .transparent import bip_0032, zip_0320
from .hd_common import ZCASH_MAIN_COINTYPE, hardened
def main():
args = render_args()
rng = Random(0xabad533d)
rand = Rand(randbytes(rng))
seed = bytes(range(32))
t_root_key = bip_0032.ExtendedSecretKey.master(seed)
t_purpose_key = t_root_key.child(hardened(44))
t_coin_key = t_purpose_key.child(hardened(ZCASH_MAIN_COINTYPE))
test_vectors = []
for account in range(0, 5):
for j in range(0, 3):
t_account_key = t_coin_key.child(hardened(account))
t_external_key = t_account_key.child(0)
t_index_key = t_external_key.child(j)
t_index_pubkey = t_index_key.public_key()
p2pkh_bytes = t_index_pubkey.address()
t_addr = base58.b58encode_check(bytes([0x1c, 0xb8]) + p2pkh_bytes).decode('utf-8')
tex_addr = zip_0320.encode("tex", p2pkh_bytes)
p2pkh_bytes_decoded = zip_0320.decode("tex", tex_addr)
assert p2pkh_bytes_decoded == p2pkh_bytes
test_vectors.append({
't_addr': t_addr,
'p2pkh_bytes': p2pkh_bytes,
'tex_addr': tex_addr,
'account': account,
'child_index': j,
})
render_tv(
args,
'unified_address',
(
('t_addr', {'rust_type': '&\'static str'}),
('p2pkh_bytes', '[u8; 20]'),
('tex_addr', {'rust_type': '&\'static str'}),
('account', 'u32'),
('child_index', 'u32'),
),
test_vectors,
)
if __name__ == "__main__":
main()