IBC: panic on GetSignBytes and remove SubModuleCdc (#7645)

* panic on GetSignBytes and remove SubModuleCdc where possible

* fix build

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
colin axnér 2020-10-23 19:14:12 +02:00 committed by GitHub
parent c6cbe3a3db
commit e4378e747d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 57 additions and 108 deletions

View File

@ -64,9 +64,10 @@ func (msg MsgTransfer) ValidateBasic() error {
return ValidateIBCDenom(msg.Token.Denom)
}
// GetSignBytes implements sdk.Msg
// GetSignBytes implements sdk.Msg. The function will panic since it is used
// for amino transaction verification which IBC does not support.
func (msg MsgTransfer) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
panic("IBC messages do not support amino")
}
// GetSigners implements sdk.Msg

View File

@ -1,7 +1,6 @@
package types
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
@ -85,15 +84,6 @@ func TestMsgTransferValidation(t *testing.T) {
}
}
// TestMsgTransferGetSignBytes tests GetSignBytes for MsgTransfer
func TestMsgTransferGetSignBytes(t *testing.T) {
msg := NewMsgTransfer(validPort, validChannel, coin, addr1, addr2, clienttypes.NewHeight(0, 110), 10)
res := msg.GetSignBytes()
expected := fmt.Sprintf(`{"receiver":"cosmos1w3jhxarpv3j8yvs7f9y7g","sender":"%s","source_channel":"testchannel","source_port":"testportid","timeout_height":{"version_height":"110","version_number":"0"},"timeout_timestamp":"10","token":{"amount":"100","denom":"atom"}}`, addr1.String())
require.Equal(t, expected, string(res))
}
// TestMsgTransferGetSigners tests GetSigners for MsgTransfer
func TestMsgTransferGetSigners(t *testing.T) {
msg := NewMsgTransfer(validPort, validChannel, coin, addr1, addr2, timeoutHeight, 0)

View File

@ -3,7 +3,6 @@ package types
import (
proto "github.com/gogo/protobuf/proto"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
@ -44,15 +43,6 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
)
}
var (
// SubModuleCdc references the global x/ibc/core/02-client module codec. Note, the codec should
// ONLY be used in certain instances of tests and for JSON encoding.
//
// The actual codec used for serialization should be provided to x/ibc/core/02-client and
// defined at the application level.
SubModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
)
// PackClientState constructs a new Any packed with the given client state value. It returns
// an error if the client state can't be casted to a protobuf message or if the concrete
// implemention is not registered to the protobuf codec.

View File

@ -87,9 +87,10 @@ func (msg MsgCreateClient) ValidateBasic() error {
return host.ClientIdentifierValidator(msg.ClientId)
}
// GetSignBytes implements sdk.Msg
// GetSignBytes implements sdk.Msg. The function will panic since it is used
// for amino transaction verification which IBC does not support.
func (msg MsgCreateClient) GetSignBytes() []byte {
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
panic("IBC messages do not support amino")
}
// GetSigners implements sdk.Msg
@ -156,9 +157,10 @@ func (msg MsgUpdateClient) ValidateBasic() error {
return host.ClientIdentifierValidator(msg.ClientId)
}
// GetSignBytes implements sdk.Msg
// GetSignBytes implements sdk.Msg. The function will panic since it is used
// for amino transaction verification which IBC does not support.
func (msg MsgUpdateClient) GetSignBytes() []byte {
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
panic("IBC messages do not support amino")
}
// GetSigners implements sdk.Msg
@ -233,9 +235,10 @@ func (msg MsgUpgradeClient) ValidateBasic() error {
return host.ClientIdentifierValidator(msg.ClientId)
}
// GetSignBytes implements sdk.Msg
// GetSignBytes implements sdk.Msg. The function will panic since it is used
// for amino transaction verification which IBC does not support.
func (msg MsgUpgradeClient) GetSignBytes() []byte {
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
panic("IBC messages do not support amino")
}
// GetSigners implements sdk.Msg
@ -299,10 +302,10 @@ func (msg MsgSubmitMisbehaviour) ValidateBasic() error {
return host.ClientIdentifierValidator(msg.ClientId)
}
// GetSignBytes returns the raw bytes a signer is expected to sign when submitting
// a MsgSubmitMisbehaviour message.
// GetSignBytes implements sdk.Msg. The function will panic since it is used
// for amino transaction verification which IBC does not support.
func (msg MsgSubmitMisbehaviour) GetSignBytes() []byte {
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
panic("IBC messages do not support amino")
}
// GetSigners returns the single expected signer for a MsgSubmitMisbehaviour.

View File

