From 0f6f89f57698cdfd29bcf77819a5f09eabae029a Mon Sep 17 00:00:00 2001 From: Delweng Date: Wed, 16 Oct 2024 11:33:39 +0800 Subject: [PATCH] feat(eth/tracers): add coinbase to ctx (#12321) backport ethereum/go-ethereum#30231 Signed-off-by: jsvisa --- eth/tracers/js/goja.go | 6 ++++++ eth/tracers/js/tracer_test.go | 3 +++ 2 files changed, 9 insertions(+) diff --git a/eth/tracers/js/goja.go b/eth/tracers/js/goja.go index e3c756adf35..98817836432 100644 --- a/eth/tracers/js/goja.go +++ b/eth/tracers/js/goja.go @@ -249,6 +249,12 @@ func (t *jsTracer) CaptureStart(env *vm.EVM, from libcommon.Address, to libcommo } t.ctx["value"] = valueBig t.ctx["block"] = t.vm.ToValue(env.Context.BlockNumber) + coinbase, err := t.toBuf(t.vm, env.Context.Coinbase.Bytes()) + if err != nil { + t.err = err + return + } + t.ctx["coinbase"] = t.vm.ToValue(coinbase) // Update list of precompiles based on current block rules := env.ChainRules() t.activePrecompiles = vm.ActivePrecompiles(rules) diff --git a/eth/tracers/js/tracer_test.go b/eth/tracers/js/tracer_test.go index b83e034a580..96624bca385 100644 --- a/eth/tracers/js/tracer_test.go +++ b/eth/tracers/js/tracer_test.go @@ -161,6 +161,9 @@ func TestTracer(t *testing.T) { want: "", fail: "tracer reached limit for padding memory slice: end 1049600, memorySize 32 at step (:1:83(23)) in server-side tracer function 'step'", contract: []byte{byte(vm.PUSH1), byte(0xff), byte(vm.PUSH1), byte(0x00), byte(vm.MSTORE8), byte(vm.STOP)}, + }, { // tests ctx.coinbase + code: "{lengths: [], step: function(log) { }, fault: function() {}, result: function(ctx) { var coinbase = ctx.coinbase; return toAddress(coinbase); }}", + want: `{"0":0,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0}`, }, } { if have, err := execTracer(tt.code, tt.contract); tt.want != string(have) || tt.fail != err {