Skip to content

Commit abb0094

Browse files
committed
move extcodesize consumption to gas method
1 parent f4e0f1b commit abb0094

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

core/vm/eips.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,7 @@ func opExtCodeCopyEIP4762(pc *uint64, interpreter *EVMInterpreter, scope *ScopeC
338338
}
339339
addr := common.Address(a.Bytes20())
340340
code := interpreter.evm.StateDB.GetCode(addr)
341-
paddedCodeCopy, copyOffset, nonPaddedCopyLength := getDataAndAdjustedBounds(code, uint64CodeOffset, length.Uint64())
342-
consumed, wanted := interpreter.evm.AccessEvents.CodeChunksRangeGas(addr, copyOffset, nonPaddedCopyLength, uint64(len(code)), false, scope.Contract.Gas)
343-
scope.Contract.UseGas(consumed, interpreter.evm.Config.Tracer, tracing.GasChangeUnspecified)
344-
if consumed < wanted {
345-
return nil, ErrOutOfGas
346-
}
341+
paddedCodeCopy, _, _ := getDataAndAdjustedBounds(code, uint64CodeOffset, length.Uint64())
347342
scope.Memory.Set(memOffset.Uint64(), length.Uint64(), paddedCodeCopy)
348343

349344
return nil, nil

core/vm/operations_verkle.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,5 +201,17 @@ func gasExtCodeCopyEIP4762(evm *EVM, contract *Contract, stack *Stack, mem *Memo
201201
if gas, overflow = math.SafeAdd(gas, wgas); overflow {
202202
return 0, ErrGasUintOverflow
203203
}
204+
codeOffset := stack.Back(2)
205+
length := stack.Back(3)
206+
uint64CodeOffset, overflow := codeOffset.Uint64WithOverflow()
207+
if overflow {
208+
uint64CodeOffset = gomath.MaxUint64
209+
}
210+
code := evm.StateDB.GetCode(addr)
211+
_, copyOffset, nonPaddedCopyLength := getDataAndAdjustedBounds(code, uint64CodeOffset, length.Uint64())
212+
_, wanted := evm.AccessEvents.CodeChunksRangeGas(addr, copyOffset, nonPaddedCopyLength, uint64(len(code)), false, gas)
213+
if gas, overflow = math.SafeAdd(gas, wanted); overflow {
214+
return 0, ErrGasUintOverflow
215+
}
204216
return gas, nil
205217
}

0 commit comments

Comments
 (0)