@ -58,9 +58,10 @@ func (msg MsgConnectionOpenInit) ValidateBasic() error {
return msg.Counterparty.ValidateBasic()
}
// GetSignBytes implements sdk.Msg
// GetSignBytes implements sdk.Msg. The function will panic since it is used
// for amino transaction verification which IBC does not support.
func (msg MsgConnectionOpenInit) GetSignBytes() []byte {
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
panic("IBC messages do not support amino")
}
// GetSigners implements sdk.Msg
@ -172,9 +173,10 @@ func (msg MsgConnectionOpenTry) UnpackInterfaces(unpacker codectypes.AnyUnpacker
return nil
}
// GetSignBytes implements sdk.Msg
// GetSignBytes implements sdk.Msg. The function will panic since it is used
// for amino transaction verification which IBC does not support.
func (msg MsgConnectionOpenTry) GetSignBytes() []byte {
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
panic("IBC messages do not support amino")
}
// GetSigners implements sdk.Msg
@ -268,9 +270,10 @@ func (msg MsgConnectionOpenAck) ValidateBasic() error {
return nil
}
// GetSignBytes implements sdk.Msg
// GetSignBytes implements sdk.Msg. The function will panic since it is used
// for amino transaction verification which IBC does not support.
func (msg MsgConnectionOpenAck) GetSignBytes() []byte {
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
panic("IBC messages do not support amino")
}
// GetSigners implements sdk.Msg
@ -325,9 +328,10 @@ func (msg MsgConnectionOpenConfirm) ValidateBasic() error {
return nil
}
// GetSignBytes implements sdk.Msg
// GetSignBytes implements sdk.Msg. The function will panic since it is used
// for amino transaction verification which IBC does not support.
func (msg MsgConnectionOpenConfirm) GetSignBytes() []byte {
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
panic("IBC messages do not support amino")
}
// GetSigners implements sdk.Msg

View File

@ -50,9 +50,10 @@ func (msg MsgChannelOpenInit) ValidateBasic() error {
return msg.Channel.ValidateBasic()
}
// GetSignBytes implements sdk.Msg
// GetSignBytes implements sdk.Msg. The function will panic since it is used
// for amino transaction verification which IBC does not support.
func (msg MsgChannelOpenInit) GetSignBytes() []byte {
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
panic("IBC messages do not support amino")
}
// GetSigners implements sdk.Msg
@ -118,9 +119,10 @@ func (msg MsgChannelOpenTry) ValidateBasic() error {
return msg.Channel.ValidateBasic()
}
// GetSignBytes implements sdk.Msg
// GetSignBytes implements sdk.Msg. The function will panic since it is used
// for amino transaction verification which IBC does not support.
func (msg MsgChannelOpenTry) GetSignBytes() []byte {
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
panic("IBC messages do not support amino")
}
// GetSigners implements sdk.Msg
@ -182,9 +184,10 @@ func (msg MsgChannelOpenAck) ValidateBasic() error {
return nil
}
// GetSignBytes implements sdk.Msg
// GetSignBytes implements sdk.Msg. The function will panic since it is used
// for amino transaction verification which IBC does not support.
func (msg MsgChannelOpenAck) GetSignBytes() []byte {
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
panic("IBC messages do not support amino")
}
// GetSigners implements sdk.Msg
@ -241,9 +244,10 @@ func (msg MsgChannelOpenConfirm) ValidateBasic() error {
return nil
}
// GetSignBytes implements sdk.Msg
// GetSignBytes implements sdk.Msg. The function will panic since it is used
// for amino transaction verification which IBC does not support.
func (msg MsgChannelOpenConfirm) GetSignBytes() []byte {
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
panic("IBC messages do not support amino")
}
// GetSigners implements sdk.Msg
@ -291,9 +295,10 @@ func (msg MsgChannelCloseInit) ValidateBasic() error {
return nil
}
// GetSignBytes implements sdk.Msg
// GetSignBytes implements sdk.Msg. The function will panic since it is used
// for amino transaction verification which IBC does not support.
func (msg MsgChannelCloseInit) GetSignBytes() []byte {
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
panic("IBC messages do not support amino")
}
// GetSigners implements sdk.Msg
@ -350,9 +355,10 @@ func (msg MsgChannelCloseConfirm) ValidateBasic() error {
return nil
}
// GetSignBytes implements sdk.Msg
// GetSignBytes implements sdk.Msg. The function will panic since it is used
// for amino transaction verification which IBC does not support.
func (msg MsgChannelCloseConfirm) GetSignBytes() []byte {
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
panic("IBC messages do not support amino")
}
// GetSigners implements sdk.Msg
@ -400,9 +406,10 @@ func (msg MsgRecvPacket) ValidateBasic() error {
return msg.Packet.ValidateBasic()
}
// GetSignBytes implements sdk.Msg
// GetSignBytes implements sdk.Msg. The function will panic since it is used
// for amino transaction verification which IBC does not support.
func (msg MsgRecvPacket) GetSignBytes() []byte {
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
panic("IBC messages do not support amino")
}
// GetDataSignBytes returns the base64-encoded bytes used for the
@ -463,9 +470,10 @@ func (msg MsgTimeout) ValidateBasic() error {
return msg.Packet.ValidateBasic()
}
// GetSignBytes implements sdk.Msg
// GetSignBytes implements sdk.Msg. The function will panic since it is used
// for amino transaction verification which IBC does not support.
func (msg MsgTimeout) GetSignBytes() []byte {
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
panic("IBC messages do not support amino")
}
// GetSigners implements sdk.Msg
@ -522,9 +530,10 @@ func (msg MsgTimeoutOnClose) ValidateBasic() error {
return msg.Packet.ValidateBasic()
}
// GetSignBytes implements sdk.Msg
// GetSignBytes implements sdk.Msg. The function will panic since it is used
// for amino transaction verification which IBC does not support.
func (msg MsgTimeoutOnClose) GetSignBytes() []byte {
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
panic("IBC messages do not support amino")
}
// GetSigners implements sdk.Msg
@ -576,9 +585,10 @@ func (msg MsgAcknowledgement) ValidateBasic() error {
return msg.Packet.ValidateBasic()
}
// GetSignBytes implements sdk.Msg
// GetSignBytes implements sdk.Msg. The function will panic since it is used
// for amino transaction verification which IBC does not support.
func (msg MsgAcknowledgement) GetSignBytes() []byte {
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
panic("IBC messages do not support amino")
}
// GetSigners implements sdk.Msg

