From f07451a0253978727a1633204405c6caf45ac100 Mon Sep 17 00:00:00 2001 From: Daira Hopwood Date: Tue, 8 Feb 2022 13:48:29 +0000 Subject: [PATCH 1/2] Move remaining scripts out of the root directory. closes #79 Signed-off-by: Daira Hopwood --- README.md | 3 +-- pyproject.toml | 7 ++++++ regenerate.sh | 22 ++++++------------- .../f4jumble_long.py | 4 ++-- .../orchard/empty_roots.py | 9 ++++---- .../orchard/map_to_curve.py | 13 ++++++----- .../orchard/poseidon_hash.py | 11 +++++----- .../unified_address.py | 18 +++++++-------- .../unified_full_viewing_keys.py | 12 +++++----- .../unified_incoming_viewing_keys.py | 12 +++++----- 10 files changed, 56 insertions(+), 55 deletions(-) rename f4jumble_long.py => zcash_test_vectors/f4jumble_long.py (85%) rename orchard_empty_roots.py => zcash_test_vectors/orchard/empty_roots.py (63%) rename orchard_map_to_curve.py => zcash_test_vectors/orchard/map_to_curve.py (83%) rename orchard_poseidon_hash.py => zcash_test_vectors/orchard/poseidon_hash.py (78%) rename unified_address.py => zcash_test_vectors/unified_address.py (81%) rename unified_full_viewing_keys.py => zcash_test_vectors/unified_full_viewing_keys.py (91%) rename unified_incoming_viewing_keys.py => zcash_test_vectors/unified_incoming_viewing_keys.py (91%) diff --git a/README.md b/README.md index ef283c4..0fae3b8 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,7 @@ after adjusting: - Install [`poetry`](https://python-poetry.org/). - `poetry install` - `poetry run SCRIPT_NAME [-t json|rust|zcash]` - - `SCRIPT_NAME` is either one of the scripts listed in `pyproject.toml`, or - one of the Python files in the root directory. + - `SCRIPT_NAME` is one of the scripts listed in `pyproject.toml`. ## License diff --git a/pyproject.toml b/pyproject.toml index 14a0672..ee78abf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,10 @@ secp256k1 = "0.14.0" [tool.poetry.scripts] # General test vectors f4jumble = "zcash_test_vectors.f4jumble:main" +f4jumble_long = "zcash_test_vectors.f4jumble_long:main" +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_0143 = "zcash_test_vectors.zip_0143:main" zip_0243 = "zcash_test_vectors.zip_0243:main" zip_0244 = "zcash_test_vectors.zip_0244:main" @@ -44,10 +48,13 @@ sapling_signatures = "zcash_test_vectors.sapling.redjubjub:main" sapling_zip32 = "zcash_test_vectors.sapling.zip32:main" # Orchard test vectors +orchard_empty_roots = "zcash_test_vectors.orchard.empty_roots:main" orchard_generators = "zcash_test_vectors.orchard.generators:main" orchard_group_hash = "zcash_test_vectors.orchard.group_hash:main" orchard_key_components = "zcash_test_vectors.orchard.key_components:main" +orchard_map_to_curve = "zcash_test_vectors.orchard.map_to_curve:main" orchard_merkle_tree = "zcash_test_vectors.orchard.merkle_tree:main" orchard_note_encryption = "zcash_test_vectors.orchard.note_encryption:main" orchard_poseidon = "zcash_test_vectors.orchard.poseidon:main" +orchard_poseidon_hash = "zcash_test_vectors.orchard.poseidon_hash:main" orchard_sinsemilla = "zcash_test_vectors.orchard.sinsemilla:main" diff --git a/regenerate.sh b/regenerate.sh index ee7dba7..58df6ca 100755 --- a/regenerate.sh +++ b/regenerate.sh @@ -2,40 +2,32 @@ tv_scripts=( f4jumble + f4jumble_long + orchard_empty_roots orchard_generators orchard_group_hash orchard_key_components + orchard_map_to_curve orchard_merkle_tree orchard_note_encryption orchard_poseidon + orchard_poseidon_hash orchard_sinsemilla sapling_generators sapling_key_components sapling_note_encryption sapling_signatures sapling_zip32 + unified_address + unified_full_viewing_keys + unified_incoming_viewing_keys zip_0143 zip_0243 zip_0244 zip_0316) -tv_external_scripts=( - f4jumble_long - orchard_empty_roots - orchard_map_to_curve - orchard_poseidon_hash - unified_address - unified_full_viewing_keys - unified_incoming_viewing_keys) - for generator in "${tv_scripts[@]}" do echo "# $generator" poetry run $generator -t $1 >test-vectors/$1/$generator.$2 done - -for generator in "${tv_external_scripts[@]}" -do - echo "# $generator" - poetry run python ./$generator.py -t $1 >test-vectors/$1/$generator.$2 -done diff --git a/f4jumble_long.py b/zcash_test_vectors/f4jumble_long.py similarity index 85% rename from f4jumble_long.py rename to zcash_test_vectors/f4jumble_long.py index 417de29..82208ee 100755 --- a/f4jumble_long.py +++ b/zcash_test_vectors/f4jumble_long.py @@ -3,8 +3,8 @@ import sys; assert sys.version_info[0] >= 3, "Python 3 required." from hashlib import blake2b -from zcash_test_vectors.output import render_args, render_tv -from zcash_test_vectors.f4jumble import f4jumble, f4jumble_inv, MAX_l_M +from .output import render_args, render_tv +from .f4jumble import f4jumble, f4jumble_inv, MAX_l_M def main(): diff --git a/orchard_empty_roots.py b/zcash_test_vectors/orchard/empty_roots.py similarity index 63% rename from orchard_empty_roots.py rename to zcash_test_vectors/orchard/empty_roots.py index e09e68c..d55dc08 100755 --- a/orchard_empty_roots.py +++ b/zcash_test_vectors/orchard/empty_roots.py @@ -1,10 +1,11 @@ #!/usr/bin/env python3 import sys; assert sys.version_info[0] >= 3, "Python 3 required." -from zcash_test_vectors.orchard.merkle_tree import empty_roots -from zcash_test_vectors.orchard.pallas import Fp -from zcash_test_vectors.output import render_args, render_tv -from zcash_test_vectors.utils import i2lebsp +from .merkle_tree import empty_roots +from .pallas import Fp + +from ..output import render_args, render_tv +from ..utils import i2lebsp def main(): diff --git a/orchard_map_to_curve.py b/zcash_test_vectors/orchard/map_to_curve.py similarity index 83% rename from orchard_map_to_curve.py rename to zcash_test_vectors/orchard/map_to_curve.py index c08640a..1653d81 100755 --- a/orchard_map_to_curve.py +++ b/zcash_test_vectors/orchard/map_to_curve.py @@ -1,12 +1,13 @@ #!/usr/bin/env python3 import sys; assert sys.version_info[0] >= 3, "Python 3 required." -from zcash_test_vectors.orchard.group_hash import map_to_curve_simple_swu -from zcash_test_vectors.orchard.iso_pallas import Point as IsoPoint -from zcash_test_vectors.orchard.pallas import Fp -from zcash_test_vectors.utils import leos2ip -from zcash_test_vectors.output import render_args, render_tv -from zcash_test_vectors.rand import Rand +from .group_hash import map_to_curve_simple_swu +from .iso_pallas import Point as IsoPoint +from .pallas import Fp + +from ..utils import leos2ip +from ..output import render_args, render_tv +from ..rand import Rand def main(): diff --git a/orchard_poseidon_hash.py b/zcash_test_vectors/orchard/poseidon_hash.py similarity index 78% rename from orchard_poseidon_hash.py rename to zcash_test_vectors/orchard/poseidon_hash.py index 048ea07..885bbbe 100755 --- a/orchard_poseidon_hash.py +++ b/zcash_test_vectors/orchard/poseidon_hash.py @@ -1,11 +1,12 @@ #!/usr/bin/env python3 import sys; assert sys.version_info[0] >= 3, "Python 3 required." -from zcash_test_vectors.orchard.pallas import Fp -from zcash_test_vectors.orchard import poseidon -from zcash_test_vectors.utils import leos2ip -from zcash_test_vectors.output import render_args, render_tv -from zcash_test_vectors.rand import Rand +from .pallas import Fp +from . import poseidon + +from ..utils import leos2ip +from ..output import render_args, render_tv +from ..rand import Rand def main(): test_vectors = [[Fp.ZERO, Fp(1)]] diff --git a/unified_address.py b/zcash_test_vectors/unified_address.py similarity index 81% rename from unified_address.py rename to zcash_test_vectors/unified_address.py index e415004..fcc641a 100755 --- a/unified_address.py +++ b/zcash_test_vectors/unified_address.py @@ -5,16 +5,16 @@ import math from random import Random import struct -from zcash_test_vectors.bech32m import bech32_encode, bech32_decode, convertbits, Encoding +from .bech32m import bech32_encode, bech32_decode, convertbits, Encoding -from zcash_test_vectors.output import render_args, render_tv, Some -from zcash_test_vectors.rand import Rand, randbytes -from zcash_test_vectors.zc_utils import write_compact_size, parse_compact_size -from zcash_test_vectors.f4jumble import f4jumble, f4jumble_inv -from zcash_test_vectors.sapling import key_components as sapling_key_components -from zcash_test_vectors.orchard import key_components as orchard_key_components -from zcash_test_vectors.unified_encoding import encode_unified, decode_unified -from zcash_test_vectors.unified_encoding import P2PKH_ITEM, P2SH_ITEM, SAPLING_ITEM, ORCHARD_ITEM +from .output import render_args, render_tv, Some +from .rand import Rand, randbytes +from .zc_utils import write_compact_size, parse_compact_size +from .f4jumble import f4jumble, f4jumble_inv +from .sapling import key_components as sapling_key_components +from .orchard import key_components as orchard_key_components +from .unified_encoding import encode_unified, decode_unified +from .unified_encoding import P2PKH_ITEM, P2SH_ITEM, SAPLING_ITEM, ORCHARD_ITEM def main(): args = render_args() diff --git a/unified_full_viewing_keys.py b/zcash_test_vectors/unified_full_viewing_keys.py similarity index 91% rename from unified_full_viewing_keys.py rename to zcash_test_vectors/unified_full_viewing_keys.py index 07a1107..d38cd20 100755 --- a/unified_full_viewing_keys.py +++ b/zcash_test_vectors/unified_full_viewing_keys.py @@ -6,12 +6,12 @@ from random import Random from cryptography.hazmat.primitives.asymmetric import ec from cryptography.hazmat.primitives.serialization import PublicFormat, Encoding -from zcash_test_vectors.output import render_args, render_tv, Some -from zcash_test_vectors.rand import Rand, randbytes -from zcash_test_vectors.orchard import key_components as orchard_key_components -from zcash_test_vectors.sapling import zip32 as sapling_zip32 -from zcash_test_vectors.unified_encoding import encode_unified, decode_unified -from zcash_test_vectors.unified_encoding import P2PKH_ITEM, SAPLING_ITEM, ORCHARD_ITEM +from .output import render_args, render_tv, Some +from .rand import Rand, randbytes +from .orchard import key_components as orchard_key_components +from .sapling import zip32 as sapling_zip32 +from .unified_encoding import encode_unified, decode_unified +from .unified_encoding import P2PKH_ITEM, SAPLING_ITEM, ORCHARD_ITEM def main(): args = render_args() diff --git a/unified_incoming_viewing_keys.py b/zcash_test_vectors/unified_incoming_viewing_keys.py similarity index 91% rename from unified_incoming_viewing_keys.py rename to zcash_test_vectors/unified_incoming_viewing_keys.py index 88dbba2..d4747bd 100755 --- a/unified_incoming_viewing_keys.py +++ b/zcash_test_vectors/unified_incoming_viewing_keys.py @@ -6,12 +6,12 @@ from random import Random from cryptography.hazmat.primitives.asymmetric import ec from cryptography.hazmat.primitives.serialization import PublicFormat, Encoding -from zcash_test_vectors.output import render_args, render_tv, Some -from zcash_test_vectors.rand import Rand, randbytes -from zcash_test_vectors.orchard import key_components as orchard_key_components -from zcash_test_vectors.sapling import zip32 as sapling_zip32 -from zcash_test_vectors.unified_encoding import encode_unified, decode_unified -from zcash_test_vectors.unified_encoding import P2PKH_ITEM, SAPLING_ITEM, ORCHARD_ITEM +from .output import render_args, render_tv, Some +from .rand import Rand, randbytes +from .orchard import key_components as orchard_key_components +from .sapling import zip32 as sapling_zip32 +from .unified_encoding import encode_unified, decode_unified +from .unified_encoding import P2PKH_ITEM, SAPLING_ITEM, ORCHARD_ITEM def main(): args = render_args() From d6d69f838889360d35c42ae572fd1c82069ec6e6 Mon Sep 17 00:00:00 2001 From: Daira Hopwood Date: Tue, 8 Feb 2022 14:56:48 +0000 Subject: [PATCH 2/2] Merge files that were only separate in order to provide multiple entry points. Signed-off-by: Daira Hopwood --- pyproject.toml | 6 +-- zcash_test_vectors/f4jumble.py | 29 +++++++++++ zcash_test_vectors/f4jumble_long.py | 41 --------------- zcash_test_vectors/orchard/group_hash.py | 49 ++++++++++++++++- zcash_test_vectors/orchard/map_to_curve.py | 58 --------------------- zcash_test_vectors/orchard/poseidon.py | 40 +++++++++++++- zcash_test_vectors/orchard/poseidon_hash.py | 44 ---------------- 7 files changed, 117 insertions(+), 150 deletions(-) delete mode 100755 zcash_test_vectors/f4jumble_long.py delete mode 100755 zcash_test_vectors/orchard/map_to_curve.py delete mode 100755 zcash_test_vectors/orchard/poseidon_hash.py diff --git a/pyproject.toml b/pyproject.toml index ee78abf..4220609 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,7 +31,7 @@ secp256k1 = "0.14.0" [tool.poetry.scripts] # General test vectors f4jumble = "zcash_test_vectors.f4jumble:main" -f4jumble_long = "zcash_test_vectors.f4jumble_long:main" +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" @@ -51,10 +51,10 @@ sapling_zip32 = "zcash_test_vectors.sapling.zip32:main" orchard_empty_roots = "zcash_test_vectors.orchard.empty_roots:main" orchard_generators = "zcash_test_vectors.orchard.generators:main" orchard_group_hash = "zcash_test_vectors.orchard.group_hash:main" +orchard_map_to_curve = "zcash_test_vectors.orchard.group_hash:map_to_curve_test_vectors" orchard_key_components = "zcash_test_vectors.orchard.key_components:main" -orchard_map_to_curve = "zcash_test_vectors.orchard.map_to_curve:main" orchard_merkle_tree = "zcash_test_vectors.orchard.merkle_tree:main" orchard_note_encryption = "zcash_test_vectors.orchard.note_encryption:main" orchard_poseidon = "zcash_test_vectors.orchard.poseidon:main" -orchard_poseidon_hash = "zcash_test_vectors.orchard.poseidon_hash:main" +orchard_poseidon_hash = "zcash_test_vectors.orchard.poseidon:hash_test_vectors" orchard_sinsemilla = "zcash_test_vectors.orchard.sinsemilla:main" diff --git a/zcash_test_vectors/f4jumble.py b/zcash_test_vectors/f4jumble.py index 1d47dff..884d30e 100755 --- a/zcash_test_vectors/f4jumble.py +++ b/zcash_test_vectors/f4jumble.py @@ -123,6 +123,35 @@ def main(): plain_test_vectors, ) +def long_test_vectors(): + args = render_args() + + hashed_test_vectors = [] + + for l_M in [ + 3246395, + MAX_l_M, + ]: + M = bytes([i & 0xFF for i in range(l_M)]) + jumbled = f4jumble(M) + assert len(jumbled) == len(M) + assert f4jumble_inv(jumbled) == M + + hashed_test_vectors.append({ + 'length': l_M, + 'jumbled_hash': blake2b(jumbled).digest() + }) + + render_tv( + args, + 'f4jumble_long', + ( + ('length', 'usize'), + ('jumbled_hash', '[u8; 64]'), + ), + hashed_test_vectors, + ) + if __name__ == "__main__": main() diff --git a/zcash_test_vectors/f4jumble_long.py b/zcash_test_vectors/f4jumble_long.py deleted file mode 100755 index 82208ee..0000000 --- a/zcash_test_vectors/f4jumble_long.py +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env python3 -import sys; assert sys.version_info[0] >= 3, "Python 3 required." - -from hashlib import blake2b - -from .output import render_args, render_tv -from .f4jumble import f4jumble, f4jumble_inv, MAX_l_M - - -def main(): - args = render_args() - - hashed_test_vectors = [] - - for l_M in [ - 3246395, - MAX_l_M, - ]: - M = bytes([i & 0xFF for i in range(l_M)]) - jumbled = f4jumble(M) - assert len(jumbled) == len(M) - assert f4jumble_inv(jumbled) == M - - hashed_test_vectors.append({ - 'length': l_M, - 'jumbled_hash': blake2b(jumbled).digest() - }) - - render_tv( - args, - 'f4jumble_long', - ( - ('length', 'usize'), - ('jumbled_hash', '[u8; 64]'), - ), - hashed_test_vectors, - ) - - -if __name__ == "__main__": - main() diff --git a/zcash_test_vectors/orchard/group_hash.py b/zcash_test_vectors/orchard/group_hash.py index 30db8fd..2fc1e57 100755 --- a/zcash_test_vectors/orchard/group_hash.py +++ b/zcash_test_vectors/orchard/group_hash.py @@ -7,11 +7,13 @@ import math from . import iso_pallas from .pallas import Fp, p, q, PALLAS_B, Point -from .iso_pallas import PALLAS_ISO_B, PALLAS_ISO_A -from ..utils import i2beosp, cldiv, beos2ip, i2leosp, lebs2ip +from .iso_pallas import PALLAS_ISO_B, PALLAS_ISO_A, Point as IsoPoint + +from ..utils import i2beosp, cldiv, beos2ip, i2leosp, lebs2ip, leos2ip from ..output import render_args, render_tv from ..rand import Rand + # https://stackoverflow.com/questions/2612720/how-to-do-bitwise-exclusive-or-of-two-strings-in-python def sxor(s1,s2): return bytes([a ^ b for a,b in zip(s1,s2)]) @@ -182,6 +184,49 @@ def main(): } for (domain, msg) in test_vectors], ) +def map_to_curve_test_vectors(): + fixed_test_vectors = [ + (Fp(0), IsoPoint(Fp(19938918781445865934736160264407396416050199005817793816893455093350997047296), + Fp(1448774895934493446148762800986014913165975534940595774801697325542407056356))), + (Fp(1), IsoPoint(Fp(5290181550357368025040301950220623271393946308300025648720253222947454165280), + Fp(24520995241805476578231005891941079870703368870355132644748659103632565232759))), + (Fp(0x123456789abcdef123456789abcdef123456789abcdef123456789abcdef0123), + IsoPoint(Fp(16711718778908753690082328243251803703269853000652055785581237369882690082595), + Fp(1764705856161931038824461929646873031992914829456409784642560948827969833589))), + ] + + for (u, point) in fixed_test_vectors: + P = map_to_curve_simple_swu(u) + assert P == point + + test_vectors = [u for (u, _) in fixed_test_vectors] + + from random import Random + rng = Random(0xabad533d) + def randbytes(l): + ret = [] + while len(ret) < l: + ret.append(rng.randrange(0, 256)) + return bytes(ret) + rand = Rand(randbytes) + + # Generate random test vectors + for _ in range(10): + test_vectors.append(Fp(leos2ip(rand.b(32)))) + + render_tv( + render_args(), + 'orchard_map_to_curve', + ( + ('u', '[u8; 32]'), + ('point', '[u8; 32]'), + ), + [{ + 'u': bytes(u), + 'point': bytes(map_to_curve_simple_swu(u)), + } for u in test_vectors], + ) + if __name__ == "__main__": main() diff --git a/zcash_test_vectors/orchard/map_to_curve.py b/zcash_test_vectors/orchard/map_to_curve.py deleted file mode 100755 index 1653d81..0000000 --- a/zcash_test_vectors/orchard/map_to_curve.py +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env python3 -import sys; assert sys.version_info[0] >= 3, "Python 3 required." - -from .group_hash import map_to_curve_simple_swu -from .iso_pallas import Point as IsoPoint -from .pallas import Fp - -from ..utils import leos2ip -from ..output import render_args, render_tv -from ..rand import Rand - - -def main(): - fixed_test_vectors = [ - (Fp(0), IsoPoint(Fp(19938918781445865934736160264407396416050199005817793816893455093350997047296), - Fp(1448774895934493446148762800986014913165975534940595774801697325542407056356))), - (Fp(1), IsoPoint(Fp(5290181550357368025040301950220623271393946308300025648720253222947454165280), - Fp(24520995241805476578231005891941079870703368870355132644748659103632565232759))), - (Fp(0x123456789abcdef123456789abcdef123456789abcdef123456789abcdef0123), - IsoPoint(Fp(16711718778908753690082328243251803703269853000652055785581237369882690082595), - Fp(1764705856161931038824461929646873031992914829456409784642560948827969833589))), - ] - - for (u, point) in fixed_test_vectors: - P = map_to_curve_simple_swu(u) - assert P == point - - test_vectors = [u for (u, _) in fixed_test_vectors] - - from random import Random - rng = Random(0xabad533d) - def randbytes(l): - ret = [] - while len(ret) < l: - ret.append(rng.randrange(0, 256)) - return bytes(ret) - rand = Rand(randbytes) - - # Generate random test vectors - for _ in range(10): - test_vectors.append(Fp(leos2ip(rand.b(32)))) - - render_tv( - render_args(), - 'orchard_map_to_curve', - ( - ('u', '[u8; 32]'), - ('point', '[u8; 32]'), - ), - [{ - 'u': bytes(u), - 'point': bytes(map_to_curve_simple_swu(u)), - } for u in test_vectors], - ) - - -if __name__ == "__main__": - main() diff --git a/zcash_test_vectors/orchard/poseidon.py b/zcash_test_vectors/orchard/poseidon.py index 403508a..9149e81 100755 --- a/zcash_test_vectors/orchard/poseidon.py +++ b/zcash_test_vectors/orchard/poseidon.py @@ -1,13 +1,16 @@ #!/usr/bin/env python3 import sys; assert sys.version_info[0] >= 3, "Python 3 required." -from ..orchard.pallas import Fp import numpy as np from itertools import chain + +from .pallas import Fp + from ..utils import leos2ip from ..output import render_args, render_tv from ..rand import Rand + # Number of full rounds R_F = 8 # Number of partial rounds @@ -156,8 +159,8 @@ def hash(x, y): assert isinstance(y, Fp) return perm([x, y, CAPACITY_ELEMENT])[0] -def main(): +def main(): # These are test vectors from https://github.com/daira/pasta-hadeshash/commit/f7ca15dcf8568f1a4b2c4b7188815e80e9ab8975. fixed_test_input = [ Fp(0x0000000000000000000000000000000000000000000000000000000000000000), @@ -204,5 +207,38 @@ def main(): } for input in test_vectors], ) +def hash_test_vectors(): + test_vectors = [[Fp.ZERO, Fp(1)]] + + from random import Random + rng = Random(0xabad533d) + def randbytes(l): + ret = [] + while len(ret) < l: + ret.append(rng.randrange(0, 256)) + return bytes(ret) + rand = Rand(randbytes) + + # Generate random test vectors + for _ in range(10): + test_vectors.append([ + Fp(leos2ip(rand.b(32))), + Fp(leos2ip(rand.b(32))), + ]) + + render_tv( + render_args(), + 'orchard_poseidon_hash', + ( + ('input', '[[u8; 32]; 2]'), + ('output', '[u8; 32]'), + ), + [{ + 'input': list(map(bytes, input)), + 'output': bytes(hash(input[0], input[1])), + } for input in test_vectors], + ) + + if __name__ == "__main__": main() diff --git a/zcash_test_vectors/orchard/poseidon_hash.py b/zcash_test_vectors/orchard/poseidon_hash.py deleted file mode 100755 index 885bbbe..0000000 --- a/zcash_test_vectors/orchard/poseidon_hash.py +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env python3 -import sys; assert sys.version_info[0] >= 3, "Python 3 required." - -from .pallas import Fp -from . import poseidon - -from ..utils import leos2ip -from ..output import render_args, render_tv -from ..rand import Rand - -def main(): - test_vectors = [[Fp.ZERO, Fp(1)]] - - from random import Random - rng = Random(0xabad533d) - def randbytes(l): - ret = [] - while len(ret) < l: - ret.append(rng.randrange(0, 256)) - return bytes(ret) - rand = Rand(randbytes) - - # Generate random test vectors - for _ in range(10): - test_vectors.append([ - Fp(leos2ip(rand.b(32))), - Fp(leos2ip(rand.b(32))), - ]) - - render_tv( - render_args(), - 'orchard_poseidon_hash', - ( - ('input', '[[u8; 32]; 2]'), - ('output', '[u8; 32]'), - ), - [{ - 'input': list(map(bytes, input)), - 'output': bytes(poseidon.hash(input[0], input[1])), - } for input in test_vectors], - ) - -if __name__ == "__main__": - main()