remove the original hash function

This commit is contained in:
Cool Developer
2022-04-13 13:13:55 +01:00
parent 5ee5396d03
commit 3c0a3adbbe
3 changed files with 20 additions and 177 deletions

View File

@@ -1,7 +1,6 @@
package poseidon
import (
"fmt"
"math/big"
"testing"
@@ -11,24 +10,13 @@ import (
const prime uint64 = 18446744069414584321
func compareHash(inpBI [NROUNDSF]uint64, capBI [CAPLEN]uint64) ([CAPLEN]uint64, error) {
h, err := Hash(inpBI, capBI)
h1, _ := NeptuneHash(inpBI, capBI)
if h != h1 {
return h, fmt.Errorf("Not same")
}
return h, err
}
func TestPoseidonHashCompare(t *testing.T) {
b0 := uint64(0)
b1 := uint64(1)
bm1 := prime - 1
bM := prime
h, err := compareHash([NROUNDSF]uint64{b0, b0, b0, b0, b0, b0, b0, b0},
h, err := Hash([NROUNDSF]uint64{b0, b0, b0, b0, b0, b0, b0, b0},
[CAPLEN]uint64{b0, b0, b0, b0})
assert.Nil(t, err)
assert.Equal(t,
@@ -40,7 +28,7 @@ func TestPoseidonHashCompare(t *testing.T) {
}, h,
)
h, err = compareHash([NROUNDSF]uint64{b1, b1, b1, b1, b1, b1, b1, b1},
h, err = Hash([NROUNDSF]uint64{b1, b1, b1, b1, b1, b1, b1, b1},
[CAPLEN]uint64{b1, b1, b1, b1})
assert.Nil(t, err)
assert.Equal(t,
@@ -52,7 +40,7 @@ func TestPoseidonHashCompare(t *testing.T) {
}, h,
)
h, err = compareHash([NROUNDSF]uint64{b1, b1, b1, b1, b1, b1, b1, b1},
h, err = Hash([NROUNDSF]uint64{b1, b1, b1, b1, b1, b1, b1, b1},
[CAPLEN]uint64{b1, b1, b1, b1})
assert.Nil(t, err)
assert.Equal(t,
@@ -64,7 +52,7 @@ func TestPoseidonHashCompare(t *testing.T) {
}, h,
)
h, err = compareHash(
h, err = Hash(
[NROUNDSF]uint64{bm1, bm1, bm1, bm1, bm1, bm1, bm1, bm1},
[CAPLEN]uint64{bm1, bm1, bm1, bm1},
)
@@ -78,7 +66,7 @@ func TestPoseidonHashCompare(t *testing.T) {
}, h,
)
h, err = compareHash([NROUNDSF]uint64{bM, bM, bM, bM, bM, bM, bM, bM},
h, err = Hash([NROUNDSF]uint64{bM, bM, bM, bM, bM, bM, bM, bM},
[CAPLEN]uint64{b0, b0, b0, b0})
assert.Nil(t, err)
assert.Equal(t,
@@ -90,7 +78,7 @@ func TestPoseidonHashCompare(t *testing.T) {
}, h,
)
h, err = compareHash([NROUNDSF]uint64{
h, err = Hash([NROUNDSF]uint64{
uint64(923978),
uint64(235763497586),
uint64(9827635653498),
@@ -111,24 +99,6 @@ func TestPoseidonHashCompare(t *testing.T) {
)
}
func BenchmarkPoseidonHash(b *testing.B) {
inp := [NROUNDSF]uint64{1, 2, 3, 4, 5, 6, 7, 8}
cap := [CAPLEN]uint64{10, 11, 12, 13}
for i := 0; i < b.N; i++ {
Hash(inp, cap) //nolint:errcheck,gosec
}
}
func BenchmarkNeptuneHash(b *testing.B) {
inp := [NROUNDSF]uint64{1, 2, 3, 4, 5, 6, 7, 8}
cap := [CAPLEN]uint64{10, 11, 12, 13}
for i := 0; i < b.N; i++ {
NeptuneHash(inp, cap) //nolint:errcheck,gosec
}
}
func BenchmarkPoseidonHash12Inputs(b *testing.B) {
bigArray12 := []*big.Int{
big.NewInt(1),
@@ -149,3 +119,12 @@ func BenchmarkPoseidonHash12Inputs(b *testing.B) {
poseidon.Hash(bigArray12) //nolint:errcheck,gosec
}
}
func BenchmarkNeptuneHash(b *testing.B) {
inp := [NROUNDSF]uint64{1, 2, 3, 4, 5, 6, 7, 8}
cap := [CAPLEN]uint64{10, 11, 12, 13}
for i := 0; i < b.N; i++ {
Hash(inp, cap) //nolint:errcheck,gosec
}
}