|
33 | 33 | "34_bytes", |
34 | 34 | ], |
35 | 35 | ) |
| 36 | +@pytest.mark.parametrize("calldata_source", ["contract", "tx"]) |
36 | 37 | def test_calldataload( |
37 | 38 | state_test: StateTestFiller, |
38 | 39 | calldata: bytes, |
39 | 40 | calldata_offset: int, |
40 | 41 | fork: Fork, |
41 | 42 | pre: Alloc, |
42 | 43 | expected_storage: Account, |
| 44 | + calldata_source: str, |
43 | 45 | ): |
44 | 46 | """ |
45 | 47 | Test `CALLDATALOAD` opcode. |
46 | 48 |
|
| 49 | + Tests two scenarios: |
| 50 | + - calldata_source is "contract": CALLDATALOAD reads from calldata passed by another contract |
| 51 | + - calldata_source is "tx": CALLDATALOAD reads directly from transaction calldata |
| 52 | +
|
47 | 53 | Based on https://github.com/ethereum/tests/blob/ae4791077e8fcf716136e70fe8392f1a1f1495fb/src/GeneralStateTestsFiller/VMTests/vmTests/calldatacopyFiller.yml |
48 | 54 | """ |
49 | | - address_a = pre.deploy_contract( |
| 55 | + contract_address = pre.deploy_contract( |
50 | 56 | Op.SSTORE(0, Op.CALLDATALOAD(offset=calldata_offset)) + Op.STOP, |
51 | 57 | ) |
52 | 58 |
|
53 | | - to = pre.deploy_contract( |
54 | | - Om.MSTORE(calldata, 0x0) |
55 | | - + Op.CALL( |
56 | | - gas=Op.SUB(Op.GAS(), 0x100), |
57 | | - address=address_a, |
58 | | - value=0x0, |
59 | | - args_offset=0x0, |
60 | | - args_size=len(calldata), |
61 | | - ret_offset=0x0, |
62 | | - ret_size=0x0, |
| 59 | + if calldata_source == "contract": |
| 60 | + to = pre.deploy_contract( |
| 61 | + Om.MSTORE(calldata, 0x0) |
| 62 | + + Op.CALL( |
| 63 | + gas=Op.SUB(Op.GAS(), 0x100), |
| 64 | + address=contract_address, |
| 65 | + value=0x0, |
| 66 | + args_offset=0x0, |
| 67 | + args_size=len(calldata), |
| 68 | + ret_offset=0x0, |
| 69 | + ret_size=0x0, |
| 70 | + ) |
| 71 | + + Op.STOP |
| 72 | + ) |
| 73 | + |
| 74 | + tx = Transaction( |
| 75 | + data=calldata, |
| 76 | + gas_limit=100_000, |
| 77 | + protected=fork >= Byzantium, |
| 78 | + sender=pre.fund_eoa(), |
| 79 | + to=to, |
| 80 | + ) |
| 81 | + |
| 82 | + else: |
| 83 | + tx = Transaction( |
| 84 | + data=calldata, |
| 85 | + gas_limit=100_000, |
| 86 | + protected=fork >= Byzantium, |
| 87 | + sender=pre.fund_eoa(), |
| 88 | + to=contract_address, |
63 | 89 | ) |
64 | | - + Op.STOP |
65 | | - ) |
66 | 90 |
|
67 | | - tx = Transaction( |
68 | | - data=calldata, |
69 | | - gas_limit=100_000, |
70 | | - protected=fork >= Byzantium, |
71 | | - sender=pre.fund_eoa(), |
72 | | - to=to, |
73 | | - ) |
74 | 91 | post = { |
75 | | - address_a: Account(storage={0x00: expected_storage}), |
| 92 | + contract_address: Account(storage={0x00: expected_storage}), |
76 | 93 | } |
77 | 94 | state_test(pre=pre, post=post, tx=tx) |
0 commit comments