Skip to content

Commit 96aa19d

Browse files
committed
refactor(spec-specs): Changes from comments on PR #1841
1 parent a793e1c commit 96aa19d

File tree

8 files changed

+110
-220
lines changed

8 files changed

+110
-220
lines changed

src/ethereum/forks/amsterdam/fork.py

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
from . import vm
3232
from .block_access_lists.builder import build_block_access_list
33-
from .block_access_lists.rlp_types import BlockAccessIndex
3433
from .block_access_lists.rlp_utils import compute_block_access_list_hash
3534
from .blocks import Block, Header, Log, Receipt, Withdrawal, encode_receipt
3635
from .bloom import logs_bloom
@@ -68,9 +67,8 @@
6867
capture_pre_balance,
6968
commit_transaction_frame,
7069
create_child_frame,
71-
get_block_access_index,
70+
filter_net_zero_frame_changes,
7271
increment_block_access_index,
73-
normalize_balance_changes_for_transaction,
7472
track_address,
7573
track_balance_change,
7674
track_nonce_change,
@@ -634,7 +632,7 @@ def process_system_transaction(
634632
"""
635633
# EIP-7928: Create a child frame for system transaction
636634
# This allows proper pre-state capture for net-zero filtering
637-
system_tx_state_changes = create_child_frame(block_env.block_state_changes)
635+
system_tx_state_changes = create_child_frame(block_env.state_changes)
638636

639637
tx_env = vm.TransactionEnvironment(
640638
origin=SYSTEM_ADDRESS,
@@ -671,6 +669,7 @@ def process_system_transaction(
671669
accessed_storage_keys=set(),
672670
disable_precompiles=False,
673671
parent_evm=None,
672+
is_create=False,
674673
state_changes=call_frame,
675674
)
676675

@@ -818,17 +817,17 @@ def apply_body(
818817
# EIP-7928: Increment block frame to post-execution index
819818
# After N transactions, block frame is at index N
820819
# Post-execution operations (withdrawals, etc.) use index N+1
821-
increment_block_access_index(block_env.block_state_changes)
820+
increment_block_access_index(block_env.state_changes)
822821

823822
process_withdrawals(block_env, block_output, withdrawals)
824823

825824
process_general_purpose_requests(
826825
block_env=block_env,
827826
block_output=block_output,
828827
)
829-
# Build block access list from block_env.block_state_changes
828+
# Build block access list from block_env.state_changes
830829
block_output.block_access_list = build_block_access_list(
831-
block_env.block_state_changes
830+
block_env.state_changes
832831
)
833832

834833
return block_output
@@ -911,9 +910,8 @@ def process_transaction(
911910
"""
912911
# EIP-7928: Create a transaction-level StateChanges frame
913912
# The frame will read the current block_access_index from the block frame
914-
increment_block_access_index(block_env.block_state_changes)
915-
tx_state_changes = create_child_frame(block_env.block_state_changes)
916-
block_access_index = get_block_access_index(block_env.block_state_changes)
913+
increment_block_access_index(block_env.state_changes)
914+
tx_state_changes = create_child_frame(block_env.state_changes)
917915

918916
# Capture coinbase pre-balance for net-zero filtering
919917
coinbase_pre_balance = get_account(
@@ -957,9 +955,7 @@ def process_transaction(
957955
# Track sender nonce increment
958956
increment_nonce(block_env.state, sender)
959957
sender_nonce_after = get_account(block_env.state, sender).nonce
960-
track_nonce_change(
961-
tx_state_changes, sender, U64(sender_nonce_after), block_access_index
962-
)
958+
track_nonce_change(tx_state_changes, sender, U64(sender_nonce_after))
963959

964960
# Track sender balance deduction for gas fee
965961
sender_balance_before = get_account(block_env.state, sender).balance
@@ -976,7 +972,6 @@ def process_transaction(
976972
tx_state_changes,
977973
sender,
978974
U256(sender_balance_after_gas_fee),
979-
block_access_index,
980975
)
981976

982977
access_list_addresses = set()
@@ -1052,7 +1047,6 @@ def process_transaction(
10521047
tx_env.state_changes,
10531048
sender,
10541049
sender_balance_after_refund,
1055-
block_access_index,
10561050
)
10571051

10581052
coinbase_balance_after_mining_fee = get_account(
@@ -1066,7 +1060,6 @@ def process_transaction(
10661060
tx_env.state_changes,
10671061
block_env.coinbase,
10681062
coinbase_balance_after_mining_fee,
1069-
block_access_index,
10701063
)
10711064

10721065
if coinbase_balance_after_mining_fee == 0 and account_exists_and_is_empty(
@@ -1095,27 +1088,16 @@ def process_transaction(
10951088
for address in tx_output.accounts_to_delete:
10961089
destroy_account(block_env.state, address)
10971090

1098-
# EIP-7928: Normalize balance changes for this transaction before merging
1099-
# into block frame. Must happen AFTER destroy_account so net-zero filtering
1100-
# sees the correct post-transaction balance (0 for destroyed accounts).
1101-
normalize_balance_changes_for_transaction(
1102-
tx_env.state_changes,
1103-
block_access_index,
1104-
block_env.state,
1105-
)
1091+
# EIP-7928: Filter net-zero changes before committing to block frame.
1092+
# Must happen AFTER destroy_account so filtering sees correct state.
1093+
filter_net_zero_frame_changes(tx_env.state_changes, block_env.state)
11061094

11071095
commit_transaction_frame(tx_env.state_changes)
11081096

11091097
# EIP-7928: Track in-transaction self-destruct normalization AFTER merge
11101098
# Convert storage writes to reads and remove nonce/code changes
11111099
for address in tx_output.accounts_to_delete:
1112-
track_selfdestruct(
1113-
block_env.block_state_changes,
1114-
address,
1115-
BlockAccessIndex(
1116-
get_block_access_index(block_env.block_state_changes)
1117-
),
1118-
)
1100+
track_selfdestruct(block_env.state_changes, address)
11191101

11201102

11211103
def process_withdrawals(
@@ -1126,16 +1108,12 @@ def process_withdrawals(
11261108
"""
11271109
Increase the balance of the withdrawing account.
11281110
"""
1129-
block_access_index = get_block_access_index(block_env.block_state_changes)
1130-
11311111
# Capture pre-state for withdrawal balance filtering
11321112
withdrawal_addresses = {wd.address for wd in withdrawals}
11331113
for address in withdrawal_addresses:
11341114
pre_balance = get_account(block_env.state, address).balance
1135-
track_address(block_env.block_state_changes, address)
1136-
capture_pre_balance(
1137-
block_env.block_state_changes, address, pre_balance
1138-
)
1115+
track_address(block_env.state_changes, address)
1116+
capture_pre_balance(block_env.state_changes, address, pre_balance)
11391117

11401118
def increase_recipient_balance(recipient: Account) -> None:
11411119
recipient.balance += wd.amount * U256(10**9)
@@ -1151,22 +1129,16 @@ def increase_recipient_balance(recipient: Account) -> None:
11511129

11521130
new_balance = get_account(block_env.state, wd.address).balance
11531131
track_balance_change(
1154-
block_env.block_state_changes,
1132+
block_env.state_changes,
11551133
wd.address,
11561134
new_balance,
1157-
block_access_index,
11581135
)
11591136

11601137
if account_exists_and_is_empty(block_env.state, wd.address):
11611138
destroy_account(block_env.state, wd.address)
11621139

1163-
# EIP-7928: Normalize balance changes after all withdrawals
1164-
# Filters out net-zero changes
1165-
normalize_balance_changes_for_transaction(
1166-
block_env.block_state_changes,
1167-
block_access_index,
1168-
block_env.state,
1169-
)
1140+
# EIP-7928: Filter net-zero balance changes for withdrawals
1141+
filter_net_zero_frame_changes(block_env.state_changes, block_env.state)
11701142

11711143

11721144
def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool:

0 commit comments

Comments
 (0)