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

chore: rename 06-solomachine type Misbehaviour to DuplicateSignatures #1093

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
40 changes: 20 additions & 20 deletions docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@
- [ConnectionStateData](#ibc.lightclients.solomachine.v2.ConnectionStateData)
- [ConsensusState](#ibc.lightclients.solomachine.v2.ConsensusState)
- [ConsensusStateData](#ibc.lightclients.solomachine.v2.ConsensusStateData)
- [DuplicateSignatures](#ibc.lightclients.solomachine.v2.DuplicateSignatures)
- [Header](#ibc.lightclients.solomachine.v2.Header)
- [HeaderData](#ibc.lightclients.solomachine.v2.HeaderData)
- [Misbehaviour](#ibc.lightclients.solomachine.v2.Misbehaviour)
- [NextSequenceRecvData](#ibc.lightclients.solomachine.v2.NextSequenceRecvData)
- [PacketAcknowledgementData](#ibc.lightclients.solomachine.v2.PacketAcknowledgementData)
- [PacketCommitmentData](#ibc.lightclients.solomachine.v2.PacketCommitmentData)
Expand Down Expand Up @@ -3680,6 +3680,25 @@ verification.



<a name="ibc.lightclients.solomachine.v2.DuplicateSignatures"></a>

### DuplicateSignatures
DuplicateSignatures defines misbehaviour for a solo machine which consists
of a sequence and two signatures over different messages at that sequence.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `client_id` | [string](#string) | | |
| `sequence` | [uint64](#uint64) | | |
| `signature_one` | [SignatureAndData](#ibc.lightclients.solomachine.v2.SignatureAndData) | | |
| `signature_two` | [SignatureAndData](#ibc.lightclients.solomachine.v2.SignatureAndData) | | |






<a name="ibc.lightclients.solomachine.v2.Header"></a>

### Header
Expand Down Expand Up @@ -3715,25 +3734,6 @@ HeaderData returns the SignBytes data for update verification.



<a name="ibc.lightclients.solomachine.v2.Misbehaviour"></a>

### Misbehaviour
Misbehaviour defines misbehaviour for a solo machine which consists
of a sequence and two signatures over different messages at that sequence.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `client_id` | [string](#string) | | |
| `sequence` | [uint64](#uint64) | | |
| `signature_one` | [SignatureAndData](#ibc.lightclients.solomachine.v2.SignatureAndData) | | |
| `signature_two` | [SignatureAndData](#ibc.lightclients.solomachine.v2.SignatureAndData) | | |






<a name="ibc.lightclients.solomachine.v2.NextSequenceRecvData"></a>

### NextSequenceRecvData
Expand Down
2 changes: 1 addition & 1 deletion modules/core/02-client/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ func (suite *TypesTestSuite) TestMsgSubmitMisbehaviour_ValidateBasic() {
{
"invalid solomachine misbehaviour",
func() {
msg, err = types.NewMsgSubmitMisbehaviour("solomachine", &solomachinetypes.Misbehaviour{}, suite.chainA.SenderAccount.GetAddress().String())
msg, err = types.NewMsgSubmitMisbehaviour("solomachine", &solomachinetypes.DuplicateSignatures{}, suite.chainA.SenderAccount.GetAddress().String())
suite.Require().NoError(err)
},
false,
Expand Down
2 changes: 1 addition & 1 deletion modules/light-clients/06-solomachine/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
)
registry.RegisterImplementations(
(*exported.Misbehaviour)(nil),
&Misbehaviour{},
&DuplicateSignatures{},
)
}

Expand Down
24 changes: 12 additions & 12 deletions modules/light-clients/06-solomachine/types/misbehaviour.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,48 @@ import (
"github.com/cosmos/ibc-go/v3/modules/core/exported"
)

var _ exported.Misbehaviour = &Misbehaviour{}
var _ exported.Misbehaviour = &DuplicateSignatures{}
Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't rename the flies. I figure if the naming for Misbehaviour interface is kept then it's probably fine, otherwise I can update the file name appropriately to something like duplicate_signatures.go. cc. @colin-axner

Copy link
Contributor

Choose a reason for hiding this comment

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

we can do it in a follow up if we so choose


// ClientType is a Solo Machine light client.
func (misbehaviour Misbehaviour) ClientType() string {
func (ds DuplicateSignatures) ClientType() string {
return exported.Solomachine
}

// GetClientID returns the ID of the client that committed a misbehaviour.
func (misbehaviour Misbehaviour) GetClientID() string {
return misbehaviour.ClientId
func (ds DuplicateSignatures) GetClientID() string {
return ds.ClientId
}

// Type implements Evidence interface.
func (misbehaviour Misbehaviour) Type() string {
func (ds DuplicateSignatures) Type() string {
return exported.TypeClientMisbehaviour
}

// ValidateBasic implements Evidence interface.
damiannolan marked this conversation as resolved.
Show resolved Hide resolved
func (misbehaviour Misbehaviour) ValidateBasic() error {
if err := host.ClientIdentifierValidator(misbehaviour.ClientId); err != nil {
func (ds DuplicateSignatures) ValidateBasic() error {
if err := host.ClientIdentifierValidator(ds.ClientId); err != nil {
return sdkerrors.Wrap(err, "invalid client identifier for solo machine")
}

if misbehaviour.Sequence == 0 {
if ds.Sequence == 0 {
return sdkerrors.Wrap(clienttypes.ErrInvalidMisbehaviour, "sequence cannot be 0")
}

if err := misbehaviour.SignatureOne.ValidateBasic(); err != nil {
if err := ds.SignatureOne.ValidateBasic(); err != nil {
return sdkerrors.Wrap(err, "signature one failed basic validation")
}

if err := misbehaviour.SignatureTwo.ValidateBasic(); err != nil {
if err := ds.SignatureTwo.ValidateBasic(); err != nil {
return sdkerrors.Wrap(err, "signature two failed basic validation")
}

// misbehaviour signatures cannot be identical
if bytes.Equal(misbehaviour.SignatureOne.Signature, misbehaviour.SignatureTwo.Signature) {
if bytes.Equal(ds.SignatureOne.Signature, ds.SignatureTwo.Signature) {
return sdkerrors.Wrap(clienttypes.ErrInvalidMisbehaviour, "misbehaviour signatures cannot be equal")
}

// message data signed cannot be identical
if bytes.Equal(misbehaviour.SignatureOne.Data, misbehaviour.SignatureTwo.Data) {
if bytes.Equal(ds.SignatureOne.Data, ds.SignatureTwo.Data) {
return sdkerrors.Wrap(clienttypes.ErrInvalidMisbehaviour, "misbehaviour signature data must be signed over different messages")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ func (cs ClientState) CheckMisbehaviourAndUpdateState(
misbehaviour exported.Misbehaviour,
) (exported.ClientState, error) {

soloMisbehaviour, ok := misbehaviour.(*Misbehaviour)
soloMisbehaviour, ok := misbehaviour.(*DuplicateSignatures)
if !ok {
return nil, sdkerrors.Wrapf(
clienttypes.ErrInvalidClientType,
"misbehaviour type %T, expected %T", misbehaviour, &Misbehaviour{},
"misbehaviour type %T, expected %T", misbehaviour, &DuplicateSignatures{},
)
}

Expand All @@ -50,7 +50,7 @@ func (cs ClientState) CheckMisbehaviourAndUpdateState(
// verifySignatureAndData verifies that the currently registered public key has signed
// over the provided data and that the data is valid. The data is valid if it can be
// unmarshaled into the specified data type.
func verifySignatureAndData(cdc codec.BinaryCodec, clientState ClientState, misbehaviour *Misbehaviour, sigAndData *SignatureAndData) error {
func verifySignatureAndData(cdc codec.BinaryCodec, clientState ClientState, misbehaviour *DuplicateSignatures, sigAndData *SignatureAndData) error {

// do not check misbehaviour timestamp since we want to allow processing of past misbehaviour

Expand Down
44 changes: 22 additions & 22 deletions modules/light-clients/06-solomachine/types/misbehaviour_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,91 +19,91 @@ func (suite *SoloMachineTestSuite) TestMisbehaviourValidateBasic() {

testCases := []struct {
name string
malleateMisbehaviour func(misbehaviour *types.Misbehaviour)
malleateMisbehaviour func(duplicateSigHeader *types.DuplicateSignatures)
expPass bool
}{
{
"valid misbehaviour",
func(*types.Misbehaviour) {},
func(*types.DuplicateSignatures) {},
true,
},
{
"invalid client ID",
func(misbehaviour *types.Misbehaviour) {
misbehaviour.ClientId = "(badclientid)"
func(duplicateSigHeader *types.DuplicateSignatures) {
duplicateSigHeader.ClientId = "(badclientid)"
},
false,
},
{
"sequence is zero",
func(misbehaviour *types.Misbehaviour) {
misbehaviour.Sequence = 0
func(duplicateSigHeader *types.DuplicateSignatures) {
duplicateSigHeader.Sequence = 0
},
false,
},
{
"signature one sig is empty",
func(misbehaviour *types.Misbehaviour) {
misbehaviour.SignatureOne.Signature = []byte{}
func(duplicateSigHeader *types.DuplicateSignatures) {
duplicateSigHeader.SignatureOne.Signature = []byte{}
},
false,
},
{
"signature two sig is empty",
func(misbehaviour *types.Misbehaviour) {
misbehaviour.SignatureTwo.Signature = []byte{}
func(duplicateSigHeader *types.DuplicateSignatures) {
duplicateSigHeader.SignatureTwo.Signature = []byte{}
},
false,
},
{
"signature one data is empty",
func(misbehaviour *types.Misbehaviour) {
misbehaviour.SignatureOne.Data = nil
func(duplicateSigHeader *types.DuplicateSignatures) {
duplicateSigHeader.SignatureOne.Data = nil
},
false,
},
{
"signature two data is empty",
func(misbehaviour *types.Misbehaviour) {
misbehaviour.SignatureTwo.Data = []byte{}
func(duplicateSigHeader *types.DuplicateSignatures) {
duplicateSigHeader.SignatureTwo.Data = []byte{}
},
false,
},
{
"signatures are identical",
func(misbehaviour *types.Misbehaviour) {
misbehaviour.SignatureTwo.Signature = misbehaviour.SignatureOne.Signature
func(duplicateSigHeader *types.DuplicateSignatures) {
duplicateSigHeader.SignatureTwo.Signature = duplicateSigHeader.SignatureOne.Signature
},
false,
},
{
"data signed is identical",
func(misbehaviour *types.Misbehaviour) {
misbehaviour.SignatureTwo.Data = misbehaviour.SignatureOne.Data
func(duplicateSigHeader *types.DuplicateSignatures) {
duplicateSigHeader.SignatureTwo.Data = duplicateSigHeader.SignatureOne.Data
},
false,
},
{
"data type for SignatureOne is unspecified",
func(misbehaviour *types.Misbehaviour) {
func(misbehaviour *types.DuplicateSignatures) {
misbehaviour.SignatureOne.DataType = types.UNSPECIFIED
}, false,
},
{
"data type for SignatureTwo is unspecified",
func(misbehaviour *types.Misbehaviour) {
func(misbehaviour *types.DuplicateSignatures) {
misbehaviour.SignatureTwo.DataType = types.UNSPECIFIED
}, false,
},
{
"timestamp for SignatureOne is zero",
func(misbehaviour *types.Misbehaviour) {
func(misbehaviour *types.DuplicateSignatures) {
misbehaviour.SignatureOne.Timestamp = 0
}, false,
},
{
"timestamp for SignatureTwo is zero",
func(misbehaviour *types.Misbehaviour) {
func(misbehaviour *types.DuplicateSignatures) {
misbehaviour.SignatureTwo.Timestamp = 0
}, false,
},
Expand Down
Loading