From a0febb64fa1498fad74fd032847e90a2a9ca6b1a Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Fri, 21 Jul 2023 22:20:17 +0200 Subject: [PATCH] add ClientMessage from #4049 --- modules/light-clients/08-wasm/go.mod | 2 +- .../08-wasm/types/client_message.go | 23 ++ modules/light-clients/08-wasm/types/errors.go | 15 +- .../08-wasm/types/misbehaviour_handle.go | 7 +- modules/light-clients/08-wasm/types/msgs.go | 8 +- modules/light-clients/08-wasm/types/update.go | 22 +- .../light-clients/08-wasm/types/wasm.pb.go | 213 ++++++++++++++++-- proto/ibc/lightclients/wasm/v1/wasm.proto | 7 + 8 files changed, 256 insertions(+), 41 deletions(-) create mode 100644 modules/light-clients/08-wasm/types/client_message.go diff --git a/modules/light-clients/08-wasm/go.mod b/modules/light-clients/08-wasm/go.mod index b9bdaab2229..5b333a42aa0 100644 --- a/modules/light-clients/08-wasm/go.mod +++ b/modules/light-clients/08-wasm/go.mod @@ -10,6 +10,7 @@ require ( cosmossdk.io/errors v1.0.0-beta.7 github.com/CosmWasm/wasmvm v1.2.4 github.com/cometbft/cometbft v0.37.2 + github.com/cometbft/cometbft-db v0.8.0 github.com/cosmos/cosmos-sdk v0.47.3 github.com/cosmos/gogoproto v1.4.10 github.com/cosmos/ibc-go/v7 v7.2.0 @@ -49,7 +50,6 @@ require ( github.com/chzyer/readline v1.5.1 // indirect github.com/cockroachdb/apd/v2 v2.0.2 // indirect github.com/coinbase/rosetta-sdk-go/types v1.0.0 // indirect - github.com/cometbft/cometbft-db v0.8.0 // indirect github.com/confio/ics23/go v0.9.0 // indirect github.com/cosmos/btcutil v1.0.5 // indirect github.com/cosmos/cosmos-proto v1.0.0-beta.2 // indirect diff --git a/modules/light-clients/08-wasm/types/client_message.go b/modules/light-clients/08-wasm/types/client_message.go new file mode 100644 index 00000000000..ef06129afcb --- /dev/null +++ b/modules/light-clients/08-wasm/types/client_message.go @@ -0,0 +1,23 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + + "github.com/cosmos/ibc-go/v7/modules/core/exported" +) + +var _ exported.ClientMessage = &ClientMessage{} + +// ClientType defines that the client message is a Wasm client consensus algorithm +func (h ClientMessage) ClientType() string { + return exported.Wasm +} + +// ValidateBasic defines a basic validation for the wasm client message. +func (h ClientMessage) ValidateBasic() error { + if len(h.Data) == 0 { + return errorsmod.Wrap(ErrInvalidData, "data cannot be empty") + } + + return nil +} diff --git a/modules/light-clients/08-wasm/types/errors.go b/modules/light-clients/08-wasm/types/errors.go index 44d31fbe688..6c34228a515 100644 --- a/modules/light-clients/08-wasm/types/errors.go +++ b/modules/light-clients/08-wasm/types/errors.go @@ -3,12 +3,13 @@ package types import errorsmod "cosmossdk.io/errors" var ( - ErrInvalid = errorsmod.Register(ModuleName, 1, "invalid") - ErrInvalidData = errorsmod.Register(ModuleName, 2, "invalid data") - ErrInvalidCodeID = errorsmod.Register(ModuleName, 3, "invalid code ID") + ErrInvalid = errorsmod.Register(ModuleName, 1, "invalid") + ErrInvalidData = errorsmod.Register(ModuleName, 2, "invalid data") + ErrInvalidCodeID = errorsmod.Register(ModuleName, 3, "invalid code ID") + ErrInvalidClientMessage = errorsmod.Register(ModuleName, 4, "invalid client message") // Wasm specific - ErrWasmEmptyCode = errorsmod.Register(ModuleName, 4, "empty wasm code") - ErrWasmCodeTooLarge = errorsmod.Register(ModuleName, 5, "wasm code too large") - ErrWasmCodeExists = errorsmod.Register(ModuleName, 6, "wasm code already exists") - ErrWasmCodeIDNotFound = errorsmod.Register(ModuleName, 7, "wasm code id not found") + ErrWasmEmptyCode = errorsmod.Register(ModuleName, 5, "empty wasm code") + ErrWasmCodeTooLarge = errorsmod.Register(ModuleName, 6, "wasm code too large") + ErrWasmCodeExists = errorsmod.Register(ModuleName, 7, "wasm code already exists") + ErrWasmCodeIDNotFound = errorsmod.Register(ModuleName, 8, "wasm code id not found") ) diff --git a/modules/light-clients/08-wasm/types/misbehaviour_handle.go b/modules/light-clients/08-wasm/types/misbehaviour_handle.go index 77c698b6fec..7e860f532af 100644 --- a/modules/light-clients/08-wasm/types/misbehaviour_handle.go +++ b/modules/light-clients/08-wasm/types/misbehaviour_handle.go @@ -10,8 +10,13 @@ import ( // CheckForMisbehaviour detects misbehaviour in a submitted Header message and verifies // the correctness of a submitted Misbehaviour ClientMessage func (cs ClientState) CheckForMisbehaviour(ctx sdk.Context, _ codec.BinaryCodec, clientStore sdk.KVStore, clientMsg exported.ClientMessage) bool { + clientMessage, ok := clientMsg.(*ClientMessage) + if !ok { + return false + } + payload := QueryMsg{ - CheckForMisbehaviour: &checkForMisbehaviourMsg{ClientMessage: clientMsg}, + CheckForMisbehaviour: &checkForMisbehaviourMsg{ClientMessage: clientMessage}, } result, err := call[contractResult](ctx, clientStore, &cs, payload) diff --git a/modules/light-clients/08-wasm/types/msgs.go b/modules/light-clients/08-wasm/types/msgs.go index 2b1f45c9992..ff64e5c2456 100644 --- a/modules/light-clients/08-wasm/types/msgs.go +++ b/modules/light-clients/08-wasm/types/msgs.go @@ -53,7 +53,7 @@ type ( Height exported.Height `json:"height"` } verifyClientMessageMsg struct { - ClientMessage exported.ClientMessage `json:"client_message"` + ClientMessage *ClientMessage `json:"client_message"` } verifyMembershipMsg struct { Height exported.Height `json:"height"` @@ -71,7 +71,7 @@ type ( Path exported.Path `json:"path"` } checkForMisbehaviourMsg struct { - ClientMessage exported.ClientMessage `json:"client_message"` + ClientMessage *ClientMessage `json:"client_message"` } ) @@ -89,10 +89,10 @@ type ( ConsensusState *ConsensusState `json:"consensus_state"` } updateStateMsg struct { - ClientMessage exported.ClientMessage `json:"client_message"` + ClientMessage *ClientMessage `json:"client_message"` } updateStateOnMisbehaviourMsg struct { - ClientMessage exported.ClientMessage `json:"client_message"` + ClientMessage *ClientMessage `json:"client_message"` } verifyUpgradeAndUpdateStateMsg struct { UpgradeClientState exported.ClientState `json:"upgrade_client_state"` diff --git a/modules/light-clients/08-wasm/types/update.go b/modules/light-clients/08-wasm/types/update.go index 873234ff4f0..b0646b75338 100644 --- a/modules/light-clients/08-wasm/types/update.go +++ b/modules/light-clients/08-wasm/types/update.go @@ -3,6 +3,8 @@ package types import ( "fmt" + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -16,8 +18,13 @@ var _ exported.ClientState = (*ClientState)(nil) // will assume that the content of the ClientMessage has been verified and can be trusted. An error should be returned // if the ClientMessage fails to verify. func (cs ClientState) VerifyClientMessage(ctx sdk.Context, _ codec.BinaryCodec, clientStore sdk.KVStore, clientMsg exported.ClientMessage) error { + clientMessage, ok := clientMsg.(*ClientMessage) + if !ok { + return errorsmod.Wrapf(ErrInvalidClientMessage, "expected type %T, got %T", &ClientMessage{}, clientMsg) + } + payload := QueryMsg{ - VerifyClientMessage: &verifyClientMessageMsg{ClientMessage: clientMsg}, + VerifyClientMessage: &verifyClientMessageMsg{ClientMessage: clientMessage}, } _, err := call[contractResult](ctx, clientStore, &cs, payload) return err @@ -25,13 +32,13 @@ func (cs ClientState) VerifyClientMessage(ctx sdk.Context, _ codec.BinaryCodec, // Client state and new consensus states are updated in the store by the contract func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, clientMsg exported.ClientMessage) []exported.Height { - _, ok := clientMsg.(*Header) + clientMessage, ok := clientMsg.(*ClientMessage) if !ok { - panic(fmt.Errorf("expected type %T, got %T", &Header{}, clientMsg)) + panic(fmt.Errorf("expected type %T, got %T", &ClientMessage{}, clientMsg)) } payload := SudoMsg{ - UpdateState: &updateStateMsg{ClientMessage: clientMsg}, + UpdateState: &updateStateMsg{ClientMessage: clientMessage}, } _, err := call[contractResult](ctx, clientStore, &cs, payload) @@ -45,8 +52,13 @@ func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, client // UpdateStateOnMisbehaviour should perform appropriate state changes on a client state given that misbehaviour has been detected and verified // Client state is updated in the store by contract. func (cs ClientState) UpdateStateOnMisbehaviour(ctx sdk.Context, _ codec.BinaryCodec, clientStore sdk.KVStore, clientMsg exported.ClientMessage) { + clientMessage, ok := clientMsg.(*ClientMessage) + if !ok { + panic(fmt.Errorf("expected type %T, got %T", &ClientMessage{}, clientMsg)) + } + payload := SudoMsg{ - UpdateStateOnMisbehaviour: &updateStateOnMisbehaviourMsg{ClientMessage: clientMsg}, + UpdateStateOnMisbehaviour: &updateStateOnMisbehaviourMsg{ClientMessage: clientMessage}, } _, err := call[contractResult](ctx, clientStore, &cs, payload) diff --git a/modules/light-clients/08-wasm/types/wasm.pb.go b/modules/light-clients/08-wasm/types/wasm.pb.go index 4854d71ae89..e92c876d353 100644 --- a/modules/light-clients/08-wasm/types/wasm.pb.go +++ b/modules/light-clients/08-wasm/types/wasm.pb.go @@ -186,11 +186,50 @@ func (m *Misbehaviour) XXX_DiscardUnknown() { var xxx_messageInfo_Misbehaviour proto.InternalMessageInfo +// Wasm light client message (either header(s) or misbehaviour) +type ClientMessage struct { + Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` +} + +func (m *ClientMessage) Reset() { *m = ClientMessage{} } +func (m *ClientMessage) String() string { return proto.CompactTextString(m) } +func (*ClientMessage) ProtoMessage() {} +func (*ClientMessage) Descriptor() ([]byte, []int) { + return fileDescriptor_678928ebbdee1807, []int{4} +} +func (m *ClientMessage) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ClientMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ClientMessage.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 *ClientMessage) XXX_Merge(src proto.Message) { + xxx_messageInfo_ClientMessage.Merge(m, src) +} +func (m *ClientMessage) XXX_Size() int { + return m.Size() +} +func (m *ClientMessage) XXX_DiscardUnknown() { + xxx_messageInfo_ClientMessage.DiscardUnknown(m) +} + +var xxx_messageInfo_ClientMessage proto.InternalMessageInfo + func init() { proto.RegisterType((*ClientState)(nil), "ibc.lightclients.wasm.v1.ClientState") proto.RegisterType((*ConsensusState)(nil), "ibc.lightclients.wasm.v1.ConsensusState") proto.RegisterType((*Header)(nil), "ibc.lightclients.wasm.v1.Header") proto.RegisterType((*Misbehaviour)(nil), "ibc.lightclients.wasm.v1.Misbehaviour") + proto.RegisterType((*ClientMessage)(nil), "ibc.lightclients.wasm.v1.ClientMessage") } func init() { @@ -198,30 +237,31 @@ func init() { } var fileDescriptor_678928ebbdee1807 = []byte{ - // 358 bytes of a gzipped FileDescriptorProto + // 371 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xc1, 0x4a, 0xc3, 0x30, - 0x1c, 0xc6, 0x9b, 0x59, 0x2a, 0x66, 0xd3, 0x43, 0x11, 0x2c, 0x43, 0xba, 0x31, 0x2f, 0xbb, 0x2c, - 0x71, 0x7a, 0x19, 0xe2, 0x69, 0x43, 0x98, 0x07, 0x2f, 0x13, 0x3c, 0x88, 0x30, 0xd2, 0x34, 0xb4, - 0x81, 0x76, 0x19, 0x4b, 0x5a, 0xf1, 0x09, 0xf4, 0xe8, 0x23, 0xf8, 0x38, 0x3b, 0xee, 0xe8, 0x49, - 0x64, 0x7b, 0x11, 0x49, 0x52, 0xd1, 0xc3, 0x04, 0x4f, 0xfd, 0xf7, 0xcb, 0x2f, 0xdf, 0xff, 0x83, - 0x7c, 0xf0, 0x84, 0x47, 0x14, 0x67, 0x3c, 0x49, 0x15, 0xcd, 0x38, 0x9b, 0x29, 0x89, 0x1f, 0x89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4b, 0x0e, 0xef, 0x96, 0xeb, 0x10, 0xac, 0xd6, 0x21, - 0xf8, 0x5c, 0x87, 0xe0, 0x75, 0x13, 0x3a, 0xab, 0x4d, 0xe8, 0xbc, 0x6f, 0x42, 0xe7, 0xfe, 0x32, - 0xe1, 0x2a, 0x2d, 0x22, 0x44, 0x45, 0x8e, 0xa9, 0x90, 0xb9, 0x90, 0x98, 0x47, 0xb4, 0x97, 0x08, - 0x9c, 0x8b, 0xb8, 0xc8, 0x98, 0xb4, 0x45, 0xe8, 0x7d, 0x37, 0xe1, 0x74, 0xd0, 0x33, 0x65, 0x50, - 0x4f, 0x73, 0x26, 0x23, 0xcf, 0x3c, 0xdd, 0xf9, 0x57, 0x00, 0x00, 0x00, 0xff, 0xff, 0xd1, 0x14, - 0x16, 0xed, 0x32, 0x02, 0x00, 0x00, + 0x18, 0xc7, 0xdb, 0x59, 0x2a, 0x66, 0x9b, 0x87, 0x22, 0x58, 0x86, 0x74, 0x63, 0x5e, 0xe6, 0x61, + 0x8d, 0xd3, 0xcb, 0x10, 0x4f, 0x1b, 0xc2, 0x3c, 0xec, 0x32, 0xc1, 0x83, 0x08, 0x23, 0x4d, 0x3f, + 0xda, 0x40, 0xbb, 0x8c, 0x25, 0xad, 0xf8, 0x04, 0x7a, 0xf4, 0x11, 0x7c, 0x9c, 0x1d, 0x77, 0xf4, + 0x24, 0xb2, 0xbd, 0x88, 0x34, 0xa9, 0xe8, 0x61, 0x03, 0x4f, 0xf9, 0xf2, 0xcf, 0x2f, 0xff, 0xef, + 0x4f, 0xf2, 0xa1, 0x53, 0x16, 0x50, 0x9c, 0xb0, 0x28, 0x96, 0x34, 0x61, 0x30, 0x93, 0x02, 0x3f, + 0x11, 0x91, 0xe2, 0xbc, 0xa7, 0x56, 0x7f, 0xbe, 0xe0, 0x92, 0x3b, 0x2e, 0x0b, 0xa8, 0xff, 0x17, + 0xf2, 0xd5, 0x61, 0xde, 0x6b, 0x1c, 0x45, 0x3c, 0xe2, 0x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0x9e, + 0xf9, 0xb6, 0xf1, 0x8c, 0xd5, 0xc6, 0x33, 0x3e, 0x36, 0x9e, 0xf1, 0x70, 0x1d, 0x31, 0x19, 0x67, + 0x81, 0x4f, 0x79, 0x8a, 0x29, 0x17, 0x29, 0x17, 0x98, 0x05, 0xb4, 0x1b, 0x71, 0x9c, 0xf2, 0x30, + 0x4b, 0x40, 0xe8, 0x99, 0xe9, 0xfe, 0x0c, 0xcd, 0x79, 0xbf, 0xab, 0xe6, 0x46, 0x3e, 0xcf, 0x41, + 0x04, 0xb6, 0xfa, 0xe5, 0xcb, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0x38, 0xaf, 0x41, 0x5c, 0x5d, + 0x02, 0x00, 0x00, } func (m *ClientState) Marshal() (dAtA []byte, err error) { @@ -376,6 +416,36 @@ func (m *Misbehaviour) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *ClientMessage) 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 *ClientMessage) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ClientMessage) 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 = encodeVarintWasm(dAtA, i, uint64(len(m.Data))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintWasm(dAtA []byte, offset int, v uint64) int { offset -= sovWasm(v) base := offset @@ -450,6 +520,19 @@ func (m *Misbehaviour) Size() (n int) { return n } +func (m *ClientMessage) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Data) + if l > 0 { + n += 1 + l + sovWasm(uint64(l)) + } + return n +} + func sovWasm(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -911,6 +994,90 @@ func (m *Misbehaviour) Unmarshal(dAtA []byte) error { } return nil } +func (m *ClientMessage) 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 ErrIntOverflowWasm + } + 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: ClientMessage: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ClientMessage: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + 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 ErrIntOverflowWasm + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthWasm + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthWasm + } + 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 := skipWasm(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthWasm + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipWasm(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/proto/ibc/lightclients/wasm/v1/wasm.proto b/proto/ibc/lightclients/wasm/v1/wasm.proto index 643957549a8..8a4452cba2a 100644 --- a/proto/ibc/lightclients/wasm/v1/wasm.proto +++ b/proto/ibc/lightclients/wasm/v1/wasm.proto @@ -43,3 +43,10 @@ message Misbehaviour { bytes data = 1; } + +// Wasm light client message (either header(s) or misbehaviour) +message ClientMessage { + option (gogoproto.goproto_getters) = false; + + bytes data = 1; +} \ No newline at end of file