From 79c4de3a63f8b068c147a77e5b6ec65a13f11ac2 Mon Sep 17 00:00:00 2001 From: crypto-facs <84574577+crypto-facs@users.noreply.github.com> Date: Tue, 16 Nov 2021 03:57:03 -0500 Subject: [PATCH] cherry-pick (tharsis#746) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Federico Kunze Küllmer --- app/app.go | 2 +- init.sh | 2 +- server/config/config.go | 6 ++-- x/evm/keeper/grpc_query.go | 6 ++-- x/evm/keeper/grpc_query_test.go | 53 +++++++++++++++++++++++--------- x/evm/keeper/keeper.go | 6 +--- x/evm/keeper/state_transition.go | 13 +++++--- x/evm/types/tracer.go | 7 +++-- 8 files changed, 62 insertions(+), 33 deletions(-) diff --git a/app/app.go b/app/app.go index 47ada7ee67..0563b0d958 100644 --- a/app/app.go +++ b/app/app.go @@ -341,7 +341,7 @@ func NewEthermintApp( app.EvmKeeper = evmkeeper.NewKeeper( appCodec, keys[evmtypes.StoreKey], tkeys[evmtypes.TransientKey], app.GetSubspace(evmtypes.ModuleName), app.AccountKeeper, app.BankKeeper, app.StakingKeeper, - tracer, bApp.Trace(), // debug EVM based on Baseapp options + tracer, ) app.FeeMarketKeeper = feemarketkeeper.NewKeeper( diff --git a/init.sh b/init.sh index e9a13d1d4b..5b80f348f0 100755 --- a/init.sh +++ b/init.sh @@ -87,4 +87,4 @@ if [[ $1 == "pending" ]]; then fi # Start the node (remove the --pruning=nothing flag if historical queries are not needed) -ethermintd start --pruning=nothing $TRACE --log_level $LOGLEVEL --minimum-gas-prices=0.0001aphoton --json-rpc.api eth,txpool,personal,net,debug,web3,miner +ethermintd start --pruning=nothing --evm.tracer=json $TRACE --log_level $LOGLEVEL --minimum-gas-prices=0.0001aphoton --json-rpc.api eth,txpool,personal,net,debug,web3,miner diff --git a/server/config/config.go b/server/config/config.go index b1814b1f94..2bc8830ef5 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -25,14 +25,14 @@ const ( DefaultJSONRPCWsAddress = "0.0.0.0:8546" // DefaultEVMTracer is the default vm.Tracer type - DefaultEVMTracer = "json" + DefaultEVMTracer = "" DefaultGasCap uint64 = 25000000 DefaultFilterCap int32 = 200 ) -var evmTracers = []string{DefaultEVMTracer, "markdown", "struct", "access_list"} +var evmTracers = []string{"json", "markdown", "struct", "access_list"} // Config defines the server's top level configuration. It includes the default app config // from the SDK as well as the EVM configuration to enable the JSON-RPC APIs. @@ -129,7 +129,7 @@ func DefaultEVMConfig() *EVMConfig { // Validate returns an error if the tracer type is invalid. func (c EVMConfig) Validate() error { - if !strings.StringInSlice(c.Tracer, evmTracers) { + if c.Tracer != "" && !strings.StringInSlice(c.Tracer, evmTracers) { return fmt.Errorf("invalid tracer type %s, available types: %v", c.Tracer, evmTracers) } diff --git a/x/evm/keeper/grpc_query.go b/x/evm/keeper/grpc_query.go index b731d0c23f..2174b78f74 100644 --- a/x/evm/keeper/grpc_query.go +++ b/x/evm/keeper/grpc_query.go @@ -231,7 +231,7 @@ func (k Keeper) EthCall(c context.Context, req *types.EthCallRequest) (*types.Ms return nil, status.Error(codes.Internal, err.Error()) } - tracer := types.NewTracer(k.tracer, msg, ethCfg, k.Ctx().BlockHeight(), k.debug) + tracer := types.NewTracer(k.tracer, msg, ethCfg, k.Ctx().BlockHeight()) evm := k.NewEVM(msg, ethCfg, params, coinbase, tracer) // pass true means execute in query mode, which don't do actual gas refund. @@ -308,7 +308,7 @@ func (k Keeper) EstimateGas(c context.Context, req *types.EthCallRequest) (*type msg := args.ToMessage(req.GasCap) - tracer := types.NewTracer(k.tracer, msg, ethCfg, k.Ctx().BlockHeight(), k.debug) + tracer := types.NewTracer(k.tracer, msg, ethCfg, k.Ctx().BlockHeight()) evm := k.NewEVM(msg, ethCfg, params, coinbase, tracer) // pass true means execute in query mode, which don't do actual gas refund. rsp, err := k.ApplyMessage(evm, msg, ethCfg, true) @@ -519,7 +519,7 @@ func (k *Keeper) traceTx( } tracer = vm.NewStructLogger(&logConfig) default: - tracer = types.NewTracer(types.TracerStruct, msg, ethCfg, ctx.BlockHeight(), true) + tracer = types.NewTracer(types.TracerStruct, msg, ethCfg, ctx.BlockHeight()) } evm := k.NewEVM(msg, ethCfg, params, coinbase, tracer) diff --git a/x/evm/keeper/grpc_query_test.go b/x/evm/keeper/grpc_query_test.go index 0e54e25ec5..0ee17ebd50 100644 --- a/x/evm/keeper/grpc_query_test.go +++ b/x/evm/keeper/grpc_query_test.go @@ -556,7 +556,6 @@ func (suite *KeeperTestSuite) TestEstimateGas() { } func (suite *KeeperTestSuite) TestTraceTx() { - ctx := sdk.WrapSDKContext(suite.ctx) // TODO deploy contract that triggers internal transactions var ( txMsg *types.MsgEthereumTx @@ -579,7 +578,20 @@ func (suite *KeeperTestSuite) TestTraceTx() { predecessors = []*types.MsgEthereumTx{} }, expPass: true, - traceResponse: []byte{0x7b, 0x22, 0x67, 0x61, 0x73, 0x22, 0x3a, 0x33, 0x34, 0x38, 0x32, 0x38, 0x2c, 0x22, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x22, 0x3a, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x22, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x3a, 0x22, 0x22, 0x2c, 0x22, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x4c, 0x6f, 0x67, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d}, + traceResponse: []byte{0x7b, 0x22, 0x67, 0x61, 0x73, 0x22, 0x3a, 0x33, 0x34, 0x38, 0x32, 0x38, 0x2c, 0x22, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x22, 0x3a, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x22, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x3a, 0x22, 0x22, 0x2c, 0x22, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x4c, 0x6f, 0x67, 0x73, 0x22, 0x3a, 0x5b, 0x7b, 0x22, 0x70, 0x63, 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x6f, 0x70, 0x22, 0x3a, 0x22, 0x50, 0x55, 0x53, 0x48, 0x31, 0x22, 0x2c, 0x22, 0x67, 0x61, 0x73, 0x22, 0x3a, 0x33, 0x30, 0x32, 0x39, 0x36, 0x2c, 0x22, 0x67, 0x61, 0x73, 0x43, 0x6f, 0x73, 0x74, 0x22, 0x3a, 0x33, 0x2c, 0x22, 0x64, 0x65, 0x70, 0x74, 0x68, 0x22, 0x3a, 0x31, 0x2c, 0x22, 0x73, 0x74, 0x61, 0x63, 0x6b, 0x22, 0x3a, 0x5b, 0x5d, 0x2c, 0x22, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x22, 0x3a, 0x5b, 0x5d, 0x2c, 0x22, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x22, 0x3a, 0x7b, 0x7d, 0x7d}, + }, + { + msg: "default trace with filtered response", + malleate: func() { + txIndex = 0 + traceConfig = &types.TraceConfig{ + DisableStack: true, + DisableStorage: true, + } + predecessors = []*types.MsgEthereumTx{} + }, + expPass: true, + traceResponse: []byte{0x7b, 0x22, 0x67, 0x61, 0x73, 0x22, 0x3a, 0x33, 0x34, 0x38, 0x32, 0x38, 0x2c, 0x22, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x22, 0x3a, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x22, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x3a, 0x22, 0x22, 0x2c, 0x22, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x4c, 0x6f, 0x67, 0x73, 0x22, 0x3a, 0x5b, 0x7b, 0x22, 0x70, 0x63, 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x6f, 0x70, 0x22, 0x3a, 0x22, 0x50, 0x55, 0x53, 0x48, 0x31, 0x22, 0x2c, 0x22, 0x67, 0x61, 0x73, 0x22, 0x3a, 0x33, 0x30, 0x32, 0x39, 0x36, 0x2c, 0x22, 0x67, 0x61, 0x73, 0x43, 0x6f, 0x73, 0x74, 0x22, 0x3a, 0x33, 0x2c, 0x22, 0x64, 0x65, 0x70, 0x74, 0x68, 0x22, 0x3a, 0x31, 0x2c, 0x22, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0x2c, 0x7b, 0x22, 0x70, 0x63, 0x22, 0x3a, 0x32, 0x2c, 0x22, 0x6f, 0x70, 0x22, 0x3a, 0x22, 0x50, 0x55, 0x53, 0x48, 0x31, 0x22, 0x2c, 0x22, 0x67}, }, { msg: "javascript tracer", malleate: func() { @@ -596,11 +608,14 @@ func (suite *KeeperTestSuite) TestTraceTx() { msg: "default trace with dynamicTxFee", malleate: func() { txIndex = 0 - traceConfig = nil + traceConfig = &types.TraceConfig{ + DisableStack: true, + DisableStorage: true, + } predecessors = []*types.MsgEthereumTx{} }, expPass: true, - traceResponse: []byte{0x7b, 0x22, 0x67, 0x61, 0x73, 0x22, 0x3a, 0x33, 0x34, 0x38, 0x32, 0x38, 0x2c, 0x22, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x22, 0x3a, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x22, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x3a, 0x22, 0x22, 0x2c, 0x22, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x4c, 0x6f, 0x67, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d}, + traceResponse: []byte{0x7b, 0x22, 0x67, 0x61, 0x73, 0x22, 0x3a, 0x33, 0x34, 0x38, 0x32, 0x38, 0x2c, 0x22, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x22, 0x3a, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x22, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x3a, 0x22, 0x22, 0x2c, 0x22, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x4c, 0x6f, 0x67, 0x73, 0x22, 0x3a, 0x5b, 0x7b, 0x22, 0x70, 0x63, 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x6f, 0x70, 0x22, 0x3a, 0x22, 0x50, 0x55, 0x53, 0x48, 0x31, 0x22, 0x2c, 0x22, 0x67, 0x61, 0x73, 0x22, 0x3a, 0x33, 0x30, 0x32, 0x39, 0x36, 0x2c, 0x22, 0x67, 0x61, 0x73, 0x43, 0x6f, 0x73, 0x74, 0x22, 0x3a, 0x33, 0x2c, 0x22, 0x64, 0x65, 0x70, 0x74, 0x68, 0x22, 0x3a, 0x31, 0x2c, 0x22, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0x2c, 0x7b, 0x22, 0x70, 0x63, 0x22, 0x3a, 0x32, 0x2c, 0x22, 0x6f, 0x70, 0x22, 0x3a, 0x22, 0x50, 0x55, 0x53, 0x48, 0x31, 0x22, 0x2c, 0x22, 0x67}, }, { msg: "javascript tracer with dynamicTxFee", malleate: func() { @@ -629,7 +644,7 @@ func (suite *KeeperTestSuite) TestTraceTx() { predecessors = append(predecessors, firstTx) }, expPass: true, - traceResponse: []byte{0x7b, 0x22, 0x67, 0x61, 0x73, 0x22, 0x3a, 0x32, 0x35, 0x32, 0x32, 0x38, 0x2c, 0x22, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x22, 0x3a, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x22, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x3a, 0x22, 0x22, 0x2c, 0x22, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x4c, 0x6f, 0x67, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d}, + traceResponse: []byte{0x7b, 0x22, 0x67, 0x61, 0x73, 0x22, 0x3a, 0x32, 0x35, 0x32, 0x32, 0x38, 0x2c, 0x22, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x22, 0x3a, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x22, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x3a, 0x22, 0x22, 0x2c, 0x22, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x4c, 0x6f, 0x67, 0x73, 0x22, 0x3a, 0x5b, 0x7b, 0x22, 0x70, 0x63, 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x6f, 0x70, 0x22, 0x3a, 0x22, 0x50, 0x55, 0x53, 0x48, 0x31, 0x22, 0x2c, 0x22, 0x67, 0x61, 0x73, 0x22, 0x3a, 0x39, 0x31, 0x39, 0x36, 0x2c, 0x22, 0x67, 0x61, 0x73, 0x43, 0x6f, 0x73, 0x74, 0x22, 0x3a, 0x33, 0x2c, 0x22, 0x64, 0x65, 0x70, 0x74, 0x68, 0x22, 0x3a, 0x31, 0x2c, 0x22, 0x73, 0x74, 0x61, 0x63, 0x6b, 0x22, 0x3a, 0x5b, 0x5d, 0x2c, 0x22, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x22, 0x3a, 0x5b, 0x5d, 0x2c, 0x22, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x22, 0x3a, 0x7b, 0x7d, 0x7d, 0x2c}, }, } @@ -650,11 +665,17 @@ func (suite *KeeperTestSuite) TestTraceTx() { TxIndex: txIndex, Predecessors: predecessors, } - res, err := suite.queryClient.TraceTx(ctx, &traceReq) + res, err := suite.queryClient.TraceTx(sdk.WrapSDKContext(suite.ctx), &traceReq) + suite.Require().NoError(err) if tc.expPass { suite.Require().NoError(err) - suite.Require().Equal(tc.traceResponse, res.Data) + // if data is to big, slice the result + if len(res.Data) > 150 { + suite.Require().Equal(tc.traceResponse, res.Data[:150]) + } else { + suite.Require().Equal(tc.traceResponse, res.Data) + } } else { suite.Require().Error(err) } @@ -663,7 +684,6 @@ func (suite *KeeperTestSuite) TestTraceTx() { } func (suite *KeeperTestSuite) TestTraceBlock() { - ctx := sdk.WrapSDKContext(suite.ctx) var ( txs []*types.MsgEthereumTx traceConfig *types.TraceConfig @@ -681,7 +701,7 @@ func (suite *KeeperTestSuite) TestTraceBlock() { traceConfig = nil }, expPass: true, - traceResponse: []byte{0x5b, 0x7b, 0x22, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x3a, 0x7b, 0x22, 0x67, 0x61, 0x73, 0x22, 0x3a, 0x33, 0x34, 0x38, 0x32, 0x38, 0x2c, 0x22, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x22, 0x3a, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x22, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x3a, 0x22, 0x22, 0x2c, 0x22, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x4c, 0x6f, 0x67, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0x7d, 0x5d}, + traceResponse: []byte{0x5b, 0x7b, 0x22, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x3a, 0x7b, 0x22, 0x67, 0x61, 0x73, 0x22, 0x3a, 0x33, 0x34, 0x38, 0x32, 0x38, 0x2c, 0x22, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x22, 0x3a, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x22, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x3a, 0x22, 0x22, 0x2c, 0x22, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x4c, 0x6f, 0x67, 0x73, 0x22, 0x3a, 0x5b, 0x7b, 0x22, 0x70, 0x63, 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x6f, 0x70, 0x22, 0x3a, 0x22, 0x50, 0x55, 0x53, 0x48, 0x31, 0x22, 0x2c, 0x22, 0x67, 0x61, 0x73, 0x22, 0x3a, 0x33, 0x30, 0x32, 0x39, 0x36, 0x2c, 0x22, 0x67, 0x61, 0x73, 0x43, 0x6f, 0x73, 0x74, 0x22, 0x3a, 0x33, 0x2c, 0x22, 0x64, 0x65, 0x70, 0x74, 0x68, 0x22, 0x3a, 0x31, 0x2c, 0x22, 0x73, 0x74, 0x61, 0x63, 0x6b, 0x22, 0x3a, 0x5b, 0x5d, 0x2c, 0x22, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x22, 0x3a, 0x5b, 0x5d, 0x2c, 0x22, 0x73}, }, { msg: "filtered trace", @@ -692,7 +712,7 @@ func (suite *KeeperTestSuite) TestTraceBlock() { } }, expPass: true, - traceResponse: []byte{0x5b, 0x7b, 0x22, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x3a, 0x7b, 0x22, 0x67, 0x61, 0x73, 0x22, 0x3a, 0x33, 0x34, 0x38, 0x32, 0x38, 0x2c, 0x22, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x22, 0x3a, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x22, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x3a, 0x22, 0x22, 0x2c, 0x22, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x4c, 0x6f, 0x67, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0x7d, 0x5d}, + traceResponse: []byte{0x5b, 0x7b, 0x22, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x3a, 0x7b, 0x22, 0x67, 0x61, 0x73, 0x22, 0x3a, 0x33, 0x34, 0x38, 0x32, 0x38, 0x2c, 0x22, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x22, 0x3a, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x22, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x3a, 0x22, 0x22, 0x2c, 0x22, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x4c, 0x6f, 0x67, 0x73, 0x22, 0x3a, 0x5b, 0x7b, 0x22, 0x70, 0x63, 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x6f, 0x70, 0x22, 0x3a, 0x22, 0x50, 0x55, 0x53, 0x48, 0x31, 0x22, 0x2c, 0x22, 0x67, 0x61, 0x73, 0x22, 0x3a, 0x33, 0x30, 0x32, 0x39, 0x36, 0x2c, 0x22, 0x67, 0x61, 0x73, 0x43, 0x6f, 0x73, 0x74, 0x22, 0x3a, 0x33, 0x2c, 0x22, 0x64, 0x65, 0x70, 0x74, 0x68, 0x22, 0x3a, 0x31, 0x2c, 0x22, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0x2c, 0x7b, 0x22, 0x70, 0x63, 0x22, 0x3a, 0x32, 0x2c, 0x22, 0x6f, 0x70, 0x22}, }, { msg: "javascript tracer", malleate: func() { @@ -712,7 +732,7 @@ func (suite *KeeperTestSuite) TestTraceBlock() { } }, expPass: true, - traceResponse: []byte{0x5b, 0x7b, 0x22, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x3a, 0x7b, 0x22, 0x67, 0x61, 0x73, 0x22, 0x3a, 0x33, 0x34, 0x38, 0x32, 0x38, 0x2c, 0x22, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x22, 0x3a, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x22, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x3a, 0x22, 0x22, 0x2c, 0x22, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x4c, 0x6f, 0x67, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0x7d, 0x5d}, + traceResponse: []byte{0x5b, 0x7b, 0x22, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x3a, 0x7b, 0x22, 0x67, 0x61, 0x73, 0x22, 0x3a, 0x33, 0x34, 0x38, 0x32, 0x38, 0x2c, 0x22, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x22, 0x3a, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x22, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x3a, 0x22, 0x22, 0x2c, 0x22, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x4c, 0x6f, 0x67, 0x73, 0x22, 0x3a, 0x5b, 0x7b, 0x22, 0x70, 0x63, 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x6f, 0x70, 0x22, 0x3a, 0x22, 0x50, 0x55, 0x53, 0x48, 0x31, 0x22, 0x2c, 0x22, 0x67, 0x61, 0x73, 0x22, 0x3a, 0x33, 0x30, 0x32, 0x39, 0x36, 0x2c, 0x22, 0x67, 0x61, 0x73, 0x43, 0x6f, 0x73, 0x74, 0x22, 0x3a, 0x33, 0x2c, 0x22, 0x64, 0x65, 0x70, 0x74, 0x68, 0x22, 0x3a, 0x31, 0x2c, 0x22, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0x2c, 0x7b, 0x22, 0x70, 0x63, 0x22, 0x3a, 0x32, 0x2c, 0x22, 0x6f, 0x70, 0x22}, }, { msg: "javascript tracer with dynamicTxFee", malleate: func() { @@ -737,7 +757,7 @@ func (suite *KeeperTestSuite) TestTraceBlock() { txs = append([]*types.MsgEthereumTx{}, firstTx, secondTx) }, expPass: true, - traceResponse: []byte{0x5b, 0x7b, 0x22, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x3a, 0x7b, 0x22, 0x67, 0x61, 0x73, 0x22, 0x3a, 0x33, 0x34, 0x38, 0x32, 0x38, 0x2c, 0x22, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x22, 0x3a, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x22, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x3a, 0x22, 0x22, 0x2c, 0x22, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x4c, 0x6f, 0x67, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0x7d, 0x2c, 0x7b, 0x22, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x3a, 0x7b, 0x22, 0x67, 0x61, 0x73, 0x22, 0x3a, 0x32, 0x35, 0x32, 0x32, 0x38, 0x2c, 0x22, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x22, 0x3a, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x22, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x3a, 0x22, 0x22, 0x2c, 0x22, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x4c, 0x6f, 0x67, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0x7d, 0x5d}, + traceResponse: []byte{0x5b, 0x7b, 0x22, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x3a, 0x7b, 0x22, 0x67, 0x61, 0x73, 0x22, 0x3a, 0x33, 0x34, 0x38, 0x32, 0x38, 0x2c, 0x22, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x22, 0x3a, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x22, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x3a, 0x22, 0x22, 0x2c, 0x22, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x4c, 0x6f, 0x67, 0x73, 0x22, 0x3a, 0x5b, 0x7b, 0x22, 0x70, 0x63, 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x6f, 0x70, 0x22, 0x3a, 0x22, 0x50, 0x55, 0x53, 0x48, 0x31, 0x22, 0x2c, 0x22, 0x67, 0x61, 0x73, 0x22, 0x3a, 0x33, 0x30, 0x32, 0x39, 0x36, 0x2c, 0x22, 0x67, 0x61, 0x73, 0x43, 0x6f, 0x73, 0x74, 0x22, 0x3a, 0x33, 0x2c, 0x22, 0x64, 0x65, 0x70, 0x74, 0x68, 0x22, 0x3a, 0x31, 0x2c, 0x22, 0x73, 0x74, 0x61, 0x63, 0x6b, 0x22, 0x3a, 0x5b, 0x5d, 0x2c, 0x22, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x22, 0x3a, 0x5b, 0x5d, 0x2c, 0x22, 0x73}, }, } @@ -759,11 +779,16 @@ func (suite *KeeperTestSuite) TestTraceBlock() { Txs: txs, TraceConfig: traceConfig, } - res, err := suite.queryClient.TraceBlock(ctx, &traceReq) + res, err := suite.queryClient.TraceBlock(sdk.WrapSDKContext(suite.ctx), &traceReq) if tc.expPass { suite.Require().NoError(err) - suite.Require().Equal(tc.traceResponse, res.Data) + // if data is to big, slice the result + if len(res.Data) > 150 { + suite.Require().Equal(tc.traceResponse, res.Data[:150]) + } else { + suite.Require().Equal(tc.traceResponse, res.Data) + } } else { suite.Require().Error(err) } diff --git a/x/evm/keeper/keeper.go b/x/evm/keeper/keeper.go index 9b74753beb..fae3a69018 100644 --- a/x/evm/keeper/keeper.go +++ b/x/evm/keeper/keeper.go @@ -51,9 +51,6 @@ type Keeper struct { // Tracer used to collect execution traces from the EVM transaction execution tracer string - // trace EVM state transition execution. This value is obtained from the `--trace` flag. - // For more info check https://geth.ethereum.org/docs/dapp/tracing - debug bool // EVM Hooks for tx post-processing hooks types.EvmHooks @@ -67,7 +64,7 @@ func NewKeeper( cdc codec.BinaryCodec, storeKey, transientKey sdk.StoreKey, paramSpace paramtypes.Subspace, ak types.AccountKeeper, bankKeeper types.BankKeeper, sk types.StakingKeeper, - tracer string, debug bool, + tracer string, ) *Keeper { // ensure evm module account is set if addr := ak.GetModuleAddress(types.ModuleName); addr == nil { @@ -89,7 +86,6 @@ func NewKeeper( storeKey: storeKey, transientKey: transientKey, tracer: tracer, - debug: debug, stateErr: nil, } } diff --git a/x/evm/keeper/state_transition.go b/x/evm/keeper/state_transition.go index 522f68f0aa..0c46d8d707 100644 --- a/x/evm/keeper/state_transition.go +++ b/x/evm/keeper/state_transition.go @@ -44,16 +44,21 @@ func (k *Keeper) NewEVM( } txCtx := core.NewEVMTxContext(msg) - vmConfig := k.VMConfig(msg, params, tracer) + vmConfig := k.VMConfig(params, tracer) return vm.NewEVM(blockCtx, txCtx, k, config, vmConfig) } // VMConfig creates an EVM configuration from the debug setting and the extra EIPs enabled on the // module parameters. The config generated uses the default JumpTable from the EVM. -func (k Keeper) VMConfig(msg core.Message, params types.Params, tracer vm.Tracer) vm.Config { +func (k Keeper) VMConfig(params types.Params, tracer vm.Tracer) vm.Config { + var debug bool + if _, ok := tracer.(types.NoOpTracer); !ok { + debug = true + } + return vm.Config{ - Debug: k.debug, + Debug: debug, Tracer: tracer, NoRecursion: false, // TODO: consider disabling recursion though params ExtraEips: params.EIPs(), @@ -166,7 +171,7 @@ func (k *Keeper) ApplyTransaction(tx *ethtypes.Transaction) (*types.MsgEthereumT } // create an ethereum EVM instance and run the message - tracer := types.NewTracer(k.tracer, msg, ethCfg, ctx.BlockHeight(), k.debug) + tracer := types.NewTracer(k.tracer, msg, ethCfg, ctx.BlockHeight()) evm := k.NewEVM(msg, ethCfg, params, coinbase, tracer) txHash := tx.Hash() diff --git a/x/evm/types/tracer.go b/x/evm/types/tracer.go index cbf5261a94..28dfd74550 100644 --- a/x/evm/types/tracer.go +++ b/x/evm/types/tracer.go @@ -21,10 +21,10 @@ const ( // NewTracer creates a new Logger tracer to collect execution traces from an // EVM transaction. -func NewTracer(tracer string, msg core.Message, cfg *params.ChainConfig, height int64, debug bool) vm.Tracer { +func NewTracer(tracer string, msg core.Message, cfg *params.ChainConfig, height int64) vm.Tracer { // TODO: enable additional log configuration logCfg := &vm.LogConfig{ - Debug: debug, + Debug: true, } switch tracer { @@ -90,6 +90,7 @@ func FormatLogs(logs []vm.StructLog) []StructLogRes { Depth: trace.Depth, Error: trace.ErrorString(), } + if trace.Stack != nil { stack := make([]string, len(trace.Stack)) for i, stackValue := range trace.Stack { @@ -97,6 +98,7 @@ func FormatLogs(logs []vm.StructLog) []StructLogRes { } formatted[index].Stack = &stack } + if trace.Memory != nil { memory := make([]string, 0, (len(trace.Memory)+31)/32) for i := 0; i+32 <= len(trace.Memory); i += 32 { @@ -104,6 +106,7 @@ func FormatLogs(logs []vm.StructLog) []StructLogRes { } formatted[index].Memory = &memory } + if trace.Storage != nil { storage := make(map[string]string) for i, storageValue := range trace.Storage {