Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staticcheck #42

Merged
merged 6 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
Expand Down
43 changes: 24 additions & 19 deletions .github/workflows/status-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,52 @@ on:
branches: [ master ]

jobs:

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: ^1.18
go-version-file: go.mod
bobhageman marked this conversation as resolved.
Show resolved Hide resolved

- name: Run gofmt
# gofmt does not return non-zero exit codes on failure, so we have to check that there are no issues using grep.
run: gofmt -d -e . | (! grep ^)

# The checks below are disabled until all present issues are fixed.
- name: Run go vet
run: go vet ./...

# - name: Run go vet
# run: go vet ./...

# - name: Install ineffassign
# run: go install github.com/gordonklaus/ineffassign@latest

# - name: Run ineffassign
# run: ineffassign ./...

# - name: Install misspell
# run: go install github.com/client9/misspell/cmd/misspell@latest
- name: Install ineffassign
run: go install github.com/gordonklaus/ineffassign@latest

- name: Run ineffassign
run: ineffassign ./...

- name: Install misspell
run: go install github.com/client9/misspell/cmd/misspell@latest

- name: Run misspell
# misspel is set to ignore false positive 'witn' which stands for witness in gabi.
run: misspell -error -i witn .

- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/[email protected]

# - name: Run misspell
# run: misspell -error .
- name: Run staticcheck
run: staticcheck ./...

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: ^1.18
go-version-file: go.mod

- name: Run all unit tests
run: go test -v ./...
Expand Down
2 changes: 2 additions & 0 deletions gabi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ func setupRevocation(t *testing.T, sk *gabikeys.PrivateKey, pk *gabikeys.PublicK
require.NoError(t, err)

acc, err := update.SignedAccumulator.UnmarshalVerify(pk)
require.NoError(t, err)

witness, err := revocation.RandomWitness(sk, acc)
require.NoError(t, err)
Expand Down Expand Up @@ -1477,6 +1478,7 @@ func TestKeyshareResponseSingleBase(t *testing.T) {
Value: totalP,
Commitment: userComm[0].Pcommit,
}})
require.NoError(t, err)

challenge := createChallenge(bigOne, nonce, []*big.Int{totalP, totalW}, false)

Expand Down
7 changes: 3 additions & 4 deletions gabikeys/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"os"
"strconv"
"time"
Expand Down Expand Up @@ -121,7 +120,7 @@ func NewPrivateKeyFromFile(filename string, demo bool) (*PrivateKey, error) {
}
defer common.Close(f)

