Use the jubjub::AffinePoint in the canonical, encoded little-endian byte form in
Pedersen tests Keeps the librustzcash test vectors with their big-endian byte order as comments, for greppability.
This commit is contained in:
parent
a2c9011e06
commit
616d82faaf
|
@ -222,16 +222,6 @@ dependencies = [
|
||||||
"radium",
|
"radium",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bitvec"
|
|
||||||
version = "0.17.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "41262f11d771fd4a61aa3ce019fca363b4b6c282fca9da2a31186d3965a47a5c"
|
|
||||||
dependencies = [
|
|
||||||
"either",
|
|
||||||
"radium",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "blake2b_simd"
|
name = "blake2b_simd"
|
||||||
version = "0.5.10"
|
version = "0.5.10"
|
||||||
|
@ -698,12 +688,6 @@ version = "1.5.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
|
checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "either"
|
|
||||||
version = "1.5.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "equihash"
|
name = "equihash"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
|
@ -5,65 +5,63 @@
|
||||||
// enum variant from the original source.
|
// enum variant from the original source.
|
||||||
//
|
//
|
||||||
// The Python hex-encoded outputs for these test vectors were output in
|
// The Python hex-encoded outputs for these test vectors were output in
|
||||||
// big-endian byte order, so to parse them, we have to reverse their order; in
|
// big-endian byte order, so to parse them, we reversed their order; in
|
||||||
// librustzcash, they match their Display impl to match the Python hex strings
|
// librustzcash, they match their Display impl to match the Python hex strings
|
||||||
// and that's what they compare in their unit tests, not the bytes.
|
// and that's what they compare in their unit tests, not the bytes.
|
||||||
|
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
use bitvec::prelude::*;
|
use bitvec::prelude::*;
|
||||||
use jubjub::{AffinePoint, Fq};
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
fn point_from_hex<T: AsRef<[u8]>>(u_in_hex: T, v_in_hex: T) -> AffinePoint {
|
fn point_from_hex<T: AsRef<[u8]>>(point_in_hex: T) -> jubjub::AffinePoint {
|
||||||
let mut u_bytes = [0u8; 32];
|
let mut bytes = [0u8; 32];
|
||||||
let _ = hex::decode_to_slice(u_in_hex, &mut u_bytes);
|
let _ = hex::decode_to_slice(point_in_hex, &mut bytes);
|
||||||
// The test vectors were/are output in reverse-endian order.
|
|
||||||
u_bytes.reverse();
|
|
||||||
let u_scalar = Fq::from_bytes(&u_bytes).unwrap();
|
|
||||||
|
|
||||||
let mut v_bytes = [0u8; 32];
|
jubjub::AffinePoint::from_bytes(bytes).unwrap()
|
||||||
let _ = hex::decode_to_slice(v_in_hex, &mut v_bytes);
|
|
||||||
// The test vectors were/are output in reverse-endian order.
|
|
||||||
v_bytes.reverse();
|
|
||||||
let v_scalar = Fq::from_bytes(&v_bytes).unwrap();
|
|
||||||
|
|
||||||
AffinePoint::from_raw_unchecked(u_scalar, v_scalar)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TestVector {
|
pub struct TestVector {
|
||||||
pub input_bits: BitVec<Lsb0, u8>,
|
pub input_bits: BitVec<Lsb0, u8>,
|
||||||
pub output_point: AffinePoint,
|
pub output_point: jubjub::AffinePoint,
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref TEST_VECTORS: [TestVector; 12] = [
|
pub static ref TEST_VECTORS: [TestVector; 12] = [
|
||||||
TestVector {
|
TestVector {
|
||||||
input_bits: bitvec![Lsb0, u8; 1, 1, 1, 1, 1, 1],
|
input_bits: bitvec![Lsb0, u8; 1, 1, 1, 1, 1, 1],
|
||||||
|
// original librustzcash affine point test vector (in reversed-endian byte order):
|
||||||
|
// "06b1187c11ca4fb4383b2e0d0dbbde3ad3617338b5029187ec65a5eaed5e4d0b",
|
||||||
|
// "3ce70f536652f0dea496393a1e55c4e08b9d55508e16d11e5db40d4810cbc982"
|
||||||
output_point: point_from_hex(
|
output_point: point_from_hex(
|
||||||
"06b1187c11ca4fb4383b2e0d0dbbde3ad3617338b5029187ec65a5eaed5e4d0b",
|
"82c9cb10480db45d1ed1168e50559d8be0c4551e3a3996a4def05266530fe7bc"
|
||||||
"3ce70f536652f0dea496393a1e55c4e08b9d55508e16d11e5db40d4810cbc982"
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
TestVector {
|
TestVector {
|
||||||
input_bits: bitvec![Lsb0, u8; 1, 1, 1, 1, 1, 1, 0],
|
input_bits: bitvec![Lsb0, u8; 1, 1, 1, 1, 1, 1, 0],
|
||||||
|
// Original librustzcash affine point test vector (in reversed-endian byte order):
|
||||||
|
// "2fc3bc454c337f71d4f04f86304262fcbfc9ecd808716b92fc42cbe6827f7f1a",
|
||||||
|
// "46d0d25bf1a654eedc6a9b1e5af398925113959feac31b7a2c036ff9b9ec0638"
|
||||||
output_point: point_from_hex(
|
output_point: point_from_hex(
|
||||||
"2fc3bc454c337f71d4f04f86304262fcbfc9ecd808716b92fc42cbe6827f7f1a",
|
"3806ecb9f96f032c7a1bc3ea9f9513519298f35a1e9b6adcee54a6f15bd2d046"
|
||||||
"46d0d25bf1a654eedc6a9b1e5af398925113959feac31b7a2c036ff9b9ec0638"
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
TestVector {
|
TestVector {
|
||||||
input_bits: bitvec![Lsb0, u8; 1, 1, 1, 1, 1, 1, 1],
|
input_bits: bitvec![Lsb0, u8; 1, 1, 1, 1, 1, 1, 1],
|
||||||
|
// Original librustzcash affine point test vector (in reversed-endian byte order):
|
||||||
|
// "4f8ce0e0a9e674b3ab9606a7d7aefba386e81583d81918127814cde41d209d97",
|
||||||
|
// "312b5ab93b14c9b9af334fe1fe3c50fffb53fbd074fa40ca600febde7c97e346"
|
||||||
output_point: point_from_hex(
|
output_point: point_from_hex(
|
||||||
"4f8ce0e0a9e674b3ab9606a7d7aefba386e81583d81918127814cde41d209d97",
|
"46e3977cdeeb0f60ca40fa74d0fb53fbff503cfee14f33afb9c9143bb95a2bb1"
|
||||||
"312b5ab93b14c9b9af334fe1fe3c50fffb53fbd074fa40ca600febde7c97e346"
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
TestVector {
|
TestVector {
|
||||||
input_bits: bitvec![Lsb0, u8; 1, 1, 1, 1, 1, 1, 1, 0, 0],
|
input_bits: bitvec![Lsb0, u8; 1, 1, 1, 1, 1, 1, 1, 0, 0],
|
||||||
|
// Original librustzcash affine point test vector (in reversed-endian byte order):
|
||||||
|
// "4f8ce0e0a9e674b3ab9606a7d7aefba386e81583d81918127814cde41d209d97",
|
||||||
|
// "312b5ab93b14c9b9af334fe1fe3c50fffb53fbd074fa40ca600febde7c97e346"
|
||||||
output_point: point_from_hex(
|
output_point: point_from_hex(
|
||||||
"4f8ce0e0a9e674b3ab9606a7d7aefba386e81583d81918127814cde41d209d97",
|
"46e3977cdeeb0f60ca40fa74d0fb53fbff503cfee14f33afb9c9143bb95a2bb1"
|
||||||
"312b5ab93b14c9b9af334fe1fe3c50fffb53fbd074fa40ca600febde7c97e346"
|
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
TestVector {
|
TestVector {
|
||||||
|
@ -76,9 +74,11 @@ lazy_static! {
|
||||||
1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1,
|
1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1,
|
||||||
0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0,
|
0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0,
|
||||||
],
|
],
|
||||||
|
// Original librustzcash affine point test vector (in reversed-endian byte order):
|
||||||
|
// "599ab788360ae8c6d5bb7618aec37056d6227408d857fdc394078a3d7afdfe0f",
|
||||||
|
// "4320c373da670e28d168f4ffd72b43208e8c815f40841682c57a3ee1d005a527"
|
||||||
output_point: point_from_hex(
|
output_point: point_from_hex(
|
||||||
"599ab788360ae8c6d5bb7618aec37056d6227408d857fdc394078a3d7afdfe0f",
|
"27a505d0e13e7ac5821684405f818c8e20432bd7fff468d1280e67da73c320c3"
|
||||||
"4320c373da670e28d168f4ffd72b43208e8c815f40841682c57a3ee1d005a527"
|
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
TestVector {
|
TestVector {
|
||||||
|
@ -91,9 +91,11 @@ lazy_static! {
|
||||||
0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0,
|
0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0,
|
||||||
1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0,
|
1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0,
|
||||||
],
|
],
|
||||||
|
// Original librustzcash affine point test vector (in reversed-endian byte order):
|
||||||
|
// "2da510317620f5dfdce1f31db6019f947eedcf02ff2972cff597a5c3ad21f5dd",
|
||||||
|
// "198789969c0c33e6c359b9da4a51771f4d50863f36beef90436944fe568399f2"
|
||||||
output_point: point_from_hex(
|
output_point: point_from_hex(
|
||||||
"2da510317620f5dfdce1f31db6019f947eedcf02ff2972cff597a5c3ad21f5dd",
|
"f2998356fe44694390efbe363f86504d1f77514adab959c3e6330c9c96898799"
|
||||||
"198789969c0c33e6c359b9da4a51771f4d50863f36beef90436944fe568399f2"
|
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
TestVector {
|
TestVector {
|
||||||
|
@ -106,9 +108,11 @@ lazy_static! {
|
||||||
0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0,
|
0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0,
|
||||||
0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1,
|
0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1,
|
||||||
],
|
],
|
||||||
|
// Original librustzcash affine point test vector (in reversed-endian byte order):
|
||||||
|
// "601247c7e640992d193dfb51df6ed93446687a7f2bcd0e4a598e6feb1ef20c40",
|
||||||
|
// "371931733b73e7b95c2cad55a6cebd15c83619f697c64283e54e5ef61442a743"
|
||||||
output_point: point_from_hex(
|
output_point: point_from_hex(
|
||||||
"601247c7e640992d193dfb51df6ed93446687a7f2bcd0e4a598e6feb1ef20c40",
|
"43a74214f65e4ee58342c697f61936c815bdcea655ad2c5cb9e7733b73311937"
|
||||||
"371931733b73e7b95c2cad55a6cebd15c83619f697c64283e54e5ef61442a743"
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
TestVector {
|
TestVector {
|
||||||
|
@ -141,9 +145,11 @@ lazy_static! {
|
||||||
1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1,
|
1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1,
|
||||||
1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
|
1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
|
||||||
],
|
],
|
||||||
|
// Original librustzcash affine point test vector (in reversed-endian byte order):
|
||||||
|
// "314192ecb1f2d8806a8108704c875a25d9fb7e444f9f373919adedebe8f2ae27",
|
||||||
|
// "6b12b32f1372ad574799dee9eb591d961b704bf611f55fcc71f7e82cd3330b74"
|
||||||
output_point: point_from_hex(
|
output_point: point_from_hex(
|
||||||
"314192ecb1f2d8806a8108704c875a25d9fb7e444f9f373919adedebe8f2ae27",
|
"740b33d32ce8f771cc5ff511f64b701b961d59ebe9de994757ad72132fb312eb"
|
||||||
"6b12b32f1372ad574799dee9eb591d961b704bf611f55fcc71f7e82cd3330b74"
|
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
TestVector {
|
TestVector {
|
||||||
|
@ -177,9 +183,11 @@ lazy_static! {
|
||||||
1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1,
|
1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1,
|
||||||
0,
|
0,
|
||||||
],
|
],
|
||||||
|
// Original librustzcash affine point test vector (in reversed-endian byte order):
|
||||||
|
// "0666c2bce7f362a2b807d212e9a577f116891a932affd7addec39fbf372c494e",
|
||||||
|
// "6758bccfaf2e47c07756b96edea23aa8d10c33b38220bd1c411af612eeec18ab"
|
||||||
output_point: point_from_hex(
|
output_point: point_from_hex(
|
||||||
"0666c2bce7f362a2b807d212e9a577f116891a932affd7addec39fbf372c494e",
|
"ab18ecee12f61a411cbd2082b3330cd1a83aa2de6eb95677c0472eafcfbc5867"
|
||||||
"6758bccfaf2e47c07756b96edea23aa8d10c33b38220bd1c411af612eeec18ab"
|
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
TestVector {
|
TestVector {
|
||||||
|
@ -219,9 +227,11 @@ lazy_static! {
|
||||||
0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0,
|
0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0,
|
||||||
1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1,
|
1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1,
|
||||||
],
|
],
|
||||||
|
// Original librustzcash affine point test vector (in reversed-endian byte order):
|
||||||
|
// "130afe02b99375484efb0998f5331d2178e1d00e803049bb0769099420624f5f",
|
||||||
|
// "5e2fc6970554ffe358652aa7968ac4fcf3de0c830e6ea492e01a38fafb68cd71"
|
||||||
output_point: point_from_hex(
|
output_point: point_from_hex(
|
||||||
"130afe02b99375484efb0998f5331d2178e1d00e803049bb0769099420624f5f",
|
"71cd68fbfa381ae092a46e0e830cdef3fcc48a96a72a6558e3ff540597c62fde"
|
||||||
"5e2fc6970554ffe358652aa7968ac4fcf3de0c830e6ea492e01a38fafb68cd71"
|
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
TestVector {
|
TestVector {
|
||||||
|
@ -261,9 +271,11 @@ lazy_static! {
|
||||||
0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1,
|
0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1,
|
||||||
1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1,
|
1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1,
|
||||||
],
|
],
|
||||||
|
// Original librustzcash affine point test vector (in reversed-endian byte order):
|
||||||
|
// "67914ebd539961b70f468fa23d4cb42133693a8ac57cd35a1e6369fe34fbedf7",
|
||||||
|
// "44770870c0f0cfe59a10df95d6c21e6f1514a2f464b66377599438c126052d9f"
|
||||||
output_point: point_from_hex(
|
output_point: point_from_hex(
|
||||||
"67914ebd539961b70f468fa23d4cb42133693a8ac57cd35a1e6369fe34fbedf7",
|
"9f2d0526c13894597763b664f4a214156f1ec2d695df109ae5cff0c0700877c4"
|
||||||
"44770870c0f0cfe59a10df95d6c21e6f1514a2f464b66377599438c126052d9f"
|
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
TestVector {
|
TestVector {
|
||||||
|
@ -276,9 +288,11 @@ lazy_static! {
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||||
],
|
],
|
||||||
|
// Original librustzcash affine point test vector (in reversed-endian byte order):
|
||||||
|
// "329e3bb2ca31ea6e13a986730237f6fd16b842a510cbabe851bdbcf57d75ee0d",
|
||||||
|
// "471d2109656afcb96d0609b371b132b97efcf72c6051064dd19fdc004799bfa9"
|
||||||
output_point: point_from_hex(
|
output_point: point_from_hex(
|
||||||
"329e3bb2ca31ea6e13a986730237f6fd16b842a510cbabe851bdbcf57d75ee0d",
|
"a9bf994700dc9fd14d0651602cf7fc7eb932b171b309066db9fc6a6509211dc7"
|
||||||
"471d2109656afcb96d0609b371b132b97efcf72c6051064dd19fdc004799bfa9"
|
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
|
@ -246,7 +246,7 @@ impl ZcashDeserialize for TransparentOutput {
|
||||||
fn zcash_deserialize<R: io::Read>(mut reader: R) -> Result<Self, SerializationError> {
|
fn zcash_deserialize<R: io::Read>(mut reader: R) -> Result<Self, SerializationError> {
|
||||||
Ok(TransparentOutput {
|
Ok(TransparentOutput {
|
||||||
value: reader.read_u64::<LittleEndian>()?.try_into()?,
|
value: reader.read_u64::<LittleEndian>()?.try_into()?,
|
||||||
lock_script: tyoes::Script::zcash_deserialize(&mut reader)?,
|
lock_script: types::Script::zcash_deserialize(&mut reader)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue