feat(specs): EIP-8037 state-delta counter (frame-diff alternative) [DRAFT]#2765
Closed
spencer-tb wants to merge 3 commits intoethereum:forks/amsterdamfrom
Closed
feat(specs): EIP-8037 state-delta counter (frame-diff alternative) [DRAFT]#2765spencer-tb wants to merge 3 commits intoethereum:forks/amsterdamfrom
spencer-tb wants to merge 3 commits intoethereum:forks/amsterdamfrom
Conversation
Move the state_delta_bytes counter from TransactionState onto Evm and bump it inline at opcode/interpreter sites instead of inside state_tracker hooks. State_tracker stays pure (no Evm import, no gas-accounting concerns). - Evm.state_delta_bytes is the per-frame byte counter; sums via incorporate_child_on_success. - SSTORE bumps inline after set_storage based on 0 ↔ nonzero transition. - CALL value-to-empty bumps in process_message after move_ether (on the child evm so revert handles it). - CREATE/CREATE2 bumps in process_create_message on the success path: +112 + len(contract_code) after set_code. - SELFDESTRUCT same-tx destruction: depth-0 destroy loop debits -112 - len(code) - 32×slots inline before destroy_account. - COST_PER_STATE_BYTE replaces the unused dynamic-cpsb formula constants and state_gas_per_byte() function. validate_transaction/calculate_intrinsic_cost drop the gas_limit parameter.
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.
Summary
Prototype implementation of EIP-8037 state gas charging via a per-frame state-delta byte counter on
TransactionState, fresh fromforks/amsterdam. Successor to PR #2683's diff-at-return approach.Two commits:
feat(specs): EIP-8037 diff-at-return state gas charging(735947d4) — initial port of feat(specs): EIP-8037 diff-at-call-return state gas charging [DRAFT] #2683's diff-at-return mechanism onto freshforks/amsterdam. Computes a state diff at eachprocess_messagereturn.feat(specs): EIP-8037 state-delta counter on TransactionState(5f1f5fe1) — replaces the diff with a counter onTransactionState.state_delta_bytes. Hooked at the five low-level state funcs (set_account,set_storage,set_code,destroy_account,destroy_storage).Final state is the counter approach; the diff commit is preserved in history for reviewability.
Why counter over diff
Two real problems with the diff approach surfaced during review:
destroy_accountdoesn't cleancode_writes(codes keyed by hash, may be shared). The diff never sees code disappear on same-tx CREATE+SELFDESTRUCT, so we had to add an explicit refund block infork.pyrecomputing account + storage + code by hand.Counter solves both —
destroy_accountexplicitly debits-= len(code)(no gap), and the abstraction matches journal semantics.Hook table
None → Someset_accountSome → Noneset_account0 → nonzeroset_storagenonzero → 0set_storagecode_hash)set_codedestroy_storagedestroy_account7702 auths run pre-EVM (before depth-0 snapshot), so their account creation is counted but absorbed into the snapshot —
frame_deltadoesn't see them. Intrinsic.state pre-charge + reservoir refund for existing-account auths handles this (unchanged from current behavior).Charge at frame return
The counter is stored on
TransactionState, included incopy_tx_stateandrestore_tx_state— naturally rolls back on revert, no extra journal needed.SELFDESTRUCT same-tx refund
Moved into depth-0
process_message, before the counter charge:The destroy hooks (
-112account,-len(code)code,-32per non-zero slot) credittx_state.state_delta_bytesnaturally. The subsequentframe_delta * cpsbcalculation nets these credits against earlier charges. Removed:fork.py:process_transaction(was added in commit735947d4).for address in tx_output.accounts_to_delete: destroy_account(...)loop infork.py(now done inprocess_message).Files modified (final state, counter approach)
Open items
mypyclean on the three modified files.Related