Browse Source

Fix linters errors

feature/githubactions
Eduard S 4 years ago
parent
commit
0ac8b46493
6 changed files with 21 additions and 35 deletions
  1. +1
    -4
      babyjub/babyjub.go
  2. +11
    -20
      babyjub/eddsa_test.go
  3. +4
    -1
      babyjub/helpers.go
  4. +1
    -1
      mimc7/mimc7_test.go
  5. +2
    -2
      poseidon/poseidon_test.go
  6. +2
    -7
      utils/utils.go

+ 1
- 4
babyjub/babyjub.go

@ -154,10 +154,7 @@ func (p *Point) InSubGroup() bool {
// PointCoordSign returns the sign of the curve point coordinate. It returns
// false if the sign is positive and false if the sign is negative.
func PointCoordSign(c *big.Int) bool {
if c.Cmp(new(big.Int).Rsh(constants.Q, 1)) == 1 {
return true
}
return false
return c.Cmp(new(big.Int).Rsh(constants.Q, 1)) == 1
}
func PackPoint(ay *big.Int, sign bool) [32]byte {

+ 11
- 20
babyjub/eddsa_test.go

@ -1,7 +1,6 @@
package babyjub
import (
"crypto/rand"
"encoding/hex"
"fmt"
"math/big"
@ -10,25 +9,13 @@ import (
"github.com/iden3/go-iden3-crypto/constants"
"github.com/iden3/go-iden3-crypto/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func genInputs() (*PrivateKey, *big.Int) {
k := NewRandPrivKey()
fmt.Println("k", hex.EncodeToString(k[:]))
msgBuf := [32]byte{}
rand.Read(msgBuf[:])
msg := utils.SetBigIntFromLEBytes(new(big.Int), msgBuf[:])
msg.Mod(msg, constants.Q)
fmt.Println("msg", msg)
return &k, msg
}
func TestPublicKey(t *testing.T) {
var k PrivateKey
for i := 0; i < 256; i++ {
hex.Decode(k[:], []byte{byte(i)})
for i := 0; i < 32; i++ {
k[i] = byte(i)
}
pk := k.Public()
assert.True(t, pk.X.Cmp(constants.Q) == -1)
@ -37,7 +24,8 @@ func TestPublicKey(t *testing.T) {
func TestSignVerifyMimc7(t *testing.T) {
var k PrivateKey
hex.Decode(k[:], []byte("0001020304050607080900010203040506070809000102030405060708090001"))
_, err := hex.Decode(k[:], []byte("0001020304050607080900010203040506070809000102030405060708090001"))
require.Nil(t, err)
msgBuf, err := hex.DecodeString("00010203040506070809")
if err != nil {
panic(err)
@ -81,7 +69,8 @@ func TestSignVerifyMimc7(t *testing.T) {
func TestSignVerifyPoseidon(t *testing.T) {
var k PrivateKey
hex.Decode(k[:], []byte("0001020304050607080900010203040506070809000102030405060708090001"))
_, err := hex.Decode(k[:], []byte("0001020304050607080900010203040506070809000102030405060708090001"))
require.Nil(t, err)
msgBuf, err := hex.DecodeString("00010203040506070809")
if err != nil {
panic(err)
@ -125,7 +114,8 @@ func TestSignVerifyPoseidon(t *testing.T) {
func TestCompressDecompress(t *testing.T) {
var k PrivateKey
hex.Decode(k[:], []byte("0001020304050607080900010203040506070809000102030405060708090001"))
_, err := hex.Decode(k[:], []byte("0001020304050607080900010203040506070809000102030405060708090001"))
require.Nil(t, err)
pk := k.Public()
for i := 0; i < 64; i++ {
msgBuf, err := hex.DecodeString(fmt.Sprintf("000102030405060708%02d", i))
@ -144,7 +134,8 @@ func TestCompressDecompress(t *testing.T) {
func BenchmarkBabyjubEddsa(b *testing.B) {
var k PrivateKey
hex.Decode(k[:], []byte("0001020304050607080900010203040506070809000102030405060708090001"))
_, err := hex.Decode(k[:], []byte("0001020304050607080900010203040506070809000102030405060708090001"))
require.Nil(b, err)
pk := k.Public()
const n = 256

+ 4
- 1
babyjub/helpers.go

@ -8,6 +8,9 @@ import (
// the original blake from the SHA3 competition and not the new blake2 version.
func Blake512(m []byte) []byte {
h := blake512.New()
h.Write(m[:])
_, err := h.Write(m[:])
if err != nil {
panic(err)
}
return h.Sum(nil)
}

+ 1
- 1
mimc7/mimc7_test.go

@ -87,6 +87,6 @@ func BenchmarkMIMC7(b *testing.B) {
bigArray4 := []*big.Int{b12, b45, b78, b41}
for i := 0; i < b.N; i++ {
Hash(bigArray4, nil)
Hash(bigArray4, nil) //nolint:errcheck
}
}

+ 2
- 2
poseidon/poseidon_test.go

@ -104,7 +104,7 @@ func BenchmarkPoseidon(b *testing.B) {
bigArray4 := []*big.Int{b12, b45, b78, b41}
for i := 0; i < b.N; i++ {
Hash(bigArray4)
Hash(bigArray4) //nolint:errcheck
}
}
@ -117,6 +117,6 @@ func BenchmarkPoseidonLarge(b *testing.B) {
bigArray4 := []*big.Int{b12, b45, b78, b41}
for i := 0; i < b.N; i++ {
Hash(bigArray4)
Hash(bigArray4) //nolint:errcheck
}
}

+ 2
- 7
utils/utils.go

@ -66,9 +66,7 @@ func HexEncode(bs []byte) string {
// HexDecode decodes a hex string into an array of bytes.
func HexDecode(h string) ([]byte, error) {
if strings.HasPrefix(h, "0x") {
h = h[2:]
}
h = strings.TrimPrefix(h, "0x")
return hex.DecodeString(h)
}
@ -92,10 +90,7 @@ func HexDecodeInto(dst []byte, h []byte) error {
// CheckBigIntInField checks if given *big.Int fits in a Field Q element
func CheckBigIntInField(a *big.Int) bool {
if a.Cmp(constants.Q) != -1 {
return false
}
return true
return a.Cmp(constants.Q) == -1
}
// CheckBigIntArrayInField checks if given *big.Int fits in a Field Q element

Loading…
Cancel
Save