Skip to content

perf(host): EXTCODECOPY charge and code read from one journal probe - #244

Open
garyschulte wants to merge 4 commits into
Consensys-Incorporated:mainfrom
garyschulte:perf/extcodecopy-warm-probe-lookup
Open

garyschulte wants to merge 4 commits into
Consensys-Incorporated:mainfrom
garyschulte:perf/extcodecopy-warm-probe-lookup

Conversation

@garyschulte

@garyschulte garyschulte commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • Cold and first-touch accounts get slower. When warmAccount misses, isAddressCold looks the same address up again, then codeInfo loads it: three evm_state lookups where there used to be two.
  • A raw pointer into evm_state leaves the journal. Host.warmAccount returns *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.
  • The API needs a caveat to be used correctly. "Null says nothing about coldness", so every caller has to write warm == null and isAddressCold(...).
  • A doc comment moved to the wrong function. warmAccount was inserted between isAddressLoaded and its doc comment, so warmAccount now has the wrong description and isAddressLoaded has none.

What

JournalInner.codeProbe / Host.codeProbe follow the existing sloadProbe. One evm_state lookup with no side effects returns { code: ?[]const u8, is_cold: bool }:

  • is_cold is exactly what isAddressCold returns, on every path.
  • code is 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 to codeInfo only 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 Bytecode copy. 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 same main for comparison. All post-state roots match.

copy size main #224 #224 vs main this PR this PR vs main vs #224
0 75,358,416 47,939,398 −36.38% 48,080,595 −36.20% +0.29%
32 87,275,633 59,263,657 −32.10% 58,566,674 −32.89% −1.18%
256 85,658,459 57,092,030 −33.35% 56,456,994 −34.09% −1.11%
512 69,509,944 47,729,181 −31.33% 47,152,827 −32.16% −1.21%
1024 61,115,296 41,561,802 −31.99% 41,075,230 −32.79% −1.17%
max 4,467,763 3,521,844 −21.17% 3,498,148 −21.70% −0.67%

No fixture exercises cold EXTCODECOPY, so the cold-path saving (one fewer lookup) isn't measured here.

Tests

New codeProbe journal tests (src/evm/context/journal_tests.zig), one per warmth state. Each also checks that the probe agrees with
isAddressCold:
- 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

  • New EXTCODECOPY tests (src/evm/interpreter/opcodes/host_ops_tests.zig) check the copied bytes and the exact gas for:
    • a cold account: cold access charge
    • a warm account with its code loaded: warm charge, fast path
    • a warm account without its code loaded: warm charge, codeInfo fallback
    • an address warm as coinbase but not loaded: warm charge, loaded after charging
    • an account warmed in a reverted call: charged cold again
  • Each new test was checked against a deliberately broken probe (one ignoring warmth, one ignoring the coinbase warm list) and fails as expected.

🤖 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 on sloadProbe: one read-only journal lookup returns { code: ?[]const u8, is_cold: bool } without warming accounts, journaling, or EIP-7928 BAL reads. is_cold always matches isAddressCold; code is set only when the account is already loaded and warm in the current transaction with code present.

EXTCODECOPY now calls Host.codeProbe before gas charging (replacing a separate cold check), uses probe bytes when available, and falls back to codeInfo only after charging—preserving charge-before-load BAL behavior. The vtable exposes CodeProbe through journal and host layers.

New tests cover every codeProbe warmth 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.

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>
@Gabriel-Trintinalia

Copy link
Copy Markdown
Contributor

/benchmark

@github-actions

Copy link
Copy Markdown

Benchmark — rv64im (zkvm-standards baseline) ⚪ no change

8ba5ef840920 vs merge-base d3bb2f5493af over 10 block(s) of Sepolia.

component merge-base this PR delta
⚪ total 170,483,314,853 170,483,010,673 -0.000%
⚪ main 113,257,152,616 113,256,970,920 -0.000%
⚪ opcodes 18,463,921,591 18,463,887,990 -0.000%
⚪ precompiles 19,128,713,867 19,128,706,847 -0.000%
⚪ memory 16,760,428,539 16,760,346,676 -0.000%
⚪ base 2,873,098,240 2,873,098,240 +0.000%

🟢 4 improved · 🔴 6 regressed · ⚪ 0 unchanged (best -0.002%, worst +0.000%).

Per-block (Sepolia)
block merge-base this PR delta
⚪ 11856500 34,497,453,321 34,497,453,392 +0.000%
⚪ 11856501 15,091,258,178 15,091,235,827 -0.000%
⚪ 11856502 6,551,009,888 6,551,009,959 +0.000%
⚪ 11856503 9,873,842,224 9,873,775,481 -0.001%
⚪ 11856504 9,303,028,385 9,303,028,456 +0.000%
⚪ 11856505 7,983,033,051 7,983,033,122 +0.000%
⚪ 11856506 34,764,155,211 34,764,155,282 +0.000%
⚪ 11856507 8,386,000,140 8,385,977,789 -0.000%
⚪ 11856508 10,046,421,887 10,046,228,726 -0.002%
⚪ 11856509 33,987,112,568 33,987,112,639 +0.000%
30M tier 🟢 -0.080%

Median total cost by suite over 120 block(s) (empty blocks excluded).

suite blocks merge-base this PR delta
⚪ eip7928_block_level_access_lists/block_access_list 5 47,828,520,532 47,828,520,603 +0.000%
⚪ instruction/account_query 6 37,313,959,787 37,313,959,858 +0.000%
⚪ instruction/arithmetic 4 95,794,373,182 95,794,373,253 +0.000%
⚪ instruction/bitwise 6 59,283,954,023 59,283,954,094 +0.000%
⚪ instruction/block_context 3 64,255,809,447 64,255,809,518 +0.000%
⚪ instruction/call_context 10 31,337,594,422 31,337,594,493 +0.000%
⚪ instruction/comparison 2 23,493,917,855 23,493,917,926 +0.000%
⚪ instruction/control_flow 7 21,149,032,863 21,149,032,934 +0.000%
⚪ instruction/keccak 3 29,642,951,306 29,642,951,377 +0.000%
⚪ instruction/log 2 2,227,069,023 2,227,069,094 +0.000%
⚪ instruction/memory 5 39,568,360,647 39,568,360,718 +0.000%
⚪ instruction/stack 7 52,686,550,210 52,686,550,281 +0.000%
⚪ instruction/storage 7 9,855,568,492 9,855,568,563 +0.000%
⚪ instruction/system 13 3,200,875,800 3,200,875,871 +0.000%
⚪ instruction/tx_context 2 57,254,424,812 57,254,424,883 +0.000%
⚪ precompile/alt_bn128 5 28,096,395,216 28,096,395,287 +0.000%
⚪ precompile/blake2f 3 45,216,677,267 45,216,677,338 +0.000%
⚪ precompile/bls12_381 6 26,293,567,434 26,293,567,505 +0.000%
⚪ precompile/ecrecover 1 12,501,468,302 12,501,468,373 +0.000%
⚪ precompile/identity 3 26,299,209,427 26,299,209,498 +0.000%
⚪ precompile/modexp 3 15,577,928,393 15,577,928,464 +0.000%
⚪ precompile/p256verify 2 6,959,806,921 6,959,806,992 +0.000%
⚪ precompile/point_evaluation 2 102,555,924,774 102,555,924,845 +0.000%
⚪ precompile/ripemd160 3 19,100,671,495 19,100,671,566 +0.000%
⚪ precompile/sha256 3 18,447,684,289 18,447,684,360 +0.000%
⚪ scenario/mix_operations 1 11,620,272,137 11,620,272,208 +0.000%
⚪ scenario/transaction_types 6 4,231,804,911 4,231,804,982 +0.000%

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.

@github-actions github-actions Bot added the benchmarked Guest benchmark has been run on this PR label Nov 16, 2026
@github-actions

Copy link
Copy Markdown

Benchmark — ZisK (rv64im + Zbb + Zbs) ⚪ no change

8ba5ef840920 vs merge-base d3bb2f5493af over 10 block(s) of Sepolia.

component merge-base this PR delta
⚪ total 154,734,862,762 154,734,558,744 -0.000%
⚪ main 99,567,742,476 99,567,560,780 -0.000%
⚪ opcodes 16,770,610,442 16,770,578,447 -0.000%
⚪ precompiles 19,684,408,463 19,684,401,443 -0.000%
⚪ memory 15,839,003,141 15,838,919,834 -0.001%
⚪ base 2,873,098,240 2,873,098,240 +0.000%

