From a1f57cd2fd81a3ee560b25f9e7bcdea79262bde7 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Tue, 12 Dec 2023 16:32:34 -0700 Subject: [PATCH 1/9] use grpc timeout in nonce overallocation --- signer/cosigner_nonce_cache.go | 9 +++++---- signer/threshold_validator.go | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/signer/cosigner_nonce_cache.go b/signer/cosigner_nonce_cache.go index f9b34b89..3b8ad25c 100644 --- a/signer/cosigner_nonce_cache.go +++ b/signer/cosigner_nonce_cache.go @@ -15,6 +15,7 @@ const ( defaultGetNoncesInterval = 3 * time.Second defaultGetNoncesTimeout = 4 * time.Second defaultNonceExpiration = 10 * time.Second // half of the local cosigner cache expiration + nonceOverallocation = 1.5 ) type CosignerNonceCache struct { @@ -198,7 +199,7 @@ func (cnc *CosignerNonceCache) getUuids(n int) []uuid.UUID { } func (cnc *CosignerNonceCache) target(noncesPerMinute float64) int { - t := int((noncesPerMinute / 60) * ((cnc.getNoncesInterval.Seconds() * 1.2) + 0.5)) + t := int((noncesPerMinute / 60) * ((cnc.getNoncesInterval.Seconds() * nonceOverallocation) + float64(cnc.getNoncesTimeout.Seconds()))) if t <= 0 { return 1 // always target at least one nonce ready } @@ -332,12 +333,12 @@ func (cnc *CosignerNonceCache) Start(ctx context.Context) { cnc.lastReconcileNonces.Store(uint64(cnc.cache.Size())) cnc.lastReconcileTime = time.Now() - ticker := time.NewTimer(cnc.getNoncesInterval) + timer := time.NewTimer(cnc.getNoncesInterval) for { select { case <-ctx.Done(): return - case <-ticker.C: + case <-timer.C: case <-cnc.empty: // clear out channel for len(cnc.empty) > 0 { @@ -345,7 +346,7 @@ func (cnc *CosignerNonceCache) Start(ctx context.Context) { } } cnc.reconcile(ctx) - ticker.Reset(cnc.getNoncesInterval) + timer.Reset(cnc.getNoncesInterval) } } diff --git a/signer/threshold_validator.go b/signer/threshold_validator.go index 2a9d8609..e99b75df 100644 --- a/signer/threshold_validator.go +++ b/signer/threshold_validator.go @@ -84,7 +84,7 @@ func NewThresholdValidator( allCosigners, leader, defaultGetNoncesInterval, - defaultGetNoncesTimeout, + grpcTimeout, defaultNonceExpiration, uint8(threshold), nil, From b98b43ca947c25f8c7532867cf6ec47911781f49 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Sun, 17 Dec 2023 16:11:36 -0700 Subject: [PATCH 2/9] bn254 first pass, still needs nonces --- cmd/horcrux/cmd/address.go | 14 +- cmd/horcrux/cmd/migrate.go | 8 +- cmd/horcrux/cmd/migrate_test.go | 10 +- cmd/horcrux/cmd/root.go | 2 +- cmd/horcrux/cmd/shards.go | 15 +- cmd/horcrux/cmd/testdata/testdata.go | 2 +- go.mod | 53 +--- go.sum | 283 ++---------------- signer/config.go | 31 +- signer/cosigner_key.go | 89 +----- signer/cosigner_key_shares.go | 94 ++++-- signer/cosigner_nonce_cache_test.go | 10 +- signer/local_cosigner.go | 28 +- signer/local_cosigner_test.go | 7 +- signer/raft_store_test.go | 2 +- signer/threshold_signer.go | 8 + signer/threshold_signer_soft_bn254.go | 133 ++++++++ ...ft.go => threshold_signer_soft_ed25519.go} | 45 ++- signer/threshold_validator_test.go | 101 +++++-- test/go.mod | 2 + test/go.sum | 20 ++ test/horcrux_test.go | 38 +-- test/validator.go | 15 +- test/validator_single.go | 27 +- test/validator_threshold.go | 22 +- 25 files changed, 493 insertions(+), 566 deletions(-) create mode 100644 signer/threshold_signer_soft_bn254.go rename signer/{threshold_signer_soft.go => threshold_signer_soft_ed25519.go} (64%) diff --git a/cmd/horcrux/cmd/address.go b/cmd/horcrux/cmd/address.go index 644d577a..572093b9 100644 --- a/cmd/horcrux/cmd/address.go +++ b/cmd/horcrux/cmd/address.go @@ -1,12 +1,12 @@ package cmd import ( + "crypto/sha256" "encoding/hex" "encoding/json" "fmt" "strings" - "github.com/cometbft/cometbft/crypto" cometprivval "github.com/cometbft/cometbft/privval" "github.com/cosmos/cosmos-sdk/types/bech32" "github.com/spf13/cobra" @@ -29,7 +29,7 @@ func addressCmd() *cobra.Command { Args: cobra.RangeArgs(1, 2), RunE: func(cmd *cobra.Command, args []string) error { - var pubKey crypto.PubKey + var pubKey []byte chainID := args[0] @@ -45,7 +45,7 @@ func addressCmd() *cobra.Command { return err } - key, err := signer.LoadCosignerEd25519Key(keyFile) + key, err := signer.LoadCosignerKey(keyFile) if err != nil { return fmt.Errorf("error reading cosigner key: %w, check that key is present for chain ID: %s", err, chainID) } @@ -62,12 +62,12 @@ func addressCmd() *cobra.Command { } filePV := cometprivval.LoadFilePVEmptyState(keyFile, "") - pubKey = filePV.Key.PubKey + pubKey = filePV.Key.PubKey.Bytes() default: panic(fmt.Errorf("unexpected sign mode: %s", config.Config.SignMode)) } - pubKeyAddress := pubKey.Address() + address := sha256.New().Sum(pubKey)[:20] pubKeyJSON, err := signer.PubKey("", pubKey) if err != nil { @@ -75,12 +75,12 @@ func addressCmd() *cobra.Command { } output := AddressCmdOutput{ - HexAddress: strings.ToUpper(hex.EncodeToString(pubKeyAddress)), + HexAddress: strings.ToUpper(hex.EncodeToString(address)), PubKey: pubKeyJSON, } if len(args) == 2 { - bech32ValConsAddress, err := bech32.ConvertAndEncode(args[1]+"valcons", pubKeyAddress) + bech32ValConsAddress, err := bech32.ConvertAndEncode(args[1]+"valcons", address) if err != nil { return err } diff --git a/cmd/horcrux/cmd/migrate.go b/cmd/horcrux/cmd/migrate.go index 51bfdc87..59a0ad45 100644 --- a/cmd/horcrux/cmd/migrate.go +++ b/cmd/horcrux/cmd/migrate.go @@ -103,7 +103,7 @@ func (key *v2CosignerKey) UnmarshalJSON(data []byte) error { // Prior to the tendermint protobuf migration, the public key bytes in key files // were encoded using the go-amino libraries via - // cdc.MarshalBinaryBare(CosignerEd25519Key.PubKey) + // cdc.MarshalBinaryBare(CosignerKey.PubKey) // // To support reading the public key bytes from these key files, we fallback to // amino unmarshalling if the protobuf unmarshalling fails @@ -218,13 +218,13 @@ func migrateCmd() *cobra.Command { return err } - newEd25519Key := signer.CosignerEd25519Key{ - PubKey: legacyCosignerKey.PubKey, + newEd25519Key := signer.CosignerKey{ + PubKey: legacyCosignerKey.PubKey.Bytes(), PrivateShard: legacyCosignerKey.ShareKey, ID: legacyCosignerKey.ID, } - newEd25519KeyBz, err := newEd25519Key.MarshalJSON() + newEd25519KeyBz, err := json.Marshal(newEd25519Key) if err != nil { return fmt.Errorf("failed to marshal new Ed25519 key to json: %w", err) } diff --git a/cmd/horcrux/cmd/migrate_test.go b/cmd/horcrux/cmd/migrate_test.go index b356723d..311ae236 100644 --- a/cmd/horcrux/cmd/migrate_test.go +++ b/cmd/horcrux/cmd/migrate_test.go @@ -42,7 +42,7 @@ func TestMigrateV2toV3(t *testing.T) { newKeyShardFileBz, err := os.ReadFile(newKeyShardFile) require.NoError(t, err) - require.Equal(t, testdata.CosignerEd25519KeyMigrated, string(newKeyShardFileBz)) + require.Equal(t, testdata.CosignerKeyMigrated, string(newKeyShardFileBz)) newRSAKeyFileBz, err := os.ReadFile(newRSAKeyFile) require.NoError(t, err) @@ -104,7 +104,7 @@ func TestMigrateV2toV3DifferentKeyFilePath(t *testing.T) { newKeyShardFileBz, err := os.ReadFile(newKeyShardFile) require.NoError(t, err) - require.Equal(t, testdata.CosignerEd25519KeyMigrated, string(newKeyShardFileBz)) + require.Equal(t, testdata.CosignerKeyMigrated, string(newKeyShardFileBz)) newRSAKeyFileBz, err := os.ReadFile(newRSAKeyFile) require.NoError(t, err) @@ -144,7 +144,7 @@ func TestMigrateV2toV3KeysOnly(t *testing.T) { newKeyShardFileBz, err := os.ReadFile(newKeyShardFile) require.NoError(t, err) - require.Equal(t, testdata.CosignerEd25519KeyMigrated, string(newKeyShardFileBz)) + require.Equal(t, testdata.CosignerKeyMigrated, string(newKeyShardFileBz)) newRSAKeyFileBz, err := os.ReadFile(newRSAKeyFile) require.NoError(t, err) @@ -184,7 +184,7 @@ func TestMigrateV2toV3ConfigAlreadyMigrated(t *testing.T) { newKeyShardFileBz, err := os.ReadFile(newKeyShardFile) require.NoError(t, err) - require.Equal(t, testdata.CosignerEd25519KeyMigrated, string(newKeyShardFileBz)) + require.Equal(t, testdata.CosignerKeyMigrated, string(newKeyShardFileBz)) newRSAKeyFileBz, err := os.ReadFile(newRSAKeyFile) require.NoError(t, err) @@ -208,7 +208,7 @@ func TestMigrateV2toV3AlreadyMigrated(t *testing.T) { ed25519KeyShardFile := filepath.Join(tmp, "test_shard.json") - err = os.WriteFile(ed25519KeyShardFile, []byte(testdata.CosignerEd25519KeyMigrated), 0600) + err = os.WriteFile(ed25519KeyShardFile, []byte(testdata.CosignerKeyMigrated), 0600) require.NoError(t, err) rsaKeyShardFile := filepath.Join(tmp, "rsa_keys.json") diff --git a/cmd/horcrux/cmd/root.go b/cmd/horcrux/cmd/root.go index dd8e4ebc..79eb1158 100644 --- a/cmd/horcrux/cmd/root.go +++ b/cmd/horcrux/cmd/root.go @@ -23,7 +23,7 @@ func rootCmd() *cobra.Command { cmd.AddCommand(configCmd()) cmd.AddCommand(startCmd()) cmd.AddCommand(addressCmd()) - cmd.AddCommand(createCosignerEd25519ShardsCmd()) + cmd.AddCommand(createCosignerShardsCmd()) cmd.AddCommand(createCosignerECIESShardsCmd()) rsaCmd := createCosignerRSAShardsCmd() diff --git a/cmd/horcrux/cmd/shards.go b/cmd/horcrux/cmd/shards.go index 5af886d8..3360d480 100644 --- a/cmd/horcrux/cmd/shards.go +++ b/cmd/horcrux/cmd/shards.go @@ -61,11 +61,12 @@ func addTotalShardsFlag(cmd *cobra.Command) { // createCosignerEd25519ShardsCmd is a cobra command for creating // cosigner shards from a full priv validator key. -func createCosignerEd25519ShardsCmd() *cobra.Command { +func createCosignerShardsCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "create-ed25519-shards", - Args: cobra.NoArgs, - Short: "Create cosigner Ed25519 shards", + Use: "create-shards", + Aliases: []string{"create-ed25519-shards", "create-bn254-shards"}, + Args: cobra.NoArgs, + Short: "Create cosigner consensus key shards", RunE: func(cmd *cobra.Command, args []string) (err error) { flags := cmd.Flags() @@ -112,7 +113,7 @@ func createCosignerEd25519ShardsCmd() *cobra.Command { return nil } - csKeys, err := signer.CreateCosignerEd25519ShardsFromFile(keyFile, threshold, shards) + csKeys, err := signer.CreateCosignerShardsFromFile(keyFile, threshold, shards) if err != nil { return err } @@ -133,10 +134,10 @@ func createCosignerEd25519ShardsCmd() *cobra.Command { return err } filename := filepath.Join(dir, fmt.Sprintf("%s_shard.json", chainID)) - if err = signer.WriteCosignerEd25519ShardFile(c, filename); err != nil { + if err = signer.WriteCosignerShardFile(c, filename); err != nil { return err } - fmt.Fprintf(cmd.OutOrStdout(), "Created Ed25519 Shard %s\n", filename) + fmt.Fprintf(cmd.OutOrStdout(), "Created %s Shard %s\n", c.KeyType, filename) } return nil }, diff --git a/cmd/horcrux/cmd/testdata/testdata.go b/cmd/horcrux/cmd/testdata/testdata.go index 2b7a0449..11c4380a 100644 --- a/cmd/horcrux/cmd/testdata/testdata.go +++ b/cmd/horcrux/cmd/testdata/testdata.go @@ -11,7 +11,7 @@ var ConfigMigrated string var ConfigV2 []byte //go:embed cosigner-key-migrated-ed25519.json -var CosignerEd25519KeyMigrated string +var CosignerKeyMigrated string //go:embed cosigner-key-migrated-rsa.json var CosignerRSAKeyMigrated string diff --git a/go.mod b/go.mod index e2339162..4f2368ab 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/Jille/raftadmin v1.2.1 github.com/armon/go-metrics v0.4.1 github.com/cometbft/cometbft v0.38.0 + github.com/consensys/gnark-crypto v0.12.1 github.com/cosmos/cosmos-sdk v0.50.1 github.com/cosmos/gogoproto v1.4.11 github.com/ethereum/go-ethereum v1.13.5 @@ -25,79 +26,46 @@ require ( github.com/tendermint/go-amino v0.16.0 gitlab.com/unit410/edwards25519 v0.0.0-20220725154547-61980033348e gitlab.com/unit410/threshold-ed25519 v0.0.0-20220812172601-56783212c4cc + go.dedis.ch/kyber/v3 v3.1.0 golang.org/x/sync v0.3.0 google.golang.org/grpc v1.59.0 gopkg.in/yaml.v2 v2.4.0 ) require ( - cosmossdk.io/api v0.7.2 // indirect - cosmossdk.io/collections v0.4.0 // indirect - cosmossdk.io/core v0.11.0 // indirect - cosmossdk.io/depinject v1.0.0-alpha.4 // indirect - cosmossdk.io/errors v1.0.0 // indirect - cosmossdk.io/log v1.2.1 // indirect - cosmossdk.io/math v1.2.0 // indirect - cosmossdk.io/store v1.0.0 // indirect - cosmossdk.io/x/tx v0.12.0 // indirect - filippo.io/edwards25519 v1.0.0 // indirect - github.com/DataDog/zstd v1.5.5 // indirect github.com/beorn7/perks v1.0.1 // indirect + github.com/bits-and-blooms/bitset v1.8.0 // indirect github.com/boltdb/bolt v1.3.1 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect - github.com/cespare/xxhash v1.1.0 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect - github.com/cockroachdb/errors v1.11.1 // indirect - github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect - github.com/cockroachdb/pebble v0.0.0-20231116191551-bfb2e6a97fdd // indirect - github.com/cockroachdb/redact v1.1.5 // indirect - github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect - github.com/cometbft/cometbft-db v0.7.0 // indirect + github.com/consensys/bavard v0.1.13 // indirect github.com/cosmos/btcutil v1.0.5 // indirect - github.com/cosmos/cosmos-db v1.0.0 // indirect - github.com/cosmos/cosmos-proto v1.0.0-beta.3 // indirect - github.com/cosmos/ics23/go v0.10.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect - github.com/dgraph-io/badger/v2 v2.2007.4 // indirect - github.com/dgraph-io/ristretto v0.1.1 // indirect - github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect - github.com/dustin/go-humanize v1.0.1 // indirect github.com/fatih/color v1.15.0 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect - github.com/getsentry/sentry-go v0.25.0 // indirect - github.com/go-kit/kit v0.12.0 // indirect github.com/go-kit/log v0.2.1 // indirect github.com/go-logfmt/logfmt v0.6.0 // indirect - github.com/golang/glog v1.1.2 // indirect github.com/golang/protobuf v1.5.3 // indirect - github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect - github.com/google/btree v1.1.2 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-hclog v1.5.0 // indirect github.com/hashicorp/go-immutable-radix v1.3.1 // indirect - github.com/hashicorp/go-metrics v0.5.2 // indirect github.com/hashicorp/go-msgpack v1.1.5 // indirect github.com/hashicorp/go-msgpack/v2 v2.1.1 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect + github.com/hashicorp/go-uuid v1.0.1 // indirect github.com/hashicorp/golang-lru v1.0.2 // indirect github.com/hashicorp/hcl v1.0.0 // indirect - github.com/hdevalence/ed25519consensus v0.1.0 // indirect github.com/holiman/uint256 v1.2.3 // indirect - github.com/iancoleman/strcase v0.3.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/jmhodges/levigo v1.0.0 // indirect - github.com/klauspost/compress v1.17.3 // indirect - github.com/kr/pretty v0.3.1 // indirect - github.com/kr/text v0.2.0 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect - github.com/linxGnu/grocksdb v1.8.5 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/mmcloughlin/addchain v0.4.0 // indirect github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect github.com/pelletier/go-toml/v2 v2.0.9 // indirect github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc // indirect @@ -106,27 +74,22 @@ require ( github.com/prometheus/client_model v0.5.0 // indirect github.com/prometheus/common v0.45.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect - github.com/rogpeppe/go-internal v1.11.0 // indirect - github.com/rs/zerolog v1.31.0 // indirect github.com/sasha-s/go-deadlock v0.3.1 // indirect github.com/spf13/afero v1.9.5 // indirect github.com/spf13/cast v1.5.1 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.4.2 // indirect - github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect - github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect + go.dedis.ch/fixbuf v1.0.3 // indirect go.etcd.io/bbolt v1.3.8 // indirect golang.org/x/crypto v0.14.0 // indirect golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect golang.org/x/net v0.17.0 // indirect golang.org/x/sys v0.14.0 // indirect golang.org/x/text v0.13.0 // indirect - google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - sigs.k8s.io/yaml v1.3.0 // indirect + rsc.io/tmplfunc v0.0.3 // indirect ) diff --git a/go.sum b/go.sum index dce87931..a5a4c27a 100644 --- a/go.sum +++ b/go.sum @@ -35,53 +35,23 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= -cosmossdk.io/api v0.7.2 h1:BO3i5fvKMKvfaUiMkCznxViuBEfyWA/k6w2eAF6q1C4= -cosmossdk.io/api v0.7.2/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38= -cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= -cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= -cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo= -cosmossdk.io/core v0.11.0/go.mod h1:LaTtayWBSoacF5xNzoF8tmLhehqlA9z1SWiPuNC6X1w= -cosmossdk.io/depinject v1.0.0-alpha.4 h1:PLNp8ZYAMPTUKyG9IK2hsbciDWqna2z1Wsl98okJopc= -cosmossdk.io/depinject v1.0.0-alpha.4/go.mod h1:HeDk7IkR5ckZ3lMGs/o91AVUc7E596vMaOmslGFM3yU= -cosmossdk.io/errors v1.0.0 h1:nxF07lmlBbB8NKQhtJ+sJm6ef5uV1XkvPXG2bUntb04= -cosmossdk.io/errors v1.0.0/go.mod h1:+hJZLuhdDE0pYN8HkOrVNwrIOYvUGnn6+4fjnJs/oV0= -cosmossdk.io/log v1.2.1 h1:Xc1GgTCicniwmMiKwDxUjO4eLhPxoVdI9vtMW8Ti/uk= -cosmossdk.io/log v1.2.1/go.mod h1:GNSCc/6+DhFIj1aLn/j7Id7PaO8DzNylUZoOYBL9+I4= -cosmossdk.io/math v1.2.0 h1:8gudhTkkD3NxOP2YyyJIYYmt6dQ55ZfJkDOaxXpy7Ig= -cosmossdk.io/math v1.2.0/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0= -cosmossdk.io/store v1.0.0 h1:6tnPgTpTSIskaTmw/4s5C9FARdgFflycIc9OX8i1tOI= -cosmossdk.io/store v1.0.0/go.mod h1:ABMprwjvx6IpMp8l06TwuMrj6694/QP5NIW+X6jaTYc= -cosmossdk.io/x/tx v0.12.0 h1:Ry2btjQdrfrje9qZ3iZeZSmDArjgxUJMMcLMrX4wj5U= -cosmossdk.io/x/tx v0.12.0/go.mod h1:qTth2coAGkwCwOCjqQ8EAQg+9udXNRzcnSbMgGKGEI0= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= -filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= -github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= -github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4= -github.com/99designs/keyring v1.2.1 h1:tYLp1ULvO7i3fI5vE21ReQuj99QFSs7lGm0xWyJo87o= -github.com/99designs/keyring v1.2.1/go.mod h1:fc+wB5KTk9wQ9sDx0kFXB3A0MaeGHM9AwRStKOQ5vOA= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DataDog/datadog-go v2.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= -github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ= -github.com/DataDog/zstd v1.5.5/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= github.com/Jille/raft-grpc-leader-rpc v1.1.0 h1:u36rmA4tjp+4FSdZ17jg/1sfSCYNQIe5bzzwvW0iVTM= github.com/Jille/raft-grpc-leader-rpc v1.1.0/go.mod h1:l+pK+uPuqpFDFcPmyUPSng4257UXrST0Vc3Lo4XwVB0= github.com/Jille/raft-grpc-transport v1.4.0 h1:Kwk+IceQD8MpLKOulBu2ignX+aZAEjOhffEhN44sdzQ= github.com/Jille/raft-grpc-transport v1.4.0/go.mod h1:afVUd8LQKUUo3V/ToLBH3mbSyvivRlMYCDK0eJRGTfQ= github.com/Jille/raftadmin v1.2.1 h1:P35JYYJmyHnsJ7sEjdXVRRvaqXUQUuNjIqPFf5n3CEM= github.com/Jille/raftadmin v1.2.1/go.mod h1:CocBqmOFhfk8oIgbzZKYACdm5PizUXfzupqTQV17Pgk= -github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= -github.com/VividCortex/gohistogram v1.0.0 h1:6+hBz+qvs0JOrrNhhmR7lFxo5sINxBCGXrdtl/UvroE= -github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= -github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878/go.mod h1:3AMJUQhVx52RsWOnlkpikZr01T/yAVN2gn0861vByNg= github.com/armon/go-metrics v0.3.9/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc= github.com/armon/go-metrics v0.4.1 h1:hR91U9KYmb6bLBYLQjyM+3j+rcd/UhE+G78SFnF8gJA= @@ -91,8 +61,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 h1:41iFGWnSlI2gVpmOtVTJZNodLdLQLn/KsJqFvXwnd/s= -github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/bits-and-blooms/bitset v1.8.0 h1:FD+XqgOZDUxxZ8hzoBFuV9+cGWY9CslN6d5MS5JVb4c= +github.com/bits-and-blooms/bitset v1.8.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4= github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U= @@ -101,11 +71,7 @@ github.com/btcsuite/btcd/btcutil v1.1.3 h1:xfbtw8lwpp0G6NwSHb+UE67ryTFHJAiNuipus github.com/btcsuite/btcd/btcutil v1.1.3/go.mod h1:UR7dsSJzJUfMmFiiLlIrMq1lS9jh9EdCV7FStZSnpi0= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= -github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= -github.com/cenkalti/backoff/v4 v4.1.3 h1:cFAlzYUlVYDysBEH2T5hyJZMh3+5+WCBvSnK6Q8UtC4= -github.com/cenkalti/backoff/v4 v4.1.3/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= @@ -120,51 +86,19 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= -github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaYPt5hWxV3MUfO5dFPFiOXg9CyG5/kCfayTqsJ4= -github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU= -github.com/cockroachdb/errors v1.11.1 h1:xSEW75zKaKCWzR3OfxXUxgrk/NtT4G1MiOv5lWZazG8= -github.com/cockroachdb/errors v1.11.1/go.mod h1:8MUxA3Gi6b25tYlFEBGLf+D8aISL+M4MIpiWMSNRfxw= -github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= -github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= -github.com/cockroachdb/pebble v0.0.0-20231116191551-bfb2e6a97fdd h1:qJuMKww8C5kQx0A0zgQUaswdcWlzgzTGAA5YdFAin3Y= -github.com/cockroachdb/pebble v0.0.0-20231116191551-bfb2e6a97fdd/go.mod h1:acMRUGd/BK8AUmQNK3spUCCGzFLZU2bSST3NMXSq2Kc= -github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30= -github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= -github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= -github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ= github.com/cometbft/cometbft v0.38.0 h1:ogKnpiPX7gxCvqTEF4ly25/wAxUqf181t30P3vqdpdc= github.com/cometbft/cometbft v0.38.0/go.mod h1:5Jz0Z8YsHSf0ZaAqGvi/ifioSdVFPtEGrm8Y9T/993k= -github.com/cometbft/cometbft-db v0.7.0 h1:uBjbrBx4QzU0zOEnU8KxoDl18dMNgDh+zZRUE0ucsbo= -github.com/cometbft/cometbft-db v0.7.0/go.mod h1:yiKJIm2WKrt6x8Cyxtq9YTEcIMPcEe4XPxhgX59Fzf0= -github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= -github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= -github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= -github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ= +github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI= +github.com/consensys/gnark-crypto v0.12.1 h1:lHH39WuuFgVHONRl3J0LRBtuYdQTumFSDtJF7HpyG8M= +github.com/consensys/gnark-crypto v0.12.1/go.mod h1:v2Gy7L/4ZRosZ7Ivs+9SfUDr0f5UlG+EM5t7MPHiLuY= github.com/cosmos/btcutil v1.0.5 h1:t+ZFcX77LpKtDBhjucvnOH8C2l2ioGsBNEQ3jef8xFk= github.com/cosmos/btcutil v1.0.5/go.mod h1:IyB7iuqZMJlthe2tkIFL33xPyzbFYP0XVdS8P5lUPis= -github.com/cosmos/cosmos-db v1.0.0 h1:EVcQZ+qYag7W6uorBKFPvX6gRjw6Uq2hIh4hCWjuQ0E= -github.com/cosmos/cosmos-db v1.0.0/go.mod h1:iBvi1TtqaedwLdcrZVYRSSCb6eSy61NLj4UNmdIgs0U= -github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o= -github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I= github.com/cosmos/cosmos-sdk v0.50.1 h1:2SYwAYqd7ZwtrWxu/J8PwbQV/cDcu90bCr/a78g3lVw= github.com/cosmos/cosmos-sdk v0.50.1/go.mod h1:fsLSPGstCwn6MMsFDMAQWGJj8E4sYsN9Gnu1bGE5imA= -github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= -github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= -github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE= -github.com/cosmos/gogogateway v1.2.0/go.mod h1:iQpLkGWxYcnCdz5iAdLcRBSw3h7NXeOkZ4GUkT+tbFI= github.com/cosmos/gogoproto v1.4.11 h1:LZcMHrx4FjUgrqQSWeaGC1v/TeuVFqSLa43CC6aWR2g= github.com/cosmos/gogoproto v1.4.11/go.mod h1:/g39Mh8m17X8Q/GDEs5zYTSNaNnInBSohtaxzQnYq1Y= -github.com/cosmos/iavl v1.0.0 h1:bw6t0Mv/mVCJvlMTOPHWLs5uUE3BRBfVWCRelOzl+so= -github.com/cosmos/iavl v1.0.0/go.mod h1:CmTGqMnRnucjxbjduneZXT+0vPgNElYvdefjX2q9tYc= -github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= -github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0= -github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5nvue4rK+yM= -github.com/cosmos/ledger-cosmos-go v0.13.3/go.mod h1:HENcEP+VtahZFw38HZ3+LS3Iv5XV6svsnkk9vdJtLr8= -github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/danieljoos/wincred v1.1.2 h1:QLdCxFs1/Yl4zduvBdcHB8goaYk9RARS2SgLLRuAyr0= -github.com/danieljoos/wincred v1.1.2/go.mod h1:GijpziifJoIBfYh+S7BbkdUTU4LfM+QnGqR5Vl2tAx0= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -172,23 +106,6 @@ github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5il github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= -github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f h1:U5y3Y5UE0w7amNe7Z5G/twsBW0KEalRQXZzf8ufSh9I= -github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f/go.mod h1:xH/i4TFMt8koVQZ6WFms69WAsDWr2XsYL3Hkl7jkoLE= -github.com/dgraph-io/badger/v2 v2.2007.4 h1:TRWBQg8UrlUhaFdco01nO2uXwzKS7zd+HVdwV/GHc4o= -github.com/dgraph-io/badger/v2 v2.2007.4/go.mod h1:vSw/ax2qojzbN6eXHIx6KPKtCSHJN/Uz0X0VPruTIhk= -github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E= -github.com/dgraph-io/ristretto v0.1.1 h1:6CWw5tJNgpegArSHpNHJKldNeq03FQCwYvfMVWajOK8= -github.com/dgraph-io/ristretto v0.1.1/go.mod h1:S1GPSBCYCIhmVNfcth17y2zZtQT6wzkzgwUve0VDWWA= -github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= -github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 h1:fAjc9m62+UWV/WAFKLNi6ZS0675eEUC9y3AlwSbQu1Y= -github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= -github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= -github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= -github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= -github.com/dvsekhvalnov/jose2go v1.5.0 h1:3j8ya4Z4kMCwT5nXIKFSV84YS+HdqSSO0VsTQxaLAeM= -github.com/dvsekhvalnov/jose2go v1.5.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU= -github.com/emicklei/dot v1.6.0 h1:vUzuoVE8ipzS7QkES4UfxdpCwdU2U97m2Pb2tQCoYRY= -github.com/emicklei/dot v1.6.0/go.mod h1:DeV7GvQtIw4h2u73RKBkkFdvVAz0D9fzeJrgPW6gy/s= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -198,40 +115,23 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.m github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/ethereum/go-ethereum v1.13.5 h1:U6TCRciCqZRe4FPXmy1sMGxTfuk8P7u2UoinF3VbaFk= github.com/ethereum/go-ethereum v1.13.5/go.mod h1:yMTu38GSuyxaYzQMViqNmQ1s3cE84abZexQmTgenWk0= -github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0= -github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= -github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojtoVVWjGfOF9635RETekkoH6Cc9SX0A= -github.com/facebookgo/stack v0.0.0-20160209184415-751773369052/go.mod h1:UbMTZqLaRiH3MsBH8va0n7s1pQYcu3uTb8G4tygF4Zg= -github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 h1:7HZCaLC5+BZpmbhCOZJ293Lz68O7PYrF2EzeiFMwCLk= -github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4/go.mod h1:5tD+neXqOorC30/tWg0LCSkrqj/AR6gu8yY8/fpw1q0= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= -github.com/felixge/httpsnoop v1.0.2 h1:+nS9g82KMXccJ/wp0zyRW9ZBHFETmMGtkk+2CTTrW4o= -github.com/felixge/httpsnoop v1.0.2/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= -github.com/getsentry/sentry-go v0.25.0 h1:q6Eo+hS+yoJlTO3uu/azhQadsD8V+jQn2D8VvX1eOyI= -github.com/getsentry/sentry-go v0.25.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= -github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-kit/kit v0.12.0 h1:e4o3o3IsBfAKQh5Qbbiqyfu97Ku7jrO/JbohvztANh4= -github.com/go-kit/kit v0.12.0/go.mod h1:lHd+EkCZPIwYItmGDDRdhinkzX2A1sj+M9biaEaizzs= github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU= github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0= @@ -241,18 +141,10 @@ github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4= github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= -github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 h1:ZpnhV/YsD2/4cESfV5+Hoeu/iUR3ruzNvZ+yQfO03a0= -github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4= -github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/gogo/googleapis v1.4.1 h1:1Yx4Myt7BxzvUr5ldGSbwYiZG6t9wGBZ+8/fX3Wvtq0= -github.com/gogo/googleapis v1.4.1/go.mod h1:2lpHqI5OcWCtVElxXnPt+s8oJvMpySlOyM6xDCrzib4= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/glog v1.1.2 h1:DVjP2PbBOzHyzA+dn3WhHIq4NdVu3Q+pvivFICf/7fo= -github.com/golang/glog v1.1.2/go.mod h1:zR+okUeTbrL6EL3xHUDxZuEtGv04p5shwip1+mL/rLQ= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -263,8 +155,6 @@ github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= -github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= -github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -284,14 +174,8 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= 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/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/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU= -github.com/google/btree v1.1.2/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -311,8 +195,6 @@ github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/ github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= -github.com/google/orderedcode v0.0.1 h1:UzfcAexk9Vhv8+9pNOgRu41f16lHq725vPwnSeiG/Us= -github.com/google/orderedcode v0.0.1/go.mod h1:iVyU4/qPKHY5h/wSd6rZZCDcLJNxiWO6dvsYES2Sb20= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= @@ -323,26 +205,17 @@ github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hf github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= -github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4= -github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q= -github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= -github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= -github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= -github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI= github.com/grpc-ecosystem/go-grpc-middleware v1.4.0/go.mod h1:g5qyo/la0ALbONm6Vbp88Yd8NsDy6rZz+RcrMPxvld8= -github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= -github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU= -github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -354,8 +227,6 @@ github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVH github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJFeZnpfm2KLowc= github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= -github.com/hashicorp/go-metrics v0.5.2 h1:ErEYO2f//CjKsUDw4SmLzelsK6L3ZmOAR/4P9iS7ruY= -github.com/hashicorp/go-metrics v0.5.2/go.mod h1:KEjodfebIOuBYSAe/bHTm+HChmKSxAOXPBieMLYozDE= github.com/hashicorp/go-msgpack v0.5.5/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-msgpack v1.1.5 h1:9byZdVjKTe5mce63pRVNP1L7UAmdHOTEMGehn6KvJWs= github.com/hashicorp/go-msgpack v1.1.5/go.mod h1:gWVc3sv/wbDmR3rQsj1CAktEZzoz1YNK9NfGLXJ69/4= @@ -363,8 +234,6 @@ github.com/hashicorp/go-msgpack/v2 v2.1.1 h1:xQEY9yB2wnHitoSzk/B9UjXWRQ67QKu5AOm github.com/hashicorp/go-msgpack/v2 v2.1.1/go.mod h1:upybraOAblm4S7rx0+jeNy+CWWhzywQsSRV5033mMu4= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= -github.com/hashicorp/go-plugin v1.5.2 h1:aWv8eimFqWlsEiMrYZdPYl+FdHaBJSN4AWwGWfT1G2Y= -github.com/hashicorp/go-plugin v1.5.2/go.mod h1:w1sAEES3g3PuV/RzUrgow20W2uErMly84hhD3um1WL4= github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE= @@ -386,26 +255,12 @@ github.com/hashicorp/raft-boltdb v0.0.0-20210409134258-03c10cc3d4ea h1:RxcPJuutP github.com/hashicorp/raft-boltdb v0.0.0-20210409134258-03c10cc3d4ea/go.mod h1:qRd6nFJYYS6Iqnc/8HcUmko2/2Gw8qTFEmxDLii6W5I= github.com/hashicorp/raft-boltdb/v2 v2.2.2 h1:rlkPtOllgIcKLxVT4nutqlTH2NRFn+tO1wwZk/4Dxqw= github.com/hashicorp/raft-boltdb/v2 v2.2.2/go.mod h1:N8YgaZgNJLpZC+h+by7vDu5rzsRgONThTEeUS3zWbfY= -github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE= -github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ= -github.com/hdevalence/ed25519consensus v0.1.0 h1:jtBwzzcHuTmFrQN6xQZn6CQEO/V9f7HsjsjeEZ6auqU= -github.com/hdevalence/ed25519consensus v0.1.0/go.mod h1:w3BHWjwJbFU29IRHL1Iqkw3sus+7FctEyM4RqDxYNzo= 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/huandu/skiplist v1.2.0 h1:gox56QD77HzSC0w+Ws3MH3iie755GBJU1OER3h5VsYw= -github.com/huandu/skiplist v1.2.0/go.mod h1:7v3iFjLcSAzO4fN5B8dvebvo/qsfumiLiDXMrPiHF9w= -github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI= -github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= -github.com/improbable-eng/grpc-web v0.15.0 h1:BN+7z6uNXZ1tQGcNAuaU1YjsLTApzkjt2tzCixLaUPQ= -github.com/improbable-eng/grpc-web v0.15.0/go.mod h1:1sy9HKV4Jt9aEs9JSnkWlRJPuPtwNr0l57L4f878wP8= -github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U= -github.com/jmhodges/levigo v1.0.0/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= @@ -413,9 +268,6 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.12.3/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= -github.com/klauspost/compress v1.17.3 h1:qkRjuerhUU1EmXLYGkSH6EZL+vPSxIrYjLNAK4slzwA= -github.com/klauspost/compress v1.17.3/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= @@ -428,13 +280,10 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kraken-hpc/go-fork v0.1.1 h1:O3X/ynoNy/eS7UIcZYef8ndFq2RXEIOue9kZqyzF0Sk= github.com/kraken-hpc/go-fork v0.1.1/go.mod h1:uu0e5h+V4ONH5Qk/xuVlyNXJXy/swhqGIEMK7w+9dNc= -github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= -github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= +github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8= github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg= -github.com/linxGnu/grocksdb v1.8.5 h1:Okfk5B1h0ikCYdDM7Tc5yJUS8LTwAmMBq5IPWTmOLPs= -github.com/linxGnu/grocksdb v1.8.5/go.mod h1:xZCIb5Muw+nhbDK4Y5UJuOrin5MceOuiXkVUR7vp4WY= -github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= @@ -448,59 +297,33 @@ github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcME github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg= github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k= -github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g= -github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU= -github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8= -github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= +github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU= +github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/mtibben/percent v0.2.1 h1:5gssi8Nqo8QU/r2pynCm+hBQHpkB/uNK7BJCFogWdzs= -github.com/mtibben/percent v0.2.1/go.mod h1:KG9uO+SZkUp+VkRHsCdYQV3XSZrrSpR3O9ibNBTZrns= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= -github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= -github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a h1:dlRvE5fWabOchtH7znfiFCcOvmIYgOeAS5ifBXBlh9Q= github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a/go.mod h1:hVoHR2EVESiICEMbg137etN/Lx+lSrHPTD39Z/uE+2s= -github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA= -github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU= -github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= -github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= -github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= -github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= -github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= -github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= -github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro= -github.com/onsi/gomega v1.20.0 h1:8W0cWlwFkflGPLltQvLRB7ZVD5HuP6ng320w2IS245Q= -github.com/onsi/gomega v1.20.0/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= -github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml/v2 v2.0.9 h1:uH2qQXheeefCCkuBBSLi7jCiSmj3VRh2+Goq2N7Xxu0= github.com/pelletier/go-toml/v2 v2.0.9/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o= github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc h1:8bQZVK1X6BJR/6nYUPxQEP+ReTsceJTKizeuwjWOPUA= github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= -github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= -github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -531,43 +354,26 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= -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/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= -github.com/rs/cors v1.8.3 h1:O+qNyWn7Z+F9M0ILBHgMVPuB1xTOucVd5gtaYyXBpRo= -github.com/rs/cors v1.8.3/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= -github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= -github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A= -github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= -github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sasha-s/go-deadlock v0.3.1 h1:sqv7fDNShgjcaxkO0JNcOAlr8B9+cV5Ey/OB71efZx0= github.com/sasha-s/go-deadlock v0.3.1/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZjwesgfQ1/iLM= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= -github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= -github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= -github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM= github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= -github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA= github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48= -github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= -github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= -github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= github.com/spf13/viper v1.16.0 h1:rGGH0XDZhdUOryiDWjmIvUSWpbNqisK8Wk0Vyefw8hc= github.com/spf13/viper v1.16.0/go.mod h1:yg78JgCJcbrQOvV9YLXgkLaZqUidkY9K+Dd1FofRzQg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -586,30 +392,28 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= -github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d h1:vfofYNRScrDdvS342BElfbETmL1Aiz3i2t0zfRj16Hs= -github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d/go.mod h1:RRCYJbIwD5jmqPI9XoAFR0OcDxqUctll6zUj/+B4S48= -github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c h1:g+WoO5jjkqGAzHWCjJB1zZfXPIAaDpzXIEJ0eS6B5Ok= -github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c/go.mod h1:ahpPrc7HpcfEWDQRZEmnXMzHY03mLDYMCxeDzy46i+8= github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E= github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= -github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI= -github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= -github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= -github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -github.com/zondax/hid v0.9.2 h1:WCJFnEDMiqGF64nlZz28E9qLVZ0KSJ7xpc5DLEyma2U= -github.com/zondax/hid v0.9.2/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM= -github.com/zondax/ledger-go v0.14.3 h1:wEpJt2CEcBJ428md/5MgSLsXLBos98sBOyxNmCjfUCw= -github.com/zondax/ledger-go v0.14.3/go.mod h1:IKKaoxupuB43g4NxeQmbLXv7T9AlQyie1UpHb342ycI= gitlab.com/unit410/edwards25519 v0.0.0-20220725154547-61980033348e h1:/QfokHt2yG9PcjnFSdpIQhJwrz2Q1bmKA718vw4/He8= gitlab.com/unit410/edwards25519 v0.0.0-20220725154547-61980033348e/go.mod h1:lTSPILLBMt6qQOJgsiarbW85JhpkhoOfW2EBkxkcuSI= gitlab.com/unit410/threshold-ed25519 v0.0.0-20220812172601-56783212c4cc h1:ESmaQH1+uOLW0wOIPT4EVLh+gwKdmKovr+eZg4jWUNs= gitlab.com/unit410/threshold-ed25519 v0.0.0-20220812172601-56783212c4cc/go.mod h1:1CIpwbV+rSyzoBVr6Ok9vvEP7UHrW/d0zEB+jU6+E3o= +go.dedis.ch/fixbuf v1.0.3 h1:hGcV9Cd/znUxlusJ64eAlExS+5cJDIyTyEG+otu5wQs= +go.dedis.ch/fixbuf v1.0.3/go.mod h1:yzJMt34Wa5xD37V5RTdmp38cz3QhMagdGoem9anUalw= +go.dedis.ch/kyber/v3 v3.0.4/go.mod h1:OzvaEnPvKlyrWyp3kGXlFdp7ap1VC6RkZDTaPikqhsQ= +go.dedis.ch/kyber/v3 v3.0.9/go.mod h1:rhNjUUg6ahf8HEg5HUvVBYoWY4boAafX8tYxX+PS+qg= +go.dedis.ch/kyber/v3 v3.1.0 h1:ghu+kiRgM5JyD9TJ0hTIxTLQlJBR/ehjWvWwYW3XsC0= +go.dedis.ch/kyber/v3 v3.1.0/go.mod h1:kXy7p3STAurkADD+/aZcsznZGKVHEqbtmdIzvPfrs1U= +go.dedis.ch/protobuf v1.0.5/go.mod h1:eIV4wicvi6JK0q/QnfIEGeSFNG0ZeB24kzut5+HaRLo= +go.dedis.ch/protobuf v1.0.7/go.mod h1:pv5ysfkDX/EawiPqcW3ikOxsL5t+BqnV6xHSmE79KI4= +go.dedis.ch/protobuf v1.0.11 h1:FTYVIEzY/bfl37lu3pR4lIj+F9Vp1jE8oh91VmxKgLo= +go.dedis.ch/protobuf v1.0.11/go.mod h1:97QR256dnkimeNdfmURz0wAMNVbd1VmLXhG1CrTYrJ4= go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= go.etcd.io/bbolt v1.3.8 h1:xs88BrvEv273UsB79e0hcVrlUWmS0a8upikMFhSyAtA= go.etcd.io/bbolt v1.3.8/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw= @@ -627,7 +431,7 @@ go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -700,7 +504,6 @@ golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/ golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= @@ -711,11 +514,8 @@ golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20210907225631-ff17edfbf26d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -742,9 +542,8 @@ golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190124100055-b90733256f2e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -755,13 +554,9 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190523142557-0e01d883c5c5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -783,7 +578,6 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -795,21 +589,13 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210906170528-6f6e22806c34/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= -golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -871,7 +657,6 @@ golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82u golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= @@ -881,7 +666,6 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= @@ -948,10 +732,6 @@ google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20210108203827-ffc7fda8c3d7/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210226172003-ab064af71705/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210903162649-d08c68adba83/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= -google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 h1:wpZ8pe2x1Q3f2KyT5f8oP/fa9rHAKgFPr/HZdNuS+PQ= -google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:J7XzRzVy1+IPwWHZUzoD0IccYZIrXILAQpc+Qy9CMhY= -google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 h1:JpwMPBpFN3uKhdaekDpiNlImDdkUAyiJ6ez/uxGaUSo= -google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:0xJLfVdJqpAPl8tDg1ujOCGzx6LFLttXT5NhllGOXY4= google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 h1:Jyp0Hsi0bmHXG6k9eATXoYtjd6e2UzZ1SCn/wIupY14= google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:oQ5rr10WTTMvP4A36n8JpR1OrO1BEiV4f78CneXZxkA= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= @@ -997,27 +777,20 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 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/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= @@ -1025,12 +798,8 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -nhooyr.io/websocket v1.8.6 h1:s+C3xAMLwGmlI31Nyn/eAehUlZPwfYZu2JXM621Q5/k= -nhooyr.io/websocket v1.8.6/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0= -pgregory.net/rapid v1.1.0 h1:CMa0sjHSru3puNx+J0MIAuiiEV4N0qj8/cMWGBBCsjw= -pgregory.net/rapid v1.1.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= -sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= -sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= +rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU= +rsc.io/tmplfunc v0.0.3/go.mod h1:AG3sTPzElb1Io3Yg4voV9AGZJuleGAwaVRxL9M49PhA= diff --git a/signer/config.go b/signer/config.go index 4765cc04..ab16027c 100644 --- a/signer/config.go +++ b/signer/config.go @@ -1,6 +1,7 @@ package signer import ( + "encoding/base64" "fmt" "net" "net/url" @@ -8,13 +9,6 @@ import ( "path/filepath" "time" - "github.com/cometbft/cometbft/crypto" - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/legacy" - "github.com/cosmos/cosmos-sdk/codec/types" - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" - "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/types/bech32" "github.com/strangelove-ventures/horcrux/v3/client" "gopkg.in/yaml.v2" @@ -347,32 +341,15 @@ func ChainNodesFromFlag(nodes []string) (ChainNodes, error) { return out, nil } -func PubKey(bech32BasePrefix string, pubKey crypto.PubKey) (string, error) { +func PubKey(bech32BasePrefix string, pubKey []byte) (string, error) { if bech32BasePrefix != "" { - pubkey, err := cryptocodec.FromCmtPubKeyInterface(pubKey) - if err != nil { - return "", err - } consPubPrefix := bech32BasePrefix + "valconspub" - pubKeyBech32, err := bech32.ConvertAndEncode(consPubPrefix, legacy.Cdc.Amino.MustMarshalBinaryBare(pubkey)) + pubKeyBech32, err := bech32.ConvertAndEncode(consPubPrefix, pubKey) if err != nil { return "", err } return pubKeyBech32, nil } - registry := types.NewInterfaceRegistry() - marshaler := codec.NewProtoCodec(registry) - var pk *cryptotypes.PubKey - registry.RegisterInterface("cosmos.crypto.PubKey", pk) - registry.RegisterImplementations(pk, &ed25519.PubKey{}) - sdkPK, err := cryptocodec.FromCmtPubKeyInterface(pubKey) - if err != nil { - return "", err - } - pubKeyJSON, err := marshaler.MarshalInterfaceJSON(sdkPK) - if err != nil { - return "", err - } - return string(pubKeyJSON), nil + return base64.StdEncoding.EncodeToString(pubKey), nil } diff --git a/signer/cosigner_key.go b/signer/cosigner_key.go index 8aaa396d..19ff3b7e 100644 --- a/signer/cosigner_key.go +++ b/signer/cosigner_key.go @@ -3,90 +3,19 @@ package signer import ( "encoding/json" "os" - - cometcrypto "github.com/cometbft/cometbft/crypto" - cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519" - cometcryptoencoding "github.com/cometbft/cometbft/crypto/encoding" - cometprotocrypto "github.com/cometbft/cometbft/proto/tendermint/crypto" - amino "github.com/tendermint/go-amino" ) -// CosignerEd25519Key is a single Ed255219 key shard for an m-of-n threshold signer. -type CosignerEd25519Key struct { - PubKey cometcrypto.PubKey `json:"pubKey"` - PrivateShard []byte `json:"privateShard"` - ID int `json:"id"` -} - -func (key *CosignerEd25519Key) MarshalJSON() ([]byte, error) { - type Alias CosignerEd25519Key - - protoPubkey, err := cometcryptoencoding.PubKeyToProto(key.PubKey) - if err != nil { - return nil, err - } - - protoBytes, err := protoPubkey.Marshal() - if err != nil { - return nil, err - } - - return json.Marshal(&struct { - PubKey []byte `json:"pubKey"` - *Alias - }{ - PubKey: protoBytes, - Alias: (*Alias)(key), - }) -} - -func (key *CosignerEd25519Key) UnmarshalJSON(data []byte) error { - type Alias CosignerEd25519Key - - aux := &struct { - PubkeyBytes []byte `json:"pubKey"` - *Alias - }{ - Alias: (*Alias)(key), - } - if err := json.Unmarshal(data, &aux); err != nil { - return err - } - - var pubkey cometcrypto.PubKey - var protoPubkey cometprotocrypto.PublicKey - err := protoPubkey.Unmarshal(aux.PubkeyBytes) - - // Prior to the tendermint protobuf migration, the public key bytes in key files - // were encoded using the go-amino libraries via - // cdc.MarshalBinaryBare(key.PubKey) - // - // To support reading the public key bytes from these key files, we fallback to - // amino unmarshalling if the protobuf unmarshalling fails - if err != nil { - var pub cometcryptoed25519.PubKey - codec := amino.NewCodec() - codec.RegisterInterface((*cometcrypto.PubKey)(nil), nil) - codec.RegisterConcrete(cometcryptoed25519.PubKey{}, "tendermint/PubKeyEd25519", nil) - errInner := codec.UnmarshalBinaryBare(aux.PubkeyBytes, &pub) - if errInner != nil { - return err - } - pubkey = pub - } else { - pubkey, err = cometcryptoencoding.PubKeyFromProto(protoPubkey) - if err != nil { - return err - } - } - - key.PubKey = pubkey - return nil +// CosignerKey is a single key shard for an m-of-n threshold signer. +type CosignerKey struct { + KeyType string `json:"keyType"` + PubKey []byte `json:"pubKey"` + PrivateShard []byte `json:"privateShard"` + ID int `json:"id"` } -// LoadCosignerEd25519Key loads a CosignerEd25519Key from file. -func LoadCosignerEd25519Key(file string) (CosignerEd25519Key, error) { - pvKey := CosignerEd25519Key{} +// LoadCosignerKey loads a CosignerKey from file. +func LoadCosignerKey(file string) (CosignerKey, error) { + pvKey := CosignerKey{} keyJSONBytes, err := os.ReadFile(file) if err != nil { return pvKey, err diff --git a/signer/cosigner_key_shares.go b/signer/cosigner_key_shares.go index 0aee38a5..74d56f9f 100644 --- a/signer/cosigner_key_shares.go +++ b/signer/cosigner_key_shares.go @@ -4,32 +4,46 @@ import ( "crypto/rand" "crypto/rsa" "encoding/json" + "errors" + "fmt" "os" - cometjson "github.com/cometbft/cometbft/libs/json" - "github.com/cometbft/cometbft/privval" "github.com/ethereum/go-ethereum/crypto/ecies" "github.com/ethereum/go-ethereum/crypto/secp256k1" tsed25519 "gitlab.com/unit410/threshold-ed25519/pkg" + "go.dedis.ch/kyber/v3/pairing/bn256" + "go.dedis.ch/kyber/v3/share" "golang.org/x/sync/errgroup" ) -// CreateCosignerEd25519ShardsFromFile creates CosignerEd25519Key objects from a priv_validator_key.json file -func CreateCosignerEd25519ShardsFromFile(priv string, threshold, shards uint8) ([]CosignerEd25519Key, error) { +var ErrUnsupportedKeyType = errors.New("unsupported key type") + +// CreateCosignerEd25519ShardsFromFile creates CosignerKey objects from a priv_validator_key.json file +func CreateCosignerShardsFromFile(priv string, threshold, shards uint8) ([]CosignerKey, error) { pv, err := ReadPrivValidatorFile(priv) if err != nil { return nil, err } - return CreateCosignerEd25519Shards(pv, threshold, shards), nil + + switch pv.PrivKey.Type { + case "tendermint/PrivKeyEd25519": + return CreateCosignerEd25519Shards(pv, threshold, shards), nil + case "tendermint/PrivKeyBn254": + return CreateCosignerBn254Shards(pv, threshold, shards), nil + default: + return nil, ErrUnsupportedKeyType + } } -// CreateCosignerEd25519Shards creates CosignerEd25519Key objects from a privval.FilePVKey -func CreateCosignerEd25519Shards(pv privval.FilePVKey, threshold, shards uint8) []CosignerEd25519Key { - privShards := tsed25519.DealShares(tsed25519.ExpandSecret(pv.PrivKey.Bytes()[:32]), threshold, shards) - out := make([]CosignerEd25519Key, shards) +// CreateCosignerEd25519Shards creates CosignerKey objects from a privval.FilePVKey +func CreateCosignerEd25519Shards(pv *TMPrivvalFile, threshold, shards uint8) []CosignerKey { + fmt.Printf("ED25519 pv.PrivKey.Value: %v, len: %d\n", pv.PrivKey.Value, len(pv.PrivKey.Value)) + privShards := tsed25519.DealShares(tsed25519.ExpandSecret(pv.PrivKey.Value[:32]), threshold, shards) + out := make([]CosignerKey, shards) for i, shard := range privShards { - out[i] = CosignerEd25519Key{ - PubKey: pv.PubKey, + out[i] = CosignerKey{ + KeyType: CosignerKeyTypeEd25519, + PubKey: pv.PubKey.Value, PrivateShard: shard, ID: i + 1, } @@ -37,6 +51,30 @@ func CreateCosignerEd25519Shards(pv privval.FilePVKey, threshold, shards uint8) return out } +// CreateCosignerEd25519Shards creates CosignerKey objects from a privval.FilePVKey +func CreateCosignerBn254Shards(pv *TMPrivvalFile, threshold, shards uint8) []CosignerKey { + fmt.Printf("BN254 pv.PrivKey.Value: %v, len: %d\n", pv.PrivKey.Value, len(pv.PrivKey.Value)) + suite := bn256.NewSuite() + secret := suite.G1().Scalar().SetBytes(pv.PrivKey.Value) + priPoly := share.NewPriPoly(suite.G2(), int(threshold), secret, suite.RandomStream()) + privShards := priPoly.Shares(int(shards)) + + out := make([]CosignerKey, shards) + for i, shard := range privShards { + v, err := shard.V.MarshalBinary() + if err != nil { + panic(err) + } + out[i] = CosignerKey{ + KeyType: CosignerKeyTypeBn254, + PubKey: pv.PubKey.Value, + PrivateShard: v, + ID: i + 1, + } + } + return out +} + // CreateCosignerRSAShards generate CosignerRSAKey objects. func CreateCosignerRSAShards(shards int) ([]CosignerRSAKey, error) { rsaKeys, pubKeys, err := makeRSAKeys(shards) @@ -54,20 +92,36 @@ func CreateCosignerRSAShards(shards int) ([]CosignerRSAKey, error) { return out, nil } +type TMPrivvalFile struct { + Address string `json:"address"` + PubKey struct { + Type string `json:"type"` + Value []byte `json:"value"` + } `json:"pub_key"` + PrivKey struct { + Type string `json:"type"` + Value []byte `json:"value"` + } `json:"priv_key"` +} + // ReadPrivValidatorFile reads in a privval.FilePVKey from a given file. -func ReadPrivValidatorFile(priv string) (out privval.FilePVKey, err error) { - var bz []byte - if bz, err = os.ReadFile(priv); err != nil { - return +func ReadPrivValidatorFile(priv string) (*TMPrivvalFile, error) { + bz, err := os.ReadFile(priv) + if err != nil { + return nil, err } - if err = cometjson.Unmarshal(bz, &out); err != nil { - return + + var out TMPrivvalFile + + if err := json.Unmarshal(bz, &out); err != nil { + return nil, err } - return + + return &out, nil } -// WriteCosignerEd25519ShardFile writes a cosigner Ed25519 key to a given file name. -func WriteCosignerEd25519ShardFile(cosigner CosignerEd25519Key, file string) error { +// WriteCosignerShardFile writes a cosigner key shard to a given file name. +func WriteCosignerShardFile(cosigner CosignerKey, file string) error { jsonBytes, err := json.Marshal(&cosigner) if err != nil { return err diff --git a/signer/cosigner_nonce_cache_test.go b/signer/cosigner_nonce_cache_test.go index 2c65f175..623f7b04 100644 --- a/signer/cosigner_nonce_cache_test.go +++ b/signer/cosigner_nonce_cache_test.go @@ -56,7 +56,7 @@ func TestMovingAverage(t *testing.T) { } func TestClearNonces(t *testing.T) { - lcs, _ := getTestLocalCosigners(t, 2, 3) + lcs := getTestLocalCosigners(t, CosignerKeyTypeEd25519, 2, 3) cosigners := make([]Cosigner, len(lcs)) for i, lc := range lcs { cosigners[i] = lc @@ -141,7 +141,7 @@ func (mp *mockPruner) Result() (int, int) { } func TestNonceCacheDemand(t *testing.T) { - lcs, _ := getTestLocalCosigners(t, 2, 3) + lcs := getTestLocalCosigners(t, CosignerKeyTypeEd25519, 2, 3) cosigners := make([]Cosigner, len(lcs)) for i, lc := range lcs { cosigners[i] = lc @@ -190,7 +190,7 @@ func TestNonceCacheDemand(t *testing.T) { } func TestNonceCacheExpiration(t *testing.T) { - lcs, _ := getTestLocalCosigners(t, 2, 3) + lcs := getTestLocalCosigners(t, CosignerKeyTypeEd25519, 2, 3) cosigners := make([]Cosigner, len(lcs)) for i, lc := range lcs { cosigners[i] = lc @@ -401,7 +401,7 @@ func TestNonceCachePrune(t *testing.T) { } func TestNonceCacheDemandSlow(t *testing.T) { - lcs, _ := getTestLocalCosigners(t, 2, 3) + lcs := getTestLocalCosigners(t, CosignerKeyTypeEd25519, 2, 3) cosigners := make([]Cosigner, len(lcs)) for i, lc := range lcs { cosigners[i] = lc @@ -438,7 +438,7 @@ func TestNonceCacheDemandSlowDefault(t *testing.T) { if testing.Short() { t.Skip() } - lcs, _ := getTestLocalCosigners(t, 2, 3) + lcs := getTestLocalCosigners(t, CosignerKeyTypeEd25519, 2, 3) cosigners := make([]Cosigner, len(lcs)) for i, lc := range lcs { cosigners[i] = lc diff --git a/signer/local_cosigner.go b/signer/local_cosigner.go index d8955371..e1ad771a 100644 --- a/signer/local_cosigner.go +++ b/signer/local_cosigner.go @@ -187,18 +187,20 @@ func (cosigner *LocalCosigner) CombineSignatures(chainID string, signatures []Pa // Implements Cosigner interface func (cosigner *LocalCosigner) VerifySignature(chainID string, payload, signature []byte) bool { if err := cosigner.LoadSignStateIfNecessary(chainID); err != nil { + fmt.Printf("error loading sign state: %s\n", err) return false } ccs, err := cosigner.getChainState(chainID) if err != nil { + fmt.Printf("error getting chain state: %s\n", err) return false } sig := make([]byte, len(signature)) copy(sig, signature) - return cometcryptoed25519.PubKey(ccs.signer.PubKey()).VerifySignature(payload, sig) + return ccs.signer.VerifySignature(payload, sig) } // Sign the sign request using the cosigner's shard @@ -276,7 +278,7 @@ func (cosigner *LocalCosigner) generateNonces() ([]Nonces, error) { total := len(cosigner.config.Config.ThresholdModeConfig.Cosigners) meta := make([]Nonces, total) - nonces, err := GenerateNonces( + nonces, err := GenerateNoncesEd25519( uint8(cosigner.config.Config.ThresholdModeConfig.Threshold), uint8(total), ) @@ -303,13 +305,29 @@ func (cosigner *LocalCosigner) LoadSignStateIfNecessary(chainID string) error { return err } - var signer ThresholdSigner - - signer, err = NewThresholdSignerSoft(cosigner.config, cosigner.GetID(), chainID) + keyFile, err := cosigner.config.KeyFileExistsCosigner(chainID) if err != nil { return err } + key, err := LoadCosignerKey(keyFile) + if err != nil { + return fmt.Errorf("error reading cosigner key: %s", err) + } + + var signer ThresholdSigner + switch key.KeyType { + case CosignerKeyTypeBn254: + signer, err = NewThresholdSignerSoftBn254(key, uint8(cosigner.config.Config.ThresholdModeConfig.Threshold), uint8(len(cosigner.config.Config.ThresholdModeConfig.Cosigners))) + if err != nil { + return err + } + default: + fallthrough + case CosignerKeyTypeEd25519: + signer = NewThresholdSignerSoftEd25519(key, uint8(cosigner.config.Config.ThresholdModeConfig.Threshold), uint8(len(cosigner.config.Config.ThresholdModeConfig.Cosigners))) + } + cosigner.chainState.Store(chainID, &ChainState{ lastSignState: signState, signer: signer, diff --git a/signer/local_cosigner_test.go b/signer/local_cosigner_test.go index 462da002..7754c772 100644 --- a/signer/local_cosigner_test.go +++ b/signer/local_cosigner_test.go @@ -4,6 +4,7 @@ import ( "context" "crypto/rand" "crypto/rsa" + "encoding/json" "fmt" "os" "path/filepath" @@ -136,8 +137,8 @@ func testLocalCosignerSign(t *testing.T, threshold, total uint8, security []Cosi for i := 0; i < int(total); i++ { id := i + 1 - key := CosignerEd25519Key{ - PubKey: pubKey, + key := CosignerKey{ + PubKey: pubKey.Bytes(), PrivateShard: privShards[i], ID: id, } @@ -161,7 +162,7 @@ func testLocalCosignerSign(t *testing.T, threshold, total uint8, security []Cosi "", ) - keyBz, err := key.MarshalJSON() + keyBz, err := json.Marshal(key) require.NoError(t, err) err = os.WriteFile(cosigner.config.KeyFilePathCosigner(testChainID), keyBz, 0600) require.NoError(t, err) diff --git a/signer/raft_store_test.go b/signer/raft_store_test.go index c7b051e8..553417f2 100644 --- a/signer/raft_store_test.go +++ b/signer/raft_store_test.go @@ -24,7 +24,7 @@ func Test_StoreInMemOpenSingleNode(t *testing.T) { eciesKey, err := ecies.GenerateKey(rand.Reader, secp256k1.S256(), nil) require.NoError(t, err) - key := CosignerEd25519Key{ + key := CosignerKey{ PubKey: dummyPub, PrivateShard: []byte{}, ID: 1, diff --git a/signer/threshold_signer.go b/signer/threshold_signer.go index f8e9ef34..cb06e407 100644 --- a/signer/threshold_signer.go +++ b/signer/threshold_signer.go @@ -2,6 +2,11 @@ package signer import "time" +const ( + CosignerKeyTypeEd25519 = "ed25519" + CosignerKeyTypeBn254 = "bn254" +) + // Interface for the local signer whether it's a soft sign or HSM type ThresholdSigner interface { // PubKey returns the public key bytes for the combination of all cosigners. @@ -12,6 +17,9 @@ type ThresholdSigner interface { // CombineSignatures combines multiple partial signatures to a full signature. CombineSignatures([]PartialSignature) ([]byte, error) + + // VerifySignature verifies a signature against a payload and public key. + VerifySignature(payload, signature []byte) bool } // Nonces contains the ephemeral information generated by one cosigner for all other cosigners. diff --git a/signer/threshold_signer_soft_bn254.go b/signer/threshold_signer_soft_bn254.go new file mode 100644 index 00000000..b9486559 --- /dev/null +++ b/signer/threshold_signer_soft_bn254.go @@ -0,0 +1,133 @@ +package signer + +import ( + "fmt" + + "go.dedis.ch/kyber/v3" + "go.dedis.ch/kyber/v3/pairing/bn256" + "go.dedis.ch/kyber/v3/share" + "go.dedis.ch/kyber/v3/sign/bls" +) + +var _ ThresholdSigner = &ThresholdSignerSoftBn254{} + +type ThresholdSignerSoftBn254 struct { + privateKey kyber.Scalar + pubKey kyber.Point + threshold uint8 + total uint8 + + suite *bn256.Suite +} + +func NewThresholdSignerSoftBn254(key CosignerKey, threshold, total uint8) (*ThresholdSignerSoftBn254, error) { + suite := bn256.NewSuite() + privateKey := suite.G2().Scalar().SetBytes(key.PrivateShard) + pubKey := suite.G2().Point() + if err := pubKey.UnmarshalBinary(key.PubKey); err != nil { + return nil, err + } + return &ThresholdSignerSoftBn254{ + privateKey: privateKey, + pubKey: pubKey, + threshold: threshold, + total: total, + suite: suite, + }, nil +} + +func (s *ThresholdSignerSoftBn254) PubKey() []byte { + pub, err := s.pubKey.MarshalBinary() + if err != nil { + panic(err) + } + return pub +} + +func (s *ThresholdSignerSoftBn254) Sign(nonces []Nonce, payload []byte) ([]byte, error) { + // nonceShare, noncePub, err := s.sumNonces(nonces) + // if err != nil { + // return nil, fmt.Errorf("failed to combine nonces: %w", err) + // } + + return bls.Sign(s.suite, s.privateKey, payload) +} + +// func (s *ThresholdSignerSoftBn254) sumNonces(nonces []Nonce) (tsed25519.Scalar, tsed25519.Element, error) { +// shareParts := make([]tsed25519.Scalar, len(nonces)) +// publicKeys := make([]tsed25519.Element, len(nonces)) + +// for i, n := range nonces { +// shareParts[i] = n.Share +// publicKeys[i] = n.PubKey +// } + +// nonceShare := tsed25519.AddScalars(shareParts) +// noncePub := tsed25519.AddElements(publicKeys) + +// // check bounds for ephemeral share to avoid passing out of bounds valids to SignWithShare +// if len(nonceShare) != 32 { +// return nil, nil, errors.New("ephemeral share is out of bounds") +// } + +// var scalarBytes [32]byte +// copy(scalarBytes[:], nonceShare) +// if !edwards25519.ScMinimal(&scalarBytes) { +// return nil, nil, errors.New("ephemeral share is out of bounds") +// } + +// return nonceShare, noncePub, nil +// } + +// func GenerateNoncesBn254(threshold, total uint8) (Nonces, error) { +// secret := make([]byte, 32) +// if _, err := rand.Read(secret); err != nil { +// return Nonces{}, err +// } + +// nonces := Nonces{ +// PubKey: tsed25519.ScalarMultiplyBase(secret), +// Shares: make([][]byte, total), +// } + +// shares := tsed25519.DealShares(secret, threshold, total) + +// for i, sh := range shares { +// nonces.Shares[i] = sh +// } + +// return nonces, nil +// } + +func (s *ThresholdSignerSoftBn254) CombineSignatures(signatures []PartialSignature) ([]byte, error) { + pubShares := make([]*share.PubShare, 0) + for _, sig := range signatures { + i := sig.ID - 1 + + point := s.suite.G1().Point() + if err := point.UnmarshalBinary(sig.Signature); err != nil { + return nil, err + } + pubShares = append(pubShares, &share.PubShare{I: i, V: point}) + if len(pubShares) >= int(s.threshold) { + break + } + } + commit, err := share.RecoverCommit(s.suite.G1(), pubShares, int(s.threshold), int(s.total)) + if err != nil { + return nil, err + } + sig, err := commit.MarshalBinary() + if err != nil { + return nil, err + } + return sig, nil +} + +func (s *ThresholdSignerSoftBn254) VerifySignature(payload, signature []byte) bool { + if err := bls.Verify(s.suite, s.pubKey, payload, signature); err != nil { + fmt.Printf("Failed to verify signature: %v\n", err) + return false + } + return true +} diff --git a/signer/threshold_signer_soft.go b/signer/threshold_signer_soft_ed25519.go similarity index 64% rename from signer/threshold_signer_soft.go rename to signer/threshold_signer_soft_ed25519.go index c94500cc..8191c1dd 100644 --- a/signer/threshold_signer_soft.go +++ b/signer/threshold_signer_soft_ed25519.go @@ -6,49 +6,34 @@ import ( "errors" "fmt" + cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519" "gitlab.com/unit410/edwards25519" tsed25519 "gitlab.com/unit410/threshold-ed25519/pkg" ) -var _ ThresholdSigner = &ThresholdSignerSoft{} +var _ ThresholdSigner = &ThresholdSignerSoftEd25519{} -type ThresholdSignerSoft struct { +type ThresholdSignerSoftEd25519 struct { privateKeyShard []byte pubKey []byte threshold uint8 total uint8 } -func NewThresholdSignerSoft(config *RuntimeConfig, id int, chainID string) (*ThresholdSignerSoft, error) { - keyFile, err := config.KeyFileExistsCosigner(chainID) - if err != nil { - return nil, err - } - - key, err := LoadCosignerEd25519Key(keyFile) - if err != nil { - return nil, fmt.Errorf("error reading cosigner key: %s", err) - } - - if key.ID != id { - return nil, fmt.Errorf("key shard ID (%d) in (%s) does not match cosigner ID (%d)", key.ID, keyFile, id) - } - - s := ThresholdSignerSoft{ +func NewThresholdSignerSoftEd25519(key CosignerKey, threshold, total uint8) *ThresholdSignerSoftEd25519 { + return &ThresholdSignerSoftEd25519{ privateKeyShard: key.PrivateShard, - pubKey: key.PubKey.Bytes(), - threshold: uint8(config.Config.ThresholdModeConfig.Threshold), - total: uint8(len(config.Config.ThresholdModeConfig.Cosigners)), + pubKey: key.PubKey, + threshold: threshold, + total: total, } - - return &s, nil } -func (s *ThresholdSignerSoft) PubKey() []byte { +func (s *ThresholdSignerSoftEd25519) PubKey() []byte { return s.pubKey } -func (s *ThresholdSignerSoft) Sign(nonces []Nonce, payload []byte) ([]byte, error) { +func (s *ThresholdSignerSoftEd25519) Sign(nonces []Nonce, payload []byte) ([]byte, error) { nonceShare, noncePub, err := s.sumNonces(nonces) if err != nil { return nil, fmt.Errorf("failed to combine nonces: %w", err) @@ -59,7 +44,7 @@ func (s *ThresholdSignerSoft) Sign(nonces []Nonce, payload []byte) ([]byte, erro return append(noncePub, sig...), nil } -func (s *ThresholdSignerSoft) sumNonces(nonces []Nonce) (tsed25519.Scalar, tsed25519.Element, error) { +func (s *ThresholdSignerSoftEd25519) sumNonces(nonces []Nonce) (tsed25519.Scalar, tsed25519.Element, error) { shareParts := make([]tsed25519.Scalar, len(nonces)) publicKeys := make([]tsed25519.Element, len(nonces)) @@ -85,7 +70,7 @@ func (s *ThresholdSignerSoft) sumNonces(nonces []Nonce) (tsed25519.Scalar, tsed2 return nonceShare, noncePub, nil } -func GenerateNonces(threshold, total uint8) (Nonces, error) { +func GenerateNoncesEd25519(threshold, total uint8) (Nonces, error) { secret := make([]byte, 32) if _, err := rand.Read(secret); err != nil { return Nonces{}, err @@ -105,7 +90,7 @@ func GenerateNonces(threshold, total uint8) (Nonces, error) { return nonces, nil } -func (s *ThresholdSignerSoft) CombineSignatures(signatures []PartialSignature) ([]byte, error) { +func (s *ThresholdSignerSoftEd25519) CombineSignatures(signatures []PartialSignature) ([]byte, error) { sigIds := make([]int, len(signatures)) shareSigs := make([][]byte, len(signatures)) var ephPub []byte @@ -123,3 +108,7 @@ func (s *ThresholdSignerSoft) CombineSignatures(signatures []PartialSignature) ( return append(ephPub, combinedSig...), nil } + +func (s *ThresholdSignerSoftEd25519) VerifySignature(payload, signature []byte) bool { + return cometcryptoed25519.PubKey(s.pubKey).VerifySignature(payload, signature) +} diff --git a/signer/threshold_validator_test.go b/signer/threshold_validator_test.go index ea5c6060..3371422d 100644 --- a/signer/threshold_validator_test.go +++ b/signer/threshold_validator_test.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "crypto/rand" + "encoding/json" "fmt" mrand "math/rand" "path/filepath" @@ -13,7 +14,6 @@ import ( "os" "testing" - cometcrypto "github.com/cometbft/cometbft/crypto" cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519" "github.com/cometbft/cometbft/crypto/tmhash" cometlog "github.com/cometbft/cometbft/libs/log" @@ -24,38 +24,58 @@ import ( "github.com/ethereum/go-ethereum/crypto/secp256k1" "github.com/stretchr/testify/require" tsed25519 "gitlab.com/unit410/threshold-ed25519/pkg" + "go.dedis.ch/kyber/v3/pairing/bn256" + "go.dedis.ch/kyber/v3/share" "golang.org/x/sync/errgroup" ) -func TestThresholdValidator2of2(t *testing.T) { - testThresholdValidator(t, 2, 2) +func TestThresholdValidator2of2Ed25519(t *testing.T) { + testThresholdValidator(t, CosignerKeyTypeEd25519, 2, 2) } -func TestThresholdValidator3of3(t *testing.T) { - testThresholdValidator(t, 3, 3) +func TestThresholdValidator2of2Bn254(t *testing.T) { + testThresholdValidator(t, CosignerKeyTypeBn254, 2, 2) } -func TestThresholdValidator2of3(t *testing.T) { - testThresholdValidator(t, 2, 3) +func TestThresholdValidator3of3Ed25519(t *testing.T) { + testThresholdValidator(t, CosignerKeyTypeEd25519, 3, 3) } -func TestThresholdValidator3of5(t *testing.T) { - testThresholdValidator(t, 3, 5) +func TestThresholdValidator3of3Bn254(t *testing.T) { + testThresholdValidator(t, CosignerKeyTypeBn254, 3, 3) +} + +func TestThresholdValidator2of3Ed25519(t *testing.T) { + testThresholdValidator(t, CosignerKeyTypeEd25519, 2, 3) +} + +func TestThresholdValidator2of3Bn254(t *testing.T) { + testThresholdValidator(t, CosignerKeyTypeBn254, 2, 3) +} + +func TestThresholdValidator3of5Ed25519(t *testing.T) { + testThresholdValidator(t, CosignerKeyTypeEd25519, 3, 5) +} + +func TestThresholdValidator3of5Bn254(t *testing.T) { + testThresholdValidator(t, CosignerKeyTypeBn254, 3, 5) } func loadKeyForLocalCosigner( cosigner *LocalCosigner, - pubKey cometcrypto.PubKey, + keyType string, + pubKey []byte, chainID string, privateShard []byte, ) error { - key := CosignerEd25519Key{ + key := CosignerKey{ + KeyType: keyType, PubKey: pubKey, PrivateShard: privateShard, ID: cosigner.GetID(), } - keyBz, err := key.MarshalJSON() + keyBz, err := json.Marshal(key) if err != nil { return err } @@ -63,8 +83,8 @@ func loadKeyForLocalCosigner( return os.WriteFile(cosigner.config.KeyFilePathCosigner(chainID), keyBz, 0600) } -func testThresholdValidator(t *testing.T, threshold, total uint8) { - cosigners, pubKey := getTestLocalCosigners(t, threshold, total) +func testThresholdValidator(t *testing.T, keyType string, threshold, total uint8) { + cosigners := getTestLocalCosigners(t, keyType, threshold, total) thresholdCosigners := make([]Cosigner, 0, threshold-1) @@ -108,7 +128,7 @@ func testThresholdValidator(t *testing.T, threshold, total uint8) { signature, _, err := validator.Sign(ctx, testChainID, block) require.NoError(t, err) - require.True(t, pubKey.VerifySignature(block.SignBytes, signature)) + require.True(t, validator.myCosigner.VerifySignature(testChainID, block.SignBytes, signature)) firstSignature := signature @@ -293,7 +313,7 @@ func testThresholdValidator(t *testing.T, threshold, total uint8) { } } -func getTestLocalCosigners(t *testing.T, threshold, total uint8) ([]*LocalCosigner, cometcrypto.PubKey) { +func getTestLocalCosigners(t *testing.T, keyType string, threshold, total uint8) []*LocalCosigner { eciesKeys := make([]*ecies.PrivateKey, total) pubKeys := make([]*ecies.PublicKey, total) cosigners := make([]*LocalCosigner, total) @@ -307,9 +327,38 @@ func getTestLocalCosigners(t *testing.T, threshold, total uint8) ([]*LocalCosign pubKeys[i] = &eciesKey.PublicKey } - privateKey := cometcryptoed25519.GenPrivKey() - privKeyBytes := privateKey[:] - privShards := tsed25519.DealShares(tsed25519.ExpandSecret(privKeyBytes[:32]), threshold, total) + var ( + pubKey []byte + privShards = make([][]byte, total) + ) + + switch keyType { + case CosignerKeyTypeEd25519: + privateKey := cometcryptoed25519.GenPrivKey() + privKeyBytes := privateKey[:] + privShardsEd25519 := tsed25519.DealShares(tsed25519.ExpandSecret(privKeyBytes[:32]), threshold, total) + + for i := range privShardsEd25519 { + privShards[i] = privShardsEd25519[i][:] + } + pubKey = privateKey.PubKey().Bytes() + case CosignerKeyTypeBn254: + suite := bn256.NewSuite() + secret := suite.G1().Scalar().Pick(suite.RandomStream()) + priPoly := share.NewPriPoly(suite.G2(), int(threshold), secret, suite.RandomStream()) + pubPoly := priPoly.Commit(suite.G2().Point().Base()) + var err error + pk := pubPoly.Commit() + pubKey, err = pk.MarshalBinary() + require.NoError(t, err) + fmt.Printf("pubKey: %+v\n", pk) + + for i, x := range priPoly.Shares(int(total)) { + privShards[i], err = x.V.MarshalBinary() + require.NoError(t, err) + fmt.Printf("share i: %d, %x\n", x.I, privShards[i]) + } + } tmpDir := t.TempDir() @@ -353,18 +402,18 @@ func getTestLocalCosigners(t *testing.T, threshold, total uint8) ([]*LocalCosign cosigners[i] = cosigner - err = loadKeyForLocalCosigner(cosigner, privateKey.PubKey(), testChainID, privShards[i]) + err = loadKeyForLocalCosigner(cosigner, keyType, pubKey, testChainID, privShards[i]) require.NoError(t, err) - err = loadKeyForLocalCosigner(cosigner, privateKey.PubKey(), testChainID2, privShards[i]) + err = loadKeyForLocalCosigner(cosigner, keyType, pubKey, testChainID2, privShards[i]) require.NoError(t, err) } - return cosigners, privateKey.PubKey() + return cosigners } func testThresholdValidatorLeaderElection(t *testing.T, threshold, total uint8) { - cosigners, pubKey := getTestLocalCosigners(t, threshold, total) + cosigners := getTestLocalCosigners(t, CosignerKeyTypeEd25519, threshold, total) thresholdValidators := make([]*ThresholdValidator, 0, total) var leader *ThresholdValidator @@ -468,7 +517,7 @@ func testThresholdValidatorLeaderElection(t *testing.T, threshold, total uint8) sig := make([]byte, len(signature)) copy(sig, signature) - if !pubKey.VerifySignature(signBytes, sig) { + if !tv.myCosigner.VerifySignature(testChainID, signBytes, sig) { t.Log("Proposal signature verification failed") return } @@ -510,7 +559,7 @@ func testThresholdValidatorLeaderElection(t *testing.T, threshold, total uint8) sig := make([]byte, len(signature)) copy(sig, signature) - if !pubKey.VerifySignature(signBytes, sig) { + if !tv.myCosigner.VerifySignature(testChainID, signBytes, sig) { t.Log("PreVote signature verification failed") return } @@ -552,7 +601,7 @@ func testThresholdValidatorLeaderElection(t *testing.T, threshold, total uint8) sig := make([]byte, len(signature)) copy(sig, signature) - if !pubKey.VerifySignature(signBytes, sig) { + if !tv.myCosigner.VerifySignature(testChainID, signBytes, sig) { t.Log("PreCommit signature verification failed") return } diff --git a/test/go.mod b/test/go.mod index 03333dec..b95e0b27 100644 --- a/test/go.mod +++ b/test/go.mod @@ -226,6 +226,8 @@ require ( github.com/zondax/ledger-go v0.14.3 // indirect gitlab.com/unit410/edwards25519 v0.0.0-20220725154547-61980033348e // indirect gitlab.com/unit410/threshold-ed25519 v0.0.0-20220812172601-56783212c4cc // indirect + go.dedis.ch/fixbuf v1.0.3 // indirect + go.dedis.ch/kyber/v3 v3.1.0 // indirect go.etcd.io/bbolt v1.3.8 // indirect go.opencensus.io v0.24.0 // indirect go.uber.org/multierr v1.11.0 // indirect diff --git a/test/go.sum b/test/go.sum index 44768beb..94f563b1 100644 --- a/test/go.sum +++ b/test/go.sum @@ -376,6 +376,10 @@ github.com/cometbft/cometbft v0.38.0 h1:ogKnpiPX7gxCvqTEF4ly25/wAxUqf181t30P3vqd github.com/cometbft/cometbft v0.38.0/go.mod h1:5Jz0Z8YsHSf0ZaAqGvi/ifioSdVFPtEGrm8Y9T/993k= github.com/cometbft/cometbft-db v0.8.0 h1:vUMDaH3ApkX8m0KZvOFFy9b5DZHBAjsnEuo9AKVZpjo= github.com/cometbft/cometbft-db v0.8.0/go.mod h1:6ASCP4pfhmrCBpfk01/9E1SI29nD3HfVHrY4PG8x5c0= +github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ= +github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI= +github.com/consensys/gnark-crypto v0.12.1 h1:lHH39WuuFgVHONRl3J0LRBtuYdQTumFSDtJF7HpyG8M= +github.com/consensys/gnark-crypto v0.12.1/go.mod h1:v2Gy7L/4ZRosZ7Ivs+9SfUDr0f5UlG+EM5t7MPHiLuY= github.com/containerd/containerd v1.6.24 h1:HKF4bfN7WoCk+/n/hi3OrTKJlPWxZmeg1uVDRpEPlXA= github.com/containerd/containerd v1.6.24/go.mod h1:06DkIUikjOcYdqFgOXDwBHO+qR4/qfbMPQ9XxtAGs1c= github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg= @@ -896,6 +900,8 @@ github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:F github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= +github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU= github.com/moby/patternmatcher v0.5.0 h1:YCZgJOeULcxLw1Q+sVR636pmS7sPEn1Qo2iAN6M7DBo= github.com/moby/patternmatcher v0.5.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= github.com/moby/sys/sequential v0.5.0 h1:OPvI35Lzn9K04PBbCLW0g4LcFAJgHsvXsRyewg5lXtc= @@ -1173,6 +1179,16 @@ gitlab.com/unit410/edwards25519 v0.0.0-20220725154547-61980033348e h1:/QfokHt2yG gitlab.com/unit410/edwards25519 v0.0.0-20220725154547-61980033348e/go.mod h1:lTSPILLBMt6qQOJgsiarbW85JhpkhoOfW2EBkxkcuSI= gitlab.com/unit410/threshold-ed25519 v0.0.0-20220812172601-56783212c4cc h1:ESmaQH1+uOLW0wOIPT4EVLh+gwKdmKovr+eZg4jWUNs= gitlab.com/unit410/threshold-ed25519 v0.0.0-20220812172601-56783212c4cc/go.mod h1:1CIpwbV+rSyzoBVr6Ok9vvEP7UHrW/d0zEB+jU6+E3o= +go.dedis.ch/fixbuf v1.0.3 h1:hGcV9Cd/znUxlusJ64eAlExS+5cJDIyTyEG+otu5wQs= +go.dedis.ch/fixbuf v1.0.3/go.mod h1:yzJMt34Wa5xD37V5RTdmp38cz3QhMagdGoem9anUalw= +go.dedis.ch/kyber/v3 v3.0.4/go.mod h1:OzvaEnPvKlyrWyp3kGXlFdp7ap1VC6RkZDTaPikqhsQ= +go.dedis.ch/kyber/v3 v3.0.9/go.mod h1:rhNjUUg6ahf8HEg5HUvVBYoWY4boAafX8tYxX+PS+qg= +go.dedis.ch/kyber/v3 v3.1.0 h1:ghu+kiRgM5JyD9TJ0hTIxTLQlJBR/ehjWvWwYW3XsC0= +go.dedis.ch/kyber/v3 v3.1.0/go.mod h1:kXy7p3STAurkADD+/aZcsznZGKVHEqbtmdIzvPfrs1U= +go.dedis.ch/protobuf v1.0.5/go.mod h1:eIV4wicvi6JK0q/QnfIEGeSFNG0ZeB24kzut5+HaRLo= +go.dedis.ch/protobuf v1.0.7/go.mod h1:pv5ysfkDX/EawiPqcW3ikOxsL5t+BqnV6xHSmE79KI4= +go.dedis.ch/protobuf v1.0.11 h1:FTYVIEzY/bfl37lu3pR4lIj+F9Vp1jE8oh91VmxKgLo= +go.dedis.ch/protobuf v1.0.11/go.mod h1:97QR256dnkimeNdfmURz0wAMNVbd1VmLXhG1CrTYrJ4= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= go.etcd.io/bbolt v1.3.8 h1:xs88BrvEv273UsB79e0hcVrlUWmS0a8upikMFhSyAtA= @@ -1213,6 +1229,7 @@ golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -1383,6 +1400,7 @@ golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190124100055-b90733256f2e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -1901,6 +1919,8 @@ pgregory.net/rapid v1.1.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU= +rsc.io/tmplfunc v0.0.3/go.mod h1:AG3sTPzElb1Io3Yg4voV9AGZJuleGAwaVRxL9M49PhA= sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY= diff --git a/test/horcrux_test.go b/test/horcrux_test.go index 5a62bf35..3e15020b 100644 --- a/test/horcrux_test.go +++ b/test/horcrux_test.go @@ -2,11 +2,11 @@ package test import ( "context" + "crypto/sha256" "fmt" "sync" "testing" - "github.com/cometbft/cometbft/crypto" dockertypes "github.com/docker/docker/api/types" "github.com/strangelove-ventures/horcrux/v3/signer" interchaintest "github.com/strangelove-ventures/interchaintest/v8" @@ -134,7 +134,7 @@ func TestUpgradeValidatorToHorcrux(t *testing.T) { err = testutil.WaitForBlocks(ctx, 20, cw.chain) require.NoError(t, err) - requireHealthyValidator(t, cw.chain.Validators[0], pubKey.Address()) + requireHealthyValidator(t, cw.chain.Validators[0], sha256.New().Sum(pubKey)[:20]) } // TestDownedSigners2of3 tests taking down 2 nodes at a time in the 2/3 threshold horcrux cluster for a period of time. @@ -156,7 +156,7 @@ func TestDownedSigners2of3(t *testing.T) { require.NoError(t, testutil.WaitForBlocks(ctx, 15, cw.chain)) ourValidator := cw.chain.Validators[0] - requireHealthyValidator(t, ourValidator, pubKey.Address()) + requireHealthyValidator(t, ourValidator, sha256.New().Sum(pubKey)[:20]) cosigners := ourValidator.Sidecars @@ -168,7 +168,7 @@ func TestDownedSigners2of3(t *testing.T) { t.Logf("{%s} -> Waiting for blocks after stopping cosigner {%s}", ourValidator.Name(), cosigner.Name()) require.NoError(t, testutil.WaitForBlocks(ctx, 15, cw.chain)) - requireHealthyValidator(t, ourValidator, pubKey.Address()) + requireHealthyValidator(t, ourValidator, sha256.New().Sum(pubKey)[:20]) t.Logf("{%s} -> Restarting signer...", cosigner.Name()) require.NoError(t, cosigner.StartContainer(ctx)) @@ -176,7 +176,7 @@ func TestDownedSigners2of3(t *testing.T) { t.Logf("{%s} -> Waiting for blocks after restarting cosigner {%s}", ourValidator.Name(), cosigner.Name()) require.NoError(t, testutil.WaitForBlocks(ctx, 15, cw.chain)) - requireHealthyValidator(t, ourValidator, pubKey.Address()) + requireHealthyValidator(t, ourValidator, sha256.New().Sum(pubKey)[:20]) } } @@ -199,7 +199,7 @@ func TestDownedSigners3of5(t *testing.T) { require.NoError(t, testutil.WaitForBlocks(ctx, 15, cw.chain)) ourValidator := cw.chain.Validators[0] - requireHealthyValidator(t, ourValidator, pubKey.Address()) + requireHealthyValidator(t, ourValidator, sha256.New().Sum(pubKey)[:20]) cosigners := ourValidator.Sidecars @@ -226,13 +226,13 @@ func TestDownedSigners3of5(t *testing.T) { t.Logf("{%s} -> Waiting for blocks after stopping cosigner {%s}", ourValidator.Name(), cosigner2.Name()) require.NoError(t, testutil.WaitForBlocks(ctx, 15, cw.chain)) - requireHealthyValidator(t, ourValidator, pubKey.Address()) + requireHealthyValidator(t, ourValidator, sha256.New().Sum(pubKey)[:20]) t.Logf("{%s} -> Restarting cosigner...", cosigner1.Name()) require.NoError(t, cosigner1.StartContainer(ctx)) require.NoError(t, testutil.WaitForBlocks(ctx, 15, cw.chain)) - requireHealthyValidator(t, ourValidator, pubKey.Address()) + requireHealthyValidator(t, ourValidator, sha256.New().Sum(pubKey)[:20]) } } @@ -253,7 +253,7 @@ func TestLeaderElection2of3(t *testing.T) { ) ourValidator := cw.chain.Validators[0] - requireHealthyValidator(t, ourValidator, pubKey.Address()) + requireHealthyValidator(t, ourValidator, sha256.New().Sum(pubKey)[:20]) cosigners := ourValidator.Sidecars @@ -295,7 +295,7 @@ func TestLeaderElection2of3(t *testing.T) { require.NoError(t, testutil.WaitForBlocks(ctx, 5, cw.chain)) - requireHealthyValidator(t, ourValidator, pubKey.Address()) + requireHealthyValidator(t, ourValidator, sha256.New().Sum(pubKey)[:20]) } } @@ -313,7 +313,7 @@ func TestChainPureHorcrux(t *testing.T) { sentriesPerSigner = 1 ) - pubKeys := make([]crypto.PubKey, totalValidators) + pubKeys := make([][]byte, totalValidators) cw := &chainWrapper{ totalValidators: totalValidators, totalSentries: 1 + totalValidators*(sentriesPerValidator-1), @@ -329,7 +329,7 @@ func TestChainPureHorcrux(t *testing.T) { require.NoError(t, err) for _, p := range pubKeys { - requireHealthyValidator(t, cw.chain.Validators[0], p.Address()) + requireHealthyValidator(t, cw.chain.Validators[0], sha256.New().Sum(p)[:20]) } } @@ -349,14 +349,14 @@ func TestMultipleChainHorcrux(t *testing.T) { ) chainWrappers := make([]*chainWrapper, totalChains) - pubKeys := make([]crypto.PubKey, totalChains) + pubKeys := make([][]byte, totalChains) chainConfigs := make([]*cosignerChainConfig, totalChains) preGenesises := make([]func(*chainWrapper) func(ibc.ChainConfig) error, totalChains) for i := 0; i < totalChains; i++ { chainConfigs[i] = &cosignerChainConfig{ sentries: make([]cosmos.ChainNodes, sentriesPerSigner), - shards: make([]signer.CosignerEd25519Key, totalSigners), + shards: make([]signer.CosignerKey, totalSigners), } } @@ -444,13 +444,13 @@ func TestMultipleChainHorcrux(t *testing.T) { testutil.WaitForBlocks(ctx, 20, chains...) for i, p := range pubKeys { - requireHealthyValidator(t, chainWrappers[i].chain.Validators[0], p.Address()) + requireHealthyValidator(t, chainWrappers[i].chain.Validators[0], sha256.New().Sum(p)[:20]) } } type cosignerChainConfig struct { chainID string - shards []signer.CosignerEd25519Key + shards []signer.CosignerKey sentries []cosmos.ChainNodes } @@ -584,14 +584,14 @@ func TestHorcruxProxyGRPC(t *testing.T) { ) chainWrappers := make([]*chainWrapper, totalChains) - pubKeys := make([]crypto.PubKey, totalChains) + pubKeys := make([][]byte, totalChains) chainConfigs := make([]*cosignerChainConfig, totalChains) preGenesises := make([]func(*chainWrapper) func(ibc.ChainConfig) error, totalChains) for i := 0; i < totalChains; i++ { chainConfigs[i] = &cosignerChainConfig{ sentries: make([]cosmos.ChainNodes, sentriesPerSigner), - shards: make([]signer.CosignerEd25519Key, totalSigners), + shards: make([]signer.CosignerKey, totalSigners), } } @@ -706,6 +706,6 @@ func TestHorcruxProxyGRPC(t *testing.T) { testutil.WaitForBlocks(ctx, 20, chains...) for i, p := range pubKeys { - requireHealthyValidator(t, chainWrappers[i].chain.Validators[0], p.Address()) + requireHealthyValidator(t, chainWrappers[i].chain.Validators[0], sha256.New().Sum(p)[:20]) } } diff --git a/test/validator.go b/test/validator.go index 487eecf0..cc8a40ab 100644 --- a/test/validator.go +++ b/test/validator.go @@ -9,11 +9,10 @@ import ( "time" cometbytes "github.com/cometbft/cometbft/libs/bytes" - cometjson "github.com/cometbft/cometbft/libs/json" - "github.com/cometbft/cometbft/privval" "github.com/cosmos/cosmos-sdk/types/bech32" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/docker/docker/client" + "github.com/strangelove-ventures/horcrux/v3/signer" "github.com/strangelove-ventures/horcrux/v3/signer/proto" interchaintest "github.com/strangelove-ventures/interchaintest/v8" "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" @@ -175,18 +174,18 @@ func horcruxProxySidecar(ctx context.Context, node *cosmos.ChainNode, name strin } // getPrivvalKey reads the priv_validator_key.json file from the given node. -func getPrivvalKey(ctx context.Context, node *cosmos.ChainNode) (privval.FilePVKey, error) { +func getPrivvalKey(ctx context.Context, node *cosmos.ChainNode) (*signer.TMPrivvalFile, error) { keyBz, err := node.ReadFile(ctx, "config/priv_validator_key.json") if err != nil { - return privval.FilePVKey{}, fmt.Errorf("failed to read priv_validator_key.json: %w", err) + return nil, fmt.Errorf("failed to read priv_validator_key.json: %w", err) } - pvKey := privval.FilePVKey{} - if err := cometjson.Unmarshal(keyBz, &pvKey); err != nil { - return privval.FilePVKey{}, fmt.Errorf("failed to unmarshal priv validator key: %w", err) + var pvKey signer.TMPrivvalFile + if err := json.Unmarshal(keyBz, &pvKey); err != nil { + return nil, fmt.Errorf("failed to unmarshal priv validator key: %w", err) } - return pvKey, nil + return &pvKey, nil } // enablePrivvalListener enables the privval listener on the given sentry nodes. diff --git a/test/validator_single.go b/test/validator_single.go index 13396712..4c6d42c2 100644 --- a/test/validator_single.go +++ b/test/validator_single.go @@ -2,11 +2,13 @@ package test import ( "context" + "crypto/sha256" + "encoding/hex" "encoding/json" "fmt" "testing" - "github.com/cometbft/cometbft/crypto" + cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519" cometjson "github.com/cometbft/cometbft/libs/json" "github.com/cometbft/cometbft/privval" "github.com/docker/docker/client" @@ -32,7 +34,7 @@ func testChainSingleNodeAndHorcruxSingle( err := testutil.WaitForBlocks(ctx, 20, cw.chain) require.NoError(t, err) - requireHealthyValidator(t, cw.chain.Validators[0], pubKey.Address()) + requireHealthyValidator(t, cw.chain.Validators[0], sha256.New().Sum(pubKey)[:20]) } // startChainSingleNodeAndHorcruxSingle starts a single chain with a single horcrux (single-sign mode) validator and single node validators for the rest. @@ -41,11 +43,11 @@ func startChainSingleNodeAndHorcruxSingle( t *testing.T, totalValidators int, // total number of validators on chain (one horcrux + single node for the rest) totalSentries int, // number of sentry nodes for the single horcrux validator -) (*chainWrapper, crypto.PubKey) { +) (*chainWrapper, []byte) { client, network := interchaintest.DockerSetup(t) logger := zaptest.NewLogger(t) - var pubKey crypto.PubKey + var pubKey []byte cw := &chainWrapper{ totalValidators: totalValidators, @@ -65,7 +67,7 @@ func preGenesisSingleNodeAndHorcruxSingle( logger *zap.Logger, client *client.Client, network string, - pubKey *crypto.PubKey) func(*chainWrapper) func(ibc.ChainConfig) error { + pubKey *[]byte) func(*chainWrapper) func(ibc.ChainConfig) error { return func(cw *chainWrapper) func(ibc.ChainConfig) error { return func(cc ibc.ChainConfig) error { horcruxValidator := cw.chain.Validators[0] @@ -75,7 +77,7 @@ func preGenesisSingleNodeAndHorcruxSingle( return err } - *pubKey = pvKey.PubKey + *pubKey = pvKey.PubKey.Value sentries := append(cosmos.ChainNodes{horcruxValidator}, cw.chain.FullNodes...) @@ -119,7 +121,7 @@ func writeConfigAndKeysSingle( chainID string, singleSigner *cosmos.SidecarProcess, config signer.Config, - pvKey privval.FilePVKey, + key *signer.TMPrivvalFile, ) error { configBz, err := json.Marshal(config) if err != nil { @@ -130,6 +132,17 @@ func writeConfigAndKeysSingle( return fmt.Errorf("failed to write config.yaml: %w", err) } + address, err := hex.DecodeString(key.Address) + if err != nil { + return fmt.Errorf("failed to decode address: %w", err) + } + + pvKey := privval.FilePVKey{ + Address: address, + PubKey: cometcryptoed25519.PubKey(key.PubKey.Value), + PrivKey: cometcryptoed25519.PrivKey(key.PrivKey.Value), + } + pvKeyBz, err := cometjson.Marshal(pvKey) if err != nil { return fmt.Errorf("failed to marshal priv validator key: %w", err) diff --git a/test/validator_threshold.go b/test/validator_threshold.go index bff4928d..8a7e6605 100644 --- a/test/validator_threshold.go +++ b/test/validator_threshold.go @@ -2,13 +2,13 @@ package test import ( "context" + "crypto/sha256" "encoding/json" "fmt" "net/http" "testing" "time" - "github.com/cometbft/cometbft/crypto" "github.com/docker/docker/client" dto "github.com/prometheus/client_model/go" "github.com/prometheus/common/expfmt" @@ -43,7 +43,9 @@ func testChainSingleNodeAndHorcruxThreshold( err := testutil.WaitForBlocks(ctx, 20, cw.chain) require.NoError(t, err) - requireHealthyValidator(t, ourValidator, pubKey.Address()) + address := sha256.New().Sum(pubKey)[:20] + + requireHealthyValidator(t, ourValidator, address) } // startChainSingleNodeAndHorcruxThreshold starts a single chain with a single horcrux (threshold mode) validator and single node validators for the rest of the validators. @@ -55,12 +57,12 @@ func startChainSingleNodeAndHorcruxThreshold( threshold uint8, // key shard threshold, and therefore how many horcrux signers must participate to sign a block totalSentries int, // number of sentry nodes for the single horcrux validator sentriesPerSigner int, // how many sentries should each horcrux signer connect to (min: 1, max: totalSentries) -) (*chainWrapper, crypto.PubKey) { +) (*chainWrapper, []byte) { client, network := interchaintest.DockerSetup(t) logger := zaptest.NewLogger(t) var chain *cosmos.CosmosChain - var pubKey crypto.PubKey + var pubKey []byte cw := &chainWrapper{ chain: chain, @@ -84,7 +86,7 @@ func preGenesisSingleNodeAndHorcruxThreshold( totalSigners int, // total number of signers for the single horcrux validator threshold uint8, // key shard threshold, and therefore how many horcrux signers must participate to sign a block sentriesPerSigner int, // how many sentries should each horcrux signer connect to (min: 1, max: totalSentries) - pubKey *crypto.PubKey) func(*chainWrapper) func(ibc.ChainConfig) error { + pubKey *[]byte) func(*chainWrapper) func(ibc.ChainConfig) error { return func(cw *chainWrapper) func(ibc.ChainConfig) error { return func(cc ibc.ChainConfig) error { horcruxValidator := cw.chain.Validators[0] @@ -124,7 +126,7 @@ func preGenesisAllHorcruxThreshold( sentriesPerValidator int, // how many sentries for each horcrux validator (min: sentriesPerSigner, max: totalSentries) sentriesPerSigner int, // how many sentries should each horcrux signer connect to (min: 1, max: sentriesPerValidator) - pubKeys []crypto.PubKey) func(*chainWrapper) func(ibc.ChainConfig) error { + pubKeys [][]byte) func(*chainWrapper) func(ibc.ChainConfig) error { return func(cw *chainWrapper) func(ibc.ChainConfig) error { return func(cc ibc.ChainConfig) error { fnsPerVal := sentriesPerValidator - 1 // minus 1 for the validator itself @@ -174,7 +176,7 @@ func convertValidatorToHorcrux( threshold uint8, sentries cosmos.ChainNodes, sentriesPerSigner int, -) (crypto.PubKey, error) { +) ([]byte, error) { sentriesForCosigners := getSentriesForCosignerConnection(sentries, totalSigners, sentriesPerSigner) ed25519Shards, pvPubKey, err := getShardedPrivvalKey(ctx, validator, threshold, uint8(totalSigners)) @@ -251,7 +253,7 @@ func convertValidatorToHorcrux( } // getPrivvalKey gets the privval key from the validator and creates threshold shards from it. -func getShardedPrivvalKey(ctx context.Context, node *cosmos.ChainNode, threshold uint8, shards uint8) ([]signer.CosignerEd25519Key, crypto.PubKey, error) { +func getShardedPrivvalKey(ctx context.Context, node *cosmos.ChainNode, threshold uint8, shards uint8) ([]signer.CosignerKey, []byte, error) { pvKey, err := getPrivvalKey(ctx, node) if err != nil { return nil, nil, err @@ -259,13 +261,13 @@ func getShardedPrivvalKey(ctx context.Context, node *cosmos.ChainNode, threshold ed25519Shards := signer.CreateCosignerEd25519Shards(pvKey, threshold, shards) - return ed25519Shards, pvKey.PubKey, nil + return ed25519Shards, pvKey.PubKey.Value, nil } // chainEd25519Shard is a wrapper for a chain ID and a shard of an ed25519 consensus key. type chainEd25519Shard struct { chainID string - key signer.CosignerEd25519Key + key signer.CosignerKey } // writeConfigAndKeysThreshold writes the config and keys for a horcrux cosigner to the sidecar's docker volume. From 285889689ab10926bb157f49056b2ec572ee2ae2 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Sun, 17 Dec 2023 17:13:22 -0700 Subject: [PATCH 3/9] some fixes --- .golangci.yml | 2 + cmd/horcrux/cmd/migrate.go | 7 +- .../cosigner-key-migrated-ed25519.json | 2 +- signer/cosigner_key.go | 74 +++++++++++++++++++ signer/cosigner_key_shares.go | 3 - signer/cosigner_nonce_cache.go | 4 +- signer/local_cosigner.go | 16 +++- signer/threshold_signer_soft_bn254.go | 4 +- test/horcrux_test.go | 35 ++++++--- test/validator_single.go | 3 +- test/validator_threshold.go | 8 +- 11 files changed, 127 insertions(+), 31 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 8fe7a04a..266d1de4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -99,6 +99,8 @@ linters-settings: alias: boltdb - pkg: math/rand alias: mrand + - pkg: github.com/consensys/gnark-crypto/ecc/bn254/ecdsa + alias: ecdsa_bn254 maligned: suggest-new: true govet: diff --git a/cmd/horcrux/cmd/migrate.go b/cmd/horcrux/cmd/migrate.go index 59a0ad45..08705c06 100644 --- a/cmd/horcrux/cmd/migrate.go +++ b/cmd/horcrux/cmd/migrate.go @@ -218,7 +218,8 @@ func migrateCmd() *cobra.Command { return err } - newEd25519Key := signer.CosignerKey{ + newEd25519Key := &signer.CosignerKey{ + KeyType: signer.CosignerKeyTypeEd25519, PubKey: legacyCosignerKey.PubKey.Bytes(), PrivateShard: legacyCosignerKey.ShareKey, ID: legacyCosignerKey.ID, @@ -234,13 +235,13 @@ func migrateCmd() *cobra.Command { return fmt.Errorf("failed to write new Ed25519 key to %s: %w", newEd25519Path, err) } - newRSAKey := signer.CosignerRSAKey{ + newRSAKey := &signer.CosignerRSAKey{ RSAKey: legacyCosignerKey.RSAKey, ID: legacyCosignerKey.ID, RSAPubs: legacyCosignerKey.RSAPubs, } - newRSAKeyBz, err := newRSAKey.MarshalJSON() + newRSAKeyBz, err := json.Marshal(newRSAKey) if err != nil { return fmt.Errorf("failed to marshal new RSA key to json: %w", err) } diff --git a/cmd/horcrux/cmd/testdata/cosigner-key-migrated-ed25519.json b/cmd/horcrux/cmd/testdata/cosigner-key-migrated-ed25519.json index ae8a9382..2beb747c 100644 --- a/cmd/horcrux/cmd/testdata/cosigner-key-migrated-ed25519.json +++ b/cmd/horcrux/cmd/testdata/cosigner-key-migrated-ed25519.json @@ -1 +1 @@ -{"pubKey":"CiBRLhKCqDU6Wufhj0TZK6jNO8LreArc+CKHKYitdTyYUg==","privateShard":"q0zuUQpplAfBJxoA2e2O1H7BdBgopzhPmL8mIWP8AQw=","id":3} \ No newline at end of file +{"pubKey":"CiBRLhKCqDU6Wufhj0TZK6jNO8LreArc+CKHKYitdTyYUg==","keyType":"ed25519","privateShard":"q0zuUQpplAfBJxoA2e2O1H7BdBgopzhPmL8mIWP8AQw=","id":3} \ No newline at end of file diff --git a/signer/cosigner_key.go b/signer/cosigner_key.go index 19ff3b7e..330e060f 100644 --- a/signer/cosigner_key.go +++ b/signer/cosigner_key.go @@ -3,6 +3,12 @@ package signer import ( "encoding/json" "os" + + cometcrypto "github.com/cometbft/cometbft/crypto" + cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519" + cometcryptoencoding "github.com/cometbft/cometbft/crypto/encoding" + cometprotocrypto "github.com/cometbft/cometbft/proto/tendermint/crypto" + "github.com/tendermint/go-amino" ) // CosignerKey is a single key shard for an m-of-n threshold signer. @@ -13,6 +19,74 @@ type CosignerKey struct { ID int `json:"id"` } +func (key *CosignerKey) MarshalJSON() ([]byte, error) { + type Alias CosignerKey + + protoPubkey, err := cometcryptoencoding.PubKeyToProto(cometcryptoed25519.PubKey(key.PubKey)) + if err != nil { + return nil, err + } + + protoBytes, err := protoPubkey.Marshal() + if err != nil { + return nil, err + } + + return json.Marshal(&struct { + PubKey []byte `json:"pubKey"` + *Alias + }{ + PubKey: protoBytes, + Alias: (*Alias)(key), + }) +} + +func (key *CosignerKey) UnmarshalJSON(data []byte) error { + type Alias CosignerKey + + aux := &struct { + PubkeyBytes []byte `json:"pubKey"` + *Alias + }{ + Alias: (*Alias)(key), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + + var pubkey cometcrypto.PubKey + var protoPubkey cometprotocrypto.PublicKey + err := protoPubkey.Unmarshal(aux.PubkeyBytes) + + // Prior to the tendermint protobuf migration, the public key bytes in key files + // were encoded using the go-amino libraries via + // cdc.MarshalBinaryBare(key.PubKey) + // + // To support reading the public key bytes from these key files, we fallback to + // amino unmarshalling if the protobuf unmarshalling fails + if err != nil { + var pub cometcryptoed25519.PubKey + codec := amino.NewCodec() + codec.RegisterInterface((*cometcrypto.PubKey)(nil), nil) + codec.RegisterConcrete(cometcryptoed25519.PubKey{}, "tendermint/PubKeyEd25519", nil) + codec.RegisterConcrete(cometcryptoed25519.PubKey{}, "tendermint/PubKeyBn254", nil) + + errInner := codec.UnmarshalBinaryBare(aux.PubkeyBytes, &pub) + if errInner != nil { + return err + } + pubkey = pub + } else { + pubkey, err = cometcryptoencoding.PubKeyFromProto(protoPubkey) + if err != nil { + return err + } + } + + key.PubKey = pubkey.Bytes() + return nil +} + // LoadCosignerKey loads a CosignerKey from file. func LoadCosignerKey(file string) (CosignerKey, error) { pvKey := CosignerKey{} diff --git a/signer/cosigner_key_shares.go b/signer/cosigner_key_shares.go index 74d56f9f..05fe3498 100644 --- a/signer/cosigner_key_shares.go +++ b/signer/cosigner_key_shares.go @@ -5,7 +5,6 @@ import ( "crypto/rsa" "encoding/json" "errors" - "fmt" "os" "github.com/ethereum/go-ethereum/crypto/ecies" @@ -37,7 +36,6 @@ func CreateCosignerShardsFromFile(priv string, threshold, shards uint8) ([]Cosig // CreateCosignerEd25519Shards creates CosignerKey objects from a privval.FilePVKey func CreateCosignerEd25519Shards(pv *TMPrivvalFile, threshold, shards uint8) []CosignerKey { - fmt.Printf("ED25519 pv.PrivKey.Value: %v, len: %d\n", pv.PrivKey.Value, len(pv.PrivKey.Value)) privShards := tsed25519.DealShares(tsed25519.ExpandSecret(pv.PrivKey.Value[:32]), threshold, shards) out := make([]CosignerKey, shards) for i, shard := range privShards { @@ -53,7 +51,6 @@ func CreateCosignerEd25519Shards(pv *TMPrivvalFile, threshold, shards uint8) []C // CreateCosignerEd25519Shards creates CosignerKey objects from a privval.FilePVKey func CreateCosignerBn254Shards(pv *TMPrivvalFile, threshold, shards uint8) []CosignerKey { - fmt.Printf("BN254 pv.PrivKey.Value: %v, len: %d\n", pv.PrivKey.Value, len(pv.PrivKey.Value)) suite := bn256.NewSuite() secret := suite.G1().Scalar().SetBytes(pv.PrivKey.Value) priPoly := share.NewPriPoly(suite.G2(), int(threshold), secret, suite.RandomStream()) diff --git a/signer/cosigner_nonce_cache.go b/signer/cosigner_nonce_cache.go index 3b8ad25c..58f2ee47 100644 --- a/signer/cosigner_nonce_cache.go +++ b/signer/cosigner_nonce_cache.go @@ -199,7 +199,9 @@ func (cnc *CosignerNonceCache) getUuids(n int) []uuid.UUID { } func (cnc *CosignerNonceCache) target(noncesPerMinute float64) int { - t := int((noncesPerMinute / 60) * ((cnc.getNoncesInterval.Seconds() * nonceOverallocation) + float64(cnc.getNoncesTimeout.Seconds()))) + t := int((noncesPerMinute / 60) * + ((cnc.getNoncesInterval.Seconds() * nonceOverallocation) + + cnc.getNoncesTimeout.Seconds())) if t <= 0 { return 1 // always target at least one nonce ready } diff --git a/signer/local_cosigner.go b/signer/local_cosigner.go index e1ad771a..9d3e9069 100644 --- a/signer/local_cosigner.go +++ b/signer/local_cosigner.go @@ -318,14 +318,22 @@ func (cosigner *LocalCosigner) LoadSignStateIfNecessary(chainID string) error { var signer ThresholdSigner switch key.KeyType { case CosignerKeyTypeBn254: - signer, err = NewThresholdSignerSoftBn254(key, uint8(cosigner.config.Config.ThresholdModeConfig.Threshold), uint8(len(cosigner.config.Config.ThresholdModeConfig.Cosigners))) + signer, err = NewThresholdSignerSoftBn254( + key, + uint8(cosigner.config.Config.ThresholdModeConfig.Threshold), + uint8(len(cosigner.config.Config.ThresholdModeConfig.Cosigners)), + ) if err != nil { return err } - default: - fallthrough case CosignerKeyTypeEd25519: - signer = NewThresholdSignerSoftEd25519(key, uint8(cosigner.config.Config.ThresholdModeConfig.Threshold), uint8(len(cosigner.config.Config.ThresholdModeConfig.Cosigners))) + fallthrough + default: + signer = NewThresholdSignerSoftEd25519( + key, + uint8(cosigner.config.Config.ThresholdModeConfig.Threshold), + uint8(len(cosigner.config.Config.ThresholdModeConfig.Cosigners)), + ) } cosigner.chainState.Store(chainID, &ChainState{ diff --git a/signer/threshold_signer_soft_bn254.go b/signer/threshold_signer_soft_bn254.go index b9486559..c4567096 100644 --- a/signer/threshold_signer_soft_bn254.go +++ b/signer/threshold_signer_soft_bn254.go @@ -6,7 +6,7 @@ import ( "go.dedis.ch/kyber/v3" "go.dedis.ch/kyber/v3/pairing/bn256" "go.dedis.ch/kyber/v3/share" - "go.dedis.ch/kyber/v3/sign/bls" + "go.dedis.ch/kyber/v3/sign/bls" //nolint:staticcheck ) var _ ThresholdSigner = &ThresholdSignerSoftBn254{} @@ -44,7 +44,7 @@ func (s *ThresholdSignerSoftBn254) PubKey() []byte { return pub } -func (s *ThresholdSignerSoftBn254) Sign(nonces []Nonce, payload []byte) ([]byte, error) { +func (s *ThresholdSignerSoftBn254) Sign(_ []Nonce, payload []byte) ([]byte, error) { // nonceShare, noncePub, err := s.sumNonces(nonces) // if err != nil { // return nil, fmt.Errorf("failed to combine nonces: %w", err) diff --git a/test/horcrux_test.go b/test/horcrux_test.go index 3e15020b..9331f1f3 100644 --- a/test/horcrux_test.go +++ b/test/horcrux_test.go @@ -134,7 +134,9 @@ func TestUpgradeValidatorToHorcrux(t *testing.T) { err = testutil.WaitForBlocks(ctx, 20, cw.chain) require.NoError(t, err) - requireHealthyValidator(t, cw.chain.Validators[0], sha256.New().Sum(pubKey)[:20]) + sha := sha256.Sum256(pubKey) + + requireHealthyValidator(t, cw.chain.Validators[0], sha[:20]) } // TestDownedSigners2of3 tests taking down 2 nodes at a time in the 2/3 threshold horcrux cluster for a period of time. @@ -156,7 +158,9 @@ func TestDownedSigners2of3(t *testing.T) { require.NoError(t, testutil.WaitForBlocks(ctx, 15, cw.chain)) ourValidator := cw.chain.Validators[0] - requireHealthyValidator(t, ourValidator, sha256.New().Sum(pubKey)[:20]) + sha := sha256.Sum256(pubKey) + address := sha[:20] + requireHealthyValidator(t, ourValidator, address) cosigners := ourValidator.Sidecars @@ -168,7 +172,7 @@ func TestDownedSigners2of3(t *testing.T) { t.Logf("{%s} -> Waiting for blocks after stopping cosigner {%s}", ourValidator.Name(), cosigner.Name()) require.NoError(t, testutil.WaitForBlocks(ctx, 15, cw.chain)) - requireHealthyValidator(t, ourValidator, sha256.New().Sum(pubKey)[:20]) + requireHealthyValidator(t, ourValidator, address) t.Logf("{%s} -> Restarting signer...", cosigner.Name()) require.NoError(t, cosigner.StartContainer(ctx)) @@ -176,7 +180,7 @@ func TestDownedSigners2of3(t *testing.T) { t.Logf("{%s} -> Waiting for blocks after restarting cosigner {%s}", ourValidator.Name(), cosigner.Name()) require.NoError(t, testutil.WaitForBlocks(ctx, 15, cw.chain)) - requireHealthyValidator(t, ourValidator, sha256.New().Sum(pubKey)[:20]) + requireHealthyValidator(t, ourValidator, address) } } @@ -199,7 +203,9 @@ func TestDownedSigners3of5(t *testing.T) { require.NoError(t, testutil.WaitForBlocks(ctx, 15, cw.chain)) ourValidator := cw.chain.Validators[0] - requireHealthyValidator(t, ourValidator, sha256.New().Sum(pubKey)[:20]) + sha := sha256.Sum256(pubKey) + address := sha[:20] + requireHealthyValidator(t, ourValidator, address) cosigners := ourValidator.Sidecars @@ -226,13 +232,13 @@ func TestDownedSigners3of5(t *testing.T) { t.Logf("{%s} -> Waiting for blocks after stopping cosigner {%s}", ourValidator.Name(), cosigner2.Name()) require.NoError(t, testutil.WaitForBlocks(ctx, 15, cw.chain)) - requireHealthyValidator(t, ourValidator, sha256.New().Sum(pubKey)[:20]) + requireHealthyValidator(t, ourValidator, address) t.Logf("{%s} -> Restarting cosigner...", cosigner1.Name()) require.NoError(t, cosigner1.StartContainer(ctx)) require.NoError(t, testutil.WaitForBlocks(ctx, 15, cw.chain)) - requireHealthyValidator(t, ourValidator, sha256.New().Sum(pubKey)[:20]) + requireHealthyValidator(t, ourValidator, address) } } @@ -253,7 +259,9 @@ func TestLeaderElection2of3(t *testing.T) { ) ourValidator := cw.chain.Validators[0] - requireHealthyValidator(t, ourValidator, sha256.New().Sum(pubKey)[:20]) + sha := sha256.Sum256(pubKey) + address := sha[:20] + requireHealthyValidator(t, ourValidator, address) cosigners := ourValidator.Sidecars @@ -295,7 +303,7 @@ func TestLeaderElection2of3(t *testing.T) { require.NoError(t, testutil.WaitForBlocks(ctx, 5, cw.chain)) - requireHealthyValidator(t, ourValidator, sha256.New().Sum(pubKey)[:20]) + requireHealthyValidator(t, ourValidator, address) } } @@ -329,7 +337,8 @@ func TestChainPureHorcrux(t *testing.T) { require.NoError(t, err) for _, p := range pubKeys { - requireHealthyValidator(t, cw.chain.Validators[0], sha256.New().Sum(p)[:20]) + sha := sha256.Sum256(p) + requireHealthyValidator(t, cw.chain.Validators[0], sha[:20]) } } @@ -444,7 +453,8 @@ func TestMultipleChainHorcrux(t *testing.T) { testutil.WaitForBlocks(ctx, 20, chains...) for i, p := range pubKeys { - requireHealthyValidator(t, chainWrappers[i].chain.Validators[0], sha256.New().Sum(p)[:20]) + sha := sha256.Sum256(p) + requireHealthyValidator(t, chainWrappers[i].chain.Validators[0], sha[:20]) } } @@ -706,6 +716,7 @@ func TestHorcruxProxyGRPC(t *testing.T) { testutil.WaitForBlocks(ctx, 20, chains...) for i, p := range pubKeys { - requireHealthyValidator(t, chainWrappers[i].chain.Validators[0], sha256.New().Sum(p)[:20]) + sha := sha256.Sum256(p) + requireHealthyValidator(t, chainWrappers[i].chain.Validators[0], sha[:20]) } } diff --git a/test/validator_single.go b/test/validator_single.go index 4c6d42c2..9cf1f6d0 100644 --- a/test/validator_single.go +++ b/test/validator_single.go @@ -34,7 +34,8 @@ func testChainSingleNodeAndHorcruxSingle( err := testutil.WaitForBlocks(ctx, 20, cw.chain) require.NoError(t, err) - requireHealthyValidator(t, cw.chain.Validators[0], sha256.New().Sum(pubKey)[:20]) + sha := sha256.Sum256(pubKey) + requireHealthyValidator(t, cw.chain.Validators[0], sha[:20]) } // startChainSingleNodeAndHorcruxSingle starts a single chain with a single horcrux (single-sign mode) validator and single node validators for the rest. diff --git a/test/validator_threshold.go b/test/validator_threshold.go index 8a7e6605..2200c427 100644 --- a/test/validator_threshold.go +++ b/test/validator_threshold.go @@ -37,15 +37,15 @@ func testChainSingleNodeAndHorcruxThreshold( cw, pubKey := startChainSingleNodeAndHorcruxThreshold(ctx, t, totalValidators, totalSigners, threshold, totalSentries, sentriesPerSigner) ourValidator := cw.chain.Validators[0] - cosigners := ourValidator.Sidecars - go getCosignerMetrics(ctx, cosigners) + // cosigners := ourValidator.Sidecars + // go getCosignerMetrics(ctx, cosigners) err := testutil.WaitForBlocks(ctx, 20, cw.chain) require.NoError(t, err) - address := sha256.New().Sum(pubKey)[:20] + sha := sha256.Sum256(pubKey) - requireHealthyValidator(t, ourValidator, address) + requireHealthyValidator(t, ourValidator, sha[:20]) } // startChainSingleNodeAndHorcruxThreshold starts a single chain with a single horcrux (threshold mode) validator and single node validators for the rest of the validators. From 0c9df8f7218a04070b54458e7d36bf5668e1ba46 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Sun, 17 Dec 2023 18:40:13 -0700 Subject: [PATCH 4/9] Marshal bn254 pubkeys --- cmd/horcrux/cmd/migrate.go | 8 +- proto/buf.lock | 5 + proto/buf.yaml | 2 + proto/tendermint/crypto/keys.proto | 18 + signer/bn254/bn254.go | 174 ++++++ signer/cosigner_key.go | 37 +- signer/encoding/codec.go | 76 +++ signer/local_cosigner_test.go | 2 +- signer/proto/keys.pb.go | 791 ++++++++++++++++++++++++ signer/single_signer_validator.go | 3 + signer/threshold_signer_soft_bn254.go | 2 +- signer/threshold_signer_soft_ed25519.go | 2 +- signer/threshold_validator_test.go | 4 +- 13 files changed, 1101 insertions(+), 23 deletions(-) create mode 100644 proto/tendermint/crypto/keys.proto create mode 100644 signer/bn254/bn254.go create mode 100644 signer/encoding/codec.go create mode 100644 signer/proto/keys.pb.go diff --git a/cmd/horcrux/cmd/migrate.go b/cmd/horcrux/cmd/migrate.go index 08705c06..0c2b2772 100644 --- a/cmd/horcrux/cmd/migrate.go +++ b/cmd/horcrux/cmd/migrate.go @@ -10,10 +10,10 @@ import ( cometcrypto "github.com/cometbft/cometbft/crypto" cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519" - cometcryptoencoding "github.com/cometbft/cometbft/crypto/encoding" - cometprotocrypto "github.com/cometbft/cometbft/proto/tendermint/crypto" "github.com/spf13/cobra" "github.com/strangelove-ventures/horcrux/v3/signer" + "github.com/strangelove-ventures/horcrux/v3/signer/encoding" + "github.com/strangelove-ventures/horcrux/v3/signer/proto" amino "github.com/tendermint/go-amino" "gopkg.in/yaml.v2" ) @@ -98,7 +98,7 @@ func (key *v2CosignerKey) UnmarshalJSON(data []byte) error { } var pubkey cometcrypto.PubKey - var protoPubkey cometprotocrypto.PublicKey + var protoPubkey proto.PublicKey err = protoPubkey.Unmarshal(aux.PubkeyBytes) // Prior to the tendermint protobuf migration, the public key bytes in key files @@ -118,7 +118,7 @@ func (key *v2CosignerKey) UnmarshalJSON(data []byte) error { } pubkey = pub } else { - pubkey, err = cometcryptoencoding.PubKeyFromProto(protoPubkey) + pubkey, err = encoding.PubKeyFromProto(protoPubkey) if err != nil { return err } diff --git a/proto/buf.lock b/proto/buf.lock index c91b5810..4850ea9b 100755 --- a/proto/buf.lock +++ b/proto/buf.lock @@ -1,2 +1,7 @@ # Generated by buf. DO NOT EDIT. version: v1 +deps: + - remote: buf.build + owner: cosmos + repository: gogo-proto + commit: 5e5b9fdd01804356895f8f79a6f1ddc1 diff --git a/proto/buf.yaml b/proto/buf.yaml index c126332f..8477697c 100644 --- a/proto/buf.yaml +++ b/proto/buf.yaml @@ -1 +1,3 @@ version: v1 +deps: + - buf.build/cosmos/gogo-proto \ No newline at end of file diff --git a/proto/tendermint/crypto/keys.proto b/proto/tendermint/crypto/keys.proto new file mode 100644 index 00000000..75efddbc --- /dev/null +++ b/proto/tendermint/crypto/keys.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; +package tendermint.crypto; + +option go_package = "github.com/strangelove-ventures/horcrux/signer/proto"; + +import "gogoproto/gogo.proto"; + +// PublicKey defines the keys available for use with Validators +message PublicKey { + option (gogoproto.compare) = true; + option (gogoproto.equal) = true; + + oneof sum { + bytes ed25519 = 1; + bytes secp256k1 = 2; + bytes bn254 = 3; + } +} diff --git a/signer/bn254/bn254.go b/signer/bn254/bn254.go new file mode 100644 index 00000000..7a8e5220 --- /dev/null +++ b/signer/bn254/bn254.go @@ -0,0 +1,174 @@ +package bn254 + +import ( + "bytes" + "crypto/sha256" + "crypto/subtle" + "fmt" + "io" + + "github.com/cometbft/cometbft/crypto" + "github.com/cometbft/cometbft/crypto/tmhash" + cometjson "github.com/cometbft/cometbft/libs/json" + ecdsa_bn254 "github.com/consensys/gnark-crypto/ecc/bn254/ecdsa" +) + +//------------------------------------- + +var ( + _ crypto.PrivKey = PrivKey{} +) + +const ( + PrivKeyName = "tendermint/PrivKeyBn254" + PubKeyName = "tendermint/PubKeyBn254" + // PubKeySize is is the size, in bytes, of public keys as used in this package. + PubKeySize = 32 + // PrivateKeySize is the size, in bytes, of private keys as used in this package. + PrivateKeySize = 64 + // Size of an Bn254 signature. Namely the size of a compressed + // Bn254 point, and a field element. Both of which are 32 bytes. + SignatureSize = 64 + // SeedSize is the size, in bytes, of private key seeds. These are the + // private key representations used by RFC 8032. + SeedSize = 32 + + KeyType = "bn254" +) + +func init() { + cometjson.RegisterType(PubKey{}, PubKeyName) + cometjson.RegisterType(PrivKey{}, PrivKeyName) +} + +// PrivKey implements crypto.PrivKey. +type PrivKey []byte + +// Bytes returns the privkey byte format. +func (privKey PrivKey) Bytes() []byte { + return []byte(privKey) +} + +// Sign produces a signature on the provided message. +// This assumes the privkey is wellformed in the golang format. +// The first 32 bytes should be random, +// corresponding to the normal bn254 private key. +// The latter 32 bytes should be the compressed public key. +// If these conditions aren't met, Sign will panic or produce an +// incorrect signature. +func (privKey PrivKey) Sign(msg []byte) ([]byte, error) { + priv := new(ecdsa_bn254.PrivateKey) + _, err := priv.SetBytes(privKey[:]) + if err != nil { + return nil, err + } + + hFunc := sha256.New() + + return priv.Sign(msg, hFunc) +} + +// PubKey gets the corresponding public key from the private key. +// +// Panics if the private key is not initialized. +func (privKey PrivKey) PubKey() crypto.PubKey { + // If the latter 32 bytes of the privkey are all zero, privkey is not + // initialized. + initialized := false + for _, v := range privKey[32:] { + if v != 0 { + initialized = true + break + } + } + + if !initialized { + panic("Expected bn254 PrivKey to include concatenated pubkey bytes") + } + + pubkeyBytes := make([]byte, PubKeySize) + copy(pubkeyBytes, privKey[32:]) + return PubKey(pubkeyBytes) +} + +// Equals - you probably don't need to use this. +// Runs in constant time based on length of the keys. +func (privKey PrivKey) Equals(other crypto.PrivKey) bool { + if otherEd, ok := other.(PrivKey); ok { + return subtle.ConstantTimeCompare(privKey[:], otherEd[:]) == 1 + } + + return false +} + +func (privKey PrivKey) Type() string { + return KeyType +} + +// GenPrivKey generates a new bn254 private key. +// It uses OS randomness in conjunction with the current global random seed +// in cometbft/libs/rand to generate the private key. +func GenPrivKey() PrivKey { + return genPrivKey(crypto.CReader()) +} + +// genPrivKey generates a new bn254 private key using the provided reader. +func genPrivKey(rand io.Reader) PrivKey { + priv, err := ecdsa_bn254.GenerateKey(rand) + if err != nil { + panic(err) + } + + return PrivKey(priv.Bytes()) +} + +//------------------------------------- + +var _ crypto.PubKey = PubKey{} + +// PubKey implements crypto.PubKey for the Bn254 signature scheme. +type PubKey []byte + +// Address is the SHA256-20 of the raw pubkey bytes. +func (pubKey PubKey) Address() crypto.Address { + if len(pubKey) != PubKeySize { + panic("pubkey is incorrect size") + } + return crypto.Address(tmhash.SumTruncated(pubKey)) +} + +// Bytes returns the PubKey byte format. +func (pubKey PubKey) Bytes() []byte { + return []byte(pubKey) +} + +func (pubKey PubKey) VerifySignature(msg []byte, sig []byte) bool { + // make sure we use the same algorithm to sign + if len(sig) != SignatureSize { + return false + } + + pub := new(ecdsa_bn254.PublicKey) + if _, err := pub.SetBytes(pubKey[:]); err != nil { + return false + } + + valid, _ := pub.Verify(msg, sig, sha256.New()) + return valid +} + +func (pubKey PubKey) String() string { + return fmt.Sprintf("PubKeyBn254{%X}", []byte(pubKey)) +} + +func (pubKey PubKey) Type() string { + return KeyType +} + +func (pubKey PubKey) Equals(other crypto.PubKey) bool { + if otherEd, ok := other.(PubKey); ok { + return bytes.Equal(pubKey[:], otherEd[:]) + } + + return false +} diff --git a/signer/cosigner_key.go b/signer/cosigner_key.go index 330e060f..0424e843 100644 --- a/signer/cosigner_key.go +++ b/signer/cosigner_key.go @@ -2,12 +2,15 @@ package signer import ( "encoding/json" + "errors" + "fmt" "os" cometcrypto "github.com/cometbft/cometbft/crypto" cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519" - cometcryptoencoding "github.com/cometbft/cometbft/crypto/encoding" - cometprotocrypto "github.com/cometbft/cometbft/proto/tendermint/crypto" + "github.com/strangelove-ventures/horcrux/signer/bn254" + "github.com/strangelove-ventures/horcrux/signer/encoding" + "github.com/strangelove-ventures/horcrux/signer/proto" "github.com/tendermint/go-amino" ) @@ -22,7 +25,17 @@ type CosignerKey struct { func (key *CosignerKey) MarshalJSON() ([]byte, error) { type Alias CosignerKey - protoPubkey, err := cometcryptoencoding.PubKeyToProto(cometcryptoed25519.PubKey(key.PubKey)) + var pub cometcrypto.PubKey + switch key.KeyType { + case CosignerKeyTypeBn254: + pub = bn254.PubKey(key.PubKey) + case CosignerKeyTypeEd25519: + fallthrough + default: + pub = cometcryptoed25519.PubKey(key.PubKey) + } + + protoPubkey, err := encoding.PubKeyToProto(pub) if err != nil { return nil, err } @@ -55,7 +68,7 @@ func (key *CosignerKey) UnmarshalJSON(data []byte) error { } var pubkey cometcrypto.PubKey - var protoPubkey cometprotocrypto.PublicKey + var protoPubkey proto.PublicKey err := protoPubkey.Unmarshal(aux.PubkeyBytes) // Prior to the tendermint protobuf migration, the public key bytes in key files @@ -65,19 +78,17 @@ func (key *CosignerKey) UnmarshalJSON(data []byte) error { // To support reading the public key bytes from these key files, we fallback to // amino unmarshalling if the protobuf unmarshalling fails if err != nil { - var pub cometcryptoed25519.PubKey codec := amino.NewCodec() codec.RegisterInterface((*cometcrypto.PubKey)(nil), nil) codec.RegisterConcrete(cometcryptoed25519.PubKey{}, "tendermint/PubKeyEd25519", nil) - codec.RegisterConcrete(cometcryptoed25519.PubKey{}, "tendermint/PubKeyBn254", nil) - errInner := codec.UnmarshalBinaryBare(aux.PubkeyBytes, &pub) - if errInner != nil { - return err + var pub cometcryptoed25519.PubKey + if errInner := codec.UnmarshalBinaryBare(aux.PubkeyBytes, &pub); errInner != nil { + return fmt.Errorf("error in unmarshal ed25519: %w", errors.Join(err, errInner)) } pubkey = pub } else { - pubkey, err = cometcryptoencoding.PubKeyFromProto(protoPubkey) + pubkey, err = encoding.PubKeyFromProto(protoPubkey) if err != nil { return err } @@ -88,8 +99,8 @@ func (key *CosignerKey) UnmarshalJSON(data []byte) error { } // LoadCosignerKey loads a CosignerKey from file. -func LoadCosignerKey(file string) (CosignerKey, error) { - pvKey := CosignerKey{} +func LoadCosignerKey(file string) (*CosignerKey, error) { + pvKey := new(CosignerKey) keyJSONBytes, err := os.ReadFile(file) if err != nil { return pvKey, err @@ -97,7 +108,7 @@ func LoadCosignerKey(file string) (CosignerKey, error) { err = json.Unmarshal(keyJSONBytes, &pvKey) if err != nil { - return pvKey, err + return pvKey, fmt.Errorf("error in unmarshal: %w", err) } return pvKey, nil diff --git a/signer/encoding/codec.go b/signer/encoding/codec.go new file mode 100644 index 00000000..ee58cd20 --- /dev/null +++ b/signer/encoding/codec.go @@ -0,0 +1,76 @@ +package encoding + +import ( + "fmt" + + "github.com/cometbft/cometbft/crypto" + "github.com/cometbft/cometbft/crypto/ed25519" + "github.com/cometbft/cometbft/crypto/secp256k1" + "github.com/cometbft/cometbft/libs/json" + "github.com/strangelove-ventures/horcrux/signer/bn254" + "github.com/strangelove-ventures/horcrux/signer/proto" +) + +func init() { + json.RegisterType((*proto.PublicKey_Bn254)(nil), "tendermint.crypto.PublicKey_Bn254") +} + +// PubKeyToProto takes crypto.PubKey and transforms it to a protobuf Pubkey +func PubKeyToProto(k crypto.PubKey) (proto.PublicKey, error) { + var kp proto.PublicKey + switch k := k.(type) { + case ed25519.PubKey: + kp = proto.PublicKey{ + Sum: &proto.PublicKey_Ed25519{ + Ed25519: k, + }, + } + case secp256k1.PubKey: + kp = proto.PublicKey{ + Sum: &proto.PublicKey_Secp256K1{ + Secp256K1: k, + }, + } + case bn254.PubKey: + kp = proto.PublicKey{ + Sum: &proto.PublicKey_Bn254{ + Bn254: k, + }, + } + default: + return kp, fmt.Errorf("toproto: key type %v is not supported", k) + } + return kp, nil +} + +// PubKeyFromProto takes a protobuf Pubkey and transforms it to a crypto.Pubkey +func PubKeyFromProto(k proto.PublicKey) (crypto.PubKey, error) { + switch k := k.Sum.(type) { + case *proto.PublicKey_Ed25519: + if len(k.Ed25519) != ed25519.PubKeySize { + return nil, fmt.Errorf("invalid size for PubKeyEd25519. Got %d, expected %d", + len(k.Ed25519), ed25519.PubKeySize) + } + pk := make(ed25519.PubKey, ed25519.PubKeySize) + copy(pk, k.Ed25519) + return pk, nil + case *proto.PublicKey_Secp256K1: + if len(k.Secp256K1) != secp256k1.PubKeySize { + return nil, fmt.Errorf("invalid size for PubKeySecp256k1. Got %d, expected %d", + len(k.Secp256K1), secp256k1.PubKeySize) + } + pk := make(secp256k1.PubKey, secp256k1.PubKeySize) + copy(pk, k.Secp256K1) + return pk, nil + case *proto.PublicKey_Bn254: + if len(k.Bn254) != bn254.PubKeySize { + return nil, fmt.Errorf("invalid size for PubKeyBn254. Got %d, expected %d", + len(k.Bn254), bn254.PubKeySize) + } + pk := make(bn254.PubKey, bn254.PubKeySize) + copy(pk, k.Bn254) + return pk, nil + default: + return nil, fmt.Errorf("fromproto: key type %v is not supported", k) + } +} diff --git a/signer/local_cosigner_test.go b/signer/local_cosigner_test.go index 7754c772..46c09659 100644 --- a/signer/local_cosigner_test.go +++ b/signer/local_cosigner_test.go @@ -137,7 +137,7 @@ func testLocalCosignerSign(t *testing.T, threshold, total uint8, security []Cosi for i := 0; i < int(total); i++ { id := i + 1 - key := CosignerKey{ + key := &CosignerKey{ PubKey: pubKey.Bytes(), PrivateShard: privShards[i], ID: id, diff --git a/signer/proto/keys.pb.go b/signer/proto/keys.pb.go new file mode 100644 index 00000000..23114779 --- /dev/null +++ b/signer/proto/keys.pb.go @@ -0,0 +1,791 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: tendermint/crypto/keys.proto + +package proto + +import ( + bytes "bytes" + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// PublicKey defines the keys available for use with Validators +type PublicKey struct { + // Types that are valid to be assigned to Sum: + // + // *PublicKey_Ed25519 + // *PublicKey_Secp256K1 + // *PublicKey_Bn254 + Sum isPublicKey_Sum `protobuf_oneof:"sum"` +} + +func (m *PublicKey) Reset() { *m = PublicKey{} } +func (m *PublicKey) String() string { return proto.CompactTextString(m) } +func (*PublicKey) ProtoMessage() {} +func (*PublicKey) Descriptor() ([]byte, []int) { + return fileDescriptor_cb048658b234868c, []int{0} +} +func (m *PublicKey) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PublicKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PublicKey.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *PublicKey) XXX_Merge(src proto.Message) { + xxx_messageInfo_PublicKey.Merge(m, src) +} +func (m *PublicKey) XXX_Size() int { + return m.Size() +} +func (m *PublicKey) XXX_DiscardUnknown() { + xxx_messageInfo_PublicKey.DiscardUnknown(m) +} + +var xxx_messageInfo_PublicKey proto.InternalMessageInfo + +type isPublicKey_Sum interface { + isPublicKey_Sum() + Equal(interface{}) bool + MarshalTo([]byte) (int, error) + Size() int + Compare(interface{}) int +} + +type PublicKey_Ed25519 struct { + Ed25519 []byte `protobuf:"bytes,1,opt,name=ed25519,proto3,oneof" json:"ed25519,omitempty"` +} +type PublicKey_Secp256K1 struct { + Secp256K1 []byte `protobuf:"bytes,2,opt,name=secp256k1,proto3,oneof" json:"secp256k1,omitempty"` +} +type PublicKey_Bn254 struct { + Bn254 []byte `protobuf:"bytes,3,opt,name=bn254,proto3,oneof" json:"bn254,omitempty"` +} + +func (*PublicKey_Ed25519) isPublicKey_Sum() {} +func (*PublicKey_Secp256K1) isPublicKey_Sum() {} +func (*PublicKey_Bn254) isPublicKey_Sum() {} + +func (m *PublicKey) GetSum() isPublicKey_Sum { + if m != nil { + return m.Sum + } + return nil +} + +func (m *PublicKey) GetEd25519() []byte { + if x, ok := m.GetSum().(*PublicKey_Ed25519); ok { + return x.Ed25519 + } + return nil +} + +func (m *PublicKey) GetSecp256K1() []byte { + if x, ok := m.GetSum().(*PublicKey_Secp256K1); ok { + return x.Secp256K1 + } + return nil +} + +func (m *PublicKey) GetBn254() []byte { + if x, ok := m.GetSum().(*PublicKey_Bn254); ok { + return x.Bn254 + } + 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_Bn254)(nil), + } +} + +func init() { + proto.RegisterType((*PublicKey)(nil), "tendermint.crypto.PublicKey") +} + +func init() { proto.RegisterFile("tendermint/crypto/keys.proto", fileDescriptor_cb048658b234868c) } + +var fileDescriptor_cb048658b234868c = []byte{ + // 243 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, 0x01, 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, 0x12, 0x12, 0xe3, 0x62, 0x4d, 0xca, 0x33, 0x32, 0x35, 0x91, 0x60, 0x86, 0xca, 0x41, 0xb8, + 0x56, 0x1c, 0x2f, 0x16, 0xc8, 0x33, 0xbe, 0x58, 0x28, 0xcf, 0xe8, 0xc4, 0xca, 0xc5, 0x5c, 0x5c, + 0x9a, 0xeb, 0xe4, 0x77, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, + 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0x26, 0xe9, + 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xc5, 0x25, 0x45, 0x89, 0x79, 0xe9, + 0xa9, 0x39, 0xf9, 0x65, 0xa9, 0xba, 0x65, 0xa9, 0x79, 0x25, 0xa5, 0x45, 0xa9, 0xc5, 0xfa, 0x19, + 0xf9, 0x45, 0xc9, 0x45, 0xa5, 0x15, 0xfa, 0xc5, 0x99, 0xe9, 0x79, 0xa9, 0x45, 0xfa, 0x60, 0x1f, + 0x24, 0xb1, 0x81, 0x29, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x82, 0xe1, 0xf2, 0x9e, 0x11, + 0x01, 0x00, 0x00, +} + +func (this *PublicKey) Compare(that interface{}) int { + if that == nil { + if this == nil { + return 0 + } + return 1 + } + + that1, ok := that.(*PublicKey) + if !ok { + that2, ok := that.(PublicKey) + if ok { + that1 = &that2 + } else { + return 1 + } + } + if that1 == nil { + if this == nil { + return 0 + } + return 1 + } else if this == nil { + return -1 + } + if that1.Sum == nil { + if this.Sum != nil { + return 1 + } + } else if this.Sum == nil { + return -1 + } else { + thisType := -1 + switch this.Sum.(type) { + case *PublicKey_Ed25519: + thisType = 0 + case *PublicKey_Secp256K1: + thisType = 1 + case *PublicKey_Bn254: + thisType = 2 + default: + panic(fmt.Sprintf("compare: unexpected type %T in oneof", this.Sum)) + } + that1Type := -1 + switch that1.Sum.(type) { + case *PublicKey_Ed25519: + that1Type = 0 + case *PublicKey_Secp256K1: + that1Type = 1 + case *PublicKey_Bn254: + that1Type = 2 + default: + panic(fmt.Sprintf("compare: unexpected type %T in oneof", that1.Sum)) + } + if thisType == that1Type { + if c := this.Sum.Compare(that1.Sum); c != 0 { + return c + } + } else if thisType < that1Type { + return -1 + } else if thisType > that1Type { + return 1 + } + } + return 0 +} +func (this *PublicKey_Ed25519) Compare(that interface{}) int { + if that == nil { + if this == nil { + return 0 + } + return 1 + } + + that1, ok := that.(*PublicKey_Ed25519) + if !ok { + that2, ok := that.(PublicKey_Ed25519) + 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.Ed25519, that1.Ed25519); c != 0 { + return c + } + return 0 +} +func (this *PublicKey_Secp256K1) Compare(that interface{}) int { + if that == nil { + if this == nil { + return 0 + } + return 1 + } + + that1, ok := that.(*PublicKey_Secp256K1) + if !ok { + that2, ok := that.(PublicKey_Secp256K1) + 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.Secp256K1, that1.Secp256K1); c != 0 { + return c + } + return 0 +} +func (this *PublicKey_Bn254) Compare(that interface{}) int { + if that == nil { + if this == nil { + return 0 + } + return 1 + } + + that1, ok := that.(*PublicKey_Bn254) + if !ok { + that2, ok := that.(PublicKey_Bn254) + 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.Bn254, that1.Bn254); c != 0 { + return c + } + return 0 +} +func (this *PublicKey) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*PublicKey) + if !ok { + that2, ok := that.(PublicKey) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if that1.Sum == nil { + if this.Sum != nil { + return false + } + } else if this.Sum == nil { + return false + } else if !this.Sum.Equal(that1.Sum) { + return false + } + return true +} +func (this *PublicKey_Ed25519) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*PublicKey_Ed25519) + if !ok { + that2, ok := that.(PublicKey_Ed25519) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !bytes.Equal(this.Ed25519, that1.Ed25519) { + return false + } + return true +} +func (this *PublicKey_Secp256K1) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*PublicKey_Secp256K1) + if !ok { + that2, ok := that.(PublicKey_Secp256K1) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !bytes.Equal(this.Secp256K1, that1.Secp256K1) { + return false + } + return true +} +func (this *PublicKey_Bn254) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*PublicKey_Bn254) + if !ok { + that2, ok := that.(PublicKey_Bn254) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !bytes.Equal(this.Bn254, that1.Bn254) { + return false + } + return true +} +func (m *PublicKey) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PublicKey) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PublicKey) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Sum != nil { + { + size := m.Sum.Size() + i -= size + if _, err := m.Sum.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + } + } + return len(dAtA) - i, nil +} + +func (m *PublicKey_Ed25519) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PublicKey_Ed25519) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.Ed25519 != nil { + i -= len(m.Ed25519) + copy(dAtA[i:], m.Ed25519) + i = encodeVarintKeys(dAtA, i, uint64(len(m.Ed25519))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} +func (m *PublicKey_Secp256K1) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PublicKey_Secp256K1) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.Secp256K1 != nil { + i -= len(m.Secp256K1) + copy(dAtA[i:], m.Secp256K1) + i = encodeVarintKeys(dAtA, i, uint64(len(m.Secp256K1))) + i-- + dAtA[i] = 0x12 + } + return len(dAtA) - i, nil +} +func (m *PublicKey_Bn254) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PublicKey_Bn254) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.Bn254 != nil { + i -= len(m.Bn254) + copy(dAtA[i:], m.Bn254) + i = encodeVarintKeys(dAtA, i, uint64(len(m.Bn254))) + i-- + dAtA[i] = 0x1a + } + return len(dAtA) - i, nil +} +func encodeVarintKeys(dAtA []byte, offset int, v uint64) int { + offset -= sovKeys(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *PublicKey) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Sum != nil { + n += m.Sum.Size() + } + return n +} + +func (m *PublicKey_Ed25519) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Ed25519 != nil { + l = len(m.Ed25519) + n += 1 + l + sovKeys(uint64(l)) + } + return n +} +func (m *PublicKey_Secp256K1) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Secp256K1 != nil { + l = len(m.Secp256K1) + n += 1 + l + sovKeys(uint64(l)) + } + return n +} +func (m *PublicKey_Bn254) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Bn254 != nil { + l = len(m.Bn254) + n += 1 + l + sovKeys(uint64(l)) + } + return n +} + +func sovKeys(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozKeys(x uint64) (n int) { + return sovKeys(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *PublicKey) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowKeys + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PublicKey: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PublicKey: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Ed25519", 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_Ed25519{v} + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Secp256K1", 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_Secp256K1{v} + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Bn254", 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_Bn254{v} + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipKeys(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthKeys + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipKeys(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowKeys + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowKeys + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowKeys + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthKeys + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupKeys + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthKeys + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthKeys = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowKeys = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupKeys = fmt.Errorf("proto: unexpected end of group") +) diff --git a/signer/single_signer_validator.go b/signer/single_signer_validator.go index ee0d40ff..d5d7703e 100644 --- a/signer/single_signer_validator.go +++ b/signer/single_signer_validator.go @@ -6,6 +6,9 @@ import ( "os" "sync" "time" + + // required to register bn254 types for signing + _ "github.com/strangelove-ventures/horcrux/signer/bn254" ) var _ PrivValidator = &SingleSignerValidator{} diff --git a/signer/threshold_signer_soft_bn254.go b/signer/threshold_signer_soft_bn254.go index c4567096..fd99bee3 100644 --- a/signer/threshold_signer_soft_bn254.go +++ b/signer/threshold_signer_soft_bn254.go @@ -20,7 +20,7 @@ type ThresholdSignerSoftBn254 struct { suite *bn256.Suite } -func NewThresholdSignerSoftBn254(key CosignerKey, threshold, total uint8) (*ThresholdSignerSoftBn254, error) { +func NewThresholdSignerSoftBn254(key *CosignerKey, threshold, total uint8) (*ThresholdSignerSoftBn254, error) { suite := bn256.NewSuite() privateKey := suite.G2().Scalar().SetBytes(key.PrivateShard) pubKey := suite.G2().Point() diff --git a/signer/threshold_signer_soft_ed25519.go b/signer/threshold_signer_soft_ed25519.go index 8191c1dd..b185063d 100644 --- a/signer/threshold_signer_soft_ed25519.go +++ b/signer/threshold_signer_soft_ed25519.go @@ -20,7 +20,7 @@ type ThresholdSignerSoftEd25519 struct { total uint8 } -func NewThresholdSignerSoftEd25519(key CosignerKey, threshold, total uint8) *ThresholdSignerSoftEd25519 { +func NewThresholdSignerSoftEd25519(key *CosignerKey, threshold, total uint8) *ThresholdSignerSoftEd25519 { return &ThresholdSignerSoftEd25519{ privateKeyShard: key.PrivateShard, pubKey: key.PubKey, diff --git a/signer/threshold_validator_test.go b/signer/threshold_validator_test.go index 3371422d..411aa509 100644 --- a/signer/threshold_validator_test.go +++ b/signer/threshold_validator_test.go @@ -68,7 +68,7 @@ func loadKeyForLocalCosigner( chainID string, privateShard []byte, ) error { - key := CosignerKey{ + key := &CosignerKey{ KeyType: keyType, PubKey: pubKey, PrivateShard: privateShard, @@ -351,12 +351,10 @@ func getTestLocalCosigners(t *testing.T, keyType string, threshold, total uint8) pk := pubPoly.Commit() pubKey, err = pk.MarshalBinary() require.NoError(t, err) - fmt.Printf("pubKey: %+v\n", pk) for i, x := range priPoly.Shares(int(total)) { privShards[i], err = x.V.MarshalBinary() require.NoError(t, err) - fmt.Printf("share i: %d, %x\n", x.I, privShards[i]) } } From bd1f4bcc6957ecacac1575b880224a99ca5d9539 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Sun, 17 Dec 2023 22:13:34 -0700 Subject: [PATCH 5/9] pubkey size 128 bytes --- signer/bn254/bn254.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/signer/bn254/bn254.go b/signer/bn254/bn254.go index 7a8e5220..6d3c036e 100644 --- a/signer/bn254/bn254.go +++ b/signer/bn254/bn254.go @@ -23,15 +23,12 @@ const ( PrivKeyName = "tendermint/PrivKeyBn254" PubKeyName = "tendermint/PubKeyBn254" // PubKeySize is is the size, in bytes, of public keys as used in this package. - PubKeySize = 32 + PubKeySize = 128 // PrivateKeySize is the size, in bytes, of private keys as used in this package. PrivateKeySize = 64 // Size of an Bn254 signature. Namely the size of a compressed // Bn254 point, and a field element. Both of which are 32 bytes. SignatureSize = 64 - // SeedSize is the size, in bytes, of private key seeds. These are the - // private key representations used by RFC 8032. - SeedSize = 32 KeyType = "bn254" ) From 778c5f9ce8471690949a80a0b1371b9dcf8af698 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Thu, 21 Dec 2023 16:22:52 -0700 Subject: [PATCH 6/9] use gnark crypto lib --- cmd/horcrux/cmd/shards_test.go | 57 ++++ .../testdata/priv_validator_key-bn254.json | 11 + cmd/horcrux/cmd/testdata/testdata.go | 3 + signer/bn254/bn254.go | 303 ++++++++++++------ signer/bn254/shamir.go | 82 +++++ signer/bn254/threshold.go | 90 ++++++ signer/bn254/threshold_test.go | 74 +++++ signer/cosigner_key_shares.go | 46 +-- signer/proto/keys.pb.go | 2 +- signer/threshold_signer_soft_bn254.go | 131 ++------ signer/threshold_validator_test.go | 20 +- test/validator.go | 9 +- test/validator_single.go | 19 +- test/validator_threshold.go | 7 +- 14 files changed, 602 insertions(+), 252 deletions(-) create mode 100644 cmd/horcrux/cmd/testdata/priv_validator_key-bn254.json create mode 100644 signer/bn254/shamir.go create mode 100644 signer/bn254/threshold.go create mode 100644 signer/bn254/threshold_test.go diff --git a/cmd/horcrux/cmd/shards_test.go b/cmd/horcrux/cmd/shards_test.go index a640376c..05a895fc 100644 --- a/cmd/horcrux/cmd/shards_test.go +++ b/cmd/horcrux/cmd/shards_test.go @@ -6,7 +6,10 @@ import ( "testing" "github.com/cometbft/cometbft/crypto/ed25519" + cometjson "github.com/cometbft/cometbft/libs/json" "github.com/cometbft/cometbft/privval" + "github.com/strangelove-ventures/horcrux/cmd/horcrux/cmd/testdata" + "github.com/strangelove-ventures/horcrux/signer" "github.com/stretchr/testify/require" ) @@ -139,3 +142,57 @@ func TestRSAShards(t *testing.T) { }) } } + +func TestPrivValidatorBn254(t *testing.T) { + bz := testdata.PrivValidatorKeyBn254 + var privvalKey privval.FilePVKey + err := cometjson.Unmarshal(bz, &privvalKey) + require.NoError(t, err) + + msg := []byte("hello") + + sig, err := privvalKey.PrivKey.Sign(msg) + require.NoError(t, err) + + valid := privvalKey.PrivKey.PubKey().VerifySignature(msg, sig) + require.True(t, valid) + + valid = privvalKey.PubKey.VerifySignature(msg, sig) + require.True(t, valid) + + shards, err := signer.CreateCosignerShards(&privvalKey, 2, 3) + require.NoError(t, err) + + var signers = make([]*signer.ThresholdSignerSoftBn254, len(shards)) + var sigs = make([][]byte, len(shards)) + + for i, shard := range shards { + signers[i], err = signer.NewThresholdSignerSoftBn254(&shard, 2, 3) + require.NoError(t, err) + + sig, err = signers[i].Sign(nil, msg) + require.NoError(t, err) + + sigs[i] = sig + } + + var partialSigs = make([]signer.PartialSignature, 0, 2) + for i, sig := range sigs { + if i == 0 { + continue + } + partialSigs = append(partialSigs, signer.PartialSignature{ + ID: i + 1, + Signature: sig, + }) + } + + combinedSig, err := signers[0].CombineSignatures(partialSigs) + require.NoError(t, err) + + valid = privvalKey.PrivKey.PubKey().VerifySignature(msg, combinedSig) + require.True(t, valid) + + valid = privvalKey.PubKey.VerifySignature(msg, combinedSig) + require.True(t, valid) +} diff --git a/cmd/horcrux/cmd/testdata/priv_validator_key-bn254.json b/cmd/horcrux/cmd/testdata/priv_validator_key-bn254.json new file mode 100644 index 00000000..a5031563 --- /dev/null +++ b/cmd/horcrux/cmd/testdata/priv_validator_key-bn254.json @@ -0,0 +1,11 @@ +{ + "address": "092F3E64DF1B43207DCB187747C7E35A0A8C277B", + "pub_key": { + "type": "tendermint/PubKeyBn254", + "value": "jX4uANsjStZrWdWurqaFKXB8AQjoUhd/GiZjeEAB01Y=" + }, + "priv_key": { + "type": "tendermint/PrivKeyBn254", + "value": "0sZKL1ORco5/VXVtoLSaF2QS4TmzZlBgctr1aUfja1gCXu6OqvPob9f2q7XnzSQRCL1gmY1SsYcoImN4iR/HSg==" + } +} \ No newline at end of file diff --git a/cmd/horcrux/cmd/testdata/testdata.go b/cmd/horcrux/cmd/testdata/testdata.go index 11c4380a..aa7f8b64 100644 --- a/cmd/horcrux/cmd/testdata/testdata.go +++ b/cmd/horcrux/cmd/testdata/testdata.go @@ -18,3 +18,6 @@ var CosignerRSAKeyMigrated string //go:embed cosigner-key-v2.json var CosignerKeyV2 []byte + +//go:embed priv_validator_key-bn254.json +var PrivValidatorKeyBn254 []byte diff --git a/signer/bn254/bn254.go b/signer/bn254/bn254.go index 6d3c036e..a8cdc6d1 100644 --- a/signer/bn254/bn254.go +++ b/signer/bn254/bn254.go @@ -2,99 +2,93 @@ package bn254 import ( "bytes" - "crypto/sha256" + "crypto/hmac" + "crypto/rand" "crypto/subtle" "fmt" - "io" + "math/big" - "github.com/cometbft/cometbft/crypto" - "github.com/cometbft/cometbft/crypto/tmhash" - cometjson "github.com/cometbft/cometbft/libs/json" - ecdsa_bn254 "github.com/consensys/gnark-crypto/ecc/bn254/ecdsa" -) + "golang.org/x/crypto/sha3" -//------------------------------------- + "github.com/consensys/gnark-crypto/ecc/bn254" + "github.com/consensys/gnark-crypto/ecc/bn254/ecdsa" + "github.com/consensys/gnark-crypto/ecc/bn254/fp" + "github.com/consensys/gnark-crypto/ecc/bn254/fr" + "github.com/consensys/gnark-crypto/ecc/bn254/fr/mimc" -var ( - _ crypto.PrivKey = PrivKey{} + "github.com/cometbft/cometbft/crypto" + cometjson "github.com/cometbft/cometbft/libs/json" + "github.com/holiman/uint256" ) const ( - PrivKeyName = "tendermint/PrivKeyBn254" - PubKeyName = "tendermint/PubKeyBn254" - // PubKeySize is is the size, in bytes, of public keys as used in this package. - PubKeySize = 128 - // PrivateKeySize is the size, in bytes, of private keys as used in this package. - PrivateKeySize = 64 - // Size of an Bn254 signature. Namely the size of a compressed - // Bn254 point, and a field element. Both of which are 32 bytes. - SignatureSize = 64 - - KeyType = "bn254" + PubKeySize = sizePublicKey + PrivKeySize = sizePrivateKey + sizeFr = fr.Bytes + sizeFp = fp.Bytes + sizePublicKey = sizeFp + sizePrivateKey = sizeFr + sizePublicKey + XHashToScalarFieldPrefix = 0 + YHashToScalarFieldPrefix = 1 + PrivKeyName = "tendermint/PrivKeyBn254" + PubKeyName = "tendermint/PubKeyBn254" + KeyType = "bn254" ) +var G1Gen bn254.G1Affine +var G2Gen bn254.G2Affine +var G2Cofactor big.Int + +var Hash = sha3.NewLegacyKeccak256 + func init() { cometjson.RegisterType(PubKey{}, PubKeyName) cometjson.RegisterType(PrivKey{}, PrivKeyName) + + _, _, G1Gen, G2Gen = bn254.Generators() + + // BN254 cofactor + value, err := new(big.Int).SetString("30644e72e131a029b85045b68181585e06ceecda572a2489345f2299c0f9fa8d", 16) + if !err { + panic("Cannot build cofactor") + } + + G2Cofactor.Set(value) } -// PrivKey implements crypto.PrivKey. +var _ crypto.PrivKey = PrivKey{} + type PrivKey []byte -// Bytes returns the privkey byte format. +func (PrivKey) TypeTag() string { return PrivKeyName } + func (privKey PrivKey) Bytes() []byte { return []byte(privKey) } -// Sign produces a signature on the provided message. -// This assumes the privkey is wellformed in the golang format. -// The first 32 bytes should be random, -// corresponding to the normal bn254 private key. -// The latter 32 bytes should be the compressed public key. -// If these conditions aren't met, Sign will panic or produce an -// incorrect signature. func (privKey PrivKey) Sign(msg []byte) ([]byte, error) { - priv := new(ecdsa_bn254.PrivateKey) - _, err := priv.SetBytes(privKey[:]) - if err != nil { - return nil, err - } - - hFunc := sha256.New() - - return priv.Sign(msg, hFunc) + s := new(big.Int) + s = s.SetBytes(privKey) + hm := HashToG2(msg) + var p bn254.G2Affine + p.ScalarMultiplication(&hm, s) + compressedSig := p.Bytes() + return compressedSig[:], nil } -// PubKey gets the corresponding public key from the private key. -// -// Panics if the private key is not initialized. func (privKey PrivKey) PubKey() crypto.PubKey { - // If the latter 32 bytes of the privkey are all zero, privkey is not - // initialized. - initialized := false - for _, v := range privKey[32:] { - if v != 0 { - initialized = true - break - } - } - - if !initialized { - panic("Expected bn254 PrivKey to include concatenated pubkey bytes") - } - - pubkeyBytes := make([]byte, PubKeySize) - copy(pubkeyBytes, privKey[32:]) - return PubKey(pubkeyBytes) + s := new(big.Int) + s.SetBytes(privKey) + var pk bn254.G1Affine + pk.ScalarMultiplication(&G1Gen, s) + pkBytes := pk.Bytes() + return PubKey(pkBytes[:]) } -// Equals - you probably don't need to use this. -// Runs in constant time based on length of the keys. func (privKey PrivKey) Equals(other crypto.PrivKey) bool { if otherEd, ok := other.(PrivKey); ok { return subtle.ConstantTimeCompare(privKey[:], otherEd[:]) == 1 } - return false } @@ -102,60 +96,52 @@ func (privKey PrivKey) Type() string { return KeyType } -// GenPrivKey generates a new bn254 private key. -// It uses OS randomness in conjunction with the current global random seed -// in cometbft/libs/rand to generate the private key. -func GenPrivKey() PrivKey { - return genPrivKey(crypto.CReader()) -} - -// genPrivKey generates a new bn254 private key using the provided reader. -func genPrivKey(rand io.Reader) PrivKey { - priv, err := ecdsa_bn254.GenerateKey(rand) - if err != nil { - panic(err) - } - - return PrivKey(priv.Bytes()) -} - -//------------------------------------- - var _ crypto.PubKey = PubKey{} -// PubKey implements crypto.PubKey for the Bn254 signature scheme. type PubKey []byte -// Address is the SHA256-20 of the raw pubkey bytes. +func (PubKey) TypeTag() string { return PubKeyName } + func (pubKey PubKey) Address() crypto.Address { - if len(pubKey) != PubKeySize { - panic("pubkey is incorrect size") - } - return crypto.Address(tmhash.SumTruncated(pubKey)) + return crypto.AddressHash(pubKey[:]) } -// Bytes returns the PubKey byte format. func (pubKey PubKey) Bytes() []byte { - return []byte(pubKey) + return pubKey } func (pubKey PubKey) VerifySignature(msg []byte, sig []byte) bool { - // make sure we use the same algorithm to sign - if len(sig) != SignatureSize { + hashedMessage := HashToG2(msg) + var public bn254.G1Affine + _, err := public.SetBytes(pubKey) + if err != nil { + return false + } + if public.IsInfinity() { return false } - pub := new(ecdsa_bn254.PublicKey) - if _, err := pub.SetBytes(pubKey[:]); err != nil { + var signature bn254.G2Affine + _, err = signature.SetBytes(sig) + if err != nil { return false } + if signature.IsInfinity() { + return false + } + + var G1BaseNeg bn254.G1Affine + G1BaseNeg.Neg(&G1Gen) - valid, _ := pub.Verify(msg, sig, sha256.New()) + valid, err := bn254.PairingCheck([]bn254.G1Affine{G1BaseNeg, public}, []bn254.G2Affine{signature, hashedMessage}) + if err != nil { + return false + } return valid } func (pubKey PubKey) String() string { - return fmt.Sprintf("PubKeyBn254{%X}", []byte(pubKey)) + return fmt.Sprintf("PubKeyBn254{%X}", []byte(pubKey[:])) } func (pubKey PubKey) Type() string { @@ -166,6 +152,131 @@ func (pubKey PubKey) Equals(other crypto.PubKey) bool { if otherEd, ok := other.(PubKey); ok { return bytes.Equal(pubKey[:], otherEd[:]) } - return false } + +func GenPrivKey() PrivKey { + secret, err := ecdsa.GenerateKey(rand.Reader) + if err != nil { + panic(err) + } + return PrivKey(secret.Bytes()) +} + +// Naive scalar multiplication used for cofactor clearing, basic double-and-add +func nativeNaiveScalarMul(p bn254.G2Affine, s *big.Int) bn254.G2Affine { + // initialize result point to infinity + var result bn254.G2Affine + result.X.SetZero() + result.Y.SetZero() + bits := s.BitLen() + // iterate over binary digits of s and double the current result point at each iteration + for i := bits - 1; i >= 0; i-- { + result.Add(&result, &result) + // if current binary digit is 1, add the original point p to the result + if s.Bit(i) == 1 { + result.Add(&result, &p) + } + } + return result +} + +func HashToField(msg []byte) fr.Element { + hmac := hmac.New(Hash, []byte("CometBLS")) + hmac.Write(msg) + modMinusOne := new(big.Int).Sub(fr.Modulus(), big.NewInt(1)) + num := new(big.Int).SetBytes(hmac.Sum(nil)) + num.Mod(num, modMinusOne) + num.Add(num, big.NewInt(1)) + val, overflow := uint256.FromBig(num) + if overflow { + panic("impossible; qed;") + } + valBytes := val.Bytes32() + var element fr.Element + err := element.SetBytesCanonical(valBytes[:]) + if err != nil { + panic("impossible; qed;") + } + return element +} + +func HashToField2(msg []byte) (fr.Element, fr.Element) { + x := HashToField(append([]byte{XHashToScalarFieldPrefix}, msg...)) + y := HashToField(append([]byte{YHashToScalarFieldPrefix}, msg...)) + return x, y +} + +func HashToG2(msg []byte) bn254.G2Affine { + x, y := HashToField2(msg) + point := nativeNaiveScalarMul(bn254.MapToCurve2(&bn254.E2{ + A0: *new(fp.Element).SetBigInt(x.BigInt(new(big.Int))), + A1: *new(fp.Element).SetBigInt(y.BigInt(new(big.Int))), + }), &G2Cofactor) + // Any of the following case are impossible and should break consensus + if !point.IsOnCurve() { + panic("Point is not on the curve") + } + if !point.IsInSubGroup() { + panic("Point is not in subgroup") + } + if point.IsInfinity() { + panic("Point is zero") + } + return point +} + +type MerkleLeaf struct { + VotingPower int64 + ShiftedX fr.Element + ShiftedY fr.Element + MsbX uint8 + MsbY uint8 +} + +func NewMerkleLeaf(pubKey bn254.G1Affine, votingPower int64) (MerkleLeaf, error) { + x := pubKey.X.BigInt(new(big.Int)) + y := pubKey.Y.BigInt(new(big.Int)) + msbX := x.Bit(254) + msbY := y.Bit(254) + var frX, frY fr.Element + x.SetBit(x, 254, 0) + var padded [32]byte + x.FillBytes(padded[:]) + err := frX.SetBytesCanonical(padded[:]) + if err != nil { + return MerkleLeaf{}, err + } + y.SetBit(y, 254, 0) + y.FillBytes(padded[:]) + err = frY.SetBytesCanonical(padded[:]) + if err != nil { + return MerkleLeaf{}, err + } + return MerkleLeaf{ + VotingPower: votingPower, + ShiftedX: frX, + ShiftedY: frY, + MsbX: uint8(msbX), + MsbY: uint8(msbY), + }, nil +} + +// mimc(X, Xmsb, Y, Ymsb, power) +func (l MerkleLeaf) Hash() []byte { + frXBytes := l.ShiftedX.Bytes() + frYBytes := l.ShiftedY.Bytes() + mimc := mimc.NewMiMC() + mimc.Write(frXBytes[:]) + mimc.Write(frYBytes[:]) + var padded [32]byte + big.NewInt(int64(l.MsbX)).FillBytes(padded[:]) + mimc.Write(padded[:]) + big.NewInt(int64(l.MsbY)).FillBytes(padded[:]) + mimc.Write(padded[:]) + var powerBytes big.Int + powerBytes.SetUint64(uint64(l.VotingPower)) + powerBytes.FillBytes(padded[:]) + mimc.Write(padded[:]) + return mimc.Sum(nil) +} diff --git a/signer/bn254/shamir.go b/signer/bn254/shamir.go new file mode 100644 index 00000000..78c2e6cf --- /dev/null +++ b/signer/bn254/shamir.go @@ -0,0 +1,82 @@ +package bn254 + +import ( + "crypto/rand" + "math/big" + + "github.com/consensys/gnark-crypto/ecc/bn254/fr" +) + +type Polynomial []*big.Int + +func (p Polynomial) Y(x int) *big.Int { + sum := big.NewInt(0) + for i := 0; i < len(p); i++ { + exp := big.NewInt(int64(i)) + inc := big.NewInt(int64(x)) + inc.Exp(inc, exp, fr.Modulus()) + inc.Mul(inc, p[i]) + sum.Add(sum, inc) + } + sum.Mod(sum, fr.Modulus()) + return sum +} + +type Shards []*big.Int + +func GenFromSecret(secret []byte, threshold uint8, total uint8) (Polynomial, Shards) { + polynomial := make(Polynomial, threshold) + polynomial[0] = new(big.Int) + polynomial[0].SetBytes(secret) + + for i := 1; i < int(threshold); i++ { + bi, err := rand.Int(rand.Reader, fr.Modulus()) + if err != nil { + panic(err) + } + polynomial[i] = bi + } + + shares := make([]*big.Int, total) + for point := 1; point <= int(total); point++ { + shares[point-1] = polynomial.Y(point) + } + + return polynomial, shares +} + +func lagrangeCoeff(point int64, points ...int64) *big.Int { + var prodElements []*big.Int + + for _, j := range points { + if point == j { + continue + } + + iScalar := big.NewInt(point) + jScalar := big.NewInt(j) + + nominator := jScalar // j + + var denominator = new(big.Int) + denominator.Sub(jScalar, iScalar) + denominator.Mod(denominator, fr.Modulus()) + + denominator.ModInverse(denominator, fr.Modulus()) + + division := nominator.Mul(nominator, denominator) + + prodElements = append(prodElements, division) + } + + if len(prodElements) == 0 { + panic("empty lagrange coeff vector") + } + + prod := prodElements[0] + for i := 1; i < len(prodElements); i++ { + prod.Mul(prod, prodElements[i]) + } + + return prod +} diff --git a/signer/bn254/threshold.go b/signer/bn254/threshold.go new file mode 100644 index 00000000..e80d7c72 --- /dev/null +++ b/signer/bn254/threshold.go @@ -0,0 +1,90 @@ +package bn254 + +import ( + "fmt" + "math/big" + + "github.com/consensys/gnark-crypto/ecc/bn254" +) + +var genG2 = new(bn254.G2Affine) +var zeroG1 = new(bn254.G1Affine) +var zeroG2 = new(bn254.G2Affine) + +func init() { + _, _, g1, g2 := bn254.Generators() + g1Bytes254 := g1.Bytes() + g2Bytes254 := g2.Bytes() + + _, _ = genG2.SetBytes(g2Bytes254[:]) + + _, _ = zeroG1.SetBytes(g1Bytes254[:]) + _, _ = zeroG2.SetBytes(g2Bytes254[:]) + + zeroG1.Sub(zeroG1, &G1Gen) + zeroG2.Sub(zeroG2, genG2) +} + +// CombinePublicKeys combines public keys using Lagrange coefficients +func CombinePublicKeys(pks []*bn254.G1Affine, evaluationPoints ...int64) *bn254.G1Affine { + var sum = new(bn254.G1Affine) + zeroG1Bz := zeroG1.Bytes() + sum.SetBytes(zeroG1Bz[:]) + + for i := 0; i < len(evaluationPoints); i++ { + var inc = new(bn254.G1Affine) + inc.ScalarMultiplication(pks[evaluationPoints[i]-1], lagrangeCoeff(evaluationPoints[i], evaluationPoints...)) + sum.Add(sum, inc) + } + + return sum +} + +// CombineSignatures combines signatures using Lagrange coefficients +func CombineSignatures(signatures []*bn254.G2Affine, evaluationPoints ...int64) *bn254.G2Affine { + var sum = new(bn254.G2Affine) + zeroG2Bz := zeroG2.Bytes() + sum.SetBytes(zeroG2Bz[:]) + + var signatureIndex int + for _, evaluationPoint := range evaluationPoints { + var inc = new(bn254.G2Affine) + inc.ScalarMultiplication(signatures[signatureIndex], lagrangeCoeff(evaluationPoint, evaluationPoints...)) + sum.Add(sum, inc) + signatureIndex++ + } + + return sum +} + +// SignWithShard signs a digest with a bn254 private key +func SignWithShard(sk *big.Int, digest []byte) (*bn254.G2Affine, error) { + g2 := HashToG2(digest) + g2.ScalarMultiplication(&g2, sk) + + return &g2, nil +} + +// VerifyShardSignature verifies a bn254 signature against a digest and a public key +func VerifyShardSignature(pk *bn254.G1Affine, digest []byte, sig *bn254.G2Affine) error { + digestOnG2 := HashToG2(digest) + + var g1Neg bn254.G1Affine + g1Neg.Neg(&G1Gen) + + shouldBeOne, err := bn254.MillerLoop([]bn254.G1Affine{g1Neg, *pk}, []bn254.G2Affine{*sig, digestOnG2}) + if err != nil { + return fmt.Errorf("failed MillerLoop: %w", err) + } + + shouldBeOne = bn254.FinalExponentiation(&shouldBeOne) + + unity := bn254.GT{} + unity.SetOne() + + if unity.Equal(&shouldBeOne) { + return nil + } + + return fmt.Errorf("signature mismatch") +} diff --git a/signer/bn254/threshold_test.go b/signer/bn254/threshold_test.go new file mode 100644 index 00000000..f1f0b149 --- /dev/null +++ b/signer/bn254/threshold_test.go @@ -0,0 +1,74 @@ +package bn254_test + +import ( + "math/big" + "testing" + + "github.com/consensys/gnark-crypto/ecc/bn254" + horcrux_bn254 "github.com/strangelove-ventures/horcrux/signer/bn254" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "golang.org/x/crypto/sha3" +) + +func TestBn254(t *testing.T) { + skInt := int64(2) + + var pk bn254.G1Affine + pk.ScalarMultiplication(&horcrux_bn254.G1Gen, big.NewInt(skInt)) + + msg := []byte("payload to sign") + + digest := sha3.NewLegacyKeccak256().Sum(msg) + + hash, err := bn254.HashToG2(digest, nil) + require.NoError(t, err) + + var sig bn254.G2Affine + _ = sig.ScalarMultiplication(&hash, big.NewInt(skInt)) + + left, err := bn254.MillerLoop([]bn254.G1Affine{horcrux_bn254.G1Gen}, []bn254.G2Affine{sig}) + require.NoError(t, err) + + left = bn254.FinalExponentiation(&left) + + right, err := bn254.MillerLoop([]bn254.G1Affine{pk}, []bn254.G2Affine{hash}) + require.NoError(t, err) + + right = bn254.FinalExponentiation(&right) + + assert.True(t, left.Equal(&right)) +} + +func TestThresholdBn254(t *testing.T) { + secret := horcrux_bn254.GenPrivKey() + secretBz := secret.Bytes() + + pubKey := secret.PubKey() + + _, shards := horcrux_bn254.GenFromSecret(secretBz, 2, 3) + + msg := []byte("payload to sign") + + digest := sha3.NewLegacyKeccak256().Sum(msg) + + var signatures []*bn254.G2Affine + for _, shard := range shards { + signature, err := horcrux_bn254.SignWithShard(shard, digest[:]) + require.NoError(t, err) + + var pubKey bn254.G1Affine + pubKey.ScalarMultiplication(&horcrux_bn254.G1Gen, shard) + + err = horcrux_bn254.VerifyShardSignature(&pubKey, digest[:], signature) + require.NoError(t, err) + + signatures = append(signatures, signature) + } + + thresholdSignature := horcrux_bn254.CombineSignatures(signatures[:2], 1, 2) + thresholdSignatureBz := thresholdSignature.Bytes() + + valid := pubKey.VerifySignature(digest[:], thresholdSignatureBz[:]) + require.True(t, valid) +} diff --git a/signer/cosigner_key_shares.go b/signer/cosigner_key_shares.go index 05fe3498..fe8d4ba6 100644 --- a/signer/cosigner_key_shares.go +++ b/signer/cosigner_key_shares.go @@ -7,11 +7,14 @@ import ( "errors" "os" + cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519" + cometjson "github.com/cometbft/cometbft/libs/json" + "github.com/cometbft/cometbft/privval" "github.com/ethereum/go-ethereum/crypto/ecies" "github.com/ethereum/go-ethereum/crypto/secp256k1" + "github.com/strangelove-ventures/horcrux/signer/bn254" + horcrux_bn254 "github.com/strangelove-ventures/horcrux/signer/bn254" tsed25519 "gitlab.com/unit410/threshold-ed25519/pkg" - "go.dedis.ch/kyber/v3/pairing/bn256" - "go.dedis.ch/kyber/v3/share" "golang.org/x/sync/errgroup" ) @@ -24,10 +27,15 @@ func CreateCosignerShardsFromFile(priv string, threshold, shards uint8) ([]Cosig return nil, err } - switch pv.PrivKey.Type { - case "tendermint/PrivKeyEd25519": + return CreateCosignerShards(pv, threshold, shards) +} + +// CreateCosignerShards creates CosignerKey objects from a privval.FilePVKey +func CreateCosignerShards(pv *privval.FilePVKey, threshold, shards uint8) ([]CosignerKey, error) { + switch pv.PrivKey.(type) { + case cometcryptoed25519.PrivKey: return CreateCosignerEd25519Shards(pv, threshold, shards), nil - case "tendermint/PrivKeyBn254": + case bn254.PrivKey: return CreateCosignerBn254Shards(pv, threshold, shards), nil default: return nil, ErrUnsupportedKeyType @@ -35,13 +43,13 @@ func CreateCosignerShardsFromFile(priv string, threshold, shards uint8) ([]Cosig } // CreateCosignerEd25519Shards creates CosignerKey objects from a privval.FilePVKey -func CreateCosignerEd25519Shards(pv *TMPrivvalFile, threshold, shards uint8) []CosignerKey { - privShards := tsed25519.DealShares(tsed25519.ExpandSecret(pv.PrivKey.Value[:32]), threshold, shards) +func CreateCosignerEd25519Shards(pv *privval.FilePVKey, threshold, shards uint8) []CosignerKey { + privShards := tsed25519.DealShares(tsed25519.ExpandSecret(pv.PrivKey.(cometcryptoed25519.PrivKey).Bytes()[:32]), threshold, shards) out := make([]CosignerKey, shards) for i, shard := range privShards { out[i] = CosignerKey{ KeyType: CosignerKeyTypeEd25519, - PubKey: pv.PubKey.Value, + PubKey: pv.PubKey.Bytes(), PrivateShard: shard, ID: i + 1, } @@ -50,22 +58,16 @@ func CreateCosignerEd25519Shards(pv *TMPrivvalFile, threshold, shards uint8) []C } // CreateCosignerEd25519Shards creates CosignerKey objects from a privval.FilePVKey -func CreateCosignerBn254Shards(pv *TMPrivvalFile, threshold, shards uint8) []CosignerKey { - suite := bn256.NewSuite() - secret := suite.G1().Scalar().SetBytes(pv.PrivKey.Value) - priPoly := share.NewPriPoly(suite.G2(), int(threshold), secret, suite.RandomStream()) - privShards := priPoly.Shares(int(shards)) +func CreateCosignerBn254Shards(pv *privval.FilePVKey, threshold, shards uint8) []CosignerKey { + _, privShards := horcrux_bn254.GenFromSecret(pv.PrivKey.Bytes(), threshold, shards) + //pks := horcrux_bn254.CreatePublicKeys(privShards) out := make([]CosignerKey, shards) for i, shard := range privShards { - v, err := shard.V.MarshalBinary() - if err != nil { - panic(err) - } out[i] = CosignerKey{ KeyType: CosignerKeyTypeBn254, - PubKey: pv.PubKey.Value, - PrivateShard: v, + PubKey: pv.PubKey.Bytes(), + PrivateShard: shard.Bytes(), ID: i + 1, } } @@ -102,15 +104,15 @@ type TMPrivvalFile struct { } // ReadPrivValidatorFile reads in a privval.FilePVKey from a given file. -func ReadPrivValidatorFile(priv string) (*TMPrivvalFile, error) { +func ReadPrivValidatorFile(priv string) (*privval.FilePVKey, error) { bz, err := os.ReadFile(priv) if err != nil { return nil, err } - var out TMPrivvalFile + var out privval.FilePVKey - if err := json.Unmarshal(bz, &out); err != nil { + if err := cometjson.Unmarshal(bz, &out); err != nil { return nil, err } diff --git a/signer/proto/keys.pb.go b/signer/proto/keys.pb.go index 23114779..03815c29 100644 --- a/signer/proto/keys.pb.go +++ b/signer/proto/keys.pb.go @@ -127,7 +127,7 @@ func (*PublicKey) XXX_OneofWrappers() []interface{} { } func init() { - proto.RegisterType((*PublicKey)(nil), "tendermint.crypto.PublicKey") + // proto.RegisterType((*PublicKey)(nil), "tendermint.crypto.PublicKey") } func init() { proto.RegisterFile("tendermint/crypto/keys.proto", fileDescriptor_cb048658b234868c) } diff --git a/signer/threshold_signer_soft_bn254.go b/signer/threshold_signer_soft_bn254.go index fd99bee3..199346d7 100644 --- a/signer/threshold_signer_soft_bn254.go +++ b/signer/threshold_signer_soft_bn254.go @@ -1,133 +1,68 @@ package signer import ( - "fmt" + "math/big" - "go.dedis.ch/kyber/v3" - "go.dedis.ch/kyber/v3/pairing/bn256" - "go.dedis.ch/kyber/v3/share" - "go.dedis.ch/kyber/v3/sign/bls" //nolint:staticcheck + "github.com/consensys/gnark-crypto/ecc/bn254" + horcrux_bn254 "github.com/strangelove-ventures/horcrux/signer/bn254" ) var _ ThresholdSigner = &ThresholdSignerSoftBn254{} type ThresholdSignerSoftBn254 struct { - privateKey kyber.Scalar - pubKey kyber.Point + privateKey *big.Int + pubKey []byte threshold uint8 total uint8 - - suite *bn256.Suite } func NewThresholdSignerSoftBn254(key *CosignerKey, threshold, total uint8) (*ThresholdSignerSoftBn254, error) { - suite := bn256.NewSuite() - privateKey := suite.G2().Scalar().SetBytes(key.PrivateShard) - pubKey := suite.G2().Point() - if err := pubKey.UnmarshalBinary(key.PubKey); err != nil { - return nil, err - } + privateKey := new(big.Int) + privateKey = privateKey.SetBytes(key.PrivateShard) return &ThresholdSignerSoftBn254{ privateKey: privateKey, - pubKey: pubKey, + pubKey: key.PubKey, threshold: threshold, total: total, - suite: suite, }, nil } func (s *ThresholdSignerSoftBn254) PubKey() []byte { - pub, err := s.pubKey.MarshalBinary() + return s.pubKey +} + +func (s *ThresholdSignerSoftBn254) Sign(_ []Nonce, msg []byte) ([]byte, error) { + sig, err := horcrux_bn254.SignWithShard(s.privateKey, msg) if err != nil { - panic(err) + return nil, err } - return pub -} -func (s *ThresholdSignerSoftBn254) Sign(_ []Nonce, payload []byte) ([]byte, error) { - // nonceShare, noncePub, err := s.sumNonces(nonces) - // if err != nil { - // return nil, fmt.Errorf("failed to combine nonces: %w", err) - // } + compressed := sig.Bytes() - return bls.Sign(s.suite, s.privateKey, payload) + return compressed[:], nil } -// func (s *ThresholdSignerSoftBn254) sumNonces(nonces []Nonce) (tsed25519.Scalar, tsed25519.Element, error) { -// shareParts := make([]tsed25519.Scalar, len(nonces)) -// publicKeys := make([]tsed25519.Element, len(nonces)) - -// for i, n := range nonces { -// shareParts[i] = n.Share -// publicKeys[i] = n.PubKey -// } - -// nonceShare := tsed25519.AddScalars(shareParts) -// noncePub := tsed25519.AddElements(publicKeys) - -// // check bounds for ephemeral share to avoid passing out of bounds valids to SignWithShare -// if len(nonceShare) != 32 { -// return nil, nil, errors.New("ephemeral share is out of bounds") -// } - -// var scalarBytes [32]byte -// copy(scalarBytes[:], nonceShare) -// if !edwards25519.ScMinimal(&scalarBytes) { -// return nil, nil, errors.New("ephemeral share is out of bounds") -// } - -// return nonceShare, noncePub, nil -// } - -// func GenerateNoncesBn254(threshold, total uint8) (Nonces, error) { -// secret := make([]byte, 32) -// if _, err := rand.Read(secret); err != nil { -// return Nonces{}, err -// } - -// nonces := Nonces{ -// PubKey: tsed25519.ScalarMultiplyBase(secret), -// Shares: make([][]byte, total), -// } - -// shares := tsed25519.DealShares(secret, threshold, total) - -// for i, sh := range shares { -// nonces.Shares[i] = sh -// } - -// return nonces, nil -// } - func (s *ThresholdSignerSoftBn254) CombineSignatures(signatures []PartialSignature) ([]byte, error) { - pubShares := make([]*share.PubShare, 0) - for _, sig := range signatures { - i := sig.ID - 1 - - point := s.suite.G1().Point() - if err := point.UnmarshalBinary(sig.Signature); err != nil { + var sigs = make([]*bn254.G2Affine, len(signatures)) + var points = make([]int64, len(signatures)) + for i, s := range signatures { + sig := new(bn254.G2Affine) + _, err := sig.SetBytes(s.Signature) + if err != nil { return nil, err } - pubShares = append(pubShares, &share.PubShare{I: i, V: point}) - if len(pubShares) >= int(s.threshold) { - break - } - } - commit, err := share.RecoverCommit(s.suite.G1(), pubShares, int(s.threshold), int(s.total)) - if err != nil { - return nil, err - } - sig, err := commit.MarshalBinary() - if err != nil { - return nil, err + + sigs[i] = sig + points[i] = int64(s.ID) } - return sig, nil + + combinedSig := horcrux_bn254.CombineSignatures(sigs, points...) + + compressed := combinedSig.Bytes() + + return compressed[:], nil } -func (s *ThresholdSignerSoftBn254) VerifySignature(payload, signature []byte) bool { - if err := bls.Verify(s.suite, s.pubKey, payload, signature); err != nil { - fmt.Printf("Failed to verify signature: %v\n", err) - return false - } - return true +func (s *ThresholdSignerSoftBn254) VerifySignature(msg, signature []byte) bool { + return horcrux_bn254.PubKey(s.pubKey).VerifySignature(msg, signature) } diff --git a/signer/threshold_validator_test.go b/signer/threshold_validator_test.go index 411aa509..c18ea405 100644 --- a/signer/threshold_validator_test.go +++ b/signer/threshold_validator_test.go @@ -22,10 +22,9 @@ import ( comet "github.com/cometbft/cometbft/types" "github.com/ethereum/go-ethereum/crypto/ecies" "github.com/ethereum/go-ethereum/crypto/secp256k1" + horcrux_bn254 "github.com/strangelove-ventures/horcrux/signer/bn254" "github.com/stretchr/testify/require" tsed25519 "gitlab.com/unit410/threshold-ed25519/pkg" - "go.dedis.ch/kyber/v3/pairing/bn256" - "go.dedis.ch/kyber/v3/share" "golang.org/x/sync/errgroup" ) @@ -343,19 +342,14 @@ func getTestLocalCosigners(t *testing.T, keyType string, threshold, total uint8) } pubKey = privateKey.PubKey().Bytes() case CosignerKeyTypeBn254: - suite := bn256.NewSuite() - secret := suite.G1().Scalar().Pick(suite.RandomStream()) - priPoly := share.NewPriPoly(suite.G2(), int(threshold), secret, suite.RandomStream()) - pubPoly := priPoly.Commit(suite.G2().Point().Base()) - var err error - pk := pubPoly.Commit() - pubKey, err = pk.MarshalBinary() - require.NoError(t, err) + privateKey := horcrux_bn254.GenPrivKey() + _, privShardsBn254 := horcrux_bn254.GenFromSecret(privateKey.Bytes(), threshold, total) - for i, x := range priPoly.Shares(int(total)) { - privShards[i], err = x.V.MarshalBinary() - require.NoError(t, err) + for i := range privShardsBn254 { + privShards[i] = privShardsBn254[i].Bytes() } + + pubKey = privateKey.PubKey().Bytes() } tmpDir := t.TempDir() diff --git a/test/validator.go b/test/validator.go index cc8a40ab..bcbd8b81 100644 --- a/test/validator.go +++ b/test/validator.go @@ -9,10 +9,11 @@ import ( "time" cometbytes "github.com/cometbft/cometbft/libs/bytes" + cometjson "github.com/cometbft/cometbft/libs/json" + "github.com/cometbft/cometbft/privval" "github.com/cosmos/cosmos-sdk/types/bech32" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/docker/docker/client" - "github.com/strangelove-ventures/horcrux/v3/signer" "github.com/strangelove-ventures/horcrux/v3/signer/proto" interchaintest "github.com/strangelove-ventures/interchaintest/v8" "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" @@ -174,14 +175,14 @@ func horcruxProxySidecar(ctx context.Context, node *cosmos.ChainNode, name strin } // getPrivvalKey reads the priv_validator_key.json file from the given node. -func getPrivvalKey(ctx context.Context, node *cosmos.ChainNode) (*signer.TMPrivvalFile, error) { +func getPrivvalKey(ctx context.Context, node *cosmos.ChainNode) (*privval.FilePVKey, error) { keyBz, err := node.ReadFile(ctx, "config/priv_validator_key.json") if err != nil { return nil, fmt.Errorf("failed to read priv_validator_key.json: %w", err) } - var pvKey signer.TMPrivvalFile - if err := json.Unmarshal(keyBz, &pvKey); err != nil { + var pvKey privval.FilePVKey + if err := cometjson.Unmarshal(keyBz, &pvKey); err != nil { return nil, fmt.Errorf("failed to unmarshal priv validator key: %w", err) } diff --git a/test/validator_single.go b/test/validator_single.go index 9cf1f6d0..4b7c4b15 100644 --- a/test/validator_single.go +++ b/test/validator_single.go @@ -3,12 +3,10 @@ package test import ( "context" "crypto/sha256" - "encoding/hex" "encoding/json" "fmt" "testing" - cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519" cometjson "github.com/cometbft/cometbft/libs/json" "github.com/cometbft/cometbft/privval" "github.com/docker/docker/client" @@ -78,7 +76,7 @@ func preGenesisSingleNodeAndHorcruxSingle( return err } - *pubKey = pvKey.PubKey.Value + *pubKey = pvKey.PubKey.Bytes() sentries := append(cosmos.ChainNodes{horcruxValidator}, cw.chain.FullNodes...) @@ -122,7 +120,7 @@ func writeConfigAndKeysSingle( chainID string, singleSigner *cosmos.SidecarProcess, config signer.Config, - key *signer.TMPrivvalFile, + key *privval.FilePVKey, ) error { configBz, err := json.Marshal(config) if err != nil { @@ -133,18 +131,7 @@ func writeConfigAndKeysSingle( return fmt.Errorf("failed to write config.yaml: %w", err) } - address, err := hex.DecodeString(key.Address) - if err != nil { - return fmt.Errorf("failed to decode address: %w", err) - } - - pvKey := privval.FilePVKey{ - Address: address, - PubKey: cometcryptoed25519.PubKey(key.PubKey.Value), - PrivKey: cometcryptoed25519.PrivKey(key.PrivKey.Value), - } - - pvKeyBz, err := cometjson.Marshal(pvKey) + pvKeyBz, err := cometjson.Marshal(key) if err != nil { return fmt.Errorf("failed to marshal priv validator key: %w", err) } diff --git a/test/validator_threshold.go b/test/validator_threshold.go index 2200c427..eb243760 100644 --- a/test/validator_threshold.go +++ b/test/validator_threshold.go @@ -259,9 +259,12 @@ func getShardedPrivvalKey(ctx context.Context, node *cosmos.ChainNode, threshold return nil, nil, err } - ed25519Shards := signer.CreateCosignerEd25519Shards(pvKey, threshold, shards) + privShards, err := signer.CreateCosignerShards(pvKey, threshold, shards) + if err != nil { + return nil, nil, err + } - return ed25519Shards, pvKey.PubKey.Value, nil + return privShards, pvKey.PubKey.Bytes(), nil } // chainEd25519Shard is a wrapper for a chain ID and a shard of an ed25519 consensus key. From 40daed9af440b6dc25c1e67fa233c177e00c88c5 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Thu, 21 Dec 2023 16:29:13 -0700 Subject: [PATCH 7/9] lint --- .golangci.yml | 2 ++ cmd/horcrux/cmd/shards_test.go | 1 + signer/bn254/shamir.go | 2 +- signer/bn254/threshold.go | 8 ++++++-- signer/bn254/threshold_test.go | 12 ++++++------ signer/cosigner_key.go | 6 +++--- signer/cosigner_key_shares.go | 9 +++++---- signer/encoding/codec.go | 4 ++-- 8 files changed, 26 insertions(+), 18 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 266d1de4..7e17e593 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -101,6 +101,8 @@ linters-settings: alias: mrand - pkg: github.com/consensys/gnark-crypto/ecc/bn254/ecdsa alias: ecdsa_bn254 + - pkg: github.com/strangelove-ventures/horcrux/signer/bn254 + alias: horcrux_bn254 maligned: suggest-new: true govet: diff --git a/cmd/horcrux/cmd/shards_test.go b/cmd/horcrux/cmd/shards_test.go index 05a895fc..e5ccc88c 100644 --- a/cmd/horcrux/cmd/shards_test.go +++ b/cmd/horcrux/cmd/shards_test.go @@ -167,6 +167,7 @@ func TestPrivValidatorBn254(t *testing.T) { var sigs = make([][]byte, len(shards)) for i, shard := range shards { + shard := shard signers[i], err = signer.NewThresholdSignerSoftBn254(&shard, 2, 3) require.NoError(t, err) diff --git a/signer/bn254/shamir.go b/signer/bn254/shamir.go index 78c2e6cf..e81c206d 100644 --- a/signer/bn254/shamir.go +++ b/signer/bn254/shamir.go @@ -46,7 +46,7 @@ func GenFromSecret(secret []byte, threshold uint8, total uint8) (Polynomial, Sha } func lagrangeCoeff(point int64, points ...int64) *big.Int { - var prodElements []*big.Int + var prodElements []*big.Int //nolint:prealloc for _, j := range points { if point == j { diff --git a/signer/bn254/threshold.go b/signer/bn254/threshold.go index e80d7c72..695495af 100644 --- a/signer/bn254/threshold.go +++ b/signer/bn254/threshold.go @@ -29,7 +29,9 @@ func init() { func CombinePublicKeys(pks []*bn254.G1Affine, evaluationPoints ...int64) *bn254.G1Affine { var sum = new(bn254.G1Affine) zeroG1Bz := zeroG1.Bytes() - sum.SetBytes(zeroG1Bz[:]) + if _, err := sum.SetBytes(zeroG1Bz[:]); err != nil { + panic(err) + } for i := 0; i < len(evaluationPoints); i++ { var inc = new(bn254.G1Affine) @@ -44,7 +46,9 @@ func CombinePublicKeys(pks []*bn254.G1Affine, evaluationPoints ...int64) *bn254. func CombineSignatures(signatures []*bn254.G2Affine, evaluationPoints ...int64) *bn254.G2Affine { var sum = new(bn254.G2Affine) zeroG2Bz := zeroG2.Bytes() - sum.SetBytes(zeroG2Bz[:]) + if _, err := sum.SetBytes(zeroG2Bz[:]); err != nil { + panic(err) + } var signatureIndex int for _, evaluationPoint := range evaluationPoints { diff --git a/signer/bn254/threshold_test.go b/signer/bn254/threshold_test.go index f1f0b149..d9b3af82 100644 --- a/signer/bn254/threshold_test.go +++ b/signer/bn254/threshold_test.go @@ -52,23 +52,23 @@ func TestThresholdBn254(t *testing.T) { digest := sha3.NewLegacyKeccak256().Sum(msg) - var signatures []*bn254.G2Affine - for _, shard := range shards { - signature, err := horcrux_bn254.SignWithShard(shard, digest[:]) + signatures := make([]*bn254.G2Affine, len(shards)) + for i, shard := range shards { + signature, err := horcrux_bn254.SignWithShard(shard, digest) require.NoError(t, err) var pubKey bn254.G1Affine pubKey.ScalarMultiplication(&horcrux_bn254.G1Gen, shard) - err = horcrux_bn254.VerifyShardSignature(&pubKey, digest[:], signature) + err = horcrux_bn254.VerifyShardSignature(&pubKey, digest, signature) require.NoError(t, err) - signatures = append(signatures, signature) + signatures[i] = signature } thresholdSignature := horcrux_bn254.CombineSignatures(signatures[:2], 1, 2) thresholdSignatureBz := thresholdSignature.Bytes() - valid := pubKey.VerifySignature(digest[:], thresholdSignatureBz[:]) + valid := pubKey.VerifySignature(digest, thresholdSignatureBz[:]) require.True(t, valid) } diff --git a/signer/cosigner_key.go b/signer/cosigner_key.go index 0424e843..62371f0f 100644 --- a/signer/cosigner_key.go +++ b/signer/cosigner_key.go @@ -8,9 +8,9 @@ import ( cometcrypto "github.com/cometbft/cometbft/crypto" cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519" - "github.com/strangelove-ventures/horcrux/signer/bn254" - "github.com/strangelove-ventures/horcrux/signer/encoding" - "github.com/strangelove-ventures/horcrux/signer/proto" + "github.com/strangelove-ventures/horcrux/v3/signer/bn254" + "github.com/strangelove-ventures/horcrux/v3/signer/encoding" + "github.com/strangelove-ventures/horcrux/v3/signer/proto" "github.com/tendermint/go-amino" ) diff --git a/signer/cosigner_key_shares.go b/signer/cosigner_key_shares.go index fe8d4ba6..3efadc0e 100644 --- a/signer/cosigner_key_shares.go +++ b/signer/cosigner_key_shares.go @@ -12,7 +12,6 @@ import ( "github.com/cometbft/cometbft/privval" "github.com/ethereum/go-ethereum/crypto/ecies" "github.com/ethereum/go-ethereum/crypto/secp256k1" - "github.com/strangelove-ventures/horcrux/signer/bn254" horcrux_bn254 "github.com/strangelove-ventures/horcrux/signer/bn254" tsed25519 "gitlab.com/unit410/threshold-ed25519/pkg" "golang.org/x/sync/errgroup" @@ -35,7 +34,7 @@ func CreateCosignerShards(pv *privval.FilePVKey, threshold, shards uint8) ([]Cos switch pv.PrivKey.(type) { case cometcryptoed25519.PrivKey: return CreateCosignerEd25519Shards(pv, threshold, shards), nil - case bn254.PrivKey: + case horcrux_bn254.PrivKey: return CreateCosignerBn254Shards(pv, threshold, shards), nil default: return nil, ErrUnsupportedKeyType @@ -44,7 +43,10 @@ func CreateCosignerShards(pv *privval.FilePVKey, threshold, shards uint8) ([]Cos // CreateCosignerEd25519Shards creates CosignerKey objects from a privval.FilePVKey func CreateCosignerEd25519Shards(pv *privval.FilePVKey, threshold, shards uint8) []CosignerKey { - privShards := tsed25519.DealShares(tsed25519.ExpandSecret(pv.PrivKey.(cometcryptoed25519.PrivKey).Bytes()[:32]), threshold, shards) + privShards := tsed25519.DealShares( + tsed25519.ExpandSecret(pv.PrivKey.(cometcryptoed25519.PrivKey).Bytes()[:32]), + threshold, shards, + ) out := make([]CosignerKey, shards) for i, shard := range privShards { out[i] = CosignerKey{ @@ -60,7 +62,6 @@ func CreateCosignerEd25519Shards(pv *privval.FilePVKey, threshold, shards uint8) // CreateCosignerEd25519Shards creates CosignerKey objects from a privval.FilePVKey func CreateCosignerBn254Shards(pv *privval.FilePVKey, threshold, shards uint8) []CosignerKey { _, privShards := horcrux_bn254.GenFromSecret(pv.PrivKey.Bytes(), threshold, shards) - //pks := horcrux_bn254.CreatePublicKeys(privShards) out := make([]CosignerKey, shards) for i, shard := range privShards { diff --git a/signer/encoding/codec.go b/signer/encoding/codec.go index ee58cd20..bdee34c6 100644 --- a/signer/encoding/codec.go +++ b/signer/encoding/codec.go @@ -7,8 +7,8 @@ import ( "github.com/cometbft/cometbft/crypto/ed25519" "github.com/cometbft/cometbft/crypto/secp256k1" "github.com/cometbft/cometbft/libs/json" - "github.com/strangelove-ventures/horcrux/signer/bn254" - "github.com/strangelove-ventures/horcrux/signer/proto" + "github.com/strangelove-ventures/horcrux/v3/signer/bn254" + "github.com/strangelove-ventures/horcrux/v3/signer/proto" ) func init() { From 5c32f1fe6db3d3efa2967ab98f2b0c8c39b0cee2 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Thu, 21 Dec 2023 16:39:36 -0700 Subject: [PATCH 8/9] regen protos --- .golangci.yml | 2 +- cmd/horcrux/cmd/shards_test.go | 2 +- proto/tendermint/crypto/keys.proto | 2 +- scripts/protocgen.sh | 2 +- signer/bn254/threshold_test.go | 2 +- signer/cosigner_key_shares.go | 2 +- signer/proto/cosigner.pb.go | 96 +++++++++++++-------------- signer/proto/keys.pb.go | 12 ++-- signer/proto/remote_signer.pb.go | 12 ++-- signer/single_signer_validator.go | 2 +- signer/threshold_signer_soft_bn254.go | 2 +- signer/threshold_validator_test.go | 2 +- 12 files changed, 69 insertions(+), 69 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 7e17e593..6043d6e8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -101,7 +101,7 @@ linters-settings: alias: mrand - pkg: github.com/consensys/gnark-crypto/ecc/bn254/ecdsa alias: ecdsa_bn254 - - pkg: github.com/strangelove-ventures/horcrux/signer/bn254 + - pkg: github.com/strangelove-ventures/horcrux/v3/signer/bn254 alias: horcrux_bn254 maligned: suggest-new: true diff --git a/cmd/horcrux/cmd/shards_test.go b/cmd/horcrux/cmd/shards_test.go index e5ccc88c..848b16b9 100644 --- a/cmd/horcrux/cmd/shards_test.go +++ b/cmd/horcrux/cmd/shards_test.go @@ -9,7 +9,7 @@ import ( cometjson "github.com/cometbft/cometbft/libs/json" "github.com/cometbft/cometbft/privval" "github.com/strangelove-ventures/horcrux/cmd/horcrux/cmd/testdata" - "github.com/strangelove-ventures/horcrux/signer" + "github.com/strangelove-ventures/horcrux/v3/signer" "github.com/stretchr/testify/require" ) diff --git a/proto/tendermint/crypto/keys.proto b/proto/tendermint/crypto/keys.proto index 75efddbc..e5959ee4 100644 --- a/proto/tendermint/crypto/keys.proto +++ b/proto/tendermint/crypto/keys.proto @@ -1,7 +1,7 @@ syntax = "proto3"; package tendermint.crypto; -option go_package = "github.com/strangelove-ventures/horcrux/signer/proto"; +option go_package = "github.com/strangelove-ventures/horcrux/v3/signer/proto"; import "gogoproto/gogo.proto"; diff --git a/scripts/protocgen.sh b/scripts/protocgen.sh index c0fb5985..6e0428d0 100644 --- a/scripts/protocgen.sh +++ b/scripts/protocgen.sh @@ -11,5 +11,5 @@ for dir in $proto_dirs; do done done -cp -r github.com/strangelove-ventures/horcrux/signer ./ +cp -r github.com/strangelove-ventures/horcrux/v3/signer ./ rm -rf github.com diff --git a/signer/bn254/threshold_test.go b/signer/bn254/threshold_test.go index d9b3af82..fc00a1f5 100644 --- a/signer/bn254/threshold_test.go +++ b/signer/bn254/threshold_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/consensys/gnark-crypto/ecc/bn254" - horcrux_bn254 "github.com/strangelove-ventures/horcrux/signer/bn254" + horcrux_bn254 "github.com/strangelove-ventures/horcrux/v3/signer/bn254" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "golang.org/x/crypto/sha3" diff --git a/signer/cosigner_key_shares.go b/signer/cosigner_key_shares.go index 3efadc0e..adbce5b2 100644 --- a/signer/cosigner_key_shares.go +++ b/signer/cosigner_key_shares.go @@ -12,7 +12,7 @@ import ( "github.com/cometbft/cometbft/privval" "github.com/ethereum/go-ethereum/crypto/ecies" "github.com/ethereum/go-ethereum/crypto/secp256k1" - horcrux_bn254 "github.com/strangelove-ventures/horcrux/signer/bn254" + horcrux_bn254 "github.com/strangelove-ventures/horcrux/v3/signer/bn254" tsed25519 "gitlab.com/unit410/threshold-ed25519/pkg" "golang.org/x/sync/errgroup" ) diff --git a/signer/proto/cosigner.pb.go b/signer/proto/cosigner.pb.go index ff9bf4d6..1195a78f 100644 --- a/signer/proto/cosigner.pb.go +++ b/signer/proto/cosigner.pb.go @@ -899,54 +899,54 @@ func init() { } var fileDescriptor_b7a1f695b94b848a = []byte{ - // 744 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x56, 0xdf, 0x4f, 0xd3, 0x50, - 0x14, 0x5e, 0xb7, 0x76, 0xb2, 0x33, 0x30, 0x70, 0x25, 0x58, 0x1a, 0xb3, 0xcc, 0x1b, 0x35, 0x4b, - 0x94, 0xcd, 0x4c, 0xa3, 0xcf, 0x20, 0x89, 0x12, 0x14, 0x49, 0x07, 0x2f, 0x86, 0x90, 0x74, 0xdd, - 0x65, 0x6d, 0x1c, 0xed, 0xb8, 0xf7, 0x16, 0xe1, 0x0f, 0xf0, 0xdd, 0x17, 0xff, 0x27, 0x1e, 0x79, - 0xf4, 0x4d, 0x03, 0xff, 0x88, 0xb9, 0xb7, 0xb7, 0x65, 0x2d, 0x1d, 0xf0, 0xc0, 0xd3, 0x7a, 0x4e, - 0xcf, 0x8f, 0xef, 0xfb, 0xf6, 0xdd, 0x9b, 0x02, 0x66, 0x9c, 0x3a, 0xc1, 0x90, 0x8c, 0xc2, 0x63, - 0xd2, 0xf1, 0x42, 0xea, 0xd2, 0xe8, 0xa4, 0xe3, 0x86, 0xcc, 0x1f, 0x06, 0x84, 0xb6, 0xc7, 0x34, - 0xe4, 0x21, 0x7a, 0x34, 0x51, 0xd3, 0x56, 0x35, 0xf8, 0xa7, 0x06, 0xc6, 0xda, 0x28, 0x74, 0xbf, - 0xa3, 0x25, 0xa8, 0x7a, 0xc4, 0x1f, 0x7a, 0xdc, 0xd4, 0x9a, 0x5a, 0xab, 0x62, 0xab, 0x08, 0x2d, - 0x82, 0x41, 0xc3, 0x28, 0x18, 0x98, 0x65, 0x99, 0x8e, 0x03, 0x84, 0x40, 0x67, 0x9c, 0x8c, 0xcd, - 0x4a, 0x53, 0x6b, 0x19, 0xb6, 0x7c, 0x46, 0x4f, 0xa0, 0x26, 0x16, 0xae, 0x9d, 0x72, 0xc2, 0x4c, - 0xbd, 0xa9, 0xb5, 0x66, 0xed, 0xab, 0x84, 0x78, 0xcb, 0xfd, 0x43, 0xc2, 0xb8, 0x73, 0x38, 0x36, - 0x0d, 0x39, 0xeb, 0x2a, 0x81, 0xf7, 0x61, 0xbe, 0x27, 0x4a, 0x05, 0x14, 0x9b, 0x1c, 0x45, 0x84, - 0x71, 0x64, 0xc2, 0x03, 0xd7, 0x73, 0xfc, 0x60, 0x63, 0x5d, 0x42, 0xaa, 0xd9, 0x49, 0x88, 0x5e, - 0x83, 0xd1, 0x17, 0x95, 0x12, 0x53, 0xbd, 0x6b, 0xb5, 0x0b, 0xa8, 0xb5, 0xe3, 0x59, 0x71, 0x21, - 0xfe, 0x0a, 0x0b, 0x13, 0xf3, 0xd9, 0x38, 0x0c, 0x18, 0x49, 0x00, 0x3b, 0x3c, 0xa2, 0x44, 0xae, - 0x50, 0x80, 0x65, 0x22, 0x0b, 0xb8, 0x9c, 0x07, 0xfc, 0x5b, 0x03, 0x63, 0x2b, 0x0c, 0x5c, 0x82, - 0x2c, 0x98, 0x61, 0x61, 0x44, 0x5d, 0xa2, 0x70, 0x1a, 0x76, 0x1a, 0xa3, 0x67, 0x30, 0x37, 0x20, - 0x8c, 0xfb, 0x81, 0xc3, 0xfd, 0x50, 0x10, 0x29, 0xcb, 0x82, 0x6c, 0x52, 0x48, 0x3f, 0x8e, 0xfa, - 0x9b, 0xe4, 0x54, 0xca, 0x39, 0x6b, 0xab, 0x48, 0x48, 0xcf, 0x3c, 0x87, 0x12, 0x25, 0x66, 0x1c, - 0x64, 0x51, 0x1b, 0x39, 0xd4, 0xb8, 0x07, 0xb5, 0xdd, 0xdd, 0x8d, 0xf5, 0x18, 0x1a, 0x02, 0x3d, - 0x8a, 0xfc, 0x81, 0xe2, 0x26, 0x9f, 0x51, 0x17, 0xaa, 0x81, 0x78, 0xc9, 0xcc, 0x72, 0xb3, 0x32, - 0x55, 0x3c, 0xd9, 0x6f, 0xab, 0x4a, 0x7c, 0x00, 0xfa, 0x27, 0xbb, 0xb7, 0x73, 0x3f, 0x1e, 0xb9, - 0x12, 0x55, 0xcf, 0x8b, 0x7a, 0xa6, 0xc1, 0xe3, 0x1e, 0xe1, 0x72, 0x39, 0x5b, 0x0d, 0x06, 0xe2, - 0x2f, 0x4b, 0xdc, 0x70, 0x4f, 0x5c, 0xd0, 0x0a, 0xe8, 0x1e, 0x65, 0x5c, 0xa2, 0xaa, 0x77, 0x97, - 0x0b, 0x3b, 0x04, 0x59, 0x5b, 0x96, 0xdd, 0x62, 0xea, 0x09, 0x8b, 0x1a, 0x19, 0x8b, 0xe2, 0x13, - 0x30, 0xaf, 0x33, 0x51, 0xbe, 0x6b, 0x42, 0x5d, 0x82, 0xd9, 0x8e, 0xfa, 0x23, 0xdf, 0x55, 0x8c, - 0x26, 0x53, 0x37, 0x7b, 0x2f, 0xeb, 0x80, 0x4a, 0xde, 0x01, 0x2d, 0x98, 0xff, 0x98, 0x6c, 0x4e, - 0xc4, 0x5b, 0x04, 0x43, 0x08, 0xc6, 0x4c, 0xad, 0x59, 0x11, 0x4e, 0x92, 0x01, 0xde, 0x84, 0x85, - 0x89, 0x4a, 0x05, 0xee, 0x5d, 0xaa, 0xa9, 0x26, 0x35, 0x6d, 0x14, 0x2a, 0x94, 0x7a, 0x2c, 0xf5, - 0xc8, 0x7b, 0x58, 0xde, 0xa1, 0x4e, 0xc0, 0x0e, 0x08, 0xfd, 0x4c, 0x9c, 0x01, 0xa1, 0xcc, 0xf3, - 0xc7, 0xc9, 0x7e, 0x0b, 0x66, 0x46, 0x32, 0x99, 0x9e, 0xe5, 0x34, 0xc6, 0xfb, 0x60, 0x15, 0x35, - 0x2a, 0x38, 0x37, 0x74, 0x8a, 0xd3, 0x15, 0x3f, 0xaf, 0x0e, 0x06, 0x94, 0x30, 0x26, 0x95, 0xaa, - 0xd9, 0xd9, 0x24, 0x46, 0x52, 0x8f, 0x78, 0xb4, 0xc2, 0x83, 0x5f, 0x4a, 0xe6, 0x49, 0x4e, 0xad, - 0x5a, 0x82, 0x6a, 0xdc, 0xa9, 0x8e, 0xb1, 0x8a, 0xf0, 0x1c, 0xd4, 0xb7, 0xfd, 0x60, 0x98, 0xf4, - 0x3e, 0x84, 0xd9, 0x38, 0x8c, 0xdb, 0xba, 0x7f, 0x75, 0x98, 0xf9, 0xa0, 0xae, 0x5a, 0xb4, 0x07, - 0xb5, 0xf4, 0x9e, 0x41, 0xcf, 0x0b, 0xa5, 0xcb, 0xdf, 0x73, 0xd6, 0x8b, 0xdb, 0xca, 0xe2, 0x45, - 0xb8, 0x84, 0x8e, 0x60, 0x3e, 0x6f, 0x2a, 0xf4, 0xaa, 0xb8, 0xbb, 0xf8, 0x14, 0x59, 0x2b, 0x77, - 0xac, 0x4e, 0x57, 0xee, 0x41, 0x2d, 0xf5, 0xc8, 0x14, 0x42, 0x79, 0xb7, 0x4d, 0x21, 0x74, 0xcd, - 0x6a, 0xb8, 0x84, 0x7e, 0x00, 0xba, 0xfe, 0xdf, 0xa3, 0x76, 0x61, 0xff, 0x54, 0x77, 0x59, 0x9d, - 0x3b, 0xd7, 0xe7, 0x68, 0xc5, 0xaf, 0xa6, 0xd3, 0xca, 0x98, 0x66, 0x3a, 0xad, 0xac, 0x8f, 0x70, - 0x09, 0x7d, 0x01, 0x5d, 0x58, 0x04, 0x35, 0x0b, 0x3b, 0x26, 0xcc, 0x64, 0x3d, 0xbd, 0xa1, 0x22, - 0x19, 0xb7, 0xb6, 0x75, 0x76, 0xd1, 0xd0, 0xce, 0x2f, 0x1a, 0xda, 0xbf, 0x8b, 0x86, 0xf6, 0xeb, - 0xb2, 0x51, 0x3a, 0xbf, 0x6c, 0x94, 0xfe, 0x5c, 0x36, 0x4a, 0xdf, 0xde, 0x0e, 0x7d, 0xee, 0x45, - 0xfd, 0xb6, 0x1b, 0x1e, 0x76, 0x26, 0x06, 0xad, 0x1c, 0x93, 0x40, 0xdc, 0x05, 0x2c, 0xfd, 0x16, - 0x88, 0xed, 0xd9, 0x91, 0x5f, 0x02, 0xfd, 0xaa, 0xfc, 0x79, 0xf3, 0x3f, 0x00, 0x00, 0xff, 0xff, - 0x97, 0xd9, 0x62, 0x0b, 0x36, 0x08, 0x00, 0x00, + // 748 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x56, 0xcd, 0x4e, 0xdb, 0x4c, + 0x14, 0x8d, 0x13, 0x3b, 0x1f, 0xb9, 0x81, 0x4f, 0x30, 0x45, 0xd4, 0x58, 0x55, 0x94, 0x8e, 0xda, + 0x2a, 0x52, 0x4b, 0x52, 0x05, 0xa9, 0xac, 0xa1, 0x48, 0x2d, 0xa2, 0x3f, 0xd4, 0x81, 0x4d, 0x85, + 0x90, 0x1c, 0x67, 0x88, 0xad, 0x06, 0x3b, 0xcc, 0x8c, 0x29, 0x3c, 0x40, 0xf7, 0xdd, 0xf4, 0x9d, + 0x58, 0xb2, 0xec, 0xae, 0x15, 0xbc, 0x48, 0x35, 0xe3, 0xb1, 0x89, 0x8d, 0x03, 0x2c, 0x58, 0xc5, + 0xf7, 0xfa, 0xfe, 0x9c, 0x73, 0x72, 0x66, 0x64, 0xc0, 0x8c, 0x53, 0x27, 0x18, 0x92, 0x51, 0x78, + 0x42, 0x3a, 0x5e, 0x48, 0x5d, 0x1a, 0x9d, 0x76, 0xdc, 0x90, 0xf9, 0xc3, 0x80, 0xd0, 0xf6, 0x98, + 0x86, 0x3c, 0x44, 0x8f, 0x26, 0x6a, 0xda, 0xaa, 0x06, 0xff, 0xd0, 0xc0, 0xd8, 0x18, 0x85, 0xee, + 0x37, 0xb4, 0x04, 0x55, 0x8f, 0xf8, 0x43, 0x8f, 0x9b, 0x5a, 0x53, 0x6b, 0x55, 0x6c, 0x15, 0xa1, + 0x45, 0x30, 0x68, 0x18, 0x05, 0x03, 0xb3, 0x2c, 0xd3, 0x71, 0x80, 0x10, 0xe8, 0x8c, 0x93, 0xb1, + 0x59, 0x69, 0x6a, 0x2d, 0xc3, 0x96, 0xcf, 0xe8, 0x09, 0xd4, 0xc4, 0xc2, 0x8d, 0x33, 0x4e, 0x98, + 0xa9, 0x37, 0xb5, 0xd6, 0xac, 0x7d, 0x9d, 0x10, 0x6f, 0xb9, 0x7f, 0x44, 0x18, 0x77, 0x8e, 0xc6, + 0xa6, 0x21, 0x67, 0x5d, 0x27, 0xf0, 0x01, 0xcc, 0xf7, 0x44, 0xa9, 0x80, 0x62, 0x93, 0xe3, 0x88, + 0x30, 0x8e, 0x4c, 0xf8, 0xcf, 0xf5, 0x1c, 0x3f, 0xd8, 0xda, 0x94, 0x90, 0x6a, 0x76, 0x12, 0xa2, + 0xd7, 0x60, 0xf4, 0x45, 0xa5, 0xc4, 0x54, 0xef, 0x5a, 0xed, 0x02, 0x6a, 0xed, 0x78, 0x56, 0x5c, + 0x88, 0x3f, 0xc3, 0xc2, 0xc4, 0x7c, 0x36, 0x0e, 0x03, 0x46, 0x12, 0xc0, 0x0e, 0x8f, 0x28, 0x91, + 0x2b, 0x14, 0x60, 0x99, 0xc8, 0x02, 0x2e, 0xe7, 0x01, 0xff, 0xd2, 0xc0, 0xf8, 0x14, 0x06, 0x2e, + 0x41, 0x16, 0xcc, 0xb0, 0x30, 0xa2, 0x2e, 0x51, 0x38, 0x0d, 0x3b, 0x8d, 0xd1, 0x33, 0x98, 0x1b, + 0x10, 0xc6, 0xfd, 0xc0, 0xe1, 0x7e, 0x28, 0x88, 0x94, 0x65, 0x41, 0x36, 0x29, 0xa4, 0x1f, 0x47, + 0xfd, 0x6d, 0x72, 0x26, 0xe5, 0x9c, 0xb5, 0x55, 0x24, 0xa4, 0x67, 0x9e, 0x43, 0x89, 0x12, 0x33, + 0x0e, 0xb2, 0xa8, 0x8d, 0x1c, 0x6a, 0xdc, 0x83, 0xda, 0xde, 0xde, 0xd6, 0x66, 0x0c, 0x0d, 0x81, + 0x1e, 0x45, 0xfe, 0x40, 0x71, 0x93, 0xcf, 0xa8, 0x0b, 0xd5, 0x40, 0xbc, 0x64, 0x66, 0xb9, 0x59, + 0x99, 0x2a, 0x9e, 0xec, 0xb7, 0x55, 0x25, 0x3e, 0x04, 0xfd, 0xbd, 0xdd, 0xdb, 0x7d, 0x18, 0x8f, + 0x5c, 0x8b, 0xaa, 0xe7, 0x45, 0x3d, 0xd7, 0xe0, 0x71, 0x8f, 0x70, 0xb9, 0x9c, 0xad, 0x07, 0x03, + 0xf1, 0x97, 0x25, 0x6e, 0x78, 0x20, 0x2e, 0x68, 0x05, 0x74, 0x8f, 0x32, 0x2e, 0x51, 0xd5, 0xbb, + 0xcb, 0x85, 0x1d, 0x82, 0xac, 0x2d, 0xcb, 0xee, 0x30, 0xf5, 0x84, 0x45, 0x8d, 0x8c, 0x45, 0xf1, + 0x29, 0x98, 0x37, 0x99, 0x28, 0xdf, 0x35, 0xa1, 0x2e, 0xc1, 0xec, 0x44, 0xfd, 0x91, 0xef, 0x2a, + 0x46, 0x93, 0xa9, 0xdb, 0xbd, 0x97, 0x75, 0x40, 0x25, 0xef, 0x80, 0x16, 0xcc, 0xbf, 0x4b, 0x36, + 0x27, 0xe2, 0x2d, 0x82, 0x21, 0x04, 0x63, 0xa6, 0xd6, 0xac, 0x08, 0x27, 0xc9, 0x00, 0x6f, 0xc3, + 0xc2, 0x44, 0xa5, 0x02, 0xf7, 0x26, 0xd5, 0x54, 0x93, 0x9a, 0x36, 0x0a, 0x15, 0x4a, 0x3d, 0x96, + 0x7a, 0x64, 0x0d, 0x96, 0x77, 0xa9, 0x13, 0xb0, 0x43, 0x42, 0x3f, 0x10, 0x67, 0x40, 0x28, 0xf3, + 0xfc, 0x71, 0xb2, 0xdf, 0x82, 0x99, 0x91, 0x4c, 0xa6, 0x67, 0x39, 0x8d, 0xf1, 0x01, 0x58, 0x45, + 0x8d, 0x0a, 0xce, 0x2d, 0x9d, 0xe2, 0x74, 0xc5, 0xcf, 0xeb, 0x83, 0x01, 0x25, 0x8c, 0x49, 0xa5, + 0x6a, 0x76, 0x36, 0x89, 0x91, 0xd4, 0x23, 0x1e, 0xad, 0xf0, 0xe0, 0x97, 0x92, 0x79, 0x92, 0x53, + 0xab, 0x96, 0xa0, 0x1a, 0x77, 0xaa, 0x63, 0xac, 0x22, 0x3c, 0x07, 0xf5, 0x1d, 0x3f, 0x18, 0x26, + 0xbd, 0xff, 0xc3, 0x6c, 0x1c, 0xc6, 0x6d, 0xdd, 0x3f, 0x3a, 0xcc, 0xbc, 0x55, 0x57, 0x2d, 0xda, + 0x87, 0x5a, 0x7a, 0xcf, 0xa0, 0xe7, 0x85, 0xd2, 0xe5, 0xef, 0x39, 0xeb, 0xc5, 0x5d, 0x65, 0xf1, + 0x22, 0x5c, 0x42, 0xc7, 0x30, 0x9f, 0x37, 0x15, 0x7a, 0x55, 0xdc, 0x5d, 0x7c, 0x8a, 0xac, 0x95, + 0x7b, 0x56, 0xa7, 0x2b, 0xf7, 0xa1, 0x96, 0x7a, 0x64, 0x0a, 0xa1, 0xbc, 0xdb, 0xa6, 0x10, 0xba, + 0x61, 0x35, 0x5c, 0x42, 0xdf, 0x01, 0xdd, 0xfc, 0xef, 0x51, 0xbb, 0xb0, 0x7f, 0xaa, 0xbb, 0xac, + 0xce, 0xbd, 0xeb, 0x73, 0xb4, 0xe2, 0x57, 0xd3, 0x69, 0x65, 0x4c, 0x33, 0x9d, 0x56, 0xd6, 0x47, + 0xb8, 0x84, 0x3e, 0x82, 0x2e, 0x2c, 0x82, 0x9a, 0x85, 0x1d, 0x13, 0x66, 0xb2, 0x9e, 0xde, 0x52, + 0x91, 0x8c, 0xdb, 0xf8, 0x72, 0x7e, 0xd9, 0xd0, 0x2e, 0x2e, 0x1b, 0xda, 0xdf, 0xcb, 0x86, 0xf6, + 0xf3, 0xaa, 0x51, 0xba, 0xb8, 0x6a, 0x94, 0x7e, 0x5f, 0x35, 0x4a, 0x5f, 0xd7, 0x86, 0x3e, 0xf7, + 0xa2, 0x7e, 0xdb, 0x0d, 0x8f, 0x3a, 0x13, 0x83, 0x56, 0x4e, 0x48, 0x20, 0xee, 0x02, 0x96, 0x7e, + 0x0b, 0x9c, 0xac, 0x76, 0x62, 0x87, 0x76, 0xe4, 0xc7, 0x40, 0xbf, 0x2a, 0x7f, 0x56, 0xff, 0x05, + 0x00, 0x00, 0xff, 0xff, 0x44, 0xff, 0xfe, 0xd7, 0x39, 0x08, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/signer/proto/keys.pb.go b/signer/proto/keys.pb.go index 03815c29..49a5785e 100644 --- a/signer/proto/keys.pb.go +++ b/signer/proto/keys.pb.go @@ -133,7 +133,7 @@ func init() { func init() { proto.RegisterFile("tendermint/crypto/keys.proto", fileDescriptor_cb048658b234868c) } var fileDescriptor_cb048658b234868c = []byte{ - // 243 bytes of a gzipped FileDescriptorProto + // 246 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, @@ -143,13 +143,13 @@ var fileDescriptor_cb048658b234868c = []byte{ 0x8e, 0x8b, 0xb3, 0x38, 0x35, 0xb9, 0xc0, 0xc8, 0xd4, 0x2c, 0xdb, 0x50, 0x82, 0x09, 0x2a, 0x8b, 0x10, 0x12, 0x12, 0xe3, 0x62, 0x4d, 0xca, 0x33, 0x32, 0x35, 0x91, 0x60, 0x86, 0xca, 0x41, 0xb8, 0x56, 0x1c, 0x2f, 0x16, 0xc8, 0x33, 0xbe, 0x58, 0x28, 0xcf, 0xe8, 0xc4, 0xca, 0xc5, 0x5c, 0x5c, - 0x9a, 0xeb, 0xe4, 0x77, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, - 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0x26, 0xe9, + 0x9a, 0xeb, 0x14, 0x78, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, + 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0xe6, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xc5, 0x25, 0x45, 0x89, 0x79, 0xe9, 0xa9, 0x39, 0xf9, 0x65, 0xa9, 0xba, 0x65, 0xa9, 0x79, 0x25, 0xa5, 0x45, 0xa9, 0xc5, 0xfa, 0x19, - 0xf9, 0x45, 0xc9, 0x45, 0xa5, 0x15, 0xfa, 0xc5, 0x99, 0xe9, 0x79, 0xa9, 0x45, 0xfa, 0x60, 0x1f, - 0x24, 0xb1, 0x81, 0x29, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x82, 0xe1, 0xf2, 0x9e, 0x11, - 0x01, 0x00, 0x00, + 0xf9, 0x45, 0xc9, 0x45, 0xa5, 0x15, 0xfa, 0x65, 0xc6, 0xfa, 0xc5, 0x99, 0xe9, 0x79, 0xa9, 0x45, + 0xfa, 0x60, 0x4f, 0x24, 0xb1, 0x81, 0x29, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf5, 0xb1, + 0x83, 0x2a, 0x14, 0x01, 0x00, 0x00, } func (this *PublicKey) Compare(that interface{}) int { diff --git a/signer/proto/remote_signer.pb.go b/signer/proto/remote_signer.pb.go index 810048ae..325f3619 100644 --- a/signer/proto/remote_signer.pb.go +++ b/signer/proto/remote_signer.pb.go @@ -125,7 +125,7 @@ func init() { } var fileDescriptor_afd7664cd19b584a = []byte{ - // 276 bytes of a gzipped FileDescriptorProto + // 279 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x2f, 0x2e, 0x29, 0x4a, 0xcc, 0x4b, 0x4f, 0xcd, 0xc9, 0x2f, 0x4b, 0xd5, 0xcf, 0xc8, 0x2f, 0x4a, 0x2e, 0x2a, 0xad, 0xd0, 0x2f, 0x4a, 0xcd, 0xcd, 0x2f, 0x49, 0x8d, 0x2f, 0xce, 0x4c, 0xcf, 0x4b, 0x2d, 0xd2, 0x2b, 0x28, @@ -138,12 +138,12 @@ var fileDescriptor_afd7664cd19b584a = []byte{ 0x10, 0xd8, 0x9d, 0xc1, 0x60, 0xdb, 0x84, 0x82, 0xb9, 0xd8, 0x20, 0x7a, 0x85, 0x94, 0xf4, 0xb0, 0xb8, 0x55, 0x0f, 0xc5, 0x11, 0x52, 0xca, 0x78, 0xd5, 0x40, 0x2c, 0x57, 0x62, 0x10, 0x0a, 0xe7, 0x62, 0x01, 0x19, 0x2f, 0xa4, 0x8a, 0x55, 0x39, 0x48, 0xca, 0x29, 0x27, 0x3f, 0x39, 0x1b, 0x66, - 0xaa, 0x1a, 0x21, 0x65, 0x30, 0x83, 0x9d, 0xfc, 0x4e, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, + 0xaa, 0x1a, 0x21, 0x65, 0x30, 0x83, 0x9d, 0x02, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, - 0x8e, 0x21, 0xca, 0x24, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x1f, 0xc9, - 0x34, 0xdd, 0xb2, 0xd4, 0xbc, 0x92, 0xd2, 0xa2, 0xd4, 0x62, 0x78, 0x38, 0x43, 0x42, 0x59, 0x1f, - 0x1c, 0xca, 0x49, 0x6c, 0x60, 0xca, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x12, 0x7a, 0x1d, 0xbd, - 0xd0, 0x01, 0x00, 0x00, + 0x8e, 0x21, 0xca, 0x3c, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x1f, 0xc9, + 0x34, 0xdd, 0xb2, 0xd4, 0xbc, 0x92, 0xd2, 0xa2, 0xd4, 0x62, 0x78, 0x38, 0x97, 0x19, 0xeb, 0x43, + 0x02, 0x5a, 0x1f, 0x1c, 0xd0, 0x49, 0x6c, 0x60, 0xca, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x1e, + 0xa5, 0x90, 0x75, 0xd3, 0x01, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/signer/single_signer_validator.go b/signer/single_signer_validator.go index d5d7703e..8c2ee22a 100644 --- a/signer/single_signer_validator.go +++ b/signer/single_signer_validator.go @@ -8,7 +8,7 @@ import ( "time" // required to register bn254 types for signing - _ "github.com/strangelove-ventures/horcrux/signer/bn254" + _ "github.com/strangelove-ventures/horcrux/v3/signer/bn254" ) var _ PrivValidator = &SingleSignerValidator{} diff --git a/signer/threshold_signer_soft_bn254.go b/signer/threshold_signer_soft_bn254.go index 199346d7..b51193ed 100644 --- a/signer/threshold_signer_soft_bn254.go +++ b/signer/threshold_signer_soft_bn254.go @@ -4,7 +4,7 @@ import ( "math/big" "github.com/consensys/gnark-crypto/ecc/bn254" - horcrux_bn254 "github.com/strangelove-ventures/horcrux/signer/bn254" + horcrux_bn254 "github.com/strangelove-ventures/horcrux/v3/signer/bn254" ) var _ ThresholdSigner = &ThresholdSignerSoftBn254{} diff --git a/signer/threshold_validator_test.go b/signer/threshold_validator_test.go index c18ea405..4546b9d4 100644 --- a/signer/threshold_validator_test.go +++ b/signer/threshold_validator_test.go @@ -22,7 +22,7 @@ import ( comet "github.com/cometbft/cometbft/types" "github.com/ethereum/go-ethereum/crypto/ecies" "github.com/ethereum/go-ethereum/crypto/secp256k1" - horcrux_bn254 "github.com/strangelove-ventures/horcrux/signer/bn254" + horcrux_bn254 "github.com/strangelove-ventures/horcrux/v3/signer/bn254" "github.com/stretchr/testify/require" tsed25519 "gitlab.com/unit410/threshold-ed25519/pkg" "golang.org/x/sync/errgroup" From 791b5f9f7a9b5594f0327242c5872ab09502b9f6 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Fri, 22 Dec 2023 01:02:03 -0700 Subject: [PATCH 9/9] remove comet as dependency --- .golangci.yml | 55 +- cmd/horcrux/cmd/address.go | 7 +- cmd/horcrux/cmd/leader_election.go | 12 +- cmd/horcrux/cmd/metrics.go | 9 +- cmd/horcrux/cmd/migrate.go | 10 +- cmd/horcrux/cmd/shards_test.go | 8 +- cmd/horcrux/cmd/start.go | 34 +- cmd/horcrux/cmd/state.go | 27 +- cmd/horcrux/cmd/state_test.go | 6 +- cmd/horcrux/cmd/threshold.go | 28 +- cmd/horcrux/cmd/version.go | 2 - {signer => comet/crypto}/bn254/bn254.go | 6 +- comet/crypto/crypto.go | 27 + comet/crypto/ed25519/ed25519.go | 192 ++ comet/encoding/codec.go | 61 + comet/libs/async/async.go | 184 ++ comet/libs/async/async_test.go | 160 + comet/libs/json/decoder.go | 278 ++ comet/libs/json/encoder.go | 254 ++ comet/libs/json/structs.go | 87 + comet/libs/json/types.go | 107 + comet/libs/net/net.go | 43 + comet/libs/net/net_test.go | 38 + comet/libs/protoio/io.go | 99 + comet/libs/protoio/io_test.go | 181 ++ comet/libs/protoio/reader.go | 106 + comet/libs/protoio/writer.go | 100 + comet/libs/tempfile/tempfile.go | 128 + comet/p2p/conn/secret_connection.go | 462 +++ {signer => comet/privval}/file.go | 32 +- .../proto => comet/proto/crypto}/keys.pb.go | 16 +- comet/proto/p2p/conn.pb.go | 1272 ++++++++ comet/proto/privval/privval.pb.go | 2804 +++++++++++++++++ comet/proto/types/canonical.pb.go | 1661 ++++++++++ comet/proto/types/types.pb.go | 1650 ++++++++++ comet/types/block.go | 70 + comet/types/canonical.go | 85 + comet/types/part_set.go | 38 + comet/types/proposal.go | 24 + comet/types/vote.go | 24 + go.mod | 18 +- go.sum | 28 - .../proto => grpc/cosigner}/cosigner.pb.go | 96 +- .../horcrux}/remote_signer.pb.go | 25 +- proto/strangelove/horcrux/cosigner.proto | 2 +- proto/strangelove/horcrux/remote_signer.proto | 2 +- proto/tendermint/crypto/keys.proto | 2 +- proto/tendermint/p2p/conn.proto | 30 + proto/tendermint/privval/privval.proto | 76 + proto/tendermint/types/canonical.proto | 46 + proto/tendermint/types/types.proto | 68 + scripts/protocgen.sh | 2 +- signer/bn254/threshold.go | 9 +- signer/bn254/threshold_test.go | 20 +- signer/cosigner.go | 26 +- signer/cosigner_grpc_server.go | 49 +- signer/cosigner_health.go | 10 +- signer/cosigner_health_test.go | 4 +- signer/cosigner_key.go | 15 +- signer/cosigner_key_shares.go | 13 +- signer/cosigner_nonce_cache.go | 6 +- signer/cosigner_nonce_cache_test.go | 10 +- signer/cosigner_security_ecies.go | 2 +- signer/cosigner_security_rsa.go | 2 +- signer/encoding/codec.go | 76 - signer/leader.go | 4 +- signer/leader_mock.go | 4 +- signer/local_cosigner.go | 35 +- signer/local_cosigner_test.go | 13 +- signer/metrics.go | 17 +- signer/multiresolver/multi_test.go | 12 +- signer/raft_events.go | 4 +- signer/raft_store.go | 56 +- signer/raft_store_test.go | 6 +- signer/remote_cosigner.go | 18 +- signer/remote_signer.go | 173 +- signer/remote_signer_grpc_server.go | 65 +- signer/serialization.go | 44 - signer/services.go | 37 +- signer/services_test.go | 21 +- signer/single_signer_validator.go | 18 +- signer/single_signer_validator_test.go | 31 +- signer/threshold_signer_soft_bn254.go | 9 +- signer/threshold_signer_soft_ed25519.go | 2 +- signer/threshold_validator.go | 151 +- signer/threshold_validator_test.go | 73 +- test/go.mod | 14 +- test/go.sum | 16 +- test/validator.go | 15 +- test/validator_single.go | 4 +- types/block.go | 52 + {signer => types}/hrs.go | 33 +- types/serialization.go | 23 + {signer => types}/serialization_test.go | 6 +- {signer => types}/sign_state.go | 97 +- 95 files changed, 11189 insertions(+), 888 deletions(-) rename {signer => comet/crypto}/bn254/bn254.go (97%) mode change 100644 => 100755 create mode 100755 comet/crypto/crypto.go create mode 100755 comet/crypto/ed25519/ed25519.go create mode 100755 comet/encoding/codec.go create mode 100644 comet/libs/async/async.go create mode 100644 comet/libs/async/async_test.go create mode 100755 comet/libs/json/decoder.go create mode 100755 comet/libs/json/encoder.go create mode 100755 comet/libs/json/structs.go create mode 100755 comet/libs/json/types.go create mode 100755 comet/libs/net/net.go create mode 100755 comet/libs/net/net_test.go create mode 100755 comet/libs/protoio/io.go create mode 100755 comet/libs/protoio/io_test.go create mode 100755 comet/libs/protoio/reader.go create mode 100755 comet/libs/protoio/writer.go create mode 100755 comet/libs/tempfile/tempfile.go create mode 100755 comet/p2p/conn/secret_connection.go rename {signer => comet/privval}/file.go (91%) mode change 100644 => 100755 rename {signer/proto => comet/proto/crypto}/keys.pb.go (97%) create mode 100644 comet/proto/p2p/conn.pb.go create mode 100644 comet/proto/privval/privval.pb.go create mode 100644 comet/proto/types/canonical.pb.go create mode 100644 comet/proto/types/types.pb.go create mode 100755 comet/types/block.go create mode 100755 comet/types/canonical.go create mode 100755 comet/types/part_set.go create mode 100755 comet/types/proposal.go create mode 100755 comet/types/vote.go rename {signer/proto => grpc/cosigner}/cosigner.pb.go (95%) rename {signer/proto => grpc/horcrux}/remote_signer.pb.go (94%) create mode 100644 proto/tendermint/p2p/conn.proto create mode 100644 proto/tendermint/privval/privval.proto create mode 100644 proto/tendermint/types/canonical.proto create mode 100644 proto/tendermint/types/types.proto delete mode 100644 signer/encoding/codec.go delete mode 100644 signer/serialization.go create mode 100644 types/block.go rename {signer => types}/hrs.go (55%) create mode 100644 types/serialization.go rename {signer => types}/serialization_test.go (88%) rename {signer => types}/sign_state.go (89%) diff --git a/.golangci.yml b/.golangci.yml index 6043d6e8..fd64c3a7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -35,52 +35,36 @@ linters-settings: alias: cryptotypes - pkg: github.com/cosmos/cosmos-sdk/x/slashing/types alias: slashingtypes - - pkg: github.com/cometbft/cometbft/types + - pkg: github.com/strangelove-ventures/horcrux/v3/comet/types alias: comet - - pkg: github.com/cometbft/cometbft/config + - pkg: github.com/strangelove-ventures/horcrux/v3/comet/config alias: cometconfig - - pkg: github.com/cometbft/cometbft/crypto + - pkg: github.com/strangelove-ventures/horcrux/v3/comet/crypto alias: cometcrypto - - pkg: github.com/cometbft/cometbft/crypto/ed25519 + - pkg: github.com/strangelove-ventures/horcrux/v3/comet/crypto/ed25519 alias: cometcryptoed25519 - - pkg: github.com/cometbft/cometbft/crypto/encoding + - pkg: github.com/strangelove-ventures/horcrux/v3/comet/crypto/bn254 + alias: cometcryptobn254 + - pkg: github.com/strangelove-ventures/horcrux/v3/comet/crypto/encoding alias: cometcryptoencoding - pkg: github.com/tendermint/go-amino alias: amino - - pkg: github.com/cometbft/cometbft/libs/bytes + - pkg: github.com/strangelove-ventures/horcrux/v3/comet/libs/bytes alias: cometbytes - - pkg: github.com/cometbft/cometbft/libs/json + - pkg: github.com/strangelove-ventures/horcrux/v3/comet/libs/json alias: cometjson - - pkg: github.com/cometbft/cometbft/libs/log - alias: cometlog - - pkg: github.com/cometbft/cometbft/libs/net + - pkg: github.com/strangelove-ventures/horcrux/v3/comet/libs/net alias: cometnet - - pkg: github.com/cometbft/cometbft/libs/os - alias: cometos - - pkg: github.com/cometbft/cometbft/libs/rand - alias: cometrand - - pkg: github.com/cometbft/cometbft/libs/service - alias: cometservice - - pkg: github.com/cometbft/cometbft/p2p/conn + - pkg: github.com/strangelove-ventures/horcrux/v3/comet/p2p/conn alias: cometp2pconn - - pkg: github.com/cometbft/cometbft/privval + - pkg: github.com/strangelove-ventures/horcrux/v3/comet/privval alias: cometprivval - - pkg: github.com/cometbft/cometbft/proto/tendermint/types + - pkg: github.com/strangelove-ventures/horcrux/v3/comet/proto/types alias: cometproto - - pkg: github.com/cometbft/cometbft/proto/tendermint/crypto + - pkg: github.com/strangelove-ventures/horcrux/v3/comet/proto/crypto alias: cometprotocrypto - - pkg: github.com/cometbft/cometbft/proto/tendermint/privval + - pkg: github.com/strangelove-ventures/horcrux/v3/comet/proto/privval alias: cometprotoprivval - - pkg: github.com/cometbft/cometbft/rpc/client - alias: cometrpcclient - - pkg: github.com/cometbft/cometbft/rpc/client/http - alias: cometrpchttp - - pkg: github.com/cometbft/cometbft/rpc/jsonrpc/client - alias: cometrpcjsonclient - - pkg: github.com/cometbft/cometbft/rpc/jsonrpc/types - alias: cometrpcjsontypes - - pkg: github.com/cometbft/cometbft/rpc/core/types - alias: cometrpctypes - pkg: github.com/ecies/go/v2 alias: ecies - pkg: github.com/grpc-ecosystem/go-grpc-middleware/retry @@ -102,9 +86,16 @@ linters-settings: - pkg: github.com/consensys/gnark-crypto/ecc/bn254/ecdsa alias: ecdsa_bn254 - pkg: github.com/strangelove-ventures/horcrux/v3/signer/bn254 - alias: horcrux_bn254 + alias: horcruxbn254 + - pkg: github.com/strangelove-ventures/horcrux/v3/grpc/cosigner + alias: grpccosigner + - pkg: github.com/strangelove-ventures/horcrux/v3/grpc/horcrux + alias: grpchorcrux maligned: suggest-new: true govet: misspell: locale: US +run: + skip-dirs: + - comet \ No newline at end of file diff --git a/cmd/horcrux/cmd/address.go b/cmd/horcrux/cmd/address.go index 572093b9..f1f54486 100644 --- a/cmd/horcrux/cmd/address.go +++ b/cmd/horcrux/cmd/address.go @@ -7,9 +7,9 @@ import ( "fmt" "strings" - cometprivval "github.com/cometbft/cometbft/privval" "github.com/cosmos/cosmos-sdk/types/bech32" "github.com/spf13/cobra" + cometprivval "github.com/strangelove-ventures/horcrux/v3/comet/privval" "github.com/strangelove-ventures/horcrux/v3/signer" ) @@ -61,7 +61,10 @@ func addressCmd() *cobra.Command { return fmt.Errorf("error reading priv-validator key: %w, check that key is present for chain ID: %s", err, chainID) } - filePV := cometprivval.LoadFilePVEmptyState(keyFile, "") + filePV, err := cometprivval.LoadFilePV(keyFile, "", false) + if err != nil { + return err + } pubKey = filePV.Key.PubKey.Bytes() default: panic(fmt.Errorf("unexpected sign mode: %s", config.Config.SignMode)) diff --git a/cmd/horcrux/cmd/leader_election.go b/cmd/horcrux/cmd/leader_election.go index 9fb4dfd6..a818fc1d 100644 --- a/cmd/horcrux/cmd/leader_election.go +++ b/cmd/horcrux/cmd/leader_election.go @@ -8,9 +8,9 @@ import ( grpcretry "github.com/grpc-ecosystem/go-grpc-middleware/retry" "github.com/spf13/cobra" "github.com/strangelove-ventures/horcrux/v3/client" + grpccosigner "github.com/strangelove-ventures/horcrux/v3/grpc/cosigner" "github.com/strangelove-ventures/horcrux/v3/signer" "github.com/strangelove-ventures/horcrux/v3/signer/multiresolver" - "github.com/strangelove-ventures/horcrux/v3/signer/proto" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" ) @@ -69,16 +69,16 @@ horcrux elect 2 # elect specific leader`, ctx, cancelFunc := context.WithTimeout(context.Background(), 30*time.Second) defer cancelFunc() - grpcClient := proto.NewCosignerClient(conn) + grpcClient := grpccosigner.NewCosignerClient(conn) _, err = grpcClient.TransferLeadership( ctx, - &proto.TransferLeadershipRequest{LeaderID: leaderID}, + &grpccosigner.TransferLeadershipRequest{LeaderID: leaderID}, ) if err != nil { return err } - res, err := grpcClient.GetLeader(ctx, &proto.GetLeaderRequest{}) + res, err := grpcClient.GetLeader(ctx, &grpccosigner.GetLeaderRequest{}) if err != nil { return err } @@ -166,9 +166,9 @@ func getLeaderCmd() *cobra.Command { ctx, cancelFunc := context.WithTimeout(context.Background(), 30*time.Second) defer cancelFunc() - grpcClient := proto.NewCosignerClient(conn) + grpcClient := grpccosigner.NewCosignerClient(conn) - res, err := grpcClient.GetLeader(ctx, &proto.GetLeaderRequest{}) + res, err := grpcClient.GetLeader(ctx, &grpccosigner.GetLeaderRequest{}) if err != nil { return err } diff --git a/cmd/horcrux/cmd/metrics.go b/cmd/horcrux/cmd/metrics.go index 078d3be5..1d0e4a59 100644 --- a/cmd/horcrux/cmd/metrics.go +++ b/cmd/horcrux/cmd/metrics.go @@ -5,18 +5,19 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/http/pprof" "time" "github.com/armon/go-metrics" gmprometheus "github.com/armon/go-metrics/prometheus" - cometlog "github.com/cometbft/cometbft/libs/log" "github.com/prometheus/client_golang/prometheus/promhttp" + "github.com/strangelove-ventures/horcrux/v3/signer" ) func AddPrometheusMetrics(mux *http.ServeMux, out io.Writer) { - logger := cometlog.NewTMLogger(cometlog.NewSyncWriter(out)).With("module", "metrics") + logger := slog.New(slog.NewTextHandler(out, nil)).With("module", "metrics") // Add metrics from raft's implementation of go-metrics cfg := gmprometheus.DefaultPrometheusOpts @@ -37,7 +38,7 @@ func AddPrometheusMetrics(mux *http.ServeMux, out io.Writer) { // EnableDebugAndMetrics - Initialization errors are not fatal, only logged func EnableDebugAndMetrics(ctx context.Context, out io.Writer) { - logger := cometlog.NewTMLogger(cometlog.NewSyncWriter(out)).With("module", "debugserver") + logger := slog.New(slog.NewTextHandler(out, nil)).With("module", "debugserver") // Configure Shared Debug HTTP Server for pprof and prometheus if len(config.Config.DebugAddr) == 0 { @@ -61,6 +62,8 @@ func EnableDebugAndMetrics(ctx context.Context, out io.Writer) { // Add prometheus metrics AddPrometheusMetrics(mux, out) + go signer.StartMetrics(ctx) + // Configure Debug Server Network Parameters srv := &http.Server{ Handler: mux, diff --git a/cmd/horcrux/cmd/migrate.go b/cmd/horcrux/cmd/migrate.go index 0c2b2772..11c6c5d6 100644 --- a/cmd/horcrux/cmd/migrate.go +++ b/cmd/horcrux/cmd/migrate.go @@ -8,12 +8,12 @@ import ( "os" "path/filepath" - cometcrypto "github.com/cometbft/cometbft/crypto" - cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519" "github.com/spf13/cobra" + cometcrypto "github.com/strangelove-ventures/horcrux/v3/comet/crypto" + cometcryptoed25519 "github.com/strangelove-ventures/horcrux/v3/comet/crypto/ed25519" + "github.com/strangelove-ventures/horcrux/v3/comet/encoding" + cometprotocrypto "github.com/strangelove-ventures/horcrux/v3/comet/proto/crypto" "github.com/strangelove-ventures/horcrux/v3/signer" - "github.com/strangelove-ventures/horcrux/v3/signer/encoding" - "github.com/strangelove-ventures/horcrux/v3/signer/proto" amino "github.com/tendermint/go-amino" "gopkg.in/yaml.v2" ) @@ -98,7 +98,7 @@ func (key *v2CosignerKey) UnmarshalJSON(data []byte) error { } var pubkey cometcrypto.PubKey - var protoPubkey proto.PublicKey + var protoPubkey cometprotocrypto.PublicKey err = protoPubkey.Unmarshal(aux.PubkeyBytes) // Prior to the tendermint protobuf migration, the public key bytes in key files diff --git a/cmd/horcrux/cmd/shards_test.go b/cmd/horcrux/cmd/shards_test.go index 848b16b9..6488ee62 100644 --- a/cmd/horcrux/cmd/shards_test.go +++ b/cmd/horcrux/cmd/shards_test.go @@ -5,10 +5,10 @@ import ( "path/filepath" "testing" - "github.com/cometbft/cometbft/crypto/ed25519" - cometjson "github.com/cometbft/cometbft/libs/json" - "github.com/cometbft/cometbft/privval" - "github.com/strangelove-ventures/horcrux/cmd/horcrux/cmd/testdata" + "github.com/strangelove-ventures/horcrux/v3/cmd/horcrux/cmd/testdata" + "github.com/strangelove-ventures/horcrux/v3/comet/crypto/ed25519" + cometjson "github.com/strangelove-ventures/horcrux/v3/comet/libs/json" + "github.com/strangelove-ventures/horcrux/v3/comet/privval" "github.com/strangelove-ventures/horcrux/v3/signer" "github.com/stretchr/testify/require" ) diff --git a/cmd/horcrux/cmd/start.go b/cmd/horcrux/cmd/start.go index 3633cce0..66cfea94 100644 --- a/cmd/horcrux/cmd/start.go +++ b/cmd/horcrux/cmd/start.go @@ -1,11 +1,13 @@ package cmd import ( + "context" "fmt" + "log/slog" + "net" "os" + "time" - cometlog "github.com/cometbft/cometbft/libs/log" - "github.com/cometbft/cometbft/libs/service" "github.com/spf13/cobra" "github.com/strangelove-ventures/horcrux/v3/signer" ) @@ -18,7 +20,7 @@ func startCmd() *cobra.Command { SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { out := cmd.OutOrStdout() - logger := cometlog.NewTMLogger(cometlog.NewSyncWriter(out)) + logger := slog.New(slog.NewTextHandler(out, nil)) err := signer.RequireNotRunning(logger, config.PidFile) if err != nil { @@ -42,12 +44,14 @@ func startCmd() *cobra.Command { acceptRisk, _ := cmd.Flags().GetBool(flagAcceptRisk) + ctx, cancel := context.WithCancel(cmd.Context()) + defer cancel() + var val signer.PrivValidator - var services []service.Service switch config.Config.SignMode { case signer.SignModeThreshold: - services, val, err = NewThresholdValidator(cmd.Context(), logger) + val, err = NewThresholdValidator(ctx, logger) if err != nil { return err } @@ -62,21 +66,23 @@ func startCmd() *cobra.Command { if config.Config.GRPCAddr != "" { grpcServer := signer.NewRemoteSignerGRPCServer(logger, val, config.Config.GRPCAddr) - services = append(services, grpcServer) - if err := grpcServer.Start(); err != nil { - return fmt.Errorf("failed to start grpc server: %w", err) - } + grpcServer.Start() } - go EnableDebugAndMetrics(cmd.Context(), out) + go EnableDebugAndMetrics(ctx, out) - services, err = signer.StartRemoteSigners(services, logger, val, config.Config.Nodes()) - if err != nil { - return fmt.Errorf("failed to start remote signer(s): %w", err) + for _, node := range config.Config.Nodes() { + // CometBFT requires a connection within 3 seconds of start or crashes + // A long timeout such as 30 seconds would cause the sentry to fail in loops + // Use a short timeout and dial often to connect within 3 second window + dialer := net.Dialer{Timeout: 2 * time.Second} + s := signer.NewReconnRemoteSigner(node, logger, val, dialer) + + s.Start(ctx) } - signer.WaitAndTerminate(logger, services, config.PidFile) + signer.WaitAndTerminate(logger, cancel, config.PidFile) return nil }, diff --git a/cmd/horcrux/cmd/state.go b/cmd/horcrux/cmd/state.go index 63ee6a5e..b6fa23c0 100644 --- a/cmd/horcrux/cmd/state.go +++ b/cmd/horcrux/cmd/state.go @@ -5,6 +5,7 @@ import ( "encoding/base64" "fmt" "io" + "log/slog" "os" "strconv" "strings" @@ -12,9 +13,9 @@ import ( "github.com/spf13/cobra" "github.com/strangelove-ventures/horcrux/v3/signer" + "github.com/strangelove-ventures/horcrux/v3/types" - cometjson "github.com/cometbft/cometbft/libs/json" - cometlog "github.com/cometbft/cometbft/libs/log" + cometjson "github.com/strangelove-ventures/horcrux/v3/comet/libs/json" ) // Snippet Taken from https://raw.githubusercontent.com/cometbft/cometbft/main/privval/file.go @@ -53,12 +54,12 @@ func showStateCmd() *cobra.Command { return fmt.Errorf("%s does not exist, initialize config with horcrux config init and try again", config.HomeDir) } - pv, err := signer.LoadSignState(config.PrivValStateFile(chainID)) + pv, err := types.LoadSignState(config.PrivValStateFile(chainID)) if err != nil { return err } - cs, err := signer.LoadSignState(config.CosignerStateFile(chainID)) + cs, err := types.LoadSignState(config.CosignerStateFile(chainID)) if err != nil { return err } @@ -84,7 +85,7 @@ func setStateCmd() *cobra.Command { chainID := args[0] out := cmd.OutOrStdout() - logger := cometlog.NewTMLogger(cometlog.NewSyncWriter(out)) + logger := slog.New(slog.NewTextHandler(out, nil)) if _, err := os.Stat(config.HomeDir); os.IsNotExist(err) { cmd.SilenceUsage = false @@ -97,12 +98,12 @@ func setStateCmd() *cobra.Command { return err } - pv, err := signer.LoadOrCreateSignState(config.PrivValStateFile(chainID)) + pv, err := types.LoadOrCreateSignState(config.PrivValStateFile(chainID)) if err != nil { return err } - cs, err := signer.LoadOrCreateSignState(config.CosignerStateFile(chainID)) + cs, err := types.LoadOrCreateSignState(config.CosignerStateFile(chainID)) if err != nil { return err } @@ -116,7 +117,7 @@ func setStateCmd() *cobra.Command { fmt.Fprintf(out, "Setting height %d\n", height) pv.NoncePublic, cs.NoncePublic = nil, nil - signState := signer.SignStateConsensus{ + signState := types.SignStateConsensus{ Height: height, Round: 0, Step: 0, @@ -155,7 +156,7 @@ func importStateCmd() *cobra.Command { } out := cmd.OutOrStdout() - logger := cometlog.NewTMLogger(cometlog.NewSyncWriter(out)) + logger := slog.New(slog.NewTextHandler(out, nil)) // Resetting the priv_validator_state.json should only be allowed if the // signer is not running. @@ -164,13 +165,13 @@ func importStateCmd() *cobra.Command { } // Recreate privValStateFile if necessary - pv, err := signer.LoadOrCreateSignState(config.PrivValStateFile(chainID)) + pv, err := types.LoadOrCreateSignState(config.PrivValStateFile(chainID)) if err != nil { return err } // shareStateFile does not exist during default config init, so create if necessary - cs, err := signer.LoadOrCreateSignState(config.CosignerStateFile(chainID)) + cs, err := types.LoadOrCreateSignState(config.CosignerStateFile(chainID)) if err != nil { return err } @@ -203,7 +204,7 @@ func importStateCmd() *cobra.Command { } pv.NoncePublic = nil - signState := signer.SignStateConsensus{ + signState := types.SignStateConsensus{ Height: pvState.Height, Round: int64(pvState.Round), Step: pvState.Step, @@ -232,7 +233,7 @@ func importStateCmd() *cobra.Command { } } -func printSignState(out io.Writer, ss *signer.SignState) { +func printSignState(out io.Writer, ss *types.SignState) { fmt.Fprintf(out, " Height: %v\n"+ " Round: %v\n"+ " Step: %v\n", diff --git a/cmd/horcrux/cmd/state_test.go b/cmd/horcrux/cmd/state_test.go index e805e202..bde63a79 100644 --- a/cmd/horcrux/cmd/state_test.go +++ b/cmd/horcrux/cmd/state_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - "github.com/strangelove-ventures/horcrux/v3/signer" + "github.com/strangelove-ventures/horcrux/v3/types" "github.com/stretchr/testify/require" ) @@ -64,7 +64,7 @@ func TestStateSetCmd(t *testing.T) { height, err := strconv.ParseInt(tc.args[1], 10, 64) require.NoError(t, err) - ss, err := signer.LoadSignState(filepath.Join(stateDir, chainID+"_priv_validator_state.json")) + ss, err := types.LoadSignState(filepath.Join(stateDir, chainID+"_priv_validator_state.json")) require.NoError(t, err) require.Equal(t, height, ss.Height) require.Equal(t, int64(0), ss.Round) @@ -73,7 +73,7 @@ func TestStateSetCmd(t *testing.T) { require.Nil(t, ss.Signature) require.Nil(t, ss.SignBytes) - ss, err = signer.LoadSignState(filepath.Join(stateDir, chainID+"_share_sign_state.json")) + ss, err = types.LoadSignState(filepath.Join(stateDir, chainID+"_share_sign_state.json")) require.NoError(t, err) require.Equal(t, height, ss.Height) require.Equal(t, int64(0), ss.Round) diff --git a/cmd/horcrux/cmd/threshold.go b/cmd/horcrux/cmd/threshold.go index e0a57863..e225f559 100644 --- a/cmd/horcrux/cmd/threshold.go +++ b/cmd/horcrux/cmd/threshold.go @@ -3,12 +3,11 @@ package cmd import ( "context" "fmt" + "log/slog" "os" "path/filepath" "time" - cometlog "github.com/cometbft/cometbft/libs/log" - cometservice "github.com/cometbft/cometbft/libs/service" "github.com/strangelove-ventures/horcrux/v3/signer" ) @@ -16,10 +15,10 @@ const maxWaitForSameBlockAttempts = 3 func NewThresholdValidator( ctx context.Context, - logger cometlog.Logger, -) ([]cometservice.Service, *signer.ThresholdValidator, error) { + logger *slog.Logger, +) (*signer.ThresholdValidator, error) { if err := config.Config.ValidateThresholdModeConfig(); err != nil { - return nil, nil, err + return nil, err } thresholdCfg := config.Config.ThresholdModeConfig @@ -35,7 +34,7 @@ func NewThresholdValidator( var rsaErr error security, rsaErr = config.CosignerSecurityRSA() if rsaErr != nil { - return nil, nil, fmt.Errorf("failed to initialize cosigner ECIES / RSA security : %w / %w", eciesErr, rsaErr) + return nil, fmt.Errorf("failed to initialize cosigner ECIES / RSA security : %w / %w", eciesErr, rsaErr) } } @@ -43,7 +42,7 @@ func NewThresholdValidator( if c.ShardID != security.GetID() { rc, err := signer.NewRemoteCosigner(c.ShardID, c.P2PAddr) if err != nil { - return nil, nil, fmt.Errorf("failed to initialize remote cosigner: %w", err) + return nil, fmt.Errorf("failed to initialize remote cosigner: %w", err) } remoteCosigners = append( remoteCosigners, @@ -55,7 +54,7 @@ func NewThresholdValidator( } if p2pListen == "" { - return nil, nil, fmt.Errorf("cosigner config does not exist for our shard ID %d", security.GetID()) + return nil, fmt.Errorf("cosigner config does not exist for our shard ID %d", security.GetID()) } localCosigner := signer.NewLocalCosigner( @@ -71,7 +70,7 @@ func NewThresholdValidator( raftDir := filepath.Join(config.HomeDir, "raft") if err := os.MkdirAll(raftDir, 0700); err != nil { - return nil, nil, fmt.Errorf("error creating raft directory: %w", err) + return nil, fmt.Errorf("error creating raft directory: %w", err) } // RAFT node ID is the cosigner ID @@ -80,10 +79,7 @@ func NewThresholdValidator( // Start RAFT store listener raftStore := signer.NewRaftStore(nodeID, raftDir, p2pListen, raftTimeout, logger, localCosigner, remoteCosigners) - if err := raftStore.Start(); err != nil { - return nil, nil, fmt.Errorf("error starting raft store: %w", err) - } - services := []cometservice.Service{raftStore} + go raftStore.Start() val := signer.NewThresholdValidator( logger, @@ -98,9 +94,7 @@ func NewThresholdValidator( raftStore.SetThresholdValidator(val) - if err := val.Start(ctx); err != nil { - return nil, nil, fmt.Errorf("failed to start threshold validator: %w", err) - } + val.Start(ctx) - return services, val, nil + return val, nil } diff --git a/cmd/horcrux/cmd/version.go b/cmd/horcrux/cmd/version.go index ecead366..b928be25 100644 --- a/cmd/horcrux/cmd/version.go +++ b/cmd/horcrux/cmd/version.go @@ -41,7 +41,6 @@ type Info struct { GitCommit string `json:"commit" yaml:"commit"` GoVersion string `json:"go_version" yaml:"go_version"` CosmosSdkVersion string `json:"cosmos_sdk_version" yaml:"cosmos_sdk_version"` - CometBFTVersion string `json:"cometbft_version" yaml:"cometbft_version"` } func NewInfo() Info { @@ -58,7 +57,6 @@ func NewInfo() Info { GitCommit: Commit, GoVersion: fmt.Sprintf("%s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH), CosmosSdkVersion: dependencyVersions["github.com/cosmos/cosmos-sdk"], - CometBFTVersion: dependencyVersions["github.com/cometbft/cometbft"], } } diff --git a/signer/bn254/bn254.go b/comet/crypto/bn254/bn254.go old mode 100644 new mode 100755 similarity index 97% rename from signer/bn254/bn254.go rename to comet/crypto/bn254/bn254.go index a8cdc6d1..b9ac9267 --- a/signer/bn254/bn254.go +++ b/comet/crypto/bn254/bn254.go @@ -16,9 +16,9 @@ import ( "github.com/consensys/gnark-crypto/ecc/bn254/fr" "github.com/consensys/gnark-crypto/ecc/bn254/fr/mimc" - "github.com/cometbft/cometbft/crypto" - cometjson "github.com/cometbft/cometbft/libs/json" "github.com/holiman/uint256" + "github.com/strangelove-ventures/horcrux/v3/comet/crypto" + cometjson "github.com/strangelove-ventures/horcrux/v3/comet/libs/json" ) const ( @@ -103,7 +103,7 @@ type PubKey []byte func (PubKey) TypeTag() string { return PubKeyName } func (pubKey PubKey) Address() crypto.Address { - return crypto.AddressHash(pubKey[:]) + return crypto.AddressHash(pubKey) } func (pubKey PubKey) Bytes() []byte { diff --git a/comet/crypto/crypto.go b/comet/crypto/crypto.go new file mode 100755 index 00000000..fbc32b05 --- /dev/null +++ b/comet/crypto/crypto.go @@ -0,0 +1,27 @@ +package crypto + +import "crypto/sha256" + +type Address = []byte + +func AddressHash(bz []byte) Address { + hash := sha256.Sum256(bz) + addr := hash[:20] + return Address(addr) +} + +type PrivKey interface { + Bytes() []byte + Sign(msg []byte) ([]byte, error) + PubKey() PubKey + Equals(PrivKey) bool + Type() string +} + +type PubKey interface { + Address() Address + Bytes() []byte + VerifySignature(msg []byte, sig []byte) bool + Equals(PubKey) bool + Type() string +} diff --git a/comet/crypto/ed25519/ed25519.go b/comet/crypto/ed25519/ed25519.go new file mode 100755 index 00000000..e7097848 --- /dev/null +++ b/comet/crypto/ed25519/ed25519.go @@ -0,0 +1,192 @@ +package ed25519 + +import ( + "bytes" + "crypto/rand" + "crypto/sha256" + "crypto/subtle" + "fmt" + "io" + + "github.com/oasisprotocol/curve25519-voi/primitives/ed25519" + "github.com/oasisprotocol/curve25519-voi/primitives/ed25519/extra/cache" + cometjson "github.com/strangelove-ventures/horcrux/v3/comet/libs/json" + + "github.com/strangelove-ventures/horcrux/v3/comet/crypto" +) + +//------------------------------------- + +var ( + _ crypto.PrivKey = PrivKey{} + + // curve25519-voi's Ed25519 implementation supports configurable + // verification behavior, and CometBFT uses the ZIP-215 verification + // semantics. + verifyOptions = &ed25519.Options{ + Verify: ed25519.VerifyOptionsZIP_215, + } + + cachingVerifier = cache.NewVerifier(cache.NewLRUCache(cacheSize)) +) + +const ( + PrivKeyName = "tendermint/PrivKeyEd25519" + PubKeyName = "tendermint/PubKeyEd25519" + // PubKeySize is is the size, in bytes, of public keys as used in this package. + PubKeySize = 32 + // PrivateKeySize is the size, in bytes, of private keys as used in this package. + PrivateKeySize = 64 + // Size of an Edwards25519 signature. Namely the size of a compressed + // Edwards25519 point, and a field element. Both of which are 32 bytes. + SignatureSize = 64 + // SeedSize is the size, in bytes, of private key seeds. These are the + // private key representations used by RFC 8032. + SeedSize = 32 + + KeyType = "ed25519" + + // cacheSize is the number of public keys that will be cached in + // an expanded format for repeated signature verification. + // + // TODO/perf: Either this should exclude single verification, or be + // tuned to `> validatorSize + maxTxnsPerBlock` to avoid cache + // thrashing. + cacheSize = 4096 +) + +func init() { + cometjson.RegisterType(PubKey{}, PubKeyName) + cometjson.RegisterType(PrivKey{}, PrivKeyName) +} + +// PrivKey implements crypto.PrivKey. +type PrivKey []byte + +// Bytes returns the privkey byte format. +func (privKey PrivKey) Bytes() []byte { + return []byte(privKey) +} + +// Sign produces a signature on the provided message. +// This assumes the privkey is wellformed in the golang format. +// The first 32 bytes should be random, +// corresponding to the normal ed25519 private key. +// The latter 32 bytes should be the compressed public key. +// If these conditions aren't met, Sign will panic or produce an +// incorrect signature. +func (privKey PrivKey) Sign(msg []byte) ([]byte, error) { + signatureBytes := ed25519.Sign(ed25519.PrivateKey(privKey), msg) + return signatureBytes, nil +} + +// PubKey gets the corresponding public key from the private key. +// +// Panics if the private key is not initialized. +func (privKey PrivKey) PubKey() crypto.PubKey { + // If the latter 32 bytes of the privkey are all zero, privkey is not + // initialized. + initialized := false + for _, v := range privKey[32:] { + if v != 0 { + initialized = true + break + } + } + + if !initialized { + panic("Expected ed25519 PrivKey to include concatenated pubkey bytes") + } + + pubkeyBytes := make([]byte, PubKeySize) + copy(pubkeyBytes, privKey[32:]) + return PubKey(pubkeyBytes) +} + +// Equals - you probably don't need to use this. +// Runs in constant time based on length of the keys. +func (privKey PrivKey) Equals(other crypto.PrivKey) bool { + if otherEd, ok := other.(PrivKey); ok { + return subtle.ConstantTimeCompare(privKey[:], otherEd[:]) == 1 + } + + return false +} + +func (privKey PrivKey) Type() string { + return KeyType +} + +// GenPrivKey generates a new ed25519 private key. +// It uses OS randomness in conjunction with the current global random seed +// in cometbft/libs/rand to generate the private key. +func GenPrivKey() PrivKey { + return genPrivKey(rand.Reader) +} + +// genPrivKey generates a new ed25519 private key using the provided reader. +func genPrivKey(rand io.Reader) PrivKey { + _, priv, err := ed25519.GenerateKey(rand) + if err != nil { + panic(err) + } + + return PrivKey(priv) +} + +// GenPrivKeyFromSecret hashes the secret with SHA2, and uses +// that 32 byte output to create the private key. +// NOTE: secret should be the output of a KDF like bcrypt, +// if it's derived from user input. +func GenPrivKeyFromSecret(secret []byte) PrivKey { + seed := sha256.Sum256(secret) // Not Ripemd160 because we want 32 bytes. + + return PrivKey(ed25519.NewKeyFromSeed(seed[:])) +} + +//------------------------------------- + +var _ crypto.PubKey = PubKey{} + +// PubKey implements crypto.PubKey for the Ed25519 signature scheme. +type PubKey []byte + +// Address is the SHA256-20 of the raw pubkey bytes. +func (pubKey PubKey) Address() crypto.Address { + if len(pubKey) != PubKeySize { + panic("pubkey is incorrect size") + } + return crypto.AddressHash(pubKey) +} + +// Bytes returns the PubKey byte format. +func (pubKey PubKey) Bytes() []byte { + return []byte(pubKey) +} + +func (pubKey PubKey) VerifySignature(msg []byte, sig []byte) bool { + // make sure we use the same algorithm to sign + if len(sig) != SignatureSize { + return false + } + + return cachingVerifier.VerifyWithOptions(ed25519.PublicKey(pubKey), msg, sig, verifyOptions) +} + +func (pubKey PubKey) String() string { + return fmt.Sprintf("PubKeyEd25519{%X}", []byte(pubKey)) +} + +func (pubKey PubKey) Type() string { + return KeyType +} + +func (pubKey PubKey) Equals(other crypto.PubKey) bool { + if otherEd, ok := other.(PubKey); ok { + return bytes.Equal(pubKey[:], otherEd[:]) + } + + return false +} + +//------------------------------------- diff --git a/comet/encoding/codec.go b/comet/encoding/codec.go new file mode 100755 index 00000000..b795b75d --- /dev/null +++ b/comet/encoding/codec.go @@ -0,0 +1,61 @@ +package encoding + +import ( + "fmt" + + "github.com/strangelove-ventures/horcrux/v3/comet/crypto" + "github.com/strangelove-ventures/horcrux/v3/comet/crypto/bn254" + "github.com/strangelove-ventures/horcrux/v3/comet/crypto/ed25519" + "github.com/strangelove-ventures/horcrux/v3/comet/libs/json" + protocrypto "github.com/strangelove-ventures/horcrux/v3/comet/proto/crypto" +) + +func init() { + json.RegisterType((*protocrypto.PublicKey_Bn254)(nil), "tendermint.crypto.PublicKey_Bn254") +} + +// PubKeyToProto takes crypto.PubKey and transforms it to a protobuf Pubkey +func PubKeyToProto(k crypto.PubKey) (protocrypto.PublicKey, error) { + var kp protocrypto.PublicKey + switch k := k.(type) { + case ed25519.PubKey: + kp = protocrypto.PublicKey{ + Sum: &protocrypto.PublicKey_Ed25519{ + Ed25519: k, + }, + } + case bn254.PubKey: + kp = protocrypto.PublicKey{ + Sum: &protocrypto.PublicKey_Bn254{ + Bn254: k, + }, + } + default: + return kp, fmt.Errorf("toproto: key type %v is not supported", k) + } + return kp, nil +} + +// PubKeyFromProto takes a protobuf Pubkey and transforms it to a crypto.Pubkey +func PubKeyFromProto(k protocrypto.PublicKey) (crypto.PubKey, error) { + switch k := k.Sum.(type) { + case *protocrypto.PublicKey_Ed25519: + if len(k.Ed25519) != ed25519.PubKeySize { + return nil, fmt.Errorf("invalid size for PubKeyEd25519. Got %d, expected %d", + len(k.Ed25519), ed25519.PubKeySize) + } + pk := make(ed25519.PubKey, ed25519.PubKeySize) + copy(pk, k.Ed25519) + return pk, nil + case *protocrypto.PublicKey_Bn254: + if len(k.Bn254) != bn254.PubKeySize { + return nil, fmt.Errorf("invalid size for PubKeyBn254. Got %d, expected %d", + len(k.Bn254), bn254.PubKeySize) + } + pk := make(bn254.PubKey, bn254.PubKeySize) + copy(pk, k.Bn254) + return pk, nil + default: + return nil, fmt.Errorf("fromproto: key type %v is not supported", k) + } +} diff --git a/comet/libs/async/async.go b/comet/libs/async/async.go new file mode 100644 index 00000000..e716821b --- /dev/null +++ b/comet/libs/async/async.go @@ -0,0 +1,184 @@ +package async + +import ( + "fmt" + "runtime" + "sync/atomic" +) + +//---------------------------------------- +// Task + +// val: the value returned after task execution. +// err: the error returned during task completion. +// abort: tells Parallel to return, whether or not all tasks have completed. +type Task func(i int) (val interface{}, abort bool, err error) + +type TaskResult struct { + Value interface{} + Error error +} + +type TaskResultCh <-chan TaskResult + +type taskResultOK struct { + TaskResult + OK bool +} + +type TaskResultSet struct { + chz []TaskResultCh + results []taskResultOK +} + +func newTaskResultSet(chz []TaskResultCh) *TaskResultSet { + return &TaskResultSet{ + chz: chz, + results: make([]taskResultOK, len(chz)), + } +} + +func (trs *TaskResultSet) Channels() []TaskResultCh { + return trs.chz +} + +func (trs *TaskResultSet) LatestResult(index int) (TaskResult, bool) { + if len(trs.results) <= index { + return TaskResult{}, false + } + resultOK := trs.results[index] + return resultOK.TaskResult, resultOK.OK +} + +// NOTE: Not concurrency safe. +// Writes results to trs.results without waiting for all tasks to complete. +func (trs *TaskResultSet) Reap() *TaskResultSet { + for i := 0; i < len(trs.results); i++ { + var trch = trs.chz[i] + select { + case result, ok := <-trch: + if ok { + // Write result. + trs.results[i] = taskResultOK{ + TaskResult: result, + OK: true, + } + } + // else { + // We already wrote it. + // } + default: + // Do nothing. + } + } + return trs +} + +// NOTE: Not concurrency safe. +// Like Reap() but waits until all tasks have returned or panic'd. +func (trs *TaskResultSet) Wait() *TaskResultSet { + for i := 0; i < len(trs.results); i++ { + var trch = trs.chz[i] + result, ok := <-trch + if ok { + // Write result. + trs.results[i] = taskResultOK{ + TaskResult: result, + OK: true, + } + } + // else { + // We already wrote it. + // } + } + return trs +} + +// Returns the firstmost (by task index) error as +// discovered by all previous Reap() calls. +func (trs *TaskResultSet) FirstValue() interface{} { + for _, result := range trs.results { + if result.Value != nil { + return result.Value + } + } + return nil +} + +// Returns the firstmost (by task index) error as +// discovered by all previous Reap() calls. +func (trs *TaskResultSet) FirstError() error { + for _, result := range trs.results { + if result.Error != nil { + return result.Error + } + } + return nil +} + +//---------------------------------------- +// Parallel + +// Run tasks in parallel, with ability to abort early. +// Returns ok=false iff any of the tasks returned abort=true. +// NOTE: Do not implement quit features here. Instead, provide convenient +// concurrent quit-like primitives, passed implicitly via Task closures. (e.g. +// it's not Parallel's concern how you quit/abort your tasks). +func Parallel(tasks ...Task) (trs *TaskResultSet, ok bool) { + var taskResultChz = make([]TaskResultCh, len(tasks)) // To return. + var taskDoneCh = make(chan bool, len(tasks)) // A "wait group" channel, early abort if any true received. + var numPanics = new(int32) // Keep track of panics to set ok=false later. + + // We will set it to false iff any tasks panic'd or returned abort. + ok = true + + // Start all tasks in parallel in separate goroutines. + // When the task is complete, it will appear in the + // respective taskResultCh (associated by task index). + for i, task := range tasks { + var taskResultCh = make(chan TaskResult, 1) // Capacity for 1 result. + taskResultChz[i] = taskResultCh + go func(i int, task Task, taskResultCh chan TaskResult) { + // Recovery + defer func() { + if pnk := recover(); pnk != nil { + atomic.AddInt32(numPanics, 1) + // Send panic to taskResultCh. + const size = 64 << 10 + buf := make([]byte, size) + buf = buf[:runtime.Stack(buf, false)] + taskResultCh <- TaskResult{nil, fmt.Errorf("panic in task %v : %s", pnk, buf)} + // Closing taskResultCh lets trs.Wait() work. + close(taskResultCh) + // Decrement waitgroup. + taskDoneCh <- false + } + }() + // Run the task. + var val, abort, err = task(i) + // Send val/err to taskResultCh. + // NOTE: Below this line, nothing must panic/ + taskResultCh <- TaskResult{val, err} + // Closing taskResultCh lets trs.Wait() work. + close(taskResultCh) + // Decrement waitgroup. + taskDoneCh <- abort + }(i, task, taskResultCh) + } + + // Wait until all tasks are done, or until abort. + // DONE_LOOP: + for i := 0; i < len(tasks); i++ { + abort := <-taskDoneCh + if abort { + ok = false + break + } + } + + // Ok is also false if there were any panics. + // We must do this check here (after DONE_LOOP). + ok = ok && (atomic.LoadInt32(numPanics) == 0) + + return newTaskResultSet(taskResultChz).Reap(), ok +} diff --git a/comet/libs/async/async_test.go b/comet/libs/async/async_test.go new file mode 100644 index 00000000..4faead44 --- /dev/null +++ b/comet/libs/async/async_test.go @@ -0,0 +1,160 @@ +package async + +import ( + "errors" + "fmt" + "sync/atomic" + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +func TestParallel(t *testing.T) { + + // Create tasks. + var counter = new(int32) + var tasks = make([]Task, 100*1000) + for i := 0; i < len(tasks); i++ { + tasks[i] = func(i int) (res interface{}, abort bool, err error) { + atomic.AddInt32(counter, 1) + return -1 * i, false, nil + } + } + + // Run in parallel. + var trs, ok = Parallel(tasks...) + assert.True(t, ok) + + // Verify. + assert.Equal(t, int(*counter), len(tasks), "Each task should have incremented the counter already") + var failedTasks int + for i := 0; i < len(tasks); i++ { + taskResult, ok := trs.LatestResult(i) + switch { + case !ok: + assert.Fail(t, "Task #%v did not complete.", i) + failedTasks++ + case taskResult.Error != nil: + assert.Fail(t, "Task should not have errored but got %v", taskResult.Error) + failedTasks++ + case !assert.Equal(t, -1*i, taskResult.Value.(int)): + assert.Fail(t, "Task should have returned %v but got %v", -1*i, taskResult.Value.(int)) + failedTasks++ + } + // else { + // Good! + // } + } + assert.Equal(t, failedTasks, 0, "No task should have failed") + assert.Nil(t, trs.FirstError(), "There should be no errors") + assert.Equal(t, 0, trs.FirstValue(), "First value should be 0") +} + +func TestParallelAbort(t *testing.T) { + + var flow1 = make(chan struct{}, 1) + var flow2 = make(chan struct{}, 1) + var flow3 = make(chan struct{}, 1) // Cap must be > 0 to prevent blocking. + var flow4 = make(chan struct{}, 1) + + // Create tasks. + var tasks = []Task{ + func(i int) (res interface{}, abort bool, err error) { + assert.Equal(t, i, 0) + flow1 <- struct{}{} + return 0, false, nil + }, + func(i int) (res interface{}, abort bool, err error) { + assert.Equal(t, i, 1) + flow2 <- <-flow1 + return 1, false, errors.New("some error") + }, + func(i int) (res interface{}, abort bool, err error) { + assert.Equal(t, i, 2) + flow3 <- <-flow2 + return 2, true, nil + }, + func(i int) (res interface{}, abort bool, err error) { + assert.Equal(t, i, 3) + <-flow4 + return 3, false, nil + }, + } + + // Run in parallel. + var taskResultSet, ok = Parallel(tasks...) + assert.False(t, ok, "ok should be false since we aborted task #2.") + + // Verify task #3. + // Initially taskResultSet.chz[3] sends nothing since flow4 didn't send. + waitTimeout(t, taskResultSet.chz[3], "Task #3") + + // Now let the last task (#3) complete after abort. + flow4 <- <-flow3 + + // Wait until all tasks have returned or panic'd. + taskResultSet.Wait() + + // Verify task #0, #1, #2. + checkResult(t, taskResultSet, 0, 0, nil, nil) + checkResult(t, taskResultSet, 1, 1, errors.New("some error"), nil) + checkResult(t, taskResultSet, 2, 2, nil, nil) + checkResult(t, taskResultSet, 3, 3, nil, nil) +} + +func TestParallelRecover(t *testing.T) { + + // Create tasks. + var tasks = []Task{ + func(i int) (res interface{}, abort bool, err error) { + return 0, false, nil + }, + func(i int) (res interface{}, abort bool, err error) { + return 1, false, errors.New("some error") + }, + func(i int) (res interface{}, abort bool, err error) { + panic(2) + }, + } + + // Run in parallel. + var taskResultSet, ok = Parallel(tasks...) + assert.False(t, ok, "ok should be false since we panic'd in task #2.") + + // Verify task #0, #1, #2. + checkResult(t, taskResultSet, 0, 0, nil, nil) + checkResult(t, taskResultSet, 1, 1, errors.New("some error"), nil) + checkResult(t, taskResultSet, 2, nil, nil, fmt.Errorf("panic in task %v", 2).Error()) +} + +// Wait for result +func checkResult(t *testing.T, taskResultSet *TaskResultSet, index int, + val interface{}, err error, pnk interface{}) { + taskResult, ok := taskResultSet.LatestResult(index) + taskName := fmt.Sprintf("Task #%v", index) + assert.True(t, ok, "TaskResultCh unexpectedly closed for %v", taskName) + assert.Equal(t, val, taskResult.Value, taskName) + switch { + case err != nil: + assert.Equal(t, err.Error(), taskResult.Error.Error(), taskName) + case pnk != nil: + assert.Contains(t, taskResult.Error.Error(), pnk, taskName) + default: + assert.Nil(t, taskResult.Error, taskName) + } +} + +// Wait for timeout (no result) +func waitTimeout(t *testing.T, taskResultCh TaskResultCh, taskName string) { + select { + case _, ok := <-taskResultCh: + if !ok { + assert.Fail(t, "TaskResultCh unexpectedly closed (%v)", taskName) + } else { + assert.Fail(t, "TaskResultCh unexpectedly returned for %v", taskName) + } + case <-time.After(1 * time.Second): // TODO use deterministic time? + // Good! + } +} diff --git a/comet/libs/json/decoder.go b/comet/libs/json/decoder.go new file mode 100755 index 00000000..86ff27d3 --- /dev/null +++ b/comet/libs/json/decoder.go @@ -0,0 +1,278 @@ +package json + +import ( + "bytes" + "encoding/json" + "errors" + "fmt" + "reflect" +) + +// Unmarshal unmarshals JSON into the given value, using Amino-compatible JSON encoding (strings +// for 64-bit numbers, and type wrappers for registered types). +func Unmarshal(bz []byte, v interface{}) error { + return decode(bz, v) +} + +func decode(bz []byte, v interface{}) error { + if len(bz) == 0 { + return errors.New("cannot decode empty bytes") + } + + rv := reflect.ValueOf(v) + if rv.Kind() != reflect.Ptr { + return errors.New("must decode into a pointer") + } + rv = rv.Elem() + + // If this is a registered type, defer to interface decoder regardless of whether the input is + // an interface or a bare value. This retains Amino's behavior, but is inconsistent with + // behavior in structs where an interface field will get the type wrapper while a bare value + // field will not. + if typeRegistry.name(rv.Type()) != "" { + return decodeReflectInterface(bz, rv) + } + + return decodeReflect(bz, rv) +} + +func decodeReflect(bz []byte, rv reflect.Value) error { + if !rv.CanAddr() { + return errors.New("value is not addressable") + } + + // Handle null for slices, interfaces, and pointers + if bytes.Equal(bz, []byte("null")) { + rv.Set(reflect.Zero(rv.Type())) + return nil + } + + // Dereference-and-construct pointers, to handle nested pointers. + for rv.Kind() == reflect.Ptr { + if rv.IsNil() { + rv.Set(reflect.New(rv.Type().Elem())) + } + rv = rv.Elem() + } + + // Times must be UTC and end with Z + if rv.Type() == timeType { + switch { + case len(bz) < 2 || bz[0] != '"' || bz[len(bz)-1] != '"': + return fmt.Errorf("JSON time must be an RFC3339 string, but got %q", bz) + case bz[len(bz)-2] != 'Z': + return fmt.Errorf("JSON time must be UTC and end with 'Z', but got %q", bz) + } + } + + // If value implements json.Umarshaler, call it. + if rv.Addr().Type().Implements(jsonUnmarshalerType) { + return rv.Addr().Interface().(json.Unmarshaler).UnmarshalJSON(bz) + } + + switch rv.Type().Kind() { + // Decode complex types recursively. + case reflect.Slice, reflect.Array: + return decodeReflectList(bz, rv) + + case reflect.Map: + return decodeReflectMap(bz, rv) + + case reflect.Struct: + return decodeReflectStruct(bz, rv) + + case reflect.Interface: + return decodeReflectInterface(bz, rv) + + // For 64-bit integers, unwrap expected string and defer to stdlib for integer decoding. + case reflect.Int64, reflect.Int, reflect.Uint64, reflect.Uint: + if bz[0] != '"' || bz[len(bz)-1] != '"' { + return fmt.Errorf("invalid 64-bit integer encoding %q, expected string", string(bz)) + } + bz = bz[1 : len(bz)-1] + fallthrough + + // Anything else we defer to the stdlib. + default: + return decodeStdlib(bz, rv) + } +} + +func decodeReflectList(bz []byte, rv reflect.Value) error { + if !rv.CanAddr() { + return errors.New("list value is not addressable") + } + + switch rv.Type().Elem().Kind() { + // Decode base64-encoded bytes using stdlib decoder, via byte slice for arrays. + case reflect.Uint8: + if rv.Type().Kind() == reflect.Array { + var buf []byte + if err := json.Unmarshal(bz, &buf); err != nil { + return err + } + if len(buf) != rv.Len() { + return fmt.Errorf("got %v bytes, expected %v", len(buf), rv.Len()) + } + reflect.Copy(rv, reflect.ValueOf(buf)) + + } else if err := decodeStdlib(bz, rv); err != nil { + return err + } + + // Decode anything else into a raw JSON slice, and decode values recursively. + default: + var rawSlice []json.RawMessage + if err := json.Unmarshal(bz, &rawSlice); err != nil { + return err + } + if rv.Type().Kind() == reflect.Slice { + rv.Set(reflect.MakeSlice(reflect.SliceOf(rv.Type().Elem()), len(rawSlice), len(rawSlice))) + } + if rv.Len() != len(rawSlice) { // arrays of wrong size + return fmt.Errorf("got list of %v elements, expected %v", len(rawSlice), rv.Len()) + } + for i, bz := range rawSlice { + if err := decodeReflect(bz, rv.Index(i)); err != nil { + return err + } + } + } + + // Replace empty slices with nil slices, for Amino compatibility + if rv.Type().Kind() == reflect.Slice && rv.Len() == 0 { + rv.Set(reflect.Zero(rv.Type())) + } + + return nil +} + +func decodeReflectMap(bz []byte, rv reflect.Value) error { + if !rv.CanAddr() { + return errors.New("map value is not addressable") + } + + // Decode into a raw JSON map, using string keys. + rawMap := make(map[string]json.RawMessage) + if err := json.Unmarshal(bz, &rawMap); err != nil { + return err + } + if rv.Type().Key().Kind() != reflect.String { + return fmt.Errorf("map keys must be strings, got %v", rv.Type().Key().String()) + } + + // Recursively decode values. + rv.Set(reflect.MakeMapWithSize(rv.Type(), len(rawMap))) + for key, bz := range rawMap { + value := reflect.New(rv.Type().Elem()).Elem() + if err := decodeReflect(bz, value); err != nil { + return err + } + rv.SetMapIndex(reflect.ValueOf(key), value) + } + return nil +} + +func decodeReflectStruct(bz []byte, rv reflect.Value) error { + if !rv.CanAddr() { + return errors.New("struct value is not addressable") + } + sInfo := makeStructInfo(rv.Type()) + + // Decode raw JSON values into a string-keyed map. + rawMap := make(map[string]json.RawMessage) + if err := json.Unmarshal(bz, &rawMap); err != nil { + return err + } + for i, fInfo := range sInfo.fields { + if !fInfo.hidden { + frv := rv.Field(i) + bz := rawMap[fInfo.jsonName] + if len(bz) > 0 { + if err := decodeReflect(bz, frv); err != nil { + return err + } + } else if !fInfo.omitEmpty { + frv.Set(reflect.Zero(frv.Type())) + } + } + } + + return nil +} + +func decodeReflectInterface(bz []byte, rv reflect.Value) error { + if !rv.CanAddr() { + return errors.New("interface value not addressable") + } + + // Decode the interface wrapper. + wrapper := interfaceWrapper{} + if err := json.Unmarshal(bz, &wrapper); err != nil { + return err + } + if wrapper.Type == "" { + return errors.New("interface type cannot be empty") + } + if len(wrapper.Value) == 0 { + return errors.New("interface value cannot be empty") + } + + // Dereference-and-construct pointers, to handle nested pointers. + for rv.Kind() == reflect.Ptr { + if rv.IsNil() { + rv.Set(reflect.New(rv.Type().Elem())) + } + rv = rv.Elem() + } + + // Look up the interface type, and construct a concrete value. + rt, returnPtr := typeRegistry.lookup(wrapper.Type) + if rt == nil { + return fmt.Errorf("unknown type %q", wrapper.Type) + } + + cptr := reflect.New(rt) + crv := cptr.Elem() + if err := decodeReflect(wrapper.Value, crv); err != nil { + return err + } + + // This makes sure interface implementations with pointer receivers (e.g. func (c *Car)) are + // constructed as pointers behind the interface. The types must be registered as pointers with + // RegisterType(). + if rv.Type().Kind() == reflect.Interface && returnPtr { + if !cptr.Type().AssignableTo(rv.Type()) { + return fmt.Errorf("invalid type %q for this value", wrapper.Type) + } + rv.Set(cptr) + } else { + if !crv.Type().AssignableTo(rv.Type()) { + return fmt.Errorf("invalid type %q for this value", wrapper.Type) + } + rv.Set(crv) + } + return nil +} + +func decodeStdlib(bz []byte, rv reflect.Value) error { + if !rv.CanAddr() && rv.Kind() != reflect.Ptr { + return errors.New("value must be addressable or pointer") + } + + // Make sure we are unmarshaling into a pointer. + target := rv + if rv.Kind() != reflect.Ptr { + target = reflect.New(rv.Type()) + } + if err := json.Unmarshal(bz, target.Interface()); err != nil { + return err + } + rv.Set(target.Elem()) + return nil +} + +type interfaceWrapper struct { + Type string `json:"type"` + Value json.RawMessage `json:"value"` +} diff --git a/comet/libs/json/encoder.go b/comet/libs/json/encoder.go new file mode 100755 index 00000000..11990e2a --- /dev/null +++ b/comet/libs/json/encoder.go @@ -0,0 +1,254 @@ +package json + +import ( + "bytes" + "encoding/json" + "errors" + "fmt" + "io" + "reflect" + "strconv" + "time" +) + +var ( + timeType = reflect.TypeOf(time.Time{}) + jsonMarshalerType = reflect.TypeOf(new(json.Marshaler)).Elem() + jsonUnmarshalerType = reflect.TypeOf(new(json.Unmarshaler)).Elem() +) + +// Marshal marshals the value as JSON, using Amino-compatible JSON encoding (strings for +// 64-bit numbers, and type wrappers for registered types). +func Marshal(v interface{}) ([]byte, error) { + buf := new(bytes.Buffer) + err := encode(buf, v) + if err != nil { + return nil, err + } + return buf.Bytes(), nil +} + +// MarshalIndent marshals the value as JSON, using the given prefix and indentation. +func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) { + bz, err := Marshal(v) + if err != nil { + return nil, err + } + buf := new(bytes.Buffer) + err = json.Indent(buf, bz, prefix, indent) + if err != nil { + return nil, err + } + return buf.Bytes(), nil +} + +func encode(w io.Writer, v interface{}) error { + // Bare nil values can't be reflected, so we must handle them here. + if v == nil { + return writeStr(w, "null") + } + rv := reflect.ValueOf(v) + + // If this is a registered type, defer to interface encoder regardless of whether the input is + // an interface or a bare value. This retains Amino's behavior, but is inconsistent with + // behavior in structs where an interface field will get the type wrapper while a bare value + // field will not. + if typeRegistry.name(rv.Type()) != "" { + return encodeReflectInterface(w, rv) + } + + return encodeReflect(w, rv) +} + +func encodeReflect(w io.Writer, rv reflect.Value) error { + if !rv.IsValid() { + return errors.New("invalid reflect value") + } + + // Recursively dereference if pointer. + for rv.Kind() == reflect.Ptr { + if rv.IsNil() { + return writeStr(w, "null") + } + rv = rv.Elem() + } + + // Convert times to UTC. + if rv.Type() == timeType { + rv = reflect.ValueOf(rv.Interface().(time.Time).Round(0).UTC()) + } + + // If the value implements json.Marshaler, defer to stdlib directly. Since we've already + // dereferenced, we try implementations with both value receiver and pointer receiver. We must + // do this after the time normalization above, and thus after dereferencing. + if rv.Type().Implements(jsonMarshalerType) { + return encodeStdlib(w, rv.Interface()) + } else if rv.CanAddr() && rv.Addr().Type().Implements(jsonMarshalerType) { + return encodeStdlib(w, rv.Addr().Interface()) + } + + switch rv.Type().Kind() { + // Complex types must be recursively encoded. + case reflect.Interface: + return encodeReflectInterface(w, rv) + + case reflect.Array, reflect.Slice: + return encodeReflectList(w, rv) + + case reflect.Map: + return encodeReflectMap(w, rv) + + case reflect.Struct: + return encodeReflectStruct(w, rv) + + // 64-bit integers are emitted as strings, to avoid precision problems with e.g. + // Javascript which uses 64-bit floats (having 53-bit precision). + case reflect.Int64, reflect.Int: + return writeStr(w, `"`+strconv.FormatInt(rv.Int(), 10)+`"`) + + case reflect.Uint64, reflect.Uint: + return writeStr(w, `"`+strconv.FormatUint(rv.Uint(), 10)+`"`) + + // For everything else, defer to the stdlib encoding/json encoder + default: + return encodeStdlib(w, rv.Interface()) + } +} + +func encodeReflectList(w io.Writer, rv reflect.Value) error { + // Emit nil slices as null. + if rv.Kind() == reflect.Slice && rv.IsNil() { + return writeStr(w, "null") + } + + // Encode byte slices as base64 with the stdlib encoder. + if rv.Type().Elem().Kind() == reflect.Uint8 { + // Stdlib does not base64-encode byte arrays, only slices, so we copy to slice. + if rv.Type().Kind() == reflect.Array { + slice := reflect.MakeSlice(reflect.SliceOf(rv.Type().Elem()), rv.Len(), rv.Len()) + reflect.Copy(slice, rv) + rv = slice + } + return encodeStdlib(w, rv.Interface()) + } + + // Anything else we recursively encode ourselves. + length := rv.Len() + if err := writeStr(w, "["); err != nil { + return err + } + for i := 0; i < length; i++ { + if err := encodeReflect(w, rv.Index(i)); err != nil { + return err + } + if i < length-1 { + if err := writeStr(w, ","); err != nil { + return err + } + } + } + return writeStr(w, "]") +} + +func encodeReflectMap(w io.Writer, rv reflect.Value) error { + if rv.Type().Key().Kind() != reflect.String { + return errors.New("map key must be string") + } + + // nil maps are not emitted as nil, to retain Amino compatibility. + + if err := writeStr(w, "{"); err != nil { + return err + } + writeComma := false + for _, keyrv := range rv.MapKeys() { + if writeComma { + if err := writeStr(w, ","); err != nil { + return err + } + } + if err := encodeStdlib(w, keyrv.Interface()); err != nil { + return err + } + if err := writeStr(w, ":"); err != nil { + return err + } + if err := encodeReflect(w, rv.MapIndex(keyrv)); err != nil { + return err + } + writeComma = true + } + return writeStr(w, "}") +} + +func encodeReflectStruct(w io.Writer, rv reflect.Value) error { + sInfo := makeStructInfo(rv.Type()) + if err := writeStr(w, "{"); err != nil { + return err + } + writeComma := false + for i, fInfo := range sInfo.fields { + frv := rv.Field(i) + if fInfo.hidden || (fInfo.omitEmpty && frv.IsZero()) { + continue + } + + if writeComma { + if err := writeStr(w, ","); err != nil { + return err + } + } + if err := encodeStdlib(w, fInfo.jsonName); err != nil { + return err + } + if err := writeStr(w, ":"); err != nil { + return err + } + if err := encodeReflect(w, frv); err != nil { + return err + } + writeComma = true + } + return writeStr(w, "}") +} + +func encodeReflectInterface(w io.Writer, rv reflect.Value) error { + // Get concrete value and dereference pointers. + for rv.Kind() == reflect.Ptr || rv.Kind() == reflect.Interface { + if rv.IsNil() { + return writeStr(w, "null") + } + rv = rv.Elem() + } + + // Look up the name of the concrete type + name := typeRegistry.name(rv.Type()) + if name == "" { + return fmt.Errorf("cannot encode unregistered type %v", rv.Type()) + } + + // Write value wrapped in interface envelope + if err := writeStr(w, fmt.Sprintf(`{"type":%q,"value":`, name)); err != nil { + return err + } + if err := encodeReflect(w, rv); err != nil { + return err + } + return writeStr(w, "}") +} + +func encodeStdlib(w io.Writer, v interface{}) error { + // Doesn't stream the output because that adds a newline, as per: + // https://golang.org/pkg/encoding/json/#Encoder.Encode + blob, err := json.Marshal(v) + if err != nil { + return err + } + _, err = w.Write(blob) + return err +} + +func writeStr(w io.Writer, s string) error { + _, err := w.Write([]byte(s)) + return err +} diff --git a/comet/libs/json/structs.go b/comet/libs/json/structs.go new file mode 100755 index 00000000..b20873c3 --- /dev/null +++ b/comet/libs/json/structs.go @@ -0,0 +1,87 @@ +package json + +import ( + "fmt" + "reflect" + "strings" + "sync" + "unicode" +) + +var ( + // cache caches struct info. + cache = newStructInfoCache() +) + +// structCache is a cache of struct info. +type structInfoCache struct { + sync.RWMutex + structInfos map[reflect.Type]*structInfo +} + +func newStructInfoCache() *structInfoCache { + return &structInfoCache{ + structInfos: make(map[reflect.Type]*structInfo), + } +} + +func (c *structInfoCache) get(rt reflect.Type) *structInfo { + c.RLock() + defer c.RUnlock() + return c.structInfos[rt] +} + +func (c *structInfoCache) set(rt reflect.Type, sInfo *structInfo) { + c.Lock() + defer c.Unlock() + c.structInfos[rt] = sInfo +} + +// structInfo contains JSON info for a struct. +type structInfo struct { + fields []*fieldInfo +} + +// fieldInfo contains JSON info for a struct field. +type fieldInfo struct { + jsonName string + omitEmpty bool + hidden bool +} + +// makeStructInfo generates structInfo for a struct as a reflect.Value. +func makeStructInfo(rt reflect.Type) *structInfo { + if rt.Kind() != reflect.Struct { + panic(fmt.Sprintf("can't make struct info for non-struct value %v", rt)) + } + if sInfo := cache.get(rt); sInfo != nil { + return sInfo + } + fields := make([]*fieldInfo, 0, rt.NumField()) + for i := 0; i < cap(fields); i++ { + frt := rt.Field(i) + fInfo := &fieldInfo{ + jsonName: frt.Name, + omitEmpty: false, + hidden: frt.Name == "" || !unicode.IsUpper(rune(frt.Name[0])), + } + o := frt.Tag.Get("json") + if o == "-" { + fInfo.hidden = true + } else if o != "" { + opts := strings.Split(o, ",") + if opts[0] != "" { + fInfo.jsonName = opts[0] + } + for _, o := range opts[1:] { + if o == "omitempty" { + fInfo.omitEmpty = true + } + } + } + fields = append(fields, fInfo) + } + sInfo := &structInfo{fields: fields} + cache.set(rt, sInfo) + return sInfo +} diff --git a/comet/libs/json/types.go b/comet/libs/json/types.go new file mode 100755 index 00000000..01032af1 --- /dev/null +++ b/comet/libs/json/types.go @@ -0,0 +1,107 @@ +package json + +import ( + "errors" + "reflect" + "sync" +) + +var ( + // typeRegistry contains globally registered types for JSON encoding/decoding. + typeRegistry = newTypes() +) + +// RegisterType registers a type for Amino-compatible interface encoding in the global type +// registry. These types will be encoded with a type wrapper `{"type":"","value":}` +// regardless of which interface they are wrapped in (if any). If the type is a pointer, it will +// still be valid both for value and pointer types, but decoding into an interface will generate +// the a value or pointer based on the registered type. +// +// Should only be called in init() functions, as it panics on error. +func RegisterType(_type interface{}, name string) { + if _type == nil { + panic("cannot register nil type") + } + err := typeRegistry.register(name, reflect.ValueOf(_type).Type()) + if err != nil { + panic(err) + } +} + +// typeInfo contains type information. +type typeInfo struct { + name string + rt reflect.Type + returnPtr bool +} + +// types is a type registry. It is safe for concurrent use. +type types struct { + sync.RWMutex + byType map[reflect.Type]*typeInfo + byName map[string]*typeInfo +} + +// newTypes creates a new type registry. +func newTypes() types { + return types{ + byType: map[reflect.Type]*typeInfo{}, + byName: map[string]*typeInfo{}, + } +} + +// registers the given type with the given name. The name and type must not be registered already. +func (t *types) register(name string, rt reflect.Type) error { + if name == "" { + return errors.New("name cannot be empty") + } + // If this is a pointer type, we recursively resolve until we get a bare type, but register that + // we should return pointers. + returnPtr := false + for rt.Kind() == reflect.Ptr { + returnPtr = true + rt = rt.Elem() + } + tInfo := &typeInfo{ + name: name, + rt: rt, + returnPtr: returnPtr, + } + + t.Lock() + defer t.Unlock() + // if _, ok := t.byName[tInfo.name]; ok { + // return fmt.Errorf("a type with name %q is already registered", name) + // } + // if _, ok := t.byType[tInfo.rt]; ok { + // return fmt.Errorf("the type %v is already registered", rt) + // } + t.byName[name] = tInfo + t.byType[rt] = tInfo + return nil +} + +// lookup looks up a type from a name, or nil if not registered. +func (t *types) lookup(name string) (reflect.Type, bool) { + t.RLock() + defer t.RUnlock() + tInfo := t.byName[name] + if tInfo == nil { + return nil, false + } + return tInfo.rt, tInfo.returnPtr +} + +// name looks up the name of a type, or empty if not registered. Unwraps pointers as necessary. +func (t *types) name(rt reflect.Type) string { + for rt.Kind() == reflect.Ptr { + rt = rt.Elem() + } + t.RLock() + defer t.RUnlock() + tInfo := t.byType[rt] + if tInfo == nil { + return "" + } + return tInfo.name +} diff --git a/comet/libs/net/net.go b/comet/libs/net/net.go new file mode 100755 index 00000000..fa85256f --- /dev/null +++ b/comet/libs/net/net.go @@ -0,0 +1,43 @@ +package net + +import ( + "net" + "strings" +) + +// Connect dials the given address and returns a net.Conn. The protoAddr argument should be prefixed with the protocol, +// eg. "tcp://127.0.0.1:8080" or "unix:///tmp/test.sock" +func Connect(protoAddr string) (net.Conn, error) { + proto, address := ProtocolAndAddress(protoAddr) + conn, err := net.Dial(proto, address) + return conn, err +} + +// ProtocolAndAddress splits an address into the protocol and address components. +// For instance, "tcp://127.0.0.1:8080" will be split into "tcp" and "127.0.0.1:8080". +// If the address has no protocol prefix, the default is "tcp". +func ProtocolAndAddress(listenAddr string) (string, string) { + protocol, address := "tcp", listenAddr + parts := strings.SplitN(address, "://", 2) + if len(parts) == 2 { + protocol, address = parts[0], parts[1] + } + return protocol, address +} + +// GetFreePort gets a free port from the operating system. +// Ripped from https://github.com/phayes/freeport. +// BSD-licensed. +func GetFreePort() (int, error) { + addr, err := net.ResolveTCPAddr("tcp", "localhost:0") + if err != nil { + return 0, err + } + + l, err := net.ListenTCP("tcp", addr) + if err != nil { + return 0, err + } + defer l.Close() + return l.Addr().(*net.TCPAddr).Port, nil +} diff --git a/comet/libs/net/net_test.go b/comet/libs/net/net_test.go new file mode 100755 index 00000000..38cd58f6 --- /dev/null +++ b/comet/libs/net/net_test.go @@ -0,0 +1,38 @@ +package net + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestProtocolAndAddress(t *testing.T) { + + cases := []struct { + fullAddr string + proto string + addr string + }{ + { + "tcp://mydomain:80", + "tcp", + "mydomain:80", + }, + { + "mydomain:80", + "tcp", + "mydomain:80", + }, + { + "unix://mydomain:80", + "unix", + "mydomain:80", + }, + } + + for _, c := range cases { + proto, addr := ProtocolAndAddress(c.fullAddr) + assert.Equal(t, proto, c.proto) + assert.Equal(t, addr, c.addr) + } +} diff --git a/comet/libs/protoio/io.go b/comet/libs/protoio/io.go new file mode 100755 index 00000000..6244afd9 --- /dev/null +++ b/comet/libs/protoio/io.go @@ -0,0 +1,99 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Modified to return number of bytes written by Writer.WriteMsg(), and added byteReader. + +package protoio + +import ( + "io" + + "github.com/cosmos/gogoproto/proto" +) + +type Writer interface { + WriteMsg(proto.Message) (int, error) +} + +type WriteCloser interface { + Writer + io.Closer +} + +type Reader interface { + ReadMsg(msg proto.Message) (int, error) +} + +type ReadCloser interface { + Reader + io.Closer +} + +type marshaler interface { + MarshalTo(data []byte) (n int, err error) +} + +func getSize(v interface{}) (int, bool) { + if sz, ok := v.(interface { + Size() (n int) + }); ok { + return sz.Size(), true + } else if sz, ok := v.(interface { + ProtoSize() (n int) + }); ok { + return sz.ProtoSize(), true + } else { + return 0, false + } +} + +// byteReader wraps an io.Reader and implements io.ByteReader, required by +// binary.ReadUvarint(). Reading one byte at a time is extremely slow, but this +// is what Amino did previously anyway, and the caller can wrap the underlying +// reader in a bufio.Reader if appropriate. +type byteReader struct { + reader io.Reader + buf []byte + bytesRead int // keeps track of bytes read via ReadByte() +} + +func newByteReader(r io.Reader) *byteReader { + return &byteReader{ + reader: r, + buf: make([]byte, 1), + } +} + +func (r *byteReader) ReadByte() (byte, error) { + n, err := r.reader.Read(r.buf) + r.bytesRead += n + if err != nil { + return 0x00, err + } + return r.buf[0], nil +} diff --git a/comet/libs/protoio/io_test.go b/comet/libs/protoio/io_test.go new file mode 100755 index 00000000..6f050395 --- /dev/null +++ b/comet/libs/protoio/io_test.go @@ -0,0 +1,181 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package protoio_test + +import ( + "bytes" + "encoding/binary" + "fmt" + "io" + "math/rand" + "testing" + "time" + + "github.com/cosmos/gogoproto/proto" + "github.com/cosmos/gogoproto/test" + "github.com/stretchr/testify/require" + + "github.com/strangelove-ventures/horcrux/v3/comet/libs/protoio" +) + +func iotest(writer protoio.WriteCloser, reader protoio.ReadCloser) error { + varint := make([]byte, binary.MaxVarintLen64) + size := 1000 + msgs := make([]*test.NinOptNative, size) + lens := make([]int, size) + r := rand.New(rand.NewSource(time.Now().UnixNano())) + for i := range msgs { + msgs[i] = test.NewPopulatedNinOptNative(r, true) + // issue 31 + if i == 5 { + msgs[i] = &test.NinOptNative{} + } + // issue 31 + if i == 999 { + msgs[i] = &test.NinOptNative{} + } + // FIXME Check size + bz, err := proto.Marshal(msgs[i]) + if err != nil { + return err + } + visize := binary.PutUvarint(varint, uint64(len(bz))) + n, err := writer.WriteMsg(msgs[i]) + if err != nil { + return err + } + if n != len(bz)+visize { + return fmt.Errorf("WriteMsg() wrote %v bytes, expected %v", n, len(bz)+visize) + } + lens[i] = n + } + if err := writer.Close(); err != nil { + return err + } + i := 0 + for { + msg := &test.NinOptNative{} + if n, err := reader.ReadMsg(msg); err != nil { + if err == io.EOF { + break + } + return err + } else if n != lens[i] { + return fmt.Errorf("read %v bytes, expected %v", n, lens[i]) + } + if err := msg.VerboseEqual(msgs[i]); err != nil { + return err + } + i++ + } + if i != size { + panic("not enough messages read") + } + return reader.Close() +} + +type buffer struct { + *bytes.Buffer + closed bool +} + +func (b *buffer) Close() error { + b.closed = true + return nil +} + +func newBuffer() *buffer { + return &buffer{bytes.NewBuffer(nil), false} +} + +func TestVarintNormal(t *testing.T) { + buf := newBuffer() + writer := protoio.NewDelimitedWriter(buf) + reader := protoio.NewDelimitedReader(buf, 1024*1024) + err := iotest(writer, reader) + require.NoError(t, err) + require.True(t, buf.closed, "did not close buffer") +} + +func TestVarintNoClose(t *testing.T) { + buf := bytes.NewBuffer(nil) + writer := protoio.NewDelimitedWriter(buf) + reader := protoio.NewDelimitedReader(buf, 1024*1024) + err := iotest(writer, reader) + require.NoError(t, err) +} + +// issue 32 +func TestVarintMaxSize(t *testing.T) { + buf := newBuffer() + writer := protoio.NewDelimitedWriter(buf) + reader := protoio.NewDelimitedReader(buf, 20) + err := iotest(writer, reader) + require.Error(t, err) +} + +func TestVarintError(t *testing.T) { + buf := newBuffer() + buf.Write([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f}) + reader := protoio.NewDelimitedReader(buf, 1024*1024) + msg := &test.NinOptNative{} + n, err := reader.ReadMsg(msg) + require.Error(t, err) + require.Equal(t, 10, n) +} + +func TestVarintTruncated(t *testing.T) { + buf := newBuffer() + buf.Write([]byte{0xff, 0xff}) + reader := protoio.NewDelimitedReader(buf, 1024*1024) + msg := &test.NinOptNative{} + n, err := reader.ReadMsg(msg) + require.Error(t, err) + require.Equal(t, 2, n) +} + +func TestShort(t *testing.T) { + buf := newBuffer() + + varintBuf := make([]byte, binary.MaxVarintLen64) + varintLen := binary.PutUvarint(varintBuf, 100) + _, err := buf.Write(varintBuf[:varintLen]) + require.NoError(t, err) + + bz, err := proto.Marshal(&test.NinOptNative{Field15: []byte{0x01, 0x02, 0x03}}) + require.NoError(t, err) + buf.Write(bz) + + reader := protoio.NewDelimitedReader(buf, 1024*1024) + require.NoError(t, err) + msg := &test.NinOptNative{} + n, err := reader.ReadMsg(msg) + require.Error(t, err) + require.Equal(t, varintLen+len(bz), n) +} diff --git a/comet/libs/protoio/reader.go b/comet/libs/protoio/reader.go new file mode 100755 index 00000000..95b8d345 --- /dev/null +++ b/comet/libs/protoio/reader.go @@ -0,0 +1,106 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Modified from original GoGo Protobuf to not buffer the reader. + +package protoio + +import ( + "bytes" + "encoding/binary" + "fmt" + "io" + + "github.com/cosmos/gogoproto/proto" +) + +// NewDelimitedReader reads varint-delimited Protobuf messages from a reader. +// Unlike the gogoproto NewDelimitedReader, this does not buffer the reader, +// which may cause poor performance but is necessary when only reading single +// messages (e.g. in the p2p package). It also returns the number of bytes +// read, which is necessary for the p2p package. +func NewDelimitedReader(r io.Reader, maxSize int) ReadCloser { + var closer io.Closer + if c, ok := r.(io.Closer); ok { + closer = c + } + return &varintReader{r, nil, maxSize, closer} +} + +type varintReader struct { + r io.Reader + buf []byte + maxSize int + closer io.Closer +} + +func (r *varintReader) ReadMsg(msg proto.Message) (int, error) { + // ReadUvarint needs an io.ByteReader, and we also need to keep track of the + // number of bytes read, so we use our own byteReader. This can't be + // buffered, so the caller should pass a buffered io.Reader to avoid poor + // performance. + byteReader := newByteReader(r.r) + l, err := binary.ReadUvarint(byteReader) + n := byteReader.bytesRead + if err != nil { + return n, err + } + + // Make sure length doesn't overflow the native int size (e.g. 32-bit), + // and that the returned sum of n+length doesn't overflow either. + length := int(l) + if l >= uint64(^uint(0)>>1) || length < 0 || n+length < 0 { + return n, fmt.Errorf("invalid out-of-range message length %v", l) + } + if length > r.maxSize { + return n, fmt.Errorf("message exceeds max size (%v > %v)", length, r.maxSize) + } + + if len(r.buf) < length { + r.buf = make([]byte, length) + } + buf := r.buf[:length] + nr, err := io.ReadFull(r.r, buf) + n += nr + if err != nil { + return n, err + } + return n, proto.Unmarshal(buf, msg) +} + +func (r *varintReader) Close() error { + if r.closer != nil { + return r.closer.Close() + } + return nil +} + +func UnmarshalDelimited(data []byte, msg proto.Message) error { + _, err := NewDelimitedReader(bytes.NewReader(data), len(data)).ReadMsg(msg) + return err +} diff --git a/comet/libs/protoio/writer.go b/comet/libs/protoio/writer.go new file mode 100755 index 00000000..0eb65850 --- /dev/null +++ b/comet/libs/protoio/writer.go @@ -0,0 +1,100 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2013, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Modified from original GoGo Protobuf to return number of bytes written. + +package protoio + +import ( + "bytes" + "encoding/binary" + "io" + + "github.com/cosmos/gogoproto/proto" +) + +// NewDelimitedWriter writes a varint-delimited Protobuf message to a writer. It is +// equivalent to the gogoproto NewDelimitedWriter, except WriteMsg() also returns the +// number of bytes written, which is necessary in the p2p package. +func NewDelimitedWriter(w io.Writer) WriteCloser { + return &varintWriter{w, make([]byte, binary.MaxVarintLen64), nil} +} + +type varintWriter struct { + w io.Writer + lenBuf []byte + buffer []byte +} + +func (w *varintWriter) WriteMsg(msg proto.Message) (int, error) { + if m, ok := msg.(marshaler); ok { + n, ok := getSize(m) + if ok { + if n+binary.MaxVarintLen64 >= len(w.buffer) { + w.buffer = make([]byte, n+binary.MaxVarintLen64) + } + lenOff := binary.PutUvarint(w.buffer, uint64(n)) + _, err := m.MarshalTo(w.buffer[lenOff:]) + if err != nil { + return 0, err + } + _, err = w.w.Write(w.buffer[:lenOff+n]) + return lenOff + n, err + } + } + + // fallback + data, err := proto.Marshal(msg) + if err != nil { + return 0, err + } + length := uint64(len(data)) + n := binary.PutUvarint(w.lenBuf, length) + _, err = w.w.Write(w.lenBuf[:n]) + if err != nil { + return 0, err + } + _, err = w.w.Write(data) + return len(data) + n, err +} + +func (w *varintWriter) Close() error { + if closer, ok := w.w.(io.Closer); ok { + return closer.Close() + } + return nil +} + +func MarshalDelimited(msg proto.Message) ([]byte, error) { + var buf bytes.Buffer + _, err := NewDelimitedWriter(&buf).WriteMsg(msg) + if err != nil { + return nil, err + } + return buf.Bytes(), nil +} diff --git a/comet/libs/tempfile/tempfile.go b/comet/libs/tempfile/tempfile.go new file mode 100755 index 00000000..e30d5a8c --- /dev/null +++ b/comet/libs/tempfile/tempfile.go @@ -0,0 +1,128 @@ +package tempfile + +import ( + "fmt" + "io" + "os" + "path/filepath" + "strconv" + "strings" + "sync" + "time" +) + +const ( + atomicWriteFilePrefix = "write-file-atomic-" + // Maximum number of atomic write file conflicts before we start reseeding + // (reduced from golang's default 10 due to using an increased randomness space) + atomicWriteFileMaxNumConflicts = 5 + // Maximum number of attempts to make at writing the write file before giving up + // (reduced from golang's default 10000 due to using an increased randomness space) + atomicWriteFileMaxNumWriteAttempts = 1000 + // LCG constants from Donald Knuth MMIX + // This LCG's has a period equal to 2**64 + lcgA = 6364136223846793005 + lcgC = 1442695040888963407 + // Create in case it doesn't exist and force kernel + // flush, which still leaves the potential of lingering disk cache. + // Never overwrites files + atomicWriteFileFlag = os.O_WRONLY | os.O_CREATE | os.O_SYNC | os.O_TRUNC | os.O_EXCL +) + +var ( + atomicWriteFileRand uint64 + atomicWriteFileRandMu sync.Mutex +) + +func writeFileRandReseed() uint64 { + // Scale the PID, to minimize the chance that two processes seeded at similar times + // don't get the same seed. Note that PID typically ranges in [0, 2**15), but can be + // up to 2**22 under certain configurations. We left bit-shift the PID by 20, so that + // a PID difference of one corresponds to a time difference of 2048 seconds. + // The important thing here is that now for a seed conflict, they would both have to be on + // the correct nanosecond offset, and second-based offset, which is much less likely than + // just a conflict with the correct nanosecond offset. + return uint64(time.Now().UnixNano() + int64(os.Getpid()<<20)) +} + +// Use a fast thread safe LCG for atomic write file names. +// Returns a string corresponding to a 64 bit int. +// If it was a negative int, the leading number is a 0. +func randWriteFileSuffix() string { + atomicWriteFileRandMu.Lock() + r := atomicWriteFileRand + if r == 0 { + r = writeFileRandReseed() + } + + // Update randomness according to lcg + r = r*lcgA + lcgC + + atomicWriteFileRand = r + atomicWriteFileRandMu.Unlock() + // Can have a negative name, replace this in the following + suffix := strconv.Itoa(int(r)) + if string(suffix[0]) == "-" { + // Replace first "-" with "0". This is purely for UI clarity, + // as otherwhise there would be two `-` in a row. + suffix = strings.Replace(suffix, "-", "0", 1) + } + return suffix +} + +// WriteFileAtomic creates a temporary file with data and provided perm and +// swaps it atomically with filename if successful. +func WriteFileAtomic(filename string, data []byte, perm os.FileMode) (err error) { + // This implementation is inspired by the golang stdlibs method of creating + // tempfiles. Notable differences are that we use different flags, a 64 bit LCG + // and handle negatives differently. + // The core reason we can't use golang's TempFile is that we must write + // to the file synchronously, as we need this to persist to disk. + // We also open it in write-only mode, to avoid concerns that arise with read. + var ( + dir = filepath.Dir(filename) + f *os.File + ) + + nconflict := 0 + // Limit the number of attempts to create a file. Something is seriously + // wrong if it didn't get created after 1000 attempts, and we don't want + // an infinite loop + i := 0 + for ; i < atomicWriteFileMaxNumWriteAttempts; i++ { + name := filepath.Join(dir, atomicWriteFilePrefix+randWriteFileSuffix()) + f, err = os.OpenFile(name, atomicWriteFileFlag, perm) + // If the file already exists, try a new file + if os.IsExist(err) { + // If the files exists too many times, start reseeding as we've + // likely hit another instances seed. + if nconflict++; nconflict > atomicWriteFileMaxNumConflicts { + atomicWriteFileRandMu.Lock() + atomicWriteFileRand = writeFileRandReseed() + atomicWriteFileRandMu.Unlock() + } + continue + } else if err != nil { + return err + } + break + } + if i == atomicWriteFileMaxNumWriteAttempts { + return fmt.Errorf("could not create atomic write file after %d attempts", i) + } + + // Clean up in any case. Defer stacking order is last-in-first-out. + defer os.Remove(f.Name()) + defer f.Close() + + if n, err := f.Write(data); err != nil { + return err + } else if n < len(data) { + return io.ErrShortWrite + } + // Close the file before renaming it, otherwise it will cause "The process + // cannot access the file because it is being used by another process." on windows. + f.Close() + + return os.Rename(f.Name(), filename) +} diff --git a/comet/p2p/conn/secret_connection.go b/comet/p2p/conn/secret_connection.go new file mode 100755 index 00000000..5c104109 --- /dev/null +++ b/comet/p2p/conn/secret_connection.go @@ -0,0 +1,462 @@ +package conn + +import ( + "bytes" + "crypto/cipher" + crand "crypto/rand" + "crypto/sha256" + "encoding/binary" + "errors" + "fmt" + "io" + "math" + "net" + "sync" + "time" + + gogotypes "github.com/cosmos/gogoproto/types" + pool "github.com/libp2p/go-buffer-pool" + "github.com/oasisprotocol/curve25519-voi/primitives/merlin" + "golang.org/x/crypto/chacha20poly1305" + "golang.org/x/crypto/curve25519" + "golang.org/x/crypto/hkdf" + "golang.org/x/crypto/nacl/box" + + "github.com/strangelove-ventures/horcrux/v3/comet/crypto" + "github.com/strangelove-ventures/horcrux/v3/comet/crypto/ed25519" + cryptoenc "github.com/strangelove-ventures/horcrux/v3/comet/encoding" + "github.com/strangelove-ventures/horcrux/v3/comet/libs/async" + "github.com/strangelove-ventures/horcrux/v3/comet/libs/protoio" + tmp2p "github.com/strangelove-ventures/horcrux/v3/comet/proto/p2p" +) + +// 4 + 1024 == 1028 total frame size +const ( + dataLenSize = 4 + dataMaxSize = 1024 + totalFrameSize = dataMaxSize + dataLenSize + aeadSizeOverhead = 16 // overhead of poly 1305 authentication tag + aeadKeySize = chacha20poly1305.KeySize + aeadNonceSize = chacha20poly1305.NonceSize + + labelEphemeralLowerPublicKey = "EPHEMERAL_LOWER_PUBLIC_KEY" + labelEphemeralUpperPublicKey = "EPHEMERAL_UPPER_PUBLIC_KEY" + labelDHSecret = "DH_SECRET" + labelSecretConnectionMac = "SECRET_CONNECTION_MAC" +) + +var ( + ErrSmallOrderRemotePubKey = errors.New("detected low order point from remote peer") + + secretConnKeyAndChallengeGen = []byte("TENDERMINT_SECRET_CONNECTION_KEY_AND_CHALLENGE_GEN") +) + +// SecretConnection implements net.Conn. +// It is an implementation of the STS protocol. +// See https://github.com/cometbft/cometbft/blob/0.1/docs/sts-final.pdf for +// details on the protocol. +// +// Consumers of the SecretConnection are responsible for authenticating +// the remote peer's pubkey against known information, like a nodeID. +// Otherwise they are vulnerable to MITM. +// (TODO(ismail): see also https://github.com/tendermint/tendermint/issues/3010) +type SecretConnection struct { + + // immutable + recvAead cipher.AEAD + sendAead cipher.AEAD + + remPubKey crypto.PubKey + conn io.ReadWriteCloser + + // net.Conn must be thread safe: + // https://golang.org/pkg/net/#Conn. + // Since we have internal mutable state, + // we need mtxs. But recv and send states + // are independent, so we can use two mtxs. + // All .Read are covered by recvMtx, + // all .Write are covered by sendMtx. + recvMtx sync.Mutex + recvBuffer []byte + recvNonce *[aeadNonceSize]byte + + sendMtx sync.Mutex + sendNonce *[aeadNonceSize]byte +} + +// MakeSecretConnection performs handshake and returns a new authenticated +// SecretConnection. +// Returns nil if there is an error in handshake. +// Caller should call conn.Close() +// See docs/sts-final.pdf for more information. +func MakeSecretConnection(conn io.ReadWriteCloser, locPrivKey crypto.PrivKey) (*SecretConnection, error) { + var ( + locPubKey = locPrivKey.PubKey() + ) + + // Generate ephemeral keys for perfect forward secrecy. + locEphPub, locEphPriv := genEphKeys() + + // Write local ephemeral pubkey and receive one too. + // NOTE: every 32-byte string is accepted as a Curve25519 public key (see + // DJB's Curve25519 paper: http://cr.yp.to/ecdh/curve25519-20060209.pdf) + remEphPub, err := shareEphPubKey(conn, locEphPub) + if err != nil { + return nil, err + } + + // Sort by lexical order. + loEphPub, hiEphPub := sort32(locEphPub, remEphPub) + + transcript := merlin.NewTranscript("TENDERMINT_SECRET_CONNECTION_TRANSCRIPT_HASH") + + transcript.AppendMessage(labelEphemeralLowerPublicKey, loEphPub[:]) + transcript.AppendMessage(labelEphemeralUpperPublicKey, hiEphPub[:]) + + // Check if the local ephemeral public key was the least, lexicographically + // sorted. + locIsLeast := bytes.Equal(locEphPub[:], loEphPub[:]) + + // Compute common diffie hellman secret using X25519. + dhSecret, err := computeDHSecret(remEphPub, locEphPriv) + if err != nil { + return nil, err + } + + transcript.AppendMessage(labelDHSecret, dhSecret[:]) + + // Generate the secret used for receiving, sending, challenge via HKDF-SHA2 + // on the transcript state (which itself also uses HKDF-SHA2 to derive a key + // from the dhSecret). + recvSecret, sendSecret := deriveSecrets(dhSecret, locIsLeast) + + const challengeSize = 32 + var challenge [challengeSize]byte + transcript.ExtractBytes(challenge[:], labelSecretConnectionMac) + + sendAead, err := chacha20poly1305.New(sendSecret[:]) + if err != nil { + return nil, errors.New("invalid send SecretConnection Key") + } + recvAead, err := chacha20poly1305.New(recvSecret[:]) + if err != nil { + return nil, errors.New("invalid receive SecretConnection Key") + } + + sc := &SecretConnection{ + conn: conn, + recvBuffer: nil, + recvNonce: new([aeadNonceSize]byte), + sendNonce: new([aeadNonceSize]byte), + recvAead: recvAead, + sendAead: sendAead, + } + + // Sign the challenge bytes for authentication. + locSignature, err := signChallenge(&challenge, locPrivKey) + if err != nil { + return nil, err + } + + // Share (in secret) each other's pubkey & challenge signature + authSigMsg, err := shareAuthSignature(sc, locPubKey, locSignature) + if err != nil { + return nil, err + } + + remPubKey, remSignature := authSigMsg.Key, authSigMsg.Sig + if _, ok := remPubKey.(ed25519.PubKey); !ok { + return nil, fmt.Errorf("expected ed25519 pubkey, got %T", remPubKey) + } + if !remPubKey.VerifySignature(challenge[:], remSignature) { + return nil, errors.New("challenge verification failed") + } + + // We've authorized. + sc.remPubKey = remPubKey + return sc, nil +} + +// RemotePubKey returns authenticated remote pubkey +func (sc *SecretConnection) RemotePubKey() crypto.PubKey { + return sc.remPubKey +} + +// Writes encrypted frames of `totalFrameSize + aeadSizeOverhead`. +// CONTRACT: data smaller than dataMaxSize is written atomically. +func (sc *SecretConnection) Write(data []byte) (n int, err error) { + sc.sendMtx.Lock() + defer sc.sendMtx.Unlock() + + for 0 < len(data) { + if err := func() error { + var sealedFrame = pool.Get(aeadSizeOverhead + totalFrameSize) + var frame = pool.Get(totalFrameSize) + defer func() { + pool.Put(sealedFrame) + pool.Put(frame) + }() + var chunk []byte + if dataMaxSize < len(data) { + chunk = data[:dataMaxSize] + data = data[dataMaxSize:] + } else { + chunk = data + data = nil + } + chunkLength := len(chunk) + binary.LittleEndian.PutUint32(frame, uint32(chunkLength)) + copy(frame[dataLenSize:], chunk) + + // encrypt the frame + sc.sendAead.Seal(sealedFrame[:0], sc.sendNonce[:], frame, nil) + incrNonce(sc.sendNonce) + // end encryption + + _, err = sc.conn.Write(sealedFrame) + if err != nil { + return err + } + n += len(chunk) + return nil + }(); err != nil { + return n, err + } + } + return n, err +} + +// CONTRACT: data smaller than dataMaxSize is read atomically. +func (sc *SecretConnection) Read(data []byte) (n int, err error) { + sc.recvMtx.Lock() + defer sc.recvMtx.Unlock() + + // read off and update the recvBuffer, if non-empty + if 0 < len(sc.recvBuffer) { + n = copy(data, sc.recvBuffer) + sc.recvBuffer = sc.recvBuffer[n:] + return n, err + } + + // read off the conn + var sealedFrame = pool.Get(aeadSizeOverhead + totalFrameSize) + defer pool.Put(sealedFrame) + _, err = io.ReadFull(sc.conn, sealedFrame) + if err != nil { + return n, err + } + + // decrypt the frame. + // reads and updates the sc.recvNonce + var frame = pool.Get(totalFrameSize) + defer pool.Put(frame) + _, err = sc.recvAead.Open(frame[:0], sc.recvNonce[:], sealedFrame, nil) + if err != nil { + return n, fmt.Errorf("failed to decrypt SecretConnection: %w", err) + } + incrNonce(sc.recvNonce) + // end decryption + + // copy checkLength worth into data, + // set recvBuffer to the rest. + var chunkLength = binary.LittleEndian.Uint32(frame) // read the first four bytes + if chunkLength > dataMaxSize { + return 0, errors.New("chunkLength is greater than dataMaxSize") + } + var chunk = frame[dataLenSize : dataLenSize+chunkLength] + n = copy(data, chunk) + if n < len(chunk) { + sc.recvBuffer = make([]byte, len(chunk)-n) + copy(sc.recvBuffer, chunk[n:]) + } + return n, err +} + +// Implements net.Conn +func (sc *SecretConnection) Close() error { return sc.conn.Close() } +func (sc *SecretConnection) LocalAddr() net.Addr { return sc.conn.(net.Conn).LocalAddr() } +func (sc *SecretConnection) RemoteAddr() net.Addr { return sc.conn.(net.Conn).RemoteAddr() } +func (sc *SecretConnection) SetDeadline(t time.Time) error { return sc.conn.(net.Conn).SetDeadline(t) } +func (sc *SecretConnection) SetReadDeadline(t time.Time) error { + return sc.conn.(net.Conn).SetReadDeadline(t) +} +func (sc *SecretConnection) SetWriteDeadline(t time.Time) error { + return sc.conn.(net.Conn).SetWriteDeadline(t) +} + +func genEphKeys() (ephPub, ephPriv *[32]byte) { + var err error + // TODO: Probably not a problem but ask Tony: different from the rust implementation (uses x25519-dalek), + // we do not "clamp" the private key scalar: + // see: https://github.com/dalek-cryptography/x25519-dalek/blob/34676d336049df2bba763cc076a75e47ae1f170f/src/x25519.rs#L56-L74 + ephPub, ephPriv, err = box.GenerateKey(crand.Reader) + if err != nil { + panic("Could not generate ephemeral key-pair") + } + return +} + +func shareEphPubKey(conn io.ReadWriter, locEphPub *[32]byte) (remEphPub *[32]byte, err error) { + + // Send our pubkey and receive theirs in tandem. + var trs, _ = async.Parallel( + func(_ int) (val interface{}, abort bool, err error) { + lc := *locEphPub + _, err = protoio.NewDelimitedWriter(conn).WriteMsg(&gogotypes.BytesValue{Value: lc[:]}) + if err != nil { + return nil, true, err // abort + } + return nil, false, nil + }, + func(_ int) (val interface{}, abort bool, err error) { + var bytes gogotypes.BytesValue + _, err = protoio.NewDelimitedReader(conn, 1024*1024).ReadMsg(&bytes) + if err != nil { + return nil, true, err // abort + } + + var _remEphPub [32]byte + copy(_remEphPub[:], bytes.Value) + return _remEphPub, false, nil + }, + ) + + // If error: + if trs.FirstError() != nil { + err = trs.FirstError() + return remEphPub, err + } + + // Otherwise: + var _remEphPub = trs.FirstValue().([32]byte) + return &_remEphPub, nil +} + +func deriveSecrets( + dhSecret *[32]byte, + locIsLeast bool, +) (recvSecret, sendSecret *[aeadKeySize]byte) { + hash := sha256.New + hkdf := hkdf.New(hash, dhSecret[:], nil, secretConnKeyAndChallengeGen) + // get enough data for 2 aead keys, and a 32 byte challenge + res := new([2*aeadKeySize + 32]byte) + _, err := io.ReadFull(hkdf, res[:]) + if err != nil { + panic(err) + } + + recvSecret = new([aeadKeySize]byte) + sendSecret = new([aeadKeySize]byte) + + // bytes 0 through aeadKeySize - 1 are one aead key. + // bytes aeadKeySize through 2*aeadKeySize -1 are another aead key. + // which key corresponds to sending and receiving key depends on whether + // the local key is less than the remote key. + if locIsLeast { + copy(recvSecret[:], res[0:aeadKeySize]) + copy(sendSecret[:], res[aeadKeySize:aeadKeySize*2]) + } else { + copy(sendSecret[:], res[0:aeadKeySize]) + copy(recvSecret[:], res[aeadKeySize:aeadKeySize*2]) + } + + return +} + +// computeDHSecret computes a Diffie-Hellman shared secret key +// from our own local private key and the other's public key. +func computeDHSecret(remPubKey, locPrivKey *[32]byte) (*[32]byte, error) { + shrKey, err := curve25519.X25519(locPrivKey[:], remPubKey[:]) + if err != nil { + return nil, err + } + var shrKeyArray [32]byte + copy(shrKeyArray[:], shrKey) + return &shrKeyArray, nil +} + +func sort32(foo, bar *[32]byte) (lo, hi *[32]byte) { + if bytes.Compare(foo[:], bar[:]) < 0 { + lo = foo + hi = bar + } else { + lo = bar + hi = foo + } + return +} + +func signChallenge(challenge *[32]byte, locPrivKey crypto.PrivKey) ([]byte, error) { + signature, err := locPrivKey.Sign(challenge[:]) + if err != nil { + return nil, err + } + return signature, nil +} + +type authSigMessage struct { + Key crypto.PubKey + Sig []byte +} + +func shareAuthSignature(sc io.ReadWriter, pubKey crypto.PubKey, signature []byte) (recvMsg authSigMessage, err error) { + + // Send our info and receive theirs in tandem. + var trs, _ = async.Parallel( + func(_ int) (val interface{}, abort bool, err error) { + pbpk, err := cryptoenc.PubKeyToProto(pubKey) + if err != nil { + return nil, true, err + } + _, err = protoio.NewDelimitedWriter(sc).WriteMsg(&tmp2p.AuthSigMessage{PubKey: pbpk, Sig: signature}) + if err != nil { + return nil, true, err // abort + } + return nil, false, nil + }, + func(_ int) (val interface{}, abort bool, err error) { + var pba tmp2p.AuthSigMessage + _, err = protoio.NewDelimitedReader(sc, 1024*1024).ReadMsg(&pba) + if err != nil { + return nil, true, err // abort + } + + pk, err := cryptoenc.PubKeyFromProto(pba.PubKey) + if err != nil { + return nil, true, err // abort + } + + _recvMsg := authSigMessage{ + Key: pk, + Sig: pba.Sig, + } + return _recvMsg, false, nil + }, + ) + + // If error: + if trs.FirstError() != nil { + err = trs.FirstError() + return recvMsg, err + } + + var _recvMsg = trs.FirstValue().(authSigMessage) + return _recvMsg, nil +} + +//-------------------------------------------------------------------------------- + +// Increment nonce little-endian by 1 with wraparound. +// Due to chacha20poly1305 expecting a 12 byte nonce we do not use the first four +// bytes. We only increment a 64 bit unsigned int in the remaining 8 bytes +// (little-endian in nonce[4:]). +func incrNonce(nonce *[aeadNonceSize]byte) { + counter := binary.LittleEndian.Uint64(nonce[4:]) + if counter == math.MaxUint64 { + // Terminates the session and makes sure the nonce would not re-used. + // See https://github.com/tendermint/tendermint/issues/3531 + panic("can't increase nonce without overflow") + } + counter++ + binary.LittleEndian.PutUint64(nonce[4:], counter) +} diff --git a/signer/file.go b/comet/privval/file.go old mode 100644 new mode 100755 similarity index 91% rename from signer/file.go rename to comet/privval/file.go index ff2b02d7..92a868c7 --- a/signer/file.go +++ b/comet/privval/file.go @@ -1,4 +1,4 @@ -package signer +package privval import ( "bytes" @@ -8,23 +8,29 @@ import ( "time" "github.com/cosmos/gogoproto/proto" + "github.com/strangelove-ventures/horcrux/v3/comet/crypto" + "github.com/strangelove-ventures/horcrux/v3/comet/crypto/ed25519" + cometjson "github.com/strangelove-ventures/horcrux/v3/comet/libs/json" + "github.com/strangelove-ventures/horcrux/v3/comet/libs/protoio" + "github.com/strangelove-ventures/horcrux/v3/comet/libs/tempfile" + cometproto "github.com/strangelove-ventures/horcrux/v3/comet/proto/types" + comettypes "github.com/strangelove-ventures/horcrux/v3/comet/types" + "github.com/strangelove-ventures/horcrux/v3/types" +) - "github.com/cometbft/cometbft/crypto" - "github.com/cometbft/cometbft/crypto/ed25519" - cometjson "github.com/cometbft/cometbft/libs/json" - "github.com/cometbft/cometbft/libs/protoio" - "github.com/cometbft/cometbft/libs/tempfile" - cometproto "github.com/cometbft/cometbft/proto/tendermint/types" - "github.com/cometbft/cometbft/types" +const ( + stepPropose int8 = 1 + stepPrevote int8 = 2 + stepPrecommit int8 = 3 ) //------------------------------------------------------------------------------- // FilePVKey stores the immutable part of PrivValidator. type FilePVKey struct { - Address types.Address `json:"address"` - PubKey crypto.PubKey `json:"pub_key"` - PrivKey crypto.PrivKey `json:"priv_key"` + Address comettypes.Address `json:"address"` + PubKey crypto.PubKey `json:"pub_key"` + PrivKey crypto.PrivKey `json:"priv_key"` filePath string } @@ -190,7 +196,7 @@ func LoadFilePV(keyFilePath, stateFilePath string, loadState bool) (*FilePV, err // GetAddress returns the address of the validator. // Implements PrivValidator. -func (pv *FilePV) GetAddress() types.Address { +func (pv *FilePV) GetAddress() comettypes.Address { return pv.Key.Address } @@ -200,7 +206,7 @@ func (pv *FilePV) GetPubKey() (crypto.PubKey, error) { return pv.Key.PubKey, nil } -func (pv *FilePV) Sign(block Block) ([]byte, time.Time, error) { +func (pv *FilePV) Sign(block types.Block) ([]byte, time.Time, error) { height, round, step, signBytes := block.Height, int32(block.Round), block.Step, block.SignBytes lss := pv.LastSignState diff --git a/signer/proto/keys.pb.go b/comet/proto/crypto/keys.pb.go similarity index 97% rename from signer/proto/keys.pb.go rename to comet/proto/crypto/keys.pb.go index 49a5785e..b1c73f93 100644 --- a/signer/proto/keys.pb.go +++ b/comet/proto/crypto/keys.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: tendermint/crypto/keys.proto -package proto +package crypto import ( bytes "bytes" @@ -127,13 +127,13 @@ func (*PublicKey) XXX_OneofWrappers() []interface{} { } func init() { - // proto.RegisterType((*PublicKey)(nil), "tendermint.crypto.PublicKey") + proto.RegisterType((*PublicKey)(nil), "tendermint.crypto.PublicKey") } func init() { proto.RegisterFile("tendermint/crypto/keys.proto", fileDescriptor_cb048658b234868c) } var fileDescriptor_cb048658b234868c = []byte{ - // 246 bytes of a gzipped FileDescriptorProto + // 247 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, @@ -143,13 +143,13 @@ var fileDescriptor_cb048658b234868c = []byte{ 0x8e, 0x8b, 0xb3, 0x38, 0x35, 0xb9, 0xc0, 0xc8, 0xd4, 0x2c, 0xdb, 0x50, 0x82, 0x09, 0x2a, 0x8b, 0x10, 0x12, 0x12, 0xe3, 0x62, 0x4d, 0xca, 0x33, 0x32, 0x35, 0x91, 0x60, 0x86, 0xca, 0x41, 0xb8, 0x56, 0x1c, 0x2f, 0x16, 0xc8, 0x33, 0xbe, 0x58, 0x28, 0xcf, 0xe8, 0xc4, 0xca, 0xc5, 0x5c, 0x5c, - 0x9a, 0xeb, 0x14, 0x78, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, - 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0xe6, 0xe9, + 0x9a, 0xeb, 0x14, 0x7e, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, + 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0xb6, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xc5, 0x25, 0x45, 0x89, 0x79, 0xe9, 0xa9, 0x39, 0xf9, 0x65, 0xa9, 0xba, 0x65, 0xa9, 0x79, 0x25, 0xa5, 0x45, 0xa9, 0xc5, 0xfa, 0x19, - 0xf9, 0x45, 0xc9, 0x45, 0xa5, 0x15, 0xfa, 0x65, 0xc6, 0xfa, 0xc5, 0x99, 0xe9, 0x79, 0xa9, 0x45, - 0xfa, 0x60, 0x4f, 0x24, 0xb1, 0x81, 0x29, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf5, 0xb1, - 0x83, 0x2a, 0x14, 0x01, 0x00, 0x00, + 0xf9, 0x45, 0xc9, 0x45, 0xa5, 0x15, 0xfa, 0x65, 0xc6, 0xfa, 0xc9, 0xf9, 0xb9, 0xa9, 0x25, 0xfa, + 0x10, 0xef, 0x40, 0x3c, 0x98, 0xc4, 0x06, 0xe6, 0x19, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0xb4, + 0xc0, 0xf5, 0x3e, 0x1a, 0x01, 0x00, 0x00, } func (this *PublicKey) Compare(that interface{}) int { diff --git a/comet/proto/p2p/conn.pb.go b/comet/proto/p2p/conn.pb.go new file mode 100644 index 00000000..7c768937 --- /dev/null +++ b/comet/proto/p2p/conn.pb.go @@ -0,0 +1,1272 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: tendermint/p2p/conn.proto + +package p2p + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + crypto "github.com/strangelove-ventures/horcrux/v3/comet/proto/crypto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type PacketPing struct { +} + +func (m *PacketPing) Reset() { *m = PacketPing{} } +func (m *PacketPing) String() string { return proto.CompactTextString(m) } +func (*PacketPing) ProtoMessage() {} +func (*PacketPing) Descriptor() ([]byte, []int) { + return fileDescriptor_22474b5527c8fa9f, []int{0} +} +func (m *PacketPing) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PacketPing) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PacketPing.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *PacketPing) XXX_Merge(src proto.Message) { + xxx_messageInfo_PacketPing.Merge(m, src) +} +func (m *PacketPing) XXX_Size() int { + return m.Size() +} +func (m *PacketPing) XXX_DiscardUnknown() { + xxx_messageInfo_PacketPing.DiscardUnknown(m) +} + +var xxx_messageInfo_PacketPing proto.InternalMessageInfo + +type PacketPong struct { +} + +func (m *PacketPong) Reset() { *m = PacketPong{} } +func (m *PacketPong) String() string { return proto.CompactTextString(m) } +func (*PacketPong) ProtoMessage() {} +func (*PacketPong) Descriptor() ([]byte, []int) { + return fileDescriptor_22474b5527c8fa9f, []int{1} +} +func (m *PacketPong) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PacketPong) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PacketPong.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *PacketPong) XXX_Merge(src proto.Message) { + xxx_messageInfo_PacketPong.Merge(m, src) +} +func (m *PacketPong) XXX_Size() int { + return m.Size() +} +func (m *PacketPong) XXX_DiscardUnknown() { + xxx_messageInfo_PacketPong.DiscardUnknown(m) +} + +var xxx_messageInfo_PacketPong proto.InternalMessageInfo + +type PacketMsg struct { + ChannelID int32 `protobuf:"varint,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` + EOF bool `protobuf:"varint,2,opt,name=eof,proto3" json:"eof,omitempty"` + Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` +} + +func (m *PacketMsg) Reset() { *m = PacketMsg{} } +func (m *PacketMsg) String() string { return proto.CompactTextString(m) } +func (*PacketMsg) ProtoMessage() {} +func (*PacketMsg) Descriptor() ([]byte, []int) { + return fileDescriptor_22474b5527c8fa9f, []int{2} +} +func (m *PacketMsg) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PacketMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PacketMsg.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *PacketMsg) XXX_Merge(src proto.Message) { + xxx_messageInfo_PacketMsg.Merge(m, src) +} +func (m *PacketMsg) XXX_Size() int { + return m.Size() +} +func (m *PacketMsg) XXX_DiscardUnknown() { + xxx_messageInfo_PacketMsg.DiscardUnknown(m) +} + +var xxx_messageInfo_PacketMsg proto.InternalMessageInfo + +func (m *PacketMsg) GetChannelID() int32 { + if m != nil { + return m.ChannelID + } + return 0 +} + +func (m *PacketMsg) GetEOF() bool { + if m != nil { + return m.EOF + } + return false +} + +func (m *PacketMsg) GetData() []byte { + if m != nil { + return m.Data + } + return nil +} + +type Packet struct { + // Types that are valid to be assigned to Sum: + // + // *Packet_PacketPing + // *Packet_PacketPong + // *Packet_PacketMsg + Sum isPacket_Sum `protobuf_oneof:"sum"` +} + +func (m *Packet) Reset() { *m = Packet{} } +func (m *Packet) String() string { return proto.CompactTextString(m) } +func (*Packet) ProtoMessage() {} +func (*Packet) Descriptor() ([]byte, []int) { + return fileDescriptor_22474b5527c8fa9f, []int{3} +} +func (m *Packet) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Packet) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Packet.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Packet) XXX_Merge(src proto.Message) { + xxx_messageInfo_Packet.Merge(m, src) +} +func (m *Packet) XXX_Size() int { + return m.Size() +} +func (m *Packet) XXX_DiscardUnknown() { + xxx_messageInfo_Packet.DiscardUnknown(m) +} + +var xxx_messageInfo_Packet proto.InternalMessageInfo + +type isPacket_Sum interface { + isPacket_Sum() + MarshalTo([]byte) (int, error) + Size() int +} + +type Packet_PacketPing struct { + PacketPing *PacketPing `protobuf:"bytes,1,opt,name=packet_ping,json=packetPing,proto3,oneof" json:"packet_ping,omitempty"` +} +type Packet_PacketPong struct { + PacketPong *PacketPong `protobuf:"bytes,2,opt,name=packet_pong,json=packetPong,proto3,oneof" json:"packet_pong,omitempty"` +} +type Packet_PacketMsg struct { + PacketMsg *PacketMsg `protobuf:"bytes,3,opt,name=packet_msg,json=packetMsg,proto3,oneof" json:"packet_msg,omitempty"` +} + +func (*Packet_PacketPing) isPacket_Sum() {} +func (*Packet_PacketPong) isPacket_Sum() {} +func (*Packet_PacketMsg) isPacket_Sum() {} + +func (m *Packet) GetSum() isPacket_Sum { + if m != nil { + return m.Sum + } + return nil +} + +func (m *Packet) GetPacketPing() *PacketPing { + if x, ok := m.GetSum().(*Packet_PacketPing); ok { + return x.PacketPing + } + return nil +} + +func (m *Packet) GetPacketPong() *PacketPong { + if x, ok := m.GetSum().(*Packet_PacketPong); ok { + return x.PacketPong + } + return nil +} + +func (m *Packet) GetPacketMsg() *PacketMsg { + if x, ok := m.GetSum().(*Packet_PacketMsg); ok { + return x.PacketMsg + } + return nil +} + +// XXX_OneofWrappers is for the internal use of the proto package. +func (*Packet) XXX_OneofWrappers() []interface{} { + return []interface{}{ + (*Packet_PacketPing)(nil), + (*Packet_PacketPong)(nil), + (*Packet_PacketMsg)(nil), + } +} + +type AuthSigMessage struct { + PubKey crypto.PublicKey `protobuf:"bytes,1,opt,name=pub_key,json=pubKey,proto3" json:"pub_key"` + Sig []byte `protobuf:"bytes,2,opt,name=sig,proto3" json:"sig,omitempty"` +} + +func (m *AuthSigMessage) Reset() { *m = AuthSigMessage{} } +func (m *AuthSigMessage) String() string { return proto.CompactTextString(m) } +func (*AuthSigMessage) ProtoMessage() {} +func (*AuthSigMessage) Descriptor() ([]byte, []int) { + return fileDescriptor_22474b5527c8fa9f, []int{4} +} +func (m *AuthSigMessage) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *AuthSigMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_AuthSigMessage.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *AuthSigMessage) XXX_Merge(src proto.Message) { + xxx_messageInfo_AuthSigMessage.Merge(m, src) +} +func (m *AuthSigMessage) XXX_Size() int { + return m.Size() +} +func (m *AuthSigMessage) XXX_DiscardUnknown() { + xxx_messageInfo_AuthSigMessage.DiscardUnknown(m) +} + +var xxx_messageInfo_AuthSigMessage proto.InternalMessageInfo + +func (m *AuthSigMessage) GetPubKey() crypto.PublicKey { + if m != nil { + return m.PubKey + } + return crypto.PublicKey{} +} + +func (m *AuthSigMessage) GetSig() []byte { + if m != nil { + return m.Sig + } + return nil +} + +func init() { + proto.RegisterType((*PacketPing)(nil), "tendermint.p2p.PacketPing") + proto.RegisterType((*PacketPong)(nil), "tendermint.p2p.PacketPong") + proto.RegisterType((*PacketMsg)(nil), "tendermint.p2p.PacketMsg") + proto.RegisterType((*Packet)(nil), "tendermint.p2p.Packet") + proto.RegisterType((*AuthSigMessage)(nil), "tendermint.p2p.AuthSigMessage") +} + +func init() { proto.RegisterFile("tendermint/p2p/conn.proto", fileDescriptor_22474b5527c8fa9f) } + +var fileDescriptor_22474b5527c8fa9f = []byte{ + // 418 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x52, 0x4d, 0x6f, 0xd3, 0x40, + 0x10, 0xb5, 0x71, 0x9b, 0x92, 0x49, 0xa8, 0xd0, 0x8a, 0x43, 0x12, 0x55, 0x4e, 0x94, 0x53, 0x0e, + 0xe0, 0x95, 0xdc, 0x5b, 0x11, 0x07, 0xcc, 0x87, 0xa8, 0xaa, 0x88, 0xc8, 0x70, 0xe2, 0x62, 0xd9, + 0xce, 0xb0, 0xb6, 0x12, 0xef, 0xae, 0xbc, 0xeb, 0x08, 0xff, 0x0b, 0x7e, 0x56, 0xb9, 0xf5, 0xc8, + 0x29, 0x42, 0xce, 0x1f, 0x41, 0xf1, 0x06, 0x9a, 0x4a, 0x70, 0x7b, 0x6f, 0x66, 0xde, 0xcc, 0x7b, + 0xda, 0x85, 0xa1, 0x46, 0xbe, 0xc4, 0xb2, 0xc8, 0xb9, 0xa6, 0xd2, 0x97, 0x34, 0x15, 0x9c, 0x7b, + 0xb2, 0x14, 0x5a, 0x90, 0xf3, 0xfb, 0x96, 0x27, 0x7d, 0x39, 0x7a, 0xc6, 0x04, 0x13, 0x6d, 0x8b, + 0xee, 0x91, 0x99, 0x1a, 0x5d, 0x1c, 0x2d, 0x48, 0xcb, 0x5a, 0x6a, 0x41, 0x57, 0x58, 0x2b, 0xd3, + 0x9d, 0xf6, 0x01, 0x16, 0x71, 0xba, 0x42, 0xbd, 0xc8, 0x39, 0x3b, 0x62, 0x82, 0xb3, 0x69, 0x06, + 0x5d, 0xc3, 0xe6, 0x8a, 0x91, 0xe7, 0x00, 0x69, 0x16, 0x73, 0x8e, 0xeb, 0x28, 0x5f, 0x0e, 0xec, + 0x89, 0x3d, 0x3b, 0x0d, 0x9e, 0x34, 0xdb, 0x71, 0xf7, 0x8d, 0xa9, 0x5e, 0xbf, 0x0d, 0xbb, 0x87, + 0x81, 0xeb, 0x25, 0x19, 0x82, 0x83, 0xe2, 0xeb, 0xe0, 0xd1, 0xc4, 0x9e, 0x3d, 0x0e, 0xce, 0x9a, + 0xed, 0xd8, 0x79, 0xf7, 0xf1, 0x7d, 0xb8, 0xaf, 0x11, 0x02, 0x27, 0xcb, 0x58, 0xc7, 0x03, 0x67, + 0x62, 0xcf, 0xfa, 0x61, 0x8b, 0xa7, 0x3f, 0x6c, 0xe8, 0x98, 0x53, 0xe4, 0x15, 0xf4, 0x64, 0x8b, + 0x22, 0x99, 0x73, 0xd6, 0x1e, 0xea, 0xf9, 0x23, 0xef, 0x61, 0x54, 0xef, 0xde, 0xf3, 0x07, 0x2b, + 0x04, 0xf9, 0x97, 0x1d, 0xcb, 0x05, 0x67, 0xad, 0x81, 0xff, 0xcb, 0xc5, 0x03, 0xb9, 0xe0, 0x8c, + 0x5c, 0xc1, 0x81, 0x45, 0x85, 0x62, 0xad, 0xc5, 0x9e, 0x3f, 0xfc, 0xb7, 0x7a, 0xae, 0xf6, 0xe2, + 0xae, 0xfc, 0x43, 0x82, 0x53, 0x70, 0x54, 0x55, 0x4c, 0x23, 0x38, 0x7f, 0x5d, 0xe9, 0xec, 0x53, + 0xce, 0xe6, 0xa8, 0x54, 0xcc, 0x90, 0xbc, 0x84, 0x33, 0x59, 0x25, 0xd1, 0x0a, 0xeb, 0x43, 0x9c, + 0x8b, 0xe3, 0x8d, 0xe6, 0x4d, 0xbc, 0x45, 0x95, 0xac, 0xf3, 0xf4, 0x06, 0xeb, 0xe0, 0xe4, 0x76, + 0x3b, 0xb6, 0xc2, 0x8e, 0xac, 0x92, 0x1b, 0xac, 0xc9, 0x53, 0x70, 0x54, 0x6e, 0x82, 0xf4, 0xc3, + 0x3d, 0x0c, 0x3e, 0xdf, 0x36, 0xae, 0x7d, 0xd7, 0xb8, 0xf6, 0xaf, 0xc6, 0xb5, 0xbf, 0xef, 0x5c, + 0xeb, 0x6e, 0xe7, 0x5a, 0x3f, 0x77, 0xae, 0xf5, 0xe5, 0x8a, 0xe5, 0x3a, 0xab, 0x12, 0x2f, 0x15, + 0x05, 0x55, 0xba, 0x8c, 0x39, 0xc3, 0xb5, 0xd8, 0xe0, 0x8b, 0x0d, 0x72, 0x5d, 0x95, 0xa8, 0x68, + 0x26, 0xca, 0xb4, 0xac, 0xbe, 0xd1, 0xcd, 0x25, 0x4d, 0x45, 0x81, 0x9a, 0x9a, 0xdf, 0x22, 0x7d, + 0x99, 0x74, 0x5a, 0x78, 0xf9, 0x3b, 0x00, 0x00, 0xff, 0xff, 0x71, 0xe7, 0x5e, 0x56, 0x70, 0x02, + 0x00, 0x00, +} + +func (m *PacketPing) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PacketPing) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PacketPing) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *PacketPong) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PacketPong) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PacketPong) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *PacketMsg) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PacketMsg) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PacketMsg) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Data) > 0 { + i -= len(m.Data) + copy(dAtA[i:], m.Data) + i = encodeVarintConn(dAtA, i, uint64(len(m.Data))) + i-- + dAtA[i] = 0x1a + } + if m.EOF { + i-- + if m.EOF { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x10 + } + if m.ChannelID != 0 { + i = encodeVarintConn(dAtA, i, uint64(m.ChannelID)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *Packet) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Packet) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Packet) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Sum != nil { + { + size := m.Sum.Size() + i -= size + if _, err := m.Sum.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + } + } + return len(dAtA) - i, nil +} + +func (m *Packet_PacketPing) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Packet_PacketPing) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.PacketPing != nil { + { + size, err := m.PacketPing.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintConn(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} +func (m *Packet_PacketPong) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Packet_PacketPong) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.PacketPong != nil { + { + size, err := m.PacketPong.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintConn(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + return len(dAtA) - i, nil +} +func (m *Packet_PacketMsg) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Packet_PacketMsg) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.PacketMsg != nil { + { + size, err := m.PacketMsg.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintConn(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + return len(dAtA) - i, nil +} +func (m *AuthSigMessage) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *AuthSigMessage) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AuthSigMessage) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Sig) > 0 { + i -= len(m.Sig) + copy(dAtA[i:], m.Sig) + i = encodeVarintConn(dAtA, i, uint64(len(m.Sig))) + i-- + dAtA[i] = 0x12 + } + { + size, err := m.PubKey.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintConn(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintConn(dAtA []byte, offset int, v uint64) int { + offset -= sovConn(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *PacketPing) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *PacketPong) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *PacketMsg) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ChannelID != 0 { + n += 1 + sovConn(uint64(m.ChannelID)) + } + if m.EOF { + n += 2 + } + l = len(m.Data) + if l > 0 { + n += 1 + l + sovConn(uint64(l)) + } + return n +} + +func (m *Packet) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Sum != nil { + n += m.Sum.Size() + } + return n +} + +func (m *Packet_PacketPing) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PacketPing != nil { + l = m.PacketPing.Size() + n += 1 + l + sovConn(uint64(l)) + } + return n +} +func (m *Packet_PacketPong) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PacketPong != nil { + l = m.PacketPong.Size() + n += 1 + l + sovConn(uint64(l)) + } + return n +} +func (m *Packet_PacketMsg) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PacketMsg != nil { + l = m.PacketMsg.Size() + n += 1 + l + sovConn(uint64(l)) + } + return n +} +func (m *AuthSigMessage) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.PubKey.Size() + n += 1 + l + sovConn(uint64(l)) + l = len(m.Sig) + if l > 0 { + n += 1 + l + sovConn(uint64(l)) + } + return n +} + +func sovConn(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozConn(x uint64) (n int) { + return sovConn(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *PacketPing) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConn + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PacketPing: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PacketPing: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipConn(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthConn + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PacketPong) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConn + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PacketPong: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PacketPong: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipConn(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthConn + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PacketMsg) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConn + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PacketMsg: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PacketMsg: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ChannelID", wireType) + } + m.ChannelID = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConn + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ChannelID |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field EOF", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConn + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.EOF = bool(v != 0) + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConn + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthConn + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthConn + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) + if m.Data == nil { + m.Data = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipConn(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthConn + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Packet) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConn + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Packet: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Packet: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PacketPing", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConn + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthConn + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthConn + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &PacketPing{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &Packet_PacketPing{v} + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PacketPong", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConn + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthConn + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthConn + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &PacketPong{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &Packet_PacketPong{v} + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PacketMsg", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConn + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthConn + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthConn + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &PacketMsg{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &Packet_PacketMsg{v} + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipConn(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthConn + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *AuthSigMessage) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConn + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: AuthSigMessage: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AuthSigMessage: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PubKey", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConn + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthConn + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthConn + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.PubKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Sig", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConn + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthConn + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthConn + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Sig = append(m.Sig[:0], dAtA[iNdEx:postIndex]...) + if m.Sig == nil { + m.Sig = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipConn(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthConn + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipConn(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowConn + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowConn + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowConn + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthConn + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupConn + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthConn + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthConn = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowConn = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupConn = fmt.Errorf("proto: unexpected end of group") +) diff --git a/comet/proto/privval/privval.pb.go b/comet/proto/privval/privval.pb.go new file mode 100644 index 00000000..ecbf7612 --- /dev/null +++ b/comet/proto/privval/privval.pb.go @@ -0,0 +1,2804 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: tendermint/privval/privval.proto + +package privval + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + crypto "github.com/strangelove-ventures/horcrux/v3/comet/proto/crypto" + types "github.com/strangelove-ventures/horcrux/v3/comet/proto/types" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type Errors int32 + +const ( + Errors_ERRORS_UNKNOWN Errors = 0 + Errors_ERRORS_UNEXPECTED_RESPONSE Errors = 1 + Errors_ERRORS_NO_CONNECTION Errors = 2 + Errors_ERRORS_CONNECTION_TIMEOUT Errors = 3 + Errors_ERRORS_READ_TIMEOUT Errors = 4 + Errors_ERRORS_WRITE_TIMEOUT Errors = 5 +) + +var Errors_name = map[int32]string{ + 0: "ERRORS_UNKNOWN", + 1: "ERRORS_UNEXPECTED_RESPONSE", + 2: "ERRORS_NO_CONNECTION", + 3: "ERRORS_CONNECTION_TIMEOUT", + 4: "ERRORS_READ_TIMEOUT", + 5: "ERRORS_WRITE_TIMEOUT", +} + +var Errors_value = map[string]int32{ + "ERRORS_UNKNOWN": 0, + "ERRORS_UNEXPECTED_RESPONSE": 1, + "ERRORS_NO_CONNECTION": 2, + "ERRORS_CONNECTION_TIMEOUT": 3, + "ERRORS_READ_TIMEOUT": 4, + "ERRORS_WRITE_TIMEOUT": 5, +} + +func (x Errors) String() string { + return proto.EnumName(Errors_name, int32(x)) +} + +func (Errors) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_4602a5fa8632580d, []int{0} +} + +type RemoteSignerError struct { + Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` +} + +func (m *RemoteSignerError) Reset() { *m = RemoteSignerError{} } +func (m *RemoteSignerError) String() string { return proto.CompactTextString(m) } +func (*RemoteSignerError) ProtoMessage() {} +func (*RemoteSignerError) Descriptor() ([]byte, []int) { + return fileDescriptor_4602a5fa8632580d, []int{0} +} +func (m *RemoteSignerError) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *RemoteSignerError) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_RemoteSignerError.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *RemoteSignerError) XXX_Merge(src proto.Message) { + xxx_messageInfo_RemoteSignerError.Merge(m, src) +} +func (m *RemoteSignerError) XXX_Size() int { + return m.Size() +} +func (m *RemoteSignerError) XXX_DiscardUnknown() { + xxx_messageInfo_RemoteSignerError.DiscardUnknown(m) +} + +var xxx_messageInfo_RemoteSignerError proto.InternalMessageInfo + +func (m *RemoteSignerError) GetCode() int32 { + if m != nil { + return m.Code + } + return 0 +} + +func (m *RemoteSignerError) GetDescription() string { + if m != nil { + return m.Description + } + return "" +} + +// PubKeyRequest requests the consensus public key from the remote signer. +type PubKeyRequest struct { + ChainId string `protobuf:"bytes,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` +} + +func (m *PubKeyRequest) Reset() { *m = PubKeyRequest{} } +func (m *PubKeyRequest) String() string { return proto.CompactTextString(m) } +func (*PubKeyRequest) ProtoMessage() {} +func (*PubKeyRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_4602a5fa8632580d, []int{1} +} +func (m *PubKeyRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PubKeyRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PubKeyRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *PubKeyRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_PubKeyRequest.Merge(m, src) +} +func (m *PubKeyRequest) XXX_Size() int { + return m.Size() +} +func (m *PubKeyRequest) XXX_DiscardUnknown() { + xxx_messageInfo_PubKeyRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_PubKeyRequest proto.InternalMessageInfo + +func (m *PubKeyRequest) GetChainId() string { + if m != nil { + return m.ChainId + } + return "" +} + +// PubKeyResponse is a response message containing the public key. +type PubKeyResponse struct { + PubKey crypto.PublicKey `protobuf:"bytes,1,opt,name=pub_key,json=pubKey,proto3" json:"pub_key"` + Error *RemoteSignerError `protobuf:"bytes,2,opt,name=error,proto3" json:"error,omitempty"` +} + +func (m *PubKeyResponse) Reset() { *m = PubKeyResponse{} } +func (m *PubKeyResponse) String() string { return proto.CompactTextString(m) } +func (*PubKeyResponse) ProtoMessage() {} +func (*PubKeyResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_4602a5fa8632580d, []int{2} +} +func (m *PubKeyResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PubKeyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PubKeyResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *PubKeyResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_PubKeyResponse.Merge(m, src) +} +func (m *PubKeyResponse) XXX_Size() int { + return m.Size() +} +func (m *PubKeyResponse) XXX_DiscardUnknown() { + xxx_messageInfo_PubKeyResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_PubKeyResponse proto.InternalMessageInfo + +func (m *PubKeyResponse) GetPubKey() crypto.PublicKey { + if m != nil { + return m.PubKey + } + return crypto.PublicKey{} +} + +func (m *PubKeyResponse) GetError() *RemoteSignerError { + if m != nil { + return m.Error + } + return nil +} + +// SignVoteRequest is a request to sign a vote +type SignVoteRequest struct { + Vote *types.Vote `protobuf:"bytes,1,opt,name=vote,proto3" json:"vote,omitempty"` + ChainId string `protobuf:"bytes,2,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` +} + +func (m *SignVoteRequest) Reset() { *m = SignVoteRequest{} } +func (m *SignVoteRequest) String() string { return proto.CompactTextString(m) } +func (*SignVoteRequest) ProtoMessage() {} +func (*SignVoteRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_4602a5fa8632580d, []int{3} +} +func (m *SignVoteRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SignVoteRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SignVoteRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *SignVoteRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_SignVoteRequest.Merge(m, src) +} +func (m *SignVoteRequest) XXX_Size() int { + return m.Size() +} +func (m *SignVoteRequest) XXX_DiscardUnknown() { + xxx_messageInfo_SignVoteRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_SignVoteRequest proto.InternalMessageInfo + +func (m *SignVoteRequest) GetVote() *types.Vote { + if m != nil { + return m.Vote + } + return nil +} + +func (m *SignVoteRequest) GetChainId() string { + if m != nil { + return m.ChainId + } + return "" +} + +// SignedVoteResponse is a response containing a signed vote or an error +type SignedVoteResponse struct { + Vote types.Vote `protobuf:"bytes,1,opt,name=vote,proto3" json:"vote"` + Error *RemoteSignerError `protobuf:"bytes,2,opt,name=error,proto3" json:"error,omitempty"` +} + +func (m *SignedVoteResponse) Reset() { *m = SignedVoteResponse{} } +func (m *SignedVoteResponse) String() string { return proto.CompactTextString(m) } +func (*SignedVoteResponse) ProtoMessage() {} +func (*SignedVoteResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_4602a5fa8632580d, []int{4} +} +func (m *SignedVoteResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SignedVoteResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SignedVoteResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *SignedVoteResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_SignedVoteResponse.Merge(m, src) +} +func (m *SignedVoteResponse) XXX_Size() int { + return m.Size() +} +func (m *SignedVoteResponse) XXX_DiscardUnknown() { + xxx_messageInfo_SignedVoteResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_SignedVoteResponse proto.InternalMessageInfo + +func (m *SignedVoteResponse) GetVote() types.Vote { + if m != nil { + return m.Vote + } + return types.Vote{} +} + +func (m *SignedVoteResponse) GetError() *RemoteSignerError { + if m != nil { + return m.Error + } + return nil +} + +// SignProposalRequest is a request to sign a proposal +type SignProposalRequest struct { + Proposal *types.Proposal `protobuf:"bytes,1,opt,name=proposal,proto3" json:"proposal,omitempty"` + ChainId string `protobuf:"bytes,2,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` +} + +func (m *SignProposalRequest) Reset() { *m = SignProposalRequest{} } +func (m *SignProposalRequest) String() string { return proto.CompactTextString(m) } +func (*SignProposalRequest) ProtoMessage() {} +func (*SignProposalRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_4602a5fa8632580d, []int{5} +} +func (m *SignProposalRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SignProposalRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SignProposalRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *SignProposalRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_SignProposalRequest.Merge(m, src) +} +func (m *SignProposalRequest) XXX_Size() int { + return m.Size() +} +func (m *SignProposalRequest) XXX_DiscardUnknown() { + xxx_messageInfo_SignProposalRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_SignProposalRequest proto.InternalMessageInfo + +func (m *SignProposalRequest) GetProposal() *types.Proposal { + if m != nil { + return m.Proposal + } + return nil +} + +func (m *SignProposalRequest) GetChainId() string { + if m != nil { + return m.ChainId + } + return "" +} + +// SignedProposalResponse is response containing a signed proposal or an error +type SignedProposalResponse struct { + Proposal types.Proposal `protobuf:"bytes,1,opt,name=proposal,proto3" json:"proposal"` + Error *RemoteSignerError `protobuf:"bytes,2,opt,name=error,proto3" json:"error,omitempty"` +} + +func (m *SignedProposalResponse) Reset() { *m = SignedProposalResponse{} } +func (m *SignedProposalResponse) String() string { return proto.CompactTextString(m) } +func (*SignedProposalResponse) ProtoMessage() {} +func (*SignedProposalResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_4602a5fa8632580d, []int{6} +} +func (m *SignedProposalResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SignedProposalResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SignedProposalResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *SignedProposalResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_SignedProposalResponse.Merge(m, src) +} +func (m *SignedProposalResponse) XXX_Size() int { + return m.Size() +} +func (m *SignedProposalResponse) XXX_DiscardUnknown() { + xxx_messageInfo_SignedProposalResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_SignedProposalResponse proto.InternalMessageInfo + +func (m *SignedProposalResponse) GetProposal() types.Proposal { + if m != nil { + return m.Proposal + } + return types.Proposal{} +} + +func (m *SignedProposalResponse) GetError() *RemoteSignerError { + if m != nil { + return m.Error + } + return nil +} + +// PingRequest is a request to confirm that the connection is alive. +type PingRequest struct { +} + +func (m *PingRequest) Reset() { *m = PingRequest{} } +func (m *PingRequest) String() string { return proto.CompactTextString(m) } +func (*PingRequest) ProtoMessage() {} +func (*PingRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_4602a5fa8632580d, []int{7} +} +func (m *PingRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PingRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PingRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *PingRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_PingRequest.Merge(m, src) +} +func (m *PingRequest) XXX_Size() int { + return m.Size() +} +func (m *PingRequest) XXX_DiscardUnknown() { + xxx_messageInfo_PingRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_PingRequest proto.InternalMessageInfo + +// PingResponse is a response to confirm that the connection is alive. +type PingResponse struct { +} + +func (m *PingResponse) Reset() { *m = PingResponse{} } +func (m *PingResponse) String() string { return proto.CompactTextString(m) } +func (*PingResponse) ProtoMessage() {} +func (*PingResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_4602a5fa8632580d, []int{8} +} +func (m *PingResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PingResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PingResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *PingResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_PingResponse.Merge(m, src) +} +func (m *PingResponse) XXX_Size() int { + return m.Size() +} +func (m *PingResponse) XXX_DiscardUnknown() { + xxx_messageInfo_PingResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_PingResponse proto.InternalMessageInfo + +type Message struct { + // Types that are valid to be assigned to Sum: + // *Message_PubKeyRequest + // *Message_PubKeyResponse + // *Message_SignVoteRequest + // *Message_SignedVoteResponse + // *Message_SignProposalRequest + // *Message_SignedProposalResponse + // *Message_PingRequest + // *Message_PingResponse + Sum isMessage_Sum `protobuf_oneof:"sum"` +} + +func (m *Message) Reset() { *m = Message{} } +func (m *Message) String() string { return proto.CompactTextString(m) } +func (*Message) ProtoMessage() {} +func (*Message) Descriptor() ([]byte, []int) { + return fileDescriptor_4602a5fa8632580d, []int{9} +} +func (m *Message) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Message) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Message.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Message) XXX_Merge(src proto.Message) { + xxx_messageInfo_Message.Merge(m, src) +} +func (m *Message) XXX_Size() int { + return m.Size() +} +func (m *Message) XXX_DiscardUnknown() { + xxx_messageInfo_Message.DiscardUnknown(m) +} + +var xxx_messageInfo_Message proto.InternalMessageInfo + +type isMessage_Sum interface { + isMessage_Sum() + MarshalTo([]byte) (int, error) + Size() int +} + +type Message_PubKeyRequest struct { + PubKeyRequest *PubKeyRequest `protobuf:"bytes,1,opt,name=pub_key_request,json=pubKeyRequest,proto3,oneof" json:"pub_key_request,omitempty"` +} +type Message_PubKeyResponse struct { + PubKeyResponse *PubKeyResponse `protobuf:"bytes,2,opt,name=pub_key_response,json=pubKeyResponse,proto3,oneof" json:"pub_key_response,omitempty"` +} +type Message_SignVoteRequest struct { + SignVoteRequest *SignVoteRequest `protobuf:"bytes,3,opt,name=sign_vote_request,json=signVoteRequest,proto3,oneof" json:"sign_vote_request,omitempty"` +} +type Message_SignedVoteResponse struct { + SignedVoteResponse *SignedVoteResponse `protobuf:"bytes,4,opt,name=signed_vote_response,json=signedVoteResponse,proto3,oneof" json:"signed_vote_response,omitempty"` +} +type Message_SignProposalRequest struct { + SignProposalRequest *SignProposalRequest `protobuf:"bytes,5,opt,name=sign_proposal_request,json=signProposalRequest,proto3,oneof" json:"sign_proposal_request,omitempty"` +} +type Message_SignedProposalResponse struct { + SignedProposalResponse *SignedProposalResponse `protobuf:"bytes,6,opt,name=signed_proposal_response,json=signedProposalResponse,proto3,oneof" json:"signed_proposal_response,omitempty"` +} +type Message_PingRequest struct { + PingRequest *PingRequest `protobuf:"bytes,7,opt,name=ping_request,json=pingRequest,proto3,oneof" json:"ping_request,omitempty"` +} +type Message_PingResponse struct { + PingResponse *PingResponse `protobuf:"bytes,8,opt,name=ping_response,json=pingResponse,proto3,oneof" json:"ping_response,omitempty"` +} + +func (*Message_PubKeyRequest) isMessage_Sum() {} +func (*Message_PubKeyResponse) isMessage_Sum() {} +func (*Message_SignVoteRequest) isMessage_Sum() {} +func (*Message_SignedVoteResponse) isMessage_Sum() {} +func (*Message_SignProposalRequest) isMessage_Sum() {} +func (*Message_SignedProposalResponse) isMessage_Sum() {} +func (*Message_PingRequest) isMessage_Sum() {} +func (*Message_PingResponse) isMessage_Sum() {} + +func (m *Message) GetSum() isMessage_Sum { + if m != nil { + return m.Sum + } + return nil +} + +func (m *Message) GetPubKeyRequest() *PubKeyRequest { + if x, ok := m.GetSum().(*Message_PubKeyRequest); ok { + return x.PubKeyRequest + } + return nil +} + +func (m *Message) GetPubKeyResponse() *PubKeyResponse { + if x, ok := m.GetSum().(*Message_PubKeyResponse); ok { + return x.PubKeyResponse + } + return nil +} + +func (m *Message) GetSignVoteRequest() *SignVoteRequest { + if x, ok := m.GetSum().(*Message_SignVoteRequest); ok { + return x.SignVoteRequest + } + return nil +} + +func (m *Message) GetSignedVoteResponse() *SignedVoteResponse { + if x, ok := m.GetSum().(*Message_SignedVoteResponse); ok { + return x.SignedVoteResponse + } + return nil +} + +func (m *Message) GetSignProposalRequest() *SignProposalRequest { + if x, ok := m.GetSum().(*Message_SignProposalRequest); ok { + return x.SignProposalRequest + } + return nil +} + +func (m *Message) GetSignedProposalResponse() *SignedProposalResponse { + if x, ok := m.GetSum().(*Message_SignedProposalResponse); ok { + return x.SignedProposalResponse + } + return nil +} + +func (m *Message) GetPingRequest() *PingRequest { + if x, ok := m.GetSum().(*Message_PingRequest); ok { + return x.PingRequest + } + return nil +} + +func (m *Message) GetPingResponse() *PingResponse { + if x, ok := m.GetSum().(*Message_PingResponse); ok { + return x.PingResponse + } + return nil +} + +// XXX_OneofWrappers is for the internal use of the proto package. +func (*Message) XXX_OneofWrappers() []interface{} { + return []interface{}{ + (*Message_PubKeyRequest)(nil), + (*Message_PubKeyResponse)(nil), + (*Message_SignVoteRequest)(nil), + (*Message_SignedVoteResponse)(nil), + (*Message_SignProposalRequest)(nil), + (*Message_SignedProposalResponse)(nil), + (*Message_PingRequest)(nil), + (*Message_PingResponse)(nil), + } +} + +func init() { + //proto.RegisterEnum("tendermint.privval.Errors", Errors_name, Errors_value) + proto.RegisterType((*RemoteSignerError)(nil), "tendermint.privval.RemoteSignerError") + proto.RegisterType((*PubKeyRequest)(nil), "tendermint.privval.PubKeyRequest") + proto.RegisterType((*PubKeyResponse)(nil), "tendermint.privval.PubKeyResponse") + proto.RegisterType((*SignVoteRequest)(nil), "tendermint.privval.SignVoteRequest") + proto.RegisterType((*SignedVoteResponse)(nil), "tendermint.privval.SignedVoteResponse") + proto.RegisterType((*SignProposalRequest)(nil), "tendermint.privval.SignProposalRequest") + proto.RegisterType((*SignedProposalResponse)(nil), "tendermint.privval.SignedProposalResponse") + proto.RegisterType((*PingRequest)(nil), "tendermint.privval.PingRequest") + proto.RegisterType((*PingResponse)(nil), "tendermint.privval.PingResponse") + proto.RegisterType((*Message)(nil), "tendermint.privval.Message") +} + +// func init() { proto.RegisterFile("tendermint/privval/privval.proto", fileDescriptor_4602a5fa8632580d) } + +var fileDescriptor_4602a5fa8632580d = []byte{ + // 782 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0x4d, 0x4f, 0xdb, 0x48, + 0x18, 0xb6, 0x21, 0x1f, 0xf0, 0x86, 0x84, 0x30, 0xb0, 0x6c, 0x40, 0x6c, 0xc8, 0x66, 0xb5, 0xbb, + 0x28, 0xd2, 0x26, 0x2b, 0x90, 0xf6, 0xc2, 0x6a, 0xa5, 0x05, 0xac, 0x26, 0x8a, 0x70, 0xd2, 0x49, + 0x28, 0x08, 0xa9, 0xb2, 0x12, 0x67, 0xea, 0x58, 0x24, 0x1e, 0xd7, 0x63, 0x47, 0xcd, 0xb9, 0xb7, + 0x9e, 0x2a, 0xf5, 0x4f, 0xf4, 0xdc, 0x5f, 0xc1, 0x91, 0x63, 0x4f, 0x55, 0x05, 0x7f, 0xa4, 0xca, + 0x78, 0xe2, 0x7c, 0xa3, 0x56, 0x5c, 0x92, 0x79, 0x3f, 0xe6, 0x79, 0x9f, 0x67, 0xe6, 0xb1, 0x06, + 0x32, 0x2e, 0xb1, 0x5a, 0xc4, 0xe9, 0x9a, 0x96, 0x5b, 0xb0, 0x1d, 0xb3, 0xd7, 0x6b, 0x74, 0x86, + 0xff, 0x79, 0xdb, 0xa1, 0x2e, 0x45, 0x68, 0xd4, 0x91, 0x17, 0x95, 0xdd, 0xbd, 0xb1, 0x5d, 0xba, + 0xd3, 0xb7, 0x5d, 0x5a, 0xb8, 0x21, 0x7d, 0xe6, 0xef, 0x98, 0xa8, 0xba, 0x7d, 0x9b, 0x30, 0xff, + 0x57, 0x54, 0xb7, 0x0c, 0x6a, 0x50, 0xbe, 0x2c, 0x0c, 0x56, 0x7e, 0x36, 0x5b, 0x82, 0x0d, 0x4c, + 0xba, 0xd4, 0x25, 0x35, 0xd3, 0xb0, 0x88, 0xa3, 0x38, 0x0e, 0x75, 0x10, 0x82, 0x90, 0x4e, 0x5b, + 0x24, 0x25, 0x67, 0xe4, 0x83, 0x30, 0xe6, 0x6b, 0x94, 0x81, 0x58, 0x8b, 0x30, 0xdd, 0x31, 0x6d, + 0xd7, 0xa4, 0x56, 0x6a, 0x29, 0x23, 0x1f, 0xac, 0xe2, 0xf1, 0x54, 0x36, 0x07, 0xf1, 0xaa, 0xd7, + 0x2c, 0x93, 0x3e, 0x26, 0xaf, 0x3d, 0xc2, 0x5c, 0xb4, 0x03, 0x2b, 0x7a, 0xbb, 0x61, 0x5a, 0x9a, + 0xd9, 0xe2, 0x50, 0xab, 0x38, 0xca, 0xe3, 0x52, 0x2b, 0xfb, 0x4e, 0x86, 0xc4, 0xb0, 0x99, 0xd9, + 0xd4, 0x62, 0x04, 0x1d, 0x43, 0xd4, 0xf6, 0x9a, 0xda, 0x0d, 0xe9, 0xf3, 0xe6, 0xd8, 0xe1, 0x5e, + 0x7e, 0xec, 0x04, 0x7c, 0xb5, 0xf9, 0xaa, 0xd7, 0xec, 0x98, 0x7a, 0x99, 0xf4, 0x4f, 0x42, 0xb7, + 0x5f, 0xf6, 0x25, 0x1c, 0xb1, 0x39, 0x08, 0x3a, 0x86, 0x30, 0x19, 0x50, 0xe7, 0xbc, 0x62, 0x87, + 0xbf, 0xe7, 0x67, 0x0f, 0x2f, 0x3f, 0xa3, 0x13, 0xfb, 0x7b, 0xb2, 0x57, 0xb0, 0x3e, 0xc8, 0xbe, + 0xa0, 0x2e, 0x19, 0x52, 0xcf, 0x41, 0xa8, 0x47, 0x5d, 0x22, 0x98, 0x6c, 0x8f, 0xc3, 0xf9, 0x67, + 0xca, 0x9b, 0x79, 0xcf, 0x84, 0xcc, 0xa5, 0x49, 0x99, 0x6f, 0x65, 0x40, 0x7c, 0x60, 0xcb, 0x07, + 0x17, 0x52, 0xff, 0xfe, 0x1e, 0x74, 0xa1, 0xd0, 0x9f, 0xf1, 0x24, 0x7d, 0x6d, 0xd8, 0x1c, 0x64, + 0xab, 0x0e, 0xb5, 0x29, 0x6b, 0x74, 0x86, 0x1a, 0xff, 0x81, 0x15, 0x5b, 0xa4, 0x04, 0x93, 0xdd, + 0x59, 0x26, 0xc1, 0xa6, 0xa0, 0xf7, 0x31, 0xbd, 0x1f, 0x64, 0xd8, 0xf6, 0xf5, 0x8e, 0x86, 0x09, + 0xcd, 0xff, 0xfe, 0xc8, 0x34, 0xa1, 0x7d, 0x34, 0xf3, 0x49, 0xfa, 0xe3, 0x10, 0xab, 0x9a, 0x96, + 0x21, 0x74, 0x67, 0x13, 0xb0, 0xe6, 0x87, 0x3e, 0xb3, 0xec, 0xa7, 0x30, 0x44, 0xcf, 0x09, 0x63, + 0x0d, 0x83, 0xa0, 0x32, 0xac, 0x0b, 0x13, 0x6a, 0x8e, 0xdf, 0x2e, 0xc8, 0xfe, 0x3a, 0x6f, 0xe2, + 0x84, 0xdd, 0x8b, 0x12, 0x8e, 0xdb, 0x13, 0xfe, 0x57, 0x21, 0x39, 0x02, 0xf3, 0x87, 0x09, 0xfe, + 0xd9, 0xc7, 0xd0, 0xfc, 0xce, 0xa2, 0x84, 0x13, 0xf6, 0xe4, 0x17, 0xf2, 0x1c, 0x36, 0x98, 0x69, + 0x58, 0xda, 0xc0, 0x11, 0x01, 0xbd, 0x65, 0x0e, 0xf8, 0xdb, 0x3c, 0xc0, 0x29, 0x53, 0x17, 0x25, + 0xbc, 0xce, 0xa6, 0x7c, 0x7e, 0x0d, 0x5b, 0x8c, 0xdf, 0xd7, 0x10, 0x54, 0xd0, 0x0c, 0x71, 0xd4, + 0x3f, 0x16, 0xa1, 0x4e, 0xfa, 0xb9, 0x28, 0x61, 0xc4, 0x66, 0x5d, 0xfe, 0x12, 0x7e, 0xe2, 0x74, + 0x87, 0x97, 0x18, 0x50, 0x0e, 0x73, 0xf0, 0x3f, 0x17, 0x81, 0x4f, 0xf9, 0xb4, 0x28, 0xe1, 0x4d, + 0x36, 0xc7, 0xbe, 0xaf, 0x20, 0x25, 0xa8, 0x8f, 0x0d, 0x10, 0xf4, 0x23, 0x7c, 0x42, 0x6e, 0x31, + 0xfd, 0x69, 0x7b, 0x16, 0x25, 0xbc, 0xcd, 0xe6, 0x1b, 0xf7, 0x0c, 0xd6, 0x6c, 0xd3, 0x32, 0x02, + 0xf6, 0x51, 0x8e, 0xbd, 0x3f, 0xf7, 0x06, 0x47, 0x2e, 0x2b, 0x4a, 0x38, 0x66, 0x8f, 0x42, 0xf4, + 0x0c, 0xe2, 0x02, 0x45, 0x50, 0x5c, 0xe1, 0x30, 0x99, 0xc5, 0x30, 0x01, 0xb1, 0x35, 0x7b, 0x2c, + 0x3e, 0x09, 0xc3, 0x32, 0xf3, 0xba, 0xb9, 0x8f, 0x32, 0x44, 0xb8, 0xc9, 0x19, 0x42, 0x90, 0x50, + 0x30, 0xae, 0xe0, 0x9a, 0x76, 0xa1, 0x96, 0xd5, 0xca, 0xa5, 0x9a, 0x94, 0x50, 0x1a, 0x76, 0x83, + 0x9c, 0x72, 0x55, 0x55, 0x4e, 0xeb, 0xca, 0x99, 0x86, 0x95, 0x5a, 0xb5, 0xa2, 0xd6, 0x94, 0xa4, + 0x8c, 0x52, 0xb0, 0x25, 0xea, 0x6a, 0x45, 0x3b, 0xad, 0xa8, 0xaa, 0x72, 0x5a, 0x2f, 0x55, 0xd4, + 0xe4, 0x12, 0xfa, 0x05, 0x76, 0x44, 0x65, 0x94, 0xd6, 0xea, 0xa5, 0x73, 0xa5, 0x72, 0x51, 0x4f, + 0x2e, 0xa3, 0x9f, 0x61, 0x53, 0x94, 0xb1, 0xf2, 0xff, 0x59, 0x50, 0x08, 0x8d, 0x21, 0x5e, 0xe2, + 0x52, 0x5d, 0x09, 0x2a, 0xe1, 0x93, 0xab, 0xdb, 0xfb, 0xb4, 0x7c, 0x77, 0x9f, 0x96, 0xbf, 0xde, + 0xa7, 0xe5, 0xf7, 0x0f, 0x69, 0xe9, 0xee, 0x21, 0x2d, 0x7d, 0x7e, 0x48, 0x4b, 0xd7, 0xff, 0x19, + 0xa6, 0xdb, 0xf6, 0x9a, 0x79, 0x9d, 0x76, 0x0b, 0xcc, 0x75, 0x1a, 0x96, 0x41, 0x3a, 0xb4, 0x47, + 0xfe, 0xea, 0x11, 0xcb, 0xf5, 0x1c, 0xc2, 0x0a, 0x6d, 0xea, 0xe8, 0x8e, 0xf7, 0xa6, 0xd0, 0x3b, + 0x2a, 0xe8, 0xb4, 0x4b, 0x06, 0x4f, 0xe5, 0xe0, 0xfd, 0x12, 0x07, 0xd5, 0x8c, 0xf0, 0xf0, 0xe8, + 0x5b, 0x00, 0x00, 0x00, 0xff, 0xff, 0x81, 0xe5, 0x07, 0x7f, 0x4d, 0x07, 0x00, 0x00, +} + +func (m *RemoteSignerError) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *RemoteSignerError) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *RemoteSignerError) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintPrivval(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x12 + } + if m.Code != 0 { + i = encodeVarintPrivval(dAtA, i, uint64(m.Code)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *PubKeyRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PubKeyRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PubKeyRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ChainId) > 0 { + i -= len(m.ChainId) + copy(dAtA[i:], m.ChainId) + i = encodeVarintPrivval(dAtA, i, uint64(len(m.ChainId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *PubKeyResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PubKeyResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PubKeyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Error != nil { + { + size, err := m.Error.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPrivval(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + { + size, err := m.PubKey.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPrivval(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *SignVoteRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SignVoteRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SignVoteRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ChainId) > 0 { + i -= len(m.ChainId) + copy(dAtA[i:], m.ChainId) + i = encodeVarintPrivval(dAtA, i, uint64(len(m.ChainId))) + i-- + dAtA[i] = 0x12 + } + if m.Vote != nil { + { + size, err := m.Vote.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPrivval(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *SignedVoteResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SignedVoteResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SignedVoteResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Error != nil { + { + size, err := m.Error.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPrivval(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + { + size, err := m.Vote.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPrivval(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *SignProposalRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SignProposalRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SignProposalRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ChainId) > 0 { + i -= len(m.ChainId) + copy(dAtA[i:], m.ChainId) + i = encodeVarintPrivval(dAtA, i, uint64(len(m.ChainId))) + i-- + dAtA[i] = 0x12 + } + if m.Proposal != nil { + { + size, err := m.Proposal.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPrivval(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *SignedProposalResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SignedProposalResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SignedProposalResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Error != nil { + { + size, err := m.Error.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPrivval(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + { + size, err := m.Proposal.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPrivval(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *PingRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PingRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PingRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *PingResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PingResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PingResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *Message) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Message) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Message) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Sum != nil { + { + size := m.Sum.Size() + i -= size + if _, err := m.Sum.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + } + } + return len(dAtA) - i, nil +} + +func (m *Message_PubKeyRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Message_PubKeyRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.PubKeyRequest != nil { + { + size, err := m.PubKeyRequest.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPrivval(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} +func (m *Message_PubKeyResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Message_PubKeyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.PubKeyResponse != nil { + { + size, err := m.PubKeyResponse.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPrivval(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + return len(dAtA) - i, nil +} +func (m *Message_SignVoteRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Message_SignVoteRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.SignVoteRequest != nil { + { + size, err := m.SignVoteRequest.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPrivval(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + return len(dAtA) - i, nil +} +func (m *Message_SignedVoteResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Message_SignedVoteResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.SignedVoteResponse != nil { + { + size, err := m.SignedVoteResponse.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPrivval(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + return len(dAtA) - i, nil +} +func (m *Message_SignProposalRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Message_SignProposalRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.SignProposalRequest != nil { + { + size, err := m.SignProposalRequest.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPrivval(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + return len(dAtA) - i, nil +} +func (m *Message_SignedProposalResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Message_SignedProposalResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.SignedProposalResponse != nil { + { + size, err := m.SignedProposalResponse.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPrivval(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + } + return len(dAtA) - i, nil +} +func (m *Message_PingRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Message_PingRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.PingRequest != nil { + { + size, err := m.PingRequest.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPrivval(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + } + return len(dAtA) - i, nil +} +func (m *Message_PingResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Message_PingResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.PingResponse != nil { + { + size, err := m.PingResponse.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPrivval(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x42 + } + return len(dAtA) - i, nil +} +func encodeVarintPrivval(dAtA []byte, offset int, v uint64) int { + offset -= sovPrivval(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *RemoteSignerError) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Code != 0 { + n += 1 + sovPrivval(uint64(m.Code)) + } + l = len(m.Description) + if l > 0 { + n += 1 + l + sovPrivval(uint64(l)) + } + return n +} + +func (m *PubKeyRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChainId) + if l > 0 { + n += 1 + l + sovPrivval(uint64(l)) + } + return n +} + +func (m *PubKeyResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.PubKey.Size() + n += 1 + l + sovPrivval(uint64(l)) + if m.Error != nil { + l = m.Error.Size() + n += 1 + l + sovPrivval(uint64(l)) + } + return n +} + +func (m *SignVoteRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Vote != nil { + l = m.Vote.Size() + n += 1 + l + sovPrivval(uint64(l)) + } + l = len(m.ChainId) + if l > 0 { + n += 1 + l + sovPrivval(uint64(l)) + } + return n +} + +func (m *SignedVoteResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Vote.Size() + n += 1 + l + sovPrivval(uint64(l)) + if m.Error != nil { + l = m.Error.Size() + n += 1 + l + sovPrivval(uint64(l)) + } + return n +} + +func (m *SignProposalRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Proposal != nil { + l = m.Proposal.Size() + n += 1 + l + sovPrivval(uint64(l)) + } + l = len(m.ChainId) + if l > 0 { + n += 1 + l + sovPrivval(uint64(l)) + } + return n +} + +func (m *SignedProposalResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Proposal.Size() + n += 1 + l + sovPrivval(uint64(l)) + if m.Error != nil { + l = m.Error.Size() + n += 1 + l + sovPrivval(uint64(l)) + } + return n +} + +func (m *PingRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *PingResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *Message) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Sum != nil { + n += m.Sum.Size() + } + return n +} + +func (m *Message_PubKeyRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PubKeyRequest != nil { + l = m.PubKeyRequest.Size() + n += 1 + l + sovPrivval(uint64(l)) + } + return n +} +func (m *Message_PubKeyResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PubKeyResponse != nil { + l = m.PubKeyResponse.Size() + n += 1 + l + sovPrivval(uint64(l)) + } + return n +} +func (m *Message_SignVoteRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.SignVoteRequest != nil { + l = m.SignVoteRequest.Size() + n += 1 + l + sovPrivval(uint64(l)) + } + return n +} +func (m *Message_SignedVoteResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.SignedVoteResponse != nil { + l = m.SignedVoteResponse.Size() + n += 1 + l + sovPrivval(uint64(l)) + } + return n +} +func (m *Message_SignProposalRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.SignProposalRequest != nil { + l = m.SignProposalRequest.Size() + n += 1 + l + sovPrivval(uint64(l)) + } + return n +} +func (m *Message_SignedProposalResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.SignedProposalResponse != nil { + l = m.SignedProposalResponse.Size() + n += 1 + l + sovPrivval(uint64(l)) + } + return n +} +func (m *Message_PingRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PingRequest != nil { + l = m.PingRequest.Size() + n += 1 + l + sovPrivval(uint64(l)) + } + return n +} +func (m *Message_PingResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PingResponse != nil { + l = m.PingResponse.Size() + n += 1 + l + sovPrivval(uint64(l)) + } + return n +} + +func sovPrivval(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozPrivval(x uint64) (n int) { + return sovPrivval(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *RemoteSignerError) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: RemoteSignerError: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: RemoteSignerError: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Code", wireType) + } + m.Code = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Code |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPrivval + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPrivval + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Description = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPrivval(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPrivval + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PubKeyRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PubKeyRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PubKeyRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPrivval + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPrivval + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPrivval(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPrivval + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PubKeyResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PubKeyResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PubKeyResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PubKey", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPrivval + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPrivval + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.PubKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Error", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPrivval + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPrivval + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Error == nil { + m.Error = &RemoteSignerError{} + } + if err := m.Error.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPrivval(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPrivval + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *SignVoteRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: SignVoteRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SignVoteRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Vote", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPrivval + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPrivval + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Vote == nil { + m.Vote = &types.Vote{} + } + if err := m.Vote.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPrivval + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPrivval + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPrivval(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPrivval + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *SignedVoteResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: SignedVoteResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SignedVoteResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Vote", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPrivval + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPrivval + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Vote.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Error", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPrivval + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPrivval + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Error == nil { + m.Error = &RemoteSignerError{} + } + if err := m.Error.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPrivval(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPrivval + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *SignProposalRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: SignProposalRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SignProposalRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Proposal", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPrivval + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPrivval + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Proposal == nil { + m.Proposal = &types.Proposal{} + } + if err := m.Proposal.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPrivval + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPrivval + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPrivval(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPrivval + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *SignedProposalResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: SignedProposalResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SignedProposalResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Proposal", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPrivval + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPrivval + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Proposal.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Error", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPrivval + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPrivval + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Error == nil { + m.Error = &RemoteSignerError{} + } + if err := m.Error.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPrivval(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPrivval + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PingRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PingRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PingRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipPrivval(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPrivval + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PingResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PingResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PingResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipPrivval(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPrivval + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Message) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Message: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Message: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PubKeyRequest", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPrivval + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPrivval + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &PubKeyRequest{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &Message_PubKeyRequest{v} + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PubKeyResponse", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPrivval + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPrivval + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &PubKeyResponse{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &Message_PubKeyResponse{v} + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SignVoteRequest", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPrivval + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPrivval + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &SignVoteRequest{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &Message_SignVoteRequest{v} + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SignedVoteResponse", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPrivval + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPrivval + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &SignedVoteResponse{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &Message_SignedVoteResponse{v} + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SignProposalRequest", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPrivval + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPrivval + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &SignProposalRequest{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &Message_SignProposalRequest{v} + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SignedProposalResponse", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPrivval + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPrivval + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &SignedProposalResponse{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &Message_SignedProposalResponse{v} + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PingRequest", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPrivval + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPrivval + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &PingRequest{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &Message_PingRequest{v} + iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PingResponse", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivval + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPrivval + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPrivval + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &PingResponse{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &Message_PingResponse{v} + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPrivval(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPrivval + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipPrivval(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPrivval + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPrivval + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPrivval + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthPrivval + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupPrivval + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthPrivval + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthPrivval = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowPrivval = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupPrivval = fmt.Errorf("proto: unexpected end of group") +) diff --git a/comet/proto/types/canonical.pb.go b/comet/proto/types/canonical.pb.go new file mode 100644 index 00000000..5d302b96 --- /dev/null +++ b/comet/proto/types/canonical.pb.go @@ -0,0 +1,1661 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: tendermint/types/canonical.proto + +package types + +import ( + encoding_binary "encoding/binary" + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + github_com_cosmos_gogoproto_types "github.com/cosmos/gogoproto/types" + _ "google.golang.org/protobuf/types/known/timestamppb" + io "io" + math "math" + math_bits "math/bits" + time "time" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf +var _ = time.Kitchen + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type CanonicalBlockID struct { + Hash []byte `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"` + PartSetHeader CanonicalPartSetHeader `protobuf:"bytes,2,opt,name=part_set_header,json=partSetHeader,proto3" json:"part_set_header"` +} + +func (m *CanonicalBlockID) Reset() { *m = CanonicalBlockID{} } +func (m *CanonicalBlockID) String() string { return proto.CompactTextString(m) } +func (*CanonicalBlockID) ProtoMessage() {} +func (*CanonicalBlockID) Descriptor() ([]byte, []int) { + return fileDescriptor_8d1a1a84ff7267ed, []int{0} +} +func (m *CanonicalBlockID) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CanonicalBlockID) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CanonicalBlockID.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *CanonicalBlockID) XXX_Merge(src proto.Message) { + xxx_messageInfo_CanonicalBlockID.Merge(m, src) +} +func (m *CanonicalBlockID) XXX_Size() int { + return m.Size() +} +func (m *CanonicalBlockID) XXX_DiscardUnknown() { + xxx_messageInfo_CanonicalBlockID.DiscardUnknown(m) +} + +var xxx_messageInfo_CanonicalBlockID proto.InternalMessageInfo + +func (m *CanonicalBlockID) GetHash() []byte { + if m != nil { + return m.Hash + } + return nil +} + +func (m *CanonicalBlockID) GetPartSetHeader() CanonicalPartSetHeader { + if m != nil { + return m.PartSetHeader + } + return CanonicalPartSetHeader{} +} + +type CanonicalPartSetHeader struct { + Total uint32 `protobuf:"varint,1,opt,name=total,proto3" json:"total,omitempty"` + Hash []byte `protobuf:"bytes,2,opt,name=hash,proto3" json:"hash,omitempty"` +} + +func (m *CanonicalPartSetHeader) Reset() { *m = CanonicalPartSetHeader{} } +func (m *CanonicalPartSetHeader) String() string { return proto.CompactTextString(m) } +func (*CanonicalPartSetHeader) ProtoMessage() {} +func (*CanonicalPartSetHeader) Descriptor() ([]byte, []int) { + return fileDescriptor_8d1a1a84ff7267ed, []int{1} +} +func (m *CanonicalPartSetHeader) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CanonicalPartSetHeader) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CanonicalPartSetHeader.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *CanonicalPartSetHeader) XXX_Merge(src proto.Message) { + xxx_messageInfo_CanonicalPartSetHeader.Merge(m, src) +} +func (m *CanonicalPartSetHeader) XXX_Size() int { + return m.Size() +} +func (m *CanonicalPartSetHeader) XXX_DiscardUnknown() { + xxx_messageInfo_CanonicalPartSetHeader.DiscardUnknown(m) +} + +var xxx_messageInfo_CanonicalPartSetHeader proto.InternalMessageInfo + +func (m *CanonicalPartSetHeader) GetTotal() uint32 { + if m != nil { + return m.Total + } + return 0 +} + +func (m *CanonicalPartSetHeader) GetHash() []byte { + if m != nil { + return m.Hash + } + return nil +} + +type CanonicalProposal struct { + Type SignedMsgType `protobuf:"varint,1,opt,name=type,proto3,enum=tendermint.types.SignedMsgType" json:"type,omitempty"` + Height int64 `protobuf:"fixed64,2,opt,name=height,proto3" json:"height,omitempty"` + Round int64 `protobuf:"fixed64,3,opt,name=round,proto3" json:"round,omitempty"` + POLRound int64 `protobuf:"varint,4,opt,name=pol_round,json=polRound,proto3" json:"pol_round,omitempty"` + BlockID *CanonicalBlockID `protobuf:"bytes,5,opt,name=block_id,json=blockId,proto3" json:"block_id,omitempty"` + Timestamp time.Time `protobuf:"bytes,6,opt,name=timestamp,proto3,stdtime" json:"timestamp"` + ChainID string `protobuf:"bytes,7,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` +} + +func (m *CanonicalProposal) Reset() { *m = CanonicalProposal{} } +func (m *CanonicalProposal) String() string { return proto.CompactTextString(m) } +func (*CanonicalProposal) ProtoMessage() {} +func (*CanonicalProposal) Descriptor() ([]byte, []int) { + return fileDescriptor_8d1a1a84ff7267ed, []int{2} +} +func (m *CanonicalProposal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CanonicalProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CanonicalProposal.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *CanonicalProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_CanonicalProposal.Merge(m, src) +} +func (m *CanonicalProposal) XXX_Size() int { + return m.Size() +} +func (m *CanonicalProposal) XXX_DiscardUnknown() { + xxx_messageInfo_CanonicalProposal.DiscardUnknown(m) +} + +var xxx_messageInfo_CanonicalProposal proto.InternalMessageInfo + +func (m *CanonicalProposal) GetType() SignedMsgType { + if m != nil { + return m.Type + } + return UnknownType +} + +func (m *CanonicalProposal) GetHeight() int64 { + if m != nil { + return m.Height + } + return 0 +} + +func (m *CanonicalProposal) GetRound() int64 { + if m != nil { + return m.Round + } + return 0 +} + +func (m *CanonicalProposal) GetPOLRound() int64 { + if m != nil { + return m.POLRound + } + return 0 +} + +func (m *CanonicalProposal) GetBlockID() *CanonicalBlockID { + if m != nil { + return m.BlockID + } + return nil +} + +func (m *CanonicalProposal) GetTimestamp() time.Time { + if m != nil { + return m.Timestamp + } + return time.Time{} +} + +func (m *CanonicalProposal) GetChainID() string { + if m != nil { + return m.ChainID + } + return "" +} + +type CanonicalVote struct { + Type SignedMsgType `protobuf:"varint,1,opt,name=type,proto3,enum=tendermint.types.SignedMsgType" json:"type,omitempty"` + Height int64 `protobuf:"fixed64,2,opt,name=height,proto3" json:"height,omitempty"` + Round int64 `protobuf:"fixed64,3,opt,name=round,proto3" json:"round,omitempty"` + BlockID *CanonicalBlockID `protobuf:"bytes,4,opt,name=block_id,json=blockId,proto3" json:"block_id,omitempty"` + Timestamp time.Time `protobuf:"bytes,5,opt,name=timestamp,proto3,stdtime" json:"timestamp"` + ChainID string `protobuf:"bytes,6,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` +} + +func (m *CanonicalVote) Reset() { *m = CanonicalVote{} } +func (m *CanonicalVote) String() string { return proto.CompactTextString(m) } +func (*CanonicalVote) ProtoMessage() {} +func (*CanonicalVote) Descriptor() ([]byte, []int) { + return fileDescriptor_8d1a1a84ff7267ed, []int{3} +} +func (m *CanonicalVote) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CanonicalVote) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CanonicalVote.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *CanonicalVote) XXX_Merge(src proto.Message) { + xxx_messageInfo_CanonicalVote.Merge(m, src) +} +func (m *CanonicalVote) XXX_Size() int { + return m.Size() +} +func (m *CanonicalVote) XXX_DiscardUnknown() { + xxx_messageInfo_CanonicalVote.DiscardUnknown(m) +} + +var xxx_messageInfo_CanonicalVote proto.InternalMessageInfo + +func (m *CanonicalVote) GetType() SignedMsgType { + if m != nil { + return m.Type + } + return UnknownType +} + +func (m *CanonicalVote) GetHeight() int64 { + if m != nil { + return m.Height + } + return 0 +} + +func (m *CanonicalVote) GetRound() int64 { + if m != nil { + return m.Round + } + return 0 +} + +func (m *CanonicalVote) GetBlockID() *CanonicalBlockID { + if m != nil { + return m.BlockID + } + return nil +} + +func (m *CanonicalVote) GetTimestamp() time.Time { + if m != nil { + return m.Timestamp + } + return time.Time{} +} + +func (m *CanonicalVote) GetChainID() string { + if m != nil { + return m.ChainID + } + return "" +} + +// CanonicalVoteExtension provides us a way to serialize a vote extension from +// a particular validator such that we can sign over those serialized bytes. +type CanonicalVoteExtension struct { + Extension []byte `protobuf:"bytes,1,opt,name=extension,proto3" json:"extension,omitempty"` + Height int64 `protobuf:"fixed64,2,opt,name=height,proto3" json:"height,omitempty"` + Round int64 `protobuf:"fixed64,3,opt,name=round,proto3" json:"round,omitempty"` + ChainId string `protobuf:"bytes,4,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` +} + +func (m *CanonicalVoteExtension) Reset() { *m = CanonicalVoteExtension{} } +func (m *CanonicalVoteExtension) String() string { return proto.CompactTextString(m) } +func (*CanonicalVoteExtension) ProtoMessage() {} +func (*CanonicalVoteExtension) Descriptor() ([]byte, []int) { + return fileDescriptor_8d1a1a84ff7267ed, []int{4} +} +func (m *CanonicalVoteExtension) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CanonicalVoteExtension) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CanonicalVoteExtension.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *CanonicalVoteExtension) XXX_Merge(src proto.Message) { + xxx_messageInfo_CanonicalVoteExtension.Merge(m, src) +} +func (m *CanonicalVoteExtension) XXX_Size() int { + return m.Size() +} +func (m *CanonicalVoteExtension) XXX_DiscardUnknown() { + xxx_messageInfo_CanonicalVoteExtension.DiscardUnknown(m) +} + +var xxx_messageInfo_CanonicalVoteExtension proto.InternalMessageInfo + +func (m *CanonicalVoteExtension) GetExtension() []byte { + if m != nil { + return m.Extension + } + return nil +} + +func (m *CanonicalVoteExtension) GetHeight() int64 { + if m != nil { + return m.Height + } + return 0 +} + +func (m *CanonicalVoteExtension) GetRound() int64 { + if m != nil { + return m.Round + } + return 0 +} + +func (m *CanonicalVoteExtension) GetChainId() string { + if m != nil { + return m.ChainId + } + return "" +} + +func init() { + proto.RegisterType((*CanonicalBlockID)(nil), "tendermint.types.CanonicalBlockID") + proto.RegisterType((*CanonicalPartSetHeader)(nil), "tendermint.types.CanonicalPartSetHeader") + proto.RegisterType((*CanonicalProposal)(nil), "tendermint.types.CanonicalProposal") + proto.RegisterType((*CanonicalVote)(nil), "tendermint.types.CanonicalVote") + proto.RegisterType((*CanonicalVoteExtension)(nil), "tendermint.types.CanonicalVoteExtension") +} + +func init() { proto.RegisterFile("tendermint/types/canonical.proto", fileDescriptor_8d1a1a84ff7267ed) } + +var fileDescriptor_8d1a1a84ff7267ed = []byte{ + // 545 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x54, 0xcd, 0x6e, 0xd3, 0x40, + 0x10, 0x8e, 0xd3, 0xfc, 0x6e, 0x1b, 0x08, 0xab, 0xaa, 0x0a, 0x51, 0x65, 0x47, 0x39, 0xa0, 0x70, + 0xc0, 0x96, 0x9a, 0x2b, 0x27, 0x17, 0x24, 0x82, 0x40, 0x54, 0x6e, 0x95, 0x03, 0x97, 0x68, 0x63, + 0x0f, 0xb6, 0x85, 0xb3, 0x63, 0xad, 0x37, 0x51, 0x7b, 0x81, 0x57, 0xe8, 0x73, 0xf0, 0x24, 0x3d, + 0xf6, 0x08, 0x97, 0x80, 0x92, 0x17, 0x41, 0xbb, 0xce, 0x9f, 0x28, 0xaa, 0x84, 0x40, 0x5c, 0xac, + 0xf9, 0x66, 0xbe, 0x9d, 0xf9, 0xf4, 0x8d, 0x77, 0x49, 0x47, 0x02, 0x0f, 0x40, 0x4c, 0x62, 0x2e, + 0x1d, 0x79, 0x95, 0x42, 0xe6, 0xf8, 0x8c, 0x23, 0x8f, 0x7d, 0x96, 0xd8, 0xa9, 0x40, 0x89, 0xb4, + 0xb9, 0x65, 0xd8, 0x9a, 0xd1, 0x3e, 0x0c, 0x31, 0x44, 0x5d, 0x74, 0x54, 0x94, 0xf3, 0xda, 0xc7, + 0x77, 0x3a, 0xe9, 0xef, 0xaa, 0x6a, 0x85, 0x88, 0x61, 0x02, 0x8e, 0x46, 0xe3, 0xe9, 0x07, 0x47, + 0xc6, 0x13, 0xc8, 0x24, 0x9b, 0xa4, 0x39, 0xa1, 0xfb, 0x89, 0x34, 0x4f, 0xd7, 0x93, 0xdd, 0x04, + 0xfd, 0x8f, 0x83, 0x17, 0x94, 0x92, 0x52, 0xc4, 0xb2, 0xa8, 0x65, 0x74, 0x8c, 0xde, 0x81, 0xa7, + 0x63, 0x3a, 0x24, 0x0f, 0x53, 0x26, 0xe4, 0x28, 0x03, 0x39, 0x8a, 0x80, 0x05, 0x20, 0x5a, 0xc5, + 0x8e, 0xd1, 0xdb, 0x3f, 0xe9, 0xd9, 0xbf, 0x0a, 0xb5, 0x37, 0x0d, 0xcf, 0x98, 0x90, 0xe7, 0x20, + 0x5f, 0x69, 0xbe, 0x5b, 0xba, 0x99, 0x5b, 0x05, 0xaf, 0x91, 0xee, 0x26, 0xbb, 0x2e, 0x39, 0xfa, + 0x3d, 0x9d, 0x1e, 0x92, 0xb2, 0x44, 0xc9, 0x12, 0x2d, 0xa3, 0xe1, 0xe5, 0x60, 0xa3, 0xad, 0xb8, + 0xd5, 0xd6, 0xfd, 0x56, 0x24, 0x8f, 0xb6, 0x4d, 0x04, 0xa6, 0x98, 0xb1, 0x84, 0xf6, 0x49, 0x49, + 0xc9, 0xd1, 0xc7, 0x1f, 0x9c, 0x58, 0x77, 0x65, 0x9e, 0xc7, 0x21, 0x87, 0xe0, 0x6d, 0x16, 0x5e, + 0x5c, 0xa5, 0xe0, 0x69, 0x32, 0x3d, 0x22, 0x95, 0x08, 0xe2, 0x30, 0x92, 0x7a, 0x40, 0xd3, 0x5b, + 0x21, 0x25, 0x46, 0xe0, 0x94, 0x07, 0xad, 0x3d, 0x9d, 0xce, 0x01, 0x7d, 0x4a, 0xea, 0x29, 0x26, + 0xa3, 0xbc, 0x52, 0xea, 0x18, 0xbd, 0x3d, 0xf7, 0x60, 0x31, 0xb7, 0x6a, 0x67, 0xef, 0xde, 0x78, + 0x2a, 0xe7, 0xd5, 0x52, 0x4c, 0x74, 0x44, 0x5f, 0x93, 0xda, 0x58, 0xd9, 0x3b, 0x8a, 0x83, 0x56, + 0x59, 0x1b, 0xd7, 0xbd, 0xc7, 0xb8, 0xd5, 0x26, 0xdc, 0xfd, 0xc5, 0xdc, 0xaa, 0xae, 0x80, 0x57, + 0xd5, 0x0d, 0x06, 0x01, 0x75, 0x49, 0x7d, 0xb3, 0xc6, 0x56, 0x45, 0x37, 0x6b, 0xdb, 0xf9, 0xa2, + 0xed, 0xf5, 0xa2, 0xed, 0x8b, 0x35, 0xc3, 0xad, 0x29, 0xdf, 0xaf, 0xbf, 0x5b, 0x86, 0xb7, 0x3d, + 0x46, 0x9f, 0x90, 0x9a, 0x1f, 0xb1, 0x98, 0x2b, 0x3d, 0xd5, 0x8e, 0xd1, 0xab, 0xe7, 0xb3, 0x4e, + 0x55, 0x4e, 0xcd, 0xd2, 0xc5, 0x41, 0xd0, 0xfd, 0x52, 0x24, 0x8d, 0x8d, 0xac, 0x21, 0x4a, 0xf8, + 0x1f, 0xbe, 0xee, 0x9a, 0x55, 0xfa, 0x97, 0x66, 0x95, 0xff, 0xde, 0xac, 0xca, 0x3d, 0x66, 0x7d, + 0xde, 0xf9, 0x99, 0x95, 0x57, 0x2f, 0x2f, 0x25, 0xf0, 0x2c, 0x46, 0x4e, 0x8f, 0x49, 0x1d, 0xd6, + 0x60, 0x75, 0xaf, 0xb6, 0x89, 0x3f, 0x74, 0xe7, 0xf1, 0x8e, 0x1a, 0xe5, 0x4e, 0x7d, 0x23, 0xc0, + 0x1d, 0xde, 0x2c, 0x4c, 0xe3, 0x76, 0x61, 0x1a, 0x3f, 0x16, 0xa6, 0x71, 0xbd, 0x34, 0x0b, 0xb7, + 0x4b, 0xb3, 0xf0, 0x75, 0x69, 0x16, 0xde, 0x3f, 0x0f, 0x63, 0x19, 0x4d, 0xc7, 0xb6, 0x8f, 0x13, + 0x27, 0x93, 0x82, 0xf1, 0x10, 0x12, 0x9c, 0xc1, 0xb3, 0x19, 0x70, 0x39, 0x15, 0x90, 0x39, 0x11, + 0x0a, 0x5f, 0x4c, 0x2f, 0x9d, 0x59, 0xdf, 0xf1, 0x71, 0x02, 0x32, 0x7f, 0x32, 0xf2, 0xc7, 0x64, + 0x5c, 0xd1, 0xa0, 0xff, 0x33, 0x00, 0x00, 0xff, 0xff, 0x38, 0x82, 0x5b, 0xa1, 0xb7, 0x04, 0x00, + 0x00, +} + +func (m *CanonicalBlockID) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *CanonicalBlockID) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CanonicalBlockID) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.PartSetHeader.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCanonical(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Hash) > 0 { + i -= len(m.Hash) + copy(dAtA[i:], m.Hash) + i = encodeVarintCanonical(dAtA, i, uint64(len(m.Hash))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *CanonicalPartSetHeader) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *CanonicalPartSetHeader) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CanonicalPartSetHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Hash) > 0 { + i -= len(m.Hash) + copy(dAtA[i:], m.Hash) + i = encodeVarintCanonical(dAtA, i, uint64(len(m.Hash))) + i-- + dAtA[i] = 0x12 + } + if m.Total != 0 { + i = encodeVarintCanonical(dAtA, i, uint64(m.Total)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *CanonicalProposal) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *CanonicalProposal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CanonicalProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ChainID) > 0 { + i -= len(m.ChainID) + copy(dAtA[i:], m.ChainID) + i = encodeVarintCanonical(dAtA, i, uint64(len(m.ChainID))) + i-- + dAtA[i] = 0x3a + } + n2, err2 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.Timestamp, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.Timestamp):]) + if err2 != nil { + return 0, err2 + } + i -= n2 + i = encodeVarintCanonical(dAtA, i, uint64(n2)) + i-- + dAtA[i] = 0x32 + if m.BlockID != nil { + { + size, err := m.BlockID.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCanonical(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + if m.POLRound != 0 { + i = encodeVarintCanonical(dAtA, i, uint64(m.POLRound)) + i-- + dAtA[i] = 0x20 + } + if m.Round != 0 { + i -= 8 + encoding_binary.LittleEndian.PutUint64(dAtA[i:], uint64(m.Round)) + i-- + dAtA[i] = 0x19 + } + if m.Height != 0 { + i -= 8 + encoding_binary.LittleEndian.PutUint64(dAtA[i:], uint64(m.Height)) + i-- + dAtA[i] = 0x11 + } + if m.Type != 0 { + i = encodeVarintCanonical(dAtA, i, uint64(m.Type)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *CanonicalVote) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *CanonicalVote) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CanonicalVote) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ChainID) > 0 { + i -= len(m.ChainID) + copy(dAtA[i:], m.ChainID) + i = encodeVarintCanonical(dAtA, i, uint64(len(m.ChainID))) + i-- + dAtA[i] = 0x32 + } + n4, err4 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.Timestamp, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.Timestamp):]) + if err4 != nil { + return 0, err4 + } + i -= n4 + i = encodeVarintCanonical(dAtA, i, uint64(n4)) + i-- + dAtA[i] = 0x2a + if m.BlockID != nil { + { + size, err := m.BlockID.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCanonical(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + if m.Round != 0 { + i -= 8 + encoding_binary.LittleEndian.PutUint64(dAtA[i:], uint64(m.Round)) + i-- + dAtA[i] = 0x19 + } + if m.Height != 0 { + i -= 8 + encoding_binary.LittleEndian.PutUint64(dAtA[i:], uint64(m.Height)) + i-- + dAtA[i] = 0x11 + } + if m.Type != 0 { + i = encodeVarintCanonical(dAtA, i, uint64(m.Type)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *CanonicalVoteExtension) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *CanonicalVoteExtension) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CanonicalVoteExtension) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ChainId) > 0 { + i -= len(m.ChainId) + copy(dAtA[i:], m.ChainId) + i = encodeVarintCanonical(dAtA, i, uint64(len(m.ChainId))) + i-- + dAtA[i] = 0x22 + } + if m.Round != 0 { + i -= 8 + encoding_binary.LittleEndian.PutUint64(dAtA[i:], uint64(m.Round)) + i-- + dAtA[i] = 0x19 + } + if m.Height != 0 { + i -= 8 + encoding_binary.LittleEndian.PutUint64(dAtA[i:], uint64(m.Height)) + i-- + dAtA[i] = 0x11 + } + if len(m.Extension) > 0 { + i -= len(m.Extension) + copy(dAtA[i:], m.Extension) + i = encodeVarintCanonical(dAtA, i, uint64(len(m.Extension))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintCanonical(dAtA []byte, offset int, v uint64) int { + offset -= sovCanonical(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *CanonicalBlockID) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Hash) + if l > 0 { + n += 1 + l + sovCanonical(uint64(l)) + } + l = m.PartSetHeader.Size() + n += 1 + l + sovCanonical(uint64(l)) + return n +} + +func (m *CanonicalPartSetHeader) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Total != 0 { + n += 1 + sovCanonical(uint64(m.Total)) + } + l = len(m.Hash) + if l > 0 { + n += 1 + l + sovCanonical(uint64(l)) + } + return n +} + +func (m *CanonicalProposal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Type != 0 { + n += 1 + sovCanonical(uint64(m.Type)) + } + if m.Height != 0 { + n += 9 + } + if m.Round != 0 { + n += 9 + } + if m.POLRound != 0 { + n += 1 + sovCanonical(uint64(m.POLRound)) + } + if m.BlockID != nil { + l = m.BlockID.Size() + n += 1 + l + sovCanonical(uint64(l)) + } + l = github_com_cosmos_gogoproto_types.SizeOfStdTime(m.Timestamp) + n += 1 + l + sovCanonical(uint64(l)) + l = len(m.ChainID) + if l > 0 { + n += 1 + l + sovCanonical(uint64(l)) + } + return n +} + +func (m *CanonicalVote) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Type != 0 { + n += 1 + sovCanonical(uint64(m.Type)) + } + if m.Height != 0 { + n += 9 + } + if m.Round != 0 { + n += 9 + } + if m.BlockID != nil { + l = m.BlockID.Size() + n += 1 + l + sovCanonical(uint64(l)) + } + l = github_com_cosmos_gogoproto_types.SizeOfStdTime(m.Timestamp) + n += 1 + l + sovCanonical(uint64(l)) + l = len(m.ChainID) + if l > 0 { + n += 1 + l + sovCanonical(uint64(l)) + } + return n +} + +func (m *CanonicalVoteExtension) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Extension) + if l > 0 { + n += 1 + l + sovCanonical(uint64(l)) + } + if m.Height != 0 { + n += 9 + } + if m.Round != 0 { + n += 9 + } + l = len(m.ChainId) + if l > 0 { + n += 1 + l + sovCanonical(uint64(l)) + } + return n +} + +func sovCanonical(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozCanonical(x uint64) (n int) { + return sovCanonical(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *CanonicalBlockID) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCanonical + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: CanonicalBlockID: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CanonicalBlockID: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Hash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCanonical + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthCanonical + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthCanonical + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Hash = append(m.Hash[:0], dAtA[iNdEx:postIndex]...) + if m.Hash == nil { + m.Hash = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PartSetHeader", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCanonical + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCanonical + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCanonical + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.PartSetHeader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCanonical(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCanonical + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *CanonicalPartSetHeader) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCanonical + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: CanonicalPartSetHeader: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CanonicalPartSetHeader: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Total", wireType) + } + m.Total = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCanonical + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Total |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Hash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCanonical + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthCanonical + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthCanonical + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Hash = append(m.Hash[:0], dAtA[iNdEx:postIndex]...) + if m.Hash == nil { + m.Hash = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCanonical(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCanonical + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *CanonicalProposal) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCanonical + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: CanonicalProposal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CanonicalProposal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) + } + m.Type = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCanonical + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Type |= SignedMsgType(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 1 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + if (iNdEx + 8) > l { + return io.ErrUnexpectedEOF + } + m.Height = int64(encoding_binary.LittleEndian.Uint64(dAtA[iNdEx:])) + iNdEx += 8 + case 3: + if wireType != 1 { + return fmt.Errorf("proto: wrong wireType = %d for field Round", wireType) + } + m.Round = 0 + if (iNdEx + 8) > l { + return io.ErrUnexpectedEOF + } + m.Round = int64(encoding_binary.LittleEndian.Uint64(dAtA[iNdEx:])) + iNdEx += 8 + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field POLRound", wireType) + } + m.POLRound = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCanonical + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.POLRound |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockID", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCanonical + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCanonical + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCanonical + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.BlockID == nil { + m.BlockID = &CanonicalBlockID{} + } + if err := m.BlockID.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Timestamp", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCanonical + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCanonical + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCanonical + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_cosmos_gogoproto_types.StdTimeUnmarshal(&m.Timestamp, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCanonical + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCanonical + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCanonical + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCanonical(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCanonical + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *CanonicalVote) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCanonical + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: CanonicalVote: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CanonicalVote: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) + } + m.Type = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCanonical + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Type |= SignedMsgType(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 1 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + if (iNdEx + 8) > l { + return io.ErrUnexpectedEOF + } + m.Height = int64(encoding_binary.LittleEndian.Uint64(dAtA[iNdEx:])) + iNdEx += 8 + case 3: + if wireType != 1 { + return fmt.Errorf("proto: wrong wireType = %d for field Round", wireType) + } + m.Round = 0 + if (iNdEx + 8) > l { + return io.ErrUnexpectedEOF + } + m.Round = int64(encoding_binary.LittleEndian.Uint64(dAtA[iNdEx:])) + iNdEx += 8 + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockID", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCanonical + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCanonical + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCanonical + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.BlockID == nil { + m.BlockID = &CanonicalBlockID{} + } + if err := m.BlockID.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Timestamp", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCanonical + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCanonical + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCanonical + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_cosmos_gogoproto_types.StdTimeUnmarshal(&m.Timestamp, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCanonical + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCanonical + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCanonical + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCanonical(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCanonical + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *CanonicalVoteExtension) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCanonical + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: CanonicalVoteExtension: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CanonicalVoteExtension: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Extension", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCanonical + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthCanonical + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthCanonical + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Extension = append(m.Extension[:0], dAtA[iNdEx:postIndex]...) + if m.Extension == nil { + m.Extension = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 1 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + if (iNdEx + 8) > l { + return io.ErrUnexpectedEOF + } + m.Height = int64(encoding_binary.LittleEndian.Uint64(dAtA[iNdEx:])) + iNdEx += 8 + case 3: + if wireType != 1 { + return fmt.Errorf("proto: wrong wireType = %d for field Round", wireType) + } + m.Round = 0 + if (iNdEx + 8) > l { + return io.ErrUnexpectedEOF + } + m.Round = int64(encoding_binary.LittleEndian.Uint64(dAtA[iNdEx:])) + iNdEx += 8 + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCanonical + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCanonical + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCanonical + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCanonical(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCanonical + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipCanonical(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCanonical + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCanonical + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCanonical + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthCanonical + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupCanonical + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthCanonical + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthCanonical = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowCanonical = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupCanonical = fmt.Errorf("proto: unexpected end of group") +) diff --git a/comet/proto/types/types.pb.go b/comet/proto/types/types.pb.go new file mode 100644 index 00000000..d6f69271 --- /dev/null +++ b/comet/proto/types/types.pb.go @@ -0,0 +1,1650 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: tendermint/types/types.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + github_com_cosmos_gogoproto_types "github.com/cosmos/gogoproto/types" + _ "google.golang.org/protobuf/types/known/timestamppb" + io "io" + math "math" + math_bits "math/bits" + time "time" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf +var _ = time.Kitchen + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// SignedMsgType is a type of signed message in the consensus. +type SignedMsgType int32 + +const ( + UnknownType SignedMsgType = 0 + // Votes + PrevoteType SignedMsgType = 1 + PrecommitType SignedMsgType = 2 + // Proposals + ProposalType SignedMsgType = 32 +) + +var SignedMsgType_name = map[int32]string{ + 0: "SIGNED_MSG_TYPE_UNKNOWN", + 1: "SIGNED_MSG_TYPE_PREVOTE", + 2: "SIGNED_MSG_TYPE_PRECOMMIT", + 32: "SIGNED_MSG_TYPE_PROPOSAL", +} + +var SignedMsgType_value = map[string]int32{ + "SIGNED_MSG_TYPE_UNKNOWN": 0, + "SIGNED_MSG_TYPE_PREVOTE": 1, + "SIGNED_MSG_TYPE_PRECOMMIT": 2, + "SIGNED_MSG_TYPE_PROPOSAL": 32, +} + +func (x SignedMsgType) String() string { + return proto.EnumName(SignedMsgType_name, int32(x)) +} + +func (SignedMsgType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_d3a6e55e2345de56, []int{0} +} + +// PartSetHeader +type PartSetHeader struct { + Total uint32 `protobuf:"varint,1,opt,name=total,proto3" json:"total,omitempty"` + Hash []byte `protobuf:"bytes,2,opt,name=hash,proto3" json:"hash,omitempty"` +} + +func (m *PartSetHeader) Reset() { *m = PartSetHeader{} } +func (m *PartSetHeader) String() string { return proto.CompactTextString(m) } +func (*PartSetHeader) ProtoMessage() {} +func (*PartSetHeader) Descriptor() ([]byte, []int) { + return fileDescriptor_d3a6e55e2345de56, []int{0} +} +func (m *PartSetHeader) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PartSetHeader) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PartSetHeader.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *PartSetHeader) XXX_Merge(src proto.Message) { + xxx_messageInfo_PartSetHeader.Merge(m, src) +} +func (m *PartSetHeader) XXX_Size() int { + return m.Size() +} +func (m *PartSetHeader) XXX_DiscardUnknown() { + xxx_messageInfo_PartSetHeader.DiscardUnknown(m) +} + +var xxx_messageInfo_PartSetHeader proto.InternalMessageInfo + +func (m *PartSetHeader) GetTotal() uint32 { + if m != nil { + return m.Total + } + return 0 +} + +func (m *PartSetHeader) GetHash() []byte { + if m != nil { + return m.Hash + } + return nil +} + +// BlockID +type BlockID struct { + Hash []byte `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"` + PartSetHeader PartSetHeader `protobuf:"bytes,2,opt,name=part_set_header,json=partSetHeader,proto3" json:"part_set_header"` +} + +func (m *BlockID) Reset() { *m = BlockID{} } +func (m *BlockID) String() string { return proto.CompactTextString(m) } +func (*BlockID) ProtoMessage() {} +func (*BlockID) Descriptor() ([]byte, []int) { + return fileDescriptor_d3a6e55e2345de56, []int{1} +} +func (m *BlockID) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *BlockID) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_BlockID.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *BlockID) XXX_Merge(src proto.Message) { + xxx_messageInfo_BlockID.Merge(m, src) +} +func (m *BlockID) XXX_Size() int { + return m.Size() +} +func (m *BlockID) XXX_DiscardUnknown() { + xxx_messageInfo_BlockID.DiscardUnknown(m) +} + +var xxx_messageInfo_BlockID proto.InternalMessageInfo + +func (m *BlockID) GetHash() []byte { + if m != nil { + return m.Hash + } + return nil +} + +func (m *BlockID) GetPartSetHeader() PartSetHeader { + if m != nil { + return m.PartSetHeader + } + return PartSetHeader{} +} + +// Vote represents a prevote or precommit vote from validators for +// consensus. +type Vote struct { + Type SignedMsgType `protobuf:"varint,1,opt,name=type,proto3,enum=tendermint.types.SignedMsgType" json:"type,omitempty"` + Height int64 `protobuf:"varint,2,opt,name=height,proto3" json:"height,omitempty"` + Round int32 `protobuf:"varint,3,opt,name=round,proto3" json:"round,omitempty"` + BlockID BlockID `protobuf:"bytes,4,opt,name=block_id,json=blockId,proto3" json:"block_id"` + Timestamp time.Time `protobuf:"bytes,5,opt,name=timestamp,proto3,stdtime" json:"timestamp"` + ValidatorAddress []byte `protobuf:"bytes,6,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` + ValidatorIndex int32 `protobuf:"varint,7,opt,name=validator_index,json=validatorIndex,proto3" json:"validator_index,omitempty"` + // Vote signature by the validator if they participated in consensus for the + // associated block. + Signature []byte `protobuf:"bytes,8,opt,name=signature,proto3" json:"signature,omitempty"` + // Vote extension provided by the application. Only valid for precommit + // messages. + Extension []byte `protobuf:"bytes,9,opt,name=extension,proto3" json:"extension,omitempty"` + // Vote extension signature by the validator if they participated in + // consensus for the associated block. + // Only valid for precommit messages. + ExtensionSignature []byte `protobuf:"bytes,10,opt,name=extension_signature,json=extensionSignature,proto3" json:"extension_signature,omitempty"` +} + +func (m *Vote) Reset() { *m = Vote{} } +func (m *Vote) String() string { return proto.CompactTextString(m) } +func (*Vote) ProtoMessage() {} +func (*Vote) Descriptor() ([]byte, []int) { + return fileDescriptor_d3a6e55e2345de56, []int{2} +} +func (m *Vote) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Vote) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Vote.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Vote) XXX_Merge(src proto.Message) { + xxx_messageInfo_Vote.Merge(m, src) +} +func (m *Vote) XXX_Size() int { + return m.Size() +} +func (m *Vote) XXX_DiscardUnknown() { + xxx_messageInfo_Vote.DiscardUnknown(m) +} + +var xxx_messageInfo_Vote proto.InternalMessageInfo + +func (m *Vote) GetType() SignedMsgType { + if m != nil { + return m.Type + } + return UnknownType +} + +func (m *Vote) GetHeight() int64 { + if m != nil { + return m.Height + } + return 0 +} + +func (m *Vote) GetRound() int32 { + if m != nil { + return m.Round + } + return 0 +} + +func (m *Vote) GetBlockID() BlockID { + if m != nil { + return m.BlockID + } + return BlockID{} +} + +func (m *Vote) GetTimestamp() time.Time { + if m != nil { + return m.Timestamp + } + return time.Time{} +} + +func (m *Vote) GetValidatorAddress() []byte { + if m != nil { + return m.ValidatorAddress + } + return nil +} + +func (m *Vote) GetValidatorIndex() int32 { + if m != nil { + return m.ValidatorIndex + } + return 0 +} + +func (m *Vote) GetSignature() []byte { + if m != nil { + return m.Signature + } + return nil +} + +func (m *Vote) GetExtension() []byte { + if m != nil { + return m.Extension + } + return nil +} + +func (m *Vote) GetExtensionSignature() []byte { + if m != nil { + return m.ExtensionSignature + } + return nil +} + +type Proposal struct { + Type SignedMsgType `protobuf:"varint,1,opt,name=type,proto3,enum=tendermint.types.SignedMsgType" json:"type,omitempty"` + Height int64 `protobuf:"varint,2,opt,name=height,proto3" json:"height,omitempty"` + Round int32 `protobuf:"varint,3,opt,name=round,proto3" json:"round,omitempty"` + PolRound int32 `protobuf:"varint,4,opt,name=pol_round,json=polRound,proto3" json:"pol_round,omitempty"` + BlockID BlockID `protobuf:"bytes,5,opt,name=block_id,json=blockId,proto3" json:"block_id"` + Timestamp time.Time `protobuf:"bytes,6,opt,name=timestamp,proto3,stdtime" json:"timestamp"` + Signature []byte `protobuf:"bytes,7,opt,name=signature,proto3" json:"signature,omitempty"` +} + +func (m *Proposal) Reset() { *m = Proposal{} } +func (m *Proposal) String() string { return proto.CompactTextString(m) } +func (*Proposal) ProtoMessage() {} +func (*Proposal) Descriptor() ([]byte, []int) { + return fileDescriptor_d3a6e55e2345de56, []int{3} +} +func (m *Proposal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Proposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Proposal.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Proposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_Proposal.Merge(m, src) +} +func (m *Proposal) XXX_Size() int { + return m.Size() +} +func (m *Proposal) XXX_DiscardUnknown() { + xxx_messageInfo_Proposal.DiscardUnknown(m) +} + +var xxx_messageInfo_Proposal proto.InternalMessageInfo + +func (m *Proposal) GetType() SignedMsgType { + if m != nil { + return m.Type + } + return UnknownType +} + +func (m *Proposal) GetHeight() int64 { + if m != nil { + return m.Height + } + return 0 +} + +func (m *Proposal) GetRound() int32 { + if m != nil { + return m.Round + } + return 0 +} + +func (m *Proposal) GetPolRound() int32 { + if m != nil { + return m.PolRound + } + return 0 +} + +func (m *Proposal) GetBlockID() BlockID { + if m != nil { + return m.BlockID + } + return BlockID{} +} + +func (m *Proposal) GetTimestamp() time.Time { + if m != nil { + return m.Timestamp + } + return time.Time{} +} + +func (m *Proposal) GetSignature() []byte { + if m != nil { + return m.Signature + } + return nil +} + +func init() { + //proto.RegisterEnum("tendermint.types.SignedMsgType", SignedMsgType_name, SignedMsgType_value) + proto.RegisterType((*PartSetHeader)(nil), "tendermint.types.PartSetHeader") + proto.RegisterType((*BlockID)(nil), "tendermint.types.BlockID") + proto.RegisterType((*Vote)(nil), "tendermint.types.Vote") + proto.RegisterType((*Proposal)(nil), "tendermint.types.Proposal") +} + +func init() { proto.RegisterFile("tendermint/types/types.proto", fileDescriptor_d3a6e55e2345de56) } + +var fileDescriptor_d3a6e55e2345de56 = []byte{ + // 672 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x54, 0xcb, 0x6e, 0xd3, 0x40, + 0x14, 0x8d, 0xdb, 0x3c, 0xa7, 0x4d, 0x93, 0x0e, 0x15, 0xb8, 0xa6, 0x72, 0xac, 0x6c, 0xa8, 0x78, + 0xd8, 0x88, 0xae, 0x90, 0xd8, 0x34, 0x34, 0x2a, 0x11, 0x24, 0xb1, 0x9c, 0xb4, 0x08, 0x36, 0x96, + 0x13, 0x0f, 0xb6, 0x55, 0x7b, 0xc6, 0x1a, 0x4f, 0x42, 0xfb, 0x07, 0xa8, 0xab, 0xfe, 0x40, 0x57, + 0xb0, 0x60, 0xcf, 0x82, 0x5f, 0xe8, 0xb2, 0x3b, 0x58, 0x15, 0x94, 0xfe, 0x08, 0xf2, 0xb8, 0x71, + 0xe8, 0x83, 0x0d, 0x42, 0x6c, 0x46, 0x73, 0xcf, 0x39, 0xf7, 0xce, 0xbd, 0xf7, 0x48, 0x03, 0xd6, + 0x18, 0xc2, 0x36, 0xa2, 0x81, 0x87, 0x99, 0xc6, 0x0e, 0x42, 0x14, 0x25, 0xa7, 0x1a, 0x52, 0xc2, + 0x08, 0xac, 0xce, 0x58, 0x95, 0xe3, 0xd2, 0x8a, 0x43, 0x1c, 0xc2, 0x49, 0x2d, 0xbe, 0x25, 0x3a, + 0xa9, 0xe6, 0x10, 0xe2, 0xf8, 0x48, 0xe3, 0xd1, 0x60, 0xf4, 0x4e, 0x63, 0x5e, 0x80, 0x22, 0x66, + 0x05, 0x61, 0x22, 0xa8, 0x3f, 0x05, 0x65, 0xdd, 0xa2, 0xac, 0x87, 0xd8, 0x0b, 0x64, 0xd9, 0x88, + 0xc2, 0x15, 0x90, 0x63, 0x84, 0x59, 0xbe, 0x28, 0x28, 0xc2, 0x7a, 0xd9, 0x48, 0x02, 0x08, 0x41, + 0xd6, 0xb5, 0x22, 0x57, 0x9c, 0x53, 0x84, 0xf5, 0x45, 0x83, 0xdf, 0xeb, 0x3e, 0x28, 0x34, 0x7c, + 0x32, 0xdc, 0x6b, 0x6d, 0xa5, 0xb4, 0x30, 0xa3, 0x61, 0x1b, 0x54, 0x42, 0x8b, 0x32, 0x33, 0x42, + 0xcc, 0x74, 0x79, 0x6d, 0x9e, 0xbd, 0xf0, 0xa4, 0xa6, 0x5e, 0x6d, 0x5e, 0xbd, 0xd4, 0x42, 0x23, + 0x7b, 0x72, 0x56, 0xcb, 0x18, 0xe5, 0xf0, 0x77, 0xb0, 0xfe, 0x75, 0x1e, 0x64, 0x77, 0x09, 0x43, + 0x70, 0x03, 0x64, 0xe3, 0x24, 0xfe, 0xd6, 0xd2, 0x4d, 0xc5, 0x7a, 0x9e, 0x83, 0x91, 0xdd, 0x8e, + 0x9c, 0xfe, 0x41, 0x88, 0x0c, 0x2e, 0x86, 0xb7, 0x41, 0xde, 0x45, 0x9e, 0xe3, 0x32, 0xde, 0xc3, + 0xbc, 0x71, 0x11, 0xc5, 0xd3, 0x52, 0x32, 0xc2, 0xb6, 0x38, 0xaf, 0x08, 0xeb, 0x39, 0x23, 0x09, + 0x60, 0x13, 0x14, 0x07, 0xf1, 0x64, 0xa6, 0x67, 0x8b, 0x59, 0xde, 0xf3, 0xea, 0xf5, 0x67, 0x2e, + 0x66, 0x6f, 0x54, 0xe2, 0x6e, 0x27, 0x67, 0xb5, 0xe9, 0x32, 0x8c, 0x02, 0xcf, 0x6d, 0xd9, 0xb0, + 0x01, 0x4a, 0xe9, 0xba, 0xc5, 0x1c, 0xaf, 0x23, 0xa9, 0x89, 0x21, 0xea, 0xd4, 0x10, 0xb5, 0x3f, + 0x55, 0x34, 0x8a, 0x71, 0xa1, 0xa3, 0x1f, 0x35, 0xc1, 0x98, 0xa5, 0xc1, 0x07, 0x60, 0x79, 0x6c, + 0xf9, 0x9e, 0x6d, 0x31, 0x42, 0x4d, 0xcb, 0xb6, 0x29, 0x8a, 0x22, 0x31, 0xcf, 0xd7, 0x5c, 0x4d, + 0x89, 0xcd, 0x04, 0x87, 0xf7, 0x40, 0x65, 0x26, 0xf6, 0xb0, 0x8d, 0xf6, 0xc5, 0x02, 0x9f, 0x6b, + 0x29, 0x85, 0x5b, 0x31, 0x0a, 0xd7, 0x40, 0x29, 0xf2, 0x1c, 0x6c, 0xb1, 0x11, 0x45, 0x62, 0x91, + 0x57, 0x9b, 0x01, 0x31, 0x8b, 0xf6, 0x19, 0xc2, 0x91, 0x47, 0xb0, 0x58, 0x4a, 0xd8, 0x14, 0x80, + 0x1a, 0xb8, 0x95, 0x06, 0xe6, 0xac, 0x0a, 0xe0, 0x3a, 0x98, 0x52, 0xbd, 0x29, 0x53, 0xff, 0x32, + 0x07, 0x8a, 0x3a, 0x25, 0x21, 0x89, 0x2c, 0xff, 0x7f, 0xb8, 0x77, 0x17, 0x94, 0x42, 0xe2, 0x9b, + 0x09, 0x93, 0xe5, 0x4c, 0x31, 0x24, 0xbe, 0x71, 0xcd, 0xda, 0xdc, 0x3f, 0xb2, 0x36, 0xff, 0x77, + 0xd6, 0x5e, 0x32, 0xa1, 0x70, 0xc5, 0x84, 0xfb, 0xdf, 0x04, 0x50, 0xbe, 0xb4, 0x0b, 0xf8, 0x10, + 0xdc, 0xe9, 0xb5, 0xb6, 0x3b, 0xcd, 0x2d, 0xb3, 0xdd, 0xdb, 0x36, 0xfb, 0x6f, 0xf4, 0xa6, 0xb9, + 0xd3, 0x79, 0xd9, 0xe9, 0xbe, 0xee, 0x54, 0x33, 0x52, 0xe5, 0xf0, 0x58, 0x59, 0xd8, 0xc1, 0x7b, + 0x98, 0xbc, 0xc7, 0x7f, 0x52, 0xeb, 0x46, 0x73, 0xb7, 0xdb, 0x6f, 0x56, 0x85, 0x44, 0xad, 0x53, + 0x34, 0x26, 0x0c, 0x71, 0xf5, 0x63, 0xb0, 0x7a, 0x83, 0xfa, 0x79, 0xb7, 0xdd, 0x6e, 0xf5, 0xab, + 0x73, 0xd2, 0xf2, 0xe1, 0xb1, 0x52, 0xd6, 0x29, 0x1a, 0x92, 0x20, 0xf0, 0x18, 0xcf, 0x50, 0x81, + 0x78, 0x3d, 0xa3, 0xab, 0x77, 0x7b, 0x9b, 0xaf, 0xaa, 0x8a, 0x54, 0x3d, 0x3c, 0x56, 0x16, 0xa7, + 0xa6, 0xc7, 0x7a, 0xa9, 0xf8, 0xe1, 0xa3, 0x9c, 0xf9, 0xfc, 0x49, 0x16, 0x1a, 0xbb, 0x27, 0x13, + 0x59, 0x38, 0x9d, 0xc8, 0xc2, 0xcf, 0x89, 0x2c, 0x1c, 0x9d, 0xcb, 0x99, 0xd3, 0x73, 0x39, 0xf3, + 0xfd, 0x5c, 0xce, 0xbc, 0x7d, 0xe6, 0x78, 0xcc, 0x1d, 0x0d, 0xd4, 0x21, 0x09, 0xb4, 0x88, 0x51, + 0x0b, 0x3b, 0xc8, 0x27, 0x63, 0xf4, 0x68, 0x8c, 0x70, 0xbc, 0x93, 0x48, 0x73, 0x09, 0x1d, 0xd2, + 0xd1, 0xbe, 0x36, 0xde, 0xd0, 0x86, 0x24, 0x40, 0x2c, 0xf9, 0xd7, 0x92, 0x9f, 0x71, 0x90, 0xe7, + 0xc1, 0xc6, 0xaf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x51, 0x5e, 0xd1, 0x24, 0x3a, 0x05, 0x00, 0x00, +} + +func (m *PartSetHeader) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PartSetHeader) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PartSetHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Hash) > 0 { + i -= len(m.Hash) + copy(dAtA[i:], m.Hash) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Hash))) + i-- + dAtA[i] = 0x12 + } + if m.Total != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Total)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *BlockID) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *BlockID) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *BlockID) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.PartSetHeader.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Hash) > 0 { + i -= len(m.Hash) + copy(dAtA[i:], m.Hash) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Hash))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *Vote) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Vote) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Vote) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ExtensionSignature) > 0 { + i -= len(m.ExtensionSignature) + copy(dAtA[i:], m.ExtensionSignature) + i = encodeVarintTypes(dAtA, i, uint64(len(m.ExtensionSignature))) + i-- + dAtA[i] = 0x52 + } + if len(m.Extension) > 0 { + i -= len(m.Extension) + copy(dAtA[i:], m.Extension) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Extension))) + i-- + dAtA[i] = 0x4a + } + if len(m.Signature) > 0 { + i -= len(m.Signature) + copy(dAtA[i:], m.Signature) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Signature))) + i-- + dAtA[i] = 0x42 + } + if m.ValidatorIndex != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.ValidatorIndex)) + i-- + dAtA[i] = 0x38 + } + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintTypes(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0x32 + } + n2, err2 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.Timestamp, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.Timestamp):]) + if err2 != nil { + return 0, err2 + } + i -= n2 + i = encodeVarintTypes(dAtA, i, uint64(n2)) + i-- + dAtA[i] = 0x2a + { + size, err := m.BlockID.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + if m.Round != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Round)) + i-- + dAtA[i] = 0x18 + } + if m.Height != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x10 + } + if m.Type != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Type)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *Proposal) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Proposal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Proposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Signature) > 0 { + i -= len(m.Signature) + copy(dAtA[i:], m.Signature) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Signature))) + i-- + dAtA[i] = 0x3a + } + n4, err4 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.Timestamp, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.Timestamp):]) + if err4 != nil { + return 0, err4 + } + i -= n4 + i = encodeVarintTypes(dAtA, i, uint64(n4)) + i-- + dAtA[i] = 0x32 + { + size, err := m.BlockID.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + if m.PolRound != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.PolRound)) + i-- + dAtA[i] = 0x20 + } + if m.Round != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Round)) + i-- + dAtA[i] = 0x18 + } + if m.Height != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x10 + } + if m.Type != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Type)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { + offset -= sovTypes(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *PartSetHeader) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Total != 0 { + n += 1 + sovTypes(uint64(m.Total)) + } + l = len(m.Hash) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func (m *BlockID) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Hash) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = m.PartSetHeader.Size() + n += 1 + l + sovTypes(uint64(l)) + return n +} + +func (m *Vote) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Type != 0 { + n += 1 + sovTypes(uint64(m.Type)) + } + if m.Height != 0 { + n += 1 + sovTypes(uint64(m.Height)) + } + if m.Round != 0 { + n += 1 + sovTypes(uint64(m.Round)) + } + l = m.BlockID.Size() + n += 1 + l + sovTypes(uint64(l)) + l = github_com_cosmos_gogoproto_types.SizeOfStdTime(m.Timestamp) + n += 1 + l + sovTypes(uint64(l)) + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if m.ValidatorIndex != 0 { + n += 1 + sovTypes(uint64(m.ValidatorIndex)) + } + l = len(m.Signature) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.Extension) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.ExtensionSignature) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func (m *Proposal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Type != 0 { + n += 1 + sovTypes(uint64(m.Type)) + } + if m.Height != 0 { + n += 1 + sovTypes(uint64(m.Height)) + } + if m.Round != 0 { + n += 1 + sovTypes(uint64(m.Round)) + } + if m.PolRound != 0 { + n += 1 + sovTypes(uint64(m.PolRound)) + } + l = m.BlockID.Size() + n += 1 + l + sovTypes(uint64(l)) + l = github_com_cosmos_gogoproto_types.SizeOfStdTime(m.Timestamp) + n += 1 + l + sovTypes(uint64(l)) + l = len(m.Signature) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func sovTypes(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTypes(x uint64) (n int) { + return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *PartSetHeader) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PartSetHeader: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PartSetHeader: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Total", wireType) + } + m.Total = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Total |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Hash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Hash = append(m.Hash[:0], dAtA[iNdEx:postIndex]...) + if m.Hash == nil { + m.Hash = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *BlockID) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: BlockID: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: BlockID: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Hash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Hash = append(m.Hash[:0], dAtA[iNdEx:postIndex]...) + if m.Hash == nil { + m.Hash = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PartSetHeader", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.PartSetHeader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Vote) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Vote: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Vote: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) + } + m.Type = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Type |= SignedMsgType(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Round", wireType) + } + m.Round = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Round |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockID", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.BlockID.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Timestamp", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_cosmos_gogoproto_types.StdTimeUnmarshal(&m.Timestamp, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddress = append(m.ValidatorAddress[:0], dAtA[iNdEx:postIndex]...) + if m.ValidatorAddress == nil { + m.ValidatorAddress = []byte{} + } + iNdEx = postIndex + case 7: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorIndex", wireType) + } + m.ValidatorIndex = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ValidatorIndex |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signature", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signature = append(m.Signature[:0], dAtA[iNdEx:postIndex]...) + if m.Signature == nil { + m.Signature = []byte{} + } + iNdEx = postIndex + case 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Extension", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Extension = append(m.Extension[:0], dAtA[iNdEx:postIndex]...) + if m.Extension == nil { + m.Extension = []byte{} + } + iNdEx = postIndex + case 10: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ExtensionSignature", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ExtensionSignature = append(m.ExtensionSignature[:0], dAtA[iNdEx:postIndex]...) + if m.ExtensionSignature == nil { + m.ExtensionSignature = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Proposal) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Proposal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Proposal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) + } + m.Type = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Type |= SignedMsgType(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Round", wireType) + } + m.Round = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Round |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PolRound", wireType) + } + m.PolRound = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PolRound |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockID", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.BlockID.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Timestamp", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_cosmos_gogoproto_types.StdTimeUnmarshal(&m.Timestamp, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signature", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signature = append(m.Signature[:0], dAtA[iNdEx:postIndex]...) + if m.Signature == nil { + m.Signature = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTypes(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTypes + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTypes + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTypes + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTypes + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTypes + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTypes + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTypes = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTypes = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTypes = fmt.Errorf("proto: unexpected end of group") +) diff --git a/comet/types/block.go b/comet/types/block.go new file mode 100755 index 00000000..f2fac6eb --- /dev/null +++ b/comet/types/block.go @@ -0,0 +1,70 @@ +package types + +import ( + "crypto/sha256" + "errors" + fmt "fmt" + + "github.com/strangelove-ventures/horcrux/v3/comet/crypto" + tmproto "github.com/strangelove-ventures/horcrux/v3/comet/proto/types" +) + +const tmhashSize = sha256.Size + +// Address is hex bytes. +type Address = crypto.Address + +// BlockID +type BlockID struct { + Hash []byte `json:"hash"` + PartSetHeader PartSetHeader `json:"parts"` +} + +// ValidateBasic performs basic validation. +func (blockID BlockID) ValidateBasic() error { + // Hash can be empty in case of POLBlockID in Proposal. + if err := ValidateHash(blockID.Hash); err != nil { + return fmt.Errorf("wrong Hash") + } + if err := blockID.PartSetHeader.ValidateBasic(); err != nil { + return fmt.Errorf("wrong PartSetHeader: %v", err) + } + return nil +} + +// IsZero returns true if this is the BlockID of a nil block. +func (blockID BlockID) IsZero() bool { + return len(blockID.Hash) == 0 && + blockID.PartSetHeader.IsZero() +} + +// ValidateHash returns an error if the hash is not empty, but its +// size != tmhash.Size. +func ValidateHash(h []byte) error { + if len(h) > 0 && len(h) != tmhashSize { + return fmt.Errorf("expected size to be %d bytes, got %d bytes", + tmhashSize, + len(h), + ) + } + return nil +} + +// FromProto sets a protobuf BlockID to the given pointer. +// It returns an error if the block id is invalid. +func BlockIDFromProto(bID *tmproto.BlockID) (*BlockID, error) { + if bID == nil { + return nil, errors.New("nil BlockID") + } + + blockID := new(BlockID) + ph, err := PartSetHeaderFromProto(&bID.PartSetHeader) + if err != nil { + return nil, err + } + + blockID.PartSetHeader = *ph + blockID.Hash = bID.Hash + + return blockID, blockID.ValidateBasic() +} diff --git a/comet/types/canonical.go b/comet/types/canonical.go new file mode 100755 index 00000000..29807a7b --- /dev/null +++ b/comet/types/canonical.go @@ -0,0 +1,85 @@ +package types + +import ( + "time" + + cmtproto "github.com/strangelove-ventures/horcrux/v3/comet/proto/types" +) + +// Canonical* wraps the structs in types for amino encoding them for use in SignBytes / the Signable interface. + +// TimeFormat is used for generating the sigs +const TimeFormat = time.RFC3339Nano + +//----------------------------------- +// Canonicalize the structs + +func CanonicalizeBlockID(bid cmtproto.BlockID) *cmtproto.CanonicalBlockID { + rbid, err := BlockIDFromProto(&bid) + if err != nil { + panic(err) + } + var cbid *cmtproto.CanonicalBlockID + if rbid == nil || rbid.IsZero() { + cbid = nil + } else { + cbid = &cmtproto.CanonicalBlockID{ + Hash: bid.Hash, + PartSetHeader: CanonicalizePartSetHeader(bid.PartSetHeader), + } + } + + return cbid +} + +// CanonicalizeVote transforms the given PartSetHeader to a CanonicalPartSetHeader. +func CanonicalizePartSetHeader(psh cmtproto.PartSetHeader) cmtproto.CanonicalPartSetHeader { + return cmtproto.CanonicalPartSetHeader(psh) +} + +// CanonicalizeVote transforms the given Proposal to a CanonicalProposal. +func CanonicalizeProposal(chainID string, proposal *cmtproto.Proposal) cmtproto.CanonicalProposal { + return cmtproto.CanonicalProposal{ + Type: cmtproto.ProposalType, + Height: proposal.Height, // encoded as sfixed64 + Round: int64(proposal.Round), // encoded as sfixed64 + POLRound: int64(proposal.PolRound), + BlockID: CanonicalizeBlockID(proposal.BlockID), + Timestamp: proposal.Timestamp, + ChainID: chainID, + } +} + +// CanonicalizeVote transforms the given Vote to a CanonicalVote, which does +// not contain ValidatorIndex and ValidatorAddress fields, or any fields +// relating to vote extensions. +func CanonicalizeVote(chainID string, vote *cmtproto.Vote) cmtproto.CanonicalVote { + return cmtproto.CanonicalVote{ + Type: vote.Type, + Height: vote.Height, // encoded as sfixed64 + Round: int64(vote.Round), // encoded as sfixed64 + BlockID: CanonicalizeBlockID(vote.BlockID), + Timestamp: vote.Timestamp, + ChainID: chainID, + } +} + +// CanonicalizeVoteExtension extracts the vote extension from the given vote +// and constructs a CanonicalizeVoteExtension struct, whose representation in +// bytes is what is signed in order to produce the vote extension's signature. +func CanonicalizeVoteExtension(chainID string, vote *cmtproto.Vote) cmtproto.CanonicalVoteExtension { + return cmtproto.CanonicalVoteExtension{ + Extension: vote.Extension, + Height: vote.Height, + Round: int64(vote.Round), + ChainId: chainID, + } +} + +// CanonicalTime can be used to stringify time in a canonical way. +func CanonicalTime(t time.Time) string { + // Note that sending time over amino resets it to + // local time, we need to force UTC here, so the + // signatures match + return t.Round(0).UTC().Format(TimeFormat) +} diff --git a/comet/types/part_set.go b/comet/types/part_set.go new file mode 100755 index 00000000..fbb50d3d --- /dev/null +++ b/comet/types/part_set.go @@ -0,0 +1,38 @@ +package types + +import ( + "errors" + fmt "fmt" + + cometproto "github.com/strangelove-ventures/horcrux/v3/comet/proto/types" +) + +type PartSetHeader struct { + Total uint32 `json:"total"` + Hash []byte `json:"hash"` +} + +// ValidateBasic performs basic validation. +func (psh PartSetHeader) ValidateBasic() error { + // Hash can be empty in case of POLBlockID.PartSetHeader in Proposal. + if err := ValidateHash(psh.Hash); err != nil { + return fmt.Errorf("wrong Hash: %w", err) + } + return nil +} + +func (psh PartSetHeader) IsZero() bool { + return psh.Total == 0 && len(psh.Hash) == 0 +} + +// FromProto sets a protobuf PartSetHeader to the given pointer +func PartSetHeaderFromProto(ppsh *cometproto.PartSetHeader) (*PartSetHeader, error) { + if ppsh == nil { + return nil, errors.New("nil PartSetHeader") + } + psh := new(PartSetHeader) + psh.Total = ppsh.Total + psh.Hash = ppsh.Hash + + return psh, psh.ValidateBasic() +} diff --git a/comet/types/proposal.go b/comet/types/proposal.go new file mode 100755 index 00000000..23680ede --- /dev/null +++ b/comet/types/proposal.go @@ -0,0 +1,24 @@ +package types + +import ( + "github.com/strangelove-ventures/horcrux/v3/comet/libs/protoio" + cmtproto "github.com/strangelove-ventures/horcrux/v3/comet/proto/types" +) + +// ProposalSignBytes returns the proto-encoding of the canonicalized Proposal, +// for signing. Panics if the marshaling fails. +// +// The encoded Protobuf message is varint length-prefixed (using MarshalDelimited) +// for backwards-compatibility with the Amino encoding, due to e.g. hardware +// devices that rely on this encoding. +// +// See CanonicalizeProposal +func ProposalSignBytes(chainID string, p *cmtproto.Proposal) []byte { + pb := CanonicalizeProposal(chainID, p) + bz, err := protoio.MarshalDelimited(&pb) + if err != nil { + panic(err) + } + + return bz +} diff --git a/comet/types/vote.go b/comet/types/vote.go new file mode 100755 index 00000000..2f7fa8d7 --- /dev/null +++ b/comet/types/vote.go @@ -0,0 +1,24 @@ +package types + +import ( + "github.com/strangelove-ventures/horcrux/v3/comet/libs/protoio" + cmtproto "github.com/strangelove-ventures/horcrux/v3/comet/proto/types" +) + +// VoteSignBytes returns the proto-encoding of the canonicalized Vote, for +// signing. Panics if the marshaling fails. +// +// The encoded Protobuf message is varint length-prefixed (using MarshalDelimited) +// for backwards-compatibility with the Amino encoding, due to e.g. hardware +// devices that rely on this encoding. +// +// See CanonicalizeVote +func VoteSignBytes(chainID string, vote *cmtproto.Vote) []byte { + pb := CanonicalizeVote(chainID, vote) + bz, err := protoio.MarshalDelimited(&pb) + if err != nil { + panic(err) + } + + return bz +} diff --git a/go.mod b/go.mod index 4f2368ab..b98f2c5a 100644 --- a/go.mod +++ b/go.mod @@ -7,18 +7,19 @@ require ( github.com/Jille/raft-grpc-transport v1.4.0 github.com/Jille/raftadmin v1.2.1 github.com/armon/go-metrics v0.4.1 - github.com/cometbft/cometbft v0.38.0 github.com/consensys/gnark-crypto v0.12.1 github.com/cosmos/cosmos-sdk v0.50.1 github.com/cosmos/gogoproto v1.4.11 github.com/ethereum/go-ethereum v1.13.5 - github.com/gogo/protobuf v1.3.2 github.com/google/uuid v1.3.1 github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 github.com/hashicorp/raft v1.6.0 github.com/hashicorp/raft-boltdb/v2 v2.2.2 + github.com/holiman/uint256 v1.2.3 github.com/kraken-hpc/go-fork v0.1.1 + github.com/libp2p/go-buffer-pool v0.1.0 github.com/mitchellh/go-homedir v1.1.0 + github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a github.com/prometheus/client_golang v1.17.0 github.com/spf13/cobra v1.7.0 github.com/spf13/viper v1.16.0 @@ -26,9 +27,10 @@ require ( github.com/tendermint/go-amino v0.16.0 gitlab.com/unit410/edwards25519 v0.0.0-20220725154547-61980033348e gitlab.com/unit410/threshold-ed25519 v0.0.0-20220812172601-56783212c4cc - go.dedis.ch/kyber/v3 v3.1.0 + golang.org/x/crypto v0.14.0 golang.org/x/sync v0.3.0 google.golang.org/grpc v1.59.0 + google.golang.org/protobuf v1.31.0 gopkg.in/yaml.v2 v2.4.0 ) @@ -44,8 +46,6 @@ require ( github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect github.com/fatih/color v1.15.0 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect - github.com/go-kit/log v0.2.1 // indirect - github.com/go-logfmt/logfmt v0.6.0 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect @@ -57,38 +57,30 @@ require ( github.com/hashicorp/go-uuid v1.0.1 // indirect github.com/hashicorp/golang-lru v1.0.2 // indirect github.com/hashicorp/hcl v1.0.0 // indirect - github.com/holiman/uint256 v1.2.3 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mmcloughlin/addchain v0.4.0 // indirect - github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect github.com/pelletier/go-toml/v2 v2.0.9 // indirect - github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_model v0.5.0 // indirect github.com/prometheus/common v0.45.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect - github.com/sasha-s/go-deadlock v0.3.1 // indirect github.com/spf13/afero v1.9.5 // indirect github.com/spf13/cast v1.5.1 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.4.2 // indirect - go.dedis.ch/fixbuf v1.0.3 // indirect go.etcd.io/bbolt v1.3.8 // indirect - golang.org/x/crypto v0.14.0 // indirect golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect golang.org/x/net v0.17.0 // indirect golang.org/x/sys v0.14.0 // indirect golang.org/x/text v0.13.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect - google.golang.org/protobuf v1.31.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect rsc.io/tmplfunc v0.0.3 // indirect diff --git a/go.sum b/go.sum index a5a4c27a..33b1da98 100644 --- a/go.sum +++ b/go.sum @@ -67,8 +67,6 @@ github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4= github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U= github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= -github.com/btcsuite/btcd/btcutil v1.1.3 h1:xfbtw8lwpp0G6NwSHb+UE67ryTFHJAiNuipusjXSohQ= -github.com/btcsuite/btcd/btcutil v1.1.3/go.mod h1:UR7dsSJzJUfMmFiiLlIrMq1lS9jh9EdCV7FStZSnpi0= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= @@ -86,8 +84,6 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= -github.com/cometbft/cometbft v0.38.0 h1:ogKnpiPX7gxCvqTEF4ly25/wAxUqf181t30P3vqdpdc= -github.com/cometbft/cometbft v0.38.0/go.mod h1:5Jz0Z8YsHSf0ZaAqGvi/ifioSdVFPtEGrm8Y9T/993k= github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ= github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI= github.com/consensys/gnark-crypto v0.12.1 h1:lHH39WuuFgVHONRl3J0LRBtuYdQTumFSDtJF7HpyG8M= @@ -120,8 +116,6 @@ github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGE github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= -github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= -github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= @@ -133,16 +127,11 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2 github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= -github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU= -github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= -github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4= -github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= -github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -321,9 +310,6 @@ github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0Mw github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pelletier/go-toml/v2 v2.0.9 h1:uH2qQXheeefCCkuBBSLi7jCiSmj3VRh2+Goq2N7Xxu0= github.com/pelletier/go-toml/v2 v2.0.9/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= -github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o= -github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc h1:8bQZVK1X6BJR/6nYUPxQEP+ReTsceJTKizeuwjWOPUA= -github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -359,8 +345,6 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/sasha-s/go-deadlock v0.3.1 h1:sqv7fDNShgjcaxkO0JNcOAlr8B9+cV5Ey/OB71efZx0= -github.com/sasha-s/go-deadlock v0.3.1/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZjwesgfQ1/iLM= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= @@ -404,16 +388,6 @@ gitlab.com/unit410/edwards25519 v0.0.0-20220725154547-61980033348e h1:/QfokHt2yG gitlab.com/unit410/edwards25519 v0.0.0-20220725154547-61980033348e/go.mod h1:lTSPILLBMt6qQOJgsiarbW85JhpkhoOfW2EBkxkcuSI= gitlab.com/unit410/threshold-ed25519 v0.0.0-20220812172601-56783212c4cc h1:ESmaQH1+uOLW0wOIPT4EVLh+gwKdmKovr+eZg4jWUNs= gitlab.com/unit410/threshold-ed25519 v0.0.0-20220812172601-56783212c4cc/go.mod h1:1CIpwbV+rSyzoBVr6Ok9vvEP7UHrW/d0zEB+jU6+E3o= -go.dedis.ch/fixbuf v1.0.3 h1:hGcV9Cd/znUxlusJ64eAlExS+5cJDIyTyEG+otu5wQs= -go.dedis.ch/fixbuf v1.0.3/go.mod h1:yzJMt34Wa5xD37V5RTdmp38cz3QhMagdGoem9anUalw= -go.dedis.ch/kyber/v3 v3.0.4/go.mod h1:OzvaEnPvKlyrWyp3kGXlFdp7ap1VC6RkZDTaPikqhsQ= -go.dedis.ch/kyber/v3 v3.0.9/go.mod h1:rhNjUUg6ahf8HEg5HUvVBYoWY4boAafX8tYxX+PS+qg= -go.dedis.ch/kyber/v3 v3.1.0 h1:ghu+kiRgM5JyD9TJ0hTIxTLQlJBR/ehjWvWwYW3XsC0= -go.dedis.ch/kyber/v3 v3.1.0/go.mod h1:kXy7p3STAurkADD+/aZcsznZGKVHEqbtmdIzvPfrs1U= -go.dedis.ch/protobuf v1.0.5/go.mod h1:eIV4wicvi6JK0q/QnfIEGeSFNG0ZeB24kzut5+HaRLo= -go.dedis.ch/protobuf v1.0.7/go.mod h1:pv5ysfkDX/EawiPqcW3ikOxsL5t+BqnV6xHSmE79KI4= -go.dedis.ch/protobuf v1.0.11 h1:FTYVIEzY/bfl37lu3pR4lIj+F9Vp1jE8oh91VmxKgLo= -go.dedis.ch/protobuf v1.0.11/go.mod h1:97QR256dnkimeNdfmURz0wAMNVbd1VmLXhG1CrTYrJ4= go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= go.etcd.io/bbolt v1.3.8 h1:xs88BrvEv273UsB79e0hcVrlUWmS0a8upikMFhSyAtA= go.etcd.io/bbolt v1.3.8/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw= @@ -431,7 +405,6 @@ go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -543,7 +516,6 @@ golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190124100055-b90733256f2e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/signer/proto/cosigner.pb.go b/grpc/cosigner/cosigner.pb.go similarity index 95% rename from signer/proto/cosigner.pb.go rename to grpc/cosigner/cosigner.pb.go index 1195a78f..6a8045b1 100644 --- a/signer/proto/cosigner.pb.go +++ b/grpc/cosigner/cosigner.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: strangelove/horcrux/cosigner.proto -package proto +package cosigner import ( context "context" @@ -900,53 +900,53 @@ func init() { var fileDescriptor_b7a1f695b94b848a = []byte{ // 748 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x56, 0xcd, 0x4e, 0xdb, 0x4c, - 0x14, 0x8d, 0x13, 0x3b, 0x1f, 0xb9, 0x81, 0x4f, 0x30, 0x45, 0xd4, 0x58, 0x55, 0x94, 0x8e, 0xda, - 0x2a, 0x52, 0x4b, 0x52, 0x05, 0xa9, 0xac, 0xa1, 0x48, 0x2d, 0xa2, 0x3f, 0xd4, 0x81, 0x4d, 0x85, - 0x90, 0x1c, 0x67, 0x88, 0xad, 0x06, 0x3b, 0xcc, 0x8c, 0x29, 0x3c, 0x40, 0xf7, 0xdd, 0xf4, 0x9d, - 0x58, 0xb2, 0xec, 0xae, 0x15, 0xbc, 0x48, 0x35, 0xe3, 0xb1, 0x89, 0x8d, 0x03, 0x2c, 0x58, 0xc5, - 0xf7, 0xfa, 0xfe, 0x9c, 0x73, 0x72, 0x66, 0x64, 0xc0, 0x8c, 0x53, 0x27, 0x18, 0x92, 0x51, 0x78, - 0x42, 0x3a, 0x5e, 0x48, 0x5d, 0x1a, 0x9d, 0x76, 0xdc, 0x90, 0xf9, 0xc3, 0x80, 0xd0, 0xf6, 0x98, - 0x86, 0x3c, 0x44, 0x8f, 0x26, 0x6a, 0xda, 0xaa, 0x06, 0xff, 0xd0, 0xc0, 0xd8, 0x18, 0x85, 0xee, - 0x37, 0xb4, 0x04, 0x55, 0x8f, 0xf8, 0x43, 0x8f, 0x9b, 0x5a, 0x53, 0x6b, 0x55, 0x6c, 0x15, 0xa1, - 0x45, 0x30, 0x68, 0x18, 0x05, 0x03, 0xb3, 0x2c, 0xd3, 0x71, 0x80, 0x10, 0xe8, 0x8c, 0x93, 0xb1, - 0x59, 0x69, 0x6a, 0x2d, 0xc3, 0x96, 0xcf, 0xe8, 0x09, 0xd4, 0xc4, 0xc2, 0x8d, 0x33, 0x4e, 0x98, - 0xa9, 0x37, 0xb5, 0xd6, 0xac, 0x7d, 0x9d, 0x10, 0x6f, 0xb9, 0x7f, 0x44, 0x18, 0x77, 0x8e, 0xc6, - 0xa6, 0x21, 0x67, 0x5d, 0x27, 0xf0, 0x01, 0xcc, 0xf7, 0x44, 0xa9, 0x80, 0x62, 0x93, 0xe3, 0x88, - 0x30, 0x8e, 0x4c, 0xf8, 0xcf, 0xf5, 0x1c, 0x3f, 0xd8, 0xda, 0x94, 0x90, 0x6a, 0x76, 0x12, 0xa2, - 0xd7, 0x60, 0xf4, 0x45, 0xa5, 0xc4, 0x54, 0xef, 0x5a, 0xed, 0x02, 0x6a, 0xed, 0x78, 0x56, 0x5c, - 0x88, 0x3f, 0xc3, 0xc2, 0xc4, 0x7c, 0x36, 0x0e, 0x03, 0x46, 0x12, 0xc0, 0x0e, 0x8f, 0x28, 0x91, - 0x2b, 0x14, 0x60, 0x99, 0xc8, 0x02, 0x2e, 0xe7, 0x01, 0xff, 0xd2, 0xc0, 0xf8, 0x14, 0x06, 0x2e, - 0x41, 0x16, 0xcc, 0xb0, 0x30, 0xa2, 0x2e, 0x51, 0x38, 0x0d, 0x3b, 0x8d, 0xd1, 0x33, 0x98, 0x1b, - 0x10, 0xc6, 0xfd, 0xc0, 0xe1, 0x7e, 0x28, 0x88, 0x94, 0x65, 0x41, 0x36, 0x29, 0xa4, 0x1f, 0x47, - 0xfd, 0x6d, 0x72, 0x26, 0xe5, 0x9c, 0xb5, 0x55, 0x24, 0xa4, 0x67, 0x9e, 0x43, 0x89, 0x12, 0x33, - 0x0e, 0xb2, 0xa8, 0x8d, 0x1c, 0x6a, 0xdc, 0x83, 0xda, 0xde, 0xde, 0xd6, 0x66, 0x0c, 0x0d, 0x81, - 0x1e, 0x45, 0xfe, 0x40, 0x71, 0x93, 0xcf, 0xa8, 0x0b, 0xd5, 0x40, 0xbc, 0x64, 0x66, 0xb9, 0x59, - 0x99, 0x2a, 0x9e, 0xec, 0xb7, 0x55, 0x25, 0x3e, 0x04, 0xfd, 0xbd, 0xdd, 0xdb, 0x7d, 0x18, 0x8f, - 0x5c, 0x8b, 0xaa, 0xe7, 0x45, 0x3d, 0xd7, 0xe0, 0x71, 0x8f, 0x70, 0xb9, 0x9c, 0xad, 0x07, 0x03, - 0xf1, 0x97, 0x25, 0x6e, 0x78, 0x20, 0x2e, 0x68, 0x05, 0x74, 0x8f, 0x32, 0x2e, 0x51, 0xd5, 0xbb, - 0xcb, 0x85, 0x1d, 0x82, 0xac, 0x2d, 0xcb, 0xee, 0x30, 0xf5, 0x84, 0x45, 0x8d, 0x8c, 0x45, 0xf1, - 0x29, 0x98, 0x37, 0x99, 0x28, 0xdf, 0x35, 0xa1, 0x2e, 0xc1, 0xec, 0x44, 0xfd, 0x91, 0xef, 0x2a, - 0x46, 0x93, 0xa9, 0xdb, 0xbd, 0x97, 0x75, 0x40, 0x25, 0xef, 0x80, 0x16, 0xcc, 0xbf, 0x4b, 0x36, - 0x27, 0xe2, 0x2d, 0x82, 0x21, 0x04, 0x63, 0xa6, 0xd6, 0xac, 0x08, 0x27, 0xc9, 0x00, 0x6f, 0xc3, - 0xc2, 0x44, 0xa5, 0x02, 0xf7, 0x26, 0xd5, 0x54, 0x93, 0x9a, 0x36, 0x0a, 0x15, 0x4a, 0x3d, 0x96, - 0x7a, 0x64, 0x0d, 0x96, 0x77, 0xa9, 0x13, 0xb0, 0x43, 0x42, 0x3f, 0x10, 0x67, 0x40, 0x28, 0xf3, - 0xfc, 0x71, 0xb2, 0xdf, 0x82, 0x99, 0x91, 0x4c, 0xa6, 0x67, 0x39, 0x8d, 0xf1, 0x01, 0x58, 0x45, - 0x8d, 0x0a, 0xce, 0x2d, 0x9d, 0xe2, 0x74, 0xc5, 0xcf, 0xeb, 0x83, 0x01, 0x25, 0x8c, 0x49, 0xa5, - 0x6a, 0x76, 0x36, 0x89, 0x91, 0xd4, 0x23, 0x1e, 0xad, 0xf0, 0xe0, 0x97, 0x92, 0x79, 0x92, 0x53, - 0xab, 0x96, 0xa0, 0x1a, 0x77, 0xaa, 0x63, 0xac, 0x22, 0x3c, 0x07, 0xf5, 0x1d, 0x3f, 0x18, 0x26, - 0xbd, 0xff, 0xc3, 0x6c, 0x1c, 0xc6, 0x6d, 0xdd, 0x3f, 0x3a, 0xcc, 0xbc, 0x55, 0x57, 0x2d, 0xda, - 0x87, 0x5a, 0x7a, 0xcf, 0xa0, 0xe7, 0x85, 0xd2, 0xe5, 0xef, 0x39, 0xeb, 0xc5, 0x5d, 0x65, 0xf1, - 0x22, 0x5c, 0x42, 0xc7, 0x30, 0x9f, 0x37, 0x15, 0x7a, 0x55, 0xdc, 0x5d, 0x7c, 0x8a, 0xac, 0x95, - 0x7b, 0x56, 0xa7, 0x2b, 0xf7, 0xa1, 0x96, 0x7a, 0x64, 0x0a, 0xa1, 0xbc, 0xdb, 0xa6, 0x10, 0xba, - 0x61, 0x35, 0x5c, 0x42, 0xdf, 0x01, 0xdd, 0xfc, 0xef, 0x51, 0xbb, 0xb0, 0x7f, 0xaa, 0xbb, 0xac, - 0xce, 0xbd, 0xeb, 0x73, 0xb4, 0xe2, 0x57, 0xd3, 0x69, 0x65, 0x4c, 0x33, 0x9d, 0x56, 0xd6, 0x47, - 0xb8, 0x84, 0x3e, 0x82, 0x2e, 0x2c, 0x82, 0x9a, 0x85, 0x1d, 0x13, 0x66, 0xb2, 0x9e, 0xde, 0x52, - 0x91, 0x8c, 0xdb, 0xf8, 0x72, 0x7e, 0xd9, 0xd0, 0x2e, 0x2e, 0x1b, 0xda, 0xdf, 0xcb, 0x86, 0xf6, - 0xf3, 0xaa, 0x51, 0xba, 0xb8, 0x6a, 0x94, 0x7e, 0x5f, 0x35, 0x4a, 0x5f, 0xd7, 0x86, 0x3e, 0xf7, - 0xa2, 0x7e, 0xdb, 0x0d, 0x8f, 0x3a, 0x13, 0x83, 0x56, 0x4e, 0x48, 0x20, 0xee, 0x02, 0x96, 0x7e, - 0x0b, 0x9c, 0xac, 0x76, 0x62, 0x87, 0x76, 0xe4, 0xc7, 0x40, 0xbf, 0x2a, 0x7f, 0x56, 0xff, 0x05, - 0x00, 0x00, 0xff, 0xff, 0x44, 0xff, 0xfe, 0xd7, 0x39, 0x08, 0x00, 0x00, + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x56, 0xcb, 0x4e, 0xdb, 0x40, + 0x14, 0x8d, 0x13, 0x3b, 0x25, 0x37, 0x50, 0xc1, 0x14, 0x51, 0x63, 0x55, 0x51, 0x3a, 0x6a, 0xab, + 0x48, 0x2d, 0x49, 0x15, 0xa4, 0xb6, 0x5b, 0x28, 0x52, 0x8b, 0xe8, 0x03, 0x39, 0xb0, 0xa9, 0x10, + 0x92, 0xe3, 0x0c, 0xb1, 0xd5, 0x60, 0x87, 0x99, 0x31, 0x85, 0x0f, 0xe8, 0xbe, 0x9b, 0xfe, 0x13, + 0x4b, 0x96, 0xdd, 0xb5, 0x82, 0x1f, 0xa9, 0x66, 0x3c, 0x36, 0xb1, 0x71, 0x80, 0x05, 0x3b, 0xdf, + 0xeb, 0xfb, 0x38, 0xe7, 0xf8, 0xcc, 0xc8, 0x80, 0x19, 0xa7, 0x4e, 0x30, 0x24, 0xa3, 0xf0, 0x98, + 0x74, 0xbc, 0x90, 0xba, 0x34, 0x3a, 0xe9, 0xb8, 0x21, 0xf3, 0x87, 0x01, 0xa1, 0xed, 0x31, 0x0d, + 0x79, 0x88, 0x1e, 0x4d, 0xd4, 0xb4, 0x55, 0x0d, 0xfe, 0xa9, 0x81, 0xb1, 0x3e, 0x0a, 0xdd, 0xef, + 0x68, 0x09, 0xaa, 0x1e, 0xf1, 0x87, 0x1e, 0x37, 0xb5, 0xa6, 0xd6, 0xaa, 0xd8, 0x2a, 0x42, 0x8b, + 0x60, 0xd0, 0x30, 0x0a, 0x06, 0x66, 0x59, 0xa6, 0xe3, 0x00, 0x21, 0xd0, 0x19, 0x27, 0x63, 0xb3, + 0xd2, 0xd4, 0x5a, 0x86, 0x2d, 0x9f, 0xd1, 0x13, 0xa8, 0x89, 0x85, 0xeb, 0xa7, 0x9c, 0x30, 0x53, + 0x6f, 0x6a, 0xad, 0x59, 0xfb, 0x2a, 0x21, 0xde, 0x72, 0xff, 0x90, 0x30, 0xee, 0x1c, 0x8e, 0x4d, + 0x43, 0xce, 0xba, 0x4a, 0xe0, 0x7d, 0x98, 0xef, 0x89, 0x52, 0x01, 0xc5, 0x26, 0x47, 0x11, 0x61, + 0x1c, 0x99, 0xf0, 0xc0, 0xf5, 0x1c, 0x3f, 0xd8, 0xdc, 0x90, 0x90, 0x6a, 0x76, 0x12, 0xa2, 0xd7, + 0x60, 0xf4, 0x45, 0xa5, 0xc4, 0x54, 0xef, 0x5a, 0xed, 0x02, 0x6a, 0xed, 0x78, 0x56, 0x5c, 0x88, + 0xbf, 0xc2, 0xc2, 0xc4, 0x7c, 0x36, 0x0e, 0x03, 0x46, 0x12, 0xc0, 0x0e, 0x8f, 0x28, 0x91, 0x2b, + 0x14, 0x60, 0x99, 0xc8, 0x02, 0x2e, 0xe7, 0x01, 0xff, 0xd6, 0xc0, 0xf8, 0x12, 0x06, 0x2e, 0x41, + 0x16, 0xcc, 0xb0, 0x30, 0xa2, 0x2e, 0x51, 0x38, 0x0d, 0x3b, 0x8d, 0xd1, 0x33, 0x98, 0x1b, 0x10, + 0xc6, 0xfd, 0xc0, 0xe1, 0x7e, 0x28, 0x88, 0x94, 0x65, 0x41, 0x36, 0x29, 0xa4, 0x1f, 0x47, 0xfd, + 0x2d, 0x72, 0x2a, 0xe5, 0x9c, 0xb5, 0x55, 0x24, 0xa4, 0x67, 0x9e, 0x43, 0x89, 0x12, 0x33, 0x0e, + 0xb2, 0xa8, 0x8d, 0x1c, 0x6a, 0xdc, 0x83, 0xda, 0xee, 0xee, 0xe6, 0x46, 0x0c, 0x0d, 0x81, 0x1e, + 0x45, 0xfe, 0x40, 0x71, 0x93, 0xcf, 0xa8, 0x0b, 0xd5, 0x40, 0xbc, 0x64, 0x66, 0xb9, 0x59, 0x99, + 0x2a, 0x9e, 0xec, 0xb7, 0x55, 0x25, 0x3e, 0x00, 0xfd, 0xa3, 0xdd, 0xdb, 0xb9, 0x1f, 0x8f, 0x5c, + 0x89, 0xaa, 0xe7, 0x45, 0x3d, 0xd3, 0xe0, 0x71, 0x8f, 0x70, 0xb9, 0x9c, 0xad, 0x05, 0x03, 0xf1, + 0xc9, 0x12, 0x37, 0xdc, 0x13, 0x17, 0xb4, 0x02, 0xba, 0x47, 0x19, 0x97, 0xa8, 0xea, 0xdd, 0xe5, + 0xc2, 0x0e, 0x41, 0xd6, 0x96, 0x65, 0xb7, 0x98, 0x7a, 0xc2, 0xa2, 0x46, 0xc6, 0xa2, 0xf8, 0x04, + 0xcc, 0xeb, 0x4c, 0x94, 0xef, 0x9a, 0x50, 0x97, 0x60, 0xb6, 0xa3, 0xfe, 0xc8, 0x77, 0x15, 0xa3, + 0xc9, 0xd4, 0xcd, 0xde, 0xcb, 0x3a, 0xa0, 0x92, 0x77, 0x40, 0x0b, 0xe6, 0x3f, 0x24, 0x9b, 0x13, + 0xf1, 0x16, 0xc1, 0x10, 0x82, 0x31, 0x53, 0x6b, 0x56, 0x84, 0x93, 0x64, 0x80, 0xb7, 0x60, 0x61, + 0xa2, 0x52, 0x81, 0x7b, 0x93, 0x6a, 0xaa, 0x49, 0x4d, 0x1b, 0x85, 0x0a, 0xa5, 0x1e, 0x4b, 0x3d, + 0xf2, 0x16, 0x96, 0x77, 0xa8, 0x13, 0xb0, 0x03, 0x42, 0x3f, 0x11, 0x67, 0x40, 0x28, 0xf3, 0xfc, + 0x71, 0xb2, 0xdf, 0x82, 0x99, 0x91, 0x4c, 0xa6, 0x67, 0x39, 0x8d, 0xf1, 0x3e, 0x58, 0x45, 0x8d, + 0x0a, 0xce, 0x0d, 0x9d, 0xe2, 0x74, 0xc5, 0xcf, 0x6b, 0x83, 0x01, 0x25, 0x8c, 0x49, 0xa5, 0x6a, + 0x76, 0x36, 0x89, 0x91, 0xd4, 0x23, 0x1e, 0xad, 0xf0, 0xe0, 0x97, 0x92, 0x79, 0x92, 0x53, 0xab, + 0x96, 0xa0, 0x1a, 0x77, 0xaa, 0x63, 0xac, 0x22, 0x3c, 0x07, 0xf5, 0x6d, 0x3f, 0x18, 0x26, 0xbd, + 0x0f, 0x61, 0x36, 0x0e, 0xe3, 0xb6, 0xee, 0x5f, 0x1d, 0x66, 0xde, 0xab, 0xab, 0x16, 0xed, 0x41, + 0x2d, 0xbd, 0x67, 0xd0, 0xf3, 0x42, 0xe9, 0xf2, 0xf7, 0x9c, 0xf5, 0xe2, 0xb6, 0xb2, 0x78, 0x11, + 0x2e, 0xa1, 0x23, 0x98, 0xcf, 0x9b, 0x0a, 0xbd, 0x2a, 0xee, 0x2e, 0x3e, 0x45, 0xd6, 0xca, 0x1d, + 0xab, 0xd3, 0x95, 0x7b, 0x50, 0x4b, 0x3d, 0x32, 0x85, 0x50, 0xde, 0x6d, 0x53, 0x08, 0x5d, 0xb3, + 0x1a, 0x2e, 0xa1, 0x1f, 0x80, 0xae, 0x7f, 0x7b, 0xd4, 0x2e, 0xec, 0x9f, 0xea, 0x2e, 0xab, 0x73, + 0xe7, 0xfa, 0x1c, 0xad, 0xf8, 0xd5, 0x74, 0x5a, 0x19, 0xd3, 0x4c, 0xa7, 0x95, 0xf5, 0x11, 0x2e, + 0xa1, 0xcf, 0xa0, 0x0b, 0x8b, 0xa0, 0x66, 0x61, 0xc7, 0x84, 0x99, 0xac, 0xa7, 0x37, 0x54, 0x24, + 0xe3, 0xd6, 0xed, 0xb3, 0x8b, 0x86, 0x76, 0x7e, 0xd1, 0xd0, 0xfe, 0x5d, 0x34, 0xb4, 0x5f, 0x97, + 0x8d, 0xd2, 0xf9, 0x65, 0xa3, 0xf4, 0xe7, 0xb2, 0x51, 0xfa, 0xf6, 0x6e, 0xe8, 0x73, 0x2f, 0xea, + 0xb7, 0xdd, 0xf0, 0xb0, 0x33, 0x31, 0x68, 0xe5, 0x98, 0x04, 0xe2, 0x2e, 0x60, 0xe9, 0xbf, 0xc0, + 0xf1, 0x6a, 0x67, 0x48, 0xc7, 0x6e, 0xfa, 0x4f, 0xd0, 0xaf, 0xca, 0x9f, 0x82, 0xd5, 0xff, 0x01, + 0x00, 0x00, 0xff, 0xff, 0x6f, 0x79, 0x53, 0xf2, 0x3a, 0x08, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/signer/proto/remote_signer.pb.go b/grpc/horcrux/remote_signer.pb.go similarity index 94% rename from signer/proto/remote_signer.pb.go rename to grpc/horcrux/remote_signer.pb.go index 325f3619..554745a4 100644 --- a/signer/proto/remote_signer.pb.go +++ b/grpc/horcrux/remote_signer.pb.go @@ -1,13 +1,14 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: strangelove/horcrux/remote_signer.proto -package proto +package horcrux import ( context "context" fmt "fmt" grpc1 "github.com/cosmos/gogoproto/grpc" proto "github.com/cosmos/gogoproto/proto" + cosigner "github.com/strangelove-ventures/horcrux/v3/grpc/cosigner" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" @@ -125,7 +126,7 @@ func init() { } var fileDescriptor_afd7664cd19b584a = []byte{ - // 279 bytes of a gzipped FileDescriptorProto + // 280 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x2f, 0x2e, 0x29, 0x4a, 0xcc, 0x4b, 0x4f, 0xcd, 0xc9, 0x2f, 0x4b, 0xd5, 0xcf, 0xc8, 0x2f, 0x4a, 0x2e, 0x2a, 0xad, 0xd0, 0x2f, 0x4a, 0xcd, 0xcd, 0x2f, 0x49, 0x8d, 0x2f, 0xce, 0x4c, 0xcf, 0x4b, 0x2d, 0xd2, 0x2b, 0x28, @@ -141,9 +142,9 @@ var fileDescriptor_afd7664cd19b584a = []byte{ 0xaa, 0x1a, 0x21, 0x65, 0x30, 0x83, 0x9d, 0x02, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0xca, 0x3c, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x1f, 0xc9, - 0x34, 0xdd, 0xb2, 0xd4, 0xbc, 0x92, 0xd2, 0xa2, 0xd4, 0x62, 0x78, 0x38, 0x97, 0x19, 0xeb, 0x43, - 0x02, 0x5a, 0x1f, 0x1c, 0xd0, 0x49, 0x6c, 0x60, 0xca, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x1e, - 0xa5, 0x90, 0x75, 0xd3, 0x01, 0x00, 0x00, + 0x34, 0xdd, 0xb2, 0xd4, 0xbc, 0x92, 0xd2, 0xa2, 0xd4, 0x62, 0x78, 0x38, 0x97, 0x19, 0xeb, 0xa7, + 0x17, 0x15, 0x24, 0xc3, 0xf8, 0x49, 0x6c, 0xe0, 0xf0, 0x36, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, + 0xc6, 0x30, 0xc4, 0xb2, 0xd3, 0x01, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -159,7 +160,7 @@ const _ = grpc.SupportPackageIsVersion4 // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type RemoteSignerClient interface { PubKey(ctx context.Context, in *PubKeyRequest, opts ...grpc.CallOption) (*PubKeyResponse, error) - Sign(ctx context.Context, in *SignBlockRequest, opts ...grpc.CallOption) (*SignBlockResponse, error) + Sign(ctx context.Context, in *cosigner.SignBlockRequest, opts ...grpc.CallOption) (*cosigner.SignBlockResponse, error) } type remoteSignerClient struct { @@ -179,8 +180,8 @@ func (c *remoteSignerClient) PubKey(ctx context.Context, in *PubKeyRequest, opts return out, nil } -func (c *remoteSignerClient) Sign(ctx context.Context, in *SignBlockRequest, opts ...grpc.CallOption) (*SignBlockResponse, error) { - out := new(SignBlockResponse) +func (c *remoteSignerClient) Sign(ctx context.Context, in *cosigner.SignBlockRequest, opts ...grpc.CallOption) (*cosigner.SignBlockResponse, error) { + out := new(cosigner.SignBlockResponse) err := c.cc.Invoke(ctx, "/strangelove.horcrux.RemoteSigner/Sign", in, out, opts...) if err != nil { return nil, err @@ -191,7 +192,7 @@ func (c *remoteSignerClient) Sign(ctx context.Context, in *SignBlockRequest, opt // RemoteSignerServer is the server API for RemoteSigner service. type RemoteSignerServer interface { PubKey(context.Context, *PubKeyRequest) (*PubKeyResponse, error) - Sign(context.Context, *SignBlockRequest) (*SignBlockResponse, error) + Sign(context.Context, *cosigner.SignBlockRequest) (*cosigner.SignBlockResponse, error) } // UnimplementedRemoteSignerServer can be embedded to have forward compatible implementations. @@ -201,7 +202,7 @@ type UnimplementedRemoteSignerServer struct { func (*UnimplementedRemoteSignerServer) PubKey(ctx context.Context, req *PubKeyRequest) (*PubKeyResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method PubKey not implemented") } -func (*UnimplementedRemoteSignerServer) Sign(ctx context.Context, req *SignBlockRequest) (*SignBlockResponse, error) { +func (*UnimplementedRemoteSignerServer) Sign(ctx context.Context, req *cosigner.SignBlockRequest) (*cosigner.SignBlockResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Sign not implemented") } @@ -228,7 +229,7 @@ func _RemoteSigner_PubKey_Handler(srv interface{}, ctx context.Context, dec func } func _RemoteSigner_Sign_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(SignBlockRequest) + in := new(cosigner.SignBlockRequest) if err := dec(in); err != nil { return nil, err } @@ -240,7 +241,7 @@ func _RemoteSigner_Sign_Handler(srv interface{}, ctx context.Context, dec func(i FullMethod: "/strangelove.horcrux.RemoteSigner/Sign", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(RemoteSignerServer).Sign(ctx, req.(*SignBlockRequest)) + return srv.(RemoteSignerServer).Sign(ctx, req.(*cosigner.SignBlockRequest)) } return interceptor(ctx, in, info, handler) } diff --git a/proto/strangelove/horcrux/cosigner.proto b/proto/strangelove/horcrux/cosigner.proto index 42d886ef..37cc4189 100644 --- a/proto/strangelove/horcrux/cosigner.proto +++ b/proto/strangelove/horcrux/cosigner.proto @@ -1,7 +1,7 @@ syntax = "proto3"; package strangelove.horcrux; -option go_package = "github.com/strangelove-ventures/horcrux/v3/signer/proto"; +option go_package = "github.com/strangelove-ventures/horcrux/v3/grpc/cosigner"; service Cosigner { rpc SignBlock (SignBlockRequest) returns (SignBlockResponse) {} diff --git a/proto/strangelove/horcrux/remote_signer.proto b/proto/strangelove/horcrux/remote_signer.proto index 2e1a6c2d..bd0d21b1 100644 --- a/proto/strangelove/horcrux/remote_signer.proto +++ b/proto/strangelove/horcrux/remote_signer.proto @@ -3,7 +3,7 @@ package strangelove.horcrux; import "strangelove/horcrux/cosigner.proto"; -option go_package = "github.com/strangelove-ventures/horcrux/v3/signer/proto"; +option go_package = "github.com/strangelove-ventures/horcrux/v3/grpc/horcrux"; service RemoteSigner { rpc PubKey (PubKeyRequest) returns (PubKeyResponse) {} diff --git a/proto/tendermint/crypto/keys.proto b/proto/tendermint/crypto/keys.proto index e5959ee4..90f9e0f9 100644 --- a/proto/tendermint/crypto/keys.proto +++ b/proto/tendermint/crypto/keys.proto @@ -1,7 +1,7 @@ syntax = "proto3"; package tendermint.crypto; -option go_package = "github.com/strangelove-ventures/horcrux/v3/signer/proto"; +option go_package = "github.com/strangelove-ventures/horcrux/v3/comet/proto/crypto"; import "gogoproto/gogo.proto"; diff --git a/proto/tendermint/p2p/conn.proto b/proto/tendermint/p2p/conn.proto new file mode 100644 index 00000000..c9ee167a --- /dev/null +++ b/proto/tendermint/p2p/conn.proto @@ -0,0 +1,30 @@ +syntax = "proto3"; +package tendermint.p2p; + +option go_package = "github.com/strangelove-ventures/horcrux/v3/comet/proto/p2p"; + +import "gogoproto/gogo.proto"; +import "tendermint/crypto/keys.proto"; + +message PacketPing {} + +message PacketPong {} + +message PacketMsg { + int32 channel_id = 1 [(gogoproto.customname) = "ChannelID"]; + bool eof = 2 [(gogoproto.customname) = "EOF"]; + bytes data = 3; +} + +message Packet { + oneof sum { + PacketPing packet_ping = 1; + PacketPong packet_pong = 2; + PacketMsg packet_msg = 3; + } +} + +message AuthSigMessage { + tendermint.crypto.PublicKey pub_key = 1 [(gogoproto.nullable) = false]; + bytes sig = 2; +} diff --git a/proto/tendermint/privval/privval.proto b/proto/tendermint/privval/privval.proto new file mode 100644 index 00000000..381851e8 --- /dev/null +++ b/proto/tendermint/privval/privval.proto @@ -0,0 +1,76 @@ +syntax = "proto3"; +package tendermint.privval; + +import "tendermint/crypto/keys.proto"; +import "tendermint/types/types.proto"; +import "gogoproto/gogo.proto"; + +option go_package = "github.com/strangelove-ventures/horcrux/v3/comet/proto/privval"; + +enum Errors { + ERRORS_UNKNOWN = 0; + ERRORS_UNEXPECTED_RESPONSE = 1; + ERRORS_NO_CONNECTION = 2; + ERRORS_CONNECTION_TIMEOUT = 3; + ERRORS_READ_TIMEOUT = 4; + ERRORS_WRITE_TIMEOUT = 5; +} + +message RemoteSignerError { + int32 code = 1; + string description = 2; +} + +// PubKeyRequest requests the consensus public key from the remote signer. +message PubKeyRequest { + string chain_id = 1; +} + +// PubKeyResponse is a response message containing the public key. +message PubKeyResponse { + tendermint.crypto.PublicKey pub_key = 1 [(gogoproto.nullable) = false]; + RemoteSignerError error = 2; +} + +// SignVoteRequest is a request to sign a vote +message SignVoteRequest { + tendermint.types.Vote vote = 1; + string chain_id = 2; +} + +// SignedVoteResponse is a response containing a signed vote or an error +message SignedVoteResponse { + tendermint.types.Vote vote = 1 [(gogoproto.nullable) = false]; + RemoteSignerError error = 2; +} + +// SignProposalRequest is a request to sign a proposal +message SignProposalRequest { + tendermint.types.Proposal proposal = 1; + string chain_id = 2; +} + +// SignedProposalResponse is response containing a signed proposal or an error +message SignedProposalResponse { + tendermint.types.Proposal proposal = 1 [(gogoproto.nullable) = false]; + RemoteSignerError error = 2; +} + +// PingRequest is a request to confirm that the connection is alive. +message PingRequest {} + +// PingResponse is a response to confirm that the connection is alive. +message PingResponse {} + +message Message { + oneof sum { + PubKeyRequest pub_key_request = 1; + PubKeyResponse pub_key_response = 2; + SignVoteRequest sign_vote_request = 3; + SignedVoteResponse signed_vote_response = 4; + SignProposalRequest sign_proposal_request = 5; + SignedProposalResponse signed_proposal_response = 6; + PingRequest ping_request = 7; + PingResponse ping_response = 8; + } +} diff --git a/proto/tendermint/types/canonical.proto b/proto/tendermint/types/canonical.proto new file mode 100644 index 00000000..eca7a87a --- /dev/null +++ b/proto/tendermint/types/canonical.proto @@ -0,0 +1,46 @@ +syntax = "proto3"; +package tendermint.types; + +option go_package = "github.com/strangelove-ventures/horcrux/v3/comet/proto/types"; + +import "gogoproto/gogo.proto"; +import "tendermint/types/types.proto"; +import "google/protobuf/timestamp.proto"; + +message CanonicalBlockID { + bytes hash = 1; + CanonicalPartSetHeader part_set_header = 2 [(gogoproto.nullable) = false]; +} + +message CanonicalPartSetHeader { + uint32 total = 1; + bytes hash = 2; +} + +message CanonicalProposal { + SignedMsgType type = 1; // type alias for byte + sfixed64 height = 2; // canonicalization requires fixed size encoding here + sfixed64 round = 3; // canonicalization requires fixed size encoding here + int64 pol_round = 4 [(gogoproto.customname) = "POLRound"]; + CanonicalBlockID block_id = 5 [(gogoproto.customname) = "BlockID"]; + google.protobuf.Timestamp timestamp = 6 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; + string chain_id = 7 [(gogoproto.customname) = "ChainID"]; +} + +message CanonicalVote { + SignedMsgType type = 1; // type alias for byte + sfixed64 height = 2; // canonicalization requires fixed size encoding here + sfixed64 round = 3; // canonicalization requires fixed size encoding here + CanonicalBlockID block_id = 4 [(gogoproto.customname) = "BlockID"]; + google.protobuf.Timestamp timestamp = 5 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; + string chain_id = 6 [(gogoproto.customname) = "ChainID"]; +} + +// CanonicalVoteExtension provides us a way to serialize a vote extension from +// a particular validator such that we can sign over those serialized bytes. +message CanonicalVoteExtension { + bytes extension = 1; + sfixed64 height = 2; + sfixed64 round = 3; + string chain_id = 4; +} diff --git a/proto/tendermint/types/types.proto b/proto/tendermint/types/types.proto new file mode 100644 index 00000000..704875ac --- /dev/null +++ b/proto/tendermint/types/types.proto @@ -0,0 +1,68 @@ +syntax = "proto3"; +package tendermint.types; + +option go_package = "github.com/strangelove-ventures/horcrux/v3/comet/proto/types"; + +import "gogoproto/gogo.proto"; +import "google/protobuf/timestamp.proto"; + +// SignedMsgType is a type of signed message in the consensus. +enum SignedMsgType { + option (gogoproto.goproto_enum_stringer) = true; + option (gogoproto.goproto_enum_prefix) = false; + + SIGNED_MSG_TYPE_UNKNOWN = 0 [(gogoproto.enumvalue_customname) = "UnknownType"]; + // Votes + SIGNED_MSG_TYPE_PREVOTE = 1 [(gogoproto.enumvalue_customname) = "PrevoteType"]; + SIGNED_MSG_TYPE_PRECOMMIT = 2 [(gogoproto.enumvalue_customname) = "PrecommitType"]; + + // Proposals + SIGNED_MSG_TYPE_PROPOSAL = 32 [(gogoproto.enumvalue_customname) = "ProposalType"]; +} + +// PartSetHeader +message PartSetHeader { + uint32 total = 1; + bytes hash = 2; +} + +// BlockID +message BlockID { + bytes hash = 1; + PartSetHeader part_set_header = 2 [(gogoproto.nullable) = false]; +} + +// Vote represents a prevote or precommit vote from validators for +// consensus. +message Vote { + SignedMsgType type = 1; + int64 height = 2; + int32 round = 3; + BlockID block_id = 4 + [(gogoproto.nullable) = false, (gogoproto.customname) = "BlockID"]; // zero if vote is nil. + google.protobuf.Timestamp timestamp = 5 + [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; + bytes validator_address = 6; + int32 validator_index = 7; + // Vote signature by the validator if they participated in consensus for the + // associated block. + bytes signature = 8; + // Vote extension provided by the application. Only valid for precommit + // messages. + bytes extension = 9; + // Vote extension signature by the validator if they participated in + // consensus for the associated block. + // Only valid for precommit messages. + bytes extension_signature = 10; +} + +message Proposal { + SignedMsgType type = 1; + int64 height = 2; + int32 round = 3; + int32 pol_round = 4; + BlockID block_id = 5 [(gogoproto.customname) = "BlockID", (gogoproto.nullable) = false]; + google.protobuf.Timestamp timestamp = 6 + [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; + bytes signature = 7; +} diff --git a/scripts/protocgen.sh b/scripts/protocgen.sh index 6e0428d0..07e711be 100644 --- a/scripts/protocgen.sh +++ b/scripts/protocgen.sh @@ -11,5 +11,5 @@ for dir in $proto_dirs; do done done -cp -r github.com/strangelove-ventures/horcrux/v3/signer ./ +cp -r github.com/strangelove-ventures/horcrux/v3/* ./ rm -rf github.com diff --git a/signer/bn254/threshold.go b/signer/bn254/threshold.go index 695495af..656be3ef 100644 --- a/signer/bn254/threshold.go +++ b/signer/bn254/threshold.go @@ -5,6 +5,7 @@ import ( "math/big" "github.com/consensys/gnark-crypto/ecc/bn254" + cometcryptobn254 "github.com/strangelove-ventures/horcrux/v3/comet/crypto/bn254" ) var genG2 = new(bn254.G2Affine) @@ -21,7 +22,7 @@ func init() { _, _ = zeroG1.SetBytes(g1Bytes254[:]) _, _ = zeroG2.SetBytes(g2Bytes254[:]) - zeroG1.Sub(zeroG1, &G1Gen) + zeroG1.Sub(zeroG1, &cometcryptobn254.G1Gen) zeroG2.Sub(zeroG2, genG2) } @@ -63,7 +64,7 @@ func CombineSignatures(signatures []*bn254.G2Affine, evaluationPoints ...int64) // SignWithShard signs a digest with a bn254 private key func SignWithShard(sk *big.Int, digest []byte) (*bn254.G2Affine, error) { - g2 := HashToG2(digest) + g2 := cometcryptobn254.HashToG2(digest) g2.ScalarMultiplication(&g2, sk) return &g2, nil @@ -71,10 +72,10 @@ func SignWithShard(sk *big.Int, digest []byte) (*bn254.G2Affine, error) { // VerifyShardSignature verifies a bn254 signature against a digest and a public key func VerifyShardSignature(pk *bn254.G1Affine, digest []byte, sig *bn254.G2Affine) error { - digestOnG2 := HashToG2(digest) + digestOnG2 := cometcryptobn254.HashToG2(digest) var g1Neg bn254.G1Affine - g1Neg.Neg(&G1Gen) + g1Neg.Neg(&cometcryptobn254.G1Gen) shouldBeOne, err := bn254.MillerLoop([]bn254.G1Affine{g1Neg, *pk}, []bn254.G2Affine{*sig, digestOnG2}) if err != nil { diff --git a/signer/bn254/threshold_test.go b/signer/bn254/threshold_test.go index fc00a1f5..0e37b8c7 100644 --- a/signer/bn254/threshold_test.go +++ b/signer/bn254/threshold_test.go @@ -5,7 +5,9 @@ import ( "testing" "github.com/consensys/gnark-crypto/ecc/bn254" - horcrux_bn254 "github.com/strangelove-ventures/horcrux/v3/signer/bn254" + cometcryptobn254 "github.com/strangelove-ventures/horcrux/v3/comet/crypto/bn254" + horcruxbn254 "github.com/strangelove-ventures/horcrux/v3/signer/bn254" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "golang.org/x/crypto/sha3" @@ -15,7 +17,7 @@ func TestBn254(t *testing.T) { skInt := int64(2) var pk bn254.G1Affine - pk.ScalarMultiplication(&horcrux_bn254.G1Gen, big.NewInt(skInt)) + pk.ScalarMultiplication(&cometcryptobn254.G1Gen, big.NewInt(skInt)) msg := []byte("payload to sign") @@ -27,7 +29,7 @@ func TestBn254(t *testing.T) { var sig bn254.G2Affine _ = sig.ScalarMultiplication(&hash, big.NewInt(skInt)) - left, err := bn254.MillerLoop([]bn254.G1Affine{horcrux_bn254.G1Gen}, []bn254.G2Affine{sig}) + left, err := bn254.MillerLoop([]bn254.G1Affine{cometcryptobn254.G1Gen}, []bn254.G2Affine{sig}) require.NoError(t, err) left = bn254.FinalExponentiation(&left) @@ -41,12 +43,12 @@ func TestBn254(t *testing.T) { } func TestThresholdBn254(t *testing.T) { - secret := horcrux_bn254.GenPrivKey() + secret := cometcryptobn254.GenPrivKey() secretBz := secret.Bytes() pubKey := secret.PubKey() - _, shards := horcrux_bn254.GenFromSecret(secretBz, 2, 3) + _, shards := horcruxbn254.GenFromSecret(secretBz, 2, 3) msg := []byte("payload to sign") @@ -54,19 +56,19 @@ func TestThresholdBn254(t *testing.T) { signatures := make([]*bn254.G2Affine, len(shards)) for i, shard := range shards { - signature, err := horcrux_bn254.SignWithShard(shard, digest) + signature, err := horcruxbn254.SignWithShard(shard, digest) require.NoError(t, err) var pubKey bn254.G1Affine - pubKey.ScalarMultiplication(&horcrux_bn254.G1Gen, shard) + pubKey.ScalarMultiplication(&cometcryptobn254.G1Gen, shard) - err = horcrux_bn254.VerifyShardSignature(&pubKey, digest, signature) + err = horcruxbn254.VerifyShardSignature(&pubKey, digest, signature) require.NoError(t, err) signatures[i] = signature } - thresholdSignature := horcrux_bn254.CombineSignatures(signatures[:2], 1, 2) + thresholdSignature := horcruxbn254.CombineSignatures(signatures[:2], 1, 2) thresholdSignatureBz := thresholdSignature.Bytes() valid := pubKey.VerifySignature(digest, thresholdSignatureBz[:]) diff --git a/signer/cosigner.go b/signer/cosigner.go index d11f6ee9..618eb3a5 100644 --- a/signer/cosigner.go +++ b/signer/cosigner.go @@ -4,9 +4,11 @@ import ( "context" "time" - cometcrypto "github.com/cometbft/cometbft/crypto" + cometcrypto "github.com/strangelove-ventures/horcrux/v3/comet/crypto" + grpccosigner "github.com/strangelove-ventures/horcrux/v3/grpc/cosigner" + "github.com/strangelove-ventures/horcrux/v3/types" + "github.com/google/uuid" - "github.com/strangelove-ventures/horcrux/v3/signer/proto" ) // Cosigner interface is a set of methods for an m-of-n threshold signature. @@ -64,8 +66,8 @@ type CosignerNonce struct { Signature []byte } -func (secretPart *CosignerNonce) toProto() *proto.Nonce { - return &proto.Nonce{ +func (secretPart *CosignerNonce) toProto() *grpccosigner.Nonce { + return &grpccosigner.Nonce{ SourceID: int32(secretPart.SourceID), DestinationID: int32(secretPart.DestinationID), PubKey: secretPart.PubKey, @@ -76,14 +78,14 @@ func (secretPart *CosignerNonce) toProto() *proto.Nonce { type CosignerNonces []CosignerNonce -func (secretParts CosignerNonces) toProto() (out []*proto.Nonce) { +func (secretParts CosignerNonces) toProto() (out []*grpccosigner.Nonce) { for _, secretPart := range secretParts { out = append(out, secretPart.toProto()) } return } -func CosignerNonceFromProto(secretPart *proto.Nonce) CosignerNonce { +func CosignerNonceFromProto(secretPart *grpccosigner.Nonce) CosignerNonce { return CosignerNonce{ SourceID: int(secretPart.SourceID), DestinationID: int(secretPart.DestinationID), @@ -93,7 +95,7 @@ func CosignerNonceFromProto(secretPart *proto.Nonce) CosignerNonce { } } -func CosignerNoncesFromProto(secretParts []*proto.Nonce) []CosignerNonce { +func CosignerNoncesFromProto(secretParts []*grpccosigner.Nonce) []CosignerNonce { out := make([]CosignerNonce, len(secretParts)) for i, secretPart := range secretParts { out[i] = CosignerNonceFromProto(secretPart) @@ -103,7 +105,7 @@ func CosignerNoncesFromProto(secretParts []*proto.Nonce) []CosignerNonce { type CosignerSignBlockRequest struct { ChainID string - Block *Block + Block *types.Block } type CosignerSignBlockResponse struct { @@ -126,10 +128,10 @@ func (n *CosignerUUIDNonces) For(id int) *CosignerUUIDNonces { type CosignerUUIDNoncesMultiple []*CosignerUUIDNonces -func (n CosignerUUIDNoncesMultiple) toProto() []*proto.UUIDNonce { - out := make([]*proto.UUIDNonce, len(n)) +func (n CosignerUUIDNoncesMultiple) toProto() []*grpccosigner.UUIDNonce { + out := make([]*grpccosigner.UUIDNonce, len(n)) for i, nonces := range n { - out[i] = &proto.UUIDNonce{ + out[i] = &grpccosigner.UUIDNonce{ Uuid: nonces.UUID[:], Nonces: nonces.Nonces.toProto(), } @@ -140,6 +142,6 @@ func (n CosignerUUIDNoncesMultiple) toProto() []*proto.UUIDNonce { type CosignerSetNoncesAndSignRequest struct { ChainID string Nonces *CosignerUUIDNonces - HRST HRSTKey + HRST types.HRSTKey SignBytes []byte } diff --git a/signer/cosigner_grpc_server.go b/signer/cosigner_grpc_server.go index be62cbed..c92f6caf 100644 --- a/signer/cosigner_grpc_server.go +++ b/signer/cosigner_grpc_server.go @@ -6,16 +6,17 @@ import ( "github.com/google/uuid" "github.com/hashicorp/raft" - "github.com/strangelove-ventures/horcrux/v3/signer/proto" + grpccosigner "github.com/strangelove-ventures/horcrux/v3/grpc/cosigner" + "github.com/strangelove-ventures/horcrux/v3/types" ) -var _ proto.CosignerServer = &CosignerGRPCServer{} +var _ grpccosigner.CosignerServer = &CosignerGRPCServer{} type CosignerGRPCServer struct { cosigner *LocalCosigner thresholdValidator *ThresholdValidator raftStore *RaftStore - proto.UnimplementedCosignerServer + grpccosigner.UnimplementedCosignerServer } func NewCosignerGRPCServer( @@ -32,28 +33,28 @@ func NewCosignerGRPCServer( func (rpc *CosignerGRPCServer) SignBlock( ctx context.Context, - req *proto.SignBlockRequest, -) (*proto.SignBlockResponse, error) { - res, _, err := rpc.thresholdValidator.Sign(ctx, req.ChainID, BlockFromProto(req.Block)) + req *grpccosigner.SignBlockRequest, +) (*grpccosigner.SignBlockResponse, error) { + res, _, err := rpc.thresholdValidator.Sign(ctx, req.ChainID, types.BlockFromProto(req.Block)) if err != nil { return nil, err } - return &proto.SignBlockResponse{ + return &grpccosigner.SignBlockResponse{ Signature: res, }, nil } func (rpc *CosignerGRPCServer) SetNoncesAndSign( ctx context.Context, - req *proto.SetNoncesAndSignRequest, -) (*proto.SetNoncesAndSignResponse, error) { + req *grpccosigner.SetNoncesAndSignRequest, +) (*grpccosigner.SetNoncesAndSignResponse, error) { res, err := rpc.cosigner.SetNoncesAndSign(ctx, CosignerSetNoncesAndSignRequest{ ChainID: req.ChainID, Nonces: &CosignerUUIDNonces{ UUID: uuid.UUID(req.Uuid), Nonces: CosignerNoncesFromProto(req.GetNonces()), }, - HRST: HRSTKeyFromProto(req.GetHrst()), + HRST: types.HRSTKeyFromProto(req.GetHrst()), SignBytes: req.GetSignBytes(), }) if err != nil { @@ -74,7 +75,7 @@ func (rpc *CosignerGRPCServer) SetNoncesAndSign( "round", req.Hrst.Round, "step", req.Hrst.Step, ) - return &proto.SetNoncesAndSignResponse{ + return &grpccosigner.SetNoncesAndSignResponse{ NoncePublic: res.NoncePublic, Timestamp: res.Timestamp.UnixNano(), Signature: res.Signature, @@ -83,8 +84,8 @@ func (rpc *CosignerGRPCServer) SetNoncesAndSign( func (rpc *CosignerGRPCServer) GetNonces( ctx context.Context, - req *proto.GetNoncesRequest, -) (*proto.GetNoncesResponse, error) { + req *grpccosigner.GetNoncesRequest, +) (*grpccosigner.GetNoncesResponse, error) { uuids := make([]uuid.UUID, len(req.Uuids)) for i, uuidBytes := range req.Uuids { uuids[i] = uuid.UUID(uuidBytes) @@ -97,17 +98,17 @@ func (rpc *CosignerGRPCServer) GetNonces( return nil, err } - return &proto.GetNoncesResponse{ + return &grpccosigner.GetNoncesResponse{ Nonces: res.toProto(), }, nil } func (rpc *CosignerGRPCServer) TransferLeadership( _ context.Context, - req *proto.TransferLeadershipRequest, -) (*proto.TransferLeadershipResponse, error) { + req *grpccosigner.TransferLeadershipRequest, +) (*grpccosigner.TransferLeadershipResponse, error) { if rpc.raftStore.raft.State() != raft.Leader { - return &proto.TransferLeadershipResponse{}, nil + return &grpccosigner.TransferLeadershipResponse{}, nil } leaderID := req.GetLeaderID() if leaderID != "" { @@ -117,23 +118,23 @@ func (rpc *CosignerGRPCServer) TransferLeadership( raftAddress := p2pURLToRaftAddress(c.GetAddress()) fmt.Printf("Transferring leadership to ID: %s - Address: %s\n", shardID, raftAddress) rpc.raftStore.raft.LeadershipTransferToServer(raft.ServerID(shardID), raft.ServerAddress(raftAddress)) - return &proto.TransferLeadershipResponse{LeaderID: shardID, LeaderAddress: raftAddress}, nil + return &grpccosigner.TransferLeadershipResponse{LeaderID: shardID, LeaderAddress: raftAddress}, nil } } } fmt.Printf("Transferring leadership to next candidate\n") rpc.raftStore.raft.LeadershipTransfer() - return &proto.TransferLeadershipResponse{}, nil + return &grpccosigner.TransferLeadershipResponse{}, nil } func (rpc *CosignerGRPCServer) GetLeader( context.Context, - *proto.GetLeaderRequest, -) (*proto.GetLeaderResponse, error) { + *grpccosigner.GetLeaderRequest, +) (*grpccosigner.GetLeaderResponse, error) { leader := rpc.raftStore.GetLeader() - return &proto.GetLeaderResponse{Leader: int32(leader)}, nil + return &grpccosigner.GetLeaderResponse{Leader: int32(leader)}, nil } -func (rpc *CosignerGRPCServer) Ping(context.Context, *proto.PingRequest) (*proto.PingResponse, error) { - return &proto.PingResponse{}, nil +func (rpc *CosignerGRPCServer) Ping(context.Context, *grpccosigner.PingRequest) (*grpccosigner.PingResponse, error) { + return &grpccosigner.PingResponse{}, nil } diff --git a/signer/cosigner_health.go b/signer/cosigner_health.go index 94697ce1..41597637 100644 --- a/signer/cosigner_health.go +++ b/signer/cosigner_health.go @@ -2,12 +2,12 @@ package signer import ( "context" + "log/slog" "sort" "sync" "time" - cometlog "github.com/cometbft/cometbft/libs/log" - "github.com/strangelove-ventures/horcrux/v3/signer/proto" + grpccosigner "github.com/strangelove-ventures/horcrux/v3/grpc/cosigner" ) const ( @@ -15,7 +15,7 @@ const ( ) type CosignerHealth struct { - logger cometlog.Logger + logger *slog.Logger cosigners []Cosigner rtt map[int]int64 mu sync.RWMutex @@ -23,7 +23,7 @@ type CosignerHealth struct { leader Leader } -func NewCosignerHealth(logger cometlog.Logger, cosigners []Cosigner, leader Leader) *CosignerHealth { +func NewCosignerHealth(logger *slog.Logger, cosigners []Cosigner, leader Leader) *CosignerHealth { return &CosignerHealth{ logger: logger, cosigners: cosigners, @@ -78,7 +78,7 @@ func (ch *CosignerHealth) updateRTT(ctx context.Context, cosigner *RemoteCosigne ctx, cancel := context.WithTimeout(ctx, 1*time.Second) defer cancel() - _, err := cosigner.client.Ping(ctx, &proto.PingRequest{}) + _, err := cosigner.client.Ping(ctx, &grpccosigner.PingRequest{}) if err != nil { ch.logger.Error("Failed to ping", "cosigner", cosigner.GetID(), "error", err) return diff --git a/signer/cosigner_health_test.go b/signer/cosigner_health_test.go index 4f7398c2..d2080949 100644 --- a/signer/cosigner_health_test.go +++ b/signer/cosigner_health_test.go @@ -1,16 +1,16 @@ package signer import ( + "log/slog" "os" "testing" - cometlog "github.com/cometbft/cometbft/libs/log" "github.com/stretchr/testify/require" ) func TestCosignerHealth(t *testing.T) { ch := NewCosignerHealth( - cometlog.NewTMLogger(cometlog.NewSyncWriter(os.Stdout)), + slog.New(slog.NewTextHandler(os.Stdout, nil)), []Cosigner{ &RemoteCosigner{id: 2}, &RemoteCosigner{id: 3}, diff --git a/signer/cosigner_key.go b/signer/cosigner_key.go index 62371f0f..ef760fe0 100644 --- a/signer/cosigner_key.go +++ b/signer/cosigner_key.go @@ -6,11 +6,12 @@ import ( "fmt" "os" - cometcrypto "github.com/cometbft/cometbft/crypto" - cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519" - "github.com/strangelove-ventures/horcrux/v3/signer/bn254" - "github.com/strangelove-ventures/horcrux/v3/signer/encoding" - "github.com/strangelove-ventures/horcrux/v3/signer/proto" + cometcrypto "github.com/strangelove-ventures/horcrux/v3/comet/crypto" + cometcryptobn254 "github.com/strangelove-ventures/horcrux/v3/comet/crypto/bn254" + cometcryptoed25519 "github.com/strangelove-ventures/horcrux/v3/comet/crypto/ed25519" + "github.com/strangelove-ventures/horcrux/v3/comet/encoding" + cometprotocrypto "github.com/strangelove-ventures/horcrux/v3/comet/proto/crypto" + "github.com/tendermint/go-amino" ) @@ -28,7 +29,7 @@ func (key *CosignerKey) MarshalJSON() ([]byte, error) { var pub cometcrypto.PubKey switch key.KeyType { case CosignerKeyTypeBn254: - pub = bn254.PubKey(key.PubKey) + pub = cometcryptobn254.PubKey(key.PubKey) case CosignerKeyTypeEd25519: fallthrough default: @@ -68,7 +69,7 @@ func (key *CosignerKey) UnmarshalJSON(data []byte) error { } var pubkey cometcrypto.PubKey - var protoPubkey proto.PublicKey + var protoPubkey cometprotocrypto.PublicKey err := protoPubkey.Unmarshal(aux.PubkeyBytes) // Prior to the tendermint protobuf migration, the public key bytes in key files diff --git a/signer/cosigner_key_shares.go b/signer/cosigner_key_shares.go index adbce5b2..4988bd77 100644 --- a/signer/cosigner_key_shares.go +++ b/signer/cosigner_key_shares.go @@ -7,12 +7,13 @@ import ( "errors" "os" - cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519" - cometjson "github.com/cometbft/cometbft/libs/json" - "github.com/cometbft/cometbft/privval" "github.com/ethereum/go-ethereum/crypto/ecies" "github.com/ethereum/go-ethereum/crypto/secp256k1" - horcrux_bn254 "github.com/strangelove-ventures/horcrux/v3/signer/bn254" + cometcryptobn254 "github.com/strangelove-ventures/horcrux/v3/comet/crypto/bn254" + cometcryptoed25519 "github.com/strangelove-ventures/horcrux/v3/comet/crypto/ed25519" + cometjson "github.com/strangelove-ventures/horcrux/v3/comet/libs/json" + "github.com/strangelove-ventures/horcrux/v3/comet/privval" + horcruxbn254 "github.com/strangelove-ventures/horcrux/v3/signer/bn254" tsed25519 "gitlab.com/unit410/threshold-ed25519/pkg" "golang.org/x/sync/errgroup" ) @@ -34,7 +35,7 @@ func CreateCosignerShards(pv *privval.FilePVKey, threshold, shards uint8) ([]Cos switch pv.PrivKey.(type) { case cometcryptoed25519.PrivKey: return CreateCosignerEd25519Shards(pv, threshold, shards), nil - case horcrux_bn254.PrivKey: + case cometcryptobn254.PrivKey: return CreateCosignerBn254Shards(pv, threshold, shards), nil default: return nil, ErrUnsupportedKeyType @@ -61,7 +62,7 @@ func CreateCosignerEd25519Shards(pv *privval.FilePVKey, threshold, shards uint8) // CreateCosignerEd25519Shards creates CosignerKey objects from a privval.FilePVKey func CreateCosignerBn254Shards(pv *privval.FilePVKey, threshold, shards uint8) []CosignerKey { - _, privShards := horcrux_bn254.GenFromSecret(pv.PrivKey.Bytes(), threshold, shards) + _, privShards := horcruxbn254.GenFromSecret(pv.PrivKey.Bytes(), threshold, shards) out := make([]CosignerKey, shards) for i, shard := range privShards { diff --git a/signer/cosigner_nonce_cache.go b/signer/cosigner_nonce_cache.go index 58f2ee47..b8c39587 100644 --- a/signer/cosigner_nonce_cache.go +++ b/signer/cosigner_nonce_cache.go @@ -3,11 +3,11 @@ package signer import ( "context" "fmt" + "log/slog" "sync" "sync/atomic" "time" - cometlog "github.com/cometbft/cometbft/libs/log" "github.com/google/uuid" ) @@ -19,7 +19,7 @@ const ( ) type CosignerNonceCache struct { - logger cometlog.Logger + logger *slog.Logger cosigners []Cosigner leader Leader @@ -159,7 +159,7 @@ type CachedNonce struct { } func NewCosignerNonceCache( - logger cometlog.Logger, + logger *slog.Logger, cosigners []Cosigner, leader Leader, getNoncesInterval time.Duration, diff --git a/signer/cosigner_nonce_cache_test.go b/signer/cosigner_nonce_cache_test.go index 623f7b04..b124b509 100644 --- a/signer/cosigner_nonce_cache_test.go +++ b/signer/cosigner_nonce_cache_test.go @@ -2,12 +2,12 @@ package signer import ( "context" + "log/slog" "os" "sync" "testing" "time" - cometlog "github.com/cometbft/cometbft/libs/log" "github.com/google/uuid" "github.com/stretchr/testify/require" ) @@ -150,7 +150,7 @@ func TestNonceCacheDemand(t *testing.T) { mp := &mockPruner{} nonceCache := NewCosignerNonceCache( - cometlog.NewTMLogger(cometlog.NewSyncWriter(os.Stdout)), + slog.New(slog.NewTextHandler(os.Stdout, nil)), cosigners, &MockLeader{id: 1, leader: &ThresholdValidator{myCosigner: lcs[0]}}, 500*time.Millisecond, @@ -202,7 +202,7 @@ func TestNonceCacheExpiration(t *testing.T) { getNoncesInterval := noncesExpiration / 5 getNoncesTimeout := 10 * time.Millisecond nonceCache := NewCosignerNonceCache( - cometlog.NewTMLogger(cometlog.NewSyncWriter(os.Stdout)), + slog.New(slog.NewTextHandler(os.Stdout, nil)), cosigners, &MockLeader{id: 1, leader: &ThresholdValidator{myCosigner: lcs[0]}}, getNoncesInterval, @@ -408,7 +408,7 @@ func TestNonceCacheDemandSlow(t *testing.T) { } nonceCache := NewCosignerNonceCache( - cometlog.NewTMLogger(cometlog.NewSyncWriter(os.Stdout)), + slog.New(slog.NewTextHandler(os.Stdout, nil)), cosigners, &MockLeader{id: 1, leader: &ThresholdValidator{myCosigner: lcs[0]}}, 90*time.Millisecond, @@ -445,7 +445,7 @@ func TestNonceCacheDemandSlowDefault(t *testing.T) { } nonceCache := NewCosignerNonceCache( - cometlog.NewTMLogger(cometlog.NewSyncWriter(os.Stdout)), + slog.New(slog.NewTextHandler(os.Stdout, nil)), cosigners, &MockLeader{id: 1, leader: &ThresholdValidator{myCosigner: lcs[0]}}, defaultGetNoncesInterval, diff --git a/signer/cosigner_security_ecies.go b/signer/cosigner_security_ecies.go index cde12d12..5c1174b0 100644 --- a/signer/cosigner_security_ecies.go +++ b/signer/cosigner_security_ecies.go @@ -9,9 +9,9 @@ import ( "math/big" "os" - cometjson "github.com/cometbft/cometbft/libs/json" "github.com/ethereum/go-ethereum/crypto/ecies" "github.com/ethereum/go-ethereum/crypto/secp256k1" + cometjson "github.com/strangelove-ventures/horcrux/v3/comet/libs/json" "golang.org/x/sync/errgroup" ) diff --git a/signer/cosigner_security_rsa.go b/signer/cosigner_security_rsa.go index eb46b442..c0bae581 100644 --- a/signer/cosigner_security_rsa.go +++ b/signer/cosigner_security_rsa.go @@ -10,7 +10,7 @@ import ( "fmt" "os" - cometjson "github.com/cometbft/cometbft/libs/json" + cometjson "github.com/strangelove-ventures/horcrux/v3/comet/libs/json" "golang.org/x/sync/errgroup" ) diff --git a/signer/encoding/codec.go b/signer/encoding/codec.go deleted file mode 100644 index bdee34c6..00000000 --- a/signer/encoding/codec.go +++ /dev/null @@ -1,76 +0,0 @@ -package encoding - -import ( - "fmt" - - "github.com/cometbft/cometbft/crypto" - "github.com/cometbft/cometbft/crypto/ed25519" - "github.com/cometbft/cometbft/crypto/secp256k1" - "github.com/cometbft/cometbft/libs/json" - "github.com/strangelove-ventures/horcrux/v3/signer/bn254" - "github.com/strangelove-ventures/horcrux/v3/signer/proto" -) - -func init() { - json.RegisterType((*proto.PublicKey_Bn254)(nil), "tendermint.crypto.PublicKey_Bn254") -} - -// PubKeyToProto takes crypto.PubKey and transforms it to a protobuf Pubkey -func PubKeyToProto(k crypto.PubKey) (proto.PublicKey, error) { - var kp proto.PublicKey - switch k := k.(type) { - case ed25519.PubKey: - kp = proto.PublicKey{ - Sum: &proto.PublicKey_Ed25519{ - Ed25519: k, - }, - } - case secp256k1.PubKey: - kp = proto.PublicKey{ - Sum: &proto.PublicKey_Secp256K1{ - Secp256K1: k, - }, - } - case bn254.PubKey: - kp = proto.PublicKey{ - Sum: &proto.PublicKey_Bn254{ - Bn254: k, - }, - } - default: - return kp, fmt.Errorf("toproto: key type %v is not supported", k) - } - return kp, nil -} - -// PubKeyFromProto takes a protobuf Pubkey and transforms it to a crypto.Pubkey -func PubKeyFromProto(k proto.PublicKey) (crypto.PubKey, error) { - switch k := k.Sum.(type) { - case *proto.PublicKey_Ed25519: - if len(k.Ed25519) != ed25519.PubKeySize { - return nil, fmt.Errorf("invalid size for PubKeyEd25519. Got %d, expected %d", - len(k.Ed25519), ed25519.PubKeySize) - } - pk := make(ed25519.PubKey, ed25519.PubKeySize) - copy(pk, k.Ed25519) - return pk, nil - case *proto.PublicKey_Secp256K1: - if len(k.Secp256K1) != secp256k1.PubKeySize { - return nil, fmt.Errorf("invalid size for PubKeySecp256k1. Got %d, expected %d", - len(k.Secp256K1), secp256k1.PubKeySize) - } - pk := make(secp256k1.PubKey, secp256k1.PubKeySize) - copy(pk, k.Secp256K1) - return pk, nil - case *proto.PublicKey_Bn254: - if len(k.Bn254) != bn254.PubKeySize { - return nil, fmt.Errorf("invalid size for PubKeyBn254. Got %d, expected %d", - len(k.Bn254), bn254.PubKeySize) - } - pk := make(bn254.PubKey, bn254.PubKeySize) - copy(pk, k.Bn254) - return pk, nil - default: - return nil, fmt.Errorf("fromproto: key type %v is not supported", k) - } -} diff --git a/signer/leader.go b/signer/leader.go index beafb3ee..9902eccf 100644 --- a/signer/leader.go +++ b/signer/leader.go @@ -1,12 +1,14 @@ package signer +import "github.com/strangelove-ventures/horcrux/v3/types" + // Leader is an interface for the detecting if the current cosigner is the leader and performing leader actions. type Leader interface { // IsLeader returns true if the cosigner is the leader. IsLeader() bool // ShareSigned shares the last signed state with the other cosigners. - ShareSigned(lss ChainSignStateConsensus) error + ShareSigned(lss types.ChainSignStateConsensus) error // Get current leader GetLeader() int diff --git a/signer/leader_mock.go b/signer/leader_mock.go index bd1c7c09..0e8c086c 100644 --- a/signer/leader_mock.go +++ b/signer/leader_mock.go @@ -2,6 +2,8 @@ package signer import ( "sync" + + "github.com/strangelove-ventures/horcrux/v3/types" ) var _ Leader = (*MockLeader)(nil) @@ -29,6 +31,6 @@ func (m *MockLeader) GetLeader() int { return m.id } -func (m *MockLeader) ShareSigned(_ ChainSignStateConsensus) error { +func (m *MockLeader) ShareSigned(_ types.ChainSignStateConsensus) error { return nil } diff --git a/signer/local_cosigner.go b/signer/local_cosigner.go index 9d3e9069..f600021a 100644 --- a/signer/local_cosigner.go +++ b/signer/local_cosigner.go @@ -4,13 +4,15 @@ import ( "context" "errors" "fmt" + "log/slog" "sync" "time" - cometcrypto "github.com/cometbft/cometbft/crypto" - cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519" - cometlog "github.com/cometbft/cometbft/libs/log" "github.com/google/uuid" + cometcrypto "github.com/strangelove-ventures/horcrux/v3/comet/crypto" + cometcryptobn254 "github.com/strangelove-ventures/horcrux/v3/comet/crypto/bn254" + cometcryptoed25519 "github.com/strangelove-ventures/horcrux/v3/comet/crypto/ed25519" + "github.com/strangelove-ventures/horcrux/v3/types" "golang.org/x/sync/errgroup" ) @@ -24,7 +26,7 @@ const nonceExpiration = 20 * time.Second // It maintains a high watermark to avoid double-signing. // Signing is thread safe. type LocalCosigner struct { - logger cometlog.Logger + logger *slog.Logger config *RuntimeConfig security CosignerSecurity chainState sync.Map @@ -37,7 +39,7 @@ type LocalCosigner struct { } func NewLocalCosigner( - logger cometlog.Logger, + logger *slog.Logger, config *RuntimeConfig, security CosignerSecurity, address string, @@ -54,7 +56,7 @@ func NewLocalCosigner( type ChainState struct { // lastSignState stores the last sign state for an HRS we have fully signed // incremented whenever we are asked to sign an HRS - lastSignState *SignState + lastSignState *types.SignState // signer generates nonces, combines nonces, signs, and verifies signatures. signer ThresholdSigner } @@ -114,7 +116,7 @@ func (cosigner *LocalCosigner) combinedNonces(myID int, threshold uint8, uuid uu // than the current high watermark. A mutex is used to avoid concurrent state updates. // The disk write is scheduled in a separate goroutine which will perform an atomic write. // pendingDiskWG is used upon termination in pendingDiskWG to ensure all writes have completed. -func (cosigner *LocalCosigner) SaveLastSignedState(chainID string, signState SignStateConsensus) error { +func (cosigner *LocalCosigner) SaveLastSignedState(chainID string, signState types.SignStateConsensus) error { ccs, err := cosigner.getChainState(chainID) if err != nil { return err @@ -170,7 +172,14 @@ func (cosigner *LocalCosigner) GetPubKey(chainID string) (cometcrypto.PubKey, er return nil, err } - return cometcryptoed25519.PubKey(ccs.signer.PubKey()), nil + switch ccs.signer.(type) { + case *ThresholdSignerSoftBn254: + return cometcryptobn254.PubKey(ccs.signer.PubKey()), nil + case *ThresholdSignerSoftEd25519: + return cometcryptoed25519.PubKey(ccs.signer.PubKey()), nil + default: + return nil, fmt.Errorf("unknown signer type: %T", ccs.signer) + } } // CombineSignatures combines partial signatures into a full signature. @@ -219,12 +228,12 @@ func (cosigner *LocalCosigner) sign(req CosignerSignRequest) (CosignerSignRespon // This function has multiple exit points. Only start time can be guaranteed metricsTimeKeeper.SetPreviousLocalSignStart(time.Now()) - hrst, err := UnpackHRST(req.SignBytes) + hrst, err := types.UnpackHRST(req.SignBytes) if err != nil { return res, err } - existingSignature, err := ccs.lastSignState.existingSignatureOrErrorIfRegression(hrst, req.SignBytes) + existingSignature, err := ccs.lastSignState.ExistingSignatureOrErrorIfRegression(hrst, req.SignBytes) if err != nil { return res, err } @@ -248,7 +257,7 @@ func (cosigner *LocalCosigner) sign(req CosignerSignRequest) (CosignerSignRespon return res, err } - err = ccs.lastSignState.Save(SignStateConsensus{ + err = ccs.lastSignState.Save(types.SignStateConsensus{ Height: hrst.Height, Round: hrst.Round, Step: hrst.Step, @@ -257,7 +266,7 @@ func (cosigner *LocalCosigner) sign(req CosignerSignRequest) (CosignerSignRespon }, &cosigner.pendingDiskWG) if err != nil { - if _, isSameHRSError := err.(*SameHRSError); !isSameHRSError { + if _, isSameHRSError := err.(*types.SameHRSError); !isSameHRSError { return res, err } } @@ -300,7 +309,7 @@ func (cosigner *LocalCosigner) LoadSignStateIfNecessary(chainID string) error { return nil } - signState, err := LoadOrCreateSignState(cosigner.config.CosignerStateFile(chainID)) + signState, err := types.LoadOrCreateSignState(cosigner.config.CosignerStateFile(chainID)) if err != nil { return err } diff --git a/signer/local_cosigner_test.go b/signer/local_cosigner_test.go index 46c09659..b7638676 100644 --- a/signer/local_cosigner_test.go +++ b/signer/local_cosigner_test.go @@ -6,18 +6,19 @@ import ( "crypto/rsa" "encoding/json" "fmt" + "log/slog" "os" "path/filepath" "testing" "time" - cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519" - "github.com/cometbft/cometbft/libs/log" - cometproto "github.com/cometbft/cometbft/proto/tendermint/types" - comet "github.com/cometbft/cometbft/types" "github.com/ethereum/go-ethereum/crypto/ecies" "github.com/ethereum/go-ethereum/crypto/secp256k1" "github.com/google/uuid" + cometcryptoed25519 "github.com/strangelove-ventures/horcrux/v3/comet/crypto/ed25519" + cometproto "github.com/strangelove-ventures/horcrux/v3/comet/proto/types" + comet "github.com/strangelove-ventures/horcrux/v3/comet/types" + "github.com/strangelove-ventures/horcrux/v3/types" "github.com/stretchr/testify/require" tsed25519 "gitlab.com/unit410/threshold-ed25519/pkg" ) @@ -124,7 +125,7 @@ func testLocalCosignerSign(t *testing.T, threshold, total uint8, security []Cosi now := time.Now() - hrst := HRSTKey{ + hrst := types.HRSTKey{ Height: 1, Round: 0, Step: 2, @@ -152,7 +153,7 @@ func testLocalCosignerSign(t *testing.T, threshold, total uint8, security []Cosi require.NoError(t, err) cosigner := NewLocalCosigner( - log.NewNopLogger(), + slog.New(slog.NewTextHandler(os.Stdout, nil)), &RuntimeConfig{ HomeDir: cosignerDir, StateDir: cosignerDir, diff --git a/signer/metrics.go b/signer/metrics.go index 2145ba77..6945f679 100644 --- a/signer/metrics.go +++ b/signer/metrics.go @@ -1,6 +1,7 @@ package signer import ( + "context" "sync" "time" @@ -315,14 +316,18 @@ var ( ) ) -func StartMetrics() { +func StartMetrics(ctx context.Context) { // Update elapsed times on an interval basis for { - metricsTimeKeeper.UpdatePrometheusMetrics() + select { + case <-ctx.Done(): + return + case <-time.After(100 * time.Millisecond): + // Prometheus often only polls every 1 to every few seconds + // Frequent updates minimize reporting error. + // Accuracy of 100ms is probably sufficient - // Prometheus often only polls every 1 to every few seconds - // Frequent updates minimize reporting error. - // Accuracy of 100ms is probably sufficient - <-time.After(100 * time.Millisecond) + metricsTimeKeeper.UpdatePrometheusMetrics() + } } } diff --git a/signer/multiresolver/multi_test.go b/signer/multiresolver/multi_test.go index 236c07df..2a4ce260 100644 --- a/signer/multiresolver/multi_test.go +++ b/signer/multiresolver/multi_test.go @@ -10,9 +10,9 @@ import ( "time" grpcretry "github.com/grpc-ecosystem/go-grpc-middleware/retry" + grpccosigner "github.com/strangelove-ventures/horcrux/v3/grpc/cosigner" "github.com/strangelove-ventures/horcrux/v3/signer" "github.com/strangelove-ventures/horcrux/v3/signer/multiresolver" - "github.com/strangelove-ventures/horcrux/v3/signer/proto" "github.com/stretchr/testify/require" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" @@ -39,7 +39,7 @@ func createListener(nodeID string, homedir string) (string, func(), error) { } grpcServer := grpc.NewServer() - proto.RegisterCosignerServer(grpcServer, signer.NewCosignerGRPCServer(nil, nil, s)) + grpccosigner.RegisterCosignerServer(grpcServer, signer.NewCosignerGRPCServer(nil, nil, s)) transportManager.Register(grpcServer) go func() { @@ -90,8 +90,8 @@ func TestMultiResolver(t *testing.T) { ctx, cancelFunc := context.WithTimeout(context.Background(), 30*time.Second) defer cancelFunc() - grpcClient := proto.NewCosignerClient(connDNS) - _, err = grpcClient.GetLeader(ctx, &proto.GetLeaderRequest{}) + grpcClient := grpccosigner.NewCosignerClient(connDNS) + _, err = grpcClient.GetLeader(ctx, &grpccosigner.GetLeaderRequest{}) require.NoError(t, err) connIP, err := grpc.Dial(targetIP, @@ -103,7 +103,7 @@ func TestMultiResolver(t *testing.T) { require.NoError(t, err) defer connIP.Close() - grpcClient = proto.NewCosignerClient(connIP) - _, err = grpcClient.GetLeader(ctx, &proto.GetLeaderRequest{}) + grpcClient = grpccosigner.NewCosignerClient(connIP) + _, err = grpcClient.GetLeader(ctx, &grpccosigner.GetLeaderRequest{}) require.NoError(t, err) } diff --git a/signer/raft_events.go b/signer/raft_events.go index e3c70cd6..9afc6e52 100644 --- a/signer/raft_events.go +++ b/signer/raft_events.go @@ -2,6 +2,8 @@ package signer import ( "encoding/json" + + "github.com/strangelove-ventures/horcrux/v3/types" ) const ( @@ -20,7 +22,7 @@ func (f *fsm) shouldRetain(key string) bool { } func (f *fsm) handleLSSEvent(value string) { - lss := &ChainSignStateConsensus{} + lss := &types.ChainSignStateConsensus{} err := json.Unmarshal([]byte(value), lss) if err != nil { f.logger.Error( diff --git a/signer/raft_store.go b/signer/raft_store.go index 4cff36b3..d44b7af8 100644 --- a/signer/raft_store.go +++ b/signer/raft_store.go @@ -11,6 +11,7 @@ import ( "encoding/json" "fmt" "io" + "log/slog" "net" "net/url" "os" @@ -22,11 +23,10 @@ import ( "github.com/Jille/raft-grpc-leader-rpc/leaderhealth" raftgrpctransport "github.com/Jille/raft-grpc-transport" "github.com/Jille/raftadmin" - "github.com/cometbft/cometbft/libs/log" - "github.com/cometbft/cometbft/libs/service" "github.com/hashicorp/raft" boltdb "github.com/hashicorp/raft-boltdb/v2" - "github.com/strangelove-ventures/horcrux/v3/signer/proto" + grpccosigner "github.com/strangelove-ventures/horcrux/v3/grpc/cosigner" + "github.com/strangelove-ventures/horcrux/v3/types" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/reflection" @@ -46,8 +46,6 @@ type command struct { // Store is a simple key-value store, where all changes are made via Raft consensus. type RaftStore struct { - service.BaseService - NodeID string RaftDir string RaftBind string @@ -59,7 +57,7 @@ type RaftStore struct { raft *raft.Raft // The consensus mechanism - logger log.Logger + logger *slog.Logger cosigner *LocalCosigner thresholdValidator *ThresholdValidator } @@ -67,8 +65,8 @@ type RaftStore struct { // New returns a new Store. func NewRaftStore( nodeID string, directory string, bindAddress string, timeout time.Duration, - logger log.Logger, cosigner *LocalCosigner, cosigners []Cosigner) *RaftStore { - cosignerRaftStore := &RaftStore{ + logger *slog.Logger, cosigner *LocalCosigner, cosigners []Cosigner) *RaftStore { + return &RaftStore{ NodeID: nodeID, RaftDir: directory, RaftBind: bindAddress, @@ -78,49 +76,37 @@ func NewRaftStore( cosigner: cosigner, Cosigners: cosigners, } - - cosignerRaftStore.BaseService = *service.NewBaseService(logger, "CosignerRaftStore", cosignerRaftStore) - return cosignerRaftStore } func (s *RaftStore) SetThresholdValidator(thresholdValidator *ThresholdValidator) { s.thresholdValidator = thresholdValidator } -func (s *RaftStore) init() error { +// Start starts the raft server +func (s *RaftStore) Start() { host := p2pURLToRaftAddress(s.RaftBind) _, port, err := net.SplitHostPort(host) if err != nil { - return fmt.Errorf("failed to parse local address: %s, %v", host, err) + panic(fmt.Errorf("failed to parse local address: %s, %v", host, err)) } s.logger.Info("Local Raft Listening", "port", port) sock, err := net.Listen("tcp", fmt.Sprintf(":%s", port)) if err != nil { - return err + panic(err) } transportManager, err := s.Open() if err != nil { - return err + panic(err) } grpcServer := grpc.NewServer() - proto.RegisterCosignerServer(grpcServer, NewCosignerGRPCServer(s.cosigner, s.thresholdValidator, s)) + grpccosigner.RegisterCosignerServer(grpcServer, NewCosignerGRPCServer(s.cosigner, s.thresholdValidator, s)) transportManager.Register(grpcServer) leaderhealth.Setup(s.raft, grpcServer, []string{"Leader"}) raftadmin.Register(grpcServer, s.raft) reflection.Register(grpcServer) - return grpcServer.Serve(sock) -} - -// OnStart starts the raft server -func (s *RaftStore) OnStart() error { - go func() { - err := s.init() - if err != nil { - panic(err) - } - }() - - return nil + if err := grpcServer.Serve(sock); err != nil { + panic(err) + } } func p2pURLToRaftAddress(p2pURL string) string { @@ -306,7 +292,7 @@ func (s *RaftStore) GetLeader() int { return id } -func (s *RaftStore) ShareSigned(lss ChainSignStateConsensus) error { +func (s *RaftStore) ShareSigned(lss types.ChainSignStateConsensus) error { return s.Emit(raftEventLSS, lss) } @@ -316,7 +302,7 @@ type fsm RaftStore func (f *fsm) Apply(l *raft.Log) interface{} { var c command if err := json.Unmarshal(l.Data, &c); err != nil { - f.logger.Error("failed to unmarshal command", err.Error()) + f.logger.Error("failed to unmarshal command", "err", err) return nil } @@ -326,7 +312,7 @@ func (f *fsm) Apply(l *raft.Log) interface{} { case "delete": return f.applyDelete(c.Key) default: - f.logger.Error("unrecognized command op", c.Op) + f.logger.Error("unrecognized command", "op", c.Op) return nil } } @@ -380,7 +366,7 @@ func (f *fsm) applyDelete(key string) interface{} { type fsmSnapshot struct { store map[string]string - logger log.Logger + logger *slog.Logger } func (f *fsmSnapshot) Persist(sink raft.SnapshotSink) error { @@ -401,10 +387,10 @@ func (f *fsmSnapshot) Persist(sink raft.SnapshotSink) error { }() if err != nil { - f.logger.Error("Snapshot persist error", err.Error()) + f.logger.Error("Snapshot persist error", "err", err) sinkErr := sink.Cancel() if sinkErr != nil { - f.logger.Error("Error cancelling sink", sinkErr.Error()) + f.logger.Error("Error cancelling sink", "err", sinkErr) } } diff --git a/signer/raft_store_test.go b/signer/raft_store_test.go index 553417f2..eb56acaf 100644 --- a/signer/raft_store_test.go +++ b/signer/raft_store_test.go @@ -2,14 +2,14 @@ package signer import ( "crypto/rand" + "log/slog" "os" "testing" "time" - cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519" - "github.com/cometbft/cometbft/libs/log" "github.com/ethereum/go-ethereum/crypto/ecies" "github.com/ethereum/go-ethereum/crypto/secp256k1" + cometcryptoed25519 "github.com/strangelove-ventures/horcrux/v3/comet/crypto/ed25519" "github.com/stretchr/testify/require" ) @@ -31,7 +31,7 @@ func Test_StoreInMemOpenSingleNode(t *testing.T) { } cosigner := NewLocalCosigner( - log.NewNopLogger(), + slog.New(slog.NewTextHandler(os.Stdout, nil)), &RuntimeConfig{}, NewCosignerSecurityECIES( CosignerECIESKey{ diff --git a/signer/remote_cosigner.go b/signer/remote_cosigner.go index fe5b87f3..a83f88f5 100644 --- a/signer/remote_cosigner.go +++ b/signer/remote_cosigner.go @@ -6,9 +6,9 @@ import ( "net/url" "time" - cometcrypto "github.com/cometbft/cometbft/crypto" "github.com/google/uuid" - "github.com/strangelove-ventures/horcrux/v3/signer/proto" + cometcrypto "github.com/strangelove-ventures/horcrux/v3/comet/crypto" + grpccosigner "github.com/strangelove-ventures/horcrux/v3/grpc/cosigner" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" ) @@ -20,7 +20,7 @@ type RemoteCosigner struct { id int address string - client proto.CosignerClient + client grpccosigner.CosignerClient } // NewRemoteCosigner returns a newly initialized RemoteCosigner @@ -63,7 +63,7 @@ func (cosigner *RemoteCosigner) VerifySignature(_ string, _, _ []byte) bool { return false } -func getGRPCClient(address string) (proto.CosignerClient, error) { +func getGRPCClient(address string) (grpccosigner.CosignerClient, error) { var grpcAddress string url, err := url.Parse(address) if err != nil { @@ -75,7 +75,7 @@ func getGRPCClient(address string) (proto.CosignerClient, error) { if err != nil { return nil, err } - return proto.NewCosignerClient(conn), nil + return grpccosigner.NewCosignerClient(conn), nil } // Implements the cosigner interface @@ -88,7 +88,7 @@ func (cosigner *RemoteCosigner) GetNonces( us[i] = make([]byte, 16) copy(us[i], u[:]) } - res, err := cosigner.client.GetNonces(ctx, &proto.GetNoncesRequest{ + res, err := cosigner.client.GetNonces(ctx, &grpccosigner.GetNoncesRequest{ Uuids: us, }) if err != nil { @@ -108,11 +108,11 @@ func (cosigner *RemoteCosigner) GetNonces( func (cosigner *RemoteCosigner) SetNoncesAndSign( ctx context.Context, req CosignerSetNoncesAndSignRequest) (*CosignerSignResponse, error) { - res, err := cosigner.client.SetNoncesAndSign(ctx, &proto.SetNoncesAndSignRequest{ + res, err := cosigner.client.SetNoncesAndSign(ctx, &grpccosigner.SetNoncesAndSignRequest{ Uuid: req.Nonces.UUID[:], ChainID: req.ChainID, Nonces: req.Nonces.Nonces.toProto(), - Hrst: req.HRST.toProto(), + Hrst: req.HRST.ToProto(), SignBytes: req.SignBytes, }) if err != nil { @@ -129,7 +129,7 @@ func (cosigner *RemoteCosigner) Sign( ctx context.Context, req CosignerSignBlockRequest, ) (*CosignerSignBlockResponse, error) { - res, err := cosigner.client.SignBlock(ctx, &proto.SignBlockRequest{ + res, err := cosigner.client.SignBlock(ctx, &grpccosigner.SignBlockRequest{ ChainID: req.ChainID, Block: req.Block.ToProto(), }) diff --git a/signer/remote_signer.go b/signer/remote_signer.go index 744c7a77..6a07d7b1 100644 --- a/signer/remote_signer.go +++ b/signer/remote_signer.go @@ -3,18 +3,19 @@ package signer import ( "context" "fmt" + "log/slog" "net" "time" - cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519" - cometcryptoencoding "github.com/cometbft/cometbft/crypto/encoding" - cometlog "github.com/cometbft/cometbft/libs/log" - cometnet "github.com/cometbft/cometbft/libs/net" - cometservice "github.com/cometbft/cometbft/libs/service" - cometp2pconn "github.com/cometbft/cometbft/p2p/conn" - cometprotocrypto "github.com/cometbft/cometbft/proto/tendermint/crypto" - cometprotoprivval "github.com/cometbft/cometbft/proto/tendermint/privval" - cometproto "github.com/cometbft/cometbft/proto/tendermint/types" + cometcrypto "github.com/strangelove-ventures/horcrux/v3/comet/crypto" + cometcryptoed25519 "github.com/strangelove-ventures/horcrux/v3/comet/crypto/ed25519" + "github.com/strangelove-ventures/horcrux/v3/comet/encoding" + cometnet "github.com/strangelove-ventures/horcrux/v3/comet/libs/net" + cometp2pconn "github.com/strangelove-ventures/horcrux/v3/comet/p2p/conn" + cometprotocrypto "github.com/strangelove-ventures/horcrux/v3/comet/proto/crypto" + cometprotoprivval "github.com/strangelove-ventures/horcrux/v3/comet/proto/privval" + cometproto "github.com/strangelove-ventures/horcrux/v3/comet/proto/types" + "github.com/strangelove-ventures/horcrux/v3/types" ) const connRetrySec = 2 @@ -22,16 +23,15 @@ const connRetrySec = 2 // PrivValidator is a wrapper for tendermint PrivValidator, // with additional Stop method for safe shutdown. type PrivValidator interface { - Sign(ctx context.Context, chainID string, block Block) ([]byte, time.Time, error) - GetPubKey(ctx context.Context, chainID string) ([]byte, error) + Sign(ctx context.Context, chainID string, block types.Block) ([]byte, time.Time, error) + GetPubKey(ctx context.Context, chainID string) (cometcrypto.PubKey, error) Stop() } // ReconnRemoteSigner dials using its dialer and responds to any // signature requests using its privVal. type ReconnRemoteSigner struct { - cometservice.BaseService - + logger *slog.Logger address string privKey cometcryptoed25519.PrivKey privVal PrivValidator @@ -46,56 +46,24 @@ type ReconnRemoteSigner struct { // If the connection is broken, the ReconnRemoteSigner will attempt to reconnect. func NewReconnRemoteSigner( address string, - logger cometlog.Logger, + logger *slog.Logger, privVal PrivValidator, dialer net.Dialer, ) *ReconnRemoteSigner { - rs := &ReconnRemoteSigner{ + return &ReconnRemoteSigner{ + logger: logger, address: address, privVal: privVal, dialer: dialer, privKey: cometcryptoed25519.GenPrivKey(), } - - rs.BaseService = *cometservice.NewBaseService(logger, "RemoteSigner", rs) - return rs -} - -// OnStart implements cmn.Service. -func (rs *ReconnRemoteSigner) OnStart() error { - go rs.loop(context.Background()) - return nil -} - -// OnStop implements cmn.Service. -func (rs *ReconnRemoteSigner) OnStop() { - rs.privVal.Stop() -} - -func (rs *ReconnRemoteSigner) establishConnection(ctx context.Context) (net.Conn, error) { - ctx, cancel := context.WithTimeout(ctx, connRetrySec*time.Second) - defer cancel() - - proto, address := cometnet.ProtocolAndAddress(rs.address) - netConn, err := rs.dialer.DialContext(ctx, proto, address) - if err != nil { - return nil, fmt.Errorf("dial error: %w", err) - } - - conn, err := cometp2pconn.MakeSecretConnection(netConn, rs.privKey) - if err != nil { - netConn.Close() - return nil, fmt.Errorf("secret connection error: %w", err) - } - - return conn, nil } -// main loop for ReconnRemoteSigner -func (rs *ReconnRemoteSigner) loop(ctx context.Context) { +// Start starts the auto-reconnecting remote signer. +func (rs *ReconnRemoteSigner) Start(ctx context.Context) { var conn net.Conn for { - if !rs.IsRunning() { + if ctx.Err() != nil { rs.closeConn(conn) return } @@ -108,14 +76,14 @@ func (rs *ReconnRemoteSigner) loop(ctx context.Context) { if err == nil { sentryConnectTries.WithLabelValues(rs.address).Set(0) timer.Stop() - rs.Logger.Info("Connected to Sentry", "address", rs.address) + rs.logger.Info("Connected to Sentry", "address", rs.address) break } sentryConnectTries.WithLabelValues(rs.address).Add(1) totalSentryConnectTries.WithLabelValues(rs.address).Inc() retries++ - rs.Logger.Error( + rs.logger.Error( "Error establishing connection, will retry", "sleep (s)", connRetrySec, "address", rs.address, @@ -131,14 +99,14 @@ func (rs *ReconnRemoteSigner) loop(ctx context.Context) { } // since dialing can take time, we check running again - if !rs.IsRunning() { + if ctx.Err() != nil { rs.closeConn(conn) return } - req, err := ReadMsg(conn) + req, err := types.ReadMsg(conn) if err != nil { - rs.Logger.Error( + rs.logger.Error( "Failed to read message from connection", "address", rs.address, "err", err, @@ -151,9 +119,9 @@ func (rs *ReconnRemoteSigner) loop(ctx context.Context) { // handleRequest handles request errors. We always send back a response res := rs.handleRequest(req) - err = WriteMsg(conn, res) + err = types.WriteMsg(conn, res) if err != nil { - rs.Logger.Error( + rs.logger.Error( "Failed to write message to connection", "address", rs.address, "err", err, @@ -164,6 +132,25 @@ func (rs *ReconnRemoteSigner) loop(ctx context.Context) { } } +func (rs *ReconnRemoteSigner) establishConnection(ctx context.Context) (net.Conn, error) { + ctx, cancel := context.WithTimeout(ctx, connRetrySec*time.Second) + defer cancel() + + proto, address := cometnet.ProtocolAndAddress(rs.address) + netConn, err := rs.dialer.DialContext(ctx, proto, address) + if err != nil { + return nil, fmt.Errorf("dial error: %w", err) + } + + conn, err := cometp2pconn.MakeSecretConnection(netConn, rs.privKey) + if err != nil { + netConn.Close() + return nil, fmt.Errorf("secret connection error: %w", err) + } + + return conn, nil +} + func (rs *ReconnRemoteSigner) handleRequest(req cometprotoprivval.Message) cometprotoprivval.Message { switch typedReq := req.Sum.(type) { case *cometprotoprivval.Message_SignVoteRequest: @@ -175,7 +162,7 @@ func (rs *ReconnRemoteSigner) handleRequest(req cometprotoprivval.Message) comet case *cometprotoprivval.Message_PingRequest: return rs.handlePingRequest() default: - rs.Logger.Error("Unknown request", "err", fmt.Errorf("%v", typedReq)) + rs.logger.Error("Unknown request", "err", fmt.Errorf("%v", typedReq)) return cometprotoprivval.Message{} } } @@ -186,7 +173,13 @@ func (rs *ReconnRemoteSigner) handleSignVoteRequest(chainID string, vote *cometp Error: nil, }} - signature, timestamp, err := signAndTrack(context.TODO(), rs.Logger, rs.privVal, chainID, VoteToBlock(chainID, vote)) + signature, timestamp, err := signAndTrack( + context.TODO(), + rs.logger, + rs.privVal, + chainID, + types.VoteToBlock(chainID, vote), + ) if err != nil { msgSum.SignedVoteResponse.Error = getRemoteSignerError(err) return cometprotoprivval.Message{Sum: msgSum} @@ -210,10 +203,10 @@ func (rs *ReconnRemoteSigner) handleSignProposalRequest( signature, timestamp, err := signAndTrack( context.TODO(), - rs.Logger, + rs.logger, rs.privVal, chainID, - ProposalToBlock(chainID, proposal), + types.ProposalToBlock(chainID, proposal), ) if err != nil { msgSum.SignedProposalResponse.Error = getRemoteSignerError(err) @@ -234,7 +227,7 @@ func (rs *ReconnRemoteSigner) handlePubKeyRequest(chainID string) cometprotopriv pubKey, err := rs.privVal.GetPubKey(context.TODO(), chainID) if err != nil { - rs.Logger.Error( + rs.logger.Error( "Failed to get Pub Key", "chain_id", chainID, "node", rs.address, @@ -243,9 +236,9 @@ func (rs *ReconnRemoteSigner) handlePubKeyRequest(chainID string) cometprotopriv msgSum.PubKeyResponse.Error = getRemoteSignerError(err) return cometprotoprivval.Message{Sum: msgSum} } - pk, err := cometcryptoencoding.PubKeyToProto(cometcryptoed25519.PubKey(pubKey)) + pk, err := encoding.PubKeyToProto(pubKey) if err != nil { - rs.Logger.Error( + rs.logger.Error( "Failed to get Pub Key", "chain_id", chainID, "node", rs.address, @@ -276,37 +269,37 @@ func getRemoteSignerError(err error) *cometprotoprivval.RemoteSignerError { } } -func StartRemoteSigners( - services []cometservice.Service, - logger cometlog.Logger, - privVal PrivValidator, - nodes []string, -) ([]cometservice.Service, error) { - var err error - go StartMetrics() - for _, node := range nodes { - // CometBFT requires a connection within 3 seconds of start or crashes - // A long timeout such as 30 seconds would cause the sentry to fail in loops - // Use a short timeout and dial often to connect within 3 second window - dialer := net.Dialer{Timeout: 2 * time.Second} - s := NewReconnRemoteSigner(node, logger, privVal, dialer) - - err = s.Start() - if err != nil { - return nil, err - } - - services = append(services, s) - } - return services, err -} +// func StartRemoteSigners( +// services []cometservice.Service, +// logger *slog.Logger, +// privVal PrivValidator, +// nodes []string, +// ) ([]cometservice.Service, error) { +// var err error +// go StartMetrics() +// for _, node := range nodes { +// // CometBFT requires a connection within 3 seconds of start or crashes +// // A long timeout such as 30 seconds would cause the sentry to fail in loops +// // Use a short timeout and dial often to connect within 3 second window +// dialer := net.Dialer{Timeout: 2 * time.Second} +// s := NewReconnRemoteSigner(node, logger, privVal, dialer) + +// err = s.Start() +// if err != nil { +// return nil, err +// } + +// services = append(services, s) +// } +// return services, err +// } func (rs *ReconnRemoteSigner) closeConn(conn net.Conn) { if conn == nil { return } if err := conn.Close(); err != nil { - rs.Logger.Error("Failed to close connection to chain node", + rs.logger.Error("Failed to close connection to chain node", "address", rs.address, "err", err, ) diff --git a/signer/remote_signer_grpc_server.go b/signer/remote_signer_grpc_server.go index c66ec76d..188451f6 100644 --- a/signer/remote_signer_grpc_server.go +++ b/signer/remote_signer_grpc_server.go @@ -2,62 +2,63 @@ package signer import ( "context" + "log/slog" "net" "time" - cometlog "github.com/cometbft/cometbft/libs/log" - cometservice "github.com/cometbft/cometbft/libs/service" - - "github.com/strangelove-ventures/horcrux/v3/signer/proto" + grpccosigner "github.com/strangelove-ventures/horcrux/v3/grpc/cosigner" + grpchorcrux "github.com/strangelove-ventures/horcrux/v3/grpc/horcrux" + "github.com/strangelove-ventures/horcrux/v3/types" "google.golang.org/grpc" "google.golang.org/grpc/reflection" ) -var _ proto.RemoteSignerServer = &RemoteSignerGRPCServer{} +var _ grpchorcrux.RemoteSignerServer = &RemoteSignerGRPCServer{} type RemoteSignerGRPCServer struct { - cometservice.BaseService - validator PrivValidator - logger cometlog.Logger + logger *slog.Logger listenAddr string server *grpc.Server - proto.UnimplementedRemoteSignerServer + grpchorcrux.UnimplementedRemoteSignerServer } func NewRemoteSignerGRPCServer( - logger cometlog.Logger, + logger *slog.Logger, validator PrivValidator, listenAddr string, ) *RemoteSignerGRPCServer { - s := &RemoteSignerGRPCServer{ + return &RemoteSignerGRPCServer{ validator: validator, logger: logger, listenAddr: listenAddr, } - s.BaseService = *cometservice.NewBaseService(logger, "RemoteSignerGRPCServer", s) - return s } -func (s *RemoteSignerGRPCServer) OnStart() error { +func (s *RemoteSignerGRPCServer) Start() { s.logger.Info("Remote Signer GRPC Listening", "address", s.listenAddr) sock, err := net.Listen("tcp", s.listenAddr) if err != nil { - return err + panic(err) } s.server = grpc.NewServer() - proto.RegisterRemoteSignerServer(s.server, s) + grpchorcrux.RegisterRemoteSignerServer(s.server, s) reflection.Register(s.server) - return s.server.Serve(sock) + if err := s.server.Serve(sock); err != nil { + panic(err) + } } func (s *RemoteSignerGRPCServer) OnStop() { s.server.GracefulStop() } -func (s *RemoteSignerGRPCServer) PubKey(ctx context.Context, req *proto.PubKeyRequest) (*proto.PubKeyResponse, error) { +func (s *RemoteSignerGRPCServer) PubKey( + ctx context.Context, + req *grpchorcrux.PubKeyRequest, +) (*grpchorcrux.PubKeyResponse, error) { chainID := req.ChainId totalPubKeyRequests.WithLabelValues(chainID).Inc() @@ -72,23 +73,23 @@ func (s *RemoteSignerGRPCServer) PubKey(ctx context.Context, req *proto.PubKeyRe return nil, err } - return &proto.PubKeyResponse{ - PubKey: pubKey, + return &grpchorcrux.PubKeyResponse{ + PubKey: pubKey.Bytes(), }, nil } func (s *RemoteSignerGRPCServer) Sign( ctx context.Context, - req *proto.SignBlockRequest, -) (*proto.SignBlockResponse, error) { - chainID, block := req.ChainID, BlockFromProto(req.Block) + req *grpccosigner.SignBlockRequest, +) (*grpccosigner.SignBlockResponse, error) { + chainID, block := req.ChainID, types.BlockFromProto(req.Block) signature, timestamp, err := signAndTrack(ctx, s.logger, s.validator, chainID, block) if err != nil { return nil, err } - return &proto.SignBlockResponse{ + return &grpccosigner.SignBlockResponse{ Signature: signature, Timestamp: timestamp.UnixNano(), }, nil @@ -96,10 +97,10 @@ func (s *RemoteSignerGRPCServer) Sign( func signAndTrack( ctx context.Context, - logger cometlog.Logger, + logger *slog.Logger, validator PrivValidator, chainID string, - block Block, + block types.Block, ) ([]byte, time.Time, error) { signature, timestamp, err := validator.Sign(ctx, chainID, block) if err != nil { @@ -107,7 +108,7 @@ func signAndTrack( case *BeyondBlockError: logger.Debug( "Rejecting sign request", - "type", signType(block.Step), + "type", types.SignType(block.Step), "chain_id", chainID, "height", block.Height, "round", block.Round, @@ -117,7 +118,7 @@ func signAndTrack( default: logger.Error( "Failed to sign", - "type", signType(block.Step), + "type", types.SignType(block.Step), "chain_id", chainID, "height", block.Height, "round", block.Round, @@ -135,7 +136,7 @@ func signAndTrack( } logger.Info( "Signed", - "type", signType(block.Step), + "type", types.SignType(block.Step), "chain_id", chainID, "height", block.Height, "round", block.Round, @@ -144,11 +145,11 @@ func signAndTrack( ) switch block.Step { - case stepPropose: + case types.StepPropose: lastProposalHeight.WithLabelValues(chainID).Set(float64(block.Height)) lastProposalRound.WithLabelValues(chainID).Set(float64(block.Round)) totalProposalsSigned.WithLabelValues(chainID).Inc() - case stepPrevote: + case types.StepPrevote: // Determine number of heights since the last Prevote stepSize := block.Height - previousPrevoteHeight if previousPrevoteHeight != 0 && stepSize > 1 { @@ -165,7 +166,7 @@ func signAndTrack( lastPrevoteHeight.WithLabelValues(chainID).Set(float64(block.Height)) lastPrevoteRound.WithLabelValues(chainID).Set(float64(block.Round)) totalPrevotesSigned.WithLabelValues(chainID).Inc() - case stepPrecommit: + case types.StepPrecommit: stepSize := block.Height - previousPrecommitHeight if previousPrecommitHeight != 0 && stepSize > 1 { missedPrecommits.WithLabelValues(chainID).Add(float64(stepSize)) diff --git a/signer/serialization.go b/signer/serialization.go deleted file mode 100644 index ee6b5ab4..00000000 --- a/signer/serialization.go +++ /dev/null @@ -1,44 +0,0 @@ -package signer - -import ( - "errors" - "io" - - "github.com/cometbft/cometbft/libs/protoio" - cometprotoprivval "github.com/cometbft/cometbft/proto/tendermint/privval" - cometproto "github.com/cometbft/cometbft/proto/tendermint/types" -) - -// ReadMsg reads a message from an io.Reader -func ReadMsg(reader io.Reader) (msg cometprotoprivval.Message, err error) { - const maxRemoteSignerMsgSize = 1024 * 10 - protoReader := protoio.NewDelimitedReader(reader, maxRemoteSignerMsgSize) - _, err = protoReader.ReadMsg(&msg) - return msg, err -} - -// WriteMsg writes a message to an io.Writer -func WriteMsg(writer io.Writer, msg cometprotoprivval.Message) (err error) { - protoWriter := protoio.NewDelimitedWriter(writer) - _, err = protoWriter.WriteMsg(&msg) - return err -} - -// UnpackHRS deserializes sign bytes and gets the height, round, and step -func UnpackHRST(signBytes []byte) (HRSTKey, error) { - { - var proposal cometproto.CanonicalProposal - if err := protoio.UnmarshalDelimited(signBytes, &proposal); err == nil { - return HRSTKey{proposal.Height, proposal.Round, stepPropose, proposal.Timestamp.UnixNano()}, nil - } - } - - { - var vote cometproto.CanonicalVote - if err := protoio.UnmarshalDelimited(signBytes, &vote); err == nil { - return HRSTKey{vote.Height, vote.Round, CanonicalVoteToStep(&vote), vote.Timestamp.UnixNano()}, nil - } - } - - return HRSTKey{0, 0, 0, 0}, errors.New("could not UnpackHRS from sign bytes") -} diff --git a/signer/services.go b/signer/services.go index e6263f06..ccdac0e4 100644 --- a/signer/services.go +++ b/signer/services.go @@ -1,19 +1,18 @@ package signer import ( + "context" "errors" "fmt" + "log/slog" "os" + "os/signal" "strconv" "strings" "syscall" - - cometlog "github.com/cometbft/cometbft/libs/log" - cometos "github.com/cometbft/cometbft/libs/os" - cometservice "github.com/cometbft/cometbft/libs/service" ) -func RequireNotRunning(log cometlog.Logger, pidFilePath string) error { +func RequireNotRunning(log *slog.Logger, pidFilePath string) error { if _, err := os.Stat(pidFilePath); err != nil { if os.IsNotExist(err) { // lock file does not exist, can continue starting daemon @@ -74,7 +73,7 @@ func RequireNotRunning(log cometlog.Logger, pidFilePath string) error { return fmt.Errorf("unexpected error while signaling horcrux PID: %d", pid) } -func WaitAndTerminate(logger cometlog.Logger, services []cometservice.Service, pidFilePath string) { +func WaitAndTerminate(logger *slog.Logger, cancel context.CancelFunc, pidFilePath string) { done := make(chan struct{}) pidFile, err := os.OpenFile(pidFilePath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600) @@ -86,17 +85,29 @@ func WaitAndTerminate(logger cometlog.Logger, services []cometservice.Service, p if err != nil { panic(fmt.Errorf("error writing to lock file: %s. %w", pidFilePath, err)) } - cometos.TrapSignal(logger, func() { + + TrapSignal(logger, func() { if err := os.Remove(pidFilePath); err != nil { fmt.Printf("Error removing lock file: %v\n", err) } - for _, service := range services { - err := service.Stop() - if err != nil { - panic(err) - } - } + cancel() close(done) }) <-done } + +// TrapSignal catches the SIGTERM/SIGINT and executes cb function. After that it exits +// with code 0. +func TrapSignal(logger *slog.Logger, cb func()) { + c := make(chan os.Signal, 1) + signal.Notify(c, os.Interrupt, syscall.SIGTERM) + go func() { + for sig := range c { + logger.Info("signal trapped", "msg", fmt.Sprintf("captured %v, exiting...", sig)) + if cb != nil { + cb() + } + os.Exit(0) + } + }() +} diff --git a/signer/services_test.go b/signer/services_test.go index 48f35dae..d441dfd6 100644 --- a/signer/services_test.go +++ b/signer/services_test.go @@ -3,6 +3,7 @@ package signer_test import ( "errors" "fmt" + "log/slog" "os" "path/filepath" "strconv" @@ -12,8 +13,6 @@ import ( "testing" "time" - cometlog "github.com/cometbft/cometbft/libs/log" - cometservice "github.com/cometbft/cometbft/libs/service" "github.com/strangelove-ventures/horcrux/v3/signer" fork "github.com/kraken-hpc/go-fork" @@ -71,7 +70,7 @@ func TestIsRunning(t *testing.T) { pidBz, err := os.ReadFile(pidFilePath) require.NoError(t, err) - err = signer.RequireNotRunning(cometlog.NewNopLogger(), pidFilePath) + err = signer.RequireNotRunning(slog.New(slog.NewTextHandler(os.Stdout, nil)), pidFilePath) expectedErrorMsg := fmt.Sprintf("horcrux is already running on PID: %s", strings.TrimSpace(string(pidBz))) require.EqualError(t, err, expectedErrorMsg) } @@ -80,7 +79,7 @@ func TestIsNotRunning(t *testing.T) { homeDir := t.TempDir() pidFilePath := filepath.Join(homeDir, "horcrux.pid") - err := signer.RequireNotRunning(cometlog.NewNopLogger(), pidFilePath) + err := signer.RequireNotRunning(slog.New(slog.NewTextHandler(os.Stdout, nil)), pidFilePath) require.NoError(t, err) } @@ -129,7 +128,7 @@ func TestIsRunningNonExistentPid(t *testing.T) { ) require.NoError(t, err, "error writing pid file") - err = signer.RequireNotRunning(cometlog.NewNopLogger(), pidFilePath) + err = signer.RequireNotRunning(slog.New(slog.NewTextHandler(os.Stdout, nil)), pidFilePath) require.Nil(t, err) _, err = os.Stat(pidFilePath) @@ -142,8 +141,7 @@ func TestConcurrentStart(t *testing.T) { homeDir := t.TempDir() pidFilePath := filepath.Join(homeDir, "horcrux.pid") - var logger cometlog.Logger - var services []cometservice.Service + var logger *slog.Logger var wg sync.WaitGroup wg.Add(concurrentAttempts) @@ -167,7 +165,7 @@ func TestConcurrentStart(t *testing.T) { for i := 0; i < concurrentAttempts; i++ { go func() { defer recoverFromPanic() - signer.WaitAndTerminate(logger, services, pidFilePath) + signer.WaitAndTerminate(logger, func() {}, pidFilePath) doneCount++ wg.Done() }() @@ -184,9 +182,8 @@ func TestIsRunningAndWaitForService(t *testing.T) { homeDir := t.TempDir() pidFilePath := filepath.Join(homeDir, "horcrux.pid") - var logger cometlog.Logger - var services []cometservice.Service - go func() { signer.WaitAndTerminate(logger, services, pidFilePath) }() + var logger = slog.New(slog.NewTextHandler(os.Stdout, nil)) + go func() { signer.WaitAndTerminate(logger, func() {}, pidFilePath) }() // Wait for signer.WaitAndTerminate to create pidFile var err error @@ -211,7 +208,7 @@ func TestIsRunningAndWaitForService(t *testing.T) { } panicFunction := func() { defer recoverFromPanic() - err = signer.RequireNotRunning(cometlog.NewNopLogger(), pidFilePath) + err = signer.RequireNotRunning(slog.New(slog.NewTextHandler(os.Stdout, nil)), pidFilePath) } go panicFunction() wg.Wait() diff --git a/signer/single_signer_validator.go b/signer/single_signer_validator.go index 8c2ee22a..447e44ea 100644 --- a/signer/single_signer_validator.go +++ b/signer/single_signer_validator.go @@ -8,7 +8,9 @@ import ( "time" // required to register bn254 types for signing - _ "github.com/strangelove-ventures/horcrux/v3/signer/bn254" + cometcrypto "github.com/strangelove-ventures/horcrux/v3/comet/crypto" + "github.com/strangelove-ventures/horcrux/v3/comet/privval" + "github.com/strangelove-ventures/horcrux/v3/types" ) var _ PrivValidator = &SingleSignerValidator{} @@ -22,7 +24,7 @@ type SingleSignerValidator struct { // SingleSignerChainState holds the priv validator and associated mutex for a single chain. type SingleSignerChainState struct { - filePV *FilePV + filePV *privval.FilePV // The filePV does not have any locking internally for signing operations. // The high-watermark/last-signed-state within the FilePV prevents double sign @@ -39,7 +41,7 @@ func NewSingleSignerValidator(config *RuntimeConfig) *SingleSignerValidator { } // GetPubKey implements types.PrivValidator -func (pv *SingleSignerValidator) GetPubKey(_ context.Context, chainID string) ([]byte, error) { +func (pv *SingleSignerValidator) GetPubKey(_ context.Context, chainID string) (cometcrypto.PubKey, error) { chainState, err := pv.loadChainStateIfNecessary(chainID) if err != nil { return nil, err @@ -48,11 +50,11 @@ func (pv *SingleSignerValidator) GetPubKey(_ context.Context, chainID string) ([ if err != nil { return nil, err } - return pubKey.Bytes(), nil + return pubKey, nil } // SignVote implements types.PrivValidator -func (pv *SingleSignerValidator) Sign(_ context.Context, chainID string, block Block) ([]byte, time.Time, error) { +func (pv *SingleSignerValidator) Sign(_ context.Context, chainID string, block types.Block) ([]byte, time.Time, error) { chainState, err := pv.loadChainStateIfNecessary(chainID) if err != nil { return nil, block.Timestamp, err @@ -75,19 +77,19 @@ func (pv *SingleSignerValidator) loadChainStateIfNecessary(chainID string) (*Sin } stateFile := pv.config.PrivValStateFile(chainID) - var filePV *FilePV + var filePV *privval.FilePV if _, err := os.Stat(stateFile); err != nil { if !os.IsNotExist(err) { panic(fmt.Errorf("failed to load state file (%s) - %w", stateFile, err)) } // The only scenario in which we want to create a new state file // on disk is when the state file does not exist. - filePV, err = LoadFilePV(keyFile, stateFile, false) + filePV, err = privval.LoadFilePV(keyFile, stateFile, false) if err != nil { return nil, err } } else { - filePV, err = LoadFilePV(keyFile, stateFile, true) + filePV, err = privval.LoadFilePV(keyFile, stateFile, true) if err != nil { return nil, err } diff --git a/signer/single_signer_validator_test.go b/signer/single_signer_validator_test.go index 4e23c3a1..eeb83da3 100644 --- a/signer/single_signer_validator_test.go +++ b/signer/single_signer_validator_test.go @@ -2,18 +2,18 @@ package signer import ( "context" + "crypto/rand" "path/filepath" "time" "os" "testing" - cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519" - "github.com/cometbft/cometbft/crypto/tmhash" - cometjson "github.com/cometbft/cometbft/libs/json" - cometrand "github.com/cometbft/cometbft/libs/rand" - cometprivval "github.com/cometbft/cometbft/privval" - cometproto "github.com/cometbft/cometbft/proto/tendermint/types" + cometcryptoed25519 "github.com/strangelove-ventures/horcrux/v3/comet/crypto/ed25519" + cometjson "github.com/strangelove-ventures/horcrux/v3/comet/libs/json" + cometprivval "github.com/strangelove-ventures/horcrux/v3/comet/privval" + cometproto "github.com/strangelove-ventures/horcrux/v3/comet/proto/types" + "github.com/strangelove-ventures/horcrux/v3/types" "github.com/stretchr/testify/require" ) @@ -54,7 +54,7 @@ func TestSingleSignerValidator(t *testing.T) { Type: cometproto.ProposalType, } - block := ProposalToBlock(testChainID, &proposal) + block := types.ProposalToBlock(testChainID, &proposal) ctx := context.Background() @@ -66,11 +66,14 @@ func TestSingleSignerValidator(t *testing.T) { proposal.Timestamp = time.Now() // should be able to sign same proposal with only differing timestamp - _, _, err = validator.Sign(ctx, testChainID, ProposalToBlock(testChainID, &proposal)) + _, _, err = validator.Sign(ctx, testChainID, types.ProposalToBlock(testChainID, &proposal)) require.NoError(t, err) // construct different block ID for proposal at same height as highest signed - randHash := cometrand.Bytes(tmhash.Size) + randHash := make([]byte, 32) + _, err = rand.Read(randHash) + require.NoError(t, err) + blockID := cometproto.BlockID{Hash: randHash, PartSetHeader: cometproto.PartSetHeader{Total: 5, Hash: randHash}} @@ -82,28 +85,28 @@ func TestSingleSignerValidator(t *testing.T) { } // should not be able to sign same proposal at same height as highest signed with different BlockID - _, _, err = validator.Sign(ctx, testChainID, ProposalToBlock(testChainID, &proposal)) + _, _, err = validator.Sign(ctx, testChainID, types.ProposalToBlock(testChainID, &proposal)) require.Error(t, err, "double sign!") proposal.Round = 19 // should not be able to sign lower than highest signed - _, _, err = validator.Sign(ctx, testChainID, ProposalToBlock(testChainID, &proposal)) + _, _, err = validator.Sign(ctx, testChainID, types.ProposalToBlock(testChainID, &proposal)) require.Error(t, err, "double sign!") // lower LSS should sign for different chain ID - _, _, err = validator.Sign(ctx, "different", ProposalToBlock("different", &proposal)) + _, _, err = validator.Sign(ctx, "different", types.ProposalToBlock("different", &proposal)) require.NoError(t, err) // reinitialize validator to make sure new runtime will not allow double sign validator = NewSingleSignerValidator(runtimeConfig) - _, _, err = validator.Sign(ctx, testChainID, ProposalToBlock(testChainID, &proposal)) + _, _, err = validator.Sign(ctx, testChainID, types.ProposalToBlock(testChainID, &proposal)) require.Error(t, err, "double sign!") proposal.Round = 21 // signing higher block now should succeed - _, _, err = validator.Sign(ctx, testChainID, ProposalToBlock(testChainID, &proposal)) + _, _, err = validator.Sign(ctx, testChainID, types.ProposalToBlock(testChainID, &proposal)) require.NoError(t, err) } diff --git a/signer/threshold_signer_soft_bn254.go b/signer/threshold_signer_soft_bn254.go index b51193ed..02b8bd79 100644 --- a/signer/threshold_signer_soft_bn254.go +++ b/signer/threshold_signer_soft_bn254.go @@ -4,7 +4,8 @@ import ( "math/big" "github.com/consensys/gnark-crypto/ecc/bn254" - horcrux_bn254 "github.com/strangelove-ventures/horcrux/v3/signer/bn254" + cometcryptobn254 "github.com/strangelove-ventures/horcrux/v3/comet/crypto/bn254" + horcruxbn254 "github.com/strangelove-ventures/horcrux/v3/signer/bn254" ) var _ ThresholdSigner = &ThresholdSignerSoftBn254{} @@ -32,7 +33,7 @@ func (s *ThresholdSignerSoftBn254) PubKey() []byte { } func (s *ThresholdSignerSoftBn254) Sign(_ []Nonce, msg []byte) ([]byte, error) { - sig, err := horcrux_bn254.SignWithShard(s.privateKey, msg) + sig, err := horcruxbn254.SignWithShard(s.privateKey, msg) if err != nil { return nil, err } @@ -56,7 +57,7 @@ func (s *ThresholdSignerSoftBn254) CombineSignatures(signatures []PartialSignatu points[i] = int64(s.ID) } - combinedSig := horcrux_bn254.CombineSignatures(sigs, points...) + combinedSig := horcruxbn254.CombineSignatures(sigs, points...) compressed := combinedSig.Bytes() @@ -64,5 +65,5 @@ func (s *ThresholdSignerSoftBn254) CombineSignatures(signatures []PartialSignatu } func (s *ThresholdSignerSoftBn254) VerifySignature(msg, signature []byte) bool { - return horcrux_bn254.PubKey(s.pubKey).VerifySignature(msg, signature) + return cometcryptobn254.PubKey(s.pubKey).VerifySignature(msg, signature) } diff --git a/signer/threshold_signer_soft_ed25519.go b/signer/threshold_signer_soft_ed25519.go index b185063d..aae08a94 100644 --- a/signer/threshold_signer_soft_ed25519.go +++ b/signer/threshold_signer_soft_ed25519.go @@ -6,7 +6,7 @@ import ( "errors" "fmt" - cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519" + cometcryptoed25519 "github.com/strangelove-ventures/horcrux/v3/comet/crypto/ed25519" "gitlab.com/unit410/edwards25519" tsed25519 "gitlab.com/unit410/threshold-ed25519/pkg" ) diff --git a/signer/threshold_validator.go b/signer/threshold_validator.go index e99b75df..37cfe99d 100644 --- a/signer/threshold_validator.go +++ b/signer/threshold_validator.go @@ -5,15 +5,14 @@ import ( "context" "errors" "fmt" - "os" + "log/slog" "strings" "sync" "time" - "github.com/cometbft/cometbft/libs/log" - cometrpcjsontypes "github.com/cometbft/cometbft/rpc/jsonrpc/types" "github.com/google/uuid" - "github.com/strangelove-ventures/horcrux/v3/signer/proto" + cometcrypto "github.com/strangelove-ventures/horcrux/v3/comet/crypto" + "github.com/strangelove-ventures/horcrux/v3/types" "golang.org/x/sync/errgroup" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -38,7 +37,7 @@ type ThresholdValidator struct { leader Leader - logger log.Logger + logger *slog.Logger pendingDiskWG sync.WaitGroup @@ -52,17 +51,17 @@ type ThresholdValidator struct { type ChainSignState struct { // stores the last sign state for a block we have fully signed // Cached to respond to SignVote requests if we already have a signature - lastSignState *SignState + lastSignState *types.SignState lastSignStateMutex *sync.Mutex // stores the last sign state that we've started progress on - lastSignStateInitiated *SignState + lastSignStateInitiated *types.SignState lastSignStateInitiatedMutex *sync.Mutex } // NewThresholdValidator creates and returns a new ThresholdValidator func NewThresholdValidator( - logger log.Logger, + logger *slog.Logger, config *RuntimeConfig, threshold int, grpcTimeout time.Duration, @@ -104,7 +103,7 @@ func NewThresholdValidator( } // Start starts the ThresholdValidator. -func (pv *ThresholdValidator) Start(ctx context.Context) error { +func (pv *ThresholdValidator) Start(ctx context.Context) { pv.logger.Info("Starting ThresholdValidator services") go pv.cosignerHealth.Start(ctx) @@ -112,15 +111,13 @@ func (pv *ThresholdValidator) Start(ctx context.Context) error { go pv.nonceCache.Start(ctx) go pv.myCosigner.StartNoncePruner(ctx) - - return nil } // SaveLastSignedState updates the high watermark height/round/step (HRS) for a completed // sign process if it is greater than the current high watermark. A mutex is used to avoid concurrent // state updates. The disk write is scheduled in a separate goroutine which will perform an atomic write. // pendingDiskWG is used upon termination in pendingDiskWG to ensure all writes have completed. -func (pv *ThresholdValidator) SaveLastSignedState(chainID string, signState SignStateConsensus) error { +func (pv *ThresholdValidator) SaveLastSignedState(chainID string, signState types.SignStateConsensus) error { css := pv.mustLoadChainState(chainID) css.lastSignStateMutex.Lock() @@ -146,12 +143,15 @@ func (pv *ThresholdValidator) mustLoadChainState(chainID string) ChainSignState // sign process if it is greater than the current high watermark. A mutex is used to avoid concurrent // state updates. The disk write is scheduled in a separate goroutine which will perform an atomic write. // pendingDiskWG is used upon termination in pendingDiskWG to ensure all writes have completed. -func (pv *ThresholdValidator) SaveLastSignedStateInitiated(chainID string, block *Block) ([]byte, time.Time, error) { +func (pv *ThresholdValidator) SaveLastSignedStateInitiated( + chainID string, + block *types.Block, +) ([]byte, time.Time, error) { css := pv.mustLoadChainState(chainID) height, round, step := block.Height, block.Round, block.Step - err := css.lastSignStateInitiated.Save(NewSignStateConsensus(height, round, step), &pv.pendingDiskWG) + err := css.lastSignStateInitiated.Save(types.NewSignStateConsensus(height, round, step), &pv.pendingDiskWG) if err == nil { // good to sign return nil, time.Time{}, nil @@ -160,7 +160,7 @@ func (pv *ThresholdValidator) SaveLastSignedStateInitiated(chainID string, block // There was an error saving the last sign state, so check if there is an existing signature for this block. existingSignature, existingTimestamp, sameBlockErr := pv.getExistingBlockSignature(chainID, block) - if _, ok := err.(*SameHRSError); !ok { + if _, ok := err.(*types.SameHRSError); !ok { if sameBlockErr == nil { return existingSignature, block.Timestamp, nil } @@ -190,14 +190,14 @@ func (pv *ThresholdValidator) SaveLastSignedStateInitiated(chainID string, block // intended usage of cond lock prior to cond.Wait(). // cond.Wait() will unlock cond.L while it blocks waiting, then re-lock when unblocking from // the cond.Broadcast(). - css.lastSignState.cond.L.Lock() - defer css.lastSignState.cond.L.Unlock() + css.lastSignState.CondLock() + defer css.lastSignState.CondUnlock() for i := 0; i < pv.maxWaitForSameBlockAttempts; i++ { // block until sign state is saved. It will notify and unblock when block is next signed. - css.lastSignState.cond.WaitWithTimeout(pv.grpcTimeout) + css.lastSignState.CondWaitWithTimeout(pv.grpcTimeout) // check if HRS exists in cache now - ssc, ok := css.lastSignState.cache[block.HRSKey()] + ssc, ok := css.lastSignState.Cached(block.HRSKey()) if !ok { pv.logger.Debug( "Block does not yet exist in cache while waiting for signature", @@ -240,19 +240,19 @@ func (pv *ThresholdValidator) SaveLastSignedStateInitiated(chainID string, block // notifyBlockSignError will alert any waiting goroutines that an error // has occurred during signing and a retry can be attempted. -func (pv *ThresholdValidator) notifyBlockSignError(chainID string, hrs HRSKey, signBytes []byte) { +func (pv *ThresholdValidator) notifyBlockSignError(chainID string, hrs types.HRSKey, signBytes []byte) { css := pv.mustLoadChainState(chainID) - css.lastSignState.mu.Lock() - css.lastSignState.cache[hrs] = SignStateConsensus{ + css.lastSignState.CondLock() + css.lastSignState.Cache(hrs, types.SignStateConsensus{ Height: hrs.Height, Round: hrs.Round, Step: hrs.Step, // empty signature to indicate error SignBytes: signBytes, - } - css.lastSignState.mu.Unlock() - css.lastSignState.cond.Broadcast() + }) + css.lastSignState.CondUnlock() + css.lastSignState.CondBroadcast() } // Stop safely shuts down the ThresholdValidator. @@ -269,57 +269,12 @@ func (pv *ThresholdValidator) waitForSignStatesToFlushToDisk() { // GetPubKey returns the public key of the validator. // Implements PrivValidator. -func (pv *ThresholdValidator) GetPubKey(_ context.Context, chainID string) ([]byte, error) { +func (pv *ThresholdValidator) GetPubKey(_ context.Context, chainID string) (cometcrypto.PubKey, error) { pubKey, err := pv.myCosigner.GetPubKey(chainID) if err != nil { return nil, err } - return pubKey.Bytes(), nil -} - -type Block struct { - Height int64 - Round int64 - Step int8 - SignBytes []byte - Timestamp time.Time -} - -func (block Block) HRSKey() HRSKey { - return HRSKey{ - Height: block.Height, - Round: block.Round, - Step: block.Step, - } -} - -func (block Block) HRSTKey() HRSTKey { - return HRSTKey{ - Height: block.Height, - Round: block.Round, - Step: block.Step, - Timestamp: block.Timestamp.UnixNano(), - } -} - -func (block Block) ToProto() *proto.Block { - return &proto.Block{ - Height: block.Height, - Round: block.Round, - Step: int32(block.Step), - SignBytes: block.SignBytes, - Timestamp: block.Timestamp.UnixNano(), - } -} - -func BlockFromProto(block *proto.Block) Block { - return Block{ - Height: block.Height, - Round: block.Round, - Step: int8(block.Step), - SignBytes: block.SignBytes, - Timestamp: time.Unix(0, block.Timestamp), - } + return pubKey, nil } type BeyondBlockError struct { @@ -328,13 +283,16 @@ type BeyondBlockError struct { func (e *BeyondBlockError) Error() string { return e.msg } -func (pv *ThresholdValidator) newBeyondBlockError(chainID string, hrs HRSKey) *BeyondBlockError { +const msgProgressAlreadyStarted = "Progress already started on block" + +func (pv *ThresholdValidator) newBeyondBlockError(chainID string, hrs types.HRSKey) *BeyondBlockError { css := pv.mustLoadChainState(chainID) lss := css.lastSignStateInitiated return &BeyondBlockError{ - msg: fmt.Sprintf("[%s] Progress already started on block %d.%d.%d, skipping %d.%d.%d", + msg: fmt.Sprintf("[%s] %s %d.%d.%d, skipping %d.%d.%d", chainID, + msgProgressAlreadyStarted, lss.Height, lss.Round, lss.Step, hrs.Height, hrs.Round, hrs.Step, ), @@ -347,7 +305,7 @@ type StillWaitingForBlockError struct { func (e *StillWaitingForBlockError) Error() string { return e.msg } -func newStillWaitingForBlockError(chainID string, hrs HRSKey) *StillWaitingForBlockError { +func newStillWaitingForBlockError(chainID string, hrs types.HRSKey) *StillWaitingForBlockError { return &StillWaitingForBlockError{ msg: fmt.Sprintf("[%s] Still waiting for block %d.%d.%d", chainID, hrs.Height, hrs.Round, hrs.Step), @@ -360,7 +318,7 @@ type SameBlockError struct { func (e *SameBlockError) Error() string { return e.msg } -func newSameBlockError(chainID string, hrs HRSKey) *SameBlockError { +func newSameBlockError(chainID string, hrs types.HRSKey) *SameBlockError { return &SameBlockError{ msg: fmt.Sprintf("[%s] Same block: %d.%d.%d", chainID, hrs.Height, hrs.Round, hrs.Step), @@ -372,13 +330,13 @@ func (pv *ThresholdValidator) LoadSignStateIfNecessary(chainID string) error { return nil } - signState, err := LoadOrCreateSignState(pv.config.PrivValStateFile(chainID)) + signState, err := types.LoadOrCreateSignState(pv.config.PrivValStateFile(chainID)) if err != nil { return err } lastSignStateInitiated := signState.FreshCache() - lastSignStateInitiated.filePath = os.DevNull + lastSignStateInitiated.ClearFile() pv.chainState.Store(chainID, ChainSignState{ lastSignState: signState, @@ -394,7 +352,7 @@ func (pv *ThresholdValidator) LoadSignStateIfNecessary(chainID string) error { // getExistingBlockSignature returns the existing block signature and no error if the signature is valid for the block. // It returns nil signature and nil error if there is no signature and it's okay to sign (fresh or again). // It returns an error if we have already signed a greater block, or if we are still waiting for in in-progress sign. -func (pv *ThresholdValidator) getExistingBlockSignature(chainID string, block *Block) ([]byte, time.Time, error) { +func (pv *ThresholdValidator) getExistingBlockSignature(chainID string, block *types.Block) ([]byte, time.Time, error) { css := pv.mustLoadChainState(chainID) latestBlock, existingSignature := css.lastSignState.GetFromCache(block.HRSKey()) @@ -419,8 +377,8 @@ func (pv *ThresholdValidator) getExistingBlockSignature(chainID string, block *B // if the block sign request is for a proposal or if the bytes to sign are identical. func (pv *ThresholdValidator) compareBlockSignatureAgainstSSC( chainID string, - block *Block, - existingSignature *SignStateConsensus, + block *types.Block, + existingSignature *types.SignStateConsensus, ) ([]byte, time.Time, error) { stamp, signBytes := block.Timestamp, block.SignBytes @@ -431,7 +389,7 @@ func (pv *ThresholdValidator) compareBlockSignatureAgainstSSC( } // If a proposal has already been signed for this HRS, or the sign payload is identical, return the existing signature. - if block.Step == stepPropose || bytes.Equal(signBytes, existingSignature.SignBytes) { + if block.Step == types.StepPropose || bytes.Equal(signBytes, existingSignature.SignBytes) { return existingSignature.Signature, block.Timestamp, nil } @@ -449,8 +407,8 @@ func (pv *ThresholdValidator) compareBlockSignatureAgainstSSC( // equal to the block. func (pv *ThresholdValidator) compareBlockSignatureAgainstHRS( chainID string, - block *Block, - hrs HRSKey, + block *types.Block, + hrs types.HRSKey, ) error { blockHRS := block.HRSKey() @@ -557,7 +515,7 @@ func (pv *ThresholdValidator) waitForPeerNonces( func (pv *ThresholdValidator) proxyIfNecessary( ctx context.Context, chainID string, - block Block, + block types.Block, ) (bool, []byte, time.Time, error) { height, round, step, stamp := block.Height, block.Round, block.Step, block.Timestamp @@ -600,26 +558,23 @@ func (pv *ThresholdValidator) proxyIfNecessary( Block: &block, }) if err != nil { - if _, ok := err.(*cometrpcjsontypes.RPCError); ok { - rpcErrUnwrapped := err.(*cometrpcjsontypes.RPCError).Data - // Need to return BeyondBlockError after proxy since the error type will be lost over RPC - if len(rpcErrUnwrapped) > 33 && rpcErrUnwrapped[:33] == "Progress already started on block" { - return true, nil, stamp, &BeyondBlockError{msg: rpcErrUnwrapped} - } + errStr := err.Error() + if strings.Contains(errStr, msgProgressAlreadyStarted) { + return true, nil, stamp, &BeyondBlockError{msg: errStr} } return true, nil, stamp, err } return true, signRes.Signature, stamp, nil } -func (pv *ThresholdValidator) Sign(ctx context.Context, chainID string, block Block) ([]byte, time.Time, error) { +func (pv *ThresholdValidator) Sign(ctx context.Context, chainID string, block types.Block) ([]byte, time.Time, error) { height, round, step, stamp, signBytes := block.Height, block.Round, block.Step, block.Timestamp, block.SignBytes log := pv.logger.With( "chain_id", chainID, "height", height, "round", round, - "type", signType(step), + "type", types.SignType(step), ) if err := pv.LoadSignStateIfNecessary(chainID); err != nil { @@ -639,7 +594,7 @@ func (pv *ThresholdValidator) Sign(ctx context.Context, chainID string, block Bl timeStartSignBlock := time.Now() - hrst := HRSTKey{ + hrst := types.HRSTKey{ Height: height, Round: round, Step: step, @@ -816,9 +771,9 @@ func (pv *ThresholdValidator) Sign(ctx context.Context, chainID string, block Bl return nil, stamp, errors.New("combined signature is not valid") } - newLss := ChainSignStateConsensus{ + newLss := types.ChainSignStateConsensus{ ChainID: chainID, - SignStateConsensus: SignStateConsensus{ + SignStateConsensus: types.SignStateConsensus{ Height: height, Round: round, Step: step, @@ -834,7 +789,7 @@ func (pv *ThresholdValidator) Sign(ctx context.Context, chainID string, block Bl err = css.lastSignState.Save(newLss.SignStateConsensus, &pv.pendingDiskWG) css.lastSignStateMutex.Unlock() if err != nil { - if _, isSameHRSError := err.(*SameHRSError); !isSameHRSError { + if _, isSameHRSError := err.(*types.SameHRSError); !isSameHRSError { pv.notifyBlockSignError(chainID, block.HRSKey(), signBytes) return nil, stamp, fmt.Errorf("error saving last sign state: %w", err) @@ -846,7 +801,7 @@ func (pv *ThresholdValidator) Sign(ctx context.Context, chainID string, block Bl if err != nil { // this is not required for double sign protection, so we don't need to return an error here. // this is only an additional mechanism that will catch double signs earlier in the sign process. - log.Error("Error emitting LSS", err.Error()) + log.Error("Error emitting LSS", "err", err) } timeSignBlock := time.Since(timeStartSignBlock) diff --git a/signer/threshold_validator_test.go b/signer/threshold_validator_test.go index 4546b9d4..b4436651 100644 --- a/signer/threshold_validator_test.go +++ b/signer/threshold_validator_test.go @@ -6,6 +6,7 @@ import ( "crypto/rand" "encoding/json" "fmt" + "log/slog" mrand "math/rand" "path/filepath" "sync" @@ -14,15 +15,14 @@ import ( "os" "testing" - cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519" - "github.com/cometbft/cometbft/crypto/tmhash" - cometlog "github.com/cometbft/cometbft/libs/log" - cometrand "github.com/cometbft/cometbft/libs/rand" - cometproto "github.com/cometbft/cometbft/proto/tendermint/types" - comet "github.com/cometbft/cometbft/types" "github.com/ethereum/go-ethereum/crypto/ecies" "github.com/ethereum/go-ethereum/crypto/secp256k1" - horcrux_bn254 "github.com/strangelove-ventures/horcrux/v3/signer/bn254" + cometcryptobn254 "github.com/strangelove-ventures/horcrux/v3/comet/crypto/bn254" + cometcryptoed25519 "github.com/strangelove-ventures/horcrux/v3/comet/crypto/ed25519" + cometproto "github.com/strangelove-ventures/horcrux/v3/comet/proto/types" + comet "github.com/strangelove-ventures/horcrux/v3/comet/types" + horcruxbn254 "github.com/strangelove-ventures/horcrux/v3/signer/bn254" + "github.com/strangelove-ventures/horcrux/v3/types" "github.com/stretchr/testify/require" tsed25519 "gitlab.com/unit410/threshold-ed25519/pkg" "golang.org/x/sync/errgroup" @@ -98,7 +98,7 @@ func testThresholdValidator(t *testing.T, keyType string, threshold, total uint8 leader := &MockLeader{id: 1} validator := NewThresholdValidator( - cometlog.NewNopLogger(), + slog.New(slog.NewTextHandler(os.Stdout, nil)), cosigners[0].config, int(threshold), time.Second, @@ -122,7 +122,7 @@ func testThresholdValidator(t *testing.T, keyType string, threshold, total uint8 Type: cometproto.ProposalType, } - block := ProposalToBlock(testChainID, &proposal) + block := types.ProposalToBlock(testChainID, &proposal) signature, _, err := validator.Sign(ctx, testChainID, block) require.NoError(t, err) @@ -140,7 +140,7 @@ func testThresholdValidator(t *testing.T, keyType string, threshold, total uint8 Timestamp: time.Now(), } - block = ProposalToBlock(testChainID, &proposal) + block = types.ProposalToBlock(testChainID, &proposal) validator.nonceCache.LoadN(ctx, 1) @@ -149,7 +149,11 @@ func testThresholdValidator(t *testing.T, keyType string, threshold, total uint8 require.NoError(t, err) // construct different block ID for proposal at same height as highest signed - randHash := cometrand.Bytes(tmhash.Size) + + randHash := make([]byte, 32) + _, err = rand.Read(randHash) + require.NoError(t, err) + blockID := cometproto.BlockID{Hash: randHash, PartSetHeader: cometproto.PartSetHeader{Total: 5, Hash: randHash}} @@ -164,7 +168,7 @@ func testThresholdValidator(t *testing.T, keyType string, threshold, total uint8 // different than single-signer mode, threshold mode will be successful for this, // but it will return the same signature as before. - signature, _, err = validator.Sign(ctx, testChainID, ProposalToBlock(testChainID, &proposal)) + signature, _, err = validator.Sign(ctx, testChainID, types.ProposalToBlock(testChainID, &proposal)) require.NoError(t, err) require.True(t, bytes.Equal(firstSignature, signature)) @@ -174,18 +178,18 @@ func testThresholdValidator(t *testing.T, keyType string, threshold, total uint8 validator.nonceCache.LoadN(ctx, 1) // should not be able to sign lower than highest signed - _, _, err = validator.Sign(ctx, testChainID, ProposalToBlock(testChainID, &proposal)) + _, _, err = validator.Sign(ctx, testChainID, types.ProposalToBlock(testChainID, &proposal)) require.Error(t, err, "double sign!") validator.nonceCache.LoadN(ctx, 1) // lower LSS should sign for different chain ID - _, _, err = validator.Sign(ctx, testChainID2, ProposalToBlock(testChainID2, &proposal)) + _, _, err = validator.Sign(ctx, testChainID2, types.ProposalToBlock(testChainID2, &proposal)) require.NoError(t, err) // reinitialize validator to make sure new runtime will not allow double sign newValidator := NewThresholdValidator( - cometlog.NewNopLogger(), + slog.New(slog.NewTextHandler(os.Stdout, nil)), cosigners[0].config, int(threshold), time.Second, @@ -198,7 +202,7 @@ func testThresholdValidator(t *testing.T, keyType string, threshold, total uint8 newValidator.nonceCache.LoadN(ctx, 1) - _, _, err = newValidator.Sign(ctx, testChainID, ProposalToBlock(testChainID, &proposal)) + _, _, err = newValidator.Sign(ctx, testChainID, types.ProposalToBlock(testChainID, &proposal)) require.Error(t, err, "double sign!") proposal = cometproto.Proposal{ @@ -219,15 +223,15 @@ func testThresholdValidator(t *testing.T, keyType string, threshold, total uint8 newValidator.nonceCache.LoadN(ctx, 3) eg.Go(func() error { - _, _, err := newValidator.Sign(ctx, testChainID, ProposalToBlock(testChainID, &proposal)) + _, _, err := newValidator.Sign(ctx, testChainID, types.ProposalToBlock(testChainID, &proposal)) return err }) eg.Go(func() error { - _, _, err := newValidator.Sign(ctx, testChainID, ProposalToBlock(testChainID, &proposalClone)) + _, _, err := newValidator.Sign(ctx, testChainID, types.ProposalToBlock(testChainID, &proposalClone)) return err }) eg.Go(func() error { - _, _, err := newValidator.Sign(ctx, testChainID, ProposalToBlock(testChainID, &proposalClone2)) + _, _, err := newValidator.Sign(ctx, testChainID, types.ProposalToBlock(testChainID, &proposalClone2)) return err }) // signing higher block now should succeed @@ -253,19 +257,19 @@ func testThresholdValidator(t *testing.T, keyType string, threshold, total uint8 eg.Go(func() error { start := time.Now() - _, _, err := newValidator.Sign(ctx, testChainID, VoteToBlock(testChainID, &prevote)) + _, _, err := newValidator.Sign(ctx, testChainID, types.VoteToBlock(testChainID, &prevote)) t.Log("Sign time", "duration", time.Since(start)) return err }) eg.Go(func() error { start := time.Now() - _, _, err := newValidator.Sign(ctx, testChainID, VoteToBlock(testChainID, &prevoteClone)) + _, _, err := newValidator.Sign(ctx, testChainID, types.VoteToBlock(testChainID, &prevoteClone)) t.Log("Sign time", "duration", time.Since(start)) return err }) eg.Go(func() error { start := time.Now() - _, _, err := newValidator.Sign(ctx, testChainID, VoteToBlock(testChainID, &prevoteClone2)) + _, _, err := newValidator.Sign(ctx, testChainID, types.VoteToBlock(testChainID, &prevoteClone2)) t.Log("Sign time", "duration", time.Since(start)) return err }) @@ -291,18 +295,18 @@ func testThresholdValidator(t *testing.T, keyType string, threshold, total uint8 eg.Go(func() error { start := time.Now() t.Log("Sign time", "duration", time.Since(start)) - _, _, err := newValidator.Sign(ctx, testChainID, VoteToBlock(testChainID, &precommit)) + _, _, err := newValidator.Sign(ctx, testChainID, types.VoteToBlock(testChainID, &precommit)) return err }) eg.Go(func() error { start := time.Now() t.Log("Sign time", "duration", time.Since(start)) - _, _, err := newValidator.Sign(ctx, testChainID, VoteToBlock(testChainID, &precommitClone)) + _, _, err := newValidator.Sign(ctx, testChainID, types.VoteToBlock(testChainID, &precommitClone)) return err }) eg.Go(func() error { start := time.Now() - _, _, err := newValidator.Sign(ctx, testChainID, VoteToBlock(testChainID, &precommitClone2)) + _, _, err := newValidator.Sign(ctx, testChainID, types.VoteToBlock(testChainID, &precommitClone2)) t.Log("Sign time", "duration", time.Since(start)) return err }) @@ -336,19 +340,16 @@ func getTestLocalCosigners(t *testing.T, keyType string, threshold, total uint8) privateKey := cometcryptoed25519.GenPrivKey() privKeyBytes := privateKey[:] privShardsEd25519 := tsed25519.DealShares(tsed25519.ExpandSecret(privKeyBytes[:32]), threshold, total) - for i := range privShardsEd25519 { privShards[i] = privShardsEd25519[i][:] } pubKey = privateKey.PubKey().Bytes() case CosignerKeyTypeBn254: - privateKey := horcrux_bn254.GenPrivKey() - _, privShardsBn254 := horcrux_bn254.GenFromSecret(privateKey.Bytes(), threshold, total) - + privateKey := cometcryptobn254.GenPrivKey() + _, privShardsBn254 := horcruxbn254.GenFromSecret(privateKey.Bytes(), threshold, total) for i := range privShardsBn254 { privShards[i] = privShardsBn254[i].Bytes() } - pubKey = privateKey.PubKey().Bytes() } @@ -379,7 +380,7 @@ func getTestLocalCosigners(t *testing.T, keyType string, threshold, total uint8) } cosigner := NewLocalCosigner( - cometlog.NewNopLogger(), + slog.New(slog.NewTextHandler(os.Stdout, nil)), cosignerConfig, NewCosignerSecurityECIES( CosignerECIESKey{ @@ -422,7 +423,7 @@ func testThresholdValidatorLeaderElection(t *testing.T, threshold, total uint8) } leaders[i] = &MockLeader{id: cosigner.GetID(), leader: leader} tv := NewThresholdValidator( - cometlog.NewNopLogger(), + slog.New(slog.NewTextHandler(os.Stdout, nil)), cosigner.config, int(threshold), time.Second, @@ -442,7 +443,7 @@ func testThresholdValidatorLeaderElection(t *testing.T, threshold, total uint8) err := tv.LoadSignStateIfNecessary(testChainID) require.NoError(t, err) - require.NoError(t, tv.Start(ctx)) + tv.Start(ctx) } quit := make(chan bool) @@ -498,7 +499,7 @@ func testThresholdValidatorLeaderElection(t *testing.T, threshold, total uint8) Type: cometproto.ProposalType, } - signature, _, err := tv.Sign(ctx, testChainID, ProposalToBlock(testChainID, &proposal)) + signature, _, err := tv.Sign(ctx, testChainID, types.ProposalToBlock(testChainID, &proposal)) if err != nil { t.Log("Proposal sign failed", "error", err) return @@ -540,7 +541,7 @@ func testThresholdValidatorLeaderElection(t *testing.T, threshold, total uint8) Type: cometproto.PrevoteType, } - signature, _, err := tv.Sign(ctx, testChainID, VoteToBlock(testChainID, &preVote)) + signature, _, err := tv.Sign(ctx, testChainID, types.VoteToBlock(testChainID, &preVote)) if err != nil { t.Log("PreVote sign failed", "error", err) return @@ -582,7 +583,7 @@ func testThresholdValidatorLeaderElection(t *testing.T, threshold, total uint8) Type: cometproto.PrecommitType, } - signature, _, err := tv.Sign(ctx, testChainID, VoteToBlock(testChainID, &preCommit)) + signature, _, err := tv.Sign(ctx, testChainID, types.VoteToBlock(testChainID, &preCommit)) if err != nil { t.Log("PreCommit sign failed", "error", err) return diff --git a/test/go.mod b/test/go.mod index b95e0b27..ecb04136 100644 --- a/test/go.mod +++ b/test/go.mod @@ -1,14 +1,13 @@ -module github.com/strangelove-ventures/horcrux/test +module github.com/strangelove-ventures/horcrux/v3/test go 1.21 require ( - github.com/cometbft/cometbft v0.38.0 github.com/cosmos/cosmos-sdk v0.50.1 github.com/docker/docker v24.0.7+incompatible github.com/prometheus/client_model v0.5.0 github.com/prometheus/common v0.45.0 - github.com/strangelove-ventures/horcrux v0.0.0 + github.com/strangelove-ventures/horcrux/v3 v3.0.0 github.com/strangelove-ventures/interchaintest/v8 v8.0.0 github.com/stretchr/testify v1.8.4 go.uber.org/zap v1.26.0 @@ -66,7 +65,10 @@ require ( github.com/cockroachdb/pebble v0.0.0-20231116191551-bfb2e6a97fdd // indirect github.com/cockroachdb/redact v1.1.5 // indirect github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect + github.com/cometbft/cometbft v0.38.0 // indirect github.com/cometbft/cometbft-db v0.8.0 // indirect + github.com/consensys/bavard v0.1.13 // indirect + github.com/consensys/gnark-crypto v0.12.1 // indirect github.com/containerd/containerd v1.6.24 // indirect github.com/cosmos/btcutil v1.0.5 // indirect github.com/cosmos/cosmos-db v1.0.0 // indirect @@ -177,6 +179,7 @@ require ( github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/go-testing-interface v1.14.1 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/mmcloughlin/addchain v0.4.0 // indirect github.com/moby/patternmatcher v0.5.0 // indirect github.com/moby/sys/sequential v0.5.0 // indirect github.com/mr-tron/base58 v1.2.0 // indirect @@ -226,8 +229,6 @@ require ( github.com/zondax/ledger-go v0.14.3 // indirect gitlab.com/unit410/edwards25519 v0.0.0-20220725154547-61980033348e // indirect gitlab.com/unit410/threshold-ed25519 v0.0.0-20220812172601-56783212c4cc // indirect - go.dedis.ch/fixbuf v1.0.3 // indirect - go.dedis.ch/kyber/v3 v3.1.0 // indirect go.etcd.io/bbolt v1.3.8 // indirect go.opencensus.io v0.24.0 // indirect go.uber.org/multierr v1.11.0 // indirect @@ -264,6 +265,7 @@ require ( modernc.org/token v1.1.0 // indirect nhooyr.io/websocket v1.8.10 // indirect pgregory.net/rapid v1.1.0 // indirect + rsc.io/tmplfunc v0.0.3 // indirect sigs.k8s.io/yaml v1.4.0 // indirect ) @@ -272,6 +274,6 @@ replace ( github.com/ChainSafe/go-schnorrkel/1 => github.com/ChainSafe/go-schnorrkel v1.0.0 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 github.com/keybase/go-keychain => github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 - github.com/strangelove-ventures/horcrux => ../ + github.com/strangelove-ventures/horcrux/v3 => ../ github.com/vedhavyas/go-subkey => github.com/strangelove-ventures/go-subkey v1.0.7 ) diff --git a/test/go.sum b/test/go.sum index 94f563b1..62f7a29e 100644 --- a/test/go.sum +++ b/test/go.sum @@ -648,6 +648,7 @@ github.com/google/pprof v0.0.0-20230817174616-7a8ec2ada47b/go.mod h1:czg5+yv1E0Z github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/s2a-go v0.1.7 h1:60BLSyTrOV4/haCDW4zb1guZItoSq8foHCXrAnjBo/o= github.com/google/s2a-go v0.1.7/go.mod h1:50CgR4k1jNlWBu4UfS4AcfhVe1r6pdZPygJ3R8F0Qdw= +github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -836,6 +837,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kraken-hpc/go-fork v0.1.1 h1:O3X/ynoNy/eS7UIcZYef8ndFq2RXEIOue9kZqyzF0Sk= github.com/kraken-hpc/go-fork v0.1.1/go.mod h1:uu0e5h+V4ONH5Qk/xuVlyNXJXy/swhqGIEMK7w+9dNc= +github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= +github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= @@ -902,6 +905,7 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU= +github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU= github.com/moby/patternmatcher v0.5.0 h1:YCZgJOeULcxLw1Q+sVR636pmS7sPEn1Qo2iAN6M7DBo= github.com/moby/patternmatcher v0.5.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= github.com/moby/sys/sequential v0.5.0 h1:OPvI35Lzn9K04PBbCLW0g4LcFAJgHsvXsRyewg5lXtc= @@ -1179,16 +1183,6 @@ gitlab.com/unit410/edwards25519 v0.0.0-20220725154547-61980033348e h1:/QfokHt2yG gitlab.com/unit410/edwards25519 v0.0.0-20220725154547-61980033348e/go.mod h1:lTSPILLBMt6qQOJgsiarbW85JhpkhoOfW2EBkxkcuSI= gitlab.com/unit410/threshold-ed25519 v0.0.0-20220812172601-56783212c4cc h1:ESmaQH1+uOLW0wOIPT4EVLh+gwKdmKovr+eZg4jWUNs= gitlab.com/unit410/threshold-ed25519 v0.0.0-20220812172601-56783212c4cc/go.mod h1:1CIpwbV+rSyzoBVr6Ok9vvEP7UHrW/d0zEB+jU6+E3o= -go.dedis.ch/fixbuf v1.0.3 h1:hGcV9Cd/znUxlusJ64eAlExS+5cJDIyTyEG+otu5wQs= -go.dedis.ch/fixbuf v1.0.3/go.mod h1:yzJMt34Wa5xD37V5RTdmp38cz3QhMagdGoem9anUalw= -go.dedis.ch/kyber/v3 v3.0.4/go.mod h1:OzvaEnPvKlyrWyp3kGXlFdp7ap1VC6RkZDTaPikqhsQ= -go.dedis.ch/kyber/v3 v3.0.9/go.mod h1:rhNjUUg6ahf8HEg5HUvVBYoWY4boAafX8tYxX+PS+qg= -go.dedis.ch/kyber/v3 v3.1.0 h1:ghu+kiRgM5JyD9TJ0hTIxTLQlJBR/ehjWvWwYW3XsC0= -go.dedis.ch/kyber/v3 v3.1.0/go.mod h1:kXy7p3STAurkADD+/aZcsznZGKVHEqbtmdIzvPfrs1U= -go.dedis.ch/protobuf v1.0.5/go.mod h1:eIV4wicvi6JK0q/QnfIEGeSFNG0ZeB24kzut5+HaRLo= -go.dedis.ch/protobuf v1.0.7/go.mod h1:pv5ysfkDX/EawiPqcW3ikOxsL5t+BqnV6xHSmE79KI4= -go.dedis.ch/protobuf v1.0.11 h1:FTYVIEzY/bfl37lu3pR4lIj+F9Vp1jE8oh91VmxKgLo= -go.dedis.ch/protobuf v1.0.11/go.mod h1:97QR256dnkimeNdfmURz0wAMNVbd1VmLXhG1CrTYrJ4= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= go.etcd.io/bbolt v1.3.8 h1:xs88BrvEv273UsB79e0hcVrlUWmS0a8upikMFhSyAtA= @@ -1229,7 +1223,6 @@ golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -1400,7 +1393,6 @@ golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190124100055-b90733256f2e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/test/validator.go b/test/validator.go index bcbd8b81..4f820dae 100644 --- a/test/validator.go +++ b/test/validator.go @@ -8,13 +8,12 @@ import ( "testing" "time" - cometbytes "github.com/cometbft/cometbft/libs/bytes" - cometjson "github.com/cometbft/cometbft/libs/json" - "github.com/cometbft/cometbft/privval" "github.com/cosmos/cosmos-sdk/types/bech32" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/docker/docker/client" - "github.com/strangelove-ventures/horcrux/v3/signer/proto" + cometjson "github.com/strangelove-ventures/horcrux/v3/comet/libs/json" + "github.com/strangelove-ventures/horcrux/v3/comet/privval" + grpccosigner "github.com/strangelove-ventures/horcrux/v3/grpc/cosigner" interchaintest "github.com/strangelove-ventures/interchaintest/v8" "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" "github.com/strangelove-ventures/interchaintest/v8/ibc" @@ -220,7 +219,7 @@ func enablePrivvalListener( } // getValSigningInfo returns the signing info for the given validator from the reference node. -func getValSigningInfo(tn *cosmos.ChainNode, address cometbytes.HexBytes) (*slashingtypes.ValidatorSigningInfo, error) { +func getValSigningInfo(tn *cosmos.ChainNode, address []byte) (*slashingtypes.ValidatorSigningInfo, error) { valConsPrefix := fmt.Sprintf("%svalcons", tn.Chain.Config().Bech32Prefix) bech32ValConsAddress, err := bech32.ConvertAndEncode(valConsPrefix, address) @@ -238,7 +237,7 @@ func getValSigningInfo(tn *cosmos.ChainNode, address cometbytes.HexBytes) (*slas } // requireHealthyValidator asserts that the given validator is not tombstoned, not jailed, and has not missed any blocks in the slashing window. -func requireHealthyValidator(t *testing.T, referenceNode *cosmos.ChainNode, validatorAddress cometbytes.HexBytes) { +func requireHealthyValidator(t *testing.T, referenceNode *cosmos.ChainNode, validatorAddress []byte) { signingInfo, err := getValSigningInfo(referenceNode, validatorAddress) require.NoError(t, err) @@ -297,9 +296,9 @@ func getLeader(ctx context.Context, cosigner *cosmos.SidecarProcess) (int, error ctx, cancelFunc := context.WithTimeout(ctx, 10*time.Second) defer cancelFunc() - grpcClient := proto.NewCosignerClient(conn) + grpcClient := grpccosigner.NewCosignerClient(conn) - res, err := grpcClient.GetLeader(ctx, &proto.GetLeaderRequest{}) + res, err := grpcClient.GetLeader(ctx, &grpccosigner.GetLeaderRequest{}) if err != nil { return -1, err } diff --git a/test/validator_single.go b/test/validator_single.go index 4b7c4b15..ea68cff5 100644 --- a/test/validator_single.go +++ b/test/validator_single.go @@ -7,9 +7,9 @@ import ( "fmt" "testing" - cometjson "github.com/cometbft/cometbft/libs/json" - "github.com/cometbft/cometbft/privval" "github.com/docker/docker/client" + cometjson "github.com/strangelove-ventures/horcrux/v3/comet/libs/json" + "github.com/strangelove-ventures/horcrux/v3/comet/privval" "github.com/strangelove-ventures/horcrux/v3/signer" interchaintest "github.com/strangelove-ventures/interchaintest/v8" "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" diff --git a/types/block.go b/types/block.go new file mode 100644 index 00000000..f5322f13 --- /dev/null +++ b/types/block.go @@ -0,0 +1,52 @@ +package types + +import ( + "time" + + grpccosigner "github.com/strangelove-ventures/horcrux/v3/grpc/cosigner" +) + +type Block struct { + Height int64 + Round int64 + Step int8 + SignBytes []byte + Timestamp time.Time +} + +func (block Block) HRSKey() HRSKey { + return HRSKey{ + Height: block.Height, + Round: block.Round, + Step: block.Step, + } +} + +func (block Block) HRSTKey() HRSTKey { + return HRSTKey{ + Height: block.Height, + Round: block.Round, + Step: block.Step, + Timestamp: block.Timestamp.UnixNano(), + } +} + +func (block Block) ToProto() *grpccosigner.Block { + return &grpccosigner.Block{ + Height: block.Height, + Round: block.Round, + Step: int32(block.Step), + SignBytes: block.SignBytes, + Timestamp: block.Timestamp.UnixNano(), + } +} + +func BlockFromProto(block *grpccosigner.Block) Block { + return Block{ + Height: block.Height, + Round: block.Round, + Step: int8(block.Step), + SignBytes: block.SignBytes, + Timestamp: time.Unix(0, block.Timestamp), + } +} diff --git a/signer/hrs.go b/types/hrs.go similarity index 55% rename from signer/hrs.go rename to types/hrs.go index 19155f66..e1b8af5c 100644 --- a/signer/hrs.go +++ b/types/hrs.go @@ -1,7 +1,11 @@ -package signer +package types import ( - "github.com/strangelove-ventures/horcrux/v3/signer/proto" + "errors" + + "github.com/strangelove-ventures/horcrux/v3/comet/libs/protoio" + cometproto "github.com/strangelove-ventures/horcrux/v3/comet/proto/types" + grpccosigner "github.com/strangelove-ventures/horcrux/v3/grpc/cosigner" ) // HRSKey represents the key for the HRS metadata map. @@ -51,7 +55,7 @@ func (hrst HRSTKey) HRSKey() HRSKey { } // HRSTKeyFromProto returns a HRSTKey from a proto.HRST. -func HRSTKeyFromProto(hrs *proto.HRST) HRSTKey { +func HRSTKeyFromProto(hrs *grpccosigner.HRST) HRSTKey { return HRSTKey{ Height: hrs.GetHeight(), Round: hrs.GetRound(), @@ -60,11 +64,30 @@ func HRSTKeyFromProto(hrs *proto.HRST) HRSTKey { } } -func (hrst HRSTKey) toProto() *proto.HRST { - return &proto.HRST{ +func (hrst HRSTKey) ToProto() *grpccosigner.HRST { + return &grpccosigner.HRST{ Height: hrst.Height, Round: hrst.Round, Step: int32(hrst.Step), Timestamp: hrst.Timestamp, } } + +// UnpackHRS deserializes sign bytes and gets the height, round, and step +func UnpackHRST(signBytes []byte) (HRSTKey, error) { + { + var proposal cometproto.CanonicalProposal + if err := protoio.UnmarshalDelimited(signBytes, &proposal); err == nil { + return HRSTKey{proposal.Height, proposal.Round, StepPropose, proposal.Timestamp.UnixNano()}, nil + } + } + + { + var vote cometproto.CanonicalVote + if err := protoio.UnmarshalDelimited(signBytes, &vote); err == nil { + return HRSTKey{vote.Height, vote.Round, CanonicalVoteToStep(&vote), vote.Timestamp.UnixNano()}, nil + } + } + + return HRSTKey{0, 0, 0, 0}, errors.New("could not UnpackHRS from sign bytes") +} diff --git a/types/serialization.go b/types/serialization.go new file mode 100644 index 00000000..21ddc820 --- /dev/null +++ b/types/serialization.go @@ -0,0 +1,23 @@ +package types + +import ( + "io" + + "github.com/strangelove-ventures/horcrux/v3/comet/libs/protoio" + cometprotoprivval "github.com/strangelove-ventures/horcrux/v3/comet/proto/privval" +) + +// ReadMsg reads a message from an io.Reader +func ReadMsg(reader io.Reader) (msg cometprotoprivval.Message, err error) { + const maxRemoteSignerMsgSize = 1024 * 10 + protoReader := protoio.NewDelimitedReader(reader, maxRemoteSignerMsgSize) + _, err = protoReader.ReadMsg(&msg) + return msg, err +} + +// WriteMsg writes a message to an io.Writer +func WriteMsg(writer io.Writer, msg cometprotoprivval.Message) (err error) { + protoWriter := protoio.NewDelimitedWriter(writer) + _, err = protoWriter.WriteMsg(&msg) + return err +} diff --git a/signer/serialization_test.go b/types/serialization_test.go similarity index 88% rename from signer/serialization_test.go rename to types/serialization_test.go index d51a678c..48b08d0b 100644 --- a/signer/serialization_test.go +++ b/types/serialization_test.go @@ -1,10 +1,10 @@ -package signer +package types import ( "testing" - cometproto "github.com/cometbft/cometbft/proto/tendermint/types" - comet "github.com/cometbft/cometbft/types" + cometproto "github.com/strangelove-ventures/horcrux/v3/comet/proto/types" + comet "github.com/strangelove-ventures/horcrux/v3/comet/types" "github.com/stretchr/testify/require" ) diff --git a/signer/sign_state.go b/types/sign_state.go similarity index 89% rename from signer/sign_state.go rename to types/sign_state.go index 0ab8d731..21cf3ca1 100644 --- a/signer/sign_state.go +++ b/types/sign_state.go @@ -1,4 +1,4 @@ -package signer +package types import ( "bytes" @@ -7,31 +7,31 @@ import ( "fmt" "os" "sync" - - cometbytes "github.com/cometbft/cometbft/libs/bytes" - cometjson "github.com/cometbft/cometbft/libs/json" - "github.com/cometbft/cometbft/libs/protoio" - "github.com/cometbft/cometbft/libs/tempfile" - cometproto "github.com/cometbft/cometbft/proto/tendermint/types" - comet "github.com/cometbft/cometbft/types" - "github.com/gogo/protobuf/proto" + "time" + + "github.com/cosmos/gogoproto/proto" + cometjson "github.com/strangelove-ventures/horcrux/v3/comet/libs/json" + "github.com/strangelove-ventures/horcrux/v3/comet/libs/protoio" + "github.com/strangelove-ventures/horcrux/v3/comet/libs/tempfile" + cometproto "github.com/strangelove-ventures/horcrux/v3/comet/proto/types" + comet "github.com/strangelove-ventures/horcrux/v3/comet/types" "github.com/strangelove-ventures/horcrux/v3/signer/cond" ) const ( - stepPropose int8 = 1 - stepPrevote int8 = 2 - stepPrecommit int8 = 3 + StepPropose int8 = 1 + StepPrevote int8 = 2 + StepPrecommit int8 = 3 blocksToCache = 3 ) -func signType(step int8) string { +func SignType(step int8) string { switch step { - case stepPropose: + case StepPropose: return "proposal" - case stepPrevote: + case StepPrevote: return "prevote" - case stepPrecommit: + case StepPrecommit: return "precommit" default: return "unknown" @@ -41,9 +41,9 @@ func signType(step int8) string { func CanonicalVoteToStep(vote *cometproto.CanonicalVote) int8 { switch vote.Type { case cometproto.PrevoteType: - return stepPrevote + return StepPrevote case cometproto.PrecommitType: - return stepPrecommit + return StepPrecommit default: panic("Unknown vote type") } @@ -52,9 +52,9 @@ func CanonicalVoteToStep(vote *cometproto.CanonicalVote) int8 { func VoteToStep(vote *cometproto.Vote) int8 { switch vote.Type { case cometproto.PrevoteType: - return stepPrevote + return StepPrevote case cometproto.PrecommitType: - return stepPrecommit + return StepPrecommit default: panic("Unknown vote type") } @@ -71,7 +71,7 @@ func VoteToBlock(chainID string, vote *cometproto.Vote) Block { } func ProposalToStep(_ *cometproto.Proposal) int8 { - return stepPropose + return StepPropose } func ProposalToBlock(chainID string, proposal *cometproto.Proposal) Block { @@ -86,11 +86,11 @@ func ProposalToBlock(chainID string, proposal *cometproto.Proposal) Block { func StepToType(step int8) cometproto.SignedMsgType { switch step { - case stepPropose: + case StepPropose: return cometproto.ProposalType - case stepPrevote: + case StepPrevote: return cometproto.PrevoteType - case stepPrecommit: + case StepPrecommit: return cometproto.PrecommitType default: panic("Unknown step") @@ -99,12 +99,12 @@ func StepToType(step int8) cometproto.SignedMsgType { // SignState stores signing information for high level watermark management. type SignState struct { - Height int64 `json:"height"` - Round int64 `json:"round"` - Step int8 `json:"step"` - NoncePublic []byte `json:"nonce_public"` - Signature []byte `json:"signature,omitempty"` - SignBytes cometbytes.HexBytes `json:"signbytes,omitempty"` + Height int64 `json:"height"` + Round int64 `json:"round"` + Step int8 `json:"step"` + NoncePublic []byte `json:"nonce_public"` + Signature []byte `json:"signature,omitempty"` + SignBytes []byte `json:"signbytes,omitempty"` filePath string @@ -114,7 +114,36 @@ type SignState struct { cond *cond.Cond } -func (signState *SignState) existingSignatureOrErrorIfRegression(hrst HRSTKey, signBytes []byte) ([]byte, error) { +func (signState *SignState) CondLock() { + signState.cond.L.Lock() +} + +func (signState *SignState) CondUnlock() { + signState.cond.L.Unlock() +} + +func (signState *SignState) CondWaitWithTimeout(timeout time.Duration) { + signState.cond.WaitWithTimeout(timeout) +} + +func (signState *SignState) CondBroadcast() { + signState.cond.Broadcast() +} + +func (signState *SignState) Cached(hrs HRSKey) (SignStateConsensus, bool) { + val, ok := signState.cache[hrs] + return val, ok +} + +func (signState *SignState) Cache(hrs HRSKey, ssc SignStateConsensus) { + signState.cache[hrs] = ssc +} + +func (signState *SignState) ClearFile() { + signState.filePath = os.DevNull +} + +func (signState *SignState) ExistingSignatureOrErrorIfRegression(hrst HRSTKey, signBytes []byte) ([]byte, error) { signState.mu.RLock() defer signState.mu.RUnlock() @@ -163,7 +192,7 @@ type SignStateConsensus struct { Round int64 Step int8 Signature []byte - SignBytes cometbytes.HexBytes + SignBytes []byte } func (signState SignStateConsensus) HRSKey() HRSKey { @@ -500,9 +529,9 @@ func (signState *SignStateConsensus) OnlyDifferByTimestamp(signBytes []byte) err } func onlyDifferByTimestamp(step int8, signStateSignBytes, signBytes []byte) error { - if step == stepPropose { + if step == StepPropose { return checkProposalOnlyDifferByTimestamp(signStateSignBytes, signBytes) - } else if step == stepPrevote || step == stepPrecommit { + } else if step == StepPrevote || step == StepPrecommit { return checkVoteOnlyDifferByTimestamp(signStateSignBytes, signBytes) }