View File

@ -346,18 +346,6 @@ func (suite *TypesTestSuite) TestMsgRecvPacketValidateBasic() {
}
}
func (suite *TypesTestSuite) TestMsgRecvPacketGetSignBytes() {
msg := types.NewMsgRecvPacket(packet, suite.proof, height, addr)
res := msg.GetSignBytes()
expected := fmt.Sprintf(
`{"packet":{"data":%s,"destination_channel":"testcpchannel","destination_port":"testcpport","sequence":"1","source_channel":"testchannel","source_port":"testportid","timeout_height":{"version_height":"100","version_number":"0"},"timeout_timestamp":"100"},"proof":"Co0BCi4KCmljczIzOmlhdmwSA0tFWRobChkKA0tFWRIFVkFMVUUaCwgBGAEgASoDAAICClsKDGljczIzOnNpbXBsZRIMaWF2bFN0b3JlS2V5Gj0KOwoMaWF2bFN0b3JlS2V5EiAcIiDXSHQRSvh/Wa07MYpTK0B4XtbaXtzxBED76xk0WhoJCAEYASABKgEA","proof_height":{"version_height":"1","version_number":"0"},"signer":"%s"}`,
string(msg.GetDataSignBytes()),
addr.String(),
)
suite.Equal(expected, string(res))
}
func (suite *TypesTestSuite) TestMsgRecvPacketGetSigners() {
msg := types.NewMsgRecvPacket(packet, suite.proof, height, addr)
res := msg.GetSigners()

View File

@ -1,7 +1,6 @@
package types
import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/x/ibc/core/exported"
)
@ -42,12 +41,3 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
&MerkleProof{},
)
}
var (
// SubModuleCdc references the global x/ibc/core/23-commitmentl module codec. Note, the codec should
// ONLY be used in certain instances of tests and for JSON encoding.
//
// The actual codec used for serialization should be provided to x/ibc/core/23-commitmentl and
// defined at the application level.
SubModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
)

View File

@ -30,15 +30,6 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
)
}
var (
// SubModuleCdc references the global x/ibc/light-clients/06-solomachine module codec. Note, the codec
// should ONLY be used in certain instances of tests and for JSON encoding.
//
// The actual codec used for serialization should be provided to x/ibc/light-clients/06-solomachine and
// defined at the application level.
SubModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
)
func UnmarshalSignatureData(cdc codec.BinaryMarshaler, data []byte) (signing.SignatureData, error) {
protoSigData := &signing.SignatureDescriptor_Data{}
if err := cdc.UnmarshalBinaryBare(data, protoSigData); err != nil {

View File

@ -1,7 +1,6 @@
package types
import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/x/ibc/core/exported"
)
@ -30,12 +29,3 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
&Header{},
)
}
var (
// SubModuleCdc references the global x/ibc/light-clients/07-tendermint module codec. Note, the codec should
// ONLY be used in certain instances of tests and for JSON encoding.
//
// The actual codec used for serialization should be provided to x/ibc/light-clients/07-tendermint and
// defined at the application level.
SubModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
)

View File

@ -1,7 +1,6 @@
package types
import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/x/ibc/core/exported"
)
@ -14,10 +13,3 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
&ClientState{},
)
}
var (
// SubModuleCdc references the global x/ibc/light-clients/09-localhost module codec.
// The actual codec used for serialization should be provided to x/ibc/light-clients/09-localhost and
// defined at the application level.
SubModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
)