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

feat: implement misbehaviour detection #1121

Merged
merged 3 commits into from
Mar 14, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
chore: remove unnecessary import + use global tm codec
  • Loading branch information
jtieri committed Mar 13, 2023
commit f59dc4801f40a6689ba79afdec8ca997b7b1a1a1
2 changes: 0 additions & 2 deletions interchaintest/go.sum
Original file line number Diff line number Diff line change
@@ -1371,8 +1371,6 @@ github.com/spf13/viper v1.15.0/go.mod h1:fFcTBJxvhhzSJiZy8n+PeW6t8l+KeT/uTARa0jH
github.com/stefanberger/go-pkcs11uri v0.0.0-20201008174630-78d3cae3a980/go.mod h1:AO3tvPzVZ/ayst6UlUKUv6rcPQInYe3IknH3jYhAKu8=
github.com/strangelove-ventures/go-subkey v1.0.7 h1:cOP/Lajg3uxV/tvspu0m6+0Cu+DJgygkEAbx/s+f35I=
github.com/strangelove-ventures/go-subkey v1.0.7/go.mod h1:E34izOIEm+sZ1YmYawYRquqBQWeZBjVB4pF7bMuhc1c=
github.com/strangelove-ventures/interchaintest/v7 v7.0.0-20230309173441-1cbc09c52979 h1:3G0ZRyzEBF/QNYQnhg2wkIop8n1W2DBb9lofGcrmYDk=
github.com/strangelove-ventures/interchaintest/v7 v7.0.0-20230309173441-1cbc09c52979/go.mod h1:3wUe5Ik4S4AzxS6ygivmC+VY7qngf/VOSn9FmXS7Ao4=
github.com/strangelove-ventures/interchaintest/v7 v7.0.0-20230309210425-6f04be9aab19 h1:myDhIC75y5Kycqke0Go3PeRnsXvGW6fynHDGds2dKFk=
github.com/strangelove-ventures/interchaintest/v7 v7.0.0-20230309210425-6f04be9aab19/go.mod h1:DTYkHkPDFjGE0jGLSG3elpgngb9fhaCHdmM0ERRd/T4=
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
4 changes: 2 additions & 2 deletions interchaintest/misbehaviour_test.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package interchaintest_test

import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"testing"
@@ -25,7 +26,6 @@ import (
ibcmocks "github.com/cosmos/ibc-go/v7/testing/mock"
"github.com/cosmos/ibc-go/v7/testing/simapp"
relayertest "github.com/cosmos/relayer/v2/interchaintest"
"github.com/dvsekhvalnov/jose2go/base64url"
"github.com/strangelove-ventures/interchaintest/v7"
"github.com/strangelove-ventures/interchaintest/v7/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v7/ibc"
@@ -140,7 +140,7 @@ func TestScenarioMisbehaviourDetection(t *testing.T) {
err = json.Unmarshal(keyBz, &pvk)
require.NoError(t, err)

decodedKeyBz, err := base64url.Decode(pvk.PrivKey.Value)
decodedKeyBz, err := base64.StdEncoding.DecodeString(pvk.PrivKey.Value)
require.NoError(t, err)

privKey := &sdked25519.PrivKey{
47 changes: 0 additions & 47 deletions relayer/processor/codec.go

This file was deleted.

4 changes: 1 addition & 3 deletions relayer/processor/path_end_runtime.go
Original file line number Diff line number Diff line change
@@ -20,7 +20,6 @@ type pathEndRuntime struct {
info PathEnd

chainProvider provider.ChainProvider
cdc codec

// cached data
latestBlock provider.LatestBlock
@@ -61,7 +60,6 @@ func newPathEndRuntime(log *zap.Logger, pathEnd PathEnd, metrics *PrometheusMetr
zap.String("chain_id", pathEnd.ChainID),
zap.String("client_id", pathEnd.ClientID),
),
cdc: makeCodec(),
info: pathEnd,
incomingCacheData: make(chan ChainProcessorCacheData, 100),
connectionStateCache: make(ConnectionStateCache),
@@ -305,7 +303,7 @@ func (pathEnd *pathEndRuntime) checkForMisbehaviour(
) (bool, error) {
cachedHeader := counterparty.ibcHeaderCache[state.ConsensusHeight.RevisionHeight]

misbehaviour, err := provider.CheckForMisbehaviour(ctx, pathEnd.cdc.Marshaler, counterparty.chainProvider, pathEnd.info.ClientID, state.Header, cachedHeader)
misbehaviour, err := provider.CheckForMisbehaviour(ctx, counterparty.chainProvider, pathEnd.info.ClientID, state.Header, cachedHeader)
if err != nil {
return false, err
}
14 changes: 11 additions & 3 deletions relayer/provider/matcher.go
Original file line number Diff line number Diff line change
@@ -6,12 +6,21 @@ import (
"reflect"
"time"

"github.com/cosmos/cosmos-sdk/codec"
sdkcodec "github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
tmclient "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
)

var tendermintClientCodec = tmClientCodec()

func tmClientCodec() *sdkcodec.ProtoCodec {
interfaceRegistry := types.NewInterfaceRegistry()
tmclient.RegisterInterfaces(interfaceRegistry)
return sdkcodec.NewProtoCodec(interfaceRegistry)
}

// ClientsMatch will check the type of an existing light client on the src chain, tracking the dst chain, and run
// an appropriate matcher function to determine if the existing client's state matches a proposed new client
// state constructed from the dst chain.
@@ -39,7 +48,6 @@ func ClientsMatch(ctx context.Context, src, dst ChainProvider, existingClient cl
// header and the trusted header match then both returned values will be nil.
func CheckForMisbehaviour(
ctx context.Context,
cdc codec.BinaryCodec,
counterparty ChainProvider,
clientID string,
proposedHeader []byte,
@@ -50,7 +58,7 @@ func CheckForMisbehaviour(
err error
)

clientMsg, err := clienttypes.UnmarshalClientMessage(cdc, proposedHeader)
clientMsg, err := clienttypes.UnmarshalClientMessage(tendermintClientCodec, proposedHeader)
if err != nil {
return nil, err
}