Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert: Remove SIGN_MODE_AMINO_AUX #10322

Merged
merged 21 commits into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* Move Msg routers from BaseApp to middlewares.
* Move Baseapp panic recovery into a middleware.
* Rename simulation helper methods `baseapp.{Check,Deliver}` to `baseapp.Sim{Check,Deliver}`.
* [\#10322](https://github.com/cosmos/cosmos-sdk/pull/10322) The `tx.NewTxConfig` function takes a new parameter of type `address.Codec` used to encode and decode addresses. As such, a new field `AddressCdc` has been added to `simapp.EncodingConfig`.

### Client Breaking Changes

Expand Down
2 changes: 1 addition & 1 deletion client/tx/legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type TestSuite struct {
func (s *TestSuite) SetupSuite() {
encCfg := simapp.MakeTestEncodingConfig()
s.encCfg = encCfg
s.protoCfg = tx.NewTxConfig(codec.NewProtoCodec(encCfg.InterfaceRegistry), tx.DefaultSignModes)
s.protoCfg = tx.NewTxConfig(codec.NewProtoCodec(encCfg.InterfaceRegistry), tx.DefaultSignModes, s.encCfg.AddressCdc)
s.aminoCfg = legacytx.StdTxConfig{Cdc: encCfg.Amino}
}

Expand Down
15 changes: 1 addition & 14 deletions client/tx/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,24 +207,11 @@ func Sign(txf Factory, name string, txBuilder client.TxBuilder, overwriteSig boo
return err
}

pubkeys, err := txBuilder.GetTx().GetPubKeys()
if err != nil {
return err
}

signerIndex := 0
for i, p := range pubkeys {
if p.Equals(pubKey) {
signerIndex = i
break
}
}

signerData := authsigning.SignerData{
ChainID: txf.chainID,
AccountNumber: txf.accountNumber,
Sequence: txf.sequence,
SignerIndex: signerIndex,
Address: sdk.AccAddress(pubKey.Address()).String(),
}

// For SIGN_MODE_DIRECT, calling SetSignatures calls setSignerInfos on
Expand Down
3 changes: 1 addition & 2 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,7 @@ GrantAuthorization defines the GenesisState/GrantAuthorization type.
<a name="cosmos.authz.v1beta1.QueryGranterGrantsRequest"></a>

### QueryGranterGrantsRequest
QueryGranterGrantsRequest is the request type for the Query/Grants RPC method.
QueryGranterGrantsRequest is the request type for the Query/GranterGrants RPC method.


| Field | Type | Label | Description |
Expand Down Expand Up @@ -9400,7 +9400,6 @@ SignMode represents a signing mode with its own security guarantees.
| SIGN_MODE_DIRECT | 1 | SIGN_MODE_DIRECT specifies a signing mode which uses SignDoc and is verified with raw bytes from Tx. |
| SIGN_MODE_TEXTUAL | 2 | SIGN_MODE_TEXTUAL is a future signing mode that will verify some human-readable textual representation on top of the binary representation from SIGN_MODE_DIRECT. It is currently not supported. |
| SIGN_MODE_DIRECT_AUX | 3 | SIGN_MODE_DIRECT_AUX specifies a signing mode which uses SignDocDirectAux. As opposed to SIGN_MODE_DIRECT, this sign mode does not require signers signing over other signers' `signer_info`. It also allows for adding Tips in transactions. |
| SIGN_MODE_AMINO_AUX | 4 | SIGN_MODE_AMINO_AUX specifies a signing mode which uses SignDocAminoAux. |
| SIGN_MODE_LEGACY_AMINO_JSON | 127 | SIGN_MODE_LEGACY_AMINO_JSON is a backwards compatibility mode which uses Amino JSON and will be removed in the future. |


Expand Down
4 changes: 0 additions & 4 deletions proto/cosmos/tx/signing/v1beta1/signing.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ enum SignMode {
// for adding Tips in transactions.
SIGN_MODE_DIRECT_AUX = 3;

// SIGN_MODE_AMINO_AUX specifies a signing mode which uses
// SignDocAminoAux.
SIGN_MODE_AMINO_AUX = 4;

// SIGN_MODE_LEGACY_AMINO_JSON is a backwards compatibility mode which uses
// Amino JSON and will be removed in the future.
SIGN_MODE_LEGACY_AMINO_JSON = 127;
Expand Down
16 changes: 6 additions & 10 deletions server/rosetta/client_online.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,22 @@ import (
"strconv"
"time"

"github.com/cosmos/cosmos-sdk/version"

abcitypes "github.com/tendermint/tendermint/abci/types"

rosettatypes "github.com/coinbase/rosetta-sdk-go/types"
"google.golang.org/grpc/metadata"

abcitypes "github.com/tendermint/tendermint/abci/types"
tmrpc "github.com/tendermint/tendermint/rpc/client"
"github.com/tendermint/tendermint/rpc/client/http"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"

crgerrs "github.com/cosmos/cosmos-sdk/server/rosetta/lib/errors"
crgtypes "github.com/cosmos/cosmos-sdk/server/rosetta/lib/types"

sdk "github.com/cosmos/cosmos-sdk/types"
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth/address"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
auth "github.com/cosmos/cosmos-sdk/x/auth/types"
bank "github.com/cosmos/cosmos-sdk/x/bank/types"

tmrpc "github.com/tendermint/tendermint/rpc/client"
)

// interface assertion
Expand Down Expand Up @@ -60,7 +56,7 @@ func NewClient(cfg *Config) (*Client, error) {
v = "unknown"
}

txConfig := authtx.NewTxConfig(cfg.Codec, authtx.DefaultSignModes)
txConfig := authtx.NewTxConfig(cfg.Codec, authtx.DefaultSignModes, address.NewBech32Codec(sdk.Bech32MainPrefix))

var supportedOperations []string
for _, ii := range cfg.InterfaceRegistry.ListImplementations(sdk.MsgInterfaceProtoName) {
Expand Down
1 change: 1 addition & 0 deletions server/rosetta/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ func (c converter) SigningComponents(tx authsigning.Tx, metadata *ConstructionMe

// set the signer data
signerData := authsigning.SignerData{
Address: signer.String(),
ChainID: metadata.ChainID,
AccountNumber: metadata.SignersData[i].AccountNumber,
Sequence: metadata.SignersData[i].Sequence,
Expand Down
3 changes: 2 additions & 1 deletion server/rosetta/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

abci "github.com/tendermint/tendermint/abci/types"

"github.com/cosmos/cosmos-sdk/x/auth/address"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -44,7 +45,7 @@ func (s *ConverterTestSuite) SetupTest() {
s.unsignedTxBytes = unsignedTxBytes
// instantiate converter
cdc, ir := rosetta.MakeCodec()
txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes)
txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes, address.NewBech32Codec(sdk.Bech32MainPrefix))
s.c = rosetta.NewConverter(cdc, ir, txConfig)
// add utils
s.ir = ir
Expand Down
1 change: 1 addition & 0 deletions simapp/helpers/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func GenTx(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, ch
// 2nd round: once all signer infos are set, every signer can sign.
for i, p := range priv {
signerData := authsign.SignerData{
Address: sdk.AccAddress(p.PubKey().Address()).String(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

why this was removed before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The signerData.Address field was actually never present before, and newly added in this PR

ChainID: chainID,
AccountNumber: accNums[i],
Sequence: accSeqs[i],
Expand Down
3 changes: 3 additions & 0 deletions simapp/params/amino.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package params
import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
)

Expand All @@ -16,8 +17,10 @@ func MakeTestEncodingConfig() EncodingConfig {
cdc := codec.NewLegacyAmino()
interfaceRegistry := types.NewInterfaceRegistry()
marshaler := codec.NewAminoCodec(cdc)
addressCdc := address.NewBech32Codec(sdk.Bech32MainPrefix)

return EncodingConfig{
AddressCdc: addressCdc,
InterfaceRegistry: interfaceRegistry,
Marshaler: marshaler,
TxConfig: legacytx.StdTxConfig{Cdc: cdc},
Expand Down
2 changes: 2 additions & 0 deletions simapp/params/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/x/auth/address"
)

// EncodingConfig specifies the concrete encoding types to use for a given app.
// This is provided for compatibility between protobuf and amino implementations.
type EncodingConfig struct {
AddressCdc address.Codec
InterfaceRegistry types.InterfaceRegistry
Codec codec.Codec
TxConfig client.TxConfig
Expand Down
6 changes: 5 additions & 1 deletion simapp/params/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package params
import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/address"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
)

Expand All @@ -17,11 +19,13 @@ func MakeTestEncodingConfig() EncodingConfig {
cdc := codec.NewLegacyAmino()
interfaceRegistry := types.NewInterfaceRegistry()
codec := codec.NewProtoCodec(interfaceRegistry)
addressCdc := address.NewBech32Codec(sdk.Bech32MainPrefix)

return EncodingConfig{
AddressCdc: addressCdc,
InterfaceRegistry: interfaceRegistry,
Codec: codec,
TxConfig: tx.NewTxConfig(codec, tx.DefaultSignModes),
TxConfig: tx.NewTxConfig(codec, tx.DefaultSignModes, addressCdc),
Amino: cdc,
}
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
}
78 changes: 36 additions & 42 deletions types/tx/signing/signing.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions x/auth/address/bech32.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package address

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/bech32"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

// Bech32Codec is a address.Codec based on bech32 encoding.
type Bech32Codec struct {
Bech32Prefix string
}

var _ Codec = &Bech32Codec{}
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved

// NewBech32Codec creates a new address.Codec based on bech32 encoding.
func NewBech32Codec(prefix string) Codec {
return Bech32Codec{prefix}
}

// StringToBytes encodes text to bytes.
func (bc Bech32Codec) StringToBytes(text string) ([]byte, error) {
hrp, bz, err := bech32.DecodeAndConvert(text)
if err != nil {
return nil, err
}

if hrp != bc.Bech32Prefix {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "hrp does not match bech32Prefix")
}

if err := sdk.VerifyAddressFormat(bz); err != nil {
return nil, err
}

return bz, nil
}

// BytesToString decodes bytes to text.
func (bc Bech32Codec) BytesToString(bz []byte) (string, error) {
text, err := bech32.ConvertAndEncode(bc.Bech32Prefix, bz)
if err != nil {
return "", err
}

return text, nil
}
File renamed without changes.
14 changes: 8 additions & 6 deletions x/auth/client/cli/tx_multisign.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,14 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) {
return fmt.Errorf("set the chain id with either the --chain-id flag or config file")
}

signingData := signing.SignerData{
ChainID: txFactory.ChainID(),
AccountNumber: txFactory.AccountNumber(),
Sequence: txFactory.Sequence(),
}

for _, sig := range sigs {
signingData := signing.SignerData{
Address: sdk.AccAddress(sig.PubKey.Address()).String(),
ChainID: txFactory.ChainID(),
AccountNumber: txFactory.AccountNumber(),
Sequence: txFactory.Sequence(),
}

err = signing.VerifySignature(sig.PubKey, signingData, sig.Data, txCfg.SignModeHandler(), txBuilder.GetTx())
if err != nil {
addr, _ := sdk.AccAddressFromHex(sig.PubKey.Address().String())
Expand Down Expand Up @@ -323,6 +324,7 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error {
multisigPub := pubKey.(*kmultisig.LegacyAminoPubKey)
multisigSig := multisig.NewMultisig(len(multisigPub.PubKeys))
signingData := signing.SignerData{
Address: sdk.AccAddress(pubKey.Address()).String(),
ChainID: txFactory.ChainID(),
AccountNumber: txFactory.AccountNumber(),
Sequence: txFactory.Sequence(),
Expand Down
1 change: 1 addition & 0 deletions x/auth/client/cli/validate_sigs.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func printAndValidateSigs(
}

signingData := authsigning.SignerData{
Address: sigAddr.String(),
ChainID: chainID,
AccountNumber: accNum,
Sequence: accSeq,
Expand Down
Loading