Skip to content

Commit 3fb9e89

Browse files
committed
update BAL format
1 parent bff2b67 commit 3fb9e89

File tree

9 files changed

+477
-656
lines changed

9 files changed

+477
-656
lines changed

src/ethereum/osaka/bal_builder.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
CodeChange,
2121
NonceChange,
2222
SlotChanges,
23-
SlotRead,
2423
StorageChange,
2524
)
2625

@@ -124,7 +123,7 @@ def build(self) -> BlockAccessList:
124123
storage_reads = []
125124
for slot in changes['storage_reads']:
126125
if slot not in changes['storage_changes']:
127-
storage_reads.append(SlotRead(slot=slot))
126+
storage_reads.append(slot)
128127

129128
# Sort all changes by tx_index for deterministic encoding
130129
balance_changes = tuple(sorted(changes['balance_changes'], key=lambda x: x.tx_index))
@@ -133,7 +132,7 @@ def build(self) -> BlockAccessList:
133132

134133
# Sort storage changes and reads by slot
135134
storage_changes.sort(key=lambda x: x.slot)
136-
storage_reads.sort(key=lambda x: x.slot)
135+
storage_reads.sort()
137136

138137
# Create account changes object
139138
account_change = AccountChanges(

src/ethereum/osaka/bal_tracker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ def track_balance_change(
8484
"""Track a balance change."""
8585
self.track_address_access(address)
8686

87-
# Convert U256 to 12-byte balance (sufficient for total ETH supply)
88-
balance_bytes = new_balance.to_be_bytes32()[-12:] # Take last 12 bytes
87+
# Convert U256 to 16-byte balance (uint128 - sufficient for total ETH supply)
88+
balance_bytes = new_balance.to_be_bytes32()[-16:] # Take last 16 bytes for uint128
8989
self.bal_builder.add_balance_change(address, self.current_tx_index, balance_bytes)
9090

9191
def track_nonce_change(

src/ethereum/osaka/ssz_types.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
StorageKey = Bytes32
2020
StorageValue = Bytes32
2121
TxIndex = Uint
22-
Balance = U256
22+
Balance = Bytes # uint128 - Post-transaction balance in wei (16 bytes, sufficient for total ETH supply)
2323
Nonce = Uint
2424

2525
# Constants chosen to support a 630m block gas limit
2626
MAX_TXS = 30_000
2727
MAX_SLOTS = 300_000
2828
MAX_ACCOUNTS = 300_000
2929
MAX_CODE_SIZE = 24_576
30+
MAX_CODE_CHANGES = 1
3031

3132

3233
@slotted_freezable
@@ -69,11 +70,6 @@ class SlotChanges:
6970
changes: Tuple[StorageChange, ...]
7071

7172

72-
@slotted_freezable
73-
@dataclass
74-
class SlotRead:
75-
"""Read-only access to a storage slot (no changes)"""
76-
slot: StorageKey
7773

7874

7975
@slotted_freezable
@@ -85,7 +81,7 @@ class AccountChanges:
8581
"""
8682
address: Address
8783
storage_changes: Tuple[SlotChanges, ...]
88-
storage_reads: Tuple[SlotRead, ...]
84+
storage_reads: Tuple[StorageKey, ...]
8985
balance_changes: Tuple[BalanceChange, ...]
9086
nonce_changes: Tuple[NonceChange, ...]
9187
code_changes: Tuple[CodeChange, ...]

src/ethereum/osaka/state.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,12 @@ def increase_nonce(sender: Account) -> None:
599599

600600
modify_state(state, address, increase_nonce)
601601

602-
# Track nonce change for BAL (for ALL accounts, including EOAs)
602+
# Track nonce change for BAL (for ALL accounts and ALL nonce changes)
603+
# This includes:
604+
# - EOA senders (transaction nonce increments)
605+
# - Contracts performing CREATE/CREATE2
606+
# - Deployed contracts
607+
# - EIP-7702 authorities
603608
if bal_tracker is not None:
604609
account = get_account(state, address)
605610
bal_tracker.track_nonce_change(address, account.nonce, state)

src/ethereum/osaka/vm/instructions/system.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def generic_create(
114114
push(evm.stack, U256(0))
115115
return
116116

117-
increment_nonce(evm.message.block_env.state, evm.message.current_target)
117+
increment_nonce(evm.message.block_env.state, evm.message.current_target, evm.message.bal_tracker)
118118

119119
child_message = Message(
120120
block_env=evm.message.block_env,

tests/osaka/run_bal_tests.py

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)