-
Notifications
You must be signed in to change notification settings - Fork 480
feat(test-benchmark): add deployment contract script, no-rewind flag #3194
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
Draft
LouisTsai-Csie
wants to merge
4
commits into
ethereum:devnets/glamsterdam/6-benchmarks
Choose a base branch
from
LouisTsai-Csie:full-benchmark-target
base: devnets/glamsterdam/6-benchmarks
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+191
−4
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
tests/benchmark/stateful/bloatnet/test_setup_contracts.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| """Deploy the CREATE2 contracts for benchmarks.""" | ||
|
|
||
| import os | ||
|
|
||
| from execution_testing import ( | ||
| DETERMINISTIC_FACTORY_ADDRESS, | ||
| EOA, | ||
| Account, | ||
| Alloc, | ||
| AuthorizationTuple, | ||
| BenchmarkTestFiller, | ||
| Fork, | ||
| Hash, | ||
| Op, | ||
| Transaction, | ||
| compute_create2_address, | ||
| ) | ||
|
|
||
| from tests.benchmark.helper.account_creator import ( | ||
| AccountCreator, | ||
| AccountMode, | ||
| ) | ||
| from tests.benchmark.helper.account_sender_receiver import ( | ||
| DELEGATE_BASE_KEY, | ||
| ) | ||
| from tests.benchmark.helper.transactions import ( | ||
| pack_transactions_into_blocks, | ||
| ) | ||
| from tests.prague.eip7702_set_code_tx.spec import Spec as Spec7702 | ||
|
|
||
| # Number of CREATE2 receiver contracts deployed per mode. Overridable via | ||
| # BLOATNET_RECEIVER_CONTRACT_COUNT so a smoke/plumbing run (e.g. benchmarkoor | ||
| # pre_runs) can deploy a small set for fast iteration; defaults to the full | ||
| # 100k benchmark set. | ||
| RECEIVER_CONTRACT_COUNT = int( | ||
| os.environ.get("BLOATNET_RECEIVER_CONTRACT_COUNT", "100000") | ||
| ) | ||
|
|
||
| CONTRACT_MODES = [ | ||
| AccountMode.EXISTING_CONTRACT_MINIMAL, | ||
| AccountMode.EXISTING_CONTRACT_SAME_MAX, | ||
| AccountMode.EXISTING_CONTRACT_DIFF_MAX, | ||
| ] | ||
|
|
||
| # Factory-frame and initcode execution costs (CALLDATACOPY, the MCOPY | ||
| # doubling loop, memory expansion) plus CREATE2's 63/64 retention. | ||
| EXECUTION_GAS_BUFFER = 50_000 | ||
|
|
||
|
|
||
| def deployment_gas_limit( | ||
| fork: Fork, initcode: bytes, runtime_size: int | ||
| ) -> int: | ||
| """ | ||
| Return the gas limit for one CREATE2 deployment, derived from the | ||
| intrinsic, CREATE2, and code-deposit costs with a margin for the | ||
| factory and initcode execution. | ||
| """ | ||
| intrinsic = fork.transaction_intrinsic_cost_calculator()( | ||
| calldata=b"\xff" * 32 + initcode | ||
| ) | ||
| create_cost = Op.CREATE2( | ||
| value=0, | ||
| offset=0, | ||
| size=len(initcode), | ||
| salt=0, | ||
| init_code_size=len(initcode), | ||
| ).gas_cost(fork) | ||
| deposit_cost = Op.RETURN( | ||
| 0, | ||
| runtime_size, | ||
| code_deposit_size=runtime_size, | ||
| ).gas_cost(fork) | ||
| base = intrinsic + create_cost + deposit_cost | ||
| return base + base // 16 + EXECUTION_GAS_BUFFER | ||
|
|
||
|
|
||
| def test_deploy_existing_contracts( | ||
| benchmark_test: BenchmarkTestFiller, | ||
| pre: Alloc, | ||
| fork: Fork, | ||
| gas_benchmark_value: int, | ||
| tx_gas_limit: int, | ||
| ) -> None: | ||
| """ | ||
| Deploy the contracts behind the `AccountMode.EXISTING_CONTRACT_*` | ||
| receivers via the deterministic CREATE2 factory. | ||
|
|
||
| Delegate deterministic EOAs to EXISTING_CONTRACT_DIFF_MAX receivers. | ||
| """ | ||
| txs = [] | ||
| post: dict = {} | ||
| for account_mode in CONTRACT_MODES: | ||
| creator = AccountCreator(account_mode) | ||
| initcode = creator.initcode | ||
| gas_limit = deployment_gas_limit(fork, initcode, creator.runtime_size) | ||
| sender = pre.fund_eoa() | ||
| for salt in range(RECEIVER_CONTRACT_COUNT): | ||
| txs.append( | ||
| Transaction( | ||
| to=DETERMINISTIC_FACTORY_ADDRESS, | ||
| data=Hash(salt) + initcode, | ||
| gas_limit=gas_limit, | ||
| sender=sender, | ||
| ) | ||
| ) | ||
| # Nonce 1 at the CREATE2-derived address proves deployment. | ||
| for salt in (0, RECEIVER_CONTRACT_COUNT - 1): | ||
| contract = compute_create2_address( | ||
| address=DETERMINISTIC_FACTORY_ADDRESS, | ||
| salt=salt, | ||
| initcode=initcode, | ||
| ) | ||
| post[contract] = Account(nonce=1) | ||
|
|
||
| # Delegate authority i to the i-th DIFF receiver (EIP-7702). | ||
| delegation_sender = pre.fund_eoa() | ||
| intrinsic = fork.transaction_intrinsic_cost_calculator() | ||
| # DIFF receivers share one initcode; build it once for CREATE2 derivation. | ||
| diff_initcode = AccountCreator( | ||
| AccountMode.EXISTING_CONTRACT_DIFF_MAX | ||
| ).initcode | ||
|
|
||
| base_gas = intrinsic(authorization_list_or_count=0) | ||
| per_auth_gas = intrinsic(authorization_list_or_count=1) - base_gas | ||
| gas_buffer = 100_000 | ||
| auths_per_tx = max( | ||
| 1, (tx_gas_limit - gas_buffer - base_gas) // per_auth_gas | ||
| ) | ||
|
|
||
| for start in range(0, RECEIVER_CONTRACT_COUNT, auths_per_tx): | ||
| count = min(auths_per_tx, RECEIVER_CONTRACT_COUNT - start) | ||
| authorization_list = [] | ||
| for i in range(start, start + count): | ||
| authority = EOA(key=DELEGATE_BASE_KEY + i) | ||
| target = compute_create2_address( | ||
| address=DETERMINISTIC_FACTORY_ADDRESS, | ||
| salt=i, | ||
| initcode=diff_initcode, | ||
| ) | ||
| authorization_list.append( | ||
| AuthorizationTuple(address=target, nonce=0, signer=authority) | ||
| ) | ||
| if i == 0 or i == RECEIVER_CONTRACT_COUNT - 1: | ||
| post[authority] = Account( | ||
| nonce=1, | ||
| code=Spec7702.delegation_designation(target), | ||
| ) | ||
|
|
||
| txs.append( | ||
| Transaction( | ||
| to=delegation_sender, | ||
| gas_limit=( | ||
| intrinsic(authorization_list_or_count=count) + gas_buffer | ||
| ), | ||
| sender=delegation_sender, | ||
| authorization_list=authorization_list, | ||
| ) | ||
| ) | ||
|
|
||
| benchmark_test( | ||
| post=post, | ||
| blocks=pack_transactions_into_blocks(txs, gas_benchmark_value), | ||
| skip_gas_used_validation=True, | ||
| expected_receipt_status=1, | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Iiuc (from the PR description) this test function is not really a test, rather it's a helper that is used to deploy contracts, and then the
--no-reset-between-testsflag is used to run the actual tests. Is this correct?If so, I think there has to be a better way to accomplish this, because we are basically overloading the test function to perform other tasks, rather than describing the test pre-requisites inside of the tests that need them.