diff --git a/CHANGELOG.md b/CHANGELOG.md index c21c2124b..5258b26e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [Unreleased] + +### Bug Fixes +* (IRISHub) [\#2852](https://github.com/irisnet/irishub/pull/2852) refactor: fix eip712 signature and inject ParseChainID method + ## 2.0.0 ### State Machine Breaking diff --git a/app/app.go b/app/app.go index b5bb349e6..ff1986c4c 100644 --- a/app/app.go +++ b/app/app.go @@ -102,6 +102,7 @@ import ( tibccli "github.com/bianjieai/tibc-go/modules/tibc/core/client/cli" tibckeeper "github.com/bianjieai/tibc-go/modules/tibc/core/keeper" + "github.com/evmos/ethermint/ethereum/eip712" srvflags "github.com/evmos/ethermint/server/flags" ethermint "github.com/evmos/ethermint/types" evmkeeper "github.com/evmos/ethermint/x/evm/keeper" @@ -219,24 +220,55 @@ func NewIrisApp( legacyAmino := encodingConfig.Amino interfaceRegistry := encodingConfig.InterfaceRegistry - bApp := baseapp.NewBaseApp(iristypes.AppName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...) + bApp := baseapp.NewBaseApp( + iristypes.AppName, + logger, + db, + encodingConfig.TxConfig.TxDecoder(), + baseAppOptions...) bApp.SetCommitMultiStoreTracer(traceStore) bApp.SetVersion(version.Version) bApp.SetInterfaceRegistry(interfaceRegistry) keys := sdk.NewKVStoreKeys( - authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, - minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, - govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, - evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey, - guardiantypes.StoreKey, tokentypes.StoreKey, nfttypes.StoreKey, htlctypes.StoreKey, recordtypes.StoreKey, - coinswaptypes.StoreKey, servicetypes.StoreKey, oracletypes.StoreKey, randomtypes.StoreKey, - farmtypes.StoreKey, feegrant.StoreKey, tibchost.StoreKey, tibcnfttypes.StoreKey, tibcmttypes.StoreKey, mttypes.StoreKey, + authtypes.StoreKey, + banktypes.StoreKey, + stakingtypes.StoreKey, + minttypes.StoreKey, + distrtypes.StoreKey, + slashingtypes.StoreKey, + govtypes.StoreKey, + paramstypes.StoreKey, + ibchost.StoreKey, + upgradetypes.StoreKey, + evidencetypes.StoreKey, + ibctransfertypes.StoreKey, + capabilitytypes.StoreKey, + guardiantypes.StoreKey, + tokentypes.StoreKey, + nfttypes.StoreKey, + htlctypes.StoreKey, + recordtypes.StoreKey, + coinswaptypes.StoreKey, + servicetypes.StoreKey, + oracletypes.StoreKey, + randomtypes.StoreKey, + farmtypes.StoreKey, + feegrant.StoreKey, + tibchost.StoreKey, + tibcnfttypes.StoreKey, + tibcmttypes.StoreKey, + mttypes.StoreKey, authzkeeper.StoreKey, // ethermint keys - evmtypes.StoreKey, feemarkettypes.StoreKey, + evmtypes.StoreKey, + feemarkettypes.StoreKey, + ) + tkeys := sdk.NewTransientStoreKeys( + paramstypes.TStoreKey, + evmtypes.TransientKey, + feemarkettypes.TransientKey, ) - tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey, evmtypes.TransientKey, feemarkettypes.TransientKey) memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) // configure state listening capabilities using AppOptions @@ -256,14 +288,26 @@ func NewIrisApp( memKeys: memKeys, } - app.ParamsKeeper = initParamsKeeper(appCodec, legacyAmino, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey]) + app.init() + + app.ParamsKeeper = initParamsKeeper( + appCodec, + legacyAmino, + keys[paramstypes.StoreKey], + tkeys[paramstypes.TStoreKey], + ) // set the BaseApp's parameter store bApp.SetParamStore( - app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable()), + app.ParamsKeeper.Subspace(baseapp.Paramspace). + WithKeyTable(paramstypes.ConsensusParamsKeyTable()), ) // add capability keeper and ScopeToModule for ibc module - app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey]) + app.CapabilityKeeper = capabilitykeeper.NewKeeper( + appCodec, + keys[capabilitytypes.StoreKey], + memKeys[capabilitytypes.MemStoreKey], + ) scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName) scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) @@ -291,7 +335,11 @@ func NewIrisApp( ) stakingKeeper := stakingkeeper.NewKeeper( - appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName), + appCodec, + keys[stakingtypes.StoreKey], + app.AccountKeeper, + app.BankKeeper, + app.GetSubspace(stakingtypes.ModuleName), ) app.MintKeeper = mintkeeper.NewKeeper( @@ -549,13 +597,24 @@ func NewIrisApp( // Create Ethermint keepers app.FeeMarketKeeper = feemarketkeeper.NewKeeper( - appCodec, app.GetSubspace(feemarkettypes.ModuleName), keys[feemarkettypes.StoreKey], tkeys[feemarkettypes.TransientKey], + appCodec, + app.GetSubspace(feemarkettypes.ModuleName), + keys[feemarkettypes.StoreKey], + tkeys[feemarkettypes.TransientKey], ) app.EvmKeeper = evmkeeper.NewKeeper( - appCodec, keys[evmtypes.StoreKey], tkeys[evmtypes.TransientKey], app.GetSubspace(evmtypes.ModuleName), - app.AccountKeeper, app.BankKeeper, &stakingKeeper, app.FeeMarketKeeper, - nil, geth.NewEVM, tracer, + appCodec, + keys[evmtypes.StoreKey], + tkeys[evmtypes.TransientKey], + app.GetSubspace(evmtypes.ModuleName), + app.AccountKeeper, + app.BankKeeper, + &stakingKeeper, + app.FeeMarketKeeper, + nil, + geth.NewEVM, + tracer, ) /**** Module Options ****/ @@ -583,7 +642,11 @@ func NewIrisApp( // can do so safely. app.mm.SetOrderInitGenesis(orderInitBlockers()...) - app.configurator = module.NewConfigurator(appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter()) + app.configurator = module.NewConfigurator( + appCodec, + app.MsgServiceRouter(), + app.GRPCQueryRouter(), + ) app.mm.RegisterInvariants(&app.CrisisKeeper) app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino) app.mm.RegisterServices(app.configurator) @@ -592,7 +655,8 @@ func NewIrisApp( // // NOTE: this is not required apps that don't use the simulator for fuzz testing // transactions - app.sm = module.NewSimulationManager(simulationModules(app, encodingConfig, skipGenesisInvariants)...) + app.sm = module.NewSimulationManager( + simulationModules(app, encodingConfig, skipGenesisInvariants)...) app.sm.RegisterStoreDecoders() @@ -655,7 +719,10 @@ func NewIrisApp( func (app *IrisApp) Name() string { return app.BaseApp.Name() } // BeginBlocker application updates every begin block -func (app *IrisApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock { +func (app *IrisApp) BeginBlocker( + ctx sdk.Context, + req abci.RequestBeginBlock, +) abci.ResponseBeginBlock { return app.mm.BeginBlock(ctx, req) } @@ -777,7 +844,12 @@ func (app *IrisApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APICo // RegisterTxService implements the Application.RegisterTxService method. func (app *IrisApp) RegisterTxService(clientCtx client.Context) { - authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry) + authtx.RegisterTxService( + app.BaseApp.GRPCQueryRouter(), + clientCtx, + app.BaseApp.Simulate, + app.interfaceRegistry, + ) } // RegisterTendermintService implements the Application.RegisterTendermintService method. @@ -790,8 +862,19 @@ func (app *IrisApp) RegisterTendermintService(clientCtx client.Context) { ) } +func (app *IrisApp) init() { + eip712.InjectCodec(eip712.Codec{ + InterfaceRegistry: app.interfaceRegistry, + Amino: app.legacyAmino, + }) +} + // initParamsKeeper init params keeper and its subspaces -func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey storetypes.StoreKey) paramskeeper.Keeper { +func initParamsKeeper( + appCodec codec.BinaryCodec, + legacyAmino *codec.LegacyAmino, + key, tkey storetypes.StoreKey, +) paramskeeper.Keeper { paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey) paramsKeeper.Subspace(authtypes.ModuleName) diff --git a/go.mod b/go.mod index 8dcdccb48..b8d2db48c 100644 --- a/go.mod +++ b/go.mod @@ -206,4 +206,4 @@ replace github.com/zondax/hid => github.com/zondax/hid v0.9.0 replace github.com/tendermint/tendermint => github.com/informalsystems/tendermint v0.34.26 // use bianjieai fork of ethermint -replace github.com/evmos/ethermint => github.com/bianjieai/ethermint v0.20.0-irishub-1 +replace github.com/evmos/ethermint => github.com/bianjieai/ethermint v0.20.1-0.20230605095401-15e71e5689f8 diff --git a/go.sum b/go.sum index 70dd092f1..b02a111a4 100644 --- a/go.sum +++ b/go.sum @@ -138,8 +138,8 @@ github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 h1:41iFGWnSlI2gVpmOtVTJZNodLdLQLn/KsJqFvXwnd/s= github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/bianjieai/ethermint v0.20.0-irishub-1 h1:Wp/5xV5JVcPO4HCYMKOE6ks+QForncsghrloT0nqIek= -github.com/bianjieai/ethermint v0.20.0-irishub-1/go.mod h1:6GwJlPogJh9aiWrDGNIOIQ0fX2Lo3Tc7sTvrSe+BFL4= +github.com/bianjieai/ethermint v0.20.1-0.20230605095401-15e71e5689f8 h1:SiMobVHil1Z7qi0yKGHORsobo/VzwxQjUdrlxOW8UVU= +github.com/bianjieai/ethermint v0.20.1-0.20230605095401-15e71e5689f8/go.mod h1:6GwJlPogJh9aiWrDGNIOIQ0fX2Lo3Tc7sTvrSe+BFL4= github.com/bianjieai/tibc-go v0.4.3 h1:SlV6nmZZHTgkdpPLFnSoKPyKZJRZMKcTPxoF7UWdCm4= github.com/bianjieai/tibc-go v0.4.3/go.mod h1:aHGACCjSgovxA5+H/WP7xLz+tTjGxul804Xese2TQ3k= github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c= diff --git a/modules/evm/moudle.go b/modules/evm/moudle.go index 361320fb8..aa539e94e 100644 --- a/modules/evm/moudle.go +++ b/modules/evm/moudle.go @@ -1,19 +1,11 @@ package evm import ( - "encoding/json" - - abci "github.com/tendermint/tendermint/abci/types" - - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" ethermint "github.com/evmos/ethermint/x/evm" "github.com/evmos/ethermint/x/evm/keeper" "github.com/evmos/ethermint/x/evm/types" - - iristypes "github.com/irisnet/irishub/types" ) var ( @@ -36,19 +28,6 @@ func NewAppModule(k *keeper.Keeper, ak types.AccountKeeper, bankKeeper types.Ban } } -// BeginBlock returns the begin block for the evm module. -func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { - ethChainID := iristypes.BuildEthChainID(ctx.ChainID()) - am.AppModule.BeginBlock(ctx.WithChainID(ethChainID), req) -} - -// InitGenesis performs genesis initialization for the evm module. It returns -// no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { - ethChainID := iristypes.BuildEthChainID(ctx.ChainID()) - return am.AppModule.InitGenesis(ctx.WithChainID(ethChainID), cdc, data) -} - // RegisterServices registers a GRPC query service to respond to the // module-specific GRPC queries. func (am AppModule) RegisterServices(cfg module.Configurator) { diff --git a/server/start.go b/server/start.go index e734bb22d..2dd1ad86f 100644 --- a/server/start.go +++ b/server/start.go @@ -52,8 +52,6 @@ import ( "github.com/evmos/ethermint/server/config" srvflags "github.com/evmos/ethermint/server/flags" ethermint "github.com/evmos/ethermint/types" - - iristypes "github.com/irisnet/irishub/types" ) // StartCmd runs the service passed in, either stand-alone or in-process with @@ -529,8 +527,7 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, appCreator ty return err } - chainID := iristypes.BuildEthChainID(genDoc.ChainID) - clientCtx := clientCtx.WithChainID(chainID) + clientCtx := clientCtx.WithChainID(genDoc.ChainID) tmEndpoint := "/websocket" tmRPCAddr := cfg.RPC.ListenAddress diff --git a/types/chain_id.go b/types/chain_id.go index b0bb1340f..28c960b22 100644 --- a/types/chain_id.go +++ b/types/chain_id.go @@ -1,29 +1,18 @@ package types import ( + "fmt" "math/big" - "strings" - - etherminttypes "github.com/evmos/ethermint/types" ) var ( EIP155ChainID = "6688" ) -func BuildEthChainID(chainID string) string { - if etherminttypes.IsValidChainID(chainID) { - return chainID - } - +func parseChainID(_ string) (*big.Int, error) { eip155ChainID, ok := new(big.Int).SetString(EIP155ChainID, 10) if !ok { - panic("invalid chain-id: " + EIP155ChainID) - } - - chains := strings.Split(chainID, "-") - if len(chains) != 2 { - panic("invalid chain-id: " + chainID) + return nil, fmt.Errorf("invalid chain-id: %s" + EIP155ChainID) } - return chains[0] + "_" + eip155ChainID.String() + "-" + chains[1] + return eip155ChainID, nil } diff --git a/types/runtime.go b/types/runtime.go index 6c5d8b24a..d2574bc33 100644 --- a/types/runtime.go +++ b/types/runtime.go @@ -9,6 +9,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" + etherminttypes "github.com/evmos/ethermint/types" + "github.com/irisnet/irishub/address" tokentypes "github.com/irisnet/irismod/modules/token/types" tokenv1 "github.com/irisnet/irismod/modules/token/types/v1" @@ -77,4 +79,6 @@ func init() { NativeToken.Mintable, owner, ) + + etherminttypes.InjectChainIDParser(parseChainID) }