db/state/execctx: fix AccountsDomain codeHash decode (DeserialiseV3) — correctness#21623
Closed
mh0lt wants to merge 1 commit into
Closed
db/state/execctx: fix AccountsDomain codeHash decode (DeserialiseV3) — correctness#21623mh0lt wants to merge 1 commit into
mh0lt wants to merge 1 commit into
Conversation
codeHashForAddr resolves an account's codeHash from the AccountsDomain so the CodeDomain ethHash bypass can serve shared bytecode without an addr-keyed file read. decodeAccountCodeHash decoded the account value with acc.DecodeForStorage, but AccountsDomain values are SerialiseV3-encoded. DecodeForStorage is the legacy MDBX bitmask format with an incompatible binary layout; applied to V3 bytes it silently misparses and leaves CodeHash empty. As a result codeHashForAddr returned nil for every account and the ethHash bypass never engaged for any contract — every CodeDomain read that missed the addr cache fell through to a file read. This is a decoding-correctness bug: the wrong decoder is applied to the stored encoding. Use accounts.DeserialiseV3, the matching decoder for AccountsDomain values. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Correctness fix
codeHashForAddrresolves an account's codeHash from theAccountsDomainso theCodeDomainethHash bypass can serve shared bytecode (proxies, clones, ERC-20 holder sets) without an addr-keyed file read.decodeAccountCodeHashdecoded the account value withacc.DecodeForStorage, butAccountsDomainvalues areSerialiseV3-encoded.DecodeForStorageis the legacy MDBX bitmask format with an incompatible binary layout — applied to V3 bytes it silently misparses and leavesCodeHashempty.Consequently
codeHashForAddrreturnednilfor every account, and the ethHash bypass never engaged for any contract: everyCodeDomainread that missed the addr cache fell through to a file read. This is a decoding-correctness bug — the wrong decoder applied to the stored encoding.Fix
Use
accounts.DeserialiseV3, the matching decoder forAccountsDomainvalues. One-function change; no behaviour change for valid encodings other than producing the correct codeHash.Verification (instrumented mainnet-tip run)
The
codeHashForAddrresolve path and ethHash bypass were instrumented:served%(cache, no file read)GetByEthHashcallsRouting
The buggy
decodeAccountCodeHash/codeHashForAddris introduced by #21386 (StateCache LRU) and does not exist onmain, so the fix targets #21386 — the appropriate point in the perf stack. It flows up to #21414 / #21416 / #20893 (all stacked on this branch). To be cherry-picked into those branches as needed.🤖 Generated with Claude Code