chore: gofumpt (#11839)

* fumpt using main not master...

* be more descriptive

* fumpt

* fix nits

Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
Jacob Gadikian
2022-05-19 10:55:27 +02:00
committed by GitHub
co-authored by Julien Robert
parent bc2d553f77
commit 55054282d2
412 changed files with 1020 additions and 1059 deletions
+8 -4
View File
@@ -34,8 +34,10 @@ const (
keyType = "ed25519"
)
var _ cryptotypes.PrivKey = &PrivKey{}
var _ codec.AminoMarshaler = &PrivKey{}
var (
_ cryptotypes.PrivKey = &PrivKey{}
_ codec.AminoMarshaler = &PrivKey{}
)
// Bytes returns the privkey byte format.
func (privKey *PrivKey) Bytes() []byte {
@@ -150,8 +152,10 @@ func GenPrivKeyFromSecret(secret []byte) *PrivKey {
//-------------------------------------
var _ cryptotypes.PubKey = &PubKey{}
var _ codec.AminoMarshaler = &PubKey{}
var (
_ cryptotypes.PubKey = &PubKey{}
_ codec.AminoMarshaler = &PubKey{}
)
// Address is the SHA256-20 of the raw pubkey bytes.
// It doesn't implement ADR-28 addresses and it must not be used
@@ -30,7 +30,6 @@ func BenchmarkSigning(b *testing.B, priv types.PrivKey) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := priv.Sign(message)
if err != nil {
b.FailNow()
}
-4
View File
@@ -29,7 +29,6 @@ func IsSNormalized(sigS *big.Int) bool {
// NormalizeS will invert the s value if not already in the lower half
// of curve order value
func NormalizeS(sigS *big.Int) *big.Int {
if IsSNormalized(sigS) {
return sigS
}
@@ -41,7 +40,6 @@ func NormalizeS(sigS *big.Int) *big.Int {
// R, S are padded to 32 bytes respectively.
// code roughly copied from secp256k1_nocgo.go
func signatureRaw(r *big.Int, s *big.Int) []byte {
rBytes := r.Bytes()
sBytes := s.Bytes()
sigBytes := make([]byte, 64)
@@ -90,10 +88,8 @@ func (sk *PrivKey) Bytes() []byte {
// It then raw encodes the signature as two fixed width 32-byte values
// concatenated, reusing the code copied from secp256k1_nocgo.go
func (sk *PrivKey) Sign(msg []byte) ([]byte, error) {
digest := sha256.Sum256(msg)
r, s, err := ecdsa.Sign(rand.Reader, &sk.PrivateKey, digest[:])
if err != nil {
return nil, err
}
@@ -38,11 +38,11 @@ func (suite *SKSuite) TestMarshal() {
require := suite.Require()
const size = 32
var buffer = make([]byte, size)
buffer := make([]byte, size)
_, err := suite.sk.MarshalTo(buffer)
require.NoError(err)
var sk = new(PrivKey)
sk := new(PrivKey)
err = sk.Unmarshal(buffer, secp256r1, size)
require.NoError(err)
require.True(sk.Equal(&suite.sk.PrivateKey))
-1
View File
@@ -60,7 +60,6 @@ func (pk *PubKey) Bytes() []byte {
// lower half of the curve order
// 7/21/21 - expects raw encoded signature (fixed-width 64-bytes, R || S)
func (pk *PubKey) VerifySignature(msg []byte, sig []byte) bool {
// check length for raw signature
// which is two 32-byte padded big.Ints
// concatenated
@@ -59,12 +59,12 @@ func (suite *PKSuite) TestMarshal() {
require := suite.Require()
const size = 33 // secp256r1 size
var buffer = make([]byte, size)
buffer := make([]byte, size)
n, err := suite.pk.MarshalTo(buffer)
require.NoError(err)
require.Equal(size, n)
var pk = new(PubKey)
pk := new(PubKey)
err = pk.Unmarshal(buffer, secp256r1, size)
require.NoError(err)
require.True(pk.PublicKey.Equal(&suite.pk.PublicKey))
+4 -2
View File
@@ -11,8 +11,10 @@ import (
"github.com/cosmos/cosmos-sdk/types/tx/signing"
)
var _ multisigtypes.PubKey = &LegacyAminoPubKey{}
var _ types.UnpackInterfacesMessage = &LegacyAminoPubKey{}
var (
_ multisigtypes.PubKey = &LegacyAminoPubKey{}
_ types.UnpackInterfacesMessage = &LegacyAminoPubKey{}
)
// NewLegacyAminoPubKey returns a new LegacyAminoPubKey.
// Multisig can be constructed with multiple same keys - it will increase the power of
+10 -5
View File
@@ -110,7 +110,8 @@ func TestVerifyMultisignature(t *testing.T) {
pk = genPk
},
true,
}, {
},
{
"wrong size for sig bit array",
func(require *require.Assertions) {
pubKeys := generatePubKeys(3)
@@ -165,7 +166,8 @@ func TestVerifyMultisignature(t *testing.T) {
)
},
true,
}, {
},
{
"duplicate signatures",
func(require *require.Assertions) {
pubKeys, sigs := generatePubKeysAndSignatures(5, msg)
@@ -178,7 +180,8 @@ func TestVerifyMultisignature(t *testing.T) {
sig.Signatures = append(sig.Signatures, sigs[0])
},
false,
}, {
},
{
"duplicated key",
func(require *require.Assertions) {
// here we test an edge case where we create a multi sig with two same
@@ -191,7 +194,8 @@ func TestVerifyMultisignature(t *testing.T) {
multisig.AddSignature(sig, sigs[0], 1)
},
true,
}, {
},
{
"same key used twice",
func(require *require.Assertions) {
pubkeys, sigs := generatePubKeysAndSignatures(3, msg)
@@ -201,7 +205,8 @@ func TestVerifyMultisignature(t *testing.T) {
multisig.AddSignature(sig, sigs[0], 1)
},
false,
}, {
},
{
"unable to verify signature",
func(require *require.Assertions) {
pubKeys := generatePubKeys(2)
@@ -93,19 +93,19 @@ func (BitCurve *BitCurve) Params() *elliptic.CurveParams {
// IsOnCurve returns true if the given (x,y) lies on the BitCurve.
func (BitCurve *BitCurve) IsOnCurve(x, y *big.Int) bool {
// y² = x³ + b
y2 := new(big.Int).Mul(y, y) //y²
y2.Mod(y2, BitCurve.P) //y²%P
y2 := new(big.Int).Mul(y, y) //
y2.Mod(y2, BitCurve.P) // y²%P
x3 := new(big.Int).Mul(x, x) //x²
x3.Mul(x3, x) //x³
x3 := new(big.Int).Mul(x, x) //
x3.Mul(x3, x) //
x3.Add(x3, BitCurve.B) //x³+B
x3.Add(x3, BitCurve.B) // x³+B
x3.Mod(x3, BitCurve.P) //(x³+B)%P
return x3.Cmp(y2) == 0
}
//TODO: double check if the function is okay
// TODO: double check if the function is okay
// affineFromJacobian reverses the Jacobian transform. See the comment at the
// top of the file.
func (BitCurve *BitCurve) affineFromJacobian(x, y, z *big.Int) (xOut, yOut *big.Int) {
@@ -217,30 +217,30 @@ func (BitCurve *BitCurve) Double(x1, y1 *big.Int) (*big.Int, *big.Int) {
func (BitCurve *BitCurve) doubleJacobian(x, y, z *big.Int) (*big.Int, *big.Int, *big.Int) {
// See http://hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#doubling-dbl-2009-l
a := new(big.Int).Mul(x, x) //X1²
b := new(big.Int).Mul(y, y) //Y1²
c := new(big.Int).Mul(b, b) //B²
a := new(big.Int).Mul(x, x) // X1²
b := new(big.Int).Mul(y, y) // Y1²
c := new(big.Int).Mul(b, b) //
d := new(big.Int).Add(x, b) //X1+B
d := new(big.Int).Add(x, b) // X1+B
d.Mul(d, d) //(X1+B)²
d.Sub(d, a) //(X1+B)²-A
d.Sub(d, c) //(X1+B)²-A-C
d.Mul(d, big.NewInt(2)) //2*((X1+B)²-A-C)
d.Mul(d, big.NewInt(2)) // 2*((X1+B)²-A-C)
e := new(big.Int).Mul(big.NewInt(3), a) //3*A
f := new(big.Int).Mul(e, e) //E²
e := new(big.Int).Mul(big.NewInt(3), a) // 3*A
f := new(big.Int).Mul(e, e) //
x3 := new(big.Int).Mul(big.NewInt(2), d) //2*D
x3.Sub(f, x3) //F-2*D
x3 := new(big.Int).Mul(big.NewInt(2), d) // 2*D
x3.Sub(f, x3) // F-2*D
x3.Mod(x3, BitCurve.P)
y3 := new(big.Int).Sub(d, x3) //D-X3
y3.Mul(e, y3) //E*(D-X3)
y3.Sub(y3, new(big.Int).Mul(big.NewInt(8), c)) //E*(D-X3)-8*C
y3 := new(big.Int).Sub(d, x3) // D-X3
y3.Mul(e, y3) // E*(D-X3)
y3.Sub(y3, new(big.Int).Mul(big.NewInt(8), c)) // E*(D-X3)-8*C
y3.Mod(y3, BitCurve.P)
z3 := new(big.Int).Mul(y, z) //Y1*Z1
z3.Mul(big.NewInt(2), z3) //3*Y1*Z1
z3 := new(big.Int).Mul(y, z) // Y1*Z1
z3.Mul(big.NewInt(2), z3) // 3*Y1*Z1
z3.Mod(z3, BitCurve.P)
return x3, y3, z3
@@ -1,3 +1,4 @@
//go:build dummy
// +build dummy
// Package c contains only a C file.
@@ -1,3 +1,4 @@
//go:build dummy
// +build dummy
// Package c contains only a C file.
@@ -1,3 +1,4 @@
//go:build dummy
// +build dummy
// Package c contains only a C file.
@@ -1,3 +1,4 @@
//go:build dummy
// +build dummy
// Package c contains only a C file.
@@ -1,3 +1,4 @@
//go:build dummy
// +build dummy
// Package c contains only a C file.
@@ -1,3 +1,4 @@
//go:build dummy
// +build dummy
// Package c contains only a C file.
@@ -1,3 +1,4 @@
//go:build dummy
// +build dummy
// Package c contains only a C file.
@@ -48,7 +48,7 @@ func randSig() []byte {
// tests for malleability
// highest bit of signature ECDSA s value must be 0, in the 33th byte
func compactSigCheck(t *testing.T, sig []byte) {
var b = int(sig[32])
b := int(sig[32])
if b < 0 {
t.Errorf("highest bit is negative: %d", b)
}
+8 -4
View File
@@ -17,8 +17,10 @@ import (
"github.com/cosmos/cosmos-sdk/types/errors"
)
var _ cryptotypes.PrivKey = &PrivKey{}
var _ codec.AminoMarshaler = &PrivKey{}
var (
_ cryptotypes.PrivKey = &PrivKey{}
_ codec.AminoMarshaler = &PrivKey{}
)
const (
PrivKeySize = 32
@@ -138,8 +140,10 @@ func GenPrivKeyFromSecret(secret []byte) *PrivKey {
//-------------------------------------
var _ cryptotypes.PubKey = &PubKey{}
var _ codec.AminoMarshaler = &PubKey{}
var (
_ cryptotypes.PubKey = &PubKey{}
_ codec.AminoMarshaler = &PubKey{}
)
// PubKeySize is comprised of 32 bytes for one field element
// (the x-coordinate), plus one byte for the parity of the y-coordinate.
@@ -10,7 +10,6 @@ import (
)
func Test_genPrivKey(t *testing.T) {
empty := make([]byte, 32)
oneB := big.NewInt(1).Bytes()
onePadded := make([]byte, 32)
+1 -1
View File
@@ -41,7 +41,7 @@ func TestPubKeySecp256k1Address(t *testing.T) {
addrBbz, _, _ := base58.CheckDecode(d.addr)
addrB := crypto.Address(addrBbz)
var priv = secp256k1.PrivKey{Key: privB}
priv := secp256k1.PrivKey{Key: privB}
pubKey := priv.PubKey()
pubT, _ := pubKey.(*secp256k1.PubKey)