Add test vectors for `zip_0032_registered`.

Co-authored-by: Jack Grigg <jack@electriccoin.co>
Co-authored-by: Kris Nuttycombe <kris@nutty.land>
Signed-off-by: Daira-Emma Hopwood <daira@jacaranda.org>
This commit is contained in:
Daira-Emma Hopwood 2025-02-20 05:36:35 +00:00
parent 0f20d79f3d
commit cbfe5ed828
6 changed files with 160 additions and 0 deletions

View File

@ -41,6 +41,7 @@ f4jumble_long = "zcash_test_vectors.f4jumble:long_test_vectors"
unified_address = "zcash_test_vectors.unified_address:main"
unified_full_viewing_keys = "zcash_test_vectors.unified_full_viewing_keys:main"
unified_incoming_viewing_keys = "zcash_test_vectors.unified_incoming_viewing_keys:main"
zip_0032_registered = "zcash_test_vectors.zip_0032:registered_key_derivation_tvs"
zip_0032_arbitrary = "zcash_test_vectors.zip_0032:arbitrary_key_derivation_tvs"
zip_0143 = "zcash_test_vectors.zip_0143:main"
zip_0243 = "zcash_test_vectors.zip_0243:main"

View File

@ -45,6 +45,7 @@ case "$2" in
unified_address
unified_full_viewing_keys
unified_incoming_viewing_keys
zip_0032_registered
zip_0032_arbitrary
zip_0143
zip_0243

View File

@ -0,0 +1,7 @@
[
["From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/zip_0032_registered.py"],
["context_string, seed, zip_number, subpath, sk, c, full_width"],
["5a63617368207465737420766563746f7273", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 1, [], "53a71507e6dfda588bc1e138c2657c9269e55f5d9b99e3887c134008193a2f47", "08bb26aae21d4efdc3249b9557fcd9131e8b9827241d9f61d0d774bb4fed3de6", null],
["5a63617368207465737420766563746f7273", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 1, [[2147483650, "7472616e7320726967687473206172652068756d616e20726967687473"]], "02dc25cc40310eed08b028e07fae9adbee2fbe56a4694def0401e656dfae0211", "d8f9d8a1f81d1b5d5506b5ff942d2ff3dae7a63f57d6b8c7fbe58149823cc6ec", "255d75b5f97dd880a14460ab0a28938e7ba497ceb1457fff2992e9015a8403f8c08112b7a94cf539c21c9da7ee99897be9476b6813532ee22c8947d753b72bdf"],
["5a63617368207465737420766563746f7273", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 1, [[2147483650, "7472616e7320726967687473206172652068756d616e20726967687473"], [2147483651, ""]], "a127db66628b256e5b664d54050c1e6b028963aea22b04d1bc6f48123674ed82", "340084033605edca11463ffec56bf0cac425c410e953628671cec6a6514c32a8", "7f853eef001b1bc5a1a5e67f5dfd0e90427596d4842f5b10a111e97c4073203cedf6b80a85145e5061acd29bc5a4e349b14f8557a7033e23b066b7ce2409d973"]
]

View File

