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

LGTM alerts audit #7440

Merged
merged 4 commits into from
Oct 2, 2020
Merged

LGTM alerts audit #7440

merged 4 commits into from
Oct 2, 2020

Conversation

fedekunze
Copy link
Collaborator

@fedekunze fedekunze commented Oct 2, 2020

Fixes issues reported by LGTM.com.

@@ -614,7 +614,7 @@ func (k Keeper) Delegate(
}
}

validator, newShares = k.AddValidatorTokensAndShares(ctx, validator, bondAmt)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wonder why the validator value is not set to store?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

AddValidatorTokensAndShares stores the validator already via a call to k.SetValidator. This line can be _, newShares = k.AddValidatorTokensAndShares(ctx, validator, bondAmt).

@codecov
Copy link

codecov bot commented Oct 2, 2020

Codecov Report

Merging #7440 into master will decrease coverage by 0.00%.
The diff coverage is 75.00%.

@@            Coverage Diff             @@
##           master    #7440      +/-   ##
==========================================
- Coverage   55.10%   55.09%   -0.01%     
==========================================
  Files         588      588              
  Lines       36787    36782       -5     
==========================================
- Hits        20270    20266       -4     
+ Misses      14416    14415       -1     
  Partials     2101     2101              

@lgtm-com
Copy link

lgtm-com bot commented Oct 2, 2020

This pull request fixes 5 alerts when merging 45f11ae into 2c93ec7 - view on LGTM.com

fixed alerts:

  • 3 for Incorrect conversion between integer types
  • 1 for Useless assignment to local variable
  • 1 for Useless assignment to field

@fedekunze fedekunze requested a review from cwgoes October 2, 2020 10:49
if err != nil {
return 0, err
}

if i < 0 {
return 0, fmt.Errorf("fields must not be negative. got %d", i)
Copy link
Contributor

Choose a reason for hiding this comment

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

The string "fields must not be negative. got %d" is very informative. What will it be replaced with?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we don't need it as the string is already cast to uint

@alessio
Copy link
Contributor

alessio commented Oct 2, 2020

@fedekunze dixit:

Don't know how to fix the keyring one tho.

Which line is it? I can't find the alert

@lgtm-com
Copy link

lgtm-com bot commented Oct 2, 2020

This pull request fixes 5 alerts when merging 10c3e33 into 2c93ec7 - view on LGTM.com

fixed alerts:

  • 3 for Incorrect conversion between integer types
  • 1 for Useless assignment to local variable
  • 1 for Useless assignment to field

Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

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

haha OK

@alessio alessio merged commit 82c9ae3 into master Oct 2, 2020
@alessio alessio deleted the fedekunze/lgtm-audit branch October 2, 2020 13:14
// validator already exists
mVal.val = update
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why did this code get removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

not used apparently

@odeke-em
Copy link
Collaborator

Thank you @fedekunze for this change! However, I think LGTM gave you a false positive and I'd roll back this change.

It is most definitely depending on just single static assignment analyses of sorts, (so basically shaving off unnecessary operations) but really the parameters to deriveKey take in index. By the specification in https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki, whether or not harden == true, index has to be in the range 0 to 1<<31 - 1, but with this change, someone can now pass in a uint32 :( And by the spec under section https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys
Screen Shot 2020-10-22 at 4 13 27 AM

but even more subtle is that we were expecting always an int32, and if harden is set, we explicitly set the 1<<32 bit on as per the spec in

func derivePrivateKey(privKeyBytes [32]byte, chainCode [32]byte, index uint32, harden bool) ([32]byte, [32]byte) {
var data []byte
if harden {
index |= 0x80000000
data = append([]byte{byte(0)}, privKeyBytes[:]...)
} else {
so that won't necessarily change much if the value is already large

We shall definitely need a test for extended keys without harden set and ensure that we don't accept values greater than (1<<31-1)

Perhaps let me file an issue too.

@odeke-em
Copy link
Collaborator

odeke-em commented Oct 22, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants