Repository navigation
perf(host): EXTCODECOPY charge and code read from one journal probe - #244
garyschulte wants to merge 4 commits into
Conversation
Add JournalInner.codeProbe / Host.codeProbe, modelled on sloadProbe: one evm_state lookup that returns the account's coldness (exactly what isAddressCold returns) and, for an account loaded and warm in this transaction, its code bytes. EXTCODECOPY charges from the probe and copies from its bytes; it falls back to codeInfo only when the code is not loaded, after charging, so the BAL ordering is unchanged. Every path does at most one evm_state lookup before the charge: warm loaded accounts skip loadAccountWithCode, and cold or first-touch accounts no longer look the address up twice. The probe has no side effects and hands back a borrowed byte slice rather than a pointer to the Account; returning a Bytecode copy across the vtable cost as much as the saved lookup. Tests cover the probe in every warmth state (unloaded, coinbase-warm, loaded without code, loaded with code, earlier transaction, reverted call) and EXTCODECOPY's copy and gas on cold, warm and reverted accounts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: garyschulte <garyschulte@gmail.com>
|
/benchmark |
Benchmark — rv64im (zkvm-standards baseline) ⚪ no change
🟢 4 improved · 🔴 6 regressed · ⚪ 0 unchanged (best -0.002%, worst +0.000%). Per-block (Sepolia)
30M tier 🟢 -0.080%Median total cost by suite over 120 block(s) (empty blocks excluded).
Trace costs are deterministic, so these deltas carry no run-to-run noise. A handful of blocks is a smoke signal, not a verdict — the full corpus stays the arbiter for anything perf-sensitive. |
Benchmark — ZisK (rv64im + Zbb + Zbs) ⚪ no change
🟢 4 improved · 🔴 0 regressed · ⚪ 6 unchanged (best -0.002%, worst +0.000%). Per-block (Sepolia)
30M tier 🟢 -0.094%Median total cost by suite over 120 block(s) (empty blocks excluded).
Trace costs are deterministic, so these deltas carry no run-to-run noise. A handful of blocks is a smoke signal, not a verdict — the full corpus stays the arbiter for anything perf-sensitive. |
|
/benchmark |
Benchmark — ZisK (rv64im + Zbb + Zbs) ⚪ no change
🟢 4 improved · 🔴 0 regressed · ⚪ 6 unchanged (best -0.002%, worst +0.000%). Per-block (Sepolia)
30M tier 🟢 -0.094%Median total cost by suite over 121 block(s) (empty blocks excluded).
Trace costs are deterministic, so these deltas carry no run-to-run noise. A handful of blocks is a smoke signal, not a verdict — the full corpus stays the arbiter for anything perf-sensitive. |
Benchmark — rv64im (zkvm-standards baseline) ⚪ no change
🟢 4 improved · 🔴 6 regressed · ⚪ 0 unchanged (best -0.002%, worst +0.000%). Per-block (Sepolia)
30M tier 🟢 -0.077%Median total cost by suite over 121 block(s) (empty blocks excluded).
Trace costs are deterministic, so these deltas carry no run-to-run noise. A handful of blocks is a smoke signal, not a verdict — the full corpus stays the arbiter for anything perf-sensitive. |
Supersedes #224. It keeps #224's warm-path win and fixes the problems it left behind.
Why
EXTCODECOPY charges warm/cold access before it loads the account, so an out-of-gas never records the account in the BAL. That needs one lookup for the charge and another for the code read. #224 removed the second lookup for warm loaded accounts, but:
warmAccountmisses,isAddressColdlooks the same address up again, thencodeInfoloads it: threeevm_statelookups where there used to be two.evm_stateleaves the journal.Host.warmAccountreturns*const Account, and EXTCODECOPY holds it across the gas charge and memory expansion. It's safe today, but any load added in between would leave it dangling after a rehash.warm == null and isAddressCold(...).warmAccountwas inserted betweenisAddressLoadedand its doc comment, sowarmAccountnow has the wrong description andisAddressLoadedhas none.What
JournalInner.codeProbe/Host.codeProbefollow the existingsloadProbe. Oneevm_statelookup with no side effects returns{ code: ?[]const u8, is_cold: bool }:is_coldis exactly whatisAddressColdreturns, on every path.codeis set only for an account loaded and warm in this transaction whose code is already loaded. Loading such an account again would have no side effects, so skipping it is safe.EXTCODECOPY charges from the probe and copies from
code. It falls back tocodeInfoonly after charging, so the BAL ordering is unchanged. Every path does at most one lookup before the charge.The probe returns a borrowed byte slice, not a
Bytecodecopy. A first version that returned?Bytecode(about 90 bytes, copied through the vtable) was 5–8% slower than #224.extcodecopy_warm, 30M gas, Amsterdam. ZisK emulator 1.3.2-alpha steps; #224 cherry-picked onto the samemainfor comparison. All post-state roots match.No fixture exercises cold EXTCODECOPY, so the cold-path saving (one fewer lookup) isn't measured here.
Tests
New
codeProbejournal tests (src/evm/context/journal_tests.zig), one per warmth state. Each also checks that the probe agrees withisAddressCold:- not loaded: cold, no code, and no BAL read or journal entry
- warm as coinbase but not loaded: warm, no code
- loaded without its code: warm, no code (the caller falls back to
codeInfo)- loaded with its code: warm, returns those bytes, no journal entry
- loaded in an earlier transaction: cold, no code (first-touch handling must still run)
- warmed inside a reverted call: cold again, no code
src/evm/interpreter/opcodes/host_ops_tests.zig) check the copied bytes and the exact gas for:codeInfofallback🤖 Generated with Claude Code
Note
Medium Risk
Touches EXTCODECOPY gas ordering and journal warm/cold semantics on a hot opcode path; behavior is constrained by tests mirroring
sloadProbe, but incorrect probe logic could affect gas or BAL correctness.Overview
Adds
codeProbe, modeled onsloadProbe: one read-only journal lookup returns{ code: ?[]const u8, is_cold: bool }without warming accounts, journaling, or EIP-7928 BAL reads.is_coldalways matchesisAddressCold;codeis set only when the account is already loaded and warm in the current transaction with code present.EXTCODECOPY now calls
Host.codeProbebefore gas charging (replacing a separate cold check), uses probe bytes when available, and falls back tocodeInfoonly after charging—preserving charge-before-load BAL behavior. The vtable exposesCodeProbethrough journal and host layers.New tests cover every
codeProbewarmth path and EXTCODECOPY gas/copy behavior (cold, warm with/without code, coinbase-warm, reverted warmth).Reviewed by Cursor Bugbot for commit 7f51951. Bugbot is set up for automated code reviews on this repo. Configure here.