diff --git a/src/ethereum/arrow_glacier/transactions.py b/src/ethereum/arrow_glacier/transactions.py index d11bc88219..c2413c7973 100644 --- a/src/ethereum/arrow_glacier/transactions.py +++ b/src/ethereum/arrow_glacier/transactions.py @@ -45,6 +45,13 @@ class LegacyTransaction: s: U256 +@slotted_freezable +@dataclass +class Access: + account: Address + slots: Tuple[Bytes32, ...] + + @slotted_freezable @dataclass class AccessListTransaction: @@ -59,7 +66,7 @@ class AccessListTransaction: to: Union[Bytes0, Address] value: U256 data: Bytes - access_list: Tuple[Tuple[Address, Tuple[Bytes32, ...]], ...] + access_list: Tuple[Access, ...] y_parity: U256 r: U256 s: U256 @@ -80,7 +87,7 @@ class FeeMarketTransaction: to: Union[Bytes0, Address] value: U256 data: Bytes - access_list: Tuple[Tuple[Address, Tuple[Bytes32, ...]], ...] + access_list: Tuple[Access, ...] y_parity: U256 r: U256 s: U256 diff --git a/src/ethereum/berlin/fork.py b/src/ethereum/berlin/fork.py index 720f7e4c8e..4f8e3bf5f3 100644 --- a/src/ethereum/berlin/fork.py +++ b/src/ethereum/berlin/fork.py @@ -687,10 +687,10 @@ def process_transaction( preaccessed_addresses = set() preaccessed_storage_keys = set() if isinstance(tx, AccessListTransaction): - for address, keys in tx.access_list: - preaccessed_addresses.add(address) - for key in keys: - preaccessed_storage_keys.add((address, key)) + for access in tx.access_list: + preaccessed_addresses.add(access.account) + for key in access.slots: + preaccessed_storage_keys.add((access.account, key)) message = prepare_message( sender, @@ -804,9 +804,10 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: access_list_cost = 0 if isinstance(tx, AccessListTransaction): - for _address, keys in tx.access_list: + for access in tx.access_list: access_list_cost += TX_ACCESS_LIST_ADDRESS_COST - access_list_cost += len(keys) * TX_ACCESS_LIST_STORAGE_KEY_COST + slots_cost = len(access.slots) * TX_ACCESS_LIST_STORAGE_KEY_COST + access_list_cost += slots_cost return Uint(TX_BASE_COST + data_cost + create_cost + access_list_cost) diff --git a/src/ethereum/berlin/transactions.py b/src/ethereum/berlin/transactions.py index 19994de100..715f526273 100644 --- a/src/ethereum/berlin/transactions.py +++ b/src/ethereum/berlin/transactions.py @@ -45,6 +45,13 @@ class LegacyTransaction: s: U256 +@slotted_freezable +@dataclass +class Access: + account: Address + slots: Tuple[Bytes32, ...] + + @slotted_freezable @dataclass class AccessListTransaction: @@ -59,7 +66,7 @@ class AccessListTransaction: to: Union[Bytes0, Address] value: U256 data: Bytes - access_list: Tuple[Tuple[Address, Tuple[Bytes32, ...]], ...] + access_list: Tuple[Access, ...] y_parity: U256 r: U256 s: U256 diff --git a/src/ethereum/cancun/fork.py b/src/ethereum/cancun/fork.py index 29ce1958e3..2ae0aea7b5 100644 --- a/src/ethereum/cancun/fork.py +++ b/src/ethereum/cancun/fork.py @@ -754,10 +754,10 @@ def process_transaction( if isinstance( tx, (AccessListTransaction, FeeMarketTransaction, BlobTransaction) ): - for address, keys in tx.access_list: - preaccessed_addresses.add(address) - for key in keys: - preaccessed_storage_keys.add((address, key)) + for access in tx.access_list: + preaccessed_addresses.add(access.account) + for key in access.slots: + preaccessed_storage_keys.add((access.account, key)) message = prepare_message( sender, @@ -849,9 +849,10 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: if isinstance( tx, (AccessListTransaction, FeeMarketTransaction, BlobTransaction) ): - for _address, keys in tx.access_list: + for access in tx.access_list: access_list_cost += TX_ACCESS_LIST_ADDRESS_COST - access_list_cost += len(keys) * TX_ACCESS_LIST_STORAGE_KEY_COST + slots_cost = len(access.slots) * TX_ACCESS_LIST_STORAGE_KEY_COST + access_list_cost += slots_cost return Uint(TX_BASE_COST + data_cost + create_cost + access_list_cost) diff --git a/src/ethereum/cancun/transactions.py b/src/ethereum/cancun/transactions.py index d81d11ed13..0d21184248 100644 --- a/src/ethereum/cancun/transactions.py +++ b/src/ethereum/cancun/transactions.py @@ -27,6 +27,13 @@ TX_ACCESS_LIST_STORAGE_KEY_COST = 1900 +@slotted_freezable +@dataclass +class Access: + account: Address + slots: Tuple[Bytes32, ...] + + @slotted_freezable @dataclass class LegacyTransaction: @@ -59,7 +66,7 @@ class AccessListTransaction: to: Union[Bytes0, Address] value: U256 data: Bytes - access_list: Tuple[Tuple[Address, Tuple[Bytes32, ...]], ...] + access_list: Tuple[Access, ...] y_parity: U256 r: U256 s: U256 @@ -80,7 +87,7 @@ class FeeMarketTransaction: to: Union[Bytes0, Address] value: U256 data: Bytes - access_list: Tuple[Tuple[Address, Tuple[Bytes32, ...]], ...] + access_list: Tuple[Access, ...] y_parity: U256 r: U256 s: U256 @@ -101,7 +108,7 @@ class BlobTransaction: to: Address value: U256 data: Bytes - access_list: Tuple[Tuple[Address, Tuple[Bytes32, ...]], ...] + access_list: Tuple[Access, ...] max_fee_per_blob_gas: U256 blob_versioned_hashes: Tuple[VersionedHash, ...] y_parity: U256 diff --git a/src/ethereum/gray_glacier/fork.py b/src/ethereum/gray_glacier/fork.py index 4a80e96bdb..0ef5648b39 100644 --- a/src/ethereum/gray_glacier/fork.py +++ b/src/ethereum/gray_glacier/fork.py @@ -800,10 +800,10 @@ def process_transaction( preaccessed_addresses = set() preaccessed_storage_keys = set() if isinstance(tx, (AccessListTransaction, FeeMarketTransaction)): - for address, keys in tx.access_list: - preaccessed_addresses.add(address) - for key in keys: - preaccessed_storage_keys.add((address, key)) + for access in tx.access_list: + preaccessed_addresses.add(access.account) + for key in access.slots: + preaccessed_storage_keys.add((access.account, key)) message = prepare_message( sender, @@ -923,9 +923,10 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: access_list_cost = 0 if isinstance(tx, (AccessListTransaction, FeeMarketTransaction)): - for _address, keys in tx.access_list: + for access in tx.access_list: access_list_cost += TX_ACCESS_LIST_ADDRESS_COST - access_list_cost += len(keys) * TX_ACCESS_LIST_STORAGE_KEY_COST + slots_cost = len(access.slots) * TX_ACCESS_LIST_STORAGE_KEY_COST + access_list_cost += slots_cost return Uint(TX_BASE_COST + data_cost + create_cost + access_list_cost) diff --git a/src/ethereum/gray_glacier/transactions.py b/src/ethereum/gray_glacier/transactions.py index d11bc88219..c2413c7973 100644 --- a/src/ethereum/gray_glacier/transactions.py +++ b/src/ethereum/gray_glacier/transactions.py @@ -45,6 +45,13 @@ class LegacyTransaction: s: U256 +@slotted_freezable +@dataclass +class Access: + account: Address + slots: Tuple[Bytes32, ...] + + @slotted_freezable @dataclass class AccessListTransaction: @@ -59,7 +66,7 @@ class AccessListTransaction: to: Union[Bytes0, Address] value: U256 data: Bytes - access_list: Tuple[Tuple[Address, Tuple[Bytes32, ...]], ...] + access_list: Tuple[Access, ...] y_parity: U256 r: U256 s: U256 @@ -80,7 +87,7 @@ class FeeMarketTransaction: to: Union[Bytes0, Address] value: U256 data: Bytes - access_list: Tuple[Tuple[Address, Tuple[Bytes32, ...]], ...] + access_list: Tuple[Access, ...] y_parity: U256 r: U256 s: U256 diff --git a/src/ethereum/london/fork.py b/src/ethereum/london/fork.py index 9aae34f0f0..31560995ee 100644 --- a/src/ethereum/london/fork.py +++ b/src/ethereum/london/fork.py @@ -808,10 +808,10 @@ def process_transaction( preaccessed_addresses = set() preaccessed_storage_keys = set() if isinstance(tx, (AccessListTransaction, FeeMarketTransaction)): - for address, keys in tx.access_list: - preaccessed_addresses.add(address) - for key in keys: - preaccessed_storage_keys.add((address, key)) + for access in tx.access_list: + preaccessed_addresses.add(access.account) + for key in access.slots: + preaccessed_storage_keys.add((access.account, key)) message = prepare_message( sender, @@ -931,9 +931,10 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: access_list_cost = 0 if isinstance(tx, (AccessListTransaction, FeeMarketTransaction)): - for _address, keys in tx.access_list: + for access in tx.access_list: access_list_cost += TX_ACCESS_LIST_ADDRESS_COST - access_list_cost += len(keys) * TX_ACCESS_LIST_STORAGE_KEY_COST + slots_cost = len(access.slots) * TX_ACCESS_LIST_STORAGE_KEY_COST + access_list_cost += slots_cost return Uint(TX_BASE_COST + data_cost + create_cost + access_list_cost) diff --git a/src/ethereum/london/transactions.py b/src/ethereum/london/transactions.py index d11bc88219..c2413c7973 100644 --- a/src/ethereum/london/transactions.py +++ b/src/ethereum/london/transactions.py @@ -45,6 +45,13 @@ class LegacyTransaction: s: U256 +@slotted_freezable +@dataclass +class Access: + account: Address + slots: Tuple[Bytes32, ...] + + @slotted_freezable @dataclass class AccessListTransaction: @@ -59,7 +66,7 @@ class AccessListTransaction: to: Union[Bytes0, Address] value: U256 data: Bytes - access_list: Tuple[Tuple[Address, Tuple[Bytes32, ...]], ...] + access_list: Tuple[Access, ...] y_parity: U256 r: U256 s: U256 @@ -80,7 +87,7 @@ class FeeMarketTransaction: to: Union[Bytes0, Address] value: U256 data: Bytes - access_list: Tuple[Tuple[Address, Tuple[Bytes32, ...]], ...] + access_list: Tuple[Access, ...] y_parity: U256 r: U256 s: U256 diff --git a/src/ethereum/paris/fork.py b/src/ethereum/paris/fork.py index 66e8f6c56b..98e80b43f3 100644 --- a/src/ethereum/paris/fork.py +++ b/src/ethereum/paris/fork.py @@ -594,10 +594,10 @@ def process_transaction( preaccessed_addresses = set() preaccessed_storage_keys = set() if isinstance(tx, (AccessListTransaction, FeeMarketTransaction)): - for address, keys in tx.access_list: - preaccessed_addresses.add(address) - for key in keys: - preaccessed_storage_keys.add((address, key)) + for access in tx.access_list: + preaccessed_addresses.add(access.account) + for key in access.slots: + preaccessed_storage_keys.add((access.account, key)) message = prepare_message( sender, @@ -717,9 +717,10 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: access_list_cost = 0 if isinstance(tx, (AccessListTransaction, FeeMarketTransaction)): - for _address, keys in tx.access_list: + for access in tx.access_list: access_list_cost += TX_ACCESS_LIST_ADDRESS_COST - access_list_cost += len(keys) * TX_ACCESS_LIST_STORAGE_KEY_COST + slots_cost = len(access.slots) * TX_ACCESS_LIST_STORAGE_KEY_COST + access_list_cost += slots_cost return Uint(TX_BASE_COST + data_cost + create_cost + access_list_cost) diff --git a/src/ethereum/paris/transactions.py b/src/ethereum/paris/transactions.py index d11bc88219..712614258b 100644 --- a/src/ethereum/paris/transactions.py +++ b/src/ethereum/paris/transactions.py @@ -27,6 +27,13 @@ TX_ACCESS_LIST_STORAGE_KEY_COST = 1900 +@slotted_freezable +@dataclass +class Access: + account: Address + slots: Tuple[Bytes32, ...] + + @slotted_freezable @dataclass class LegacyTransaction: @@ -59,7 +66,7 @@ class AccessListTransaction: to: Union[Bytes0, Address] value: U256 data: Bytes - access_list: Tuple[Tuple[Address, Tuple[Bytes32, ...]], ...] + access_list: Tuple[Access, ...] y_parity: U256 r: U256 s: U256 @@ -80,7 +87,7 @@ class FeeMarketTransaction: to: Union[Bytes0, Address] value: U256 data: Bytes - access_list: Tuple[Tuple[Address, Tuple[Bytes32, ...]], ...] + access_list: Tuple[Access, ...] y_parity: U256 r: U256 s: U256 diff --git a/src/ethereum/shanghai/fork.py b/src/ethereum/shanghai/fork.py index c713780981..b6708add82 100644 --- a/src/ethereum/shanghai/fork.py +++ b/src/ethereum/shanghai/fork.py @@ -618,10 +618,10 @@ def process_transaction( preaccessed_storage_keys = set() preaccessed_addresses.add(env.coinbase) if isinstance(tx, (AccessListTransaction, FeeMarketTransaction)): - for address, keys in tx.access_list: - preaccessed_addresses.add(address) - for key in keys: - preaccessed_storage_keys.add((address, key)) + for access in tx.access_list: + preaccessed_addresses.add(access.account) + for key in access.slots: + preaccessed_storage_keys.add((access.account, key)) message = prepare_message( sender, @@ -748,9 +748,10 @@ def calculate_intrinsic_cost(tx: Transaction) -> Uint: access_list_cost = 0 if isinstance(tx, (AccessListTransaction, FeeMarketTransaction)): - for _address, keys in tx.access_list: + for access in tx.access_list: access_list_cost += TX_ACCESS_LIST_ADDRESS_COST - access_list_cost += len(keys) * TX_ACCESS_LIST_STORAGE_KEY_COST + slots_cost = len(access.slots) * TX_ACCESS_LIST_STORAGE_KEY_COST + access_list_cost += slots_cost return Uint(TX_BASE_COST + data_cost + create_cost + access_list_cost) diff --git a/src/ethereum/shanghai/transactions.py b/src/ethereum/shanghai/transactions.py index d11bc88219..c2413c7973 100644 --- a/src/ethereum/shanghai/transactions.py +++ b/src/ethereum/shanghai/transactions.py @@ -45,6 +45,13 @@ class LegacyTransaction: s: U256 +@slotted_freezable +@dataclass +class Access: + account: Address + slots: Tuple[Bytes32, ...] + + @slotted_freezable @dataclass class AccessListTransaction: @@ -59,7 +66,7 @@ class AccessListTransaction: to: Union[Bytes0, Address] value: U256 data: Bytes - access_list: Tuple[Tuple[Address, Tuple[Bytes32, ...]], ...] + access_list: Tuple[Access, ...] y_parity: U256 r: U256 s: U256 @@ -80,7 +87,7 @@ class FeeMarketTransaction: to: Union[Bytes0, Address] value: U256 data: Bytes - access_list: Tuple[Tuple[Address, Tuple[Bytes32, ...]], ...] + access_list: Tuple[Access, ...] y_parity: U256 r: U256 s: U256 diff --git a/tests/berlin/test_rlp.py b/tests/berlin/test_rlp.py index b1d7e4e4b7..b13513b4d8 100644 --- a/tests/berlin/test_rlp.py +++ b/tests/berlin/test_rlp.py @@ -4,6 +4,7 @@ from ethereum.base_types import U64, U256, Bytes, Bytes0, Bytes8, Uint from ethereum.berlin.blocks import Block, Header, Log, Receipt from ethereum.berlin.transactions import ( + Access, AccessListTransaction, LegacyTransaction, Transaction, @@ -58,7 +59,10 @@ Bytes0(), U256(4), Bytes(b"bar"), - ((address1, (hash1, hash2)), (address2, tuple())), + ( + Access(account=address1, slots=(hash1, hash2)), + Access(account=address2, slots=tuple()), + ), U256(27), U256(5), U256(6), diff --git a/tests/cancun/test_rlp.py b/tests/cancun/test_rlp.py index 747eeb7e48..f4eac4e2f2 100644 --- a/tests/cancun/test_rlp.py +++ b/tests/cancun/test_rlp.py @@ -4,6 +4,7 @@ from ethereum.base_types import U64, U256, Bytes, Bytes0, Bytes8, Bytes32, Uint from ethereum.cancun.blocks import Block, Header, Log, Receipt, Withdrawal from ethereum.cancun.transactions import ( + Access, AccessListTransaction, FeeMarketTransaction, LegacyTransaction, @@ -59,7 +60,10 @@ Bytes0(), U256(4), Bytes(b"bar"), - ((address1, (hash1, hash2)), (address2, tuple())), + ( + Access(account=address1, slots=(hash1, hash2)), + Access(account=address2, slots=tuple()), + ), U256(27), U256(5), U256(6), @@ -74,7 +78,10 @@ Bytes0(), U256(4), Bytes(b"bar"), - ((address1, (hash1, hash2)), (address2, tuple())), + ( + Access(account=address1, slots=(hash1, hash2)), + Access(account=address2, slots=tuple()), + ), U256(27), U256(5), U256(6), diff --git a/tests/london/test_rlp.py b/tests/london/test_rlp.py index 56f6a4f81c..22bfb5bc38 100644 --- a/tests/london/test_rlp.py +++ b/tests/london/test_rlp.py @@ -5,6 +5,7 @@ from ethereum.crypto.hash import keccak256 from ethereum.london.blocks import Block, Header, Log, Receipt from ethereum.london.transactions import ( + Access, AccessListTransaction, FeeMarketTransaction, LegacyTransaction, @@ -59,7 +60,10 @@ Bytes0(), U256(4), Bytes(b"bar"), - ((address1, (hash1, hash2)), (address2, tuple())), + ( + Access(account=address1, slots=(hash1, hash2)), + Access(account=address2, slots=tuple()), + ), U256(27), U256(5), U256(6), @@ -74,7 +78,10 @@ Bytes0(), U256(4), Bytes(b"bar"), - ((address1, (hash1, hash2)), (address2, tuple())), + ( + Access(account=address1, slots=(hash1, hash2)), + Access(account=address2, slots=tuple()), + ), U256(27), U256(5), U256(6), diff --git a/tests/paris/test_rlp.py b/tests/paris/test_rlp.py index 695f385bd4..ed6a97a8c1 100644 --- a/tests/paris/test_rlp.py +++ b/tests/paris/test_rlp.py @@ -5,6 +5,7 @@ from ethereum.crypto.hash import keccak256 from ethereum.paris.blocks import Block, Header, Log, Receipt from ethereum.paris.transactions import ( + Access, AccessListTransaction, FeeMarketTransaction, LegacyTransaction, @@ -59,7 +60,10 @@ Bytes0(), U256(4), Bytes(b"bar"), - ((address1, (hash1, hash2)), (address2, tuple())), + ( + Access(account=address1, slots=(hash1, hash2)), + Access(account=address2, slots=tuple()), + ), U256(27), U256(5), U256(6), @@ -74,7 +78,10 @@ Bytes0(), U256(4), Bytes(b"bar"), - ((address1, (hash1, hash2)), (address2, tuple())), + ( + Access(account=address1, slots=(hash1, hash2)), + Access(account=address2, slots=tuple()), + ), U256(27), U256(5), U256(6), diff --git a/tests/shanghai/test_rlp.py b/tests/shanghai/test_rlp.py index 2b073783c5..86ddc7a83b 100644 --- a/tests/shanghai/test_rlp.py +++ b/tests/shanghai/test_rlp.py @@ -5,6 +5,7 @@ from ethereum.crypto.hash import keccak256 from ethereum.shanghai.blocks import Block, Header, Log, Receipt, Withdrawal from ethereum.shanghai.transactions import ( + Access, AccessListTransaction, FeeMarketTransaction, LegacyTransaction, @@ -59,7 +60,10 @@ Bytes0(), U256(4), Bytes(b"bar"), - ((address1, (hash1, hash2)), (address2, tuple())), + ( + Access(account=address1, slots=(hash1, hash2)), + Access(account=address2, slots=tuple()), + ), U256(27), U256(5), U256(6), @@ -74,7 +78,10 @@ Bytes0(), U256(4), Bytes(b"bar"), - ((address1, (hash1, hash2)), (address2, tuple())), + ( + Access(account=address1, slots=(hash1, hash2)), + Access(account=address2, slots=tuple()), + ), U256(27), U256(5), U256(6),