@ -0,0 +1,74 @@
struct TestVector {
context_string: &'static [u8],
seed: [u8; 32],
zip_number: u16,
subpath: &'static [(u32, &'static [u8])],
sk: [u8; 32],
c: [u8; 32],
full_width: Option<[u8; 64]>,
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/zip_0032_registered.py
const TEST_VECTORS: &[TestVector] = &[
TestVector {
context_string: &[
0x5a, 0x63, 0x61, 0x73, 0x68, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73
],
seed: [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
],
zip_number: 1,
subpath: &[
],
sk: [
0x53, 0xa7, 0x15, 0x07, 0xe6, 0xdf, 0xda, 0x58, 0x8b, 0xc1, 0xe1, 0x38, 0xc2, 0x65, 0x7c, 0x92, 0x69, 0xe5, 0x5f, 0x5d, 0x9b, 0x99, 0xe3, 0x88, 0x7c, 0x13, 0x40, 0x08, 0x19, 0x3a, 0x2f, 0x47
],
c: [
0x08, 0xbb, 0x26, 0xaa, 0xe2, 0x1d, 0x4e, 0xfd, 0xc3, 0x24, 0x9b, 0x95, 0x57, 0xfc, 0xd9, 0x13, 0x1e, 0x8b, 0x98, 0x27, 0x24, 0x1d, 0x9f, 0x61, 0xd0, 0xd7, 0x74, 0xbb, 0x4f, 0xed, 0x3d, 0xe6
],
full_width: None,
},
TestVector {
context_string: &[
0x5a, 0x63, 0x61, 0x73, 0x68, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73
],
seed: [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
],
zip_number: 1,
subpath: &[
(2147483650, &[0x74, 0x72, 0x61, 0x6e, 0x73, 0x20, 0x72, 0x69, 0x67, 0x68, 0x74, 0x73, 0x20, 0x61, 0x72, 0x65, 0x20, 0x68, 0x75, 0x6d, 0x61, 0x6e, 0x20, 0x72, 0x69, 0x67, 0x68, 0x74, 0x73]),
],
sk: [
0x02, 0xdc, 0x25, 0xcc, 0x40, 0x31, 0x0e, 0xed, 0x08, 0xb0, 0x28, 0xe0, 0x7f, 0xae, 0x9a, 0xdb, 0xee, 0x2f, 0xbe, 0x56, 0xa4, 0x69, 0x4d, 0xef, 0x04, 0x01, 0xe6, 0x56, 0xdf, 0xae, 0x02, 0x11
],
c: [
0xd8, 0xf9, 0xd8, 0xa1, 0xf8, 0x1d, 0x1b, 0x5d, 0x55, 0x06, 0xb5, 0xff, 0x94, 0x2d, 0x2f, 0xf3, 0xda, 0xe7, 0xa6, 0x3f, 0x57, 0xd6, 0xb8, 0xc7, 0xfb, 0xe5, 0x81, 0x49, 0x82, 0x3c, 0xc6, 0xec
],
full_width: Some([
0x25, 0x5d, 0x75, 0xb5, 0xf9, 0x7d, 0xd8, 0x80, 0xa1, 0x44, 0x60, 0xab, 0x0a, 0x28, 0x93, 0x8e, 0x7b, 0xa4, 0x97, 0xce, 0xb1, 0x45, 0x7f, 0xff, 0x29, 0x92, 0xe9, 0x01, 0x5a, 0x84, 0x03, 0xf8, 0xc0, 0x81, 0x12, 0xb7, 0xa9, 0x4c, 0xf5, 0x39, 0xc2, 0x1c, 0x9d, 0xa7, 0xee, 0x99, 0x89, 0x7b, 0xe9, 0x47, 0x6b, 0x68, 0x13, 0x53, 0x2e, 0xe2, 0x2c, 0x89, 0x47, 0xd7, 0x53, 0xb7, 0x2b, 0xdf
]),
},
TestVector {
context_string: &[
0x5a, 0x63, 0x61, 0x73, 0x68, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73
],
seed: [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
],
zip_number: 1,
subpath: &[
(2147483650, &[0x74, 0x72, 0x61, 0x6e, 0x73, 0x20, 0x72, 0x69, 0x67, 0x68, 0x74, 0x73, 0x20, 0x61, 0x72, 0x65, 0x20, 0x68, 0x75, 0x6d, 0x61, 0x6e, 0x20, 0x72, 0x69, 0x67, 0x68, 0x74, 0x73]),
(2147483651, &[]),
],
sk: [
0xa1, 0x27, 0xdb, 0x66, 0x62, 0x8b, 0x25, 0x6e, 0x5b, 0x66, 0x4d, 0x54, 0x05, 0x0c, 0x1e, 0x6b, 0x02, 0x89, 0x63, 0xae, 0xa2, 0x2b, 0x04, 0xd1, 0xbc, 0x6f, 0x48, 0x12, 0x36, 0x74, 0xed, 0x82
],
c: [
0x34, 0x00, 0x84, 0x03, 0x36, 0x05, 0xed, 0xca, 0x11, 0x46, 0x3f, 0xfe, 0xc5, 0x6b, 0xf0, 0xca, 0xc4, 0x25, 0xc4, 0x10, 0xe9, 0x53, 0x62, 0x86, 0x71, 0xce, 0xc6, 0xa6, 0x51, 0x4c, 0x32, 0xa8
],
full_width: Some([
0x7f, 0x85, 0x3e, 0xef, 0x00, 0x1b, 0x1b, 0xc5, 0xa1, 0xa5, 0xe6, 0x7f, 0x5d, 0xfd, 0x0e, 0x90, 0x42, 0x75, 0x96, 0xd4, 0x84, 0x2f, 0x5b, 0x10, 0xa1, 0x11, 0xe9, 0x7c, 0x40, 0x73, 0x20, 0x3c, 0xed, 0xf6, 0xb8, 0x0a, 0x85, 0x14, 0x5e, 0x50, 0x61, 0xac, 0xd2, 0x9b, 0xc5, 0xa4, 0xe3, 0x49, 0xb1, 0x4f, 0x85, 0x57, 0xa7, 0x03, 0x3e, 0x23, 0xb0, 0x66, 0xb7, 0xce, 0x24, 0x09, 0xd9, 0x73
]),
},
];

