Skip to content

Commit

Permalink
Merge pull request #2852 from irisnet/dreamer/refator-evm
Browse files Browse the repository at this point in the history
refactor: fix eip712 signature and inject ParseChainID method
  • Loading branch information
taramakage authored Jul 4, 2023
2 parents 9a4825f + d329f97 commit 2ebea9e
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 66 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
129 changes: 106 additions & 23 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 ****/
Expand Down Expand Up @@ -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)
Expand All @@ -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()

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
21 changes: 0 additions & 21 deletions modules/evm/moudle.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 4 additions & 15 deletions types/chain_id.go
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 4 additions & 0 deletions types/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -77,4 +79,6 @@ func init() {
NativeToken.Mintable,
owner,
)

etherminttypes.InjectChainIDParser(parseChainID)
}

0 comments on commit 2ebea9e

Please sign in to comment.