Skip to content

refactor(test): use metadata and macros; remove helpers#6

Merged
spencer-tb merged 1 commit into
spencer-tb:feat/eip-8037-halt-spill-refundfrom
fselmo:refactor/use-metadata-and-macro-remove-helpers
May 7, 2026
Merged

refactor(test): use metadata and macros; remove helpers#6
spencer-tb merged 1 commit into
spencer-tb:feat/eip-8037-halt-spill-refundfrom
fselmo:refactor/use-metadata-and-macro-remove-helpers

Conversation

@fselmo
Copy link
Copy Markdown
Collaborator

@fselmo fselmo commented May 6, 2026

Refactors current state of tests to use framework macro and metadata. Removes the need for helpers. Verified with hasher compare and they don't produce identical fixtures in some cases because the macro optimizes non-padded things with different PUSHN sizes it seems.


Claude summary when asked to hasher compare and why it wasn't the exact same

Drops _store_data_in_memory and _create_chain_extra_regular_gas from test_state_gas_reservoir.py (~32 lines net):

  • Om.MSTORE(padded_bytes, 0) replaces the manual chunked MSTORE loop. The 32-byte pre-pad keeps it on the cheap PUSH32+MSTORE path; CREATE reads only size bytes so trailing zeros are ignored.
  • Op.CREATE(..., init_code_size=inner_size) lets the framework's gas calculator account for EIP-3860 init-code-cost (it requires init_code_size metadata; not auto-derived from the size stack arg). Combined with Om.MSTORE's new_memory_size metadata, bytecode.gas_cost(fork) now covers both dynamic-gas pieces and
    the manual correction term in the test math goes away.

Behavioral equivalence verified by filling pre/post and comparing fixtures with hasher compare:

┌────────────────────┬───────────────────────────────────────┐                                                                                                                                                                                                                                                            
│       field        │ match across 24 create-chain variants │
├────────────────────┼───────────────────────────────────────┤                                                                                                                                                                                                                                                            
│ block.gasUsed      │ 24/24 ✓                               │
├────────────────────┼───────────────────────────────────────┤                                                                                                                                                                                                                                                            
│ block.receiptsRoot │ 24/24 ✓                               │
├────────────────────┼───────────────────────────────────────┤
│ block.stateRoot    │ 0/24 (expected)                       │
└────────────────────┴───────────────────────────────────────┘                                                                                                                                                                                                                                                            

The state-root divergence is an unavoidable consequence of the framework's PUSH-minimization: a 32-byte chunk with leading zeros becomes PUSH31 <31 bytes> instead of PUSH32 <32 bytes> because both opcodes push the same 256-bit integer onto the stack (left-padded to 256 bits), so MSTORE writes identical memory.
The single-byte parent-bytecode shift cascades through codeHash → contract address → child CREATE addresses → state root, but execution gas, logs, and post-storage contents are bit-identical.

Net: same logic, same on-chain behavior, smaller test surface.

@fselmo fselmo requested a review from spencer-tb May 6, 2026 22:18
@fselmo
Copy link
Copy Markdown
Collaborator Author

fselmo commented May 6, 2026

@spencer-tb suggested refactor to use framework native approach for the tests here. lmk what you think.

@spencer-tb spencer-tb merged commit 4a8a3c2 into spencer-tb:feat/eip-8037-halt-spill-refund May 7, 2026
6 of 15 checks passed
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.

2 participants