From ea6805c4b6633c2560bc40881a882f5228a80a6e Mon Sep 17 00:00:00 2001 From: evgeniy-scherbina Date: Thu, 15 Feb 2024 16:59:44 -0500 Subject: [PATCH] IBCTransfer doesn't panic --- x/evm/keeper/state_transition.go | 4 +++- x/evm/statedb/statedb.go | 4 ++++ x/evm/vm/geth/geth.go | 4 +++- x/evm/vm/interface.go | 2 ++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/x/evm/keeper/state_transition.go b/x/evm/keeper/state_transition.go index ad90dba5fd..d4b80f008d 100644 --- a/x/evm/keeper/state_transition.go +++ b/x/evm/keeper/state_transition.go @@ -52,6 +52,8 @@ func (k *Keeper) NewEVM( tracer vm.EVMLogger, stateDB vm.StateDB, ) evm.EVM { + goCtx := sdk.WrapSDKContext(ctx) + blockCtx := vm.BlockContext{ CanTransfer: core.CanTransfer, Transfer: core.Transfer, @@ -70,7 +72,7 @@ func (k *Keeper) NewEVM( tracer = k.Tracer(ctx, msg, cfg.ChainConfig) } vmConfig := k.VMConfig(ctx, msg, cfg, tracer) - return k.evmConstructor(blockCtx, txCtx, stateDB, cfg.ChainConfig, vmConfig, k.customPrecompiles) + return k.evmConstructor(goCtx, blockCtx, txCtx, stateDB, cfg.ChainConfig, vmConfig, k.customPrecompiles) } // GetHashFn implements vm.GetHashFunc for Ethermint. It handles 3 cases: diff --git a/x/evm/statedb/statedb.go b/x/evm/statedb/statedb.go index 5ad0b4163d..c50f78be45 100644 --- a/x/evm/statedb/statedb.go +++ b/x/evm/statedb/statedb.go @@ -91,6 +91,10 @@ func (s *StateDB) Keeper() Keeper { return s.keeper } +func (s *StateDB) Context() context.Context { + return s.ctx +} + // AddLog adds a log, called by evm. func (s *StateDB) AddLog(log *ethtypes.Log) { s.journal.append(addLogChange{}) diff --git a/x/evm/vm/geth/geth.go b/x/evm/vm/geth/geth.go index ebbf8743db..0ee33c9658 100644 --- a/x/evm/vm/geth/geth.go +++ b/x/evm/vm/geth/geth.go @@ -16,6 +16,7 @@ package geth import ( + "context" "math/big" "github.com/ethereum/go-ethereum/common" @@ -40,6 +41,7 @@ type EVM struct { // the default precompiled contracts and the EVM concrete implementation from // geth. func NewEVM( + goCtx context.Context, blockCtx vm.BlockContext, txCtx vm.TxContext, stateDB vm.StateDB, @@ -48,7 +50,7 @@ func NewEVM( _ evm.PrecompiledContracts, // unused ) evm.EVM { return &EVM{ - EVM: vm.NewEVM(blockCtx, txCtx, stateDB, chainConfig, config), + EVM: vm.NewEVMWithContext(goCtx, blockCtx, txCtx, stateDB, chainConfig, config), } } diff --git a/x/evm/vm/interface.go b/x/evm/vm/interface.go index ef88ffb38e..b96dcd14d0 100644 --- a/x/evm/vm/interface.go +++ b/x/evm/vm/interface.go @@ -16,6 +16,7 @@ package vm import ( + "context" "math/big" "github.com/ethereum/go-ethereum/common" @@ -75,6 +76,7 @@ type EVM interface { // Constructor defines the function used to instantiate the EVM on // each state transition. type Constructor func( + goCtx context.Context, blockCtx vm.BlockContext, txCtx vm.TxContext, stateDB vm.StateDB,