From 6f0bcac53f4b2fd6983530ea9f1c6de5f9c95591 Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Tue, 7 Feb 2023 18:32:40 +0200 Subject: [PATCH 1/2] eth/tracers/native: callTracer sets the value of a delegated call to the value of its parent --- .../testdata/call_tracer/delegatecall.json | 3 ++- .../call_tracer_withLog/delegatecall.json | 24 ++++++++++++------- eth/tracers/native/call.go | 9 +++++++ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/eth/tracers/internal/tracetest/testdata/call_tracer/delegatecall.json b/eth/tracers/internal/tracetest/testdata/call_tracer/delegatecall.json index 3e7b5f436528..5fd946f73467 100644 --- a/eth/tracers/internal/tracetest/testdata/call_tracer/delegatecall.json +++ b/eth/tracers/internal/tracetest/testdata/call_tracer/delegatecall.json @@ -72,7 +72,8 @@ "input": "0x7d65837a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a529806c67cc6486d4d62024471772f47f6fd672", "output": "0x0000000000000000000000000000000000000000000000000000000000000001", "to": "0x42b02b5deeb78f34cd5ac896473b63e6c99a71a2", - "type": "DELEGATECALL" + "type": "DELEGATECALL", + "value": "0x0" } ], "from": "0x269296dddce321a6bcbaa2f0181127593d732cba", diff --git a/eth/tracers/internal/tracetest/testdata/call_tracer_withLog/delegatecall.json b/eth/tracers/internal/tracetest/testdata/call_tracer_withLog/delegatecall.json index d5d0d072f2a1..2c82138022ec 100644 --- a/eth/tracers/internal/tracetest/testdata/call_tracer_withLog/delegatecall.json +++ b/eth/tracers/internal/tracetest/testdata/call_tracer_withLog/delegatecall.json @@ -165,7 +165,8 @@ "to": "0xef3487d24a0702703e04a26cef479e313c8fc7ae", "input": "0x24d4e90a0000000000000000000000000000000000000000000000020000000000000000", "output": "0x000000000000000000000000000000000000000000000000b17217f7d1cf79ab", - "type": "DELEGATECALL" + "type": "DELEGATECALL", + "value": "0x0" }, { "from": "0x8695e5e79dab06fbbb05f445316fa4edb0da30f0", @@ -174,7 +175,8 @@ "to": "0xef3487d24a0702703e04a26cef479e313c8fc7ae", "input": "0x872fb2b5000000000000000000000000000000000000000000000000c330b3f7006420b8", "output": "0x00000000000000000000000000000000000000000000000224bf7df2c80f0878", - "type": "DELEGATECALL" + "type": "DELEGATECALL", + "value": "0x0" }, { "from": "0x8695e5e79dab06fbbb05f445316fa4edb0da30f0", @@ -183,7 +185,8 @@ "to": "0xef3487d24a0702703e04a26cef479e313c8fc7ae", "input": "0x872fb2b50000000000000000000000000000000000000000000000000000000000000000", "output": "0x00000000000000000000000000000000000000000000000100000016aee6e8ef", - "type": "DELEGATECALL" + "type": "DELEGATECALL", + "value": "0x0" }, { "from": "0x8695e5e79dab06fbbb05f445316fa4edb0da30f0", @@ -192,7 +195,8 @@ "to": "0xef3487d24a0702703e04a26cef479e313c8fc7ae", "input": "0x24d4e90a00000000000000000000000000000000000000000000000324bf7e0976f5f167", "output": "0x0000000000000000000000000000000000000000000000012535c5e5f87ee0d2", - "type": "DELEGATECALL" + "type": "DELEGATECALL", + "value": "0x0" }, { "from": "0x8695e5e79dab06fbbb05f445316fa4edb0da30f0", @@ -201,7 +205,8 @@ "to": "0xef3487d24a0702703e04a26cef479e313c8fc7ae", "input": "0x872fb2b5000000000000000000000000000000000000000000000000c330b3f7006420b8", "output": "0x00000000000000000000000000000000000000000000000224bf7df2c80f0878", - "type": "DELEGATECALL" + "type": "DELEGATECALL", + "value": "0x0" }, { "from": "0x8695e5e79dab06fbbb05f445316fa4edb0da30f0", @@ -210,7 +215,8 @@ "to": "0xef3487d24a0702703e04a26cef479e313c8fc7ae", "input": "0x872fb2b500000000000000000000000000000000000000000000000237d37fe5d297a500", "output": "0x0000000000000000000000000000000000000000000000093088c407fcbbce38", - "type": "DELEGATECALL" + "type": "DELEGATECALL", + "value": "0x0" }, { "from": "0x8695e5e79dab06fbbb05f445316fa4edb0da30f0", @@ -219,7 +225,8 @@ "to": "0xef3487d24a0702703e04a26cef479e313c8fc7ae", "input": "0x24d4e90a00000000000000000000000000000000000000000000000b554841fac4cad6b0", "output": "0x0000000000000000000000000000000000000000000000026d7fc130d6a74cbe", - "type": "DELEGATECALL" + "type": "DELEGATECALL", + "value": "0x0" } ], "value": "0x0", @@ -387,7 +394,8 @@ "data": "0x000000000000000000000000000000000000000000000000de0b6b3a76400000" } ], - "type": "DELEGATECALL" + "type": "DELEGATECALL", + "value": "0x0" } ], "value": "0x0", diff --git a/eth/tracers/native/call.go b/eth/tracers/native/call.go index 75103f64cc87..79a08ac9ddbd 100644 --- a/eth/tracers/native/call.go +++ b/eth/tracers/native/call.go @@ -200,6 +200,15 @@ func (t *callTracer) CaptureEnter(typ vm.OpCode, from common.Address, to common. Value: value, } t.callstack = append(t.callstack, call) + + // Delegatecall has same value as parent call. + if typ == vm.DELEGATECALL { + size := len(t.callstack) + if size < 2 { + return + } + t.callstack[size-1].Value = t.callstack[size-2].Value + } } // CaptureExit is called when EVM exits a scope, even if the scope didn't From 47f4122f0117a2fe08edb116d4b57273928d638f Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi Date: Thu, 9 Feb 2023 14:12:04 +0100 Subject: [PATCH 2/2] fix for all tracers --- core/vm/evm.go | 6 +++++- eth/tracers/native/call.go | 9 --------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/core/vm/evm.go b/core/vm/evm.go index bc7b0ab964fa..d78ea0792664 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -315,7 +315,11 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by // Invoke tracer hooks that signal entering/exiting a call frame if evm.Config.Debug { - evm.Config.Tracer.CaptureEnter(DELEGATECALL, caller.Address(), addr, input, gas, nil) + // NOTE: caller must, at all times be a contract. It should never happen + // that caller is something other than a Contract. + parent := caller.(*Contract) + // DELEGATECALL inherits value from parent call + evm.Config.Tracer.CaptureEnter(DELEGATECALL, caller.Address(), addr, input, gas, parent.value) defer func(startGas uint64) { evm.Config.Tracer.CaptureExit(ret, startGas-gas, err) }(gas) diff --git a/eth/tracers/native/call.go b/eth/tracers/native/call.go index 79a08ac9ddbd..75103f64cc87 100644 --- a/eth/tracers/native/call.go +++ b/eth/tracers/native/call.go @@ -200,15 +200,6 @@ func (t *callTracer) CaptureEnter(typ vm.OpCode, from common.Address, to common. Value: value, } t.callstack = append(t.callstack, call) - - // Delegatecall has same value as parent call. - if typ == vm.DELEGATECALL { - size := len(t.callstack) - if size < 2 { - return - } - t.callstack[size-1].Value = t.callstack[size-2].Value - } } // CaptureExit is called when EVM exits a scope, even if the scope didn't