Browse Source

fix the lint issues

fix/bbjj-err
Cool Developer 2 years ago
parent
commit
49541f2ead
3 changed files with 18 additions and 14 deletions
  1. +5
    -5
      goldenposeidon/constants.go
  2. +3
    -3
      goldenposeidon/poseidon.go
  3. +10
    -6
      goldenposeidon/poseidon_test.go

+ 5
- 5
goldenposeidon/constants.go

@ -106,7 +106,7 @@ var (
0x4543d9df5476d3cb, 0xf172d73e004fc90d, 0xdfd1c4febcc81238, 0xbc8dfb627fe558fc,
}
c_opt = []uint64{
cOpt = []uint64{
0xb585f766f2144405,
0x7746a55f43921ad7,
0xb2fb0d31cee799b4,
@ -909,8 +909,8 @@ var (
// C is a constant array of element
C []*ffg.Element
// C_OPT is a constant array of element
C_OPT []*ffg.Element
// COpt is a constant array of element
COpt []*ffg.Element
// M is a matrix
M [][]*ffg.Element
// P is a matrix
@ -924,8 +924,8 @@ func init() {
C = append(C, ffg.NewElementFromUint64(c[i]))
}
for i := 0; i < len(c_opt); i++ {
C_OPT = append(C_OPT, ffg.NewElementFromUint64(c_opt[i]))
for i := 0; i < len(cOpt); i++ {
COpt = append(COpt, ffg.NewElementFromUint64(cOpt[i]))
}
for i := 0; i < len(s); i++ {

+ 3
- 3
goldenposeidon/poseidon.go

@ -32,7 +32,7 @@ func ark(state []*ffg.Element, it int) {
// arkOpt computes Add-Round Key, from the paper https://eprint.iacr.org/2019/458.pdf
func arkOpt(state []*ffg.Element, it int) {
for i := 0; i < len(state); i++ {
state[i].Add(state[i], C_OPT[it+i])
state[i].Add(state[i], COpt[it+i])
}
}
@ -98,7 +98,7 @@ func NeptuneHash(inpBI [NROUNDSF]uint64, capBI [CAPLEN]uint64) ([CAPLEN]uint64,
}
for i := 0; i < mLen; i++ {
state[i].Add(state[i], C_OPT[i])
state[i].Add(state[i], COpt[i])
}
for r := 0; r < NROUNDSF/2; r++ {
@ -109,7 +109,7 @@ func NeptuneHash(inpBI [NROUNDSF]uint64, capBI [CAPLEN]uint64) ([CAPLEN]uint64,
for r := 0; r < NROUNDSP; r++ {
exp7(state[0])
state[0].Add(state[0], C_OPT[(NROUNDSF/2+1)*mLen+r])
state[0].Add(state[0], COpt[(NROUNDSF/2+1)*mLen+r])
s0 := zero()
mul := zero()

+ 10
- 6
goldenposeidon/poseidon_test.go

@ -26,7 +26,8 @@ func TestPoseidonHashCompare(t *testing.T) {
bm1 := prime - 1
bM := prime
h, err := compareHash([NROUNDSF]uint64{b0, b0, b0, b0, b0, b0, b0, b0}, [CAPLEN]uint64{b0, b0, b0, b0})
h, err := compareHash([NROUNDSF]uint64{b0, b0, b0, b0, b0, b0, b0, b0},
[CAPLEN]uint64{b0, b0, b0, b0})
assert.Nil(t, err)
assert.Equal(t,
[CAPLEN]uint64{
@ -37,7 +38,8 @@ func TestPoseidonHashCompare(t *testing.T) {
}, h,
)
h, err = compareHash([NROUNDSF]uint64{b1, b1, b1, b1, b1, b1, b1, b1}, [CAPLEN]uint64{b1, b1, b1, b1})
h, err = compareHash([NROUNDSF]uint64{b1, b1, b1, b1, b1, b1, b1, b1},
[CAPLEN]uint64{b1, b1, b1, b1})
assert.Nil(t, err)
assert.Equal(t,
[CAPLEN]uint64{
@ -48,7 +50,8 @@ func TestPoseidonHashCompare(t *testing.T) {
}, h,
)
h, err = compareHash([NROUNDSF]uint64{b1, b1, b1, b1, b1, b1, b1, b1}, [CAPLEN]uint64{b1, b1, b1, b1})
h, err = compareHash([NROUNDSF]uint64{b1, b1, b1, b1, b1, b1, b1, b1},
[CAPLEN]uint64{b1, b1, b1, b1})
assert.Nil(t, err)
assert.Equal(t,
[CAPLEN]uint64{
@ -73,7 +76,8 @@ func TestPoseidonHashCompare(t *testing.T) {
}, h,
)
h, err = compareHash([NROUNDSF]uint64{bM, bM, bM, bM, bM, bM, bM, bM}, [CAPLEN]uint64{b0, b0, b0, b0})
h, err = compareHash([NROUNDSF]uint64{bM, bM, bM, bM, bM, bM, bM, bM},
[CAPLEN]uint64{b0, b0, b0, b0})
assert.Nil(t, err)
assert.Equal(t,
[CAPLEN]uint64{
@ -114,11 +118,11 @@ func BenchmarkPoseidonHash(b *testing.B) {
}
}
func BenchmarkPoseidonNeptuneHash(b *testing.B) {
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
NeptuneHash(inp, cap) //nolint:errcheck,gosec
}
}

Loading…
Cancel
Save