b, err := ioutil.ReadAll(f)
b, err := io.ReadAll(f)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -271,7 +270,7 @@ func NewPublicKeyFromBytes(bts []byte) (*PublicKey, error) {
if sysparam, ok := DefaultSystemParameters[keylength]; ok {
pubk.Params = sysparam
} else {
return nil, fmt.Errorf("Unknown keylength %d", keylength)
return nil, fmt.Errorf("unknown keylength %d", keylength)
}
if err = pubk.parseRevocationKey(); err != nil {
return nil, err
Expand All @@ -292,7 +291,7 @@ func NewPublicKeyFromFile(filename string) (*PublicKey, error) {
defer common.Close(f)
pubk := &PublicKey{}

b, err := ioutil.ReadAll(f)
b, err := io.ReadAll(f)
if err != nil {
return nil, err
}
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/privacybydesign/gabi

go 1.18
go 1.21

toolchain go1.21.1
bobhageman marked this conversation as resolved.
Show resolved Hide resolved

require (
github.com/bwesterb/go-exptable v1.0.0
Expand Down
6 changes: 3 additions & 3 deletions internal/common/fastrandom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ func TestCPRNG(t *testing.T) {
seed[i] = byte(i)
}
var buf [256]byte
rng, err := NewCPRNG(&seed)
_, err := NewCPRNG(&seed)
if err != nil {
t.Fatalf("NewCPRNG: %v", err)
}
for i := 0; i < 256; i++ {
rng, _ = NewCPRNG(&seed)
rng, _ := NewCPRNG(&seed)
rng.Read(buf[0:i])
if hex.EncodeToString(buf[:i]) != expected[:2*i] {
t.Fatalf("TestCPRNG (1): %d", i)
}
}
rng, _ = NewCPRNG(&seed)
rng, _ := NewCPRNG(&seed)
for i := 0; i < 16; i++ {
rng.Read(buf[i*16 : (i+1)*16])
}
Expand Down
10 changes: 5 additions & 5 deletions keyproof/additionproof.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ func newAdditionProofStructure(a1, a2, mod, result string, l uint) additionProof
}
structure.addRepresentation = zkproof.RepresentationProofStructure{
Lhs: []zkproof.LhsContribution{
{result, big.NewInt(1)},
{a1, big.NewInt(-1)},
{a2, big.NewInt(-1)},
{Base: result, Power: big.NewInt(1)},
{Base: a1, Power: big.NewInt(-1)},
{Base: a2, Power: big.NewInt(-1)},
},
Rhs: []zkproof.RhsContribution{
{mod, strings.Join([]string{structure.myname, "mod"}, "_"), 1},
{"h", strings.Join([]string{structure.myname, "hider"}, "_"), 1},
{Base: mod, Secret: strings.Join([]string{structure.myname, "mod"}, "_"), Power: 1},
{Base: "h", Secret: strings.Join([]string{structure.myname, "hider"}, "_"), Power: 1},
},
}
structure.addRange = rangeProofStructure{
Expand Down
2 changes: 1 addition & 1 deletion keyproof/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ INTRODUCTION
------------
This sublibrary implements functionality for creating and verifying zero
knowledge attestations of proper generation of idemix keys. It implements the
proof layed out in "Proving in Zero-Knowledge that a Number is the Product of
proof laid out in "Proving in Zero-Knowledge that a Number is the Product of
Two Safe Primes, Camenisch et. al. BRICS RS-98-29" section 5.2, using the
quasi-safe prime product proofs described in "An efficient non-interactive
statistical zero-knowledge proof system for quasi-safe prime products, Gennaro
Expand Down
6 changes: 3 additions & 3 deletions keyproof/exp.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ func newExpProofStructure(base, exponent, mod, result string, bitlen uint) expPr
structure.start = newPedersenStructure(strings.Join([]string{structure.myname, "start"}, "_"))
structure.startRep = zkproof.RepresentationProofStructure{
Lhs: []zkproof.LhsContribution{
{strings.Join([]string{structure.myname, "start"}, "_"), big.NewInt(1)},
{"g", big.NewInt(-1)},
{Base: strings.Join([]string{structure.myname, "start"}, "_"), Power: big.NewInt(1)},
{Base: "g", Power: big.NewInt(-1)},
},
Rhs: []zkproof.RhsContribution{
{"h", strings.Join([]string{structure.myname, "start", "hider"}, "_"), 1},
{Base: "h", Secret: strings.Join([]string{structure.myname, "start", "hider"}, "_"), Power: 1},
},
}

Expand Down
10 changes: 5 additions & 5 deletions keyproof/expstepa.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ func newExpStepAStructure(bitname, prename, postname string) expStepAStructure {
}
structure.bitRep = zkproof.RepresentationProofStructure{
Lhs: []zkproof.LhsContribution{
{bitname, big.NewInt(1)},
{Base: bitname, Power: big.NewInt(1)},
},
Rhs: []zkproof.RhsContribution{
{"h", strings.Join([]string{bitname, "hider"}, "_"), 1},
{Base: "h", Secret: strings.Join([]string{bitname, "hider"}, "_"), Power: 1},
},
}
structure.equalityRep = zkproof.RepresentationProofStructure{
Lhs: []zkproof.LhsContribution{
{prename, big.NewInt(1)},
{postname, big.NewInt(-1)},
{Base: prename, Power: big.NewInt(1)},
{Base: postname, Power: big.NewInt(-1)},
},
Rhs: []zkproof.RhsContribution{
{"h", strings.Join([]string{structure.myname, "eqhider"}, "_"), 1},
{Base: "h", Secret: strings.Join([]string{structure.myname, "eqhider"}, "_"), Power: 1},
},
}
return structure
Expand Down
6 changes: 3 additions & 3 deletions keyproof/expstepb.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ func newExpStepBStructure(bitname, prename, postname, mulname, modname string, b
}
structure.bitRep = zkproof.RepresentationProofStructure{
Lhs: []zkproof.LhsContribution{
{bitname, big.NewInt(1)},
{"g", big.NewInt(-1)},
{Base: bitname, Power: big.NewInt(1)},
{Base: "g", Power: big.NewInt(-1)},
},
Rhs: []zkproof.RhsContribution{
{"h", strings.Join([]string{bitname, "hider"}, "_"), 1},
{Base: "h", Secret: strings.Join([]string{bitname, "hider"}, "_"), Power: 1},
},
}
return structure
Expand Down
24 changes: 12 additions & 12 deletions keyproof/issquareproof.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@
squaresPedersen: make([]pedersenStructure, len(Squares)),
nRep: zkproof.RepresentationProofStructure{
Lhs: []zkproof.LhsContribution{
{"N", big.NewInt(-1)},
{"g", new(big.Int).Set(N)},
{Base: "N", Power: big.NewInt(-1)},
{Base: "g", Power: new(big.Int).Set(N)},
},
Rhs: []zkproof.RhsContribution{
{"h", "N_hider", -1},
{Base: "h", Secret: "N_hider", Power: -1},
Dismissed Show dismissed Hide dismissed
},
},
squaresRep: make([]zkproof.RepresentationProofStructure, len(Squares)),
Expand All @@ -74,11 +74,11 @@
for i, val := range result.squares {
result.squaresRep[i] = zkproof.RepresentationProofStructure{
Lhs: []zkproof.LhsContribution{
{strings.Join([]string{"s", fmt.Sprintf("%v", i)}, "_"), big.NewInt(-1)},
{"g", new(big.Int).Set(val)},
{Base: strings.Join([]string{"s", fmt.Sprintf("%v", i)}, "_"), Power: big.NewInt(-1)},
{Base: "g", Power: new(big.Int).Set(val)},
},
Rhs: []zkproof.RhsContribution{
{"h", strings.Join([]string{"s", fmt.Sprintf("%v", i), "hider"}, "_"), -1},
{Base: "h", Secret: strings.Join([]string{"s", fmt.Sprintf("%v", i), "hider"}, "_"), Power: -1},
},
}
}
Expand Down Expand Up @@ -151,9 +151,9 @@

// Generate commitments
list = append(list, s.n)
for _, val := range s.squares {
list = append(list, val)
}

list = append(list, s.squares...)

list = s.nRep.CommitmentsFromSecrets(g, list, &bases, &secrets)
for i := range s.squaresRep {
list = s.squaresRep[i].CommitmentsFromSecrets(g, list, &bases, &secrets)
Expand Down Expand Up @@ -266,9 +266,9 @@
}
list = s.nPedersen.commitmentsFromProof(g, list, challenge, proof.NProof)
list = append(list, s.n)
for _, val := range s.squares {
list = append(list, val)
}

list = append(list, s.squares...)

list = s.nRep.CommitmentsFromProof(g, list, challenge, &bases, &proofs)
for i := range s.squares {
list = s.squaresRep[i].CommitmentsFromProof(g, list, challenge, &bases, &proofs)
Expand Down
8 changes: 4 additions & 4 deletions keyproof/multiplicationproof.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ func newMultiplicationProofStructure(m1, m2, mod, result string, l uint) multipl
}
structure.multRepresentation = zkproof.RepresentationProofStructure{
Lhs: []zkproof.LhsContribution{
{result, big.NewInt(1)},
{Base: result, Power: big.NewInt(1)},
},
Rhs: []zkproof.RhsContribution{
{m2, m1, 1},
{mod, strings.Join([]string{structure.myname, "mod"}, "_"), -1},
{"h", strings.Join([]string{structure.myname, "hider"}, "_"), 1},
{Base: m2, Secret: m1, Power: 1},
{Base: mod, Secret: strings.Join([]string{structure.myname, "mod"}, "_"), Power: -1},
{Base: "h", Secret: strings.Join([]string{structure.myname, "hider"}, "_"), Power: 1},
},
}
structure.modMultPedersen = newPedersenStructure(strings.Join([]string{structure.myname, "mod"}, "_"))
Expand Down
12 changes: 6 additions & 6 deletions keyproof/pedersen.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ func newPedersenStructure(name string) pedersenStructure {
name,
zkproof.RepresentationProofStructure{
Lhs: []zkproof.LhsContribution{
{name, big.NewInt(1)},
{Base: name, Power: big.NewInt(1)},
},
Rhs: []zkproof.RhsContribution{
{"g", name, 1},
{"h", strings.Join([]string{name, "hider"}, "_"), 1},
{Base: "g", Secret: name, Power: 1},
{Base: "h", Secret: strings.Join([]string{name, "hider"}, "_"), Power: 1},
},
},
}
Expand All @@ -50,11 +50,11 @@ func newPedersenRangeProofStructure(name string, l1 uint, l2 uint) rangeProofStr
structure := rangeProofStructure{
RepresentationProofStructure: zkproof.RepresentationProofStructure{
Lhs: []zkproof.LhsContribution{
{name, big.NewInt(1)},
{Base: name, Power: big.NewInt(1)},
},
Rhs: []zkproof.RhsContribution{
{"g", name, 1},
{"h", strings.Join([]string{name, "hider"}, "_"), 1},
{Base: "g", Secret: name, Power: 1},
{Base: "h", Secret: strings.Join([]string{name, "hider"}, "_"), Power: 1},
},
},
rangeSecret: name,
Expand Down
Loading