diff --git a/.golangci.yml b/.golangci.yml index ca69008374..c73f446620 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,7 +10,6 @@ linters: - goconst - gofmt - goimports - - revive - gosec - gosimple - govet diff --git a/crypto/encoding/codec.go b/crypto/encoding/codec.go index 5980f88d4d..12262d19cd 100644 --- a/crypto/encoding/codec.go +++ b/crypto/encoding/codec.go @@ -14,6 +14,7 @@ func init() { json.RegisterType((*pc.PublicKey)(nil), "tendermint.crypto.PublicKey") json.RegisterType((*pc.PublicKey_Ed25519)(nil), "tendermint.crypto.PublicKey_Ed25519") json.RegisterType((*pc.PublicKey_Secp256K1)(nil), "tendermint.crypto.PublicKey_Secp256K1") + json.RegisterType((*pc.PublicKey_Secp256K1Uncompressed)(nil), "tendermint.crypto.PublicKey_Secp256K1Uncompressed") } // PubKeyToProto takes crypto.PubKey and transforms it to a protobuf Pubkey @@ -28,8 +29,14 @@ func PubKeyToProto(k crypto.PubKey) (pc.PublicKey, error) { } case secp256k1.PubKey: kp = pc.PublicKey{ - Sum: &pc.PublicKey_Secp256K1{ - Secp256K1: k, + Sum: &pc.PublicKey_Secp256K1Uncompressed{ + Secp256K1Uncompressed: k, + }, + } + case secp256k1.PubKeyOld: + kp = pc.PublicKey{ + Sum: &pc.PublicKey_Secp256K1Uncompressed{ + Secp256K1Uncompressed: k, }, } default: @@ -49,13 +56,13 @@ func PubKeyFromProto(k pc.PublicKey) (crypto.PubKey, error) { pk := make(ed25519.PubKey, ed25519.PubKeySize) copy(pk, k.Ed25519) return pk, nil - case *pc.PublicKey_Secp256K1: - if len(k.Secp256K1) != secp256k1.PubKeySize { + case *pc.PublicKey_Secp256K1Uncompressed: + if len(k.Secp256K1Uncompressed) != secp256k1.PubKeySize { return nil, fmt.Errorf("invalid size for PubKeySecp256k1. Got %d, expected %d", - len(k.Secp256K1), secp256k1.PubKeySize) + len(k.Secp256K1Uncompressed), secp256k1.PubKeySize) } pk := make(secp256k1.PubKey, secp256k1.PubKeySize) - copy(pk, k.Secp256K1) + copy(pk, k.Secp256K1Uncompressed) return pk, nil default: return nil, fmt.Errorf("fromproto: key type %v is not supported", k) diff --git a/crypto/secp256k1/secp256k1.go b/crypto/secp256k1/secp256k1.go index c6e31f1e79..72962968a8 100644 --- a/crypto/secp256k1/secp256k1.go +++ b/crypto/secp256k1/secp256k1.go @@ -9,8 +9,7 @@ import ( "math/big" secp256k1 "github.com/btcsuite/btcd/btcec/v2" - "github.com/btcsuite/btcd/btcec/v2/ecdsa" - "golang.org/x/crypto/ripemd160" //nolint: staticcheck // necessary for Bitcoin address format + ethCrypto "github.com/ethereum/go-ethereum/crypto" //nolint:depguard "github.com/cometbft/cometbft/crypto" cmtjson "github.com/cometbft/cometbft/libs/json" @@ -18,8 +17,10 @@ import ( // ------------------------------------- const ( - PrivKeyName = "tendermint/PrivKeySecp256k1" - PubKeyName = "tendermint/PubKeySecp256k1" + PrivKeyNameOld = "tendermint/PrivKeySecp256k1" + PubKeyNameOld = "tendermint/PubKeySecp256k1" + PrivKeyName = "comet/PrivKeySecp256k1Uncompressed" + PubKeyName = "comet/PubKeySecp256k1Uncompressed" KeyType = "secp256k1" PrivKeySize = 32 @@ -28,13 +29,34 @@ const ( func init() { cmtjson.RegisterType(PubKey{}, PubKeyName) cmtjson.RegisterType(PrivKey{}, PrivKeyName) + cmtjson.RegisterType(PubKeyOld{}, PubKeyNameOld) + cmtjson.RegisterType(PrivKeyOld{}, PrivKeyNameOld) } var _ crypto.PrivKey = PrivKey{} +var _ crypto.PrivKey = PrivKeyOld{} // PrivKey implements PrivKey. type PrivKey []byte +type PrivKeyOld []byte + +func (privKey PrivKeyOld) Bytes() []byte { + return PrivKey(privKey).Bytes() +} +func (privKey PrivKeyOld) PubKey() crypto.PubKey { + return PrivKey(privKey).PubKey() +} +func (privKey PrivKeyOld) Equals(other crypto.PrivKey) bool { + return PrivKey(privKey).Equals(other) +} +func (privKey PrivKeyOld) Type() string { + return PrivKey(privKey).Type() +} +func (privKey PrivKeyOld) Sign(msg []byte) ([]byte, error) { + return PrivKey(privKey).Sign(msg) +} + // Bytes marshalls the private key using amino encoding. func (privKey PrivKey) Bytes() []byte { return []byte(privKey) @@ -43,11 +65,14 @@ func (privKey PrivKey) Bytes() []byte { // PubKey performs the point-scalar multiplication from the privKey on the // generator point to get the pubkey. func (privKey PrivKey) PubKey() crypto.PubKey { - _, pubkeyObject := secp256k1.PrivKeyFromBytes(privKey) - - pk := pubkeyObject.SerializeCompressed() + privateObject, err := ethCrypto.ToECDSA(privKey) + if err != nil { + panic(err) + } + pk := ethCrypto.FromECDSAPub(&privateObject.PublicKey) return PubKey(pk) + } // Equals - you probably don't need to use this. @@ -75,20 +100,21 @@ func genPrivKey(rand io.Reader) PrivKey { d := new(big.Int) for { - privKeyBytes = [PrivKeySize]byte{} _, err := io.ReadFull(rand, privKeyBytes[:]) if err != nil { panic(err) } d.SetBytes(privKeyBytes[:]) - // break if we found a valid point (i.e. > 0 and < N == curverOrder) + // break if we found a valid point (i.e. > 0 and < N == curveOrder) isValidFieldElement := 0 < d.Sign() && d.Cmp(secp256k1.S256().N) < 0 if isValidFieldElement { break } } + // crypto.CRandBytes is guaranteed to be 32 bytes long, so it can be + // casted to PrivKey. return PrivKey(privKeyBytes[:]) } @@ -124,47 +150,64 @@ func GenPrivKeySecp256k1(secret []byte) PrivKey { } // Sign creates an ECDSA signature on curve Secp256k1, using SHA256 on the msg. -// The returned signature will be of the form R || S (in lower-S form). +// The returned signature will be of the form R || S || V (in lower-S form). func (privKey PrivKey) Sign(msg []byte) ([]byte, error) { - priv, _ := secp256k1.PrivKeyFromBytes(privKey) - - sig, err := ecdsa.SignCompact(priv, crypto.Sha256(msg), false) + privateObject, err := ethCrypto.ToECDSA(privKey) if err != nil { return nil, err } - // remove the first byte which is compactSigRecoveryCode - return sig[1:], nil + return ethCrypto.Sign(ethCrypto.Keccak256(msg), privateObject) } //------------------------------------- var _ crypto.PubKey = PubKey{} +var _ crypto.PubKey = PubKeyOld{} + +// PubKeySize (uncompressed) is comprised of 65 bytes for two field elements (x and y) +// and a prefix byte (0x04) to indicate that it is uncompressed. +const PubKeySize = 65 -// PubKeySize is comprised of 32 bytes for one field element -// (the x-coordinate), plus one byte for the parity of the y-coordinate. -const PubKeySize = 33 +// SigSize is the size of the ECDSA signature. +const SigSize = 65 // PubKey implements crypto.PubKey. -// It is the compressed form of the pubkey. The first byte depends is a 0x02 byte -// if the y-coordinate is the lexicographically largest of the two associated with -// the x-coordinate. Otherwise the first byte is a 0x03. -// This prefix is followed with the x-coordinate. +// It is the uncompressed form of the pubkey. The first byte is prefixed with 0x04. +// This prefix is followed with the (x,y)-coordinates. type PubKey []byte +type PubKeyOld []byte + +func (pubKey PubKeyOld) Address() crypto.Address { + return PubKey(pubKey).Address() +} + +func (pubKey PubKeyOld) Bytes() []byte { + return PubKey(pubKey).Bytes() +} + +func (pubKey PubKeyOld) String() string { + return PubKey(pubKey).String() +} -// Address returns a Bitcoin style addresses: RIPEMD160(SHA256(pubkey)) +func (pubKey PubKeyOld) Equals(other crypto.PubKey) bool { + return PubKey(pubKey).Equals(other) +} + +func (pubKey PubKeyOld) Type() string { + return PubKey(pubKey).Type() +} + +func (pubKey PubKeyOld) VerifySignature(msg []byte, sigStr []byte) bool { + return PubKey(pubKey).VerifySignature(msg, sigStr) +} + +// Address returns a Ethereym style addresses: Last_20_Bytes(KECCAK256(pubkey)) func (pubKey PubKey) Address() crypto.Address { if len(pubKey) != PubKeySize { - panic("length of pubkey is incorrect") + panic(fmt.Sprintf("length of pubkey is incorrect %d != %d", len(pubKey), PubKeySize)) } - hasherSHA256 := sha256.New() - _, _ = hasherSHA256.Write(pubKey) // does not error - sha := hasherSHA256.Sum(nil) - - hasherRIPEMD160 := ripemd160.New() - _, _ = hasherRIPEMD160.Write(sha) // does not error - - return crypto.Address(hasherRIPEMD160.Sum(nil)) + return crypto.Address(ethCrypto.Keccak256(pubKey[1:])[12:]) } // Bytes returns the pubkey marshaled with amino encoding. @@ -187,41 +230,13 @@ func (pubKey PubKey) Type() string { return KeyType } -// VerifySignature verifies a signature of the form R || S. +// VerifySignature verifies a signature of the form R || S || V. // It rejects signatures which are not in lower-S form. func (pubKey PubKey) VerifySignature(msg []byte, sigStr []byte) bool { - if len(sigStr) != 64 { + if len(sigStr) != SigSize { return false } - pub, err := secp256k1.ParsePubKey(pubKey) - if err != nil { - return false - } - - // parse the signature: - signature := signatureFromBytes(sigStr) - // Reject malleable signatures. libsecp256k1 does this check but btcec doesn't. - // see: https://github.com/ethereum/go-ethereum/blob/f9401ae011ddf7f8d2d95020b7446c17f8d98dc1/crypto/signature_nocgo.go#L90-L93 - // Serialize() would negate S value if it is over half order. - // Hence, if the signature is different after Serialize() if should be rejected. - var modifiedSignature, parseErr = ecdsa.ParseDERSignature(signature.Serialize()) - if parseErr != nil { - return false - } - if !signature.IsEqual(modifiedSignature) { - return false - } - - return signature.Verify(crypto.Sha256(msg), pub) -} - -// Read Signature struct from R || S. Caller needs to ensure -// that len(sigStr) == 64. -func signatureFromBytes(sigStr []byte) *ecdsa.Signature { - var r secp256k1.ModNScalar - r.SetByteSlice(sigStr[:32]) - var s secp256k1.ModNScalar - s.SetByteSlice(sigStr[32:64]) - return ecdsa.NewSignature(&r, &s) + hash := ethCrypto.Keccak256(msg) + return ethCrypto.VerifySignature(pubKey, hash, sigStr[:64]) } diff --git a/crypto/secp256k1/secp256k1_internal_test.go b/crypto/secp256k1/secp256k1_internal_test.go index ae1f55e492..8342c7d8e7 100644 --- a/crypto/secp256k1/secp256k1_internal_test.go +++ b/crypto/secp256k1/secp256k1_internal_test.go @@ -5,13 +5,11 @@ import ( "math/big" "testing" - "github.com/stretchr/testify/require" - secp256k1 "github.com/btcsuite/btcd/btcec/v2" + "github.com/stretchr/testify/require" ) func Test_genPrivKey(t *testing.T) { - empty := make([]byte, 32) oneB := big.NewInt(1).Bytes() onePadded := make([]byte, 32) @@ -82,3 +80,16 @@ func TestSignatureVerificationAndRejectUpperS(t *testing.T) { ) } } + +func TestGenEthPrivKey(t *testing.T) { + msg := []byte("We have lingered long enough on the shores of the cosmic ocean.") + priv := GenPrivKey() + t.Log("privkey ", priv) + sigStr, err := priv.Sign(msg) + require.NoError(t, err) + pub := priv.PubKey() + addr := pub.Address() + t.Log("address ", addr) + t.Log("pub ", pub) + t.Log("SigStr ", sigStr) +} diff --git a/crypto/secp256k1/secp256k1_test.go b/crypto/secp256k1/secp256k1_test.go index 195d9dde70..8b9e97d17a 100644 --- a/crypto/secp256k1/secp256k1_test.go +++ b/crypto/secp256k1/secp256k1_test.go @@ -24,8 +24,8 @@ type keyData struct { var secpDataTable = []keyData{ { priv: "a96e62ed3955e65be32703f12d87b6b5cf26039ecfa948dc5107a495418e5330", - pub: "02950e1cdfcb133d6024109fd489f734eeb4502418e538c28481f22bce276f248c", - addr: "1CKZ9Nx4zgds8tU7nJHotKSDr4a9bYJCa3", + pub: "04950e1cdfcb133d6024109fd489f734eeb4502418e538c28481f22bce276f248ca0ca66092c9fe8adfbb8424bd92f26e170234c42df756075278ead79a8f5c4ae", + addr: "1PrkgVnuHLGZu4EUQGmXkGVuhTfn7t8DJK", }, } diff --git a/evidence/pool_test.go b/evidence/pool_test.go index 815e366613..47ac39cfc4 100644 --- a/evidence/pool_test.go +++ b/evidence/pool_test.go @@ -82,7 +82,7 @@ func TestEvidencePoolBasic(t *testing.T) { next := pool.EvidenceFront() assert.Equal(t, ev, next.Value.(types.Evidence)) - const evidenceBytes int64 = 372 + const evidenceBytes int64 = 374 evs, size = pool.PendingEvidence(evidenceBytes) assert.Equal(t, 1, len(evs)) assert.Equal(t, evidenceBytes, size) // check that the size of the single evidence in bytes is correct diff --git a/go.mod b/go.mod index 22be3bf055..b86f1fd9ef 100644 --- a/go.mod +++ b/go.mod @@ -46,6 +46,7 @@ require ( github.com/btcsuite/btcd/btcutil v1.1.3 github.com/cometbft/cometbft-db v0.7.0 github.com/cosmos/gogoproto v1.4.11 + github.com/ethereum/go-ethereum v1.13.4 github.com/go-git/go-git/v5 v5.11.0 github.com/gofrs/uuid v4.4.0+incompatible github.com/google/uuid v1.4.0 @@ -103,7 +104,7 @@ require ( github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect github.com/docker/cli v23.0.1+incompatible // indirect github.com/docker/distribution v2.8.1+incompatible // indirect - github.com/docker/docker v23.0.1+incompatible // indirect + github.com/docker/docker v24.0.5+incompatible // indirect github.com/docker/docker-credential-helpers v0.7.0 // indirect github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.5.0 // indirect @@ -140,7 +141,7 @@ require ( github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/glog v1.1.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect - github.com/golang/snappy v0.0.4 // indirect + github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2 // indirect github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a // indirect github.com/golangci/go-misc v0.0.0-20220329215616-d24fe342adfe // indirect @@ -165,6 +166,7 @@ require ( github.com/hashicorp/go-version v1.6.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/hexops/gotextdiff v1.0.3 // indirect + github.com/holiman/uint256 v1.2.3 // indirect github.com/iancoleman/strcase v0.2.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect @@ -195,7 +197,7 @@ require ( github.com/matoous/godox v0.0.0-20230222163458-006bad1f9d26 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.17 // indirect - github.com/mattn/go-runewidth v0.0.9 // indirect + github.com/mattn/go-runewidth v0.0.13 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect github.com/mbilski/exhaustivestruct v1.2.0 // indirect github.com/mgechev/revive v1.3.1 // indirect @@ -225,6 +227,7 @@ require ( github.com/quasilyte/gogrep v0.5.0 // indirect github.com/quasilyte/regex/syntax v0.0.0-20210819130434-b3f0c404a727 // indirect github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 // indirect + github.com/rivo/uniseg v0.2.0 // indirect github.com/rs/zerolog v1.29.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/ryancurrah/gomodguard v1.3.0 // indirect diff --git a/go.sum b/go.sum index 015b09364f..0fbaa0b8dc 100644 --- a/go.sum +++ b/go.sum @@ -221,8 +221,8 @@ github.com/docker/cli v23.0.1+incompatible h1:LRyWITpGzl2C9e9uGxzisptnxAn1zfZKXy github.com/docker/cli v23.0.1+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68= github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v23.0.1+incompatible h1:vjgvJZxprTTE1A37nm+CLNAdwu6xZekyoiVlUZEINcY= -github.com/docker/docker v23.0.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v24.0.5+incompatible h1:WmgcE4fxyI6EEXxBRxsHnZXrO1pQ3smi0k/jho4HLeY= +github.com/docker/docker v24.0.5+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/docker-credential-helpers v0.7.0 h1:xtCHsjxogADNZcdv1pKUHXryefjlVRqWqIhk/uXJp0A= github.com/docker/docker-credential-helpers v0.7.0/go.mod h1:rETQfLdHNT3foU5kuNkFR1R1V12OJRRO5lzt2D1b5X0= github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= @@ -243,6 +243,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/esimonov/ifshort v1.0.4 h1:6SID4yGWfRae/M7hkVDVVyppy8q/v9OuxNdmjLQStBA= github.com/esimonov/ifshort v1.0.4/go.mod h1:Pe8zjlRrJ80+q2CxHLfEOfTwxCZ4O+MuhcHcfgNWTk0= +github.com/ethereum/go-ethereum v1.13.4 h1:25HJnaWVg3q1O7Z62LaaI6S9wVq8QCw3K88g8wEzrcM= +github.com/ethereum/go-ethereum v1.13.4/go.mod h1:I0U5VewuuTzvBtVzKo7b3hJzDhXOUtn9mJW7SsIPB0Q= github.com/ettle/strcase v0.1.1 h1:htFueZyVeE1XNnMEfbqp5r67qAN/4r6ya1ysq8Q+Zcw= github.com/ettle/strcase v0.1.1/go.mod h1:hzDLsPC7/lwKyBOywSHEP89nt2pDgdy+No1NBA9o9VY= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0= @@ -378,8 +380,9 @@ github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk= +github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2 h1:23T5iq8rbUYlhpt5DB4XJkc6BU31uODLD1o1gKvZmD0= github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2/go.mod h1:k9Qvh+8juN+UKMCS/3jFtGICgW8O96FVaZsaxdzDkR4= github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a h1:w8hkcTqaFpzKqonE9uMCefW1WDie15eSP/4MssdenaM= @@ -474,6 +477,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= +github.com/holiman/uint256 v1.2.3 h1:K8UWO1HUJpRMXBxbmaY1Y8IAMZC/RsKB+ArEnnK4l5o= +github.com/holiman/uint256 v1.2.3/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0= github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= @@ -581,8 +586,9 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= +github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/go-sqlite3 v1.14.9 h1:10HX2Td0ocZpYEjhilsuo6WWtUqttj2Kb0KtD86/KYA= github.com/mattn/go-sqlite3 v1.14.9/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= @@ -719,6 +725,8 @@ github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 h1:M8mH9eK4OUR4l github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567/go.mod h1:DWNGW8A4Y+GyBgPuaQJuWiy0XYftx4Xm/y5Jqk9I6VQ= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= +github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= @@ -1326,8 +1334,8 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= -gotest.tools/v3 v3.0.3 h1:4AuOwCGf4lLR9u3YOe2awrHygurzhO/HeQ6laiA6Sx0= -gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8= +gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= +gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/libs/log/filter.go b/libs/log/filter.go index 4b7ed981cd..5f91c3fba9 100644 --- a/libs/log/filter.go +++ b/libs/log/filter.go @@ -7,6 +7,7 @@ type level byte const ( levelDebug level = 1 << iota levelInfo + levelWarn levelError ) @@ -46,6 +47,14 @@ func (l *filter) Info(msg string, keyvals ...interface{}) { l.next.Info(msg, keyvals...) } +func (l *filter) Warn(msg string, keyvals ...interface{}) { + levelAllowed := l.allowed&levelWarn != 0 + if !levelAllowed { + return + } + l.next.Warn(msg, keyvals...) +} + func (l *filter) Debug(msg string, keyvals ...interface{}) { levelAllowed := l.allowed&levelDebug != 0 if !levelAllowed { diff --git a/libs/log/logger.go b/libs/log/logger.go index 22ed68f1a1..ef00acbd22 100644 --- a/libs/log/logger.go +++ b/libs/log/logger.go @@ -10,6 +10,7 @@ import ( type Logger interface { Debug(msg string, keyvals ...interface{}) Info(msg string, keyvals ...interface{}) + Warn(msg string, keyvals ...interface{}) Error(msg string, keyvals ...interface{}) With(keyvals ...interface{}) Logger diff --git a/libs/log/nop_logger.go b/libs/log/nop_logger.go index 12d75abe6b..c31229e843 100644 --- a/libs/log/nop_logger.go +++ b/libs/log/nop_logger.go @@ -9,6 +9,7 @@ var _ Logger = (*nopLogger)(nil) func NewNopLogger() Logger { return &nopLogger{} } func (nopLogger) Info(string, ...interface{}) {} +func (nopLogger) Warn(string, ...interface{}) {} func (nopLogger) Debug(string, ...interface{}) {} func (nopLogger) Error(string, ...interface{}) {} diff --git a/libs/log/tm_logger.go b/libs/log/tm_logger.go index ac0d08adb0..3493ca160d 100644 --- a/libs/log/tm_logger.go +++ b/libs/log/tm_logger.go @@ -59,6 +59,15 @@ func (l *tmLogger) Info(msg string, keyvals ...interface{}) { } } +// Warn logs a message at level Warn. +func (l *tmLogger) Warn(msg string, keyvals ...interface{}) { + lWithLevel := kitlevel.Warn(l.srcLogger) + if err := kitlog.With(lWithLevel, msgKey, msg).Log(keyvals...); err != nil { + errLogger := kitlevel.Error(l.srcLogger) + kitlog.With(errLogger, msgKey, msg).Log("err", err) //nolint:errcheck // no need to check error again + } +} + // Debug logs a message at level Debug. func (l *tmLogger) Debug(msg string, keyvals ...interface{}) { lWithLevel := kitlevel.Debug(l.srcLogger) diff --git a/libs/log/tracing_logger.go b/libs/log/tracing_logger.go index d2a6ff44e5..002ea0c08b 100644 --- a/libs/log/tracing_logger.go +++ b/libs/log/tracing_logger.go @@ -32,6 +32,10 @@ func (l *tracingLogger) Info(msg string, keyvals ...interface{}) { l.next.Info(msg, formatErrors(keyvals)...) } +func (l *tracingLogger) Warn(msg string, keyvals ...interface{}) { + l.next.Warn(msg, formatErrors(keyvals)...) +} + func (l *tracingLogger) Debug(msg string, keyvals ...interface{}) { l.next.Debug(msg, formatErrors(keyvals)...) } diff --git a/p2p/conn/secret_connection.go b/p2p/conn/secret_connection.go index 65bcc543af..69945c5fca 100644 --- a/p2p/conn/secret_connection.go +++ b/p2p/conn/secret_connection.go @@ -24,6 +24,7 @@ import ( "github.com/cometbft/cometbft/crypto" "github.com/cometbft/cometbft/crypto/ed25519" cryptoenc "github.com/cometbft/cometbft/crypto/encoding" + "github.com/cometbft/cometbft/crypto/secp256k1" "github.com/cometbft/cometbft/libs/async" "github.com/cometbft/cometbft/libs/protoio" cmtsync "github.com/cometbft/cometbft/libs/sync" @@ -165,8 +166,10 @@ func MakeSecretConnection(conn io.ReadWriteCloser, locPrivKey crypto.PrivKey) (* } remPubKey, remSignature := authSigMsg.Key, authSigMsg.Sig - if _, ok := remPubKey.(ed25519.PubKey); !ok { - return nil, fmt.Errorf("expected ed25519 pubkey, got %T", remPubKey) + switch remPubKey.(type) { + case secp256k1.PubKey, ed25519.PubKey: + default: + return nil, fmt.Errorf("expected secp256k1/ed25519 pubkey, got %T", remPubKey) } if !remPubKey.VerifySignature(challenge[:], remSignature) { return nil, errors.New("challenge verification failed") diff --git a/p2p/pex/pex_reactor.go b/p2p/pex/pex_reactor.go index 0457df2c62..dc2bee0e7f 100644 --- a/p2p/pex/pex_reactor.go +++ b/p2p/pex/pex_reactor.go @@ -543,6 +543,12 @@ func (r *Reactor) dialAttemptsInfo(addr *p2p.NetAddress) (attempts int, lastDial } func (r *Reactor) dialPeer(addr *p2p.NetAddress) error { + if r.Switch.Peers().Size() == 0 { + r.Logger.Error("Peer Info", "numPeers", r.Switch.Peers().Size()) + } else { + r.Logger.Info("Peer Info", "numPeers", r.Switch.Peers().Size()) + } + attempts, lastDialed := r.dialAttemptsInfo(addr) if !r.Switch.IsPeerPersistent(addr) && attempts > maxAttemptsToDial { r.book.MarkBad(addr, defaultBanTime) diff --git a/privval/file.go b/privval/file.go index a092e38b08..5b8099a59f 100644 --- a/privval/file.go +++ b/privval/file.go @@ -10,7 +10,7 @@ import ( "github.com/cosmos/gogoproto/proto" "github.com/cometbft/cometbft/crypto" - "github.com/cometbft/cometbft/crypto/ed25519" + "github.com/cometbft/cometbft/crypto/secp256k1" cmtbytes "github.com/cometbft/cometbft/libs/bytes" cmtjson "github.com/cometbft/cometbft/libs/json" cmtos "github.com/cometbft/cometbft/libs/os" @@ -178,7 +178,7 @@ func NewFilePV(privKey crypto.PrivKey, keyFilePath, stateFilePath string) *FileP // GenFilePV generates a new validator with randomly generated private key // and sets the filePaths, but does not call Save(). func GenFilePV(keyFilePath, stateFilePath string) *FilePV { - return NewFilePV(ed25519.GenPrivKey(), keyFilePath, stateFilePath) + return NewFilePV(secp256k1.GenPrivKey(), keyFilePath, stateFilePath) } // LoadFilePV loads a FilePV from the filePaths. The FilePV handles double diff --git a/proto/tendermint/crypto/keys.pb.go b/proto/tendermint/crypto/keys.pb.go index 0edb2269f5..ab113253a2 100644 --- a/proto/tendermint/crypto/keys.pb.go +++ b/proto/tendermint/crypto/keys.pb.go @@ -30,6 +30,7 @@ type PublicKey struct { // // *PublicKey_Ed25519 // *PublicKey_Secp256K1 + // *PublicKey_Secp256K1Uncompressed Sum isPublicKey_Sum `protobuf_oneof:"sum"` } @@ -80,9 +81,13 @@ type PublicKey_Ed25519 struct { type PublicKey_Secp256K1 struct { Secp256K1 []byte `protobuf:"bytes,2,opt,name=secp256k1,proto3,oneof" json:"secp256k1,omitempty"` } +type PublicKey_Secp256K1Uncompressed struct { + Secp256K1Uncompressed []byte `protobuf:"bytes,3,opt,name=secp256k1_uncompressed,json=secp256k1Uncompressed,proto3,oneof" json:"secp256k1_uncompressed,omitempty"` +} -func (*PublicKey_Ed25519) isPublicKey_Sum() {} -func (*PublicKey_Secp256K1) isPublicKey_Sum() {} +func (*PublicKey_Ed25519) isPublicKey_Sum() {} +func (*PublicKey_Secp256K1) isPublicKey_Sum() {} +func (*PublicKey_Secp256K1Uncompressed) isPublicKey_Sum() {} func (m *PublicKey) GetSum() isPublicKey_Sum { if m != nil { @@ -105,11 +110,19 @@ func (m *PublicKey) GetSecp256K1() []byte { return nil } +func (m *PublicKey) GetSecp256K1Uncompressed() []byte { + if x, ok := m.GetSum().(*PublicKey_Secp256K1Uncompressed); ok { + return x.Secp256K1Uncompressed + } + return nil +} + // XXX_OneofWrappers is for the internal use of the proto package. func (*PublicKey) XXX_OneofWrappers() []interface{} { return []interface{}{ (*PublicKey_Ed25519)(nil), (*PublicKey_Secp256K1)(nil), + (*PublicKey_Secp256K1Uncompressed)(nil), } } @@ -120,20 +133,22 @@ func init() { func init() { proto.RegisterFile("tendermint/crypto/keys.proto", fileDescriptor_cb048658b234868c) } var fileDescriptor_cb048658b234868c = []byte{ - // 204 bytes of a gzipped FileDescriptorProto + // 234 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x29, 0x49, 0xcd, 0x4b, 0x49, 0x2d, 0xca, 0xcd, 0xcc, 0x2b, 0xd1, 0x4f, 0x2e, 0xaa, 0x2c, 0x28, 0xc9, 0xd7, 0xcf, 0x4e, 0xad, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x44, 0xc8, 0xea, 0x41, 0x64, 0xa5, - 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0xb2, 0xfa, 0x20, 0x16, 0x44, 0xa1, 0x52, 0x04, 0x17, 0x67, - 0x40, 0x69, 0x52, 0x4e, 0x66, 0xb2, 0x77, 0x6a, 0xa5, 0x90, 0x14, 0x17, 0x7b, 0x6a, 0x8a, 0x91, - 0xa9, 0xa9, 0xa1, 0xa5, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x8f, 0x07, 0x43, 0x10, 0x4c, 0x40, 0x48, - 0x8e, 0x8b, 0xb3, 0x38, 0x35, 0xb9, 0xc0, 0xc8, 0xd4, 0x2c, 0xdb, 0x50, 0x82, 0x09, 0x2a, 0x8b, - 0x10, 0xb2, 0xe2, 0x78, 0xb1, 0x40, 0x9e, 0xf1, 0xc5, 0x42, 0x79, 0x46, 0x27, 0x56, 0x2e, 0xe6, - 0xe2, 0xd2, 0x5c, 0x27, 0xbf, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, - 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0x32, - 0x49, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xce, 0xcf, 0x4d, 0x2d, - 0x49, 0x4a, 0x2b, 0x41, 0x30, 0x20, 0x4e, 0xc4, 0xf0, 0x5d, 0x12, 0x1b, 0x58, 0xc2, 0x18, 0x10, - 0x00, 0x00, 0xff, 0xff, 0xa3, 0xfb, 0xf7, 0x98, 0xf9, 0x00, 0x00, 0x00, + 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0xb2, 0xfa, 0x20, 0x16, 0x44, 0xa1, 0xd2, 0x44, 0x46, 0x2e, + 0xce, 0x80, 0xd2, 0xa4, 0x9c, 0xcc, 0x64, 0xef, 0xd4, 0x4a, 0x21, 0x29, 0x2e, 0xf6, 0xd4, 0x14, + 0x23, 0x53, 0x53, 0x43, 0x4b, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x1e, 0x0f, 0x86, 0x20, 0x98, 0x80, + 0x90, 0x1c, 0x17, 0x67, 0x71, 0x6a, 0x72, 0x81, 0x91, 0xa9, 0x59, 0xb6, 0xa1, 0x04, 0x13, 0x54, + 0x16, 0x21, 0x24, 0x64, 0xce, 0x25, 0x06, 0xe7, 0xc4, 0x97, 0xe6, 0x25, 0xe7, 0xe7, 0x16, 0x14, + 0xa5, 0x16, 0x17, 0xa7, 0xa6, 0x48, 0x30, 0x43, 0x15, 0x8b, 0xc2, 0xe5, 0x43, 0x91, 0xa4, 0xad, + 0x38, 0x5e, 0x2c, 0x90, 0x67, 0x7c, 0xb1, 0x50, 0x9e, 0xd1, 0x89, 0x95, 0x8b, 0xb9, 0xb8, 0x34, + 0xd7, 0xc9, 0xef, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, + 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x4c, 0xd2, 0x33, + 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0x93, 0xf3, 0x73, 0x53, 0x4b, 0x92, 0xd2, + 0x4a, 0x10, 0x0c, 0x88, 0xe7, 0x30, 0xc2, 0x25, 0x89, 0x0d, 0x2c, 0x61, 0x0c, 0x08, 0x00, 0x00, + 0xff, 0xff, 0xf0, 0x8b, 0x85, 0xa8, 0x33, 0x01, 0x00, 0x00, } func (this *PublicKey) Compare(that interface{}) int { @@ -174,6 +189,8 @@ func (this *PublicKey) Compare(that interface{}) int { thisType = 0 case *PublicKey_Secp256K1: thisType = 1 + case *PublicKey_Secp256K1Uncompressed: + thisType = 2 default: panic(fmt.Sprintf("compare: unexpected type %T in oneof", this.Sum)) } @@ -183,6 +200,8 @@ func (this *PublicKey) Compare(that interface{}) int { that1Type = 0 case *PublicKey_Secp256K1: that1Type = 1 + case *PublicKey_Secp256K1Uncompressed: + that1Type = 2 default: panic(fmt.Sprintf("compare: unexpected type %T in oneof", that1.Sum)) } @@ -258,6 +277,36 @@ func (this *PublicKey_Secp256K1) Compare(that interface{}) int { } return 0 } +func (this *PublicKey_Secp256K1Uncompressed) Compare(that interface{}) int { + if that == nil { + if this == nil { + return 0 + } + return 1 + } + + that1, ok := that.(*PublicKey_Secp256K1Uncompressed) + if !ok { + that2, ok := that.(PublicKey_Secp256K1Uncompressed) + if ok { + that1 = &that2 + } else { + return 1 + } + } + if that1 == nil { + if this == nil { + return 0 + } + return 1 + } else if this == nil { + return -1 + } + if c := bytes.Compare(this.Secp256K1Uncompressed, that1.Secp256K1Uncompressed); c != 0 { + return c + } + return 0 +} func (this *PublicKey) Equal(that interface{}) bool { if that == nil { return this == nil @@ -336,6 +385,30 @@ func (this *PublicKey_Secp256K1) Equal(that interface{}) bool { } return true } +func (this *PublicKey_Secp256K1Uncompressed) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*PublicKey_Secp256K1Uncompressed) + if !ok { + that2, ok := that.(PublicKey_Secp256K1Uncompressed) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !bytes.Equal(this.Secp256K1Uncompressed, that1.Secp256K1Uncompressed) { + return false + } + return true +} func (m *PublicKey) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -400,6 +473,22 @@ func (m *PublicKey_Secp256K1) MarshalToSizedBuffer(dAtA []byte) (int, error) { } return len(dAtA) - i, nil } +func (m *PublicKey_Secp256K1Uncompressed) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PublicKey_Secp256K1Uncompressed) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.Secp256K1Uncompressed != nil { + i -= len(m.Secp256K1Uncompressed) + copy(dAtA[i:], m.Secp256K1Uncompressed) + i = encodeVarintKeys(dAtA, i, uint64(len(m.Secp256K1Uncompressed))) + i-- + dAtA[i] = 0x1a + } + return len(dAtA) - i, nil +} func encodeVarintKeys(dAtA []byte, offset int, v uint64) int { offset -= sovKeys(v) base := offset @@ -447,6 +536,18 @@ func (m *PublicKey_Secp256K1) Size() (n int) { } return n } +func (m *PublicKey_Secp256K1Uncompressed) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Secp256K1Uncompressed != nil { + l = len(m.Secp256K1Uncompressed) + n += 1 + l + sovKeys(uint64(l)) + } + return n +} func sovKeys(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 @@ -549,6 +650,39 @@ func (m *PublicKey) Unmarshal(dAtA []byte) error { copy(v, dAtA[iNdEx:postIndex]) m.Sum = &PublicKey_Secp256K1{v} iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Secp256K1Uncompressed", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowKeys + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthKeys + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthKeys + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := make([]byte, postIndex-iNdEx) + copy(v, dAtA[iNdEx:postIndex]) + m.Sum = &PublicKey_Secp256K1Uncompressed{v} + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipKeys(dAtA[iNdEx:]) diff --git a/proto/tendermint/crypto/keys.proto b/proto/tendermint/crypto/keys.proto index 8fa192fa4b..62139ac1e6 100644 --- a/proto/tendermint/crypto/keys.proto +++ b/proto/tendermint/crypto/keys.proto @@ -13,5 +13,6 @@ message PublicKey { oneof sum { bytes ed25519 = 1; bytes secp256k1 = 2; + bytes secp256k1_uncompressed = 3; } } diff --git a/state/execution_test.go b/state/execution_test.go index cbc39f1fe2..0f42120c1b 100644 --- a/state/execution_test.go +++ b/state/execution_test.go @@ -16,8 +16,8 @@ import ( abci "github.com/cometbft/cometbft/abci/types" abcimocks "github.com/cometbft/cometbft/abci/types/mocks" "github.com/cometbft/cometbft/crypto" - "github.com/cometbft/cometbft/crypto/ed25519" cryptoenc "github.com/cometbft/cometbft/crypto/encoding" + "github.com/cometbft/cometbft/crypto/secp256k1" "github.com/cometbft/cometbft/crypto/tmhash" "github.com/cometbft/cometbft/internal/test" "github.com/cometbft/cometbft/libs/log" @@ -445,14 +445,14 @@ func TestProcessProposal(t *testing.T) { } func TestValidateValidatorUpdates(t *testing.T) { - pubkey1 := ed25519.GenPrivKey().PubKey() - pubkey2 := ed25519.GenPrivKey().PubKey() + pubkey1 := secp256k1.GenPrivKey().PubKey() + pubkey2 := secp256k1.GenPrivKey().PubKey() pk1, err := cryptoenc.PubKeyToProto(pubkey1) assert.NoError(t, err) pk2, err := cryptoenc.PubKeyToProto(pubkey2) assert.NoError(t, err) - defaultValidatorParams := types.ValidatorParams{PubKeyTypes: []string{types.ABCIPubKeyTypeEd25519}} + defaultValidatorParams := types.ValidatorParams{PubKeyTypes: []string{types.ABCIPubKeyTypeSecp256k1}} testCases := []struct { name string @@ -502,9 +502,9 @@ func TestValidateValidatorUpdates(t *testing.T) { } func TestUpdateValidators(t *testing.T) { - pubkey1 := ed25519.GenPrivKey().PubKey() + pubkey1 := secp256k1.GenPrivKey().PubKey() val1 := types.NewValidator(pubkey1, 10) - pubkey2 := ed25519.GenPrivKey().PubKey() + pubkey2 := secp256k1.GenPrivKey().PubKey() val2 := types.NewValidator(pubkey2, 20) pk, err := cryptoenc.PubKeyToProto(pubkey1) @@ -629,7 +629,7 @@ func TestFinalizeBlockValidatorUpdates(t *testing.T) { require.NoError(t, err) blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: bps.Header()} - pubkey := ed25519.GenPrivKey().PubKey() + pubkey := secp256k1.GenPrivKey().PubKey() pk, err := cryptoenc.PubKeyToProto(pubkey) require.NoError(t, err) app.ValidatorUpdates = []abci.ValidatorUpdate{ diff --git a/state/tx_filter_test.go b/state/tx_filter_test.go index 4c5384720a..6772715d76 100644 --- a/state/tx_filter_test.go +++ b/state/tx_filter_test.go @@ -16,7 +16,7 @@ import ( func TestTxFilter(t *testing.T) { genDoc := randomGenesisDoc() - genDoc.ConsensusParams.Block.MaxBytes = 3000 + genDoc.ConsensusParams.Block.MaxBytes = 3001 genDoc.ConsensusParams.Evidence.MaxBytes = 1500 // Max size of Txs is much smaller than size of block, diff --git a/test/e2e/networks/simple.toml b/test/e2e/networks/simple.toml index 96b81f79fe..f40b3a8859 100644 --- a/test/e2e/networks/simple.toml +++ b/test/e2e/networks/simple.toml @@ -1,3 +1,5 @@ +key_type = "secp256k1" + [node.validator01] [node.validator02] [node.validator03] diff --git a/test/e2e/pkg/testnet.go b/test/e2e/pkg/testnet.go index 92ce4f7892..603c753757 100644 --- a/test/e2e/pkg/testnet.go +++ b/test/e2e/pkg/testnet.go @@ -214,7 +214,7 @@ func NewTestnetFromManifest(manifest Manifest, file string, ifd InfrastructureDa Version: v, Testnet: testnet, PrivvalKey: keyGen.Generate(manifest.KeyType), - NodeKey: keyGen.Generate("ed25519"), + NodeKey: keyGen.Generate("secp256k1"), InternalIP: ind.IPAddress, ExternalIP: extIP, ProxyPort: ind.Port, @@ -584,7 +584,7 @@ func (n Node) Stateless() bool { return n.Mode == ModeLight || n.Mode == ModeSeed } -// keyGenerator generates pseudorandom Ed25519 keys based on a seed. +// keyGenerator generates pseudorandom Secp256k1 keys based on a seed. type keyGenerator struct { random *rand.Rand } @@ -603,9 +603,9 @@ func (g *keyGenerator) Generate(keyType string) crypto.PrivKey { panic(err) // this shouldn't happen } switch keyType { - case "secp256k1": + case "", "secp256k1": return secp256k1.GenPrivKeySecp256k1(seed) - case "", "ed25519": + case "ed25519": return ed25519.GenPrivKeyFromSecret(seed) default: panic("KeyType not supported") // should not make it this far diff --git a/types/block.go b/types/block.go index 82d0fa4d98..5f4ae7ce3f 100644 --- a/types/block.go +++ b/types/block.go @@ -586,9 +586,9 @@ const ( const ( // Max size of commit without any commitSigs -> 82 for BlockID, 8 for Height, 4 for Round. MaxCommitOverheadBytes int64 = 94 - // Commit sig size is made up of 64 bytes for the signature, 20 bytes for the address, + // Commit sig size is made up of 65 bytes for the signature (for Heimdall-v2), 20 bytes for the address, // 1 byte for the flag and 14 bytes for the timestamp - MaxCommitSigBytes int64 = 109 + MaxCommitSigBytes int64 = 110 ) // CommitSig is a part of the Vote included in a Commit. diff --git a/types/block_test.go b/types/block_test.go index f9c97a7e84..df60ce5726 100644 --- a/types/block_test.go +++ b/types/block_test.go @@ -466,10 +466,10 @@ func TestBlockMaxDataBytes(t *testing.T) { 0: {-10, 1, 0, true, 0}, 1: {10, 1, 0, true, 0}, 2: {841, 1, 0, true, 0}, - 3: {842, 1, 0, false, 0}, - 4: {843, 1, 0, false, 1}, - 5: {954, 2, 0, false, 1}, - 6: {1053, 2, 100, false, 0}, + 3: {843, 1, 0, false, 0}, + 4: {844, 1, 0, false, 1}, + 5: {956, 2, 0, false, 1}, + 6: {1055, 2, 100, false, 0}, } for i, tc := range testCases { @@ -497,8 +497,8 @@ func TestBlockMaxDataBytesNoEvidence(t *testing.T) { 0: {-10, 1, true, 0}, 1: {10, 1, true, 0}, 2: {841, 1, true, 0}, - 3: {842, 1, false, 0}, - 4: {843, 1, false, 1}, + 3: {843, 1, false, 0}, + 4: {844, 1, false, 1}, } for i, tc := range testCases { diff --git a/types/params.go b/types/params.go index 81bfa5aa2b..ead8229c1a 100644 --- a/types/params.go +++ b/types/params.go @@ -112,9 +112,10 @@ func DefaultEvidenceParams() EvidenceParams { // DefaultValidatorParams returns a default ValidatorParams, which allows // only ed25519 pubkeys. +// TODO HV2: This should probably be secp256k1 in our case func DefaultValidatorParams() ValidatorParams { return ValidatorParams{ - PubKeyTypes: []string{ABCIPubKeyTypeEd25519}, + PubKeyTypes: []string{ABCIPubKeyTypeSecp256k1}, } } diff --git a/types/priv_validator.go b/types/priv_validator.go index 340794d00c..a32798244e 100644 --- a/types/priv_validator.go +++ b/types/priv_validator.go @@ -6,7 +6,7 @@ import ( "fmt" "github.com/cometbft/cometbft/crypto" - "github.com/cometbft/cometbft/crypto/ed25519" + "github.com/cometbft/cometbft/crypto/secp256k1" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" ) @@ -54,7 +54,7 @@ type MockPV struct { } func NewMockPV() MockPV { - return MockPV{ed25519.GenPrivKey(), false, false} + return MockPV{secp256k1.GenPrivKey(), false, false} } // NewMockPVWithParams allows one to create a MockPV instance, but with finer @@ -154,5 +154,5 @@ func (pv *ErroringMockPV) SignProposal(string, *cmtproto.Proposal) error { // NewErroringMockPV returns a MockPV that fails on each signing request. Again, for testing only. func NewErroringMockPV() *ErroringMockPV { - return &ErroringMockPV{MockPV{ed25519.GenPrivKey(), false, false}} + return &ErroringMockPV{MockPV{secp256k1.GenPrivKey(), false, false}} } diff --git a/types/signable.go b/types/signable.go index 8ba2e6599a..fbfc5c93a3 100644 --- a/types/signable.go +++ b/types/signable.go @@ -9,7 +9,9 @@ var ( // MaxSignatureSize is a maximum allowed signature size for the Proposal // and Vote. // XXX: secp256k1 does not have Size nor MaxSize defined. - MaxSignatureSize = cmtmath.MaxInt(ed25519.SignatureSize, 64) + // NOTE(Heimdall-v2): This is a minimal tweak to allow max signature size for ECDSA + // and reduce changes from upstream. + MaxSignatureSize = cmtmath.MaxInt(ed25519.SignatureSize, 65) ) // Signable is an interface for all signable things.