diff --git a/orchard_group_hash.py b/orchard_group_hash.py old mode 100755 new mode 100644 index 4cdeffa..76382e8 --- a/orchard_group_hash.py +++ b/orchard_group_hash.py @@ -136,46 +136,18 @@ def group_hash(d, m): def main(): - map_to_curve_test_vectors = [ - (Fp(0), orchard_iso_pallas.Point(Fp(19938918781445865934736160264407396416050199005817793816893455093350997047296), - Fp(1448774895934493446148762800986014913165975534940595774801697325542407056356))), - (Fp(1), orchard_iso_pallas.Point(Fp(5290181550357368025040301950220623271393946308300025648720253222947454165280), - Fp(24520995241805476578231005891941079870703368870355132644748659103632565232759))), - (Fp(0x123456789abcdef123456789abcdef123456789abcdef123456789abcdef0123), - orchard_iso_pallas.Point(Fp(16711718778908753690082328243251803703269853000652055785581237369882690082595), - Fp(1764705856161931038824461929646873031992914829456409784642560948827969833589))), - ] - - for (u, point) in map_to_curve_test_vectors: - P = map_to_curve_simple_swu(u) - assert P == point - - print("map_to_curve_simple_swu (Pallas):") - render_tv( - render_args(), - 'orchard_group_hash', - ( - ('u', '[u8; 32]'), - ('point', '[u8; 32]'), - ), - [{ - 'u': bytes(u), - 'point': bytes(point), - } for (u, point) in map_to_curve_test_vectors], - ) - print("") - - group_hash_test_vectors = [ + fixed_test_vectors = [ # This is the Pallas test vector from the Sage and Rust code (in affine coordinates). (b"z.cash:test", b"Trans rights now!", Point(Fp(10899331951394555178876036573383466686793225972744812919361819919497009261523), Fp(851679174277466283220362715537906858808436854303373129825287392516025427980))), ] - for (domain, msg, point) in group_hash_test_vectors: + for (domain, msg, point) in fixed_test_vectors: gh = group_hash(domain, msg) assert gh == point - print("group_hash (Pallas):") + test_vectors = [(domain, msg) for (domain, msg, _) in fixed_test_vectors] + render_tv( render_args(), 'orchard_group_hash', @@ -187,10 +159,9 @@ def main(): [{ 'domain': domain, 'msg': msg, - 'point': bytes(point), - } for (domain, msg, point) in group_hash_test_vectors], + 'point': bytes(group_hash(domain, msg)), + } for (domain, msg) in test_vectors], ) - print("") if __name__ == "__main__": diff --git a/orchard_map_to_curve.py b/orchard_map_to_curve.py new file mode 100755 index 0000000..dc42916 --- /dev/null +++ b/orchard_map_to_curve.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +from orchard_group_hash import map_to_curve_simple_swu +from orchard_iso_pallas import Point as IsoPoint +from orchard_pallas import Fp +from tv_output import render_args, render_tv + + +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] + + 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()