mukan-ibc/modules/light-clients/06-solomachine/misbehaviour_handle.go
Mukan Erkin Törük 88dd97a9f8
Some checks failed
CodeQL / Analyze (push) Waiting to run
golangci-lint / lint (push) Waiting to run
Tests / Code Coverage / build (amd64) (push) Waiting to run
Tests / Code Coverage / build (arm64) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[additional-args:-tags="test_e2e" name:e2e path:./e2e]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:08-wasm path:./modules/light-clients/08-wasm]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:ibc-go path:.]) (push) Waiting to run
Docker Build & Push Simapp (main) / docker-build (push) Has been cancelled
refactor: replace all github.com upstream refs with git.cw.tr/mukan-network
2026-05-11 03:36:22 +03:00

72 lines
2.4 KiB
Go

package solomachine
import (
errorsmod "cosmossdk.io/errors"
storetypes "cosmossdk.io/store/types"
"git.cw.tr/mukan-network/mukan-sdk/codec"
sdk "git.cw.tr/mukan-network/mukan-sdk/types"
commitmenttypesv2 "git.cw.tr/mukan-network/mukan-ibc/modules/core/23-commitment/types/v2"
"git.cw.tr/mukan-network/mukan-ibc/modules/core/exported"
)
// CheckForMisbehaviour returns true for type Misbehaviour (passed VerifyClientMessage check), otherwise returns false
func (ClientState) CheckForMisbehaviour(_ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, clientMsg exported.ClientMessage) bool {
if _, ok := clientMsg.(*Misbehaviour); ok {
return true
}
return false
}
func (cs ClientState) verifyMisbehaviour(cdc codec.BinaryCodec, 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 errorsmod.Wrap(err, "failed to verify signature one")
}
// verify second signature
if err := cs.verifySignatureAndData(cdc, misbehaviour, misbehaviour.SignatureTwo); err != nil {
return errorsmod.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(commitmenttypesv2.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
}
return VerifySignature(publicKey, data, sigData)
}