-
Notifications
You must be signed in to change notification settings - Fork 129
β¨ feat(tests): zkEVM - Add parametrized opcodes and gas limits #1483
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
Closed
raxhvl
wants to merge
5
commits into
ethereum:jsign-zkvm-bytecode-worstcase
from
raxhvl:jsign-zkvm-bytecode-worstcase
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1e6cade
zkevm: add bytecode worst case
jsign 3a51184
β»οΈ refactor(tests): rename zkevm test
raxhvl cd3229e
β¨ feat(tests): zkevm - extract proofs
raxhvl ad4e4e9
β¨ feat(zkevm): zkevm - proof eater
raxhvl 9668583
β¨ feat: zkevm - nom nom nom
raxhvl 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Tests for zkEVM.""" |
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,126 @@ | ||
""" | ||
A series of stress tests that assess the ability of a specific | ||
opcode or precompile to process large proofs in a block. | ||
|
||
Large proofs are created by deploying contracts with | ||
maximum allowed bytecode. | ||
|
||
Then, a pacman contract (α§β’β’β’) consumes the maximum possible number of | ||
proofs in a block with a given gas limit using an opcode or precompile. | ||
""" | ||
|
||
from dataclasses import dataclass | ||
from typing import Callable | ||
|
||
import pytest | ||
|
||
from ethereum_test_tools import ( | ||
Address, | ||
Alloc, | ||
Block, | ||
BlockchainTestFiller, | ||
Bytecode, | ||
Environment, | ||
Transaction, | ||
) | ||
from ethereum_test_tools.vm.opcode import Opcodes as Op | ||
|
||
REFERENCE_SPEC_GIT_PATH = "TODO" | ||
REFERENCE_SPEC_VERSION = "TODO" | ||
|
||
############################## | ||
# # | ||
# Config # | ||
# # | ||
############################## | ||
MAX_CODE_SIZE = 24 * 1024 # 24 KiB | ||
GAS_LIMITS = [30_000_000, 60_000_000, 100_000_000, 300_000_000] | ||
|
||
|
||
@dataclass | ||
class Consumer: | ||
""" | ||
Consumer configuration for eating proofs. | ||
Each consumer has a specific gas appetite and bytecode. | ||
""" | ||
|
||
opcode: Op | ||
"""The opcode this consumer uses to eat proofs.""" | ||
gas_cost: int | ||
"""The gas appetite for consuming a single proof.""" | ||
generate_bytecode: Callable[[Address], Bytecode] | ||
"""A lambda function that generates the bytecode for the eating proof.""" | ||
|
||
def __str__(self) -> str: | ||
"""Str repr.""" | ||
return f"{self.opcode}" | ||
|
||
def create_pacman(self, pre: Alloc, gas_limit: int) -> Address: | ||
""" | ||
Generate a pacman contract that ingests proofs using this opcode. | ||
α§β’β’β’ nom nom nom. | ||
""" | ||
proof_count = (gas_limit - 21_000) // self.gas_cost | ||
proof_count = 5 # TODO: REMOVE THIS LIMIT | ||
|
||
# Generate proofs | ||
proofs = [ | ||
pre.deploy_contract(code=Op.JUMPDEST * (MAX_CODE_SIZE - 11) + Op.PUSH10(i)) | ||
for i in range(proof_count) | ||
] | ||
|
||
# Generate bytecode using the opcode's configuration | ||
code = sum(self.generate_bytecode(proof) for proof in proofs) | ||
if not code: | ||
raise ValueError("Generated code is empty") | ||
|
||
return pre.deploy_contract(code=code) | ||
|
||
|
||
CONSUMERS = [ | ||
Consumer( | ||
opcode=Op.EXTCODEHASH, | ||
gas_cost=2603, # PUSH20[3] + EXTCODEHASH[2600] | ||
generate_bytecode=lambda proof: Op.EXTCODEHASH(proof), | ||
), | ||
Consumer( | ||
opcode=Op.EXTCODESIZE, | ||
gas_cost=2603, # PUSH20[3] + EXTCODESIZE[2600] | ||
generate_bytecode=lambda proof: Op.EXTCODESIZE(proof), | ||
), | ||
] | ||
|
||
|
||
############################# | ||
# # | ||
# Test Cases # | ||
# # | ||
############################## | ||
@pytest.mark.zkevm | ||
@pytest.mark.valid_from("Cancun") | ||
@pytest.mark.parametrize("gas_limit", GAS_LIMITS) | ||
@pytest.mark.parametrize("consumer", CONSUMERS, ids=str) | ||
def test_via_opcode( | ||
blockchain_test: BlockchainTestFiller, | ||
pre: Alloc, | ||
gas_limit: int, | ||
consumer: Consumer, | ||
): | ||
"""Test zkEVM proof size limits using a specific opcode.""" | ||
tx = Transaction( | ||
to=consumer.create_pacman(pre, gas_limit), | ||
gas_limit=gas_limit, | ||
gas_price=10, | ||
sender=pre.fund_eoa(), | ||
data=[], | ||
value=0, | ||
) | ||
|
||
blockchain_test( | ||
env=Environment(gas_limit=gas_limit), | ||
pre=pre, | ||
post={}, | ||
blocks=[Block(txs=[tx])], | ||
) | ||
|
||
# TODO: Assert that ingestion cost is computed correctly |
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.
opcodes/precompiles wouldn't process proofs.
These tests to be added should be seen as regular blockchain tests that so happen to be edge cases that we want to test in a zkEVM. In that sense, they should not be any different than other blockchain tests
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.
Agreed. These tests are no different. By "process" I mean making these opcode / precompile to take the bytecode as input, nothing more.