🟢 4 improved · 🔴 0 regressed · ⚪ 6 unchanged (best -0.002%, worst +0.000%).

Per-block (Sepolia)
block merge-base this PR delta
⚪ 11856500 32,690,896,374 32,690,896,374 +0.000%
⚪ 11856501 12,735,691,426 12,735,669,003 -0.000%
⚪ 11856502 5,556,038,908 5,556,038,908 +0.000%
⚪ 11856503 8,216,126,752 8,216,059,980 -0.001%
⚪ 11856504 7,925,897,589 7,925,897,589 +0.000%
⚪ 11856505 6,815,713,055 6,815,713,055 +0.000%
⚪ 11856506 33,078,277,207 33,078,277,207 +0.000%
⚪ 11856507 7,122,640,377 7,122,617,954 -0.000%
⚪ 11856508 8,291,920,914 8,291,728,514 -0.002%
⚪ 11856509 32,301,660,160 32,301,660,160 +0.000%
30M tier 🟢 -0.094%

Median total cost by suite over 120 block(s) (empty blocks excluded).

suite blocks merge-base this PR delta
⚪ eip7928_block_level_access_lists/block_access_list 5 39,205,820,214 39,205,820,214 +0.000%
⚪ instruction/account_query 6 36,626,860,737 36,626,860,737 +0.000%
⚪ instruction/arithmetic 4 34,700,063,390 34,700,063,390 +0.000%
⚪ instruction/bitwise 6 28,794,670,401 28,794,670,401 +0.000%
⚪ instruction/block_context 3 62,967,342,989 62,967,342,989 +0.000%
⚪ instruction/call_context 10 30,930,740,885 30,930,740,885 +0.000%
⚪ instruction/comparison 2 23,225,111,934 23,225,111,934 +0.000%
⚪ instruction/control_flow 7 20,768,962,637 20,768,962,637 +0.000%
⚪ instruction/keccak 3 14,382,298,979 14,382,298,979 +0.000%
⚪ instruction/log 2 2,282,532,348 2,282,532,348 +0.000%
⚪ instruction/memory 5 37,809,362,591 37,809,362,591 +0.000%
⚪ instruction/stack 7 48,840,361,872 48,840,361,872 +0.000%
⚪ instruction/storage 7 9,410,435,867 9,410,435,867 +0.000%
⚪ instruction/system 13 3,110,969,236 3,110,969,236 +0.000%
⚪ instruction/tx_context 2 52,897,952,077 52,897,952,077 +0.000%
⚪ precompile/alt_bn128 5 27,151,918,676 27,151,918,676 +0.000%
⚪ precompile/blake2f 3 43,096,598,576 43,096,598,576 +0.000%
⚪ precompile/bls12_381 6 26,242,857,462 26,242,857,462 +0.000%
⚪ precompile/ecrecover 1 12,201,599,179 12,201,599,179 +0.000%
⚪ precompile/identity 3 22,783,629,429 22,783,629,429 +0.000%
⚪ precompile/modexp 3 15,574,473,961 15,574,473,961 +0.000%
⚪ precompile/p256verify 2 6,863,337,068 6,863,337,068 +0.000%
⚪ precompile/point_evaluation 2 102,509,521,651 102,509,521,651 +0.000%
⚪ precompile/ripemd160 3 19,028,817,527 19,028,817,527 +0.000%
⚪ precompile/sha256 3 17,919,837,120 17,919,837,120 +0.000%
⚪ scenario/mix_operations 1 1,228,398,514 1,228,398,514 +0.000%
⚪ scenario/transaction_types 6 4,040,068,762 4,040,068,762 +0.000%

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.

@Gabriel-Trintinalia

Copy link
Copy Markdown
Contributor

/benchmark

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

Benchmark — ZisK (rv64im + Zbb + Zbs) ⚪ no change

d5bb50534b35 vs merge-base 9fd1e6e676f5 over 10 block(s) of Sepolia.

