66 BenchmarkTestFiller ,
77 Fork ,
88 Hash ,
9+ Op ,
910 Transaction ,
1011)
1112
1213from tests .benchmark .stateful .helpers import (
1314 AccountMode ,
1415 account_mode_initcode ,
16+ account_mode_runtime_size ,
1517 pack_transactions_into_blocks ,
1618)
1719
18- RECEIVER_CONTRACT_COUNT = 5
20+ # Distinct contracts deployed per account mode. Sized for the most
21+ # demanding consumer, test_account_access, whose cheapest iteration is
22+ # ~2,691 gas: a 300M block reaches ~111,482 distinct salts, rounded up
23+ # with margin.
24+ RECEIVER_CONTRACT_COUNT = 120_000
1925
2026CONTRACT_MODES = [
2127 AccountMode .EXISTING_CONTRACT_MINIMAL ,
2430 AccountMode .EXISTING_CONTRACT_JUMPDEST ,
2531]
2632
27- # Generous per-deployment gas limit. A max-size contract deposit costs
28- # ~54M under EIP-8037; the single-byte runtime is far cheaper but the
29- # same limit is harmless. Kept well below the block budget so many
30- # deployments pack into one block.
31- DEPLOYMENT_TX_GAS_LIMIT = 80_000_000
33+
34+ def deployment_gas_limit (
35+ fork : Fork , initcode : bytes , runtime_size : int
36+ ) -> int :
37+ """
38+ Return the gas limit for one CREATE2 deployment, derived from the
39+ intrinsic, CREATE2, and code-deposit costs with a small margin.
40+ """
41+ intrinsic = fork .transaction_intrinsic_cost_calculator ()(
42+ calldata = Hash (0 ) + initcode
43+ )
44+ create_cost = Op .CREATE2 (
45+ value = 0 ,
46+ offset = 0 ,
47+ size = len (initcode ),
48+ salt = 0 ,
49+ init_code_size = len (initcode ),
50+ ).gas_cost (fork )
51+ deposit_cost = Op .RETURN (
52+ 0 ,
53+ runtime_size ,
54+ code_deposit_size = runtime_size ,
55+ ).gas_cost (fork )
56+ base = intrinsic + create_cost + deposit_cost
57+ return base + base // 16
3258
3359
3460def test_deploy_existing_contracts (
@@ -43,20 +69,23 @@ def test_deploy_existing_contracts(
4369
4470 Runs once as a global setup before the bloatnet benchmarks; the
4571 transactions intentionally carry no test phase so that the payload
46- pipeline replays them ahead of every scenario. Deployments are
47- packed into blocks up to the block gas budget so each block carries
48- many transactions instead of one .
72+ pipeline replays them ahead of every scenario. Each deployment's
73+ gas limit is computed from its cost, then transactions are packed
74+ into blocks up to the block gas budget .
4975 """
5076 txs = []
5177 for account_mode in CONTRACT_MODES :
5278 initcode = account_mode_initcode (fork , account_mode )
79+ gas_limit = deployment_gas_limit (
80+ fork , initcode , account_mode_runtime_size (fork , account_mode )
81+ )
5382 sender = pre .fund_eoa ()
5483 for salt in range (RECEIVER_CONTRACT_COUNT ):
5584 txs .append (
5685 Transaction (
5786 to = DETERMINISTIC_FACTORY_ADDRESS ,
5887 data = Hash (salt ) + initcode ,
59- gas_limit = DEPLOYMENT_TX_GAS_LIMIT ,
88+ gas_limit = gas_limit ,
6089 sender = sender ,
6190 )
6291 )
0 commit comments