-
Notifications
You must be signed in to change notification settings - Fork 182
feat(fill): add a plugin for optional execution witness generation #2066
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f67704d
feat(fixtures): add `executionWitness` to `FixtureBlockBase`
danceratopz 3f5be35
feat(fill): add a plugin for execution witness generation
danceratopz 6e4d8ee
feat(fill): use the `generate_witness` fixture in the `filler` plugin
danceratopz c43c1ba
feat(fill,help): enable witness plugin help output to `fill --help`.
danceratopz d2eddbf
chore(fill): fix punctuation in witness plugin help string
danceratopz a2bb2b1
chore(fill): add hotfix to generate_witness for Paris
danceratopz 9be75e8
docs: update changelog
danceratopz 4bb6019
fill: update witness-filler ref as requested by jsign
danceratopz 9de8401
fixtures: change WitnessChunk from dataclass to CamelModel
danceratopz c8d28da
fixtures: rename WitnessChunk json parser helper method
danceratopz 14494fd
fill: add a WitnessFillerResult to validate witness-filler output
danceratopz 7ead93c
refactor(fill): improve `generate_witness` fixture & fork checks
danceratopz bd5c72a
chore(fixtures): remove unncessary pydantic field alias
danceratopz 6c4551a
chore(fill): exit on error if witness-filler is unavailable
danceratopz 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
""" | ||
Pytest plugin for witness functionality. | ||
|
||
Provides --witness command-line option that checks for the witness-filler tool in PATH | ||
and generates execution witness data for blockchain test fixtures when enabled. | ||
""" | ||
|
||
import shutil | ||
import subprocess | ||
from typing import Callable, List | ||
|
||
import pytest | ||
|
||
from ethereum_test_base_types import EthereumTestRootModel | ||
from ethereum_test_fixtures.blockchain import BlockchainFixture, FixtureBlock, WitnessChunk | ||
from ethereum_test_forks import Paris | ||
|
||
|
||
class WitnessFillerResult(EthereumTestRootModel[List[WitnessChunk]]): | ||
"""Model that defines the expected result from the `witness-filler` command.""" | ||
|
||
root: List[WitnessChunk] | ||
|
||
|
||
class Merge(Paris): | ||
""" | ||
Paris fork that serializes as 'Merge' for witness-filler compatibility. | ||
|
||
IMPORTANT: This class MUST be named 'Merge' (not 'MergeForWitness' or similar) | ||
because the class name is used directly in Pydantic serialization, and | ||
witness-filler expects exactly 'Merge' for this fork. | ||
""" | ||
|
||
pass | ||
|
||
|
||
def pytest_addoption(parser: pytest.Parser): | ||
"""Add witness command-line options to pytest.""" | ||
witness_group = parser.getgroup("witness", "Arguments for witness functionality") | ||
witness_group.addoption( | ||
"--witness", | ||
"--witness-the-fitness", | ||
action="store_true", | ||
dest="witness", | ||
default=False, | ||
help=( | ||
"Generate execution witness data for blockchain test fixtures using the " | ||
"witness-filler tool (must be installed separately)." | ||
), | ||
) | ||
|
||
|
||
def pytest_configure(config): | ||
""" | ||
Pytest hook called after command line options have been parsed. | ||
|
||
If --witness is enabled, checks that the witness-filler tool is available in PATH. | ||
""" | ||
if config.getoption("witness"): | ||
# Check if witness-filler binary is available in PATH | ||
if not shutil.which("witness-filler"): | ||
pytest.exit( | ||
"witness-filler tool not found in PATH. Please build and install witness-filler " | ||
"from https://github.com/kevaundray/reth.git before using --witness flag.\n" | ||
"Example: cargo install --git https://github.com/kevaundray/reth.git " | ||
"witness-filler", | ||
1, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def witness_generator( | ||
request: pytest.FixtureRequest, | ||
) -> Callable[[BlockchainFixture], None] | None: | ||
""" | ||
Provide a witness generator function if --witness is enabled. | ||
|
||
Returns: | ||
None if witness functionality is disabled. | ||
Callable that generates witness data for a BlockchainFixture if enabled. | ||
|
||
""" | ||
if not request.config.getoption("witness"): | ||
return None | ||
|
||
def generate_witness(fixture: BlockchainFixture) -> None: | ||
"""Generate witness data for a blockchain fixture using the witness-filler tool.""" | ||
if not isinstance(fixture, BlockchainFixture): | ||
return None | ||
|
||
# Hotfix: witness-filler expects "Merge" but execution-spec-tests uses "Paris" | ||
original_fork = None | ||
if fixture.fork is Paris: | ||
original_fork = fixture.fork | ||
fixture.fork = Merge | ||
|
||
try: | ||
result = subprocess.run( | ||
["witness-filler"], | ||
input=fixture.model_dump_json(by_alias=True), | ||
text=True, | ||
capture_output=True, | ||
) | ||
finally: | ||
if original_fork is not None: | ||
fixture.fork = original_fork | ||
|
||
if result.returncode != 0: | ||
raise RuntimeError( | ||
f"witness-filler tool failed with exit code {result.returncode}. " | ||
f"stderr: {result.stderr}" | ||
) | ||
|
||
try: | ||
result_model = WitnessFillerResult.model_validate_json(result.stdout) | ||
witnesses = result_model.root | ||
|
||
for i, witness in enumerate(witnesses): | ||
if i < len(fixture.blocks): | ||
block = fixture.blocks[i] | ||
if isinstance(block, FixtureBlock): | ||
block.execution_witness = witness | ||
except Exception as e: | ||
raise RuntimeError( | ||
f"Failed to parse witness data from witness-filler tool. " | ||
f"Output was: {result.stdout[:500]}{'...' if len(result.stdout) > 500 else ''}" | ||
) from e | ||
|
||
return generate_witness |
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
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.
Uh oh!
There was an error while loading. Please reload this page.