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 slashing functionality on the provider chain (ADR-013) #1275

Merged
merged 31 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
93a0db5
first version
insumity Sep 7, 2023
ea87bdc
fix mocks
insumity Sep 8, 2023
177e1db
move slashing to other file and check tombstoning
insumity Sep 8, 2023
e1bdfff
add tests that checks that Slash is called
insumity Sep 11, 2023
bbff2ee
add FIXME msg
insumity Sep 11, 2023
dfef410
small changes
insumity Sep 11, 2023
8b49af1
add fixme
insumity Sep 11, 2023
bf89509
fix test
insumity Sep 11, 2023
868e0d2
modified E2E tests and general cleaning up
insumity Sep 12, 2023
9ba3a3d
clean up
insumity Sep 12, 2023
b1a6f31
feat!: Cryptographic verification of equivocation (#1287)
mpoke Sep 14, 2023
d92a4c8
undelegations are getting slashed integraiton test
insumity Sep 14, 2023
72abcf4
Merge branch 'release/v2.1.x-lsm' into insumity/adr-013-impl-on-feat
insumity Sep 14, 2023
b46ace4
fix merge issues
insumity Sep 14, 2023
59d8192
fix mocks
insumity Sep 14, 2023
31c090d
fix lint issue
insumity Sep 14, 2023
79f8f18
Merge branch 'feat/ics-misbehaviour-handling' into insumity/adr-013-i…
insumity Sep 22, 2023
ed35638
took into account Simon's comments
insumity Sep 22, 2023
62212c7
go.sum changes
insumity Sep 22, 2023
e5b46dd
gosec fix
insumity Sep 22, 2023
4cb6283
fix linter issue
insumity Sep 22, 2023
6f15a61
cherry-picked ADR-05 so markdown link checker does not complain
insumity Sep 22, 2023
93c2cdb
lint
sainoe Sep 22, 2023
1d3ee78
Use cached context to get tokens in undelegations and redelegations.
insumity Sep 25, 2023
5c053bb
return the error
insumity Sep 26, 2023
f8633b5
lint issue
insumity Sep 26, 2023
f96f1bc
take into account Philip's comments
insumity Sep 26, 2023
d3dc0bc
clean up
insumity Sep 26, 2023
39bbcf5
fix flakey test
insumity Sep 27, 2023
694dce7
lint issue
insumity Sep 27, 2023
366e3b1
fix error returns and fix flaky test in a better way
insumity Sep 27, 2023
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
14 changes: 12 additions & 2 deletions tests/integration/double_vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// TestHandleConsumerDoubleVoting verifies that handling a double voting evidence
// of a consumer chain results in the expected jailing of the malicious validator
// of a consumer chain results in the expected tombstoning, jailing, and slashing of the malicious validator
func (s *CCVTestSuite) TestHandleConsumerDoubleVoting() {
s.SetupCCVChannel(s.path)
// required to have the consumer client revision height greater than 0
Expand Down Expand Up @@ -159,6 +159,9 @@ func (s *CCVTestSuite) TestHandleConsumerDoubleVoting() {
consuAddr := types.NewConsumerConsAddress(sdk.ConsAddress(consuVal.Address.Bytes()))
provAddr := s.providerApp.GetProviderKeeper().GetProviderAddrFromConsumerAddr(s.providerCtx(), s.consumerChain.ChainID, consuAddr)

validator, _ := s.providerApp.GetTestStakingKeeper().GetValidator(s.providerCtx(), provAddr.ToSdkConsAddr().Bytes())
initialTokens := validator.GetTokens().ToDec()

for _, tc := range testCases {
s.Run(tc.name, func() {
// reset context for each run
Expand All @@ -185,8 +188,15 @@ func (s *CCVTestSuite) TestHandleConsumerDoubleVoting() {
if tc.expPass {
s.Require().NoError(err)

// verifies that the jailing has occurred
// verifies that the tombstoning and jailing has occurred
s.Require().True(s.providerApp.GetTestSlashingKeeper().IsTombstoned(provCtx, provAddr.ToSdkConsAddr()))
s.Require().True(s.providerApp.GetTestStakingKeeper().IsValidatorJailed(provCtx, provAddr.ToSdkConsAddr()))

// verifies that the validator gets slashed and has fewer tokens after the slashing
validator, _ := s.providerApp.GetTestStakingKeeper().GetValidator(provCtx, provAddr.ToSdkConsAddr().Bytes())
slashFraction := s.providerApp.GetTestSlashingKeeper().SlashFractionDoubleSign(provCtx)
actualTokens := validator.GetTokens().ToDec()
s.Require().True(initialTokens.Sub(initialTokens.Mul(slashFraction)).Equal(actualTokens))
} else {
s.Require().Error(err)

Expand Down
12 changes: 11 additions & 1 deletion tests/integration/misbehaviour.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,26 @@ func (s *CCVTestSuite) TestHandleConsumerMisbehaviour() {
),
}

// we assume that all validators have the same number of initial tokens
validator, _ := s.getValByIdx(0)
initialTokens := validator.GetTokens().ToDec()

err := s.providerApp.GetProviderKeeper().HandleConsumerMisbehaviour(s.providerCtx(), *misb)
s.NoError(err)

// verify that validators are jailed and tombstoned
// verify that validators are jailed, tombstoned, and slashed
for _, v := range clientTMValset.Validators {
consuAddr := sdk.ConsAddress(v.Address.Bytes())
provAddr := s.providerApp.GetProviderKeeper().GetProviderAddrFromConsumerAddr(s.providerCtx(), s.consumerChain.ChainID, types.NewConsumerConsAddress(consuAddr))
val, ok := s.providerApp.GetTestStakingKeeper().GetValidatorByConsAddr(s.providerCtx(), provAddr.Address)
s.Require().True(ok)
s.Require().True(val.Jailed)
s.Require().True(s.providerApp.GetTestSlashingKeeper().IsTombstoned(s.providerCtx(), provAddr.ToSdkConsAddr()))

validator, _ := s.providerApp.GetTestStakingKeeper().GetValidator(s.providerCtx(), provAddr.ToSdkConsAddr().Bytes())
slashFraction := s.providerApp.GetTestSlashingKeeper().SlashFractionDoubleSign(s.providerCtx())
actualTokens := validator.GetTokens().ToDec()
s.Require().True(initialTokens.Sub(initialTokens.Mul(slashFraction)).Equal(actualTokens))
}
}

Expand Down
91 changes: 66 additions & 25 deletions testutil/keeper/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions x/ccv/provider/keeper/double_vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package keeper
import (
"bytes"
"fmt"

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/x/evidence/exported"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -33,8 +34,18 @@ func (k Keeper) HandleConsumerDoubleVoting(
types.NewConsumerConsAddress(sdk.ConsAddress(evidence.VoteA.ValidatorAddress.Bytes())),
)

// execute the jailing
k.JailValidator(ctx, providerAddr)
k.SlashValidator(ctx, providerAddr)
k.JailAndTombstoneValidator(ctx, providerAddr)

// FIXME: verify the following values
insumity marked this conversation as resolved.
Show resolved Hide resolved
var equivocation exported.Evidence = &evidencetypes.Equivocation{
Height: evidence.Height(),
Time: evidence.Time(),
Power: evidence.ValidatorPower,
ConsensusAddress: evidence.VoteA.ValidatorAddress.String(),
}

k.evidenceKeeper.SetEvidence(ctx, equivocation)

k.Logger(ctx).Info(
"confirmed equivocation",
Expand Down
19 changes: 16 additions & 3 deletions x/ccv/provider/keeper/misbehaviour.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package keeper

import (
"github.com/cosmos/interchain-security/v2/x/ccv/provider/types"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/evidence/exported"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
ibcclienttypes "github.com/cosmos/ibc-go/v4/modules/core/02-client/types"
ibctmtypes "github.com/cosmos/ibc-go/v4/modules/light-clients/07-tendermint/types"
"github.com/cosmos/interchain-security/v2/x/ccv/provider/types"
tmtypes "github.com/tendermint/tendermint/types"
)

Expand Down Expand Up @@ -41,10 +42,22 @@ func (k Keeper) HandleConsumerMisbehaviour(ctx sdk.Context, misbehaviour ibctmty
misbehaviour.Header1.Header.ChainID,
types.NewConsumerConsAddress(sdk.ConsAddress(v.Address.Bytes())),
)
k.JailValidator(ctx, providerAddr)
k.SlashValidator(ctx, providerAddr)
k.JailAndTombstoneValidator(ctx, providerAddr)
provAddrs = append(provAddrs, providerAddr)
}

// FIXME: it would be nice to set the evidence but not sure what this would mean
insumity marked this conversation as resolved.
Show resolved Hide resolved
// for light client attacks.
var evidence exported.Evidence = &evidencetypes.Equivocation{
Height: int64(misbehaviour.Header1.GetHeight().GetRevisionHeight()),
Time: misbehaviour.Header2.GetTime(),
Power: 0,
ConsensusAddress: "!",
}

k.evidenceKeeper.SetEvidence(ctx, evidence)

logger.Info(
"confirmed equivocation light client attack",
"byzantine validators", provAddrs,
Expand Down
Loading