Skip to content

Commit

Permalink
convert calldatacopy from yml
Browse files Browse the repository at this point in the history
  • Loading branch information
pacrob committed Jan 10, 2025
1 parent edbace1 commit 96c2be9
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 3 deletions.
3 changes: 3 additions & 0 deletions converted-ethereum-tests.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
([#1056](https://github.com/ethereum/execution-spec-tests/pull/1056))
GeneralStateTests/VMTests/vmTests/calldatacopy.json

([#748](https://github.com/ethereum/execution-spec-tests/pull/748))
GeneralStateTests/stBadOpcode/badOpcodes.json
GeneralStateTests/stBugs/evmBytecode.json
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Test fixtures for use by clients are available for each release on the [Github r
- 🔀 Update EIP-7002 according to [spec updates](https://github.com/ethereum/EIPs/pull/9119) ([#1024](https://github.com/ethereum/execution-spec-tests/pull/1024)).
- 🔀 Update EIP-2935 according to [spec updates](https://github.com/ethereum/EIPs/pull/9144) ([#1046](https://github.com/ethereum/execution-spec-tests/pull/1046))
-[EIP-7691](https://eips.ethereum.org/EIPS/eip-7691) Blob throughput increase tests by parametrization of existing EIP-4844 tests ([#1023](https://github.com/ethereum/execution-spec-tests/pull/1023))
- ✨ Port [calldatacopy test](https://github.com/ethereum/tests/blob/ae4791077e8fcf716136e70fe8392f1a1f1495fb/src/GeneralStateTestsFiller/VMTests/vmTests/calldatacopyFiller.yml) ([#1056](https://github.com/ethereum/execution-spec-tests/pull/1056)).

### 🛠️ Framework

Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ dependencies = [
"pyyaml>=6.0.2,<7",
"types-pyyaml>=6.0.12.20240917,<7",
"pytest-json-report>=1.5.0,<2",
# TODO: bump questionary to a newer release, when it becomes available.
# TODO: bump questionary to a newer release, when it becomes available.
# The current release questionary 2.0.1 requires `prompt_toolkit = ">=2.0,<=3.0.36"`.
# This conflicts with ipython; while not an EEST dependency, ipython a very useful tool:
# https://ethereum.github.io/execution-spec-tests/main/dev/interactive_usage/
"questionary @ git+https://github.com/tmbo/questionary@ff22aeae1cd9c1c734f14329934e349bec7873bc",
"prompt_toolkit>=3.0.48,<4", # ensure we have a new enough version for ipython
"prompt_toolkit>=3.0.48,<4", # ensure we have a new enough version for ipython
]

[project.urls]
Expand Down Expand Up @@ -119,4 +119,4 @@ ignore = ["D205", "D203", "D212", "D415", "C901"]

[tool.mypy]
mypy_path = ["src", "$MYPY_CONFIG_FILE_DIR/stubs"]
plugins = ["pydantic.mypy"]
plugins = ["pydantic.mypy"]
179 changes: 179 additions & 0 deletions tests/frontier/opcodes/test_calldatacopy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
"""test `CALLDATACOPY` opcode."""

from re import M

import pytest

from ethereum_test_forks import Fork
from ethereum_test_forks.forks.forks import Byzantium
from ethereum_test_tools import Account, Alloc, Bytecode, StateTestFiller, Transaction
from ethereum_test_tools.vm.opcode import Opcodes as Op


# @pytest.mark.valid_from("Byzantium")
@pytest.mark.parametrize(
"code,tx_data,code_address_storage,to_address_storage",
[
(
(
Op.CALLDATACOPY(dest_offset=0, offset=1, size=2)
+ Op.SSTORE(key=0x0, value=Op.MLOAD(offset=0))
+ Op.RETURN(offset=0, size=Op.MSIZE)
),
b"\x00",
Account(
storage={0x00: 0x3456000000000000000000000000000000000000000000000000000000000000}
),
Account(
storage={0x00: 0x3456000000000000000000000000000000000000000000000000000000000000}
),
),
(
(
Op.CALLDATACOPY(dest_offset=0, offset=1, size=1)
+ Op.SSTORE(key=0x0, value=Op.MLOAD(offset=0))
+ Op.RETURN(offset=0, size=Op.MSIZE)
),
b"\x01",
Account(
storage={0x00: 0x3400000000000000000000000000000000000000000000000000000000000000},
),
Account(
storage={0x00: 0x3400000000000000000000000000000000000000000000000000000000000000},
),
),
(
(
Op.CALLDATACOPY(dest_offset=0, offset=1, size=0)
+ Op.SSTORE(key=0x0, value=Op.MLOAD(offset=0))
+ Op.RETURN(offset=0, size=Op.MSIZE)
),
b"\x02",
Account(
storage={0x00: 0x00},
),
Account(
storage={0x00: 0x00},
),
),
(
(
Op.CALLDATACOPY(dest_offset=0, offset=0, size=0)
+ Op.SSTORE(key=0x0, value=Op.MLOAD(offset=0))
+ Op.RETURN(offset=0, size=Op.MSIZE)
),
b"\x03",
Account(
storage={0x00: 0x00},
),
Account(
storage={0x00: 0x00},
),
),
(
(
Op.CALLDATACOPY(
dest_offset=0,
offset=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA,
size=0xFF,
)
+ Op.SSTORE(key=0x0, value=Op.MLOAD(offset=0))
+ Op.RETURN(offset=0, size=Op.MSIZE)
),
b"\x04",
Account(storage={0x00: 0x00}),
Account(storage={0x00: 0x00}),
),
(
(
Op.CALLDATACOPY(
dest_offset=0,
offset=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA,
size=0x9,
)
+ Op.SSTORE(key=0x0, value=Op.MLOAD(offset=0))
+ Op.RETURN(offset=0, size=Op.MSIZE)
),
b"\x05",
Account(storage={0x00: 0x00}),
Account(storage={0x00: 0x00}),
),
(
(Op.SSTORE(key=0x1, value=0x1) + Op.PUSH1[0x1] + Op.PUSH1[0x2] + Op.CALLDATACOPY),
b"\x10",
Account(storage={0x01: 0x00}),
None,
),
(
(
Op.JUMP(pc=0x5)
+ Op.JUMPDEST
+ Op.STOP
+ Op.JUMPDEST
+ Op.MSTORE8(offset=0x1F, value=0x42)
+ Op.CALLDATACOPY(dest_offset=0x1F, offset=0x0, size=0x103)
+ Op.MLOAD(offset=0x0)
+ Op.DUP1
+ Op.PUSH1[0x60]
+ Op.JUMPI(pc=0x3, condition=Op.EQ)
+ Op.SSTORE(key=0xFF, value=0xBADC0FFEE)
),
b"\x11",
Account(storage={0xFF: 0xBADC0FFEE}),
None,
),
],
ids=[
"cdc 0 1 2",
"cdc 0 1 1",
"cdc 0 1 0",
"cdc 0 0 0",
"cdc 0 neg6 ff",
"cdc 0 neg6 9",
"underflow",
"sec",
],
)
def test_calldatacopy(
state_test: StateTestFiller,
code: Bytecode,
fork: Fork,
tx_data: bytes,
pre: Alloc,
code_address_storage: Account,
to_address_storage: Account | None,
):
"""
Test `CALLDATACOPY` opcode.
Based on https://github.com/ethereum/tests/blob/ae4791077e8fcf716136e70fe8392f1a1f1495fb/src/GeneralStateTestsFiller/VMTests/vmTests/calldatacopyFiller.ym
"""
code_address = pre.deploy_contract(code)
to = pre.deploy_contract(
code=(
Op.MSTORE(offset=0x0, value=0x1234567890ABCDEF01234567890ABCDEF0)
+ Op.CALL(
0xFFFFFF, Op.ADD(0x1000, Op.CALLDATALOAD(offset=0x4)), 0x0, 0xF, 0x10, 0x20, 0x40
)
+ Op.POP
+ Op.SSTORE(key=0x0, value=Op.MLOAD(offset=0x20))
+ Op.SSTORE(key=0x1, value=Op.MLOAD(offset=0x40))
+ Op.STOP
),
nonce=0,
)

tx = Transaction(
data=tx_data,
gas_limit=0x100_000,
gas_price=0x0A,
protected=fork >= Byzantium,
sender=pre.fund_eoa(),
to=to,
value=0x01,
)
if to_address_storage:
post = {code_address: code_address_storage, to: to_address_storage}
else:
post = {code_address: code_address_storage}
state_test(pre=pre, post=post, tx=tx)

0 comments on commit 96c2be9

Please sign in to comment.