From baf5456fb61997e44eba8525893d65700d5fde8b Mon Sep 17 00:00:00 2001 From: mmsqe Date: Wed, 13 Sep 2023 16:01:23 +0800 Subject: [PATCH] Problem: event converter don't have to be global --- app/app.go | 6 ++---- go.mod | 2 +- go.sum | 4 ++-- gomod2nix.toml | 4 ++-- x/cronos/keeper/precompiles/interface.go | 14 ++++++++++++++ x/cronos/keeper/precompiles/relayer.go | 5 ++--- x/cronos/keeper/precompiles/utils.go | 6 +++--- 7 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 x/cronos/keeper/precompiles/interface.go diff --git a/app/app.go b/app/app.go index a001e6c2c2..9c36081f5d 100644 --- a/app/app.go +++ b/app/app.go @@ -127,7 +127,6 @@ import ( ethermint "github.com/evmos/ethermint/types" "github.com/evmos/ethermint/x/evm" evmkeeper "github.com/evmos/ethermint/x/evm/keeper" - "github.com/evmos/ethermint/x/evm/keeper/precompiles" evmtypes "github.com/evmos/ethermint/x/evm/types" "github.com/evmos/ethermint/x/feemarket" feemarketkeeper "github.com/evmos/ethermint/x/feemarket/keeper" @@ -146,12 +145,12 @@ import ( "github.com/crypto-org-chain/cronos/v2/app/ante" "github.com/crypto-org-chain/cronos/v2/x/cronos" cronosclient "github.com/crypto-org-chain/cronos/v2/x/cronos/client" - cronosevents "github.com/crypto-org-chain/cronos/v2/x/cronos/events" cronoskeeper "github.com/crypto-org-chain/cronos/v2/x/cronos/keeper" evmhandlers "github.com/crypto-org-chain/cronos/v2/x/cronos/keeper/evmhandlers" cronosprecompiles "github.com/crypto-org-chain/cronos/v2/x/cronos/keeper/precompiles" "github.com/crypto-org-chain/cronos/v2/x/cronos/middleware" cronostypes "github.com/crypto-org-chain/cronos/v2/x/cronos/types" + "github.com/ethereum/go-ethereum/core/vm" "github.com/crypto-org-chain/cronos/v2/client/docs" @@ -547,11 +546,10 @@ func New( app.FeeMarketKeeper, tracer, evmS, - []precompiles.StatefulPrecompiledContract{ + []vm.PrecompiledContract{ cronosprecompiles.NewRelayerContract(app.IBCKeeper, appCodec), }, allKeys, - cronosevents.ConvertEvent, ) var gravityKeeper gravitykeeper.Keeper diff --git a/go.mod b/go.mod index b0fa294a08..0ac7fd774d 100644 --- a/go.mod +++ b/go.mod @@ -238,7 +238,7 @@ replace ( // TODO: remove it: https://github.com/cosmos/cosmos-sdk/issues/13134 github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2 github.com/ethereum/go-ethereum => github.com/evmos/go-ethereum v1.10.26-evmos-rc1 - github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20230913025430-199ccc232fd4 + github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20230913063514-bf62d0b33e56 // Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities. // TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409 github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0 diff --git a/go.sum b/go.sum index 99c7712ff5..137267ec39 100644 --- a/go.sum +++ b/go.sum @@ -497,8 +497,8 @@ github.com/crypto-org-chain/cometbft-db v0.0.0-20230412133340-ac70df4b45f6 h1:d4 github.com/crypto-org-chain/cometbft-db v0.0.0-20230412133340-ac70df4b45f6/go.mod h1:hF5aclS++7WrW8USOA3zPeKI0CuzwUD2TPYug25ANlQ= github.com/crypto-org-chain/cosmos-sdk v0.46.0-beta2.0.20230905040840-b3af5590283b h1:d2GOFR3i3BjDlPsmJkp8Gsrt9LK2nq2IVEnE/rMv1Fo= github.com/crypto-org-chain/cosmos-sdk v0.46.0-beta2.0.20230905040840-b3af5590283b/go.mod h1:EHwCeN9IXonsjKcjpS12MqeStdZvIdxt3VYXhus3G3c= -github.com/crypto-org-chain/ethermint v0.6.1-0.20230913025430-199ccc232fd4 h1:h9rEAyTlS1GkEcK9CPgh16mcVYOTRfKXgmlGyCz129E= -github.com/crypto-org-chain/ethermint v0.6.1-0.20230913025430-199ccc232fd4/go.mod h1:xT6yzwilauRVhkvhjj7lDzazfgG4ZeUNSoQsuKImitY= +github.com/crypto-org-chain/ethermint v0.6.1-0.20230913063514-bf62d0b33e56 h1:nu9oo/IEG8O2PZD57vUB43g+sK/3pH1gov9F5gI26OM= +github.com/crypto-org-chain/ethermint v0.6.1-0.20230913063514-bf62d0b33e56/go.mod h1:xT6yzwilauRVhkvhjj7lDzazfgG4ZeUNSoQsuKImitY= github.com/crypto-org-chain/gravity-bridge/module/v2 v2.0.1-0.20230825054824-75403cd90c6e h1:rSTc35OBjjCBx47rHPWBCIHNGPbMnEj8f7fNcK2TjVI= github.com/crypto-org-chain/gravity-bridge/module/v2 v2.0.1-0.20230825054824-75403cd90c6e/go.mod h1:HBaDqlFjlaXJwVQtA7jHejyaA7xwjXI2o6pU/ccP3tE= github.com/cyphar/filepath-securejoin v0.2.3/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= diff --git a/gomod2nix.toml b/gomod2nix.toml index 82cc8f04b0..ad2bab04b2 100644 --- a/gomod2nix.toml +++ b/gomod2nix.toml @@ -218,8 +218,8 @@ schema = 3 hash = "sha256-GgcReGsIIuBE2TabDYqDO9sBGogdVr9RSh4arQzdPnE=" replaced = "github.com/evmos/go-ethereum" [mod."github.com/evmos/ethermint"] - version = "v0.6.1-0.20230913025430-199ccc232fd4" - hash = "sha256-AnPsOXlXVOYznPBC6vh2alov09p0fy0cO6BTRcekU8o=" + version = "v0.6.1-0.20230913063514-bf62d0b33e56" + hash = "sha256-1WE0BADrSWYmRs3DnuleD0+Jhc/ImQbgKHFSCYzNMT4=" replaced = "github.com/crypto-org-chain/ethermint" [mod."github.com/felixge/httpsnoop"] version = "v1.0.2" diff --git a/x/cronos/keeper/precompiles/interface.go b/x/cronos/keeper/precompiles/interface.go new file mode 100644 index 0000000000..e3117589d1 --- /dev/null +++ b/x/cronos/keeper/precompiles/interface.go @@ -0,0 +1,14 @@ +package precompiles + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/vm" + "github.com/evmos/ethermint/x/evm/statedb" +) + +// ExtStateDB defines extra methods of statedb to support stateful precompiled contracts +type ExtStateDB interface { + vm.StateDB + ExecuteNativeAction(contract common.Address, converter statedb.EventConverter, action func(ctx sdk.Context) error) error +} diff --git a/x/cronos/keeper/precompiles/relayer.go b/x/cronos/keeper/precompiles/relayer.go index 5775985bd5..b6b59c9826 100644 --- a/x/cronos/keeper/precompiles/relayer.go +++ b/x/cronos/keeper/precompiles/relayer.go @@ -7,7 +7,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/vm" - "github.com/evmos/ethermint/x/evm/keeper/precompiles" ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" ) @@ -24,7 +23,7 @@ type RelayerContract struct { ibcKeeper *ibckeeper.Keeper } -func NewRelayerContract(ibcKeeper *ibckeeper.Keeper, cdc codec.Codec) precompiles.StatefulPrecompiledContract { +func NewRelayerContract(ibcKeeper *ibckeeper.Keeper, cdc codec.Codec) vm.PrecompiledContract { return &RelayerContract{ BaseContract: NewBaseContract(RelayerContractAddress), ibcKeeper: ibcKeeper, @@ -81,7 +80,7 @@ func (bc *RelayerContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool } prefix := int(binary.LittleEndian.Uint32(contract.Input[:prefixSize4Bytes])) input := contract.Input[prefixSize4Bytes:] - stateDB := evm.StateDB.(precompiles.ExtStateDB) + stateDB := evm.StateDB.(ExtStateDB) var ( err error diff --git a/x/cronos/keeper/precompiles/utils.go b/x/cronos/keeper/precompiles/utils.go index 44c27a8c73..bc443d01b5 100644 --- a/x/cronos/keeper/precompiles/utils.go +++ b/x/cronos/keeper/precompiles/utils.go @@ -7,8 +7,8 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + cronosevents "github.com/crypto-org-chain/cronos/v2/x/cronos/events" "github.com/ethereum/go-ethereum/common" - "github.com/evmos/ethermint/x/evm/keeper/precompiles" ) type NativeMessage interface { @@ -22,7 +22,7 @@ func exec[Req any, PReq interface { NativeMessage }, Resp codec.ProtoMarshaler]( cdc codec.Codec, - stateDB precompiles.ExtStateDB, + stateDB ExtStateDB, caller common.Address, contract common.Address, input []byte, @@ -42,7 +42,7 @@ func exec[Req any, PReq interface { } var res Resp - if err := stateDB.ExecuteNativeAction(contract, func(ctx sdk.Context) error { + if err := stateDB.ExecuteNativeAction(contract, cronosevents.ConvertEvent, func(ctx sdk.Context) error { var err error res, err = action(ctx, msg) return err