diff --git a/evmrpc/config_test.go b/evmrpc/config_test.go index 39e3472f8..191052de2 100644 --- a/evmrpc/config_test.go +++ b/evmrpc/config_test.go @@ -1,6 +1,7 @@ package evmrpc_test import ( + "fmt" "testing" "time" @@ -25,6 +26,8 @@ type opts struct { checkTxTimeout interface{} maxTxPoolTxs interface{} slow interface{} + liveEVMTracer interface{} + liveEVMTracerChainID interface{} } func (o *opts) Get(k string) interface{} { @@ -76,7 +79,13 @@ func (o *opts) Get(k string) interface{} { if k == "evm.slow" { return o.slow } - panic("unknown key") + if k == "evm.live_evm_tracer" { + return o.slow + } + if k == "evm.live_evm_tracer_chain_id" { + return o.slow + } + panic(fmt.Errorf("unknown key: %s", k)) } func TestReadConfig(t *testing.T) { @@ -97,6 +106,8 @@ func TestReadConfig(t *testing.T) { time.Duration(5), 1000, false, + "", + 0, } _, err := evmrpc.ReadConfig(&goodOpts) require.Nil(t, err) diff --git a/go.mod b/go.mod index 19d6edcf8..68f5c7a0b 100644 --- a/go.mod +++ b/go.mod @@ -349,7 +349,7 @@ replace ( github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.2.73-evm-rebase-10 github.com/cosmos/iavl => github.com/sei-protocol/sei-iavl v0.1.9 github.com/cosmos/ibc-go/v3 => github.com/sei-protocol/sei-ibc-go/v3 v3.3.0 - github.com/ethereum/go-ethereum => github.com/streamingfast/go-ethereum v1.13.6-0.20240223010308-d0fd1bd7f3cf + github.com/ethereum/go-ethereum => github.com/streamingfast/go-ethereum v1.13.6-0.20240315211644-7ea867c72711 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.30 // Latest goleveldb is broken, we have to stick to this version diff --git a/go.sum b/go.sum index 0aa6d7b5a..23cacaa4a 100644 --- a/go.sum +++ b/go.sum @@ -1427,8 +1427,8 @@ github.com/stbenjam/no-sprintf-host-port v0.1.1/go.mod h1:TLhvtIvONRzdmkFiio4O8L github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI= -github.com/streamingfast/go-ethereum v1.13.6-0.20240223010308-d0fd1bd7f3cf h1:sB6WRi5KuZMc0I9sVxSStN1cNJxSToPh3RfX9lO5iD0= -github.com/streamingfast/go-ethereum v1.13.6-0.20240223010308-d0fd1bd7f3cf/go.mod h1:kcRZmuzRn1lVejiFNTz4l4W7imnpq1bDAnuKS/RyhbQ= +github.com/streamingfast/go-ethereum v1.13.6-0.20240315211644-7ea867c72711 h1:cFjcFr/S7U8ApOvdCv2TOCPPblo+6tmntTfjyYMKq5A= +github.com/streamingfast/go-ethereum v1.13.6-0.20240315211644-7ea867c72711/go.mod h1:kcRZmuzRn1lVejiFNTz4l4W7imnpq1bDAnuKS/RyhbQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= diff --git a/precompiles/bank/bank_test.go b/precompiles/bank/bank_test.go index dbbd657f4..bae6ac558 100644 --- a/precompiles/bank/bank_test.go +++ b/precompiles/bank/bank_test.go @@ -35,7 +35,7 @@ func TestRun(t *testing.T) { require.Nil(t, err) args, err := send.Inputs.Pack(senderEVMAddr, evmAddr, "usei", big.NewInt(25)) require.Nil(t, err) - _, err = p.Run(&evm, senderEVMAddr, append(p.SendID, args...)) // should error because address is not whitelisted + _, err = p.Run(&evm, senderEVMAddr, append(p.SendID, args...), nil) // should error because address is not whitelisted require.NotNil(t, err) k.BankKeeper().SendCoins(ctx, senderAddr, seiAddr, sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(50)))) @@ -44,21 +44,21 @@ func TestRun(t *testing.T) { require.Nil(t, err) args, err = balance.Inputs.Pack(evmAddr, "usei") require.Nil(t, err) - res, err := p.Run(&evm, common.Address{}, append(p.BalanceID, args...)) + res, err := p.Run(&evm, common.Address{}, append(p.BalanceID, args...), nil) require.Nil(t, err) is, err := balance.Outputs.Unpack(res) require.Nil(t, err) require.Equal(t, 1, len(is)) require.Equal(t, big.NewInt(50), is[0].(*big.Int)) - res, err = p.Run(&evm, common.Address{}, append(p.BalanceID, args[:1]...)) + res, err = p.Run(&evm, common.Address{}, append(p.BalanceID, args[:1]...), nil) require.NotNil(t, err) args, err = balance.Inputs.Pack(evmAddr, "") require.Nil(t, err) - res, err = p.Run(&evm, common.Address{}, append(p.BalanceID, args...)) + res, err = p.Run(&evm, common.Address{}, append(p.BalanceID, args...), nil) require.NotNil(t, err) // invalid input - _, err = p.Run(&evm, common.Address{}, []byte{1, 2, 3, 4}) + _, err = p.Run(&evm, common.Address{}, []byte{1, 2, 3, 4}, nil) require.NotNil(t, err) } @@ -75,7 +75,7 @@ func TestMetadata(t *testing.T) { require.Nil(t, err) args, err := name.Inputs.Pack("usei") require.Nil(t, err) - res, err := p.Run(&evm, common.Address{}, append(p.NameID, args...)) + res, err := p.Run(&evm, common.Address{}, append(p.NameID, args...), nil) require.Nil(t, err) outputs, err := name.Outputs.Unpack(res) require.Nil(t, err) @@ -85,7 +85,7 @@ func TestMetadata(t *testing.T) { require.Nil(t, err) args, err = symbol.Inputs.Pack("usei") require.Nil(t, err) - res, err = p.Run(&evm, common.Address{}, append(p.SymbolID, args...)) + res, err = p.Run(&evm, common.Address{}, append(p.SymbolID, args...), nil) require.Nil(t, err) outputs, err = symbol.Outputs.Unpack(res) require.Nil(t, err) @@ -95,7 +95,7 @@ func TestMetadata(t *testing.T) { require.Nil(t, err) args, err = decimal.Inputs.Pack("usei") require.Nil(t, err) - res, err = p.Run(&evm, common.Address{}, append(p.DecimalsID, args...)) + res, err = p.Run(&evm, common.Address{}, append(p.DecimalsID, args...), nil) require.Nil(t, err) outputs, err = decimal.Outputs.Unpack(res) require.Nil(t, err) @@ -105,7 +105,7 @@ func TestMetadata(t *testing.T) { require.Nil(t, err) args, err = supply.Inputs.Pack("usei") require.Nil(t, err) - res, err = p.Run(&evm, common.Address{}, append(p.SupplyID, args...)) + res, err = p.Run(&evm, common.Address{}, append(p.SupplyID, args...), nil) require.Nil(t, err) outputs, err = supply.Outputs.Unpack(res) require.Nil(t, err) diff --git a/precompiles/json/json_test.go b/precompiles/json/json_test.go index e6a7ba5eb..80710c75a 100644 --- a/precompiles/json/json_test.go +++ b/precompiles/json/json_test.go @@ -41,7 +41,7 @@ func TestExtractAsBytes(t *testing.T) { args, err := method.Inputs.Pack(test.body, "key") require.Nil(t, err) input := append(p.ExtractAsBytesID, args...) - res, err := p.Run(evm, common.Address{}, input) + res, err := p.Run(evm, common.Address{}, input, nil) require.Nil(t, err) output, err := method.Outputs.Unpack(res) require.Nil(t, err) @@ -79,7 +79,7 @@ func TestExtractAsBytesList(t *testing.T) { args, err := method.Inputs.Pack(test.body, "key") require.Nil(t, err) input := append(p.ExtractAsBytesListID, args...) - res, err := p.Run(evm, common.Address{}, input) + res, err := p.Run(evm, common.Address{}, input, nil) require.Nil(t, err) output, err := method.Outputs.Unpack(res) require.Nil(t, err) @@ -113,7 +113,7 @@ func TestExtractAsUint256(t *testing.T) { args, err := method.Inputs.Pack(test.body, "key") require.Nil(t, err) input := append(p.ExtractAsUint256ID, args...) - res, err := p.Run(evm, common.Address{}, input) + res, err := p.Run(evm, common.Address{}, input, nil) require.Nil(t, err) output, err := method.Outputs.Unpack(res) require.Nil(t, err) diff --git a/precompiles/wasmd/wasmd_test.go b/precompiles/wasmd/wasmd_test.go index 2d476d21c..57a840a9b 100644 --- a/precompiles/wasmd/wasmd_test.go +++ b/precompiles/wasmd/wasmd_test.go @@ -61,7 +61,7 @@ func TestInstantiate(t *testing.T) { StateDB: statedb, } suppliedGas := uint64(1000000) - res, g, err := p.RunAndCalculateGas(&evm, mockEVMAddr, mockEVMAddr, append(p.InstantiateID, args...), suppliedGas) + res, g, err := p.RunAndCalculateGas(&evm, mockEVMAddr, mockEVMAddr, append(p.InstantiateID, args...), suppliedGas, nil) require.Nil(t, err) outputs, err := instantiateMethod.Outputs.Unpack(res) require.Nil(t, err) @@ -78,16 +78,16 @@ func TestInstantiate(t *testing.T) { "test", amtsbz, ) - res, g, err = p.RunAndCalculateGas(&evm, mockEVMAddr, mockEVMAddr, append(p.InstantiateID, args...), suppliedGas) + res, g, err = p.RunAndCalculateGas(&evm, mockEVMAddr, mockEVMAddr, append(p.InstantiateID, args...), suppliedGas, nil) require.NotNil(t, err) require.Equal(t, uint64(0), g) // bad inputs badArgs, _ := instantiateMethod.Inputs.Pack(codeID, "not bech32", []byte("{}"), "test", amtsbz) - _, g, err = p.RunAndCalculateGas(&evm, mockEVMAddr, mockEVMAddr, append(p.InstantiateID, badArgs...), suppliedGas) + _, g, err = p.RunAndCalculateGas(&evm, mockEVMAddr, mockEVMAddr, append(p.InstantiateID, badArgs...), suppliedGas, nil) require.NotNil(t, err) badArgs, _ = instantiateMethod.Inputs.Pack(codeID, mockAddr.String(), []byte("{}"), "test", []byte("bad coins")) - _, g, err = p.RunAndCalculateGas(&evm, mockEVMAddr, mockEVMAddr, append(p.InstantiateID, badArgs...), suppliedGas) + _, g, err = p.RunAndCalculateGas(&evm, mockEVMAddr, mockEVMAddr, append(p.InstantiateID, badArgs...), suppliedGas, nil) require.NotNil(t, err) } @@ -122,7 +122,7 @@ func TestExecute(t *testing.T) { StateDB: statedb, } suppliedGas := uint64(1000000) - res, g, err := p.RunAndCalculateGas(&evm, mockEVMAddr, mockEVMAddr, append(p.ExecuteID, args...), suppliedGas) + res, g, err := p.RunAndCalculateGas(&evm, mockEVMAddr, mockEVMAddr, append(p.ExecuteID, args...), suppliedGas, nil) require.Nil(t, err) outputs, err := executeMethod.Outputs.Unpack(res) require.Nil(t, err) @@ -135,27 +135,27 @@ func TestExecute(t *testing.T) { contractAddrAllowed := common.BytesToAddress([]byte("contractA")) testApp.EvmKeeper.SetCode(ctx, contractAddrAllowed, []byte("allowed")) testApp.EvmKeeper.AddCodeHashWhitelistedForDelegateCall(ctx, testApp.EvmKeeper.GetCodeHash(ctx, contractAddrAllowed)) - res, g, err = p.RunAndCalculateGas(&evm, mockEVMAddr, contractAddrAllowed, append(p.ExecuteID, args...), suppliedGas) + res, g, err = p.RunAndCalculateGas(&evm, mockEVMAddr, contractAddrAllowed, append(p.ExecuteID, args...), suppliedGas, nil) require.Nil(t, err) // disallowed delegatecall contractAddrDisallowed := common.BytesToAddress([]byte("contractB")) - res, g, err = p.RunAndCalculateGas(&evm, mockEVMAddr, contractAddrDisallowed, append(p.ExecuteID, args...), suppliedGas) + res, g, err = p.RunAndCalculateGas(&evm, mockEVMAddr, contractAddrDisallowed, append(p.ExecuteID, args...), suppliedGas, nil) require.NotNil(t, err) // bad contract address args, _ = executeMethod.Inputs.Pack(mockAddr.String(), []byte("{\"echo\":{\"message\":\"test msg\"}}"), amtsbz) - res, g, err = p.RunAndCalculateGas(&evm, mockEVMAddr, mockEVMAddr, append(p.ExecuteID, args...), suppliedGas) + res, g, err = p.RunAndCalculateGas(&evm, mockEVMAddr, mockEVMAddr, append(p.ExecuteID, args...), suppliedGas, nil) require.NotNil(t, err) require.Equal(t, uint64(0), g) // bad inputs args, _ = executeMethod.Inputs.Pack("not bech32", []byte("{\"echo\":{\"message\":\"test msg\"}}"), amtsbz) - res, g, err = p.RunAndCalculateGas(&evm, mockEVMAddr, mockEVMAddr, append(p.ExecuteID, args...), suppliedGas) + res, g, err = p.RunAndCalculateGas(&evm, mockEVMAddr, mockEVMAddr, append(p.ExecuteID, args...), suppliedGas, nil) require.NotNil(t, err) require.Equal(t, uint64(0), g) args, _ = executeMethod.Inputs.Pack(contractAddr.String(), []byte("{\"echo\":{\"message\":\"test msg\"}}"), []byte("bad coins")) - res, g, err = p.RunAndCalculateGas(&evm, mockEVMAddr, mockEVMAddr, append(p.ExecuteID, args...), suppliedGas) + res, g, err = p.RunAndCalculateGas(&evm, mockEVMAddr, mockEVMAddr, append(p.ExecuteID, args...), suppliedGas, nil) require.NotNil(t, err) require.Equal(t, uint64(0), g) } @@ -183,7 +183,7 @@ func TestQuery(t *testing.T) { StateDB: statedb, } suppliedGas := uint64(1000000) - res, g, err := p.RunAndCalculateGas(&evm, common.Address{}, common.Address{}, append(p.QueryID, args...), suppliedGas) + res, g, err := p.RunAndCalculateGas(&evm, common.Address{}, common.Address{}, append(p.QueryID, args...), suppliedGas, nil) require.Nil(t, err) outputs, err := queryMethod.Outputs.Unpack(res) require.Nil(t, err) @@ -193,17 +193,17 @@ func TestQuery(t *testing.T) { // bad contract address args, _ = queryMethod.Inputs.Pack(mockAddr.String(), []byte("{\"info\":{}}")) - res, g, err = p.RunAndCalculateGas(&evm, common.Address{}, common.Address{}, append(p.ExecuteID, args...), suppliedGas) + res, g, err = p.RunAndCalculateGas(&evm, common.Address{}, common.Address{}, append(p.ExecuteID, args...), suppliedGas, nil) require.NotNil(t, err) require.Equal(t, uint64(0), g) // bad input args, _ = queryMethod.Inputs.Pack("not bech32", []byte("{\"info\":{}}")) - res, g, err = p.RunAndCalculateGas(&evm, common.Address{}, common.Address{}, append(p.ExecuteID, args...), suppliedGas) + res, g, err = p.RunAndCalculateGas(&evm, common.Address{}, common.Address{}, append(p.ExecuteID, args...), suppliedGas, nil) require.NotNil(t, err) require.Equal(t, uint64(0), g) args, _ = queryMethod.Inputs.Pack(contractAddr.String(), []byte("{\"bad\":{}}")) - res, g, err = p.RunAndCalculateGas(&evm, common.Address{}, common.Address{}, append(p.ExecuteID, args...), suppliedGas) + res, g, err = p.RunAndCalculateGas(&evm, common.Address{}, common.Address{}, append(p.ExecuteID, args...), suppliedGas, nil) require.NotNil(t, err) require.Equal(t, uint64(0), g) } diff --git a/x/evm/keeper/msg_server.go b/x/evm/keeper/msg_server.go index 1c79437d9..7f4b959e2 100644 --- a/x/evm/keeper/msg_server.go +++ b/x/evm/keeper/msg_server.go @@ -159,12 +159,12 @@ func (server msgServer) getEVM(ctx sdk.Context, msg *core.Message, stateDB *stat cfg := types.DefaultChainConfig().EthereumConfig(server.ChainID(ctx)) txCtx := core.NewEVMTxContext(msg) - logger := evmtracers.GetCtxBlockchainLogger(ctx) + hooks := evmtracers.GetCtxEthTracingHooks(ctx) evmInstance := vm.NewEVM(*blockCtx, txCtx, stateDB, cfg, vm.Config{ - Tracer: logger.Hooks, + Tracer: hooks, }) stateDB.SetEVM(evmInstance) - stateDB.SetLogger(logger.Hooks) + stateDB.SetLogger(hooks) return evmInstance, nil } diff --git a/x/evm/module_test.go b/x/evm/module_test.go index aa3e7c05e..ea9dd2b25 100644 --- a/x/evm/module_test.go +++ b/x/evm/module_test.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/ethereum/go-ethereum/common" - ethstate "github.com/ethereum/go-ethereum/core/state" + "github.com/ethereum/go-ethereum/core/tracing" ethtypes "github.com/ethereum/go-ethereum/core/types" testkeeper "github.com/sei-protocol/sei-chain/testutil/keeper" "github.com/sei-protocol/sei-chain/x/evm" @@ -29,19 +29,19 @@ func TestABCI(t *testing.T) { m.BeginBlock(ctx, abci.RequestBeginBlock{}) // 1st tx s := state.NewDBImpl(ctx.WithTxIndex(1), k, false) - s.SubBalance(evmAddr1, big.NewInt(10000000000000), ethstate.BalanceChangeUnspecified) - s.AddBalance(evmAddr2, big.NewInt(8000000000000), ethstate.BalanceChangeUnspecified) + s.SubBalance(evmAddr1, big.NewInt(10000000000000), tracing.BalanceChangeUnspecified) + s.AddBalance(evmAddr2, big.NewInt(8000000000000), tracing.BalanceChangeUnspecified) feeCollectorAddr, err := k.GetFeeCollectorAddress(ctx) require.Nil(t, err) - s.AddBalance(feeCollectorAddr, big.NewInt(2000000000000), ethstate.BalanceChangeUnspecified) + s.AddBalance(feeCollectorAddr, big.NewInt(2000000000000), tracing.BalanceChangeUnspecified) surplus, err := s.Finalize() require.Nil(t, err) require.Equal(t, sdk.ZeroInt(), surplus) k.AppendToEvmTxDeferredInfo(ctx.WithTxIndex(1), ethtypes.Bloom{}, common.Hash{}, surplus) // 3rd tx s = state.NewDBImpl(ctx.WithTxIndex(3), k, false) - s.SubBalance(evmAddr2, big.NewInt(5000000000000), ethstate.BalanceChangeUnspecified) - s.AddBalance(evmAddr1, big.NewInt(5000000000000), ethstate.BalanceChangeUnspecified) + s.SubBalance(evmAddr2, big.NewInt(5000000000000), tracing.BalanceChangeUnspecified) + s.AddBalance(evmAddr1, big.NewInt(5000000000000), tracing.BalanceChangeUnspecified) surplus, err = s.Finalize() require.Nil(t, err) require.Equal(t, sdk.ZeroInt(), surplus) @@ -55,8 +55,8 @@ func TestABCI(t *testing.T) { m.BeginBlock(ctx, abci.RequestBeginBlock{}) // 2nd tx s = state.NewDBImpl(ctx.WithTxIndex(2), k, false) - s.SubBalance(evmAddr2, big.NewInt(3000000000000), ethstate.BalanceChangeUnspecified) - s.AddBalance(evmAddr1, big.NewInt(2000000000000), ethstate.BalanceChangeUnspecified) + s.SubBalance(evmAddr2, big.NewInt(3000000000000), tracing.BalanceChangeUnspecified) + s.AddBalance(evmAddr1, big.NewInt(2000000000000), tracing.BalanceChangeUnspecified) surplus, err = s.Finalize() require.Nil(t, err) require.Equal(t, sdk.NewInt(1000000000000), surplus) diff --git a/x/evm/state/balance_test.go b/x/evm/state/balance_test.go index 7302c05c3..1201d3005 100644 --- a/x/evm/state/balance_test.go +++ b/x/evm/state/balance_test.go @@ -5,7 +5,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - ethstate "github.com/ethereum/go-ethereum/core/state" + "github.com/ethereum/go-ethereum/core/tracing" testkeeper "github.com/sei-protocol/sei-chain/testutil/keeper" "github.com/sei-protocol/sei-chain/x/evm/state" "github.com/sei-protocol/sei-chain/x/evm/types" @@ -17,17 +17,17 @@ func TestAddBalance(t *testing.T) { db := state.NewDBImpl(ctx, k, false) seiAddr, evmAddr := testkeeper.MockAddressPair() require.Equal(t, big.NewInt(0), db.GetBalance(evmAddr)) - db.AddBalance(evmAddr, big.NewInt(0), ethstate.BalanceChangeUnspecified) + db.AddBalance(evmAddr, big.NewInt(0), tracing.BalanceChangeUnspecified) // set association k.SetAddressMapping(db.Ctx(), seiAddr, evmAddr) require.Equal(t, big.NewInt(0), db.GetBalance(evmAddr)) - db.AddBalance(evmAddr, big.NewInt(10000000000000), ethstate.BalanceChangeUnspecified) + db.AddBalance(evmAddr, big.NewInt(10000000000000), tracing.BalanceChangeUnspecified) require.Nil(t, db.Err()) require.Equal(t, db.GetBalance(evmAddr), big.NewInt(10000000000000)) _, evmAddr2 := testkeeper.MockAddressPair() - db.SubBalance(evmAddr2, big.NewInt(-5000000000000), ethstate.BalanceChangeUnspecified) // should redirect to AddBalance + db.SubBalance(evmAddr2, big.NewInt(-5000000000000), tracing.BalanceChangeUnspecified) // should redirect to AddBalance require.Nil(t, db.Err()) require.Equal(t, db.GetBalance(evmAddr), big.NewInt(10000000000000)) require.Equal(t, db.GetBalance(evmAddr2), big.NewInt(5000000000000)) @@ -38,7 +38,7 @@ func TestSubBalance(t *testing.T) { db := state.NewDBImpl(ctx, k, false) seiAddr, evmAddr := testkeeper.MockAddressPair() require.Equal(t, big.NewInt(0), db.GetBalance(evmAddr)) - db.SubBalance(evmAddr, big.NewInt(0), ethstate.BalanceChangeUnspecified) + db.SubBalance(evmAddr, big.NewInt(0), tracing.BalanceChangeUnspecified) // set association k.SetAddressMapping(db.Ctx(), seiAddr, evmAddr) @@ -46,7 +46,7 @@ func TestSubBalance(t *testing.T) { amt := sdk.NewCoins(sdk.NewCoin(k.GetBaseDenom(ctx), sdk.NewInt(20))) k.BankKeeper().MintCoins(db.Ctx(), types.ModuleName, amt) k.BankKeeper().SendCoinsFromModuleToAccount(db.Ctx(), types.ModuleName, seiAddr, amt) - db.SubBalance(evmAddr, big.NewInt(10000000000000), ethstate.BalanceChangeUnspecified) + db.SubBalance(evmAddr, big.NewInt(10000000000000), tracing.BalanceChangeUnspecified) require.Nil(t, db.Err()) require.Equal(t, db.GetBalance(evmAddr), big.NewInt(10000000000000)) @@ -54,13 +54,13 @@ func TestSubBalance(t *testing.T) { amt = sdk.NewCoins(sdk.NewCoin(k.GetBaseDenom(ctx), sdk.NewInt(10))) k.BankKeeper().MintCoins(db.Ctx(), types.ModuleName, amt) k.BankKeeper().SendCoinsFromModuleToAccount(db.Ctx(), types.ModuleName, sdk.AccAddress(evmAddr2[:]), amt) - db.AddBalance(evmAddr2, big.NewInt(-5000000000000), ethstate.BalanceChangeUnspecified) // should redirect to SubBalance + db.AddBalance(evmAddr2, big.NewInt(-5000000000000), tracing.BalanceChangeUnspecified) // should redirect to SubBalance require.Nil(t, db.Err()) require.Equal(t, db.GetBalance(evmAddr), big.NewInt(10000000000000)) require.Equal(t, db.GetBalance(evmAddr2), big.NewInt(5000000000000)) // insufficient balance - db.SubBalance(evmAddr2, big.NewInt(10000000000000), ethstate.BalanceChangeUnspecified) + db.SubBalance(evmAddr2, big.NewInt(10000000000000), tracing.BalanceChangeUnspecified) require.NotNil(t, db.Err()) } @@ -68,12 +68,12 @@ func TestSetBalance(t *testing.T) { k, ctx := testkeeper.MockEVMKeeper() db := state.NewDBImpl(ctx, k, true) _, evmAddr := testkeeper.MockAddressPair() - db.SetBalance(evmAddr, big.NewInt(10000000000000), ethstate.BalanceChangeUnspecified) + db.SetBalance(evmAddr, big.NewInt(10000000000000), tracing.BalanceChangeUnspecified) require.Equal(t, big.NewInt(10000000000000), db.GetBalance(evmAddr)) seiAddr2, evmAddr2 := testkeeper.MockAddressPair() k.SetAddressMapping(db.Ctx(), seiAddr2, evmAddr2) - db.SetBalance(evmAddr2, big.NewInt(10000000000000), ethstate.BalanceChangeUnspecified) + db.SetBalance(evmAddr2, big.NewInt(10000000000000), tracing.BalanceChangeUnspecified) require.Equal(t, big.NewInt(10000000000000), db.GetBalance(evmAddr2)) } @@ -83,55 +83,55 @@ func TestSurplus(t *testing.T) { // test negative usei surplus negative wei surplus db := state.NewDBImpl(ctx, k, false) - db.AddBalance(evmAddr, big.NewInt(1_000_000_000_001), ethstate.BalanceChangeUnspecified) + db.AddBalance(evmAddr, big.NewInt(1_000_000_000_001), tracing.BalanceChangeUnspecified) _, err := db.Finalize() require.NotNil(t, err) require.Contains(t, err.Error(), "negative surplus value") // test negative usei surplus positive wei surplus (negative total) db = state.NewDBImpl(ctx, k, false) - db.AddBalance(evmAddr, big.NewInt(1_000_000_000_000), ethstate.BalanceChangeUnspecified) - db.SubBalance(evmAddr, big.NewInt(1), ethstate.BalanceChangeUnspecified) + db.AddBalance(evmAddr, big.NewInt(1_000_000_000_000), tracing.BalanceChangeUnspecified) + db.SubBalance(evmAddr, big.NewInt(1), tracing.BalanceChangeUnspecified) _, err = db.Finalize() require.NotNil(t, err) require.Contains(t, err.Error(), "negative surplus value") // test negative usei surplus positive wei surplus (positive total) db = state.NewDBImpl(ctx, k, false) - db.AddBalance(evmAddr, big.NewInt(1_000_000_000_000), ethstate.BalanceChangeUnspecified) - db.SubBalance(evmAddr, big.NewInt(2), ethstate.BalanceChangeUnspecified) - db.SubBalance(evmAddr, big.NewInt(999_999_999_999), ethstate.BalanceChangeUnspecified) + db.AddBalance(evmAddr, big.NewInt(1_000_000_000_000), tracing.BalanceChangeUnspecified) + db.SubBalance(evmAddr, big.NewInt(2), tracing.BalanceChangeUnspecified) + db.SubBalance(evmAddr, big.NewInt(999_999_999_999), tracing.BalanceChangeUnspecified) surplus, err := db.Finalize() require.Nil(t, err) require.Equal(t, sdk.OneInt(), surplus) // test positive usei surplus negative wei surplus (negative total) db = state.NewDBImpl(ctx, k, false) - db.SubBalance(evmAddr, big.NewInt(1_000_000_000_000), ethstate.BalanceChangeUnspecified) - db.AddBalance(evmAddr, big.NewInt(2), ethstate.BalanceChangeUnspecified) - db.AddBalance(evmAddr, big.NewInt(999_999_999_999), ethstate.BalanceChangeUnspecified) + db.SubBalance(evmAddr, big.NewInt(1_000_000_000_000), tracing.BalanceChangeUnspecified) + db.AddBalance(evmAddr, big.NewInt(2), tracing.BalanceChangeUnspecified) + db.AddBalance(evmAddr, big.NewInt(999_999_999_999), tracing.BalanceChangeUnspecified) _, err = db.Finalize() require.NotNil(t, err) require.Contains(t, err.Error(), "negative surplus value") // test positive usei surplus negative wei surplus (positive total) db = state.NewDBImpl(ctx, k, false) - db.SubBalance(evmAddr, big.NewInt(1_000_000_000_000), ethstate.BalanceChangeUnspecified) - db.AddBalance(evmAddr, big.NewInt(999_999_999_999), ethstate.BalanceChangeUnspecified) + db.SubBalance(evmAddr, big.NewInt(1_000_000_000_000), tracing.BalanceChangeUnspecified) + db.AddBalance(evmAddr, big.NewInt(999_999_999_999), tracing.BalanceChangeUnspecified) surplus, err = db.Finalize() require.Nil(t, err) require.Equal(t, sdk.OneInt(), surplus) // test snapshots db = state.NewDBImpl(ctx, k, false) - db.SubBalance(evmAddr, big.NewInt(1_000_000_000_000), ethstate.BalanceChangeUnspecified) - db.AddBalance(evmAddr, big.NewInt(999_999_999_999), ethstate.BalanceChangeUnspecified) + db.SubBalance(evmAddr, big.NewInt(1_000_000_000_000), tracing.BalanceChangeUnspecified) + db.AddBalance(evmAddr, big.NewInt(999_999_999_999), tracing.BalanceChangeUnspecified) db.Snapshot() - db.SubBalance(evmAddr, big.NewInt(1_000_000_000_000), ethstate.BalanceChangeUnspecified) - db.AddBalance(evmAddr, big.NewInt(999_999_999_999), ethstate.BalanceChangeUnspecified) + db.SubBalance(evmAddr, big.NewInt(1_000_000_000_000), tracing.BalanceChangeUnspecified) + db.AddBalance(evmAddr, big.NewInt(999_999_999_999), tracing.BalanceChangeUnspecified) db.Snapshot() - db.SubBalance(evmAddr, big.NewInt(1_000_000_000_000), ethstate.BalanceChangeUnspecified) - db.AddBalance(evmAddr, big.NewInt(999_999_999_999), ethstate.BalanceChangeUnspecified) + db.SubBalance(evmAddr, big.NewInt(1_000_000_000_000), tracing.BalanceChangeUnspecified) + db.AddBalance(evmAddr, big.NewInt(999_999_999_999), tracing.BalanceChangeUnspecified) surplus, err = db.Finalize() require.Nil(t, err) require.Equal(t, sdk.NewInt(3), surplus) diff --git a/x/evm/state/check_test.go b/x/evm/state/check_test.go index 0908990f1..8d3d32133 100644 --- a/x/evm/state/check_test.go +++ b/x/evm/state/check_test.go @@ -4,7 +4,7 @@ import ( "math/big" "testing" - ethstate "github.com/ethereum/go-ethereum/core/state" + "github.com/ethereum/go-ethereum/core/tracing" testkeeper "github.com/sei-protocol/sei-chain/testutil/keeper" "github.com/sei-protocol/sei-chain/x/evm/state" "github.com/stretchr/testify/require" @@ -36,11 +36,11 @@ func TestEmpty(t *testing.T) { require.True(t, statedb.Empty(addr)) // has balance - statedb.AddBalance(addr, big.NewInt(1000000000000), ethstate.BalanceChangeUnspecified) + statedb.AddBalance(addr, big.NewInt(1000000000000), tracing.BalanceChangeUnspecified) require.False(t, statedb.Empty(addr)) // has non-zero nonce - statedb.SubBalance(addr, big.NewInt(1000000000000), ethstate.BalanceChangeUnspecified) + statedb.SubBalance(addr, big.NewInt(1000000000000), tracing.BalanceChangeUnspecified) statedb.SetNonce(addr, 1) require.False(t, statedb.Empty(addr)) diff --git a/x/evm/state/state_test.go b/x/evm/state/state_test.go index 08b87cbfd..84f1a9c36 100644 --- a/x/evm/state/state_test.go +++ b/x/evm/state/state_test.go @@ -6,7 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/common" - ethstate "github.com/ethereum/go-ethereum/core/state" + "github.com/ethereum/go-ethereum/core/tracing" testkeeper "github.com/sei-protocol/sei-chain/testutil/keeper" "github.com/sei-protocol/sei-chain/x/evm/state" "github.com/sei-protocol/sei-chain/x/evm/types" @@ -20,7 +20,7 @@ func TestState(t *testing.T) { statedb.CreateAccount(evmAddr) require.True(t, statedb.Created(evmAddr)) require.False(t, statedb.HasSelfDestructed(evmAddr)) - statedb.AddBalance(evmAddr, big.NewInt(10), ethstate.BalanceChangeUnspecified) + statedb.AddBalance(evmAddr, big.NewInt(10), tracing.BalanceChangeUnspecified) k.BankKeeper().MintCoins(statedb.Ctx(), types.ModuleName, sdk.NewCoins(sdk.NewCoin(k.GetBaseDenom(ctx), sdk.NewInt(10)))) key := common.BytesToHash([]byte("abc")) val := common.BytesToHash([]byte("def")) @@ -61,7 +61,7 @@ func TestCreate(t *testing.T) { tval := common.BytesToHash([]byte("mno")) statedb.SetState(evmAddr, key, val) statedb.SetTransientState(evmAddr, tkey, tval) - statedb.AddBalance(evmAddr, big.NewInt(10000000000000), ethstate.BalanceChangeUnspecified) + statedb.AddBalance(evmAddr, big.NewInt(10000000000000), tracing.BalanceChangeUnspecified) // recreate an account should clear its state, but keep its balance and transient state statedb.CreateAccount(evmAddr) require.Equal(t, tval, statedb.GetTransientState(evmAddr, tkey)) diff --git a/x/evm/state/statedb.go b/x/evm/state/statedb.go index 96780972a..d40bc737d 100644 --- a/x/evm/state/statedb.go +++ b/x/evm/state/statedb.go @@ -101,7 +101,7 @@ func (s *DBImpl) GetStorageRoot(common.Address) common.Hash { panic("GetStorageRoot is not implemented and called unexpectedly") } -func (s *DBImpl) Copy() interface{} { +func (s *DBImpl) Copy() vm.StateDB { newCtx := s.ctx.WithMultiStore(s.ctx.MultiStore().CacheMultiStore()) return &DBImpl{ ctx: newCtx, diff --git a/x/evm/tracers/firehose_test.go b/x/evm/tracers/firehose_test.go index 3349cc535..7c797453e 100644 --- a/x/evm/tracers/firehose_test.go +++ b/x/evm/tracers/firehose_test.go @@ -9,7 +9,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - pbeth "github.com/ethereum/go-ethereum/pb/sf/ethereum/type/v2" + pbeth "github.com/sei-protocol/sei-chain/pb/sf/ethereum/type/v2" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "golang.org/x/exp/maps" diff --git a/x/evm/tracers/tracing.go b/x/evm/tracers/tracing.go index b1f18dbb1..6ef374137 100644 --- a/x/evm/tracers/tracing.go +++ b/x/evm/tracers/tracing.go @@ -6,6 +6,7 @@ import ( "net/url" sdk "github.com/cosmos/cosmos-sdk/types" + ethtracing "github.com/ethereum/go-ethereum/core/tracing" "github.com/ethereum/go-ethereum/params" "github.com/sei-protocol/sei-chain/x/evm/tracing" ) @@ -64,6 +65,8 @@ func SetCtxBlockchainLogger(ctx sdk.Context, logger *tracing.Hooks) sdk.Context return ctx.WithContext(context.WithValue(ctx.Context(), CtxBlockchainLoggerKey, logger)) } +// GetCtxBlockchainLogger function to get the SEI specific [tracing.Hooks] struct +// used to trace EVM blocks and transactions. func GetCtxBlockchainLogger(ctx sdk.Context) *tracing.Hooks { rawVal := ctx.Context().Value(CtxBlockchainLoggerKey) if rawVal == nil { @@ -75,3 +78,14 @@ func GetCtxBlockchainLogger(ctx sdk.Context) *tracing.Hooks { } return logger } + +// GetCtxEthTracingHooks is a convenience function to get the ethtracing.Hooks from the context +// avoiding nil pointer exceptions when trying to send the tracer to lower-level go-ethereum components +// that deals with *tracing.Hooks directly. +func GetCtxEthTracingHooks(ctx sdk.Context) *ethtracing.Hooks { + if logger := GetCtxBlockchainLogger(ctx); logger != nil { + return logger.Hooks + } + + return nil +}