component merge-base this PR delta
⚪ total 152,444,203,037 152,443,899,019 -0.000%
⚪ main 98,047,655,652 98,047,473,956 -0.000%
⚪ opcodes 16,524,039,435 16,524,007,440 -0.000%
⚪ precompiles 19,479,879,558 19,479,872,538 -0.000%
⚪ memory 15,519,530,152 15,519,446,845 -0.001%
⚪ base 2,873,098,240 2,873,098,240 +0.000%

🟢 4 improved · 🔴 0 regressed · ⚪ 6 unchanged (best -0.002%, worst +0.000%).

Per-block (Sepolia)
block merge-base this PR delta
⚪ 11856500 32,532,675,446 32,532,675,446 +0.000%
⚪ 11856501 12,305,624,551 12,305,602,128 -0.000%
⚪ 11856502 5,363,505,853 5,363,505,853 +0.000%
⚪ 11856503 7,977,687,054 7,977,620,282 -0.001%
⚪ 11856504 7,681,280,239 7,681,280,239 +0.000%
⚪ 11856505 6,570,159,643 6,570,159,643 +0.000%
⚪ 11856506 32,945,563,315 32,945,563,315 +0.000%
⚪ 11856507 6,857,189,370 6,857,166,947 -0.000%
⚪ 11856508 8,054,762,878 8,054,570,478 -0.002%
⚪ 11856509 32,155,754,688 32,155,754,688 +0.000%
30M tier 🟢 -0.094%

Median total cost by suite over 121 block(s) (empty blocks excluded).

suite blocks merge-base this PR delta
⚪ eip7928_block_level_access_lists/block_access_list 5 39,204,918,601 39,204,918,601 +0.000%
⚪ instruction/account_query 6 36,626,416,008 36,626,416,008 +0.000%
⚪ instruction/arithmetic 4 33,310,198,720 33,310,198,720 +0.000%
⚪ instruction/bitwise 6 28,794,202,662 28,794,202,662 +0.000%
⚪ instruction/block_context 3 62,966,892,125 62,966,892,125 +0.000%
⚪ instruction/call_context 10 30,930,298,756 30,930,298,756 +0.000%
⚪ instruction/comparison 2 23,224,604,403 23,224,604,403 +0.000%
⚪ instruction/control_flow 7 20,768,502,992 20,768,502,992 +0.000%
⚪ instruction/keccak 3 14,381,837,932 14,381,837,932 +0.000%
⚪ instruction/log 2 2,282,074,061 2,282,074,061 +0.000%
⚪ instruction/memory 5 37,808,886,939 37,808,886,939 +0.000%
⚪ instruction/stack 7 48,839,915,845 48,839,915,845 +0.000%
⚪ instruction/storage 9 10,232,768,680 10,232,768,680 +0.000%
⚪ instruction/system 13 2,957,045,997 2,957,045,997 +0.000%
⚪ instruction/tx_context 2 52,897,533,596 52,897,533,596 +0.000%
⚪ precompile/alt_bn128 5 27,151,377,793 27,151,377,793 +0.000%
⚪ precompile/blake2f 3 43,095,932,025 43,095,932,025 +0.000%
⚪ precompile/bls12_381 5 6,966,368,861 6,966,368,177 -0.000%
⚪ precompile/ecrecover 1 12,201,047,015 12,201,047,015 +0.000%
⚪ precompile/identity 3 22,782,306,575 22,782,306,575 +0.000%
⚪ precompile/modexp 3 15,573,599,934 15,573,599,934 +0.000%
⚪ precompile/p256verify 2 6,862,789,584 6,862,789,584 +0.000%
⚪ precompile/point_evaluation 2 102,486,079,397 102,486,079,397 +0.000%
⚪ precompile/ripemd160 3 19,027,493,371 19,027,493,371 +0.000%
⚪ precompile/sha256 3 17,918,546,447 17,918,546,447 +0.000%
⚪ scenario/mix_operations 1 9,502,898,295 9,502,898,295 +0.000%
⚪ scenario/transaction_types 6 3,796,776,659 3,796,776,659 +0.000%

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.

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

Benchmark — rv64im (zkvm-standards baseline) ⚪ no change

d5bb50534b35 vs merge-base 9fd1e6e676f5 over 10 block(s) of Sepolia.

