Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions converted-ethereum-tests.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
([#1236](https://github.com/ethereum/execution-spec-tests/pull/1236))
GeneralStateTests/VMTests/vmTests/calldataload.json
GeneralStateTests/VMTests/vmTests/calldatasize.json
Comment thread
pacrob marked this conversation as resolved.

([#1056](https://github.com/ethereum/execution-spec-tests/pull/1056))
GeneralStateTests/VMTests/vmTests/calldatacopy.json

Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Test fixtures for use by clients are available for each release on the [Github r
### 🧪 Test Cases

- 🔀 Automatically apply the `zkevm` marker to all tests under `./tests/zkevm/` and `./tests/prague/eip2537_bls_12_381_precompiles/` via conftest configuration ([#1534](https://github.com/ethereum/execution-spec-tests/pull/1534)).
- ✨ Port [calldataload](https://github.com/ethereum/tests/blob/ae4791077e8fcf716136e70fe8392f1a1f1495fb/src/GeneralStateTestsFiller/VMTests/vmTests/calldatacopyFiller.yml) and [calldatasize](https://github.com/ethereum/tests/blob/81862e4848585a438d64f911a19b3825f0f4cd95/src/GeneralStateTestsFiller/VMTests/vmTests/calldatasizeFiller.yml) tests ([#1236](https://github.com/ethereum/execution-spec-tests/pull/1236)).

## [v4.4.0](https://github.com/ethereum/execution-spec-tests/releases/tag/v4.4.0) - 2025-04-29

Expand Down
92 changes: 92 additions & 0 deletions tests/frontier/opcodes/test_calldataload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
"""test `CALLDATALOAD` opcode."""

import pytest

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


@pytest.mark.parametrize(
"calldata,calldata_offset,expected_storage",
[
(
b"\x25\x60",
0x0,
0x2560000000000000000000000000000000000000000000000000000000000000,
),
(
b"\xff" * 32 + b"\x23",
0x1,
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF23,
),
(
bytes.fromhex("123456789ABCDEF00000000000000000000000000000000000000000000000000024"),
0x5,
0xBCDEF00000000000000000000000000000000000000000000000000024000000,
),
],
ids=[
"two_bytes",
"word_n_byte",
"34_bytes",
],
)
@pytest.mark.parametrize("calldata_source", ["contract", "tx"])
def test_calldataload(
state_test: StateTestFiller,
calldata: bytes,
calldata_offset: int,
fork: Fork,
pre: Alloc,
expected_storage: Account,
calldata_source: str,
):
"""
Test `CALLDATALOAD` opcode.

Tests two scenarios:
- calldata_source is "contract": CALLDATALOAD reads from calldata passed by another contract
- calldata_source is "tx": CALLDATALOAD reads directly from transaction calldata

Based on https://github.com/ethereum/tests/blob/ae4791077e8fcf716136e70fe8392f1a1f1495fb/src/GeneralStateTestsFiller/VMTests/vmTests/calldatacopyFiller.yml
"""
contract_address = pre.deploy_contract(
Op.SSTORE(0, Op.CALLDATALOAD(offset=calldata_offset)) + Op.STOP,
)

if calldata_source == "contract":
to = pre.deploy_contract(
Om.MSTORE(calldata, 0x0)
+ Op.CALL(
gas=Op.SUB(Op.GAS(), 0x100),
address=contract_address,
value=0x0,
args_offset=0x0,
args_size=len(calldata),
ret_offset=0x0,
ret_size=0x0,
)
+ Op.STOP
)

tx = Transaction(
data=calldata,
gas_limit=100_000,
protected=fork >= Byzantium,
sender=pre.fund_eoa(),
to=to,
)

else:
tx = Transaction(
data=calldata,
gas_limit=100_000,
protected=fork >= Byzantium,
sender=pre.fund_eoa(),
to=contract_address,
)

post = {contract_address: Account(storage={0x00: expected_storage})}
state_test(pre=pre, post=post, tx=tx)
68 changes: 68 additions & 0 deletions tests/frontier/opcodes/test_calldatasize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""test `CALLDATASIZE` opcode."""

import pytest

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


@pytest.mark.parametrize(
"args_size",
[0, 2, 16, 33, 257],
)
@pytest.mark.parametrize("calldata_source", ["contract", "tx"])
def test_calldatasize(
state_test: StateTestFiller,
fork: Fork,
args_size: int,
pre: Alloc,
calldata_source: str,
):
"""
Test `CALLDATASIZE` opcode.

Tests two scenarios:
- calldata_source is "contract": CALLDATASIZE reads from calldata passed by another contract
- calldata_source is "tx": CALLDATASIZE reads directly from transaction calldata

Based on https://github.com/ethereum/tests/blob/81862e4848585a438d64f911a19b3825f0f4cd95/src/GeneralStateTestsFiller/VMTests/vmTests/calldatasizeFiller.yml
"""
contract_address = pre.deploy_contract(Op.SSTORE(key=0x0, value=Op.CALLDATASIZE))
calldata = b"\x01" * args_size

if calldata_source == "contract":
to = pre.deploy_contract(
code=(
Om.MSTORE(calldata, 0x0)
+ Op.CALL(
gas=Op.SUB(Op.GAS(), 0x100),
address=contract_address,
value=0x0,
args_offset=0x0,
args_size=args_size,
ret_offset=0x0,
ret_size=0x0,
)
)
)

tx = Transaction(
gas_limit=100_000,
protected=fork >= Byzantium,
sender=pre.fund_eoa(),
to=to,
)

else:
tx = Transaction(
data=calldata,
gas_limit=100_000,
protected=fork >= Byzantium,
sender=pre.fund_eoa(),
to=contract_address,
)

post = {contract_address: Account(storage={0x00: args_size})}
state_test(pre=pre, post=post, tx=tx)
3 changes: 3 additions & 0 deletions tests/homestead/coverage/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def test_coverage(
+ Op.PUSH2(0x0102)
+ Op.PUSH3(0x010203)
+ Op.PUSH4(0x01020304)
+ Op.PUSH32(0x0101010101010101010101010101010101010101010101010101010101010101)
+ Op.MSTORE8(0x00, 0x01)
+ Op.ADD(0x02, 0x03)
+ Op.POP(0x01)
# lllc tests insert codecopy when using lll(seq())
+ Op.CODECOPY(0, 16, 4),
Expand Down
166 changes: 0 additions & 166 deletions tests/static/state_tests/VMTests/vmTests/calldataloadFiller.yml

This file was deleted.

Loading