Skip to content

Commit

Permalink
feat(ante): whitelisted relayers (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
keruch authored Oct 29, 2024
1 parent db081bf commit f850e3b
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 81 deletions.
16 changes: 11 additions & 5 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"runtime/debug"

distrkeeper "github.com/dymensionxyz/dymension-rdk/x/dist/keeper"
seqkeeper "github.com/dymensionxyz/dymension-rdk/x/sequencers/keeper"
cosmosante "github.com/evmos/evmos/v12/app/ante/cosmos"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand All @@ -19,7 +21,6 @@ import (
ibckeeper "github.com/cosmos/ibc-go/v6/modules/core/keeper"
evmosante "github.com/evmos/evmos/v12/app/ante"
evmosanteevm "github.com/evmos/evmos/v12/app/ante/evm"
anteutils "github.com/evmos/evmos/v12/app/ante/utils"
evmostypes "github.com/evmos/evmos/v12/types"
evmtypes "github.com/evmos/evmos/v12/x/evm/types"
evmosvestingtypes "github.com/evmos/evmos/v12/x/vesting/types"
Expand All @@ -38,7 +39,8 @@ func MustCreateHandler(codec codec.BinaryCodec,
feeMarketKeeper evmosanteevm.FeeMarketKeeper,
evmKeeper evmosanteevm.EVMKeeper,
ibcKeeper *ibckeeper.Keeper,
distrKeeper anteutils.DistributionKeeper,
distrKeeper distrkeeper.Keeper,
sequencerKeeper seqkeeper.Keeper,
) sdk.AnteHandler {
ethOpts := evmosante.HandlerOptions{
Cdc: codec,
Expand All @@ -57,8 +59,10 @@ func MustCreateHandler(codec codec.BinaryCodec,
}

opts := HandlerOptions{
HandlerOptions: ethOpts,
hasPermission: hasPermission,
HandlerOptions: ethOpts,
hasPermission: hasPermission,
DistrKeeper: distrKeeper,
SequencersKeeper: sequencerKeeper,
}

h, err := NewHandler(opts)
Expand All @@ -71,7 +75,9 @@ func MustCreateHandler(codec codec.BinaryCodec,
// HandlerOptions are the options required for constructing a default SDK AnteHandler.
type HandlerOptions struct {
evmosante.HandlerOptions
hasPermission HasPermission
hasPermission HasPermission
DistrKeeper distrkeeper.Keeper
SequencersKeeper seqkeeper.Keeper
}

func (o HandlerOptions) validate() error {
Expand Down
57 changes: 0 additions & 57 deletions app/ante/bypass_ibc_fee_decorator.go

This file was deleted.

11 changes: 6 additions & 5 deletions app/ante/create_account_decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
"github.com/cosmos/cosmos-sdk/x/auth/types"
rdkante "github.com/dymensionxyz/dymension-rdk/server/ante"
)

type createAccountDecorator struct {
type CreateAccountDecorator struct {
ak accountKeeper
}

Expand All @@ -18,8 +19,8 @@ type accountKeeper interface {
NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) types.AccountI
}

func NewCreateAccountDecorator(ak accountKeeper) createAccountDecorator {
return createAccountDecorator{ak: ak}
func NewCreateAccountDecorator(ak accountKeeper) CreateAccountDecorator {
return CreateAccountDecorator{ak: ak}
}

const newAccountCtxKeyPrefix = "new-account/"
Expand All @@ -28,7 +29,7 @@ func CtxKeyNewAccount(acc string) string {
return newAccountCtxKeyPrefix + acc
}

func (cad createAccountDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
func (cad CreateAccountDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
sigTx, ok := tx.(authsigning.SigVerifiableTx)
if !ok {
return ctx, errorsmod.Wrap(sdkerrors.ErrTxDecode, "invalid tx type")
Expand All @@ -39,7 +40,7 @@ func (cad createAccountDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulat
return ctx, err
}

ibcRelayerMsg := isIBCRelayerMsg(tx.GetMsgs())
ibcRelayerMsg := rdkante.IsIBCRelayerMsg(tx.GetMsgs())

for i, pk := range pubkeys {
if pk == nil {
Expand Down
13 changes: 11 additions & 2 deletions app/ante/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
conntypes "github.com/cosmos/ibc-go/v6/modules/core/03-connection/types"
ibcante "github.com/cosmos/ibc-go/v6/modules/core/ante"
rdkante "github.com/dymensionxyz/dymension-rdk/server/ante"
cosmosante "github.com/evmos/evmos/v12/app/ante/cosmos"
evmante "github.com/evmos/evmos/v12/app/ante/evm"
evmtypes "github.com/evmos/evmos/v12/x/evm/types"
Expand Down Expand Up @@ -70,10 +71,18 @@ func cosmosHandler(options HandlerOptions, sigChecker sdk.AnteDecorator) sdk.Ant
sdk.MsgTypeURL(&vestingtypes.MsgCreatePeriodicVestingAccount{}),
}),
ante.NewValidateMemoDecorator(options.AccountKeeper),
NewBypassIBCFeeDecorator(cosmosante.NewMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper)),
rdkante.NewBypassIBCFeeDecorator(
cosmosante.NewMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper),
options.DistrKeeper,
options.SequencersKeeper,
),
NewCreateAccountDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
NewBypassIBCFeeDecorator(cosmosante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.DistributionKeeper, options.FeegrantKeeper, options.StakingKeeper, options.TxFeeChecker)),
rdkante.NewBypassIBCFeeDecorator(
cosmosante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.DistributionKeeper, options.FeegrantKeeper, options.StakingKeeper, options.TxFeeChecker),
options.DistrKeeper,
options.SequencersKeeper,
),
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(options.AccountKeeper),
ante.NewValidateSigCountDecorator(options.AccountKeeper),
Expand Down
3 changes: 2 additions & 1 deletion app/ante/sigcheck_decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
rdkante "github.com/dymensionxyz/dymension-rdk/server/ante"
)

type sigCheckDecorator struct {
Expand Down Expand Up @@ -41,7 +42,7 @@ func (svd sigCheckDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate boo
return ctx, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "invalid number of signer; expected: %d, got %d", len(signerAddrs), len(sigs))
}

ibcRelayerMsg := isIBCRelayerMsg(tx.GetMsgs())
ibcRelayerMsg := rdkante.IsIBCRelayerMsg(tx.GetMsgs())

for i, sig := range sigs {
acc, err := authante.GetSignerAcc(ctx, svd.ak, signerAddrs[i])
Expand Down
12 changes: 9 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
"github.com/dymensionxyz/dymension-rdk/server/consensus"
"github.com/dymensionxyz/rollapp-evm/app/ante"
"github.com/gogo/protobuf/proto"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
Expand All @@ -21,6 +21,8 @@ import (
tmos "github.com/tendermint/tendermint/libs/os"
dbm "github.com/tendermint/tm-db"

"github.com/dymensionxyz/rollapp-evm/app/ante"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
Expand Down Expand Up @@ -487,7 +489,10 @@ func NewRollapp(
)

app.SequencersKeeper = *seqkeeper.NewKeeper(
appCodec, keys[seqtypes.StoreKey], app.GetSubspace(seqtypes.ModuleName),
appCodec,
keys[seqtypes.StoreKey],
app.GetSubspace(seqtypes.ModuleName),
authtypes.NewModuleAddress(seqtypes.ModuleName).String(),
)

app.TimeUpgradeKeeper = timeupgradekeeper.NewKeeper(
Expand Down Expand Up @@ -836,13 +841,14 @@ func NewRollapp(
app.EvmKeeper,
app.IBCKeeper,
app.DistrKeeper,
app.SequencersKeeper,
)
app.SetAnteHandler(h)
app.setPostHandler()

// Admission handler for consensus messages
app.setAdmissionHandler(consensus.AllowedMessagesHandler([]string{
// proto.MessageName(&banktypes.MsgSend{}), // Example of message allowed as consensus message
proto.MessageName(new(seqtypes.ConsensusMsgUpsertSequencer)),
}))

if loadLatest {
Expand Down
2 changes: 0 additions & 2 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package app

import (
"encoding/json"
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -72,7 +71,6 @@ func SetupWithOneValidator(t *testing.T) (*App, authtypes.AccountI) {
Address: acc.GetAddress().String(),
Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))),
}
fmt.Printf("address: %s\n", acc.GetAddress().String())

app := SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, balance)

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ require (
github.com/bcdevtools/evm-block-explorer-rpc-cosmos v1.1.4
github.com/cosmos/cosmos-sdk v0.46.16
github.com/cosmos/ibc-go/v6 v6.2.1
github.com/dymensionxyz/dymension-rdk v1.6.1-0.20241020152926-b250db7af580
github.com/dymensionxyz/dymint v1.2.0-rc01.0.20241015102238-a827c3784461
github.com/dymensionxyz/dymension-rdk v1.6.1-0.20241029165002-545051749bc0
github.com/dymensionxyz/dymint v1.2.0-rc01.0.20241024144934-db109b2859b4
github.com/ethereum/go-ethereum v1.12.0
github.com/evmos/evmos/v12 v12.1.6
github.com/gogo/protobuf v1.3.3
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -577,10 +577,10 @@ github.com/dymensionxyz/cometbft v0.34.29-0.20241008141942-63af9d24107f h1:CclWJ
github.com/dymensionxyz/cometbft v0.34.29-0.20241008141942-63af9d24107f/go.mod h1:L9shMfbkZ8B+7JlwANEr+NZbBcn+hBpwdbeYvA5rLCw=
github.com/dymensionxyz/cosmosclient v0.4.2-beta.0.20240821081230-b4018b2bac13 h1:u5yeve5jZR6TdRjjR+vYT/8PWKbhwCZxUmAu+/Tnxyg=
github.com/dymensionxyz/cosmosclient v0.4.2-beta.0.20240821081230-b4018b2bac13/go.mod h1:jabDQYXrccscSE0fXkh7eQFYPWJCRiuWKonFGObVq6s=
github.com/dymensionxyz/dymension-rdk v1.6.1-0.20241020152926-b250db7af580 h1:bgECFCjc/8lVq9/UQ4qCTdD/znUgKEX7a0QBOcGuuNg=
github.com/dymensionxyz/dymension-rdk v1.6.1-0.20241020152926-b250db7af580/go.mod h1:m9D/CACMkMAXKFeuU+1lkUIPWpMFb0EvGl7M5vV0HoA=
github.com/dymensionxyz/dymint v1.2.0-rc01.0.20241015102238-a827c3784461 h1:ZNh5s2dmfcgPE9g6OlhHBFtygiAxCRr+wPKSgpSo/Bw=
github.com/dymensionxyz/dymint v1.2.0-rc01.0.20241015102238-a827c3784461/go.mod h1:FNVdsvVhveAOeL0Mj9VIfGkAUKhGskEr0iRnoM+MAkU=
github.com/dymensionxyz/dymension-rdk v1.6.1-0.20241029165002-545051749bc0 h1:Pshmw95Ej/RBg+ZTgMxpdGB/Bpis2tKEjSmqwVHgaXo=
github.com/dymensionxyz/dymension-rdk v1.6.1-0.20241029165002-545051749bc0/go.mod h1:HH7sGM/4MSI8OLces8axABf7K0ppXNok+G2nxC/l5YI=
github.com/dymensionxyz/dymint v1.2.0-rc01.0.20241024144934-db109b2859b4 h1:DpfHfiqNJ0QgnPNq/nx2fAUDWwLlWORQ605uQyPPODU=
github.com/dymensionxyz/dymint v1.2.0-rc01.0.20241024144934-db109b2859b4/go.mod h1:FNVdsvVhveAOeL0Mj9VIfGkAUKhGskEr0iRnoM+MAkU=
github.com/dymensionxyz/evmos/v12 v12.1.6-dymension-v0.4.2 h1:aVP3off7u2vsvRH7lHAUPTLdf9/AfnzC/rvvi0wC/co=
github.com/dymensionxyz/evmos/v12 v12.1.6-dymension-v0.4.2/go.mod h1:CI6D89pkoiIm4BjoMFNnEaCLdKBEobLuwvhS0c1zh7Y=
github.com/dymensionxyz/gerr-cosmos v1.0.0 h1:oi91rgOkpJWr41oX9JOyjvvBnhGY54tj513x8VlDAEc=
Expand Down

0 comments on commit f850e3b

Please sign in to comment.