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

fix: register missing codecs for supporting ethsecp256k1 algo #138

Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ Modify `dymint.toml` in the chain directory (`~/.rollapp/config`)

```shell
dasel put -f "${ROLLAPP_HOME_DIR}"/config/dymint.toml "settlement_layer" -v "dymension"
dasel put -f "${ROLLAPP_HOME_DIR}"/config/dymint.toml "node_address" -v "$HUB_RPC_URL"
dasel put -f "${ROLLAPP_HOME_DIR}"/config/dymint.toml "settlement_node_address" -v "$HUB_RPC_URL"
dasel put -f "${ROLLAPP_HOME_DIR}"/config/dymint.toml "rollapp_id" -v "$ROLLAPP_CHAIN_ID"
dasel put -f "${ROLLAPP_HOME_DIR}"/config/dymint.toml "max_idle_time" -v "2s"
dasel put -f "${ROLLAPP_HOME_DIR}"/config/dymint.toml "max_proof_time" -v "1s"
Expand Down
136 changes: 112 additions & 24 deletions app/ante.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
package app

import (
"fmt"
"runtime/debug"

errorsmod "cosmossdk.io/errors"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
conntypes "github.com/cosmos/ibc-go/v6/modules/core/03-connection/types"
ibcante "github.com/cosmos/ibc-go/v6/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v6/modules/core/keeper"
cosmosante "github.com/evmos/evmos/v12/app/ante/cosmos"
evmostypes "github.com/evmos/evmos/v12/types"
evmtypes "github.com/evmos/evmos/v12/x/evm/types"
tmlog "github.com/tendermint/tendermint/libs/log"

"github.com/dymensionxyz/dymension-rdk/x/gasless"
gaslesskeeper "github.com/dymensionxyz/dymension-rdk/x/gasless/keeper"
cosmosante "github.com/evmos/evmos/v12/app/ante/cosmos"
)

// HandlerOptions are the options required for constructing a default SDK AnteHandler.
Expand All @@ -26,13 +33,74 @@ type HandlerOptions struct {
GaslessKeeper gaslesskeeper.Keeper
}

func GetAnteDecorators(options HandlerOptions) []sdk.AnteDecorator {
// NewAnteHandler returns an AnteHandler that checks and increments sequence
// numbers, checks signatures & account numbers, and deducts fees from the first
// signer.
func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
if err := options.validate(); err != nil {
return nil, fmt.Errorf("options validate: %w", err)
}

return func(
ctx sdk.Context, tx sdk.Tx, sim bool,
) (newCtx sdk.Context, err error) {
var anteHandler sdk.AnteHandler

defer Recover(ctx.Logger(), &err)

txWithExtensions, ok := tx.(ante.HasExtensionOptionsTx)
if ok {
opts := txWithExtensions.GetExtensionOptions()
if len(opts) > 0 {
switch typeURL := opts[0].GetTypeUrl(); typeURL {
case "/ethermint.types.v1.ExtensionOptionsWeb3Tx":
// Deprecated: Handle as normal Cosmos SDK tx, except signature is checked for Legacy EIP712 representation
options.ExtensionOptionChecker = func(c *codectypes.Any) bool {
_, ok := c.GetCachedValue().(*evmostypes.ExtensionOptionsWeb3Tx)
return ok
}
anteHandler = cosmosHandler(
options,
// nolint:staticcheck
cosmosante.NewLegacyEip712SigVerificationDecorator(options.AccountKeeper.(evmtypes.AccountKeeper), options.SignModeHandler), // Use old signature verification: uses EIP instead of the cosmos signature validator
)
default:
return ctx, errorsmod.Wrapf(
sdkerrors.ErrUnknownExtensionOptions,
"rejecting tx with unsupported extension option: %s", typeURL,
)
}

return anteHandler(ctx, tx, sim)
}
}

// handle as totally normal Cosmos SDK tx
switch tx.(type) {
case sdk.Tx:
// we reject any extension
anteHandler = cosmosHandler(
options,
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler), // Use modern signature verification
)
default:
return ctx, errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "invalid transaction type: %T", tx)
}

return anteHandler(ctx, tx, sim)
}, nil
}

func cosmosHandler(options HandlerOptions, sigChecker sdk.AnteDecorator) sdk.AnteHandler {
sigGasConsumer := options.SigGasConsumer
if sigGasConsumer == nil {
sigGasConsumer = ante.DefaultSigVerificationGasConsumer
}

anteDecorators := []sdk.AnteDecorator{
// only override the modern sig checker, and preserve the legacy one
if _, ok := sigChecker.(ante.SigVerificationDecorator); ok {
sigChecker = NewSigCheckDecorator(options.AccountKeeper.(accountKeeper), options.SignModeHandler)
}
return sdk.ChainAnteDecorators(
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
cosmosante.NewRejectMessagesDecorator(
[]string{
Expand All @@ -53,35 +121,55 @@ func GetAnteDecorators(options HandlerOptions) []sdk.AnteDecorator {
ante.NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
ante.NewValidateSigCountDecorator(options.AccountKeeper),
ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer),
NewSigCheckDecorator(options.AccountKeeper.(accountKeeper), options.SignModeHandler),
sigChecker,
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
}

anteDecorators = append(anteDecorators, ibcante.NewRedundantRelayDecorator(options.IBCKeeper))

return anteDecorators
)
}

// NewAnteHandler returns an AnteHandler that checks and increments sequence
// numbers, checks signatures & account numbers, and deducts fees from the first
// signer.
func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
func (o HandlerOptions) validate() error {
zale144 marked this conversation as resolved.
Show resolved Hide resolved
// From x/auth/ante.go
if options.AccountKeeper == nil {
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "account keeper is required for ante builder")
if o.AccountKeeper == nil {
return errorsmod.Wrap(sdkerrors.ErrLogic, "account keeper is required for ante builder")
}

if options.BankKeeper == nil {
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "bank keeper is required for ante builder")
if o.BankKeeper == nil {
return errorsmod.Wrap(sdkerrors.ErrLogic, "bank keeper is required for ante builder")
}

if options.SignModeHandler == nil {
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
if o.SignModeHandler == nil {
return errorsmod.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
}

if options.WasmConfig == nil {
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "wasm config is required for ante builder")
if o.WasmConfig == nil {
return errorsmod.Wrap(sdkerrors.ErrLogic, "wasm config is required for ante builder")
}

return sdk.ChainAnteDecorators(GetAnteDecorators(options)...), nil
if o.TxCounterStoreKey == nil {
return errorsmod.Wrap(sdkerrors.ErrLogic, "tx counter store key is required for ante builder")
}

if o.SigGasConsumer == nil {
return errorsmod.Wrap(sdkerrors.ErrLogic, "signature gas consumer is required for ante builder")
}

return nil
}

func Recover(logger tmlog.Logger, err *error) {
if r := recover(); r != nil {
*err = errorsmod.Wrapf(sdkerrors.ErrPanic, "%v", r)

if e, ok := r.(error); ok {
logger.Error(
"ante handler panicked",
"error", e,
"stack trace", string(debug.Stack()),
)
} else {
logger.Error(
"ante handler panicked",
"recover", fmt.Sprintf("%v", r),
)
}
}
}
16 changes: 9 additions & 7 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/authz"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
gaslessmodule "github.com/dymensionxyz/dymension-rdk/x/gasless"
gaslesskeeper "github.com/dymensionxyz/dymension-rdk/x/gasless/keeper"
gaslesstypes "github.com/dymensionxyz/dymension-rdk/x/gasless/types"
evmosante "github.com/evmos/evmos/v12/app/ante"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
abci "github.com/tendermint/tendermint/abci/types"
Expand All @@ -23,6 +21,10 @@ import (
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"

gaslessmodule "github.com/dymensionxyz/dymension-rdk/x/gasless"
gaslesskeeper "github.com/dymensionxyz/dymension-rdk/x/gasless/keeper"
gaslesstypes "github.com/dymensionxyz/dymension-rdk/x/gasless/types"

"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 @@ -144,7 +146,7 @@ import (
cwerrorsKeeper "github.com/dymensionxyz/rollapp-wasm/x/cwerrors/keeper"
cwerrorsTypes "github.com/dymensionxyz/rollapp-wasm/x/cwerrors/types"

rollappparams "github.com/dymensionxyz/dymension-rdk/x/rollappparams"
"github.com/dymensionxyz/dymension-rdk/x/rollappparams"
rollappparamskeeper "github.com/dymensionxyz/dymension-rdk/x/rollappparams/keeper"
rollappparamstypes "github.com/dymensionxyz/dymension-rdk/x/rollappparams/types"
)
Expand Down Expand Up @@ -847,14 +849,14 @@ func NewRollapp(
}

func (app *App) setAnteHandler(txConfig client.TxConfig, wasmConfig wasmtypes.WasmConfig) {
anteHandler, err := NewAnteHandler(
handler, err := NewAnteHandler(
HandlerOptions{
HandlerOptions: ante.HandlerOptions{
AccountKeeper: app.AccountKeeper,
BankKeeper: app.BankKeeper,
FeegrantKeeper: app.FeeGrantKeeper,
SignModeHandler: txConfig.SignModeHandler(),
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
SigGasConsumer: evmosante.SigVerificationGasConsumer,
},
IBCKeeper: app.IBCKeeper,
WasmConfig: &wasmConfig,
Expand All @@ -866,7 +868,7 @@ func (app *App) setAnteHandler(txConfig client.TxConfig, wasmConfig wasmtypes.Wa
panic(err)
}

app.SetAnteHandler(anteHandler)
app.SetAnteHandler(handler)
}

func (app *App) setPostHandler() {
Expand Down
21 changes: 19 additions & 2 deletions app/encoding.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
package app

import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/std"
sdk "github.com/cosmos/cosmos-sdk/types"
cryptocodec "github.com/evmos/evmos/v12/crypto/codec"

"github.com/dymensionxyz/rollapp-wasm/app/params"
)

// MakeEncodingConfig creates an EncodingConfig for testing
func MakeEncodingConfig() params.EncodingConfig {
encodingConfig := params.MakeEncodingConfig()
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
RegisterLegacyAminoCodec(encodingConfig.Amino)
RegisterInterfaces(encodingConfig.InterfaceRegistry)
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)
return encodingConfig
}

// RegisterLegacyAminoCodec registers Interfaces from types, crypto, and SDK std.
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
sdk.RegisterLegacyAminoCodec(cdc)
cryptocodec.RegisterCrypto(cdc)
codec.RegisterEvidences(cdc)
}

// RegisterInterfaces registers Interfaces from types, crypto, and SDK std.
func RegisterInterfaces(interfaceRegistry codectypes.InterfaceRegistry) {
std.RegisterInterfaces(interfaceRegistry)
cryptocodec.RegisterInterfaces(interfaceRegistry)
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ require (
github.com/dgraph-io/badger/v3 v3.2103.3 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dop251/goja v0.0.0-20220405120441-9037c2b61cbf // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/dymensionxyz/cosmosclient v0.4.2-beta.0.20240821081230-b4018b2bac13 // indirect
github.com/dymensionxyz/gerr-cosmos v1.0.0 // indirect
Expand All @@ -135,6 +137,7 @@ require (
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
Expand Down
18 changes: 10 additions & 8 deletions rollappd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import (
"github.com/cosmos/cosmos-sdk/client/config"
"github.com/cosmos/cosmos-sdk/client/debug"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/keys"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/server"
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
"github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
ethermintclient "github.com/evmos/evmos/v12/client"
evmosconfig "github.com/evmos/evmos/v12/cmd/config"
"github.com/prometheus/client_golang/prometheus"
"github.com/spf13/cast"
"github.com/spf13/cobra"
Expand All @@ -38,6 +38,7 @@ import (
rdkserverconfig "github.com/dymensionxyz/dymension-rdk/server/config"
"github.com/dymensionxyz/dymension-rdk/utils"
dymintconf "github.com/dymensionxyz/dymint/config"

"github.com/dymensionxyz/rollapp-wasm/app"
"github.com/dymensionxyz/rollapp-wasm/app/params"
)
Expand All @@ -54,7 +55,7 @@ const rollappAscii = `
func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
encodingConfig := app.MakeEncodingConfig()

