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

Enable linter in the CI #527

Merged
merged 82 commits into from
Jul 1, 2024
Merged

Enable linter in the CI #527

merged 82 commits into from
Jul 1, 2024

Conversation

K1li4nL
Copy link
Contributor

@K1li4nL K1li4nL commented May 24, 2024

No description provided.

Copy link

🔒 Could not start CI tests due to missing safe PR label. Please contact a DEDIS maintainer.

1 similar comment
Copy link

🔒 Could not start CI tests due to missing safe PR label. Please contact a DEDIS maintainer.

@K1li4nL K1li4nL changed the base branch from drandmerge to ci-32bit-update May 24, 2024 10:02
@K1li4nL K1li4nL marked this pull request as ready for review May 31, 2024 14:48
@K1li4nL K1li4nL force-pushed the kilian-fix-ci-linter branch 2 times, most recently from 65139ba to 704ecd1 Compare June 2, 2024 11:55
@K1li4nL K1li4nL changed the base branch from ci-32bit-update to matteo-int-xplatform June 2, 2024 11:55
@K1li4nL K1li4nL requested a review from pierluca June 6, 2024 06:23
Copy link
Contributor

@AnomalRoil AnomalRoil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chances this could be rebased against drandmerge without including the x86 changes from Matteo branch ? (might have to do some git cherry-picking)

Now CI does the x86 checks in there already I think.

