From 4d4eabc8f705b49335287b4aadeca265018e7895 Mon Sep 17 00:00:00 2001 From: Ignacio Hagopian Date: Fri, 11 Oct 2024 22:24:35 -0300 Subject: [PATCH] criminal hacks Signed-off-by: Ignacio Hagopian --- core/vm/instructions.go | 12 ++++++++++++ core/vm/interpreter.go | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 0d442fe96bf0..65f9f120b623 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -825,6 +825,9 @@ func opCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byt if err != nil || !scope.Contract.UseGas(dynamicCost) { return nil, ErrOutOfGas } + if memSize > 0 { + scope.Memory.Resize(memSize) + } interpreter.evm.callGasTemp, err = callGas(interpreter.evm.chainRules.IsEIP150, scope.Contract.Gas, 0, scope.Stack.Back(0)) if err != nil { @@ -886,6 +889,9 @@ func opCallCode(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([ if err != nil || !scope.Contract.UseGas(dynamicCost) { return nil, ErrOutOfGas } + if memSize > 0 { + scope.Memory.Resize(memSize) + } interpreter.evm.callGasTemp, err = callGas(interpreter.evm.chainRules.IsEIP150, scope.Contract.Gas, 0, scope.Stack.Back(0)) if err != nil { return nil, err @@ -940,6 +946,9 @@ func opDelegateCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext if err != nil || !scope.Contract.UseGas(dynamicCost) { return nil, ErrOutOfGas } + if memSize > 0 { + scope.Memory.Resize(memSize) + } interpreter.evm.callGasTemp, err = callGas(interpreter.evm.chainRules.IsEIP150, scope.Contract.Gas, 0, scope.Stack.Back(0)) if err != nil { return nil, err @@ -988,6 +997,9 @@ func opStaticCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) if err != nil || !scope.Contract.UseGas(dynamicCost) { return nil, ErrOutOfGas } + if memSize > 0 { + scope.Memory.Resize(memSize) + } interpreter.evm.callGasTemp, err = callGas(interpreter.evm.chainRules.IsEIP150, scope.Contract.Gas, 0, scope.Stack.Back(0)) if err != nil { return nil, err diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index c9a53584b19e..6d11df4625a5 100644 --- a/core/vm/interpreter.go +++ b/core/vm/interpreter.go @@ -233,7 +233,8 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) ( in.evm.Config.Tracer.CaptureState(pc, op, gasCopy, cost, callContext, in.returnData, in.evm.depth, err) logged = true } - if memorySize > 0 { + // TODO(hack): remove if conditions + if op != CALL && op != CALLCODE && op != DELEGATECALL && op != STATICCALL && memorySize > 0 { mem.Resize(memorySize) } } else if debug {