Skip to content

feat: add extra sstore benchmark cases#1774

Open
LouisTsai-Csie wants to merge 5 commits intoethereum:forks/amsterdamfrom
LouisTsai-Csie:feat/extra-sstore-benchmark
Open

feat: add extra sstore benchmark cases#1774
LouisTsai-Csie wants to merge 5 commits intoethereum:forks/amsterdamfrom
LouisTsai-Csie:feat/extra-sstore-benchmark

Conversation

@LouisTsai-Csie
Copy link
Collaborator

@LouisTsai-Csie LouisTsai-Csie commented Nov 11, 2025

🗒️ Description

Add extra SSTORE benchmark cases, more details linked in the issue #1755 .

🔗 Related Issues or PRs

Issue #1755

✅ Checklist

  • All: Ran fast tox checks to avoid unnecessary CI fails, see also Code Standards and Enabling Pre-commit Checks:
    uvx tox -e static
  • All: PR title adheres to the repo standard - it will be used as the squash commit message and should start type(scope):.
  • All: Considered adding an entry to CHANGELOG.md.
  • All: Considered updating the online docs in the ./docs/ directory.
  • All: Set appropriate labels for the changes (only maintainers can apply labels).
  • Tests: Ran mkdocs serve locally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.
  • Tests: For PRs implementing a missed test case, update the post-mortem document to add an entry the list.
  • Ported Tests: All converted JSON/YML tests from ethereum/tests or tests/static have been assigned @ported_from marker.

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@LouisTsai-Csie LouisTsai-Csie self-assigned this Nov 11, 2025
@LouisTsai-Csie LouisTsai-Csie added A-test-benchmark Area: execution_testing.benchmark and tests/benchmark P-high C-test Category: test labels Nov 11, 2025
@codecov-commenter
Copy link

codecov-commenter commented Nov 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.33%. Comparing base (d618e52) to head (2fd3875).

Additional details and impacted files
@@               Coverage Diff                @@
##           forks/amsterdam    #1774   +/-   ##
================================================
  Coverage            86.33%   86.33%           
================================================
  Files                  538      538           
  Lines                34557    34557           
  Branches              3222     3222           
================================================
  Hits                 29835    29835           
  Misses                4148     4148           
  Partials               574      574           
Flag Coverage Δ
unittests 86.33% <ø> (ø)

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.

Copy link
Contributor

@spencer-tb spencer-tb left a comment

Choose a reason for hiding this comment

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

Thanks some comments! :)

@LouisTsai-Csie LouisTsai-Csie force-pushed the feat/extra-sstore-benchmark branch 2 times, most recently from 1072748 to 0f4e7eb Compare December 1, 2025 12:49
@SamWilsn SamWilsn changed the base branch from forks/osaka to forks/amsterdam December 16, 2025 18:59
@CPerezz
Copy link
Contributor

CPerezz commented Dec 19, 2025

@LouisTsai-Csie @marioevz should we merge this such that we can start taking metrics for repricings?

@LouisTsai-Csie LouisTsai-Csie force-pushed the feat/extra-sstore-benchmark branch 3 times, most recently from 737f7e3 to e95e45c Compare December 24, 2025 15:06
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, I'll review the final test for SLOAD tomorrow 😄 👍

@LouisTsai-Csie LouisTsai-Csie force-pushed the feat/extra-sstore-benchmark branch from e95e45c to 2fd3875 Compare December 30, 2025 13:24
Copy link
Contributor

@CPerezz CPerezz left a comment

Choose a reason for hiding this comment

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

PR tittle should change to: feat(benchmark): add extra sstore benchmark cases

Some minor things here and there. But looks good overall!

Comment on lines +705 to +712
Benchmark SSTORE instruction with various configurations.

Variants:
- use_access_list: Warm storage slots via access list
- sloads_before_sstore: Number of SLOADs per slot before SSTORE
- num_contracts: Number of contract instances (cold storage writes)
- initial_value/write_value: Storage transitions
(zero_to_zero, zero_to_nonzero, nonzero_to_zero, nonzero_to_nonzero)
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be copy-paste? But the test is about SLOADs and the docstring mentions SSTOREs

Comment on lines +606 to +608
contract_gas_limit = base_gas_per_contract
if contract_idx == len(txs) - 1:
contract_gas_limit += gas_remainder
Copy link
Contributor

Choose a reason for hiding this comment

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

txs is being built, so this is always False initially.

At the point of this check, txs is being populated in the loop, so len(txs) - 1 will always be less than contract_idx on the first iterations. The condition should be:

if contract_idx == num_contracts - 1: is what we should have??

Comment on lines +715 to +716
if storage_keys_set:
slots = {i * incrementer for i in range(num_slots)}
Copy link
Contributor

Choose a reason for hiding this comment

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

If incrementer = 0, all slots collapse to {0}, meaning only 1 slot is accessed regardless of num_slots. Is this the intended behaviour?

Comment on lines +472 to +473
start_marker = 10
end_marker = 30 + (2 if sloads_before_sstore else 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we give const values or add a comment to avoid magic numbers in the test?

Comment on lines +744 to +748
benchmark_test(
pre=pre,
blocks=[Block(txs=[tx])],
skip_gas_used_validation=True,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be healthy to make sure we are indeed reading something? So basically, add a minimal check here? It won't even run on the measured block so should not be an issue.

base_gas_per_contract = min(
tx_gas_limit, gas_benchmark_values // num_contracts
)
gas_remainder = tx_gas_limit % num_contracts
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we do something like this?

Suggested change
gas_remainder = tx_gas_limit % num_contracts
if gas_benchmark_values // num_contracts <= tx_gas_limit:
base_gas_per_contract = gas_benchmark_values // num_contracts
gas_remainder = gas_benchmark_values % num_contracts
else:
base_gas_per_contract = tx_gas_limit
gas_remainder = 0

return setup + loop + cleanup


@pytest.mark.parametrize("slot_count", [50, 100])
Copy link
Member

Choose a reason for hiding this comment

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

I think my main issue with these tests is that they hard-code a number of slots to be accessed and completely disregard gas usage, which makes these tests incompatible with the rest of the benchmarking tests IMO.

Is this a specific requirement for bloatnet or can we scrap this parameter and make the slot count a function of the gas to be used?

benchmark_test: BenchmarkTestFiller,
pre: Alloc,
tx_gas_limit: int,
gas_benchmark_values: int,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
gas_benchmark_values: int,
gas_benchmark_value: int,

pytest.param(0, 0xDEADBEEF, id="zero_to_nonzero"),
pytest.param(0xDEADBEEF, 0, id="nonzero_to_zero"),
pytest.param(0xDEADBEEF, 0xBEEFBEEF, id="nonzero_to_diff"),
pytest.param(0xDEADBEEF, 0xBEEFBEEF, id="nonzero_to_same"),
Copy link
Member

Choose a reason for hiding this comment

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

This writes a different value, not the same value

tx_gas_limit: int,
) -> None:
"""
Benchmark SSTORE instruction with various configurations.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Benchmark SSTORE instruction with various configurations.
Benchmark SLOAD instruction with various configurations.

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

Labels

A-test-benchmark Area: execution_testing.benchmark and tests/benchmark C-test Category: test P-high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants