/
misbehaviour.go
77 lines (61 loc) · 2.48 KB
/
misbehaviour.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package types
import (
"bytes"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types"
host "github.com/cosmos/ibc-go/v6/modules/core/24-host"
"github.com/cosmos/ibc-go/v6/modules/core/exported"
)
var _ exported.Misbehaviour = &Misbehaviour{}
// ClientType is a Solo Machine light client.
func (misbehaviour Misbehaviour) ClientType() string {
return exported.Solomachine
}
// GetClientID returns the ID of the client that committed a misbehaviour.
func (misbehaviour Misbehaviour) GetClientID() string {
return misbehaviour.ClientId
}
// Type implements Evidence interface.
func (misbehaviour Misbehaviour) Type() string {
return exported.TypeClientMisbehaviour
}
// ValidateBasic implements Evidence interface.
func (misbehaviour Misbehaviour) ValidateBasic() error {
if err := host.ClientIdentifierValidator(misbehaviour.ClientId); err != nil {
return sdkerrors.Wrap(err, "invalid client identifier for solo machine")
}
if misbehaviour.Sequence == 0 {
return sdkerrors.Wrap(clienttypes.ErrInvalidMisbehaviour, "sequence cannot be 0")
}
if err := misbehaviour.SignatureOne.ValidateBasic(); err != nil {
return sdkerrors.Wrap(err, "signature one failed basic validation")
}
if err := misbehaviour.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) {
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) {
return sdkerrors.Wrap(clienttypes.ErrInvalidMisbehaviour, "misbehaviour signature data must be signed over different messages")
}
return nil
}
// ValidateBasic ensures that the signature and data fields are non-empty.
func (sd SignatureAndData) ValidateBasic() error {
if len(sd.Signature) == 0 {
return sdkerrors.Wrap(ErrInvalidSignatureAndData, "signature cannot be empty")
}
if len(sd.Data) == 0 {
return sdkerrors.Wrap(ErrInvalidSignatureAndData, "data for signature cannot be empty")
}
if sd.DataType == UNSPECIFIED {
return sdkerrors.Wrap(ErrInvalidSignatureAndData, "data type cannot be UNSPECIFIED")
}
if sd.Timestamp == 0 {
return sdkerrors.Wrap(ErrInvalidSignatureAndData, "timestamp cannot be 0")
}
return nil
}