Merge pull request #80 from daira/reorg
Move remaining scripts out of the root directory
This commit is contained in:
commit
cc3376f37e
|
@ -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
|
||||
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
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
|
||||
|
||||
|
||||
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()
|
|
@ -1,57 +0,0 @@
|
|||
#!/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
|
||||
|
||||
|
||||
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()
|
|
@ -1,43 +0,0 @@
|
|||
#!/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
|
||||
|
||||
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()
|
|
@ -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_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_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_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_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_test_vectors"
|
||||
orchard_sinsemilla = "zcash_test_vectors.orchard.sinsemilla:main"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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():
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
|
@ -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()
|
|
@ -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()
|
Loading…
Reference in New Issue