View File

@ -0,0 +1,7 @@
[
["From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/zip_0032_registered.py"],
["context_string, seed, zip_number, subpath, sk, c, full_width"],
["5a63617368207465737420766563746f7273", "1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100", 1, [], "472f3a190840137c88e3999b5d5fe569927c65c238e1c18b58dadfe60715a753", "e63ded4fbb74d7d0619f1d2427988b1e13d9fc57959b24c3fd4e1de2aa26bb08", null],
["5a63617368207465737420766563746f7273", "1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100", 1, [[2147483650, "7472616e7320726967687473206172652068756d616e20726967687473"]], "1102aedf56e60104ef4d69a456be2feedb9aae7fe028b008ed0e3140cc25dc02", "ecc63c824981e5fbc7b8d6573fa6e7daf32f2d94ffb506555d1b1df8a1d8f9d8", "255d75b5f97dd880a14460ab0a28938e7ba497ceb1457fff2992e9015a8403f8c08112b7a94cf539c21c9da7ee99897be9476b6813532ee22c8947d753b72bdf"],
["5a63617368207465737420766563746f7273", "1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100", 1, [[2147483650, "7472616e7320726967687473206172652068756d616e20726967687473"], [2147483651, ""]], "82ed743612486fbcd1042ba2ae6389026b1e0c05544d665b6e258b6266db27a1", "a8324c51a6c6ce71866253e910c425c4caf06bc5fe3f4611caed053603840034", "7f853eef001b1bc5a1a5e67f5dfd0e90427596d4842f5b10a111e97c4073203cedf6b80a85145e5061acd29bc5a4e349b14f8557a7033e23b066b7ce2409d973"]
]

View File

@ -38,6 +38,76 @@ def CKDh(Context, sk_par, c_par, i, lead, tag):
I_R = I[32:]
return (I_L, I_R)
class RegisteredKey(object):
Registered = HardenedOnlyContext(b'ZIPRegistered_KD', b'\xAC')
def __init__(self, IKM, subpath, sk, chaincode, full_width=None):
self.IKM = IKM
self.subpath = subpath
self.sk = sk
self.chaincode = chaincode
self.full_width = full_width # the full-width cryptovalue at this path
@classmethod
def subtree_root(cls, ContextString, S, ZipNumber):
length_ContextString = len(ContextString)
length_S = len(S)
assert length_ContextString <= 252
assert 32 <= length_S <= 252
IKM = bytes([length_ContextString]) + ContextString + bytes([length_S]) + S
(sk_m, c_m) = MKGh(cls.Registered, IKM)
(sk, chaincode) = CKDh(cls.Registered, sk_m, c_m, hardened(ZipNumber), 0, b"")
return cls(IKM, [], sk, chaincode)
def child(self, i, tag):
(sk_child, c_child) = CKDh(self.Registered, self.sk, self.chaincode, i, 0, tag)
(I_L, I_R) = CKDh(self.Registered, self.sk, self.chaincode, i, 1, tag)
return self.__class__(None, self.subpath + [(i, tag)], sk_child, c_child, I_L + I_R)
def registered_key_derivation_tvs():
args = render_args()
context_string = b'Zcash test vectors'
seed = bytes(range(32))
m_1h = RegisteredKey.subtree_root(context_string, seed, 1)
m_1h_2h = m_1h.child(hardened(2), b"trans rights are human rights")
m_1h_2h_3h = m_1h_2h.child(hardened(3), b"")
keys = [m_1h, m_1h_2h, m_1h_2h_3h]
test_vectors = [
{
'context_string': context_string,
'seed': seed,
'zip_number': 1,
'subpath': k.subpath,
'sk': k.sk,
'c': k.chaincode,
'full_width': k.full_width,
}
for k in keys
]
render_tv(
args,
'zip_0032_registered',
(
('context_string', '&\'static [u8]'),
('seed', '[u8; 32]'),
('zip_number', 'u16'),
('subpath', '&\'static [(u32, &\'static [u8])]'),
('sk', '[u8; 32]'),
('c', '[u8; 32]'),
('full_width', 'Option<[u8; 64]>'),
),
test_vectors,
)
class ArbitraryKey(object):
Adhoc = HardenedOnlyContext(b'ZcashArbitraryKD', b'\xAB')