Skip to content
Merged
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
79 changes: 76 additions & 3 deletions EIPS/eip-7981.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Access lists can circumvent [EIP-7623](./eip-7623.md) by filling blocks with unc
| `ACCESS_LIST_NONZERO_BYTE_COST` | `40` | **New in this EIP** |
| `ACCESS_LIST_ZERO_BYTE_COST` | `10` | **New in this EIP** |

Let `access_list_nonzero_bytes` and `access_list_zero_bytes` be the count of non-zero and zero bytes respectively in the serialized access list data (addresses and storage keys).
Let `access_list_nonzero_bytes` and `access_list_zero_bytes` be the count of non-zero and zero bytes respectively in the addresses (20 bytes each) and storage keys (32 bytes each) contained within the access list.


The current formula for access list costs in [EIP-2930](./eip-2930.md) is:
Expand Down Expand Up @@ -59,7 +59,7 @@ access_list_data_cost = (
access_list_cost = standard_access_list_cost + access_list_data_cost
```

Transactions pay both the existing [EIP-2930](./eip-2930.md) functionality costs plus 40 gas per non-zero byte and 10 gas per zero byte for data.
Transactions pay both the existing [EIP-2930](./eip-2930.md) functionality costs plus 40 gas per non-zero byte and 10 gas per zero byte counted across all addresses and storage keys in the access list.

## Rationale

Expand Down Expand Up @@ -88,7 +88,6 @@ This is a backwards incompatible gas repricing that requires a scheduled network

Requires updates to gas estimation in wallets and nodes. Normal usage patterns remain largely unaffected.


## Test Cases

### Case 1: Normal Transaction
Expand Down Expand Up @@ -117,6 +116,80 @@ Requires updates to gas estimation in wallets and nodes. Normal usage patterns r
- New calldata cost: Applied through [EIP-7623](./eip-7623.md) mechanism
- Result: Can no longer circumvent [EIP-7623](./eip-7623.md) floor pricing


## Reference Implementation

The following is the EELS (Ethereum Execution Layer Specification) implementation:

```python
TX_ACCESS_LIST_NONZERO_BYTE_COST = Uint(40)
TX_ACCESS_LIST_ZERO_BYTE_COST = Uint(10)

def count_access_list_bytes(access_list: Tuple[Access, ...]) -> Tuple[int, int]:
"""
Count zero and non-zero bytes in access list addresses and storage keys.

Returns a tuple of (zero_bytes, nonzero_bytes).
"""
zero_bytes = 0
nonzero_bytes = 0

for access in access_list:
# Count bytes in address (20 bytes)
for byte in access.account:
if byte == 0:
zero_bytes += 1
else:
nonzero_bytes += 1

# Count bytes in storage keys (32 bytes each)
for slot in access.slots:
for byte in slot:
if byte == 0:
zero_bytes += 1
else:
nonzero_bytes += 1

return zero_bytes, nonzero_bytes

def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]:
"""
Calculates the gas that is charged before execution is started.
"""
# ... existing calldata and base cost calculations ...

access_list_cost = Uint(0)
access_list_data_cost = Uint(0)

if isinstance(tx, (AccessListTransaction, FeeMarketTransaction,
BlobTransaction, SetCodeTransaction)):
# Standard EIP-2930 access list functionality costs
for access in tx.access_list:
access_list_cost += TX_ACCESS_LIST_ADDRESS_COST
access_list_cost += (
ulen(access.slots) * TX_ACCESS_LIST_STORAGE_KEY_COST
)

# EIP-7981: Additional data cost for access list bytes
zero_bytes, nonzero_bytes = count_access_list_bytes(tx.access_list)
access_list_data_cost = (
Uint(zero_bytes) * TX_ACCESS_LIST_ZERO_BYTE_COST +
Uint(nonzero_bytes) * TX_ACCESS_LIST_NONZERO_BYTE_COST
)

return (
Uint(
TX_BASE_COST
+ data_cost
+ create_cost
+ access_list_cost
+ access_list_data_cost # Added by EIP-7981
+ auth_cost
),
calldata_floor_gas_cost,
)
```

## Security Considerations

Reduces maximum block size from access lists, improving network stability. The additional cost is proportional to data usage while maintaining access list utility for backwards compatibility.
Expand Down
Loading