diff --git a/core/crypto/poseidon_hash.go b/core/crypto/poseidon_hash.go index 4290bf2105..623f108d35 100644 --- a/core/crypto/poseidon_hash.go +++ b/core/crypto/poseidon_hash.go @@ -42,7 +42,7 @@ func round(state []felt.Felt, full bool, index int) { mixLayer(state) } -func hadesPermutation(state []felt.Felt) { +func HadesPermutation(state []felt.Felt) { initialiseRoundKeys.Do(setRoundKeys) totalRounds := fullRounds + partialRounds for i := 0; i < totalRounds; i++ { @@ -58,7 +58,7 @@ var two = new(felt.Felt).SetUint64(2) // [Poseidon hash]: https://docs.starknet.io/documentation/architecture_and_concepts/Hashing/hash-functions/#poseidon_hash func Poseidon(x, y *felt.Felt) *felt.Felt { state := []felt.Felt{*x, *y, *two} - hadesPermutation(state) + HadesPermutation(state) return new(felt.Felt).Set(&state[0]) } @@ -77,7 +77,7 @@ func PoseidonArray(elems ...*felt.Felt) *felt.Felt { for i := 0; i < len(elems)/2; i++ { state[0].Add(&state[0], elems[2*i]) state[1].Add(&state[1], elems[2*i+1]) - hadesPermutation(state) + HadesPermutation(state) } rem := len(elems) % 2 @@ -85,7 +85,7 @@ func PoseidonArray(elems ...*felt.Felt) *felt.Felt { state[0].Add(&state[0], elems[len(elems)-1]) } state[rem].Add(&state[rem], one) - hadesPermutation(state) + HadesPermutation(state) return new(felt.Felt).Set(&state[0]) } @@ -127,7 +127,7 @@ func (d *PoseidonDigest) Update(elems ...*felt.Felt) Digest { } else { d.state[0].Add(&d.state[0], d.lastElem) d.state[1].Add(&d.state[1], elems[idx]) - hadesPermutation(d.state[:]) + HadesPermutation(d.state[:]) d.lastElem = nil } } @@ -141,7 +141,7 @@ func (d *PoseidonDigest) Finish() *felt.Felt { d.state[0].Add(&d.state[0], d.lastElem) d.state[1].Add(&d.state[1], one) } - hadesPermutation(d.state[:]) + HadesPermutation(d.state[:]) return &d.state[0] } diff --git a/core/crypto/poseidon_hash_pkg_test.go b/core/crypto/poseidon_hash_pkg_test.go index a668af4aad..06484364b2 100644 --- a/core/crypto/poseidon_hash_pkg_test.go +++ b/core/crypto/poseidon_hash_pkg_test.go @@ -10,7 +10,7 @@ import ( // Test vector from https://github.com/starkware-industries/poseidon func TestPermutate(t *testing.T) { state := []felt.Felt{{}, {}, {}} - hadesPermutation(state) + HadesPermutation(state) assert.Equal(t, "3446325744004048536138401612021367625846492093718951375866996507163446763827", state[0].Text(10)) assert.Equal(t, "1590252087433376791875644726012779423683501236913937337746052470473806035332", state[1].Text(10)) assert.Equal(t, "867921192302518434283879514999422690776342565400001269945778456016268852423", state[2].Text(10))