From da31c3388a09c4808e820ab399c7eee4b9c6586e Mon Sep 17 00:00:00 2001 From: str4d Date: Sat, 19 May 2018 07:19:33 +1200 Subject: [PATCH] Test note commitment in key component test vectors --- src/tests/key_components.rs | 123 ++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/src/tests/key_components.rs b/src/tests/key_components.rs index a1f7f0a..af3278e 100644 --- a/src/tests/key_components.rs +++ b/src/tests/key_components.rs @@ -17,6 +17,9 @@ fn key_components() { ivk: [u8; 32], default_d: [u8; 11], default_pk_d: [u8; 32], + note_v: u64, + note_r: [u8; 32], + note_cm: [u8; 32], }; // From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/sapling_key_components.py @@ -65,6 +68,17 @@ fn key_components() { 0xc4, 0x45, 0xa9, 0x55, 0x51, 0x26, 0xd3, 0xc2, 0x9f, 0x14, 0xe3, 0xd7, 0x76, 0xe8, 0x41, 0xae, 0x74, 0x15, ], + note_v: 0, + note_r: [ + 0x39, 0x17, 0x6d, 0xac, 0x39, 0xac, 0xe4, 0x98, 0x0e, 0xcc, 0x8d, 0x77, 0x8e, 0x89, + 0x86, 0x02, 0x55, 0xec, 0x36, 0x15, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + ], + note_cm: [ + 0xcb, 0x3c, 0xf9, 0x15, 0x32, 0x70, 0xd5, 0x7e, 0xb9, 0x14, 0xc6, 0xc2, 0xbc, 0xc0, + 0x18, 0x50, 0xc9, 0xfe, 0xd4, 0x4f, 0xce, 0x08, 0x06, 0x27, 0x8f, 0x08, 0x3e, 0xf2, + 0xdd, 0x07, 0x64, 0x39, + ], }, TestVector { sk: [ @@ -110,6 +124,17 @@ fn key_components() { 0xd3, 0xcf, 0xb3, 0x92, 0x10, 0x83, 0x1e, 0xa3, 0xa2, 0x96, 0xba, 0x09, 0xa9, 0x22, 0x06, 0x0f, 0xd3, 0x8b, ], + note_v: 12227227834928555328, + note_r: [ + 0x47, 0x8b, 0xa0, 0xee, 0x6e, 0x1a, 0x75, 0xb6, 0x00, 0x03, 0x6f, 0x26, 0xf1, 0x8b, + 0x70, 0x15, 0xab, 0x55, 0x6b, 0xed, 0xdf, 0x8b, 0x96, 0x02, 0x38, 0x86, 0x9f, 0x89, + 0xdd, 0x80, 0x4e, 0x06, + ], + note_cm: [ + 0xb5, 0x78, 0x93, 0x50, 0x0b, 0xfb, 0x85, 0xdf, 0x2e, 0x8b, 0x01, 0xac, 0x45, 0x2f, + 0x89, 0xe1, 0x0e, 0x26, 0x6b, 0xcf, 0xa3, 0x1c, 0x31, 0xb2, 0x9a, 0x53, 0xae, 0x72, + 0xca, 0xd4, 0x69, 0x50, + ], }, TestVector { sk: [ @@ -155,6 +180,17 @@ fn key_components() { 0x5e, 0xed, 0x4d, 0x44, 0xc6, 0x22, 0x5c, 0x3c, 0x65, 0xd8, 0x8d, 0xd9, 0x90, 0x77, 0x08, 0x01, 0x2f, 0x5a, ], + note_v: 6007711596147559040, + note_r: [ + 0x14, 0x7c, 0xf2, 0xb5, 0x1b, 0x4c, 0x7c, 0x63, 0xcb, 0x77, 0xb9, 0x9e, 0x8b, 0x78, + 0x3e, 0x5b, 0x51, 0x11, 0xdb, 0x0a, 0x7c, 0xa0, 0x4d, 0x6c, 0x01, 0x4a, 0x1d, 0x7d, + 0xa8, 0x3b, 0xae, 0x0a, + ], + note_cm: [ + 0xdb, 0x85, 0xa7, 0x0a, 0x98, 0x43, 0x7f, 0x73, 0x16, 0x7f, 0xc3, 0x32, 0xd5, 0xb7, + 0xb7, 0x40, 0x82, 0x96, 0x66, 0x17, 0x70, 0xb1, 0x01, 0xb0, 0xaa, 0x87, 0x83, 0x9f, + 0x4e, 0x55, 0xf1, 0x51, + ], }, TestVector { sk: [ @@ -200,6 +236,17 @@ fn key_components() { 0xea, 0xd7, 0x83, 0x2f, 0xb1, 0xf0, 0xf7, 0xa8, 0x31, 0x65, 0x89, 0x5b, 0xdf, 0xf9, 0x42, 0x92, 0x5f, 0x5c, ], + note_v: 18234939431076114368, + note_r: [ + 0x34, 0xa4, 0xb2, 0xa9, 0x14, 0x4f, 0xf5, 0xea, 0x54, 0xef, 0xee, 0x87, 0xcf, 0x90, + 0x1b, 0x5b, 0xed, 0x5e, 0x35, 0xd2, 0x1f, 0xbb, 0xd7, 0x88, 0xd5, 0xbd, 0x9d, 0x83, + 0x3e, 0x11, 0x28, 0x04, + ], + note_cm: [ + 0xe0, 0x8c, 0xe4, 0x82, 0xb3, 0xa8, 0xfb, 0x3b, 0x35, 0xcc, 0xdb, 0xe3, 0x43, 0x37, + 0xbd, 0x10, 0x5d, 0x88, 0x39, 0x21, 0x2e, 0x0d, 0x16, 0x44, 0xb9, 0xd5, 0x5c, 0xaa, + 0x60, 0xd1, 0x9b, 0x6c, + ], }, TestVector { sk: [ @@ -245,6 +292,17 @@ fn key_components() { 0x69, 0x77, 0xf9, 0x05, 0x22, 0xe9, 0x2f, 0xde, 0x44, 0xc9, 0xd1, 0xbb, 0x09, 0x97, 0x14, 0xb9, 0xdb, 0x2b, ], + note_v: 12015423192295118080, + note_r: [ + 0xe5, 0x57, 0x85, 0x13, 0x55, 0x74, 0x7c, 0x09, 0xac, 0x59, 0x01, 0x3c, 0xbd, 0xe8, + 0x59, 0x80, 0x96, 0x4e, 0xc1, 0x84, 0x4d, 0x9c, 0x69, 0x67, 0xca, 0x0c, 0x02, 0x9c, + 0x84, 0x57, 0xbb, 0x04, + ], + note_cm: [ + 0xbd, 0xc8, 0x54, 0xbf, 0x3e, 0x7b, 0x00, 0x82, 0x1f, 0x3b, 0x8b, 0x85, 0x23, 0x8c, + 0xcf, 0x1e, 0x67, 0x15, 0xbf, 0xe7, 0x0b, 0x63, 0x2d, 0x04, 0x4b, 0x26, 0xfb, 0x2b, + 0xc7, 0x1b, 0x7f, 0x36, + ], }, TestVector { sk: [ @@ -290,6 +348,17 @@ fn key_components() { 0x97, 0x86, 0x64, 0x8a, 0x11, 0xb5, 0x96, 0x6e, 0x51, 0xa2, 0xf7, 0xd8, 0x9e, 0x15, 0xd2, 0x9b, 0x8f, 0xdf, ], + note_v: 5795906953514121792, + note_r: [ + 0x68, 0xf0, 0x61, 0x04, 0x60, 0x6b, 0x0c, 0x54, 0x49, 0x84, 0x5f, 0xf4, 0xc6, 0x5f, + 0x73, 0xe9, 0x0f, 0x45, 0xef, 0x5a, 0x43, 0xc9, 0xd7, 0x4c, 0xb2, 0xc8, 0x5c, 0xf5, + 0x6c, 0x94, 0xc0, 0x02, + ], + note_cm: [ + 0xe8, 0x26, 0x7d, 0x30, 0xac, 0x11, 0xc1, 0x00, 0xbc, 0x7a, 0x0f, 0xdf, 0x91, 0xf7, + 0x1d, 0x74, 0xc5, 0xbc, 0xf2, 0xe1, 0xef, 0x95, 0x66, 0x90, 0x44, 0x73, 0x01, 0x69, + 0xde, 0x1a, 0x5b, 0x4c, + ], }, TestVector { sk: [ @@ -335,6 +404,17 @@ fn key_components() { 0x71, 0xd2, 0x23, 0x49, 0x3c, 0x69, 0x80, 0x25, 0x44, 0x04, 0x3f, 0x77, 0xcf, 0x1d, 0x71, 0xc1, 0xcb, 0x8c, ], + note_v: 18023134788442677120, + note_r: [ + 0x49, 0xf9, 0x0b, 0x47, 0xfd, 0x52, 0xfe, 0xe7, 0xc1, 0xc8, 0x1f, 0x0d, 0xcb, 0x5b, + 0x74, 0xc3, 0xfb, 0x9b, 0x3e, 0x03, 0x97, 0x6f, 0x8b, 0x75, 0x24, 0xea, 0xba, 0xd0, + 0x08, 0x89, 0x21, 0x07, + ], + note_cm: [ + 0x57, 0x2b, 0xa2, 0x05, 0x25, 0xb0, 0xac, 0x4d, 0x6d, 0xc0, 0x1a, 0xc2, 0xea, 0x10, + 0x90, 0xb6, 0xe0, 0xf2, 0xf4, 0xbf, 0x4e, 0xc4, 0xa0, 0xdb, 0x5b, 0xbc, 0xcb, 0x5b, + 0x78, 0x3a, 0x1e, 0x55, + ], }, TestVector { sk: [ @@ -380,6 +460,17 @@ fn key_components() { 0xc4, 0xc8, 0xf7, 0x28, 0x13, 0x2c, 0xc1, 0x24, 0x56, 0x94, 0x6e, 0x7f, 0x4c, 0xb0, 0xfb, 0x05, 0x8d, 0xa9, ], + note_v: 11803618549661680832, + note_r: [ + 0x51, 0x65, 0xaf, 0xf2, 0x2d, 0xd4, 0xed, 0x56, 0xb4, 0xd8, 0x1d, 0x1f, 0x17, 0x1c, + 0xc3, 0xd6, 0x43, 0x2f, 0xed, 0x1b, 0xeb, 0xf2, 0x0a, 0x7b, 0xea, 0xb1, 0x2d, 0xb1, + 0x42, 0xf9, 0x4a, 0x0c, + ], + note_cm: [ + 0xab, 0x7f, 0xc5, 0x66, 0x87, 0x3c, 0xcd, 0xe6, 0x71, 0xf5, 0x98, 0x27, 0x67, 0x85, + 0x60, 0xa0, 0x06, 0xf8, 0x2b, 0xb7, 0xad, 0xcd, 0x75, 0x22, 0x3f, 0xa8, 0x59, 0x36, + 0xf7, 0x8c, 0x2b, 0x23, + ], }, TestVector { sk: [ @@ -425,6 +516,17 @@ fn key_components() { 0x59, 0x45, 0xa4, 0x6d, 0x4f, 0xed, 0xf8, 0x06, 0x08, 0x28, 0x04, 0x1c, 0xd2, 0x0e, 0x62, 0xfd, 0x2c, 0xef, ], + note_v: 5584102310880684544, + note_r: [ + 0x8c, 0x3e, 0x56, 0x44, 0x9d, 0xc8, 0x63, 0x54, 0xd3, 0x3b, 0x02, 0x5e, 0xf2, 0x79, + 0x34, 0x60, 0xbc, 0xb1, 0x69, 0xf3, 0x32, 0x4e, 0x4a, 0x6b, 0x64, 0xba, 0xa6, 0x08, + 0x32, 0x31, 0x57, 0x04, + ], + note_cm: [ + 0x7b, 0x48, 0xa8, 0x37, 0x5d, 0x3e, 0xbd, 0x56, 0xbc, 0x64, 0x9b, 0xb5, 0xb5, 0x24, + 0x23, 0x36, 0xc2, 0xa0, 0x5a, 0x08, 0x03, 0x23, 0x9b, 0x5b, 0x88, 0xfd, 0x92, 0x07, + 0x8f, 0xea, 0x4d, 0x04, + ], }, TestVector { sk: [ @@ -470,6 +572,17 @@ fn key_components() { 0x25, 0x25, 0x5f, 0x7e, 0xe4, 0x87, 0x38, 0x5a, 0x30, 0x31, 0x6e, 0x15, 0xf6, 0x48, 0x2b, 0x87, 0x4f, 0xda, ], + note_v: 17811330145809239872, + note_r: [ + 0x6e, 0xbb, 0xed, 0x74, 0x36, 0x19, 0xa2, 0x56, 0xf9, 0xad, 0x2e, 0x85, 0x88, 0x0c, + 0xfa, 0xa9, 0x09, 0x8a, 0x5f, 0xdb, 0x16, 0x29, 0x99, 0x0d, 0x9a, 0x7d, 0x3b, 0xb9, + 0x3f, 0xc9, 0x00, 0x03, + ], + note_cm: [ + 0xd3, 0x76, 0xa7, 0xbe, 0xe8, 0xce, 0x67, 0xf4, 0xef, 0xde, 0x56, 0xaa, 0x77, 0xcf, + 0x64, 0x41, 0x9b, 0x0e, 0x55, 0x0a, 0xbb, 0xcb, 0x8e, 0x2b, 0xcb, 0xda, 0x8b, 0x63, + 0xe4, 0x1d, 0xeb, 0x37, + ], }, ]; @@ -510,5 +623,15 @@ fn key_components() { addr.pk_d.write(&mut vec).unwrap(); assert_eq!(&vec, &tv.default_pk_d); } + + let mut note_r_repr = FsRepr::default(); + note_r_repr.read_le(&tv.note_r[..]).unwrap(); + let note_r = ::Fs::from_repr(note_r_repr).unwrap(); + let note = addr.create_note(tv.note_v, note_r, &JUBJUB).unwrap(); + { + let mut vec = Vec::new(); + note.cm(&JUBJUB).into_repr().write_le(&mut vec).unwrap(); + assert_eq!(&vec, &tv.note_cm); + } } }