component merge-base this PR delta
⚪ total 166,910,442,882 166,910,138,552 -0.000%
⚪ main 111,132,402,584 111,132,220,888 -0.000%
⚪ opcodes 17,651,791,329 17,651,757,578 -0.000%
⚪ precompiles 18,924,184,962 18,924,177,942 -0.000%
⚪ memory 16,328,965,767 16,328,883,904 -0.001%
⚪ base 2,873,098,240 2,873,098,240 +0.000%

🟢 4 improved · 🔴 6 regressed · ⚪ 0 unchanged (best -0.002%, worst +0.000%).

Per-block (Sepolia)
block merge-base this PR delta
⚪ 11856500 34,250,177,974 34,250,178,030 +0.000%
⚪ 11856501 14,401,091,764 14,401,069,398 -0.000%
⚪ 11856502 6,236,789,449 6,236,789,505 +0.000%
⚪ 11856503 9,490,268,612 9,490,201,854 -0.001%
⚪ 11856504 8,916,882,835 8,916,882,891 +0.000%
⚪ 11856505 7,622,246,129 7,622,246,185 +0.000%
⚪ 11856506 34,566,913,115 34,566,913,171 +0.000%
⚪ 11856507 7,961,508,775 7,961,486,409 -0.000%
⚪ 11856508 9,688,102,041 9,687,908,865 -0.002%
⚪ 11856509 33,776,462,188 33,776,462,244 +0.000%
30M tier 🟢 -0.077%

Median total cost by suite over 121 block(s) (empty blocks excluded).

suite blocks merge-base this PR delta
⚪ eip7928_block_level_access_lists/block_access_list 5 47,827,380,435 47,827,380,491 +0.000%
⚪ instruction/account_query 6 37,303,683,993 37,303,684,049 +0.000%
⚪ instruction/arithmetic 4 94,190,077,827 94,190,077,883 +0.000%
⚪ instruction/bitwise 6 59,277,969,576 59,277,969,632 +0.000%
⚪ instruction/block_context 3 64,252,381,049 64,252,381,105 +0.000%
⚪ instruction/call_context 10 35,235,595,226 35,235,595,282 +0.000%
⚪ instruction/comparison 2 23,483,977,826 23,483,977,882 +0.000%
⚪ instruction/control_flow 7 21,148,379,497 21,148,379,553 +0.000%
⚪ instruction/keccak 3 29,634,596,369 29,634,596,425 +0.000%
⚪ instruction/log 2 2,217,951,125 2,217,951,181 +0.000%
⚪ instruction/memory 5 39,560,989,608 39,560,989,664 +0.000%
⚪ instruction/stack 7 52,683,273,935 52,683,273,991 +0.000%
⚪ instruction/storage 9 11,355,069,570 11,355,069,626 +0.000%
⚪ instruction/system 13 3,041,813,637 3,041,813,693 +0.000%
⚪ instruction/tx_context 2 57,250,957,445 57,250,957,501 +0.000%
⚪ precompile/alt_bn128 5 28,095,712,911 28,095,712,967 +0.000%
⚪ precompile/blake2f 3 45,209,666,109 45,209,666,165 +0.000%
⚪ precompile/bls12_381 5 7,004,858,568 7,004,858,824 +0.000%
⚪ precompile/ecrecover 1 12,494,569,015 12,494,569,071 +0.000%
⚪ precompile/identity 3 26,297,733,031 26,297,733,087 +0.000%
⚪ precompile/modexp 3 15,576,878,694 15,576,878,750 +0.000%
⚪ precompile/p256verify 2 6,956,228,132 6,956,228,188 +0.000%
⚪ precompile/point_evaluation 2 102,530,293,348 102,530,293,404 +0.000%
⚪ precompile/ripemd160 3 19,099,194,511 19,099,194,567 +0.000%
⚪ precompile/sha256 3 18,446,241,087 18,446,241,143 +0.000%
⚪ scenario/mix_operations 1 90,214,255,708 90,214,255,764 +0.000%
⚪ scenario/transaction_types 6 3,970,170,050 3,970,170,106 +0.000%

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.

@Gabriel-Trintinalia
Gabriel-Trintinalia enabled auto-merge (squash) December 2, 2026 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

benchmarked Guest benchmark has been run on this PR Performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants