fix(contracts): swap init_code_hash and code_hash keccak256 inputs - #249
fix(contracts): swap init_code_hash and code_hash keccak256 inputs#249AuburyEssentian wants to merge 1 commit into
Conversation
init_code_hash should hash create.init (the initialization bytecode), and code_hash should hash result.code (the deployed runtime bytecode). The two keccak256 calls were reversed, causing the columns to contain each other's values in the canonical_execution_contracts table. The n_init_code_bytes / n_code_bytes byte-count columns reference the correct inputs already — only the hash columns were affected. Fixes ethpandaops/xatu#688.
process_contracts hashed the wrong inputs: init_code_hash held keccak256(result.code) -- the deployed runtime code -- and code_hash held keccak256(create.init) -- the deployment init code. The adjacent init_code/code and n_init_code_bytes/n_code_bytes columns map the inputs correctly, confirming the two hashes were transposed. Swap them so init_code_hash is the keccak256 of the init code and code_hash is the keccak256 of the deployed code. Added a regression test: a contract-creation trace with distinct init and deployed bytecode now produces each hash from its correct input. Cross-referenced candidate PR paradigmxyz#249. Closes #35. Co-Authored-By: AuburyEssentian <263089372+AuburyEssentian@users.noreply.github.com> Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
stiliyanaa
left a comment
There was a problem hiding this comment.
Join Holders! Your personalized invite is available at the link below. Before you start, make sure you have the latest version of the Tonhub app installed - https://tonhub.com/holders/invite/cmpm7bei61h1r933v07326shs
|
The hash swap appears already implemented in the current code; init_code_hash hashes create.init and code_hash hashes result.code as described. Could you clarify the remaining concerns? |
|
@maintainer Could you take a look at the hash swap changes? Let me know if any further tweaks are needed. |
|
It appears the review comment from @stiliyanaa may be spam (contains an unrelated invite link). Could you please confirm if this is a genuine review request? If not, we may need to disregard it and seek review from another maintainer. |
Problem
init_code_hashandcode_hashin thecontractsdataset are populated with each other's values. The twokeccak256calls on lines 101–102 ofcontracts.rsreference the wrong inputs:init_code_hashshould hashcreate.init— the initialization bytecode sent in the CREATE transactioncode_hashshould hashresult.code— the runtime bytecode stored at the contract addressThis was confirmed in ethpandaops/xatu#688 by comparing against
geth snapshot inspect-account: the value ininit_code_hashmatches geth'saccount.codehash(the deployed code hash), and distinct count ofcode_hash(~4.5M) far exceeds the known unique deployed code count (~1.7M).The
n_init_code_bytes/n_code_bytescolumns are unaffected — they already reference the correct sources.Fix
Swap the two
keccak256arguments so each column hashes the right input.