Skip to content

Commit 7cd25ab

Browse files
amaury1093aaroncblushialexanderbezcolin-axner
authored
Proto Tx with Any (#7276)
* WIP on protobuf keys * Use Type() and Bytes() in sr25519 pub key Equals * Add tests * Add few more tests * Update other pub/priv key types Equals * Fix PrivKey's Sign method * Rename variables in tests * Fix infinite recursive calls * Use tm ed25519 keys * Add Sign and VerifySignature tests * Remove ed25519 and sr25519 references * proto linting * Add proto crypto file * Implement some of the new multisig proto type methods * Add tests for MultisigThresholdPubKey * Add tests for pubkey pb/amino conversion functions * Move crypto types.go and register new proto pubkeys * Add missing pointer ref * Address review comments * panic in MultisigThresholdPubKey VerifySignature * Use internal crypto.PubKey in multisig * Add tests for MultisigThresholdPubKey VerifyMultisignature * Only keep LegacyAminoMultisigThresholdPubKey and move to proto keys to v1 * Remove conversion functions and introduce internal PubKey type * Override Amino marshaling for proto pubkeys * Merge master * Make proto-gen * Start removal of old PubKeyMultisigThreshold references * Fix tests * Fix solomachine * Fix ante handler tests * Pull latest go-amino * Remove ed25519 * Remove old secp256k1 PubKey and PrivKey * Uncomment test case * Fix linting issues * More linting * Revert tests keys values * Add Amino overrides to proto keys * Add pubkey test * Fix tests * Use threshold isntead of K * Standardize Type * Revert standardize types commit * Fix build * Fix lint * Fix lint * Add comment * Register crypto.PubKey * Add empty key in BuildSimTx * Simplify proto names * Unpack interfaces for signing desc * Fix IBC tests? * Format proto * Use secp256k1 in ibc * Fixed merge issues * Uncomment tests * Update x/ibc/testing/solomachine.go * UnpackInterfaces for solomachine types * Remove old multisig * Add amino marshal for multisig * Fix lint * Correctly register amino * One test left! * Remove old struct * Fix test * Fix test * Unpack into tmcrypto * Remove old threshold pubkey tests * Fix register amino * Fix lint * Use sdk crypto PubKey in multisig UnpackInterfaces * Potential fix? * Register LegacyAminoPubKey * Register our own PubKey * Register tmcrypto PubKey * Register both PubKeys * Register interfaces in test * Refactor fiels * Add comments * Use anil's suggestion * Add norace back * Check nil * Address comments * FIx lint * Add tests for solomachine unpack interfaces * Fix query tx by hash * Better name in amino register * Display StdTx instead of proto Tx * Remove useless check Co-authored-by: Aaron Craelius <aaronc@users.noreply.github.com> Co-authored-by: blushi <marie.gauthier63@gmail.com> Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
1 parent 535510b commit 7cd25ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+587
-622
lines changed

baseapp/grpcrouter.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/cosmos/cosmos-sdk/client/grpc/reflection"
1313
"github.com/cosmos/cosmos-sdk/client/grpc/simulate"
1414
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
15-
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
1615
sdk "github.com/cosmos/cosmos-sdk/types"
1716
)
1817

