|
12 | 12 | "args_size",
|
13 | 13 | [0, 2, 16, 33, 257],
|
14 | 14 | )
|
15 |
| -def test_calldataload( |
| 15 | +@pytest.mark.parametrize("calldata_source", ["contract", "tx"]) |
| 16 | +def test_calldatasize( |
16 | 17 | state_test: StateTestFiller,
|
17 | 18 | fork: Fork,
|
18 | 19 | args_size: int,
|
19 | 20 | pre: Alloc,
|
| 21 | + calldata_source: str, |
20 | 22 | ):
|
21 | 23 | """
|
22 | 24 | Test `CALLDATASIZE` opcode.
|
23 | 25 |
|
| 26 | + Tests two scenarios: |
| 27 | + - calldata_source is "contract": CALLDATASIZE reads from calldata passed by another contract |
| 28 | + - calldata_source is "tx": CALLDATASIZE reads directly from transaction calldata |
| 29 | +
|
24 | 30 | Based on https://github.com/ethereum/tests/blob/81862e4848585a438d64f911a19b3825f0f4cd95/src/GeneralStateTestsFiller/VMTests/vmTests/calldatasizeFiller.yml
|
25 | 31 | """
|
26 |
| - address = pre.deploy_contract(Op.SSTORE(key=0x0, value=Op.CALLDATASIZE)) |
27 |
| - |
28 |
| - to = pre.deploy_contract( |
29 |
| - code=( |
30 |
| - Om.MSTORE(b"\x01" * args_size, 0x0) |
31 |
| - + Op.CALL( |
32 |
| - gas=Op.SUB(Op.GAS(), 0x100), |
33 |
| - address=address, |
34 |
| - value=0x0, |
35 |
| - args_offset=0x0, |
36 |
| - args_size=args_size, |
37 |
| - ret_offset=0x0, |
38 |
| - ret_size=0x0, |
| 32 | + contract_address = pre.deploy_contract(Op.SSTORE(key=0x0, value=Op.CALLDATASIZE)) |
| 33 | + calldata = b"\x01" * args_size |
| 34 | + |
| 35 | + if calldata_source == "contract": |
| 36 | + to = pre.deploy_contract( |
| 37 | + code=( |
| 38 | + Om.MSTORE(calldata, 0x0) |
| 39 | + + Op.CALL( |
| 40 | + gas=Op.SUB(Op.GAS(), 0x100), |
| 41 | + address=contract_address, |
| 42 | + value=0x0, |
| 43 | + args_offset=0x0, |
| 44 | + args_size=args_size, |
| 45 | + ret_offset=0x0, |
| 46 | + ret_size=0x0, |
| 47 | + ) |
39 | 48 | )
|
40 | 49 | )
|
41 |
| - ) |
42 |
| - |
43 |
| - tx = Transaction( |
44 |
| - gas_limit=100_000, |
45 |
| - protected=fork >= Byzantium, |
46 |
| - sender=pre.fund_eoa(), |
47 |
| - to=to, |
48 |
| - ) |
49 |
| - post = {address: Account(storage={0x00: args_size})} |
| 50 | + |
| 51 | + tx = Transaction( |
| 52 | + gas_limit=100_000, |
| 53 | + protected=fork >= Byzantium, |
| 54 | + sender=pre.fund_eoa(), |
| 55 | + to=to, |
| 56 | + ) |
| 57 | + |
| 58 | + else: |
| 59 | + tx = Transaction( |
| 60 | + data=calldata, |
| 61 | + gas_limit=100_000, |
| 62 | + protected=fork >= Byzantium, |
| 63 | + sender=pre.fund_eoa(), |
| 64 | + to=contract_address, |
| 65 | + ) |
| 66 | + |
| 67 | + post = {contract_address: Account(storage={0x00: args_size})} |
50 | 68 | state_test(pre=pre, post=post, tx=tx)
|
0 commit comments