//p = g.Point().Mul(g.Scalar().Pick(rand), nil)
//return
// p = g.Point().Mul(g.Scalar().Pick(rand), nil)
// return
/*}*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems weird that it would all be commented. Has Pick been implemented for GT now maybe?

Copy link
Contributor Author

@K1li4nL K1li4nL Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at their repo, it seems they didn't, should we remove that code ?

Comment on lines 42 to 43
g kyber.Point,
h kyber.Point,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to stick to the convention that points are using Capital letters. Can you add an exception for that linter for kyber.Point elements?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far I couldn't find anyway to add such exceptions, either we disable this check or add //nolint:... everywhere it is needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted these changes

Comment on lines 92 to 93
g []kyber.Point,
h []kyber.Point,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

proof/hash.go Outdated Show resolved Hide resolved
Copy link
Contributor

@AnomalRoil AnomalRoil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ups, used the wrong button.

@K1li4nL K1li4nL changed the base branch from matteo-int-xplatform to drandmerge June 11, 2024 06:10
.golangci.yml Show resolved Hide resolved
digest[0] &= 0xf8
digest[31] &= 0x7f
digest[31] |= 0x40

secret := c.Scalar().(*scalar)
secret := c.Scalar().(*scalar) //nolint:errcheck // V4 may bring better error handling
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds like either a TODO, or an issue that should be created, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -31,48 +31,48 @@ type point struct {
varTime bool
}

func (P *point) String() string {
func (p *point) String() string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Points should be capitalized.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -4,6 +4,6 @@ package edwards25519
// but variable time implementation can be used. Set this only on Points
// which represent public information. Using variable time algorithms to
// operate on private information can result in timing side-channels.
func (P *point) AllowVarTime(varTime bool) {
P.varTime = varTime
func (p *point) AllowVarTime(varTime bool) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Points should be capitalized

@@ -99,10 +98,9 @@ func (p *curvePoint) Pick(rand cipher.Stream) kyber.Point {
return p.Embed(nil, rand)
}

// Pick a curve point containing a variable amount of embedded data.
// Embed pick a curve point containing a variable amount of embedded data.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Embed pick a curve point containing a variable amount of embedded data.
// Embed picks a curve point containing a variable amount of embedded data.

@@ -121,7 +119,7 @@ func (p *curvePoint) Embed(data []byte, rand cipher.Stream) kyber.Point {
}
}

// Extract embedded data from a curve point
// Data extract embedded data from a curve point
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Data extract embedded data from a curve point
// Data extracts embedded data from a curve point

func (p *curvePoint) Set(P kyber.Point) kyber.Point {
p.x = P.(*curvePoint).x
p.y = P.(*curvePoint).y
func (p *curvePoint) Set(a kyber.Point) kyber.Point {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kyber.Point should be capitalized, arguably curvePoint too.

@@ -267,22 +269,19 @@ func (c *curve) onCurve(x, y *mod.Int) bool {

// Sanity-check a point to ensure that it is on the curve
// and within the appropriate subgroup.
func (c *curve) validPoint(P point) bool {
func (c *curve) validPoint(p point) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

point P

@@ -295,7 +294,7 @@ func (c *curve) embedLen() int {

// Pick a [pseudo-]random curve point with optional embedded data,
// filling in the point's x,y coordinates
func (c *curve) embed(P point, data []byte, rand cipher.Stream) {
func (c *curve) embed(p point, data []byte, rand cipher.Stream) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

point P

@@ -50,7 +50,7 @@ type SimpleShuffle struct {
}

// Simple helper to compute G^{ab-cd} for Theta vector computation.
func thenc(grp kyber.Group, G kyber.Point,
func thenc(grp kyber.Group, g kyber.Point,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

point G

if len(G) != len(H) || len(H) != len(secrets) {
return nil, nil, nil, errorDifferentLengths
return nil, nil, nil, errDifferentLengths
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is an error return by a public method, the error should be exported as well to allow wrapping and unwrapping of error.

@@ -131,7 +169,7 @@ func (p *Proof) Verify(suite Suite, G kyber.Point, H kyber.Point, xG kyber.Point
a := suite.Point().Add(rG, cxG)
b := suite.Point().Add(rH, cxH)
if !(p.VG.Equal(a) && p.VH.Equal(b)) {
return errorInvalidProof
return errInvalidProof
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, please export this error

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move these to a proper test file? Maybe test_vectors_test.go ?

p = p.Clone().(*pointG1)
p, ok := p.Clone().(*pointG1)
if !ok {
return nil, errors.New("invalid type cast")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it an exported error ErrTypeCast since you re-use it multiple times.

Comment on lines 24 to 25
var errDifferentLengths = errors.New("inputs of different lengths")
var errInvalidProof = errors.New("invalid proof")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see below about exporting errors that are returned by exported methods.

@@ -152,16 +184,22 @@ func DecShareBatch(suite Suite, H kyber.Point, X []kyber.Point, sH []kyber.Point
// log_{G}(X) == log_{sG}(sX). Note that X = xG and sX = s(xG) = x(sG).
func VerifyDecShare(suite Suite, G kyber.Point, X kyber.Point, encShare *PubVerShare, decShare *PubVerShare) error {
if err := decShare.P.Verify(suite, G, decShare.S.V, X, encShare.S.V); err != nil {
return errorDecVerification
return errDecVerification
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change the signature of this function to have a bool?

Using errors to Verify cryptography is a bad idea:

https://www.youtube.com/watch?v=4opI0w0Xs5c

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the other option would be to export that error and them wrap it with fmt.Errorf("invalid: %w", ErrDecVerification) so that the error cannot be "bypassed" but it's still possible to match on it.

share/pvss/pvss.go Show resolved Hide resolved
share/pvss/pvss.go Outdated Show resolved Hide resolved
share/dkg/pedersen/structs.go Outdated Show resolved Hide resolved
share/dkg/pedersen/structs.go Outdated Show resolved Hide resolved
Copy link

sonarcloud bot commented Jun 24, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
80.3% Duplication on New Code (required ≤ 10%)

See analysis details on SonarCloud

Copy link
Contributor

@AnomalRoil AnomalRoil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm like 108/110 files through... Will just have to test a few extra things wrt to logging changes I guess.

b0 = b1.Mod(b1, prime)
b1 = b1.Mod(b1, prime)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch. Would have been nicer to have a new test vector to detect it ;)

Comment on lines -1140 to +1158
d.c.Info(append([]interface{}{"generator"}, keyvals...))
d.c.Info("generator", keyvals)
}

func (d *DistKeyGenerator) Error(keyvals ...interface{}) {
d.c.Info(append([]interface{}{"generator"}, keyvals...))
d.c.Info("generator", keyvals)
}

func (c *Config) Info(keyvals ...interface{}) {
if c.Log != nil {
c.Log.Info(append([]interface{}{"dkg-log"}, keyvals...))
c.Log.Info("dkg-log", keyvals)
}
}

func (c *Config) Error(keyvals ...interface{}) {
if c.Log != nil {
c.Log.Error(append([]interface{}{"dkg-log"}, keyvals...))
c.Log.Error("dkg-log", keyvals)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I remember adding these at some point because our logger weren't working properly otherwise.

I'll need to test this locally actually with a couple loggers I guess T.T

@AnomalRoil AnomalRoil merged commit 38e3744 into drandmerge Jul 1, 2024
12 checks passed
@AnomalRoil AnomalRoil deleted the kilian-fix-ci-linter branch July 1, 2024 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants