go-ethereum/core
Jonny Rhea 6e62cc5aa8
core/vm: compute stack operations in place (#35156)
The stack primitives pop by value: pop() returns the 32-byte value
itself, so every popped operand is copied out of the stack arena before
it is used. The result side was already in place, peek returns a pointer
and binary ops write into the new stack top. This PR fixes the operand
side: pointer-returning primitives (popPtr, popPtrPeek, etc), with the
handlers rewritten to read operands directly from their arena slots.
Every popped operand paid the copy, whatever the op went on to do with
it, so this optimization covers the arithmetic and comparison ops as
much as JUMP, MSTORE, SSTORE and RETURN.

The copy is visible in the assembly. On arm64, master's opLt spends four
instructions moving the popped value through the frame, and the
comparison then reads it back from there:

LDP (R5), (R6, R7) ; load words 0 and 1 of the popped value from the
arena
    LDP  16(R5), (R5, R8)            ; load words 2 and 3
STP (R6, R7), vm.~r0-64(SP) ; store words 0 and 1 into a frame slot
    STP  (R5, R8), vm.~r0-48(SP)     ; store words 2 and 3

With popPtrPeek those four instructions are gone, the frame shrinks from
locals=0x58 to locals=0x18, and the function from 336 to 288 bytes. The
compiler cannot remove the copy itself: uint256.Int is a four-element
array, and Go's SSA does not promote arrays longer than one element to
registers, so a by-value pop pays this round trip no matter how far
inlining gets, for LT exactly as for ADD.

The CALL and CREATE families are deliberately not converted: a child
frame reuses the same stack arena, so parent pointers into popped slots
die when the child pushes. The rule is recorded on the primitives:
pointers stay valid until the next push or any sub call. Converting the
call family safely means materializing scalars before the child call,
left for later work with a call-heavy benchmark to justify it.

### Benchmarks

Measured with the benchmark suite from #35144 (the evm-bench contract
workloads and the block import benchmark), which is not part of this
PR's diff. Apple M4 Max, fixed iteration counts, n=10, all p=0.000. B/op
and allocs/op are statistically identical on every benchmark:

| benchmark | master | PR | vs master |
|---|---|---|---|
| Snailtracer | 60.0 ms | 54.1 ms | -9.8% |
| TenThousandHashes | 13.2 ms | 12.2 ms | -7.8% |
| ERC20Transfer | 11.7 ms | 11.0 ms | -5.5% |
| ERC20Mint | 7.49 ms | 7.02 ms | -6.2% |
| ERC20ApprovalTransfer | 8.92 ms | 8.44 ms | -5.4% |

This PR is independent of #35144 but plays nicely with it: the generated
dispatch there splices these handler bodies, so the in-place forms land
in its fast path too, where they measure larger.

### Testing

The rewritten handlers run on the interpreter's only execution path, so
correctness rests on references outside the change:

- **Consensus fixtures.** The full tests package passes: state tests,
the execution-spec families, blockchain tests.
- **Opcode testcases.** The JSON testcases compare individual opcode
results against committed expected values.
- **Tracer fixtures.** The tracetest reference files pin exact log and
return data shapes, covering the rewritten LOG and RETURN paths.
- **Cross-build differential.** A goevmlab campaign running this
branch's evm against master's evm over generated state tests across four
forks (Prague, Cancun, London, Osaka) with full trace comparison:
160,566 tests, zero divergences.

---------

Co-authored-by: MariusVanDerWijden <m.vanderwijden@live.de>
2026-06-16 07:47:05 -05:00
..
filtermaps all: fix all typos, as reported by crates-ci/typos (#35008) 2026-06-10 18:50:51 +02:00
forkid params: set osaka and BPO1 & BPO2 mainnet dates (#33063) 2025-11-03 17:41:22 +01:00
history cmd/geth: add Prague pruning points for hoodi (#34714) 2026-04-14 14:58:27 +02:00
overlay cmd, core, trie, triedb: split CachingDB into merkle + binary dbs. (#34700) 2026-04-17 08:55:54 +08:00
rawdb eth/downloader, eth/protocols/snap: freeze pivot once state is downloaded (#35155) 2026-06-15 16:09:41 +08:00
state core: re-enable the legacy snapshot after sync (#35163) 2026-06-16 11:09:32 +08:00
stateless eth/catalyst: implement engine_newPayloadWithWitnessV5 and use witness field spec ordering (#35009) 2026-05-21 21:00:57 +02:00
tracing core: implement EIP-8037, state creation gas cost increase (#33601) 2026-06-12 14:29:03 +02:00
txpool core: implement EIP-8037, state creation gas cost increase (#33601) 2026-06-12 14:29:03 +02:00
types core/types/bal: improve the bal validation (#35110) 2026-06-05 10:44:41 +08:00
vm core/vm: compute stack operations in place (#35156) 2026-06-16 07:47:05 -05:00
.gitignore
bal_test.go core: implement EIP-8037, state creation gas cost increase (#33601) 2026-06-12 14:29:03 +02:00
bench_test.go core: implement EIP-8037, state creation gas cost increase (#33601) 2026-06-12 14:29:03 +02:00
bintrie_witness_test.go core: implement EIP-8037, state creation gas cost increase (#33601) 2026-06-12 14:29:03 +02:00
block_validator.go core/types/bal: add additional static validation for access lists (#34967) 2026-05-20 09:35:28 +08:00
block_validator_test.go eth/catalyst: add initial OpenTelemetry tracing for newPayload (#33521) 2026-02-17 17:08:57 +01:00
blockchain.go core: re-enable the legacy snapshot after sync (#35163) 2026-06-16 11:09:32 +08:00
blockchain_insert.go core: remove unused peek function in insertIterator (#33155) 2025-11-12 15:30:16 +08:00
blockchain_reader.go eth/protocols/eth: implement eth71 bal response (#34879) 2026-05-19 20:25:13 +02:00
blockchain_repair_test.go core: consolidate BlockChain constructor options (#31925) 2025-06-19 12:21:15 +02:00
blockchain_sethead_test.go core, miner, tests: introduce codedb and simplify cachingDB (#33816) 2026-03-10 08:29:21 +01:00
blockchain_snapshot_test.go core: re-enable the legacy snapshot after sync (#35163) 2026-06-16 11:09:32 +08:00
blockchain_stats.go core: add code cache hit/miss meters (#34821) 2026-05-22 11:33:21 +08:00
blockchain_test.go all: fix all typos, as reported by crates-ci/typos (#35008) 2026-06-10 18:50:51 +02:00
chain_makers.go core: add slot number (#35036) 2026-05-26 12:27:07 +02:00
chain_makers_test.go core: consolidate BlockChain constructor options (#31925) 2025-06-19 12:21:15 +02:00
dao_test.go all: fix all typos, as reported by crates-ci/typos (#35008) 2026-06-10 18:50:51 +02:00
error.go core, internal/ethapi: fix incorrect max-initcode RPC error mapping (#34067) 2026-03-23 22:10:32 +08:00
eth_transfer_logs_test.go core, core/vm: implement EIP-7708 (#33645) 2026-03-23 22:29:53 +08:00
events.go ethstats: report newPayload processing time to stats server (#33395) 2026-01-05 17:49:30 +01:00
evm.go core: implement EIP-8037, state creation gas cost increase (#33601) 2026-06-12 14:29:03 +02:00
gaspool.go core: implement EIP-8037, state creation gas cost increase (#33601) 2026-06-12 14:29:03 +02:00
gen_genesis.go core/vm: implement eip-7843: SLOTNUM (#33589) 2026-02-26 13:53:46 +01:00
genesis.go core, consensus, internal, eth, miner: construct block accessList (#34957) 2026-05-19 21:51:53 +08:00
genesis_alloc.go params: add hoodi testnet definition (#31406) 2025-03-18 12:07:49 +01:00
genesis_test.go accounts/abi, core, metrics, miner, rlp, signer, triedb: fix all incorrect variable usages in error strings (#35121) 2026-06-08 12:39:10 +02:00
headerchain.go core/rawdb: reduce allocations in rawdb.ReadHeaderNumber (#31913) 2025-07-15 15:48:36 +02:00
headerchain_test.go core/state, core/tracing: new state update hook (#33490) 2026-01-08 11:07:19 +08:00
jumpdest.go core/vm: global cache for jumpdest bitmaps (#34850) 2026-05-27 09:01:05 +02:00
mkalloc.go accounts, cmd/geth, core: close opened files (#29598) 2024-04-30 15:47:21 +02:00
rlp_test.go crypto/keccak: vendor in golang.org/x/crypto/sha3 (#33323) 2026-02-03 14:55:27 -07:00
sender_cacher.go core: use sync.Once for SenderCacher initialization (#31029) 2025-01-16 14:36:45 +01:00
state_prefetcher.go core/vm: global cache for jumpdest bitmaps (#34850) 2026-05-27 09:01:05 +02:00
state_processor.go core: implement EIP-8037, state creation gas cost increase (#33601) 2026-06-12 14:29:03 +02:00
state_processor_test.go core/vm: implement eip-7843: SLOTNUM (#33589) 2026-02-26 13:53:46 +01:00
state_transition.go core: implement EIP-8037, state creation gas cost increase (#33601) 2026-06-12 14:29:03 +02:00
state_transition_test.go core: implement EIP-8037, state creation gas cost increase (#33601) 2026-06-12 14:29:03 +02:00
stateless.go all: fix all typos, as reported by crates-ci/typos (#35008) 2026-06-10 18:50:51 +02:00
txindexer.go core, core/txpool, eth: move subscriptions to constructor (#35048) 2026-06-01 08:13:59 +08:00
txindexer_test.go core/rawdb: integrate eradb backend for RPC (#31604) 2025-06-03 10:47:38 +02:00
types.go core/vm: global cache for jumpdest bitmaps (#34850) 2026-05-27 09:01:05 +02:00