Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: factor out a type from access lists #960

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/ethereum/arrow_glacier/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class LegacyTransaction:
s: U256


@slotted_freezable
@dataclass
class Access:
account: Address
slots: Tuple[Bytes32, ...]


@slotted_freezable
@dataclass
class AccessListTransaction:
Expand All @@ -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
Expand All @@ -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
Expand Down
13 changes: 7 additions & 6 deletions src/ethereum/berlin/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down
9 changes: 8 additions & 1 deletion src/ethereum/berlin/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class LegacyTransaction:
s: U256


@slotted_freezable
@dataclass
class Access:
account: Address
slots: Tuple[Bytes32, ...]


@slotted_freezable
@dataclass
class AccessListTransaction:
Expand All @@ -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
Expand Down
13 changes: 7 additions & 6 deletions src/ethereum/cancun/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down
13 changes: 10 additions & 3 deletions src/ethereum/cancun/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
13 changes: 7 additions & 6 deletions src/ethereum/gray_glacier/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down
11 changes: 9 additions & 2 deletions src/ethereum/gray_glacier/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class LegacyTransaction:
s: U256


@slotted_freezable
@dataclass
class Access:
account: Address
slots: Tuple[Bytes32, ...]


@slotted_freezable
@dataclass
class AccessListTransaction:
Expand All @@ -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
Expand All @@ -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
Expand Down
13 changes: 7 additions & 6 deletions src/ethereum/london/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down
11 changes: 9 additions & 2 deletions src/ethereum/london/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class LegacyTransaction:
s: U256


@slotted_freezable
@dataclass
class Access:
account: Address
slots: Tuple[Bytes32, ...]


@slotted_freezable
@dataclass
class AccessListTransaction:
Expand All @@ -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
Expand All @@ -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
Expand Down
13 changes: 7 additions & 6 deletions src/ethereum/paris/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down
11 changes: 9 additions & 2 deletions src/ethereum/paris/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
13 changes: 7 additions & 6 deletions src/ethereum/shanghai/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down
11 changes: 9 additions & 2 deletions src/ethereum/shanghai/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class LegacyTransaction:
s: U256


@slotted_freezable
@dataclass
class Access:
account: Address
slots: Tuple[Bytes32, ...]


@slotted_freezable
@dataclass
class AccessListTransaction:
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading
Loading