* Poseidon Sponge Hash with different frame sizes * Update deps. Bump go version * Update & fix linter. * Refactor a bit. * Reduce gc pressurefix/bbjj-err
@ -1,16 +1,18 @@ |
|||||
name: Lint |
name: Lint |
||||
on: [ push, pull_request ] |
|
||||
|
on: |
||||
|
push: |
||||
|
branches: |
||||
|
- main |
||||
|
pull_request: |
||||
|
|
||||
jobs: |
jobs: |
||||
lint: |
lint: |
||||
runs-on: ubuntu-latest |
runs-on: ubuntu-latest |
||||
steps: |
steps: |
||||
- name: Install Go |
|
||||
uses: actions/setup-go@v1 |
|
||||
|
- uses: actions/checkout@v3 |
||||
|
- uses: actions/setup-go@v3 |
||||
with: |
with: |
||||
go-version: 1.16.x |
|
||||
- name: Checkout code |
|
||||
uses: actions/checkout@v2 |
|
||||
- name: Lint |
|
||||
run: | |
|
||||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.30.0 |
|
||||
$(go env GOPATH)/bin/golangci-lint run --timeout=5m -c .golangci.yml |
|
||||
|
go-version: 1.20.x |
||||
|
- uses: golangci/golangci-lint-action@v3 |
||||
|
with: |
||||
|
version: v1.51.1 |
@ -1,17 +1,77 @@ |
|||||
issues: |
|
||||
max-same-issues: 0 |
|
||||
exclude-use-default: false |
|
||||
|
service: |
||||
|
golangci-lint-version: 1.51.x |
||||
|
|
||||
|
run: |
||||
|
timeout: 2m |
||||
|
skip-dirs: |
||||
|
- vendor |
||||
|
|
||||
|
linters-settings: |
||||
|
govet: |
||||
|
check-shadowing: true |
||||
|
revive: |
||||
|
min-confidence: 0.1 |
||||
|
rules: |
||||
|
- name: package-comments |
||||
|
disabled: true |
||||
|
maligned: |
||||
|
suggest-new: true |
||||
|
goconst: |
||||
|
min-len: 2 |
||||
|
min-occurrences: 2 |
||||
|
misspell: |
||||
|
locale: US |
||||
|
lll: |
||||
|
line-length: 140 |
||||
|
gocritic: |
||||
|
enabled-tags: |
||||
|
- performance |
||||
|
- style |
||||
|
- experimental |
||||
|
disabled-checks: |
||||
|
- hugeParam |
||||
|
|
||||
linters: |
linters: |
||||
enable: |
|
||||
- whitespace |
|
||||
|
enable: |
||||
|
- bodyclose |
||||
|
- megacheck |
||||
|
- revive |
||||
|
- govet |
||||
|
- unconvert |
||||
|
- megacheck |
||||
|
- gas |
||||
|
- gocyclo |
||||
|
- dupl |
||||
|
- misspell |
||||
|
- unparam |
||||
|
- typecheck |
||||
|
- ineffassign |
||||
|
- stylecheck |
||||
|
- exportloopref |
||||
|
- nakedret |
||||
|
- gosimple |
||||
|
- prealloc |
||||
|
- unused |
||||
|
|
||||
|
## format - fill free to fix |
||||
|
# - errcheck |
||||
|
# - gofmt |
||||
|
# - goimports |
||||
|
fast: false |
||||
|
disable-all: true |
||||
|
|
||||
|
issues: |
||||
|
exclude-rules: |
||||
|
# - Fix and remove |
||||
|
- text: "at least one file in a package should have a package comment" |
||||
|
linters: |
||||
|
- stylecheck |
||||
|
# - Fix and remove |
||||
|
- text: "should have a package comment, unless it's in another file for this package" |
||||
|
linters: |
||||
|
- revive |
||||
|
- path: _test\.go |
||||
|
linters: |
||||
- gosec |
- gosec |
||||
- gci |
|
||||
- misspell |
|
||||
- gomnd |
|
||||
- gofmt |
|
||||
- goimports |
|
||||
- lll |
|
||||
- golint |
|
||||
linters-settings: |
|
||||
lll: |
|
||||
line-length: 100 |
|
||||
|
- dupl |
||||
|
exclude-use-default: false |
@ -1,31 +1,19 @@ |
|||||
package constants |
package constants |
||||
|
|
||||
import ( |
import ( |
||||
"fmt" |
|
||||
"math/big" |
"math/big" |
||||
) |
) |
||||
|
|
||||
|
const qString = "21888242871839275222246405745257275088548364400416034343698204186575808495617" |
||||
|
|
||||
// Q is the order of the integer field (Zq) that fits inside the SNARK.
|
// Q is the order of the integer field (Zq) that fits inside the SNARK.
|
||||
var Q *big.Int |
|
||||
|
var Q, _ = new(big.Int).SetString(qString, 10) |
||||
|
|
||||
// Zero is 0.
|
// Zero is 0.
|
||||
var Zero *big.Int |
|
||||
|
var Zero = big.NewInt(0) |
||||
|
|
||||
// One is 1.
|
// One is 1.
|
||||
var One *big.Int |
|
||||
|
var One = big.NewInt(1) |
||||
|
|
||||
// MinusOne is -1.
|
// MinusOne is -1.
|
||||
var MinusOne *big.Int |
|
||||
|
|
||||
func init() { |
|
||||
Zero = big.NewInt(0) |
|
||||
One = big.NewInt(1) |
|
||||
MinusOne = big.NewInt(-1) |
|
||||
|
|
||||
qString := "21888242871839275222246405745257275088548364400416034343698204186575808495617" |
|
||||
var ok bool |
|
||||
Q, ok = new(big.Int).SetString(qString, 10) //nolint:gomnd
|
|
||||
if !ok { |
|
||||
panic(fmt.Sprintf("Bad base 10 string %s", qString)) |
|
||||
} |
|
||||
} |
|
||||
|
var MinusOne = big.NewInt(-1) |
@ -1,14 +1,17 @@ |
|||||
module github.com/iden3/go-iden3-crypto |
module github.com/iden3/go-iden3-crypto |
||||
|
|
||||
go 1.16 |
|
||||
|
go 1.18 |
||||
|
|
||||
require ( |
require ( |
||||
github.com/dchest/blake512 v1.0.0 |
github.com/dchest/blake512 v1.0.0 |
||||
github.com/stretchr/testify v1.7.0 |
|
||||
golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871 |
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect |
|
||||
github.com/davecgh/go-spew v1.1.0 // indirect |
|
||||
github.com/leanovate/gopter v0.2.9 // indirect |
|
||||
|
github.com/leanovate/gopter v0.2.9 |
||||
|
github.com/stretchr/testify v1.8.2 |
||||
|
golang.org/x/crypto v0.7.0 |
||||
|
golang.org/x/sys v0.6.0 |
||||
|
) |
||||
|
|
||||
|
require ( |
||||
|
github.com/davecgh/go-spew v1.1.1 // indirect |
||||
github.com/pmezard/go-difflib v1.0.0 // indirect |
github.com/pmezard/go-difflib v1.0.0 // indirect |
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect |
|
||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect |
||||
) |
) |
@ -0,0 +1,21 @@ |
|||||
|
package keccak256 |
||||
|
|
||||
|
import ( |
||||
|
"encoding/hex" |
||||
|
"math/big" |
||||
|
"testing" |
||||
|
|
||||
|
"github.com/stretchr/testify/assert" |
||||
|
) |
||||
|
|
||||
|
func TestKeccak256(t *testing.T) { |
||||
|
const SEED = "mimc" |
||||
|
res := Hash([]byte(SEED)) |
||||
|
assert.Equal(t, |
||||
|
"b6e489e6b37224a50bebfddbe7d89fa8fdcaa84304a70bd13f79b5d9f7951e9e", |
||||
|
hex.EncodeToString(res)) |
||||
|
c := new(big.Int).SetBytes(Hash([]byte(SEED))) |
||||
|
assert.Equal(t, |
||||
|
"82724731331859054037315113496710413141112897654334566532528783843265082629790", |
||||
|
c.String()) |
||||
|
} |