From bb16eca2c0acbbd1e744339ae1c8c4ed30f4c472 Mon Sep 17 00:00:00 2001 From: ying tong Date: Fri, 7 May 2021 12:51:40 +0800 Subject: [PATCH] Only return first state element from Poseidon hash Co-authored-by: str4d --- orchard_poseidon.py | 3 ++- orchard_poseidon_hash.py | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/orchard_poseidon.py b/orchard_poseidon.py index 41a6a8c..b510c2e 100644 --- a/orchard_poseidon.py +++ b/orchard_poseidon.py @@ -17,6 +17,7 @@ def perm(input_words): round_constants_counter = 0 state_words = list(input_words) + assert len(state_words) == t # First full rounds for r in range(0, R_f): @@ -313,7 +314,7 @@ def main(): render_tv( render_args(), - 'poseidon_perm', + 'orchard_poseidon', ( ('input', '[[u8; 32]; 3]'), ('output', '[[u8; 32]; 3]'), diff --git a/orchard_poseidon_hash.py b/orchard_poseidon_hash.py index c04620a..e415632 100644 --- a/orchard_poseidon_hash.py +++ b/orchard_poseidon_hash.py @@ -10,7 +10,7 @@ CAPACITY_ELEMENT = Fp(1 << 65) def poseidon_hash(x, y): assert isinstance(x, Fp) assert isinstance(y, Fp) - return perm([x, y, CAPACITY_ELEMENT]) + return perm([x, y, CAPACITY_ELEMENT])[0] def main(): test_vectors = [[Fp.ZERO, Fp(1)]] @@ -33,14 +33,14 @@ def main(): render_tv( render_args(), - 'poseidon_hash', + 'orchard_poseidon_hash', ( ('input', '[[u8; 32]; 2]'), - ('output', '[[u8; 32]; 3]'), + ('output', '[u8; 32]'), ), [{ 'input': list(map(bytes, input)), - 'output': list(map(bytes, poseidon_hash(input[0], input[1]))), + 'output': bytes(poseidon_hash(input[0], input[1])), } for input in test_vectors], )