Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "tests/benchmark/stateful/bloatnet/depth_benchmarks/.worst_case_miner"]
path = tests/benchmark/stateful/bloatnet/depth_benchmarks/.worst_case_miner
url = https://github.com/CPerezz/worst_case_miner
branch = master
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class EthrexExceptionMapper(ExceptionMapper):
"""Ethrex exception mapper."""

mapping_substring = {
BlockException.INVALID_GASLIMIT: (
"Gas limit changed more than allowed from the parent"
),
TransactionException.TYPE_3_TX_MAX_BLOB_GAS_ALLOWANCE_EXCEEDED: (
"Exceeded MAX_BLOB_GAS_PER_BLOCK"
),
Expand Down
26 changes: 15 additions & 11 deletions tests/benchmark/compute/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,27 +179,31 @@ def calculate_optimal_input_length(
The optimal input length in bytes that maximizes total work.

"""
gsc = fork.gas_costs()
mem_exp_gas_calculator = fork.memory_expansion_gas_calculator()

precompile_call = Op.POP(
Op.STATICCALL(
gas=Op.GAS,
address=0x01, # Placeholder Address
args_offset=Op.PUSH0,
args_size=Op.PUSH0,
ret_offset=Op.PUSH0,
ret_size=Op.PUSH0,
# gas cost
address_warm=True,
)
)
basic_gas = precompile_call.gas_cost(fork)

max_work = 0
optimal_input_length = 0

for input_length in range(1, 1_000_000, 32):
parameters_gas = (
gsc.G_BASE # PUSH0 = arg offset
+ gsc.G_BASE # PUSH0 = arg size
+ gsc.G_BASE # PUSH0 = arg size
+ gsc.G_VERY_LOW # PUSH0 = arg offset
+ gsc.G_VERY_LOW # PUSHN = address
+ gsc.G_BASE # GAS
)
iteration_gas_cost = (
parameters_gas
basic_gas
+ static_cost # Precompile static cost
+ math.ceil(input_length / 32) * per_word_dynamic_cost
# Precompile dynamic cost
+ gsc.G_BASE # POP
)

# From the available gas, subtract the memory expansion costs
Expand Down
18 changes: 10 additions & 8 deletions tests/benchmark/compute/instruction/test_account_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,19 @@ def test_ext_account_query_cold(

attack_gas_limit = gas_benchmark_value

gas_costs = fork.gas_costs()
intrinsic_gas_cost_calc = fork.transaction_intrinsic_cost_calculator()
cold_account_access_gas = opcode(
0,
# gas accounting
address_warm=False,
).gas_cost(fork)
# For calculation robustness, the calculation below ignores "glue" opcodes
# like PUSH and POP. It should be considered a worst-case number of
# accounts, and a few of them might not be targeted before the attacking
# transaction runs out of gas.
num_target_accounts = (
attack_gas_limit - intrinsic_gas_cost_calc()
) // gas_costs.G_COLD_ACCOUNT_ACCESS
) // cold_account_access_gas

blocks = []
post = {}
Expand All @@ -294,11 +298,9 @@ def test_ext_account_query_cold(
addr_offset = int.from_bytes(pre.fund_eoa(amount=0))

if not absent_accounts:
account_creation_gas = (
gas_costs.G_COLD_ACCOUNT_ACCESS
+ gas_costs.G_CALL_VALUE
+ gas_costs.G_NEW_ACCOUNT
)
account_creation_gas = Op.CALL(
value=1, address_warm=False, account_new=True, value_transfer=True
).gas_cost(fork)
# To avoid brittle/tight gas calculations of glue opcodes, we take
# 90% of the maximum tx capacity. Even if this calculation fails
# in the future, it will be caught by the post-state check.
Expand Down Expand Up @@ -372,7 +374,7 @@ def test_ext_account_query_cold(
with TestPhaseManager.execution():
max_target_per_tx = (
tx_gas_limit - intrinsic_gas_cost_calc()
) // gas_costs.G_COLD_ACCOUNT_ACCESS
) // cold_account_access_gas

num_execution_txs = math.ceil(num_target_accounts / max_target_per_tx)
gas_used = 0
Expand Down
Loading
Loading