@@ -116,10 +115,9 @@ func (qrt *GRPCQueryRouter) SetInterfaceRegistry(interfaceRegistry codectypes.In
116115
func (qrt *GRPCQueryRouter) RegisterSimulateService(
117116
simulateFn simulate.BaseAppSimulateFn,
118117
interfaceRegistry codectypes.InterfaceRegistry,
119-
pubkeyCodec cryptotypes.PublicKeyCodec,
120118
) {
121119
simulate.RegisterSimulateServiceServer(
122120
qrt,
123-
simulate.NewSimulateServer(simulateFn, interfaceRegistry, pubkeyCodec),
121+
simulate.NewSimulateServer(simulateFn, interfaceRegistry),
124122
)
125123
}

baseapp/grpcrouter_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import (
44
"context"
55
"testing"
66

7-
"github.com/cosmos/cosmos-sdk/codec/types"
8-
97
"github.com/stretchr/testify/require"
108

9+
"github.com/cosmos/cosmos-sdk/codec/types"
1110
"github.com/cosmos/cosmos-sdk/testutil/testdata"
1211
sdk "github.com/cosmos/cosmos-sdk/types"
1312
)

client/grpc/simulate/simulate.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"google.golang.org/grpc/status"
88

99
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
10-
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
1110
sdk "github.com/cosmos/cosmos-sdk/types"
1211
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
1312
)
@@ -18,15 +17,13 @@ type BaseAppSimulateFn func(txBytes []byte, txtypes sdk.Tx) (sdk.GasInfo, *sdk.R
1817
type simulateServer struct {
1918
simulate BaseAppSimulateFn
2019
interfaceRegistry codectypes.InterfaceRegistry
21-
pubkeyCodec cryptotypes.PublicKeyCodec
2220
}
2321

2422
// NewSimulateServer creates a new SimulateServer.
25-
func NewSimulateServer(simulate BaseAppSimulateFn, interfaceRegistry codectypes.InterfaceRegistry, pubkeyCodec cryptotypes.PublicKeyCodec) SimulateServiceServer {
23+
func NewSimulateServer(simulate BaseAppSimulateFn, interfaceRegistry codectypes.InterfaceRegistry) SimulateServiceServer {
2624
return simulateServer{
2725
simulate: simulate,
2826
interfaceRegistry: interfaceRegistry,
29-
pubkeyCodec: pubkeyCodec,
3027
}
3128
}
3229

@@ -42,7 +39,7 @@ func (s simulateServer) Simulate(ctx context.Context, req *SimulateRequest) (*Si
4239
if err != nil {
4340
return nil, err
4441
}
45-
txBuilder := authtx.WrapTx(req.Tx, s.pubkeyCodec)
42+
txBuilder := authtx.WrapTx(req.Tx)
4643
txBytes, err := req.Tx.Marshal()
4744
if err != nil {
4845
return nil, err

client/grpc/simulate/simulate_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/cosmos/cosmos-sdk/client/tx"
1414
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
1515
"github.com/cosmos/cosmos-sdk/simapp"
16-
"github.com/cosmos/cosmos-sdk/std"
1716
"github.com/cosmos/cosmos-sdk/testutil/testdata"
1817
sdk "github.com/cosmos/cosmos-sdk/types"
1918
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
@@ -41,11 +40,10 @@ func (s *IntegrationTestSuite) SetupSuite() {
4140

4241
// Set up TxConfig.
4342
encodingConfig := simapp.MakeEncodingConfig()
44-
pubKeyCodec := std.DefaultPublicKeyCodec{}
4543
clientCtx := client.Context{}.WithTxConfig(encodingConfig.TxConfig)
4644

4745
// Create new simulation server.
48-
srv := simulate.NewSimulateServer(app.BaseApp.Simulate, encodingConfig.InterfaceRegistry, pubKeyCodec)
46+
srv := simulate.NewSimulateServer(app.BaseApp.Simulate, encodingConfig.InterfaceRegistry)
4947

5048
queryHelper := baseapp.NewQueryServerTestHelper(sdkCtx, app.InterfaceRegistry())
5149
simulate.RegisterSimulateServiceServer(queryHelper, srv)

client/tx/legacy_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/cosmos/cosmos-sdk/codec"
1212
"github.com/cosmos/cosmos-sdk/simapp"
1313
"github.com/cosmos/cosmos-sdk/simapp/params"
14-
"github.com/cosmos/cosmos-sdk/std"
1514
"github.com/cosmos/cosmos-sdk/testutil/testdata"
1615
"github.com/cosmos/cosmos-sdk/types"
1716
signing2 "github.com/cosmos/cosmos-sdk/types/tx/signing"
@@ -60,7 +59,7 @@ type TestSuite struct {
6059
func (s *TestSuite) SetupSuite() {
6160
encCfg := simapp.MakeEncodingConfig()
6261
s.encCfg = encCfg
63-
s.protoCfg = tx.NewTxConfig(codec.NewProtoCodec(encCfg.InterfaceRegistry), std.DefaultPublicKeyCodec{}, tx.DefaultSignModes)
62+
s.protoCfg = tx.NewTxConfig(codec.NewProtoCodec(encCfg.InterfaceRegistry), tx.DefaultSignModes)
6463
s.aminoCfg = types3.StdTxConfig{Cdc: encCfg.Amino}
6564
}
6665

client/tx/tx.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
sim "github.com/cosmos/cosmos-sdk/client/grpc/simulate"
1616
"github.com/cosmos/cosmos-sdk/client/input"
1717
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
18+
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
1819
sdk "github.com/cosmos/cosmos-sdk/types"
1920
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
2021
"github.com/cosmos/cosmos-sdk/types/rest"
@@ -257,6 +258,7 @@ func BuildSimTx(txf Factory, msgs ...sdk.Msg) ([]byte, error) {
257258
// Create an empty signature literal as the ante handler will populate with a
258259
// sentinel pubkey.
259260
sig := signing.SignatureV2{
261+
PubKey: &secp256k1.PubKey{},
260262
Data: &signing.SingleSignatureData{
261263
SignMode: txf.signMode,
262264
},

crypto/codec/proto.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package codec
2+
3+
import (
4+
tmcrypto "github.com/tendermint/tendermint/crypto"
5+
6+
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
7+
"github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
8+
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
9+
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
10+
)
11+
12+
// RegisterInterfaces registers the sdk.Tx interface.
13+
func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
14+
// TODO We now register both Tendermint's PubKey and our own PubKey. In the
15+
// long-term, we should move away from Tendermint's PubKey, and delete
16+
// these lines
17+
registry.RegisterInterface("tendermint.crypto.Pubkey", (*tmcrypto.PubKey)(nil))
18+
registry.RegisterImplementations((*tmcrypto.PubKey)(nil), &secp256k1.PubKey{})
19+
registry.RegisterImplementations((*tmcrypto.PubKey)(nil), &multisig.LegacyAminoPubKey{})
20+
21+
registry.RegisterInterface("cosmos.crypto.Pubkey", (*cryptotypes.PubKey)(nil))
22+
registry.RegisterImplementations((*cryptotypes.PubKey)(nil), &secp256k1.PubKey{})
23+
registry.RegisterImplementations((*cryptotypes.PubKey)(nil), &multisig.LegacyAminoPubKey{})
24+
}

crypto/types/codec.go

Lines changed: 0 additions & 15 deletions
This file was deleted.

docs/architecture/adr-020-protobuf-transaction-encoding.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
## Status
1515

16-
Proposed
16+
Accepted
1717

1818
## Context
1919

@@ -103,7 +103,7 @@ message AuthInfo {
103103
message SignerInfo {
104104
// The public key is optional for accounts that already exist in state. If unset, the
105105
// verifier can use the required signer address for this position and lookup the public key.
106-
PublicKey public_key = 1;
106+
google.protobuf.Any public_key = 1;
107107
// ModeInfo describes the signing mode of the signer and is a nested
108108
// structure to support nested multisig pubkey's
109109
ModeInfo mode_info = 2;

proto/cosmos/tx/signing/v1beta1/signing.proto

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ syntax = "proto3";
22
package cosmos.tx.signing.v1beta1;
33

44
import "cosmos/base/crypto/v1beta1/crypto.proto";
5+
import "google/protobuf/any.proto";
56

67
option go_package = "github.com/cosmos/cosmos-sdk/types/tx/signing";
78

@@ -33,43 +34,43 @@ message SignatureDescriptors {
3334
// signature including the public key of the signer, signing modes and the signature
3435
// itself. It is primarily used for coordinating signatures between clients.
3536
message SignatureDescriptor {
36-
// public_key is the public key of the signer
37-
cosmos.base.crypto.v1beta1.PublicKey public_key = 1;
38-
39-
Data data = 2;
40-
41-
// sequence is the sequence of the account, which describes the
42-
// number of committed transactions signed by a given address. It is used to prevent
43-
// replay attacks.
44-
uint64 sequence = 3;
45-
46-
// Data represents signature data
47-
message Data {
48-
// sum is the oneof that specifies whether this represents single or multi-signature data
49-
oneof sum {
50-
// single represents a single signer
51-
Single single = 1;
52-
53-
// multi represents a multisig signer
54-
Multi multi = 2;
55-
}
56-
57-
// Single is the signature data for a single signer
58-
message Single {
59-
// mode is the signing mode of the single signer
60-
SignMode mode = 1;
61-
62-
// signature is the raw signature bytes
63-
bytes signature = 2;
64-
}
65-
66-
// Multi is the signature data for a multisig public key
67-
message Multi {
68-
// bitarray specifies which keys within the multisig are signing
69-
cosmos.base.crypto.v1beta1.CompactBitArray bitarray = 1;
70-
71-
// signatures is the signatures of the multi-signature
72-
repeated Data signatures = 2;
37+
// public_key is the public key of the signer
38+
google.protobuf.Any public_key = 1;
39+
40+
Data data = 2;
41+
42+
// sequence is the sequence of the account, which describes the
43+
// number of committed transactions signed by a given address. It is used to prevent
44+
// replay attacks.
45+
uint64 sequence = 3;
46+
47+
// Data represents signature data
48+
message Data {
49+
// sum is the oneof that specifies whether this represents single or multi-signature data
50+
oneof sum {
51+
// single represents a single signer
52+
Single single = 1;
53+
54+
// multi represents a multisig signer
55+
Multi multi = 2;
56+
}
57+
58+
// Single is the signature data for a single signer
59+
message Single {
60+
// mode is the signing mode of the single signer
61+
SignMode mode = 1;
62+
63+
// signature is the raw signature bytes
64+
bytes signature = 2;
65+
}
66+
67+
// Multi is the signature data for a multisig public key
68+
message Multi {
69+
// bitarray specifies which keys within the multisig are signing
70+
cosmos.base.crypto.v1beta1.CompactBitArray bitarray = 1;
71+
72+
// signatures is the signatures of the multi-signature
73+
repeated Data signatures = 2;
74+
}
7375
}
74-
}
7576
}

0 commit comments

Comments
 (0)