-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new(tests): EOF - EIP-663: EXCHANGE opcode (#544)
* new(test): add tests for EOF/EIP-663 DUPN SWAPN * improve code generation * chore(ci): Update workflow actions to use Node.js 20 versions (#527) * chore(ci): Update workflow actions to use Node.js 20 versions. * chore: Add changelog. * Add --traces support to besu (#511) Add support for adding traces to output when using Besu. Signed-off-by: Danno Ferrin <[email protected]> * feat(fw): call `evmone-eofparse` on generated EOF fixtures in fill (#519) Co-authored-by: Dimitry Kh <[email protected]> Co-authored-by: danceratopz <[email protected]> * docs(fix): small fix to tracing report in readme cf #511 (#539) * fix EOF return stack tests The tests were previously corrected against a bug in Besu, Signed-off-by: Danno Ferrin <[email protected]> * EXCHANGE Exercise exchange operation Signed-off-by: Danno Ferrin <[email protected]> * speling Signed-off-by: Danno Ferrin <[email protected]> * move Signed-off-by: Danno Ferrin <[email protected]> * feat(fw): Add EXCHANGE encoder * new(tests): EOF - EIP-663: Invalid container due to invalid exchange --------- Signed-off-by: Danno Ferrin <[email protected]> Co-authored-by: Paweł Bylica <[email protected]> Co-authored-by: spencer <[email protected]> Co-authored-by: Mario Vega <[email protected]> Co-authored-by: Dimitry Kh <[email protected]> Co-authored-by: danceratopz <[email protected]>
- Loading branch information
1 parent
3baf416
commit ddae720
Showing
4 changed files
with
203 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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
118 changes: 118 additions & 0 deletions
118
tests/prague/eip7692_eof_v1/eip663_dupn_swapn_exchange/test_exchange.py
This file contains 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,118 @@ | ||
""" | ||
abstract: Tests [EIP-663: SWAPN, DUPN and EXCHANGE instructions](https://eips.ethereum.org/EIPS/eip-663) | ||
Tests for the EXCHANGE instruction. | ||
""" # noqa: E501 | ||
|
||
import pytest | ||
|
||
from ethereum_test_tools import ( | ||
Account, | ||
Environment, | ||
EOFException, | ||
EOFTestFiller, | ||
StateTestFiller, | ||
TestAddress, | ||
Transaction, | ||
) | ||
from ethereum_test_tools.eof.v1 import Container, Section | ||
from ethereum_test_tools.eof.v1.constants import NON_RETURNING_SECTION | ||
from ethereum_test_tools.vm.opcode import Opcodes as Op | ||
|
||
from ..eip3540_eof_v1.spec import EOF_FORK_NAME | ||
from . import REFERENCE_SPEC_GIT_PATH, REFERENCE_SPEC_VERSION | ||
|
||
REFERENCE_SPEC_GIT_PATH = REFERENCE_SPEC_GIT_PATH | ||
REFERENCE_SPEC_VERSION = REFERENCE_SPEC_VERSION | ||
|
||
|
||
@pytest.mark.valid_from(EOF_FORK_NAME) | ||
def test_exchange_all_valid_immediates( | ||
tx: Transaction, | ||
state_test: StateTestFiller, | ||
): | ||
""" | ||
Test case for all valid EXCHANGE immediates. | ||
""" | ||
n = 256 | ||
s = 34 | ||
values = range(0x3E8, 0x3E8 + s) | ||
|
||
eof_code = Container( | ||
sections=[ | ||
Section.Code( | ||
code=b"".join(Op.PUSH2(v) for v in values) | ||
+ b"".join(Op.EXCHANGE(x) for x in range(0, n)) | ||
+ b"".join((Op.PUSH1(x) + Op.SSTORE) for x in range(0, s)) | ||
+ Op.STOP, | ||
code_inputs=0, | ||
code_outputs=NON_RETURNING_SECTION, | ||
max_stack_height=s + 1, | ||
) | ||
], | ||
) | ||
|
||
pre = { | ||
TestAddress: Account(balance=1_000_000_000), | ||
tx.to: Account(code=eof_code), | ||
} | ||
|
||
# this does the same full-loop exchange | ||
values_rotated = list(range(0x3E8, 0x3E8 + s)) | ||
for e in range(0, n): | ||
a = (e >> 4) + 1 | ||
b = (e & 0x0F) + 1 + a | ||
temp = values_rotated[a] | ||
values_rotated[a] = values_rotated[b] | ||
values_rotated[b] = temp | ||
|
||
post = {tx.to: Account(storage=dict(zip(range(0, s), reversed(values_rotated))))} | ||
|
||
state_test( | ||
env=Environment(), | ||
pre=pre, | ||
post=post, | ||
tx=tx, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"stack_height,x,y", | ||
[ | ||
# 2 and 3 are the lowest valid values for x and y, which translates to a | ||
# zero immediate value. | ||
pytest.param(0, 2, 3, id="stack_height=0_n=1_m=1"), | ||
pytest.param(1, 2, 3, id="stack_height=1_n=1_m=1"), | ||
pytest.param(2, 2, 3, id="stack_height=2_n=1_m=1"), | ||
pytest.param(17, 2, 18, id="stack_height=17_n=1_m=16"), | ||
pytest.param(17, 17, 18, id="stack_height=17_n=16_m=1"), | ||
pytest.param(32, 17, 33, id="stack_height=32_n=16_m=16"), | ||
], | ||
) | ||
@pytest.mark.valid_from(EOF_FORK_NAME) | ||
def test_exchange_all_invalid_immediates( | ||
eof_test: EOFTestFiller, | ||
stack_height: int, | ||
x: int, | ||
y: int, | ||
): | ||
""" | ||
Test case for all invalid EXCHANGE immediates. | ||
""" | ||
eof_code = Container( | ||
sections=[ | ||
Section.Code( | ||
code=b"".join(Op.PUSH2(v) for v in range(stack_height)) | ||
+ Op.EXCHANGE[x, y] | ||
+ Op.POP * stack_height | ||
+ Op.STOP, | ||
code_inputs=0, | ||
code_outputs=NON_RETURNING_SECTION, | ||
max_stack_height=stack_height, | ||
) | ||
], | ||
) | ||
|
||
eof_test( | ||
data=eof_code, | ||
expect_exception=EOFException.STACK_UNDERFLOW, | ||
) |
This file contains 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 |
---|---|---|
|
@@ -180,6 +180,7 @@ hyperledger | |
iat | ||
ignoreRevsFile | ||
img | ||
imm | ||
immediates | ||
incrementing | ||
init | ||
|