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

[DNM] merge base to main #387

Closed
wants to merge 84 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
2207f55
integration: set up `x/btcstkconsumer` module (#206)
SebastianElvis Mar 13, 2024
88f891c
F/consumer chain registry (#205)
maurolacy Mar 13, 2024
f4b88ab
F/consumer chain registry 2 (#209)
maurolacy Mar 13, 2024
873cfce
F/register codecs (#210)
maurolacy Mar 15, 2024
7928f66
F/consumer FP registry (#216)
maurolacy Mar 20, 2024
a4d244c
F/consumer fp registry 2 (#220)
maurolacy Mar 20, 2024
65657d1
handling restaked BTC delegations to consumer FPs (#222)
SebastianElvis Mar 22, 2024
0c5d6aa
F/consumer chain cli (#221)
maurolacy Mar 22, 2024
76efc0d
Update CHANGELOG
Mar 22, 2024
ce164ea
fix: only calculating Babylon FPs for FP set rotation (#223)
SebastianElvis Mar 25, 2024
5c15e74
Update CHANGELOG
Mar 25, 2024
b98b20e
fix
SebastianElvis Apr 2, 2024
0a6e9f8
R/consumer chain 2 (#224)
maurolacy Apr 3, 2024
c94b5f5
linting validateRestakedFPs
SebastianElvis Apr 16, 2024
4c1e0d5
proto: define IBC packet formats for PoS integration (#229)
SebastianElvis Apr 22, 2024
56b21f4
zoneconcierge: let zoneconcierge hold a pointer to btcstaking module …
SebastianElvis Apr 22, 2024
4601ff5
tests: Add pos-integration E2E Tests (#225)
gusin13 Apr 22, 2024
27f7072
chore: fix some proto formats for IBC packets (#234)
SebastianElvis Apr 25, 2024
78120b3
chore: rename chain to consumer for PoS integration (#233)
SebastianElvis Apr 25, 2024
038943a
btcstkconsumer: separate IBC packet for provider / consumer (#237)
SebastianElvis Apr 30, 2024
8f134e1
feat: Store btcstaking events in kv store and send IBC packet (#235)
gusin13 Apr 30, 2024
1ed7149
tests: btcstaking events e2e tests (#240)
gusin13 May 16, 2024
61ef003
release v0.2.0 rc0 (#245)
SebastianElvis May 17, 2024
49663ec
cd: Allows base/consumer-chain-support branch to run push_docker job …
hiepmai-babylonchain May 20, 2024
5f8413b
btcstkconsumer: RPC functions for BTC staking consumer module (#247)
SebastianElvis May 20, 2024
5701ec9
Fix/babylon update (#253)
maurolacy May 28, 2024
a0ec504
tests: Add undelegation and fp voting power test cases (#254)
gusin13 May 29, 2024
5d00627
feat: Add `cosmwasm_2_0` to `wasmCapabilities` (#255)
lesterli Jun 13, 2024
db66211
feat: Add Grpc querier (#257)
lesterli Jun 18, 2024
265678f
chore: remove aarch64 wasm (#261)
lesterli Jun 20, 2024
fdd9040
Fix rebase error
Jul 8, 2024
e57fefc
Fix rebase error / Simplify testutil btcstaking helpers
Jul 8, 2024
253dab4
fix: panic to merge proto files (#264)
lesterli Jul 5, 2024
e7658c2
U/contracts 0.7 (#270)
maurolacy Jul 10, 2024
0a646a3
Fix: Add stker_addr to active btc delegation
Jul 10, 2024
a6a6fc7
Update contracts from rebase branch
Jul 11, 2024
6f1b119
Fix: btc staking integration rebase errors
Jul 12, 2024
8531b8b
Fix: ExecCmd vs ExecTxCmd inconsistency
Jul 12, 2024
6c9ffa0
Fix in passing: docker warning
Jul 12, 2024
d1afabf
Fix syntax
Jul 12, 2024
d63dc74
proto-lint
Jul 12, 2024
33db0a6
proto-gen
Jul 12, 2024
b924ff0
Sanitize code path to avoid gosec warning
Jul 12, 2024
735e248
Increase Go min version to 1.22
Jul 12, 2024
fead9dc
Increase go version in CI
Jul 12, 2024
b83688b
Increase Go version in babylon container
Jul 12, 2024
30f2a15
Workaround consumer and babylon FP creation for staking integration t…
Jul 13, 2024
d1c5b08
Revert "Workaround consumer and babylon FP creation for staking integ…
Jul 15, 2024
a0e86bc
Comment pop.Verify out
Jul 15, 2024
dbf026c
fix fp gen
SebastianElvis Jul 15, 2024
5cdf5bb
fix gosec
SebastianElvis Jul 15, 2024
3d8f190
chore: rename del Babylon address in e2e (#273)
SebastianElvis Jul 17, 2024
6ecfdf4
Merge branch 'dev' into try-rebase-dev
SebastianElvis Jul 30, 2024
ce31233
fix compile
SebastianElvis Jul 30, 2024
d77e0cb
fix all tests
SebastianElvis Jul 30, 2024
74a24c9
Merge pull request #1 from babylonlabs-io/try-rebase-dev
SebastianElvis Aug 1, 2024
bd458da
feat: Automatic consumer registration (#11)
gusin13 Aug 14, 2024
20c5405
Merge branch 'dev' into merge-dev
SebastianElvis Aug 16, 2024
b03a1d8
fix e2e
SebastianElvis Aug 16, 2024
6bcadbc
Merge pull request #13 from babylonlabs-io/merge-dev-1
SebastianElvis Aug 17, 2024
81ee356
Add Consumer packet data defs / gens (#15)
maurolacy Aug 28, 2024
7942dae
tests: bcd setup in e2e (#57)
gusin13 Sep 11, 2024
35a5a1b
feat: Babylon FP cascaded slashing (#69)
gusin13 Sep 17, 2024
d6b39e8
Merge branch 'main' into try-rebase
SebastianElvis Sep 19, 2024
59a2486
fix compile
SebastianElvis Sep 19, 2024
747ca8e
feat(ADR-025): Enable jailing and unjailing (#80)
gitferry Sep 19, 2024
063241e
fix compile/tests
SebastianElvis Sep 20, 2024
bca42f1
accommodate timestamped pub rand for e2e
SebastianElvis Sep 20, 2024
0e661b3
Merge pull request #83 from babylonlabs-io/try-rebase
SebastianElvis Sep 23, 2024
a6f728b
Merge branch 'main' into base/consumer-chain-support
SebastianElvis Sep 23, 2024
a98269d
feat: Consumer FP cascaded slashing (#85)
gusin13 Sep 25, 2024
3520b05
f/Better IBC transfer tests (#128)
maurolacy Oct 4, 2024
8ee2c85
chore: gh sync workflow from main to base (#133)
gusin13 Oct 15, 2024
d10dd40
Merge branch 'main' into rebase-devnet-5
SebastianElvis Nov 14, 2024
540d59f
fix conflicts
SebastianElvis Nov 14, 2024
1be1c2b
fix compile
SebastianElvis Nov 15, 2024
098751b
Merge branch 'main' into rebase-devnet-5
SebastianElvis Nov 18, 2024
579d66c
fix tests and disable v1 upgrade e2e
SebastianElvis Nov 20, 2024
3aa1afc
Merge pull request #266 from babylonlabs-io/rebase-devnet-5
SebastianElvis Nov 20, 2024
ad3e100
F/consumer rewards e2e (#301)
maurolacy Nov 27, 2024
4898d8d
zoneconcierge: permissioned integration (#291)
SebastianElvis Dec 3, 2024
9300461
feat: add the slashing msg handler for op consumer fp (#327)
lesterli Dec 7, 2024
72654c8
e2e: remove e2e related to BTC staking integration (#339)
SebastianElvis Dec 13, 2024
e901f1c
fix: remove unused deps in `.proto` files (#355)
lesterli Dec 18, 2024
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
Next Next commit
feat: add the slashing msg handler for op consumer fp (#327)
lesterli authored Dec 7, 2024

Unverified

No user is associated with the committer email.
commit 930046144fa3e09a9048198716346bd1b26a011f
32 changes: 32 additions & 0 deletions proto/babylon/finality/v1/tx.proto
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import "tendermint/crypto/proof.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/msg/v1/msg.proto";
import "babylon/finality/v1/params.proto";
import "babylon/finality/v1/finality.proto";

// Msg defines the Msg service.
service Msg {
@@ -23,6 +24,9 @@ service Msg {
// UnjailFinalityProvider defines a method for unjailing a jailed
// finality provider, thus it can receive voting power
rpc UnjailFinalityProvider(MsgUnjailFinalityProvider) returns (MsgUnjailFinalityProviderResponse);
// EquivocationEvidence handles the evidence of equivocation message sent from
// the finality gadget cw contract
rpc EquivocationEvidence(MsgEquivocationEvidence) returns (MsgEquivocationEvidenceResponse);
}

// MsgCommitPubRandList defines a message for committing a list of public randomness for EOTS
@@ -103,3 +107,31 @@ message MsgUnjailFinalityProvider {

// MsgUnjailFinalityProviderResponse defines the Msg/UnjailFinalityProvider response type
message MsgUnjailFinalityProviderResponse {}

// MsgEquivocationEvidence is the message for handling evidence of equivocation
message MsgEquivocationEvidence {
option (cosmos.msg.v1.signer) = "signer";

string signer = 1;
// fp_btc_pk is the BTC PK of the finality provider that casts this vote
bytes fp_btc_pk = 2 [ (gogoproto.customtype) = "github.com/babylonlabs-io/babylon/types.BIP340PubKey" ];
// block_height is the height of the conflicting blocks
uint64 block_height = 3;
// pub_rand is the public randomness the finality provider has committed to
bytes pub_rand = 4 [ (gogoproto.customtype) = "github.com/babylonlabs-io/babylon/types.SchnorrPubRand" ];
// canonical_app_hash is the AppHash of the canonical block
bytes canonical_app_hash = 5;
// fork_app_hash is the AppHash of the fork block
bytes fork_app_hash = 6;
// canonical_finality_sig is the finality signature to the canonical block
// where finality signature is an EOTS signature, i.e.,
// the `s` in a Schnorr signature `(r, s)`
// `r` is the public randomness that is already committed by the finality provider
bytes canonical_finality_sig = 7 [ (gogoproto.customtype) = "github.com/babylonlabs-io/babylon/types.SchnorrEOTSSig" ];
// fork_finality_sig is the finality signature to the fork block
// where finality signature is an EOTS signature
bytes fork_finality_sig = 8 [ (gogoproto.customtype) = "github.com/babylonlabs-io/babylon/types.SchnorrEOTSSig" ];
}

// MsgEquivocationEvidenceResponse is the response for MsgEquivocationEvidence
message MsgEquivocationEvidenceResponse {}
53 changes: 53 additions & 0 deletions x/finality/keeper/msg_server.go
Original file line number Diff line number Diff line change
@@ -333,3 +333,56 @@ func (ms msgServer) validateActivationHeight(ctx sdk.Context, height uint64) (ui
}
return activationHeight, nil
}

// EquivocationEvidence handles the evidence of equivocation message sent from the finality gadget cw contract
func (ms msgServer) EquivocationEvidence(goCtx context.Context, req *types.MsgEquivocationEvidence) (*types.MsgEquivocationEvidenceResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// validate the evidence
if err := validateEvidence(req); err != nil {
return &types.MsgEquivocationEvidenceResponse{}, err
}

// construct the evidence
evidence := &types.Evidence{
FpBtcPk: req.FpBtcPk,
BlockHeight: req.BlockHeight,
PubRand: req.PubRand,
CanonicalAppHash: req.CanonicalAppHash,
CanonicalFinalitySig: req.CanonicalFinalitySig,
ForkAppHash: req.ForkAppHash,
ForkFinalitySig: req.ForkFinalitySig,
}

// slash this finality provider, including setting its voting power to
// zero, extracting its BTC SK, and emit an event
ms.slashFinalityProvider(ctx, evidence.FpBtcPk, evidence)

// save evidence
ms.SetEvidence(ctx, evidence)

return &types.MsgEquivocationEvidenceResponse{}, nil
}

// Helper function
func validateEvidence(req *types.MsgEquivocationEvidence) error {
if req.FpBtcPk == nil {
return fmt.Errorf("empty FpBtcPk")
}
if req.PubRand == nil {
return fmt.Errorf("empty PubRand")
}
if len(req.CanonicalAppHash) != 32 {
return fmt.Errorf("malformed CanonicalAppHash")
}
if len(req.ForkAppHash) != 32 {
return fmt.Errorf("malformed ForkAppHash")
}
if req.ForkFinalitySig == nil {
return fmt.Errorf("empty ForkFinalitySig")
}
if req.CanonicalFinalitySig == nil {
return fmt.Errorf("empty CanonicalFinalitySig")
}
return nil
}
112 changes: 112 additions & 0 deletions x/finality/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import (
"time"

"cosmossdk.io/core/header"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"

@@ -487,3 +488,114 @@ func TestVerifyActivationHeight(t *testing.T) {
blockHeight, activationHeight,
).Error())
}

func FuzzEquivocationEvidence(f *testing.F) {
datagen.AddRandomSeedsToFuzzer(f, 10)

f.Fuzz(func(t *testing.T, seed int64) {
r := rand.New(rand.NewSource(seed))
ctrl := gomock.NewController(t)
defer ctrl.Finish()

bsKeeper := types.NewMockBTCStakingKeeper(ctrl)
cKeeper := types.NewMockCheckpointingKeeper(ctrl)
iKeeper := types.NewMockIncentiveKeeper(ctrl)
iKeeper.EXPECT().IndexRefundableMsg(gomock.Any(), gomock.Any()).AnyTimes()
fKeeper, ctx := keepertest.FinalityKeeper(t, bsKeeper, iKeeper, cKeeper)
ms := keeper.NewMsgServerImpl(*fKeeper)

// set params with activation height
err := fKeeper.SetParams(ctx, types.DefaultParams())
require.NoError(t, err)
activationHeight := fKeeper.GetParams(ctx).FinalityActivationHeight

// create and register a random finality provider
btcSK, btcPK, err := datagen.GenRandomBTCKeyPair(r)
require.NoError(t, err)
fp, err := datagen.GenRandomFinalityProviderWithBTCSK(r, btcSK, "")
require.NoError(t, err)
fpBTCPK := bbn.NewBIP340PubKeyFromBTCPK(btcPK)
fpBTCPKBytes := fpBTCPK.MustMarshal()

// test invalid case - without PubRand field in MsgEquivocationEvidence
invalidMsg := &types.MsgEquivocationEvidence{
Signer: datagen.GenRandomAccount().Address,
FpBtcPk: fpBTCPK,
BlockHeight: activationHeight,
CanonicalAppHash: datagen.GenRandomByteArray(r, 32),
ForkAppHash: datagen.GenRandomByteArray(r, 32),
CanonicalFinalitySig: &bbn.SchnorrEOTSSig{},
ForkFinalitySig: &bbn.SchnorrEOTSSig{},
}

_, err = ms.EquivocationEvidence(ctx, invalidMsg)
require.ErrorContains(t, err, "empty PubRand")

// test valid case
blockHeight := activationHeight + uint64(datagen.RandomInt(r, 100))

// generate proper pub rand data
startHeight := blockHeight
numPubRand := uint64(200)
randListInfo, _, err := datagen.GenRandomMsgCommitPubRandList(r, btcSK, startHeight, numPubRand)
require.NoError(t, err)

// mock pub rand for evidence
pubRand := &randListInfo.PRList[0]

// mock canonical and fork app hash
canonicalAppHash := datagen.GenRandomByteArray(r, 32)
forkAppHash := datagen.GenRandomByteArray(r, 32)

// mock canonical signature
canonicalBytes := datagen.GenRandomByteArray(r, 32)
var canonicalModNScalar btcec.ModNScalar
overflowed := canonicalModNScalar.SetByteSlice(canonicalBytes)
require.False(t, overflowed)
canonicalSig := bbn.NewSchnorrEOTSSigFromModNScalar(&canonicalModNScalar)

// mock fork signature
forkBytes := datagen.GenRandomByteArray(r, 32)
var forkModNScalar btcec.ModNScalar
overflowed = forkModNScalar.SetByteSlice(forkBytes)
require.False(t, overflowed)
forkSig := bbn.NewSchnorrEOTSSigFromModNScalar(&forkModNScalar)

msg := &types.MsgEquivocationEvidence{
Signer: datagen.GenRandomAccount().Address,
FpBtcPk: fpBTCPK,
BlockHeight: blockHeight,
PubRand: pubRand,
CanonicalAppHash: canonicalAppHash,
ForkAppHash: forkAppHash,
CanonicalFinalitySig: canonicalSig,
ForkFinalitySig: forkSig,
}

// set block height in context to be >= evidence height
blockAppHash := datagen.GenRandomByteArray(r, 32)
ctx = ctx.WithHeaderInfo(header.Info{Height: int64(blockHeight), AppHash: blockAppHash})
fKeeper.IndexBlock(ctx)
bsKeeper.EXPECT().GetFinalityProvider(gomock.Any(), gomock.Eq(fpBTCPKBytes)).Return(fp, nil).AnyTimes()

// mock voting power
fKeeper.SetVotingPower(ctx, fpBTCPKBytes, blockHeight, 1)

// mock slashing interface
bsKeeper.EXPECT().SlashFinalityProvider(gomock.Any(), gomock.Eq(fpBTCPKBytes)).Return(nil)
bsKeeper.EXPECT().PropagateFPSlashingToConsumers(gomock.Any(), gomock.Eq(fpBTCPK)).Return(nil)

_, err = ms.EquivocationEvidence(ctx, msg)
require.NoError(t, err)

storedEvidence, err := fKeeper.GetEvidence(ctx, fpBTCPK, blockHeight)
require.NoError(t, err)
require.Equal(t, msg.FpBtcPk, storedEvidence.FpBtcPk)
require.Equal(t, msg.BlockHeight, storedEvidence.BlockHeight)
require.Equal(t, msg.PubRand, storedEvidence.PubRand)
require.Equal(t, msg.CanonicalAppHash, storedEvidence.CanonicalAppHash)
require.Equal(t, msg.ForkAppHash, storedEvidence.ForkAppHash)
require.Equal(t, msg.CanonicalFinalitySig, storedEvidence.CanonicalFinalitySig)
require.Equal(t, msg.ForkFinalitySig, storedEvidence.ForkFinalitySig)
})
}
798 changes: 748 additions & 50 deletions x/finality/types/tx.pb.go

Large diffs are not rendered by default.