//TODO: refactor to use depinject
// TODO: refactor to use depinject

initClientCtx := client.Context{}.
WithCodec(encodingConfig.Codec).
Expand All @@ -68,7 +69,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
WithViper("ROLLAPP")

rootCmd := &cobra.Command{
//TODO: set by code, not in Makefile
// TODO: set by code, not in Makefile
Use: version.AppName,
Short: rollappAscii,
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
Expand Down Expand Up @@ -100,11 +101,11 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
}
serverCtx := server.GetServerContextFromCmd(cmd)

//create dymint toml config file
// create dymint toml config file
home := serverCtx.Viper.GetString(tmcli.HomeFlag)
dymintconf.EnsureRoot(home, dymintconf.DefaultConfig(home))

//create Block Explorer Json-RPC toml config file
// create Block Explorer Json-RPC toml config file
berpcconfig.EnsureRoot(home, berpcconfig.DefaultBeJsonRpcConfig())

return nil
Expand Down Expand Up @@ -145,6 +146,7 @@ func initRootCmd(
// Set config
sdkconfig := sdk.GetConfig()
utils.SetPrefixes(sdkconfig, app.AccountAddressPrefix)
evmosconfig.SetBip44CoinType(sdkconfig)
sdkconfig.Seal()

ac := appCreator{
Expand All @@ -171,7 +173,7 @@ func initRootCmd(
rpc.StatusCommand(),
queryCommand(),
txCommand(),
keys.Commands(app.DefaultNodeHome),
ethermintclient.KeyCommands(app.DefaultNodeHome),
)
}

Expand Down
Loading