Skip to content

Commit

Permalink
Merge branch 'main' into rianhughes/proof-range
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes authored Jun 7, 2024
2 parents 16c6b13 + 52a8ea9 commit a26c904
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions core/crypto/poseidon_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++ {
Expand All @@ -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])
}

Expand All @@ -77,15 +77,15 @@ 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
if rem == 1 {
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])
}
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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]
}

Expand Down
2 changes: 1 addition & 1 deletion core/crypto/poseidon_hash_pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit a26c904

Please sign in to comment.