-
Notifications
You must be signed in to change notification settings - Fork 580
/
misbehaviour_handle.go
75 lines (60 loc) · 2.39 KB
/
misbehaviour_handle.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
package solomachine
import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
)
// CheckForMisbehaviour returns true for type Misbehaviour (passed VerifyClientMessage check), otherwise returns false
func (cs ClientState) CheckForMisbehaviour(_ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, clientMsg exported.ClientMessage) bool {
if _, ok := clientMsg.(*Misbehaviour); ok {
return true
}
return false
}
func (cs ClientState) verifyMisbehaviour(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, misbehaviour *Misbehaviour) error {
// NOTE: a check that the misbehaviour message data are not equal is done by
// misbehaviour.ValidateBasic which is called by the 02-client keeper.
// verify first signature
if err := cs.verifySignatureAndData(cdc, misbehaviour, misbehaviour.SignatureOne); err != nil {
return sdkerrors.Wrap(err, "failed to verify signature one")
}
// verify second signature
if err := cs.verifySignatureAndData(cdc, misbehaviour, misbehaviour.SignatureTwo); err != nil {
return sdkerrors.Wrap(err, "failed to verify signature two")
}
return nil
}
// 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 (cs ClientState) verifySignatureAndData(cdc codec.BinaryCodec, misbehaviour *Misbehaviour, sigAndData *SignatureAndData) error {
// do not check misbehaviour timestamp since we want to allow processing of past misbehaviour
if err := cdc.Unmarshal(sigAndData.Path, new(commitmenttypes.MerklePath)); err != nil {
return err
}
signBytes := SignBytes{
Sequence: misbehaviour.Sequence,
Timestamp: sigAndData.Timestamp,
Diversifier: cs.ConsensusState.Diversifier,
Path: sigAndData.Path,
Data: sigAndData.Data,
}
data, err := cdc.Marshal(&signBytes)
if err != nil {
return err
}
sigData, err := UnmarshalSignatureData(cdc, sigAndData.Signature)
if err != nil {
return err
}
publicKey, err := cs.ConsensusState.GetPubKey()
if err != nil {
return err
}
if err := VerifySignature(publicKey, data, sigData); err != nil {
return err
}
return nil
}