diff --git a/hasher.go b/hasher.go index 4b4881f..5686437 100755 --- a/hasher.go +++ b/hasher.go @@ -42,11 +42,10 @@ func init() { } func poseidonSum(input []byte) []byte { + output := make([]byte, 32) res := poseidon.Sum(input) - if rest := len(res) % 32; rest != 0 { - res = append(res, zeroBytes[:32-rest]...) - } - return res + copy(output[32-len(res):], res) + return output } // HashWithDefaultHasher hashes a HashRoot object with a Hasher from diff --git a/tests/codetrie_test.go b/tests/codetrie_test.go index 2b529dc..7ff20bb 100644 --- a/tests/codetrie_test.go +++ b/tests/codetrie_test.go @@ -11,14 +11,11 @@ import ( "github.com/iden3/go-iden3-crypto/poseidon" ) -var zeroBytes = make([]byte, 32) - func poseidonSum(input []byte) []byte { + output := make([]byte, 32) res := poseidon.Sum(input) - if len(res) != 32 { - res = append(res, zeroBytes[:32-len(res)]...) - } - return res + copy(output[32-len(res):], res) + return output } func TestVerifyMetadataProof(t *testing.T) {