Skip to content

P2-9: fix swapped contracts init_code_hash / code_hash - #73

Merged
trial123Zel merged 1 commit into
mainfrom
fix/35-contracts-hash-swap
May 17, 2026
Merged

P2-9: fix swapped contracts init_code_hash / code_hash#73
trial123Zel merged 1 commit into
mainfrom
fix/35-contracts-hash-swap

Conversation

@trial123Zel

Copy link
Copy Markdown
Owner

P2-9 — contracts init_code_hash / code_hash swapped

Problem

In the contracts dataset, process_contracts hashed the wrong inputs:

  • init_code_hash was set to keccak256(result.code) — the deployed runtime code
  • code_hash was set to keccak256(create.init) — the init (deployment) code

The two keccak256 calls referenced each other's inputs. The adjacent columns map the inputs correctly — init_codecreate.init, coderesult.code, n_init_code_bytescreate.init, n_code_bytesresult.code — which confirms the two hashes were transposed.

Fix

Swap the inputs so init_code_hash is the keccak256 of the init code and code_hash is the keccak256 of the deployed code.

Validation

  • Regression test in contracts.rs: a contract-creation trace with distinct init and deployed bytecode produces each hash from its correct input (and the test asserts the two differ, so a swap is caught).
  • cargo build, clippy --all-targets -D warnings, cargo +nightly fmt --check, cargo test -p cryo_freeze all green locally.

Credit

No upstream issue — cross-referenced candidate PR paradigmxyz#249 (@AuburyEssentian), credited via Co-Authored-By per ADR-0001.

Closes #35.

🤖 Generated with Claude Code

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>
@trial123Zel
trial123Zel merged commit e89ee91 into main May 17, 2026
6 checks passed
@trial123Zel
trial123Zel deleted the fix/35-contracts-hash-swap branch May 17, 2026 03:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

P2-9: contracts init_code_hash / code_hash swapped

1 participant