go-ethereum/core/vm
Arran Schlosberg 9021836d7d
feat: vm.Hooks.PreprocessingGasCharge() (#235)
## Why this should be merged

In lieu of modifications to `core.IntrinsicGas()`, required for support
of Warp in SAE.

If we were to introduce variadic `options.Option`s to `IntrinsicGas()`,
it's impossible to guarantee that they would always be passed. The
`types.Transaction` itself isn't actually passed to `IntrinsicGas()`
either, so we can't rely on it to carry payloads/hooks.

## How this works

`vm.Hooks` are extended to include `PreprocessingGasCharge(tx
common.Hash) (uint64, error)`, which returns the amount of gas to be
charged between `core.IntrinsicGas` and `vm.EVM` execution charges. The
two entry points to execution, `vm.EVM.Call()` and `vm.EVM.Create()` are
modified to first spend said charge before running upstream logic.

The new hook is defined on a separate interface definition, embedded in
`vm.Hooks`, to allow types to implement just that method and enforce it
with the `var _ vm.Preprocessor = (*impl)(nil)` pattern.

## How this was tested

Integration tests via both `core.ApplyTransaction()` and
`core.ApplyMessage()`. The former is more comprehensive, while the
latter allows for inspection of interim error values.

---------

Signed-off-by: Arran Schlosberg <519948+ARR4N@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Austin Larson <78000745+alarso16@users.noreply.github.com>
2025-12-15 20:49:13 +00:00
..
runtime [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
testdata core/vm: implement EIP-7951 - precompile for secp256r1 (#31991) 2025-08-13 16:39:36 -04:00
analysis.go core/vm: clarify comment (#27045) 2023-04-04 02:59:40 -04:00
analysis_test.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
common.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
contract.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
contracts.go core/vm: implement EIP-7951 - precompile for secp256r1 (#31991) 2025-08-13 16:39:36 -04:00
contracts.libevm.go feat: reentrancy.Guard for stateful precompiles (#212) 2025-10-03 19:56:29 +00:00
contracts.libevm_test.go test: PrecompileEnvironment.Value() under DELEGATECALL (#216) 2025-09-25 15:19:03 +01:00
contracts_fuzz_test.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
contracts_pkg_vm.libevm_test.go feat: export P256Verify precompile (#222) 2025-09-04 18:01:42 +00:00
contracts_test.go core/vm: implement EIP-7951 - precompile for secp256r1 (#31991) 2025-08-13 16:39:36 -04:00
doc.go core/vm: remove JIT VM codes (#16362) 2018-03-26 13:48:04 +03:00
eips.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
environment.libevm.go refactor: set EVM.readOnly and depth before running stateful precompile (#210) 2025-08-12 01:35:13 +01:00
errors.go core/vm: implement EIP-3860: Limit and meter initcode (#23847) 2023-01-11 04:05:47 -05:00
evm.go feat: vm.Hooks.PreprocessingGasCharge() (#235) 2025-12-15 20:49:13 +00:00
evm.libevm.go feat: vm.Hooks.PreprocessingGasCharge() (#235) 2025-12-15 20:49:13 +00:00
evm.libevm_test.go feat: vm.Hooks.PreprocessingGasCharge() (#235) 2025-12-15 20:49:13 +00:00
gas.go core/vm: use uint256 in EVM implementation (#20787) 2020-06-08 15:24:40 +03:00
gas_table.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
gas_table_test.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
hooks.libevm.go feat: vm.Hooks.PreprocessingGasCharge() (#235) 2025-12-15 20:49:13 +00:00
instructions.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
instructions_test.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
interface.go feat: vm.Hooks.PreprocessingGasCharge() (#235) 2025-12-15 20:49:13 +00:00
interface.libevm.go feat: vm.Hooks.PreprocessingGasCharge() (#235) 2025-12-15 20:49:13 +00:00
interpreter.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
interpreter_test.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
jump_table.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
jump_table_export.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
jump_table_test.go all: fix typos in comments (#28881) 2024-02-05 22:16:32 +01:00
libevm_test.go refactor: PrecompileEnvironment.{,Use,Refund}Gas() in lieu of args (#73) 2024-12-18 13:54:51 +00:00
logger.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
memory.go core/vm: implement EIP-5656, mcopy instruction (#26181) 2023-07-11 03:55:34 -04:00
memory_table.go core/vm: implement EIP-5656, mcopy instruction (#26181) 2023-07-11 03:55:34 -04:00
memory_test.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
opcodes.go eth/tracers/js: fix isPush for push0 (#28520) 2023-11-14 13:14:38 +01:00
operations_acl.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
options.libevm.go refactor: abstract options package (#74) 2024-11-21 13:59:51 -08:00
preprocess.libevm_test.go feat: vm.Hooks.PreprocessingGasCharge() (#235) 2025-12-15 20:49:13 +00:00
stack.go core/vm: clean up some dead functions (#24851) 2022-05-11 08:03:35 +03:00
stack.libevm.go feat: override EVM.Reset() args (#36) 2024-09-25 15:03:36 +01:00
stack.libevm_test.go Merge branch 'auto-rename-module_source-2bd6bd01d2e8561dd7fc21b631f4a34ac16627a1_workflow-c1fc594f020d23958b641a4e5a856b6e52c49d3bece94b95594864db16c1b0fc-main' into arr4n/rename-module 2024-10-17 13:07:28 +11:00
stack_table.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00