From 55ed8fef0b6f21ed07dfa9f28b00651c61e8015f Mon Sep 17 00:00:00 2001 From: Karol Chojnowski Date: Tue, 24 Sep 2024 13:18:36 +0200 Subject: [PATCH] core/tracing, core/vm: add ContractCode to the OpContext (#30466) Extends the opcontext interface to include accessor for code being executed in current context. While it is possible to get the code via `statedb.GetCode`, that approach doesn't work for initcode. --- core/tracing/hooks.go | 1 + core/vm/interpreter.go | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/core/tracing/hooks.go b/core/tracing/hooks.go index 987dfa7a1e..882eb52837 100644 --- a/core/tracing/hooks.go +++ b/core/tracing/hooks.go @@ -34,6 +34,7 @@ type OpContext interface { Address() common.Address CallValue() *uint256.Int CallInput() []byte + ContractCode() []byte } // StateDB gives tracers access to the whole state. diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index 4a39aaad00..793f398367 100644 --- a/core/vm/interpreter.go +++ b/core/vm/interpreter.go @@ -84,6 +84,11 @@ func (ctx *ScopeContext) CallInput() []byte { return ctx.Contract.Input } +// ContractCode returns the code of the contract being executed. +func (ctx *ScopeContext) ContractCode() []byte { + return ctx.Contract.Code +} + // EVMInterpreter represents an EVM interpreter type EVMInterpreter struct { evm *EVM