Skip to content

feat(specs): add max bal item check#2109

Draft
nerolation wants to merge 3 commits intoethereum:forks/amsterdamfrom
nerolation:max-items
Draft

feat(specs): add max bal item check#2109
nerolation wants to merge 3 commits intoethereum:forks/amsterdamfrom
nerolation:max-items

Conversation

@nerolation
Copy link
Contributor

@nerolation nerolation commented Jan 30, 2026

🗒️ Description

Adds a gas limit constraint validation for EIP-7928 block access lists.

It bounds the block access list size based on available gas after accounting for transaction base costs.

Changes:

  • Add BlockAccessListGasLimitExceededError exception
  • Add validate_block_access_list_gas_limit() in block_access_lists/builder.py
  • Call validation after building the BAL in apply_body()

🔗 Related Issues or PRs

ethereum/EIPs#11223

@codecov
Copy link

codecov bot commented Jan 30, 2026

Codecov Report

❌ Patch coverage is 15.78947% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.47%. Comparing base (2c549ce) to head (c7a7974).
⚠️ Report is 57 commits behind head on forks/amsterdam.

Files with missing lines Patch % Lines
...reum/forks/amsterdam/block_access_lists/builder.py 0.00% 14 Missing ⚠️
src/ethereum/forks/amsterdam/exceptions.py 0.00% 1 Missing ⚠️
src/ethereum/forks/amsterdam/fork.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##           forks/amsterdam    #2109      +/-   ##
===================================================
- Coverage            86.07%   85.47%   -0.61%     
===================================================
  Files                  599      599              
  Lines                39472    39489      +17     
  Branches              3780     3781       +1     
===================================================
- Hits                 33977    33754     -223     
- Misses                4862     5102     +240     
  Partials               633      633              
Flag Coverage Δ
unittests 85.47% <15.78%> (-0.61%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nerolation
Copy link
Contributor Author

nerolation commented Feb 16, 2026

Note that the two new constants are from EIP-7002 and EIP-7251.

Copy link
Member

@jochem-brouwer jochem-brouwer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments 😄

)
) * item_cost

if bal_items * item_cost > available_gas + system_allowance:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumes that all bal_items have a cost, but there are also free items, like the sender and receiver address. This will flag BALs which are valid as "too full"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also add tests with BALs near max-size (I think we already have this) to check if clients don't early-reject those because they are too large. We cant create a BAL which has the max size as the hard cap calculation makes some assumptions which are not true in practice (SSTORE/SLOAD without pushing items to stack for instance)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah good point!
I wouldn't say you get the sender and the receiver for free though - there's still the 21k gas costs which is above the 2000. The only truly "free" items are those from system contracts, if I'm not forgetting something here.

We should also add tests with BALs near max-size (I think we already have this) to check if clients don't early-reject those because they are too large. We cant create a BAL which has the max size as the hard cap calculation makes some assumptions which are not true in practice (SSTORE/SLOAD without pushing items to stack for instance)

The goal here was to not create any new practical constrain for block building. This means, as long as there is gas available during builders, we must ensure that the BAL item size isn't hit yet -> thus the very conservate 2000 gas per item + not having the system contract items impact it.
Re tests, yeah, we should definitely have test for this, e.g. create a block that is valid (thus it must obey the max item limit too) but as well have tests with invalid BALs that are slightly over the max-items to make sure those are rejected early on.

len(account.storage_reads) for account in block_access_list
)
total_addresses = len(block_access_list)
bal_items = Uint(total_storage_reads + total_addresses)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

total_storage_reads cost TX_ACCESS_LIST_STORAGE_KEY_COST per item, and for address the param respectively to that for addresses (which is higher). The cost is thus underestimated here (which is fine, because overestimating cost will invalidate blocks faster)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah right - it's a trade-off between simplicity and accuracy. Since this is mainly needed for early rejections of BALs that have way too many items (e.g. 2x what is realistic; those would cause 2x the work which we aren't accounting for when setting the gas limit), to counter DoS, I tend leaning towards simplicity first.

)

# Validate block access list gas limit constraint (EIP-7928)
validate_block_access_list_gas_limit(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the t8n tool be updated to reflect this as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we likely need to add this here so we can test this appropriately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants