-
Notifications
You must be signed in to change notification settings - Fork 587
/
misbehaviour.go
68 lines (54 loc) · 2.18 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
package solomachine
import (
"bytes"
errorsmod "cosmossdk.io/errors"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
"github.com/cosmos/ibc-go/v8/modules/core/exported"
)
var _ exported.ClientMessage = (*Misbehaviour)(nil)
// ClientType is a Solo Machine light client.
func (Misbehaviour) ClientType() string {
return exported.Solomachine
}
// Type implements Misbehaviour interface.
func (Misbehaviour) Type() string {
return exported.TypeClientMisbehaviour
}
// ValidateBasic implements Misbehaviour interface.
func (misbehaviour Misbehaviour) ValidateBasic() error {
if misbehaviour.Sequence == 0 {
return errorsmod.Wrap(clienttypes.ErrInvalidMisbehaviour, "sequence cannot be 0")
}
if err := misbehaviour.SignatureOne.ValidateBasic(); err != nil {
return errorsmod.Wrap(err, "signature one failed basic validation")
}
if err := misbehaviour.SignatureTwo.ValidateBasic(); err != nil {
return errorsmod.Wrap(err, "signature two failed basic validation")
}
// misbehaviour signatures cannot be identical.
if bytes.Equal(misbehaviour.SignatureOne.Signature, misbehaviour.SignatureTwo.Signature) {
return errorsmod.Wrap(clienttypes.ErrInvalidMisbehaviour, "misbehaviour signatures cannot be equal")
}
// message data signed cannot be identical if both paths are the same.
if bytes.Equal(misbehaviour.SignatureOne.Path, misbehaviour.SignatureTwo.Path) &&
bytes.Equal(misbehaviour.SignatureOne.Data, misbehaviour.SignatureTwo.Data) {
return errorsmod.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 errorsmod.Wrap(ErrInvalidSignatureAndData, "signature cannot be empty")
}
if len(sd.Data) == 0 {
return errorsmod.Wrap(ErrInvalidSignatureAndData, "data for signature cannot be empty")
}
if len(sd.Path) == 0 {
return errorsmod.Wrap(ErrInvalidSignatureAndData, "path for signature cannot be empty")
}
if sd.Timestamp == 0 {
return errorsmod.Wrap(ErrInvalidSignatureAndData, "timestamp cannot be 0")
}
return nil
}