Skip to content
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

convert calldatacopy test #1056

Merged
merged 6 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
176 changes: 176 additions & 0 deletions tests/frontier/opcodes/test_calldatacopy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
"""test `CALLDATACOPY` opcode."""

import pytest

from ethereum_test_forks import Fork
from ethereum_test_forks.forks.forks import Byzantium
pacrob marked this conversation as resolved.
Show resolved Hide resolved
from ethereum_test_tools import Account, Alloc, Bytecode, StateTestFiller, Transaction
from ethereum_test_tools.vm.opcode import Opcodes as Op


@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
)
pacrob marked this conversation as resolved.
Show resolved Hide resolved
+ Op.POP
+ Op.SSTORE(key=0x0, value=Op.MLOAD(offset=0x20))
+ Op.SSTORE(key=0x1, value=Op.MLOAD(offset=0x40))
+ Op.STOP
),
nonce=0,
pacrob marked this conversation as resolved.
Show resolved Hide resolved
)

tx = Transaction(
data=tx_data,
gas_limit=0x100_000_000,
marioevz marked this conversation as resolved.
Show resolved Hide resolved
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)
Loading