Repository navigation
feat(tests): Add EIP-8163 EXTENSION opcode test #3454
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
Open
pdobacz
wants to merge
4
commits into
ethereum:eips/bogota/eip-8163
Choose a base branch
from
monad-developers:eips/bogota/eip-8163
base: eips/bogota/eip-8163
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0c301a2
Add EIP-8163 EXTENSION opcode test support
pdobacz d17daf8
encode the opcode under test with bytes() in the evm_bytes round trip
pdobacz 2a651e5
Address review comments
pdobacz 2dab627
chore(doc): add EIP-8163 EXTENSION opcode to the EVM lists
pdobacz 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| Op.STOP, | ||
| Op.REVERT, | ||
| Op.INVALID, | ||
| Op.EXTENSION, | ||
| Op.JUMP, | ||
| Op.JUMPI, | ||
| } | ||
|
|
||
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
29 changes: 29 additions & 0 deletions
29
packages/testing/src/execution_testing/forks/forks/eips/bogota/eip_8163.py
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,29 @@ | ||
| """ | ||
| EIP-8163: Reserve EXTENSION (0xae) opcode. | ||
|
|
||
| Reserve `EXTENSION` as an extension prefix for EVM chains other than | ||
| Ethereum L1, where it behaves exactly like `INVALID`. | ||
|
|
||
| https://eips.ethereum.org/EIPS/eip-8163 | ||
| """ | ||
|
|
||
| from typing import Callable, Dict | ||
|
|
||
| from execution_testing.vm import OpcodeBase, Opcodes | ||
|
|
||
| from ....base_fork import BaseFork | ||
|
|
||
|
|
||
| class EIP8163(BaseFork): | ||
| """EIP-8163 class.""" | ||
|
|
||
| @classmethod | ||
| def opcode_gas_map( | ||
| cls, | ||
| ) -> Dict[OpcodeBase, int | Callable[[OpcodeBase], int]]: | ||
| """Add EXTENSION, which halts exceptionally like INVALID.""" | ||
| base_map = super(EIP8163, cls).opcode_gas_map() | ||
| return { | ||
| **base_map, | ||
| Opcodes.EXTENSION: 0, | ||
| } |
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 @@ | ||
| """Test cases for EVM functionality introduced in Bogota.""" |
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 [EIP-8163: Reserve EXTENSION (0xae) opcode](https://eips.ethereum.org/EIPS/eip-8163).""" |
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,17 @@ | ||
| """Reference spec for [EIP-8163: Reserve EXTENSION (0xae) opcode](https://eips.ethereum.org/EIPS/eip-8163).""" | ||
|
|
||
| from dataclasses import dataclass | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class ReferenceSpec: | ||
| """Reference specification.""" | ||
|
|
||
| git_path: str | ||
| version: str | ||
|
|
||
|
|
||
| ref_spec_8163 = ReferenceSpec( | ||
| git_path="EIPS/eip-8163.md", | ||
| version="aef32ae28e42ba3a391ed8d991ddf6a68d53c152", | ||
| ) |
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,195 @@ | ||
| """ | ||
| Tests for [EIP-8163: Reserve EXTENSION (0xae) opcode](https://eips.ethereum.org/EIPS/eip-8163). | ||
|
|
||
| EXTENSION behaves exactly like INVALID on chains with no extensions | ||
| defined for it, Ethereum L1 included, and the byte is neutral to | ||
| JUMPDEST analysis everywhere. All assertions here hold on any | ||
| EIP-8163-conformant EVM, including chains that define extensions. | ||
|
|
||
| These tests do not assert the non-existence of extensions that would | ||
| be conformant but are undefined today: there is no way to | ||
| forward-guess under what conditions such an extension would succeed, | ||
| and no point in testing it. | ||
| """ | ||
|
|
||
| import pytest | ||
| from execution_testing import ( | ||
| Account, | ||
| Alloc, | ||
| Bytecode, | ||
| Fork, | ||
| Op, | ||
| StateTestFiller, | ||
| Transaction, | ||
| TransactionReceipt, | ||
| ) | ||
|
|
||
| from .spec import ref_spec_8163 | ||
|
|
||
| REFERENCE_SPEC_GIT_PATH = ref_spec_8163.git_path | ||
| REFERENCE_SPEC_VERSION = ref_spec_8163.version | ||
|
|
||
| pytestmark = pytest.mark.valid_from("EIP8163") | ||
|
|
||
| slot_code_worked = 1 | ||
| value_code_worked = 0x1234 | ||
| value_code_untouched = 0xBA5E | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "opcode,success,all_gas_consumed", | ||
| [ | ||
| pytest.param(Op.EXTENSION, False, True), | ||
| pytest.param(Op.INVALID, False, True), | ||
| pytest.param(Op.REVERT(0, 0), False, False, id="REVERT"), | ||
| pytest.param(Op.JUMPDEST, True, False), | ||
| ], | ||
| ) | ||
| def test_top_level_call( | ||
| state_test: StateTestFiller, | ||
| pre: Alloc, | ||
| fork: Fork, | ||
| opcode: Bytecode, | ||
| success: bool, | ||
| all_gas_consumed: bool, | ||
| ) -> None: | ||
| """ | ||
| Call a contract whose whole code is the single tested byte. | ||
|
|
||
| EXTENSION behaves as INVALID, JUMPDEST as sanity check. | ||
| """ | ||
| contract_address = pre.deploy_contract(code=opcode) | ||
|
|
||
| # One gas more than the code needs, so a normal halt refunds exactly | ||
| # that gas while an exceptional halt consumes it with the rest. | ||
| execution_gas = ( | ||
| fork.transaction_intrinsic_cost_calculator()() + opcode.gas_cost(fork) | ||
| ) | ||
| gas_limit = execution_gas + 1 | ||
| tx = Transaction( | ||
| gas_limit=gas_limit, | ||
| to=contract_address, | ||
| sender=pre.fund_eoa(), | ||
| expected_receipt=TransactionReceipt( | ||
| status=int(success), | ||
| cumulative_gas_used=( | ||
| gas_limit if all_gas_consumed else execution_gas | ||
| ), | ||
| ), | ||
| ) | ||
|
|
||
| state_test(pre=pre, post={}, tx=tx) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "target,valid_jump", | ||
| [ | ||
| pytest.param(Op.JUMPDEST, True), | ||
| pytest.param(Op.PUSH1(0x5B), False, id="push_data_0x5b"), | ||
| ], | ||
| ) | ||
| @pytest.mark.parametrize( | ||
| "following", | ||
| [ | ||
| pytest.param(Bytecode(), id="nothing"), | ||
| Op.STOP, | ||
| Op.ADD, | ||
| Op.JUMPDEST, | ||
| pytest.param(Op.PUSH1(0), id="PUSH1"), | ||
| pytest.param(Op.PUSH32(0), id="PUSH32"), | ||
| Op.EXTENSION, | ||
| Op.SELFDESTRUCT, | ||
| ], | ||
| ) | ||
| def test_jumpdest_analysis_neutrality( | ||
| state_test: StateTestFiller, | ||
| pre: Alloc, | ||
| following: Bytecode, | ||
| target: Bytecode, | ||
| valid_jump: bool, | ||
| ) -> None: | ||
| """ | ||
| Jump over an EXTENSION byte to a destination right behind it. | ||
|
|
||
| JUMPDEST analysis ignores EXTENSION: a JUMPDEST behind EXTENSION | ||
| is a valid destination and a 0x5b held as PUSH1 data behind | ||
| EXTENSION is not. EXTENSION is never executed. Only JUMPDEST, the | ||
| PUSH opcodes and EXTENSION itself matter to the analysis of the | ||
| byte behind EXTENSION; every other byte is data to it. | ||
| """ | ||
| code = ( | ||
| Op.SSTORE(slot_code_worked, value_code_worked) | ||
| + Op.JUMP(pc=Op.PUSH2(data_placeholder="destination")) | ||
| + Op.EXTENSION | ||
| + following | ||
| + target | ||
| ) | ||
| code.substitute(destination=len(code) - 1) | ||
|
|
||
| contract_address = pre.deploy_contract( | ||
| code=code, | ||
| storage={slot_code_worked: value_code_untouched}, | ||
| ) | ||
|
|
||
| tx = Transaction(to=contract_address, sender=pre.fund_eoa()) | ||
|
|
||
| value = value_code_worked if valid_jump else value_code_untouched | ||
| state_test( | ||
| pre=pre, | ||
| post={contract_address: Account(storage={slot_code_worked: value})}, | ||
| tx=tx, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "opcode,success", | ||
| [ | ||
| pytest.param(Op.EXTENSION, False), | ||
| pytest.param(Op.INVALID, False), | ||
| pytest.param(Op.JUMPDEST, True), | ||
| ], | ||
| ) | ||
| @pytest.mark.parametrize( | ||
| "following", | ||
| [ | ||
| pytest.param(bytes([b]), id=f"0x{b:02x}") | ||
| for b in [0x5B, *range(0x60, 0x80)] | ||
| ] | ||
| + [pytest.param(b"", id="nothing")], | ||
| ) | ||
| def test_solo_extension_bytes( | ||
|
pdobacz marked this conversation as resolved.
|
||
| state_test: StateTestFiller, | ||
| pre: Alloc, | ||
| opcode: Op, | ||
| success: bool, | ||
| following: bytes, | ||
| ) -> None: | ||
| """ | ||
| Execute the tested byte followed by a solo 0x5b or 0x60..0x7f | ||
| byte (or nothing), expect it to halt exceptionally always. | ||
|
|
||
| EIP-8163 rules these out as single-byte extension immediates. | ||
| The stack is filled first, so the halt is known not to require an | ||
| empty stack. | ||
|
|
||
| EXTENSION behaves as INVALID, JUMPDEST as sanity check. | ||
| """ | ||
| code = ( | ||
| Op.SSTORE(slot_code_worked, value_code_worked) | ||
| + Op.PUSH1(1) * 256 | ||
| + opcode | ||
| + following | ||
| ) | ||
| contract_address = pre.deploy_contract( | ||
| code=code, | ||
| storage={slot_code_worked: value_code_untouched}, | ||
| ) | ||
|
|
||
| tx = Transaction(to=contract_address, sender=pre.fund_eoa()) | ||
|
|
||
| value = value_code_worked if success else value_code_untouched | ||
| state_test( | ||
| pre=pre, | ||
| post={contract_address: Account(storage={slot_code_worked: value})}, | ||
| tx=tx, | ||
| ) | ||
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.