-
Notifications
You must be signed in to change notification settings - Fork 176
refactor(benchmark): update to benchmark test wrapper #2160
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
base: main
Are you sure you want to change the base?
refactor(benchmark): update to benchmark test wrapper #2160
Conversation
eb1fc44
to
619f1cf
Compare
41bc03e
to
cc03678
Compare
110d7b6
to
c8fc5fa
Compare
beb239d
to
b51eba1
Compare
pre=pre, | ||
post={}, | ||
tx=tx, | ||
code_generator=JumpLoopGenerator(setup=setup, attack_block=Op.POP(Op.RETURNDATASIZE)), | ||
) | ||
|
||
|
||
def test_worst_returndatasize_zero( |
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.
For test_worst_returndatasize_zero
case, the test implementation has been changed.
In the original version, the logic followed a POP
& PUSH
pattern. This can be refactored so that contract A only calls the RETURNDATASIZE
operation until reaching the max stack size, while contract B repeatedly performs STATICCALLs
to contract A.
In this refactored approach, we can use ExtCallGenerator
as a helper.
Related issue #1968
|
||
state_test( | ||
benchmark_test( | ||
pre=pre, | ||
post={}, | ||
tx=tx, | ||
) | ||
|
||
|
||
def test_worst_keccak( |
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.
For test_worst_keccak
test, the implementation has been changed.
The original pattern:
JUMPDEST
PUSH20 length
loopcode
loopcode
loopcode
POP
PUSH0
JUMP
This could be refactored to the following to avoid additional POP
operations.
PUSH20 length
JUMPDEST
loopcode
loopcode
loopcode
PUSH0
JUMP
And the second pattern follows the JumpLoopGenerator
pattern
@@ -2083,7 +1443,7 @@ def test_worst_jumpdests( | |||
ids=lambda param: "" if isinstance(param, tuple) else param, | |||
) | |||
def test_worst_binop_simple( |
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.
For test_worst_binop_simple
case, the implementation has been changed.
TBD
@@ -2122,35 +1474,21 @@ def test_worst_binop_simple( | |||
|
|||
@pytest.mark.parametrize("opcode", [Op.ISZERO, Op.NOT]) | |||
def test_worst_unop( |
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.
For test_worst_unop
, the test case have been changed in the implementation.
Original pattern:
JUMPDEST
PUSH0
loopcode
loopcode
...
loopcode
POP
PUSH0
JUMP
It is changed to the following and updated to JumpLoopGenerator
helper:
PUSH0
JUMPDEST
loopcode
loopcode
...
loopcode
POP
JUMP
|
||
state_test( | ||
@pytest.mark.parametrize("zero_byte", [True, False]) | ||
def test_block_full_data( |
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.
For test_block_full_data
, its implementation has been updated to apply eip7825 transaction gas limit cap.
) | ||
|
||
|
||
def test_worst_blockhash( |
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.
This implementation has been updated for test_worst_blockhash
.
Optimize the case using the ExtCallGenerator
and upgrade to apply eip7825 transaction gas limit cap.
🗒️ Description
Enhanced Interface
In the original benchmark helpers, the repeated code pattern is structured as:
This PR adds a new cleanup section before each iteration, and the interface change accordingly:
Refactoring target
Updating to benchmark wrapper
JumpLoopGenerator
orExtCodeGenerator
for repeated pattern.Unifying the variable names
setup
for the code pattern before thebytecode
loop (instead ofcode_prefix
,calldata
).attack_block
for the actual benchmark execution pattern (instead ofcode_loop_body
,attack_iter
,code_sequence
,loop_body
,code_segment
,op_sequence
, oriter_block
).cleanup
for the phase after the execution loop (instead ofcode_suffix
,code_loop_footer
).gas_benchmark_value
for the benchmark gas limit (instead ofattack_gas_limit
).tx_gas_limit
for the transaction gas limit cap (instead oftx_gas_limit_cap
) -> this should be avoided as the wrapper automatically handle such scenario.Removing redundant parameters
gas_benchmark_value
as it is configured automaticallyfork
,env
param if not used in functionImplementation Note
Most of the test logic remains the same, but the following cases differ and may be worth a closer look from reviewers.
test_worst_returndatasize_zero
test_worst_keccak
test_worst_binop_simple
test_worst_unop
test_worst_calldatacopy
test_block_full_data
test_worst_blockhash
Some test cases have not been refactored, as they would require significantly more effort and may even need to be rewritten. I suggest skipping these for now and updating them in a separate PR:
test_worst_bytecode_single_opcode
Additionally, some test cases may fail on the Osaka fork:
test_worst_address_state_cold
test_worst_selfdestruct_existing
test_worst_selfdestruct_created
test_worst_selfdestruct_initcode
🔗 Related Issues or PRs
Requires PR #1956 and PR #1945
Relevant discussion: issue #1770
✅ Checklist
tox
checks to avoid unnecessary CI fails, see also Code Standards and Enabling Pre-commit Checks:uvx --with=tox-uv tox -e lint,typecheck,spellcheck,markdownlint
type(scope):
.mkdocs serve
locally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.@ported_from
marker.