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(rollapp): DRS versions #1223

Merged
merged 10 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ func (s *KeeperTestHelper) CreateSequencerByPubkey(ctx sdk.Context, rollappId st
}

func (s *KeeperTestHelper) PostStateUpdate(ctx sdk.Context, rollappId, seqAddr string, startHeight, numOfBlocks uint64) (lastHeight uint64, err error) {
return s.PostStateUpdateWithDRSVersion(ctx, rollappId, seqAddr, startHeight, numOfBlocks, "")
}

func (s *KeeperTestHelper) PostStateUpdateWithDRSVersion(ctx sdk.Context, rollappId, seqAddr string, startHeight, numOfBlocks uint64, drsVersion string) (lastHeight uint64, err error) {
var bds rollapptypes.BlockDescriptors
bds.BD = make([]rollapptypes.BlockDescriptor, numOfBlocks)
for k := 0; k < int(numOfBlocks); k++ {
Expand All @@ -128,6 +132,8 @@ func (s *KeeperTestHelper) PostStateUpdate(ctx sdk.Context, rollappId, seqAddr s
NumBlocks: numOfBlocks,
DAPath: "",
BDs: bds,
Last: false,
DrsVersion: drsVersion,
}
msgServer := rollappkeeper.NewMsgServerImpl(*s.App.RollappKeeper)
_, err = msgServer.UpdateState(ctx, &updateState)
Expand Down
1 change: 1 addition & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ func (a *AppKeepers) InitKeepers(
a.IBCKeeper.ClientKeeper,
nil,
a.BankKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

a.SequencerKeeper = *sequencermodulekeeper.NewKeeper(
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/decred/dcrd/dcrec/edwards v1.0.0
github.com/dustin/go-humanize v1.0.1
github.com/dymensionxyz/gerr-cosmos v1.0.0
github.com/dymensionxyz/sdk-utils v0.2.8
github.com/dymensionxyz/sdk-utils v0.2.9
github.com/ethereum/go-ethereum v1.10.26
github.com/evmos/ethermint v0.22.0
github.com/gogo/protobuf v1.3.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,8 @@ github.com/dymensionxyz/osmosis/osmomath v0.0.6-dymension-v0.1.0.20240820121212-
github.com/dymensionxyz/osmosis/osmomath v0.0.6-dymension-v0.1.0.20240820121212-c0e21fa21e43/go.mod h1:SdGCL9CZb14twRAJUSzb7bRE0OoopRpF2Hnd1UhJpFU=
github.com/dymensionxyz/osmosis/v15 v15.2.1-0.20240820121212-c0e21fa21e43 h1:ugbpHwwlckB4W/aNXUTEsxaakPFgXi+LAsCtvfJ200Q=
github.com/dymensionxyz/osmosis/v15 v15.2.1-0.20240820121212-c0e21fa21e43/go.mod h1:2rsnXAdjYfXtyEw0mNwAdOiAccALYjAPvINGUf9Qg7Y=
github.com/dymensionxyz/sdk-utils v0.2.8 h1:ZX5NSLd0DyGVUqucHnyI14zkeYaD7hVn7v44MQOYFUU=
github.com/dymensionxyz/sdk-utils v0.2.8/go.mod h1:it9owYOpnIe17+ftTATQNDN4z+mBQx20/2Jm8SK15Rk=
github.com/dymensionxyz/sdk-utils v0.2.9 h1:uokHmBjaygJKXQMI0EBhvjsIIYRCIa4Ndpq8tmMwoH8=
github.com/dymensionxyz/sdk-utils v0.2.9/go.mod h1:it9owYOpnIe17+ftTATQNDN4z+mBQx20/2Jm8SK15Rk=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
Expand Down
7 changes: 7 additions & 0 deletions proto/dymensionxyz/dymension/rollapp/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ message EventAppUpdated {
message EventAppRemoved {
App app = 1;
}

message EventMarkVulnerableRollapps {
// VulnerableRollappNum is a number of rollapps that were marked as vulnerable.
uint64 vulnerable_rollapp_num = 1;
// DrsVersions is a list of DRS versions that were marked as vulnerable.
repeated string drs_versions = 2;
}
2 changes: 2 additions & 0 deletions proto/dymensionxyz/dymension/rollapp/state_info.proto
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ message StateInfo {
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"created_at\""
];
// DrsVersion is a DRS version used by the rollapp.
string drs_version = 11;
}

// StateInfoSummary is a compact representation of StateInfo
Expand Down
16 changes: 16 additions & 0 deletions proto/dymensionxyz/dymension/rollapp/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ service Msg {
rpc AddApp(MsgAddApp) returns (MsgAddAppResponse);
rpc UpdateApp(MsgUpdateApp) returns (MsgUpdateAppResponse);
rpc RemoveApp(MsgRemoveApp) returns (MsgRemoveAppResponse);
rpc MarkVulnerableRollapps(MsgMarkVulnerableRollapps) returns (MsgMarkVulnerableRollappsResponse);
}

// MsgCreateRollapp creates a new rollapp chain on the hub.
Expand Down Expand Up @@ -87,6 +88,8 @@ message MsgUpdateState {
BlockDescriptors BDs = 7 [(gogoproto.nullable) = false];
// last is true if this is the last batch of the sequencer
bool last = 8;
// DrsVersion is a DRS version used by the rollapp.
string drs_version = 9;
}

message MsgUpdateStateResponse {
Expand Down Expand Up @@ -165,3 +168,16 @@ message MsgRemoveApp {

message MsgRemoveAppResponse {
}

// MsgMarkVulnerableRollapps marks specified versions as vulnerable as well as
// all corresponding rollapps. Must be called by the governance.
message MsgMarkVulnerableRollapps {
option (cosmos.msg.v1.signer) = "authority";

// Authority is the authority address.
string authority = 1;
// DrsVersions is a list of DRS versions that will be marked vulnerable.
repeated string drs_versions = 2;
}

message MsgMarkVulnerableRollappsResponse {}
1 change: 1 addition & 0 deletions testutil/keeper/dymns.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func DymNSKeeper(t testing.TB) (dymnskeeper.Keeper, dymnstypes.BankKeeper, rolla
rollappParamsSubspace,
nil, nil, nil,
bankKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

k := dymnskeeper.NewKeeper(cdc,
Expand Down
4 changes: 3 additions & 1 deletion testutil/keeper/rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/cosmos/cosmos-sdk/store"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
typesparams "github.com/cosmos/cosmos-sdk/x/params/types"

"github.com/dymensionxyz/dymension/v3/x/rollapp/keeper"
Expand Down Expand Up @@ -38,7 +40,7 @@ func RollappKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
memStoreKey,
"RollappParams",
)
k := keeper.NewKeeper(cdc, storeKey, paramsSubspace, nil, nil, nil, nil)
k := keeper.NewKeeper(cdc, storeKey, paramsSubspace, nil, nil, nil, nil, authtypes.NewModuleAddress(govtypes.ModuleName).String())

ctx := sdk.NewContext(stateStore, cometbftproto.Header{}, false, log.NewNopLogger())

Expand Down
10 changes: 5 additions & 5 deletions x/delayedack/keeper/transfer.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package keeper

import (
"cosmossdk.io/errors"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
commontypes "github.com/dymensionxyz/dymension/v3/x/common/types"
Expand Down Expand Up @@ -29,15 +29,15 @@ func (k Keeper) GetValidTransferWithFinalizationInfo(

data.TransferData, err = k.rollappKeeper.GetValidTransfer(ctx, packet.GetData(), port, channel)
if err != nil {
err = errors.Wrap(err, "get valid transfer data")
err = errorsmod.Wrap(err, "get valid transfer data")
return
}

packetID := commontypes.NewPacketUID(packetType, port, channel, packet.Sequence)
height, ok := types.PacketProofHeightFromCtx(ctx, packetID)
if !ok {
// TODO: should probably be a panic
err = errors.Wrapf(gerrc.ErrNotFound, "get proof height from context: packetID: %s", packetID)
err = errorsmod.Wrapf(gerrc.ErrNotFound, "get proof height from context: packetID: %s", packetID)
return
}
data.ProofHeight = height.RevisionHeight
Expand All @@ -47,10 +47,10 @@ func (k Keeper) GetValidTransferWithFinalizationInfo(
}

finalizedHeight, err := k.getRollappFinalizedHeight(ctx, data.Rollapp.RollappId)
if errors.IsOf(err, rollapptypes.ErrNoFinalizedStateYetForRollapp) {
if errorsmod.IsOf(err, rollapptypes.ErrNoFinalizedStateYetForRollapp) {
err = nil
} else if err != nil {
err = errors.Wrap(err, "get rollapp finalized height")
err = errorsmod.Wrap(err, "get rollapp finalized height")
} else {
data.Finalized = data.ProofHeight <= finalizedHeight
}
Expand Down
1 change: 1 addition & 0 deletions x/dymns/keeper/keeper_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func (s *KeeperTestSuite) SetupTest() {
rollappParamsSubspace,
nil, nil, nil,
bk,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

dk = dymnskeeper.NewKeeper(cdc,
Expand Down
1 change: 1 addition & 0 deletions x/rollapp/client/proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"

"github.com/dymensionxyz/dymension/v3/x/rollapp/client/cli"
)

Expand Down
3 changes: 2 additions & 1 deletion x/rollapp/keeper/authenticate_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
"github.com/dymensionxyz/gerr-cosmos/gerrc"
uibc "github.com/dymensionxyz/sdk-utils/utils/uibc"

"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
)

/*
Expand Down
47 changes: 15 additions & 32 deletions x/rollapp/keeper/fraud_handler.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
"errors"
"fmt"

errorsmod "cosmossdk.io/errors"
Expand All @@ -15,13 +16,7 @@ import (
)

// HandleFraud handles the fraud evidence submitted by the user.
func (k Keeper) HandleFraud(ctx sdk.Context, rollappID, clientId string, fraudHeight uint64, seqAddr string) error {
// Get the rollapp from the store
rollapp, found := k.GetRollapp(ctx, rollappID)
if !found {
return errorsmod.Wrapf(types.ErrInvalidRollappID, "rollapp with ID %s not found", rollappID)
}

func (k Keeper) HandleFraud(ctx sdk.Context, rollappID, clientID string, fraudHeight uint64, seqAddr string) error {
stateInfo, err := k.FindStateInfoByHeight(ctx, rollappID, fraudHeight)
if err != nil {
return err
Expand All @@ -42,34 +37,22 @@ func (k Keeper) HandleFraud(ctx sdk.Context, rollappID, clientId string, fraudHe
return errorsmod.Wrapf(types.ErrWrongProposerAddr, "sequencer address %s does not match the one in the state info", seqAddr)
}

// slash the sequencer, clean delayed packets
err = k.hooks.FraudSubmitted(ctx, rollappID, fraudHeight, seqAddr)
// check that the clientID is correct
err = k.verifyClientID(ctx, rollappID, clientID)
if err != nil {
return err
return errors.Join(types.ErrWrongClientId, err)
}

// mark the rollapp as frozen. revert all pending states to finalized
rollapp.Frozen = true
k.SetRollapp(ctx, rollapp)

k.RevertPendingStates(ctx, rollappID)

if rollapp.ChannelId != "" {
extractedClientId, _, err := k.channelKeeper.GetChannelClientState(ctx, "transfer", rollapp.ChannelId)
if err != nil {
return err
}

if extractedClientId != clientId {
return errorsmod.Wrapf(types.ErrWrongClientId, "clientID %s does not match the one in the rollapp (%s)", clientId, extractedClientId)
}
// freeze the rollapp and revert all pending states
err = k.FreezeRollapp(ctx, rollappID)
if err != nil {
return fmt.Errorf("freeze rollapp: %w", err)
danwt marked this conversation as resolved.
Show resolved Hide resolved
}

err = k.freezeClientState(ctx, clientId)
if err != nil {
return err
}
} else if clientId != "" {
return errorsmod.Wrapf(types.ErrWrongClientId, "rollapp with ID %s does not have a channel", rollappID)
// slash the sequencer, clean delayed packets
err = k.hooks.FraudSubmitted(ctx, rollappID, fraudHeight, seqAddr)
if err != nil {
return err
}

ctx.EventManager().EmitEvent(
Expand All @@ -78,7 +61,7 @@ func (k Keeper) HandleFraud(ctx sdk.Context, rollappID, clientId string, fraudHe
sdk.NewAttribute(types.AttributeKeyRollappId, rollappID),
sdk.NewAttribute(types.AttributeKeyFraudHeight, fmt.Sprint(fraudHeight)),
sdk.NewAttribute(types.AttributeKeyFraudSequencer, seqAddr),
sdk.NewAttribute(types.AttributeKeyClientID, clientId),
sdk.NewAttribute(types.AttributeKeyClientID, clientID),
),
)

Expand Down
1 change: 1 addition & 0 deletions x/rollapp/keeper/genesis_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
)

Expand Down
3 changes: 2 additions & 1 deletion x/rollapp/keeper/grpc_query_latest_height.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
"github.com/dymensionxyz/gerr-cosmos/gerrc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
)

func (k Keeper) LatestHeight(c context.Context, req *types.QueryGetLatestHeightRequest) (*types.QueryGetLatestHeightResponse, error) {
Expand Down
3 changes: 2 additions & 1 deletion x/rollapp/keeper/grpc_query_latest_state_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
)

func (k Keeper) LatestStateIndex(c context.Context, req *types.QueryGetLatestStateIndexRequest) (*types.QueryGetLatestStateIndexResponse, error) {
Expand Down
3 changes: 2 additions & 1 deletion x/rollapp/keeper/grpc_query_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
)

func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
Expand Down
3 changes: 2 additions & 1 deletion x/rollapp/keeper/grpc_query_state_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
"github.com/dymensionxyz/gerr-cosmos/gerrc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
)

func (k Keeper) StateInfo(c context.Context, req *types.QueryGetStateInfoRequest) (*types.QueryGetStateInfoResponse, error) {
Expand Down
3 changes: 2 additions & 1 deletion x/rollapp/keeper/grpc_query_state_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/dymensionxyz/sdk-utils/utils/urand"

keepertest "github.com/dymensionxyz/dymension/v3/testutil/keeper"
"github.com/dymensionxyz/dymension/v3/testutil/nullify"
"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
"github.com/dymensionxyz/sdk-utils/utils/urand"
)

// Prevent strconv unused error
Expand Down
Loading
Loading