23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117 | @pytest.mark.ported_from(
[
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stCreateTest/CREATE_FirstByte_loopFiller.yml",
],
pr=["https://github.com/ethereum/execution-spec-tests/pull/1615"],
coverage_missed_reason=(
"coinbase is deleted in original test (tx.gas_price==env.base_fee), "
"opcodes lt, iszero, jump are no longer used"
),
)
@pytest.mark.valid_from("Frontier")
@pytest.mark.with_all_create_opcodes
@pytest.mark.eels_base_coverage
def test_create_one_byte(
state_test: StateTestFiller,
fork: Fork,
pre: Alloc,
create_opcode: Op,
) -> None:
"""Run create deploys with single bytes for each byte."""
initcode: dict[int, Bytecode] = {}
for byte in range(256):
initcode[byte] = Op.MSTORE8(0, byte) + Op.RETURN(0, 1)
initcode_length = 10
sender = pre.fund_eoa()
expect_post = Storage()
# make a subcontract that deploys code, because deploy 0xef eats ALL gas
create_contract = pre.deploy_contract(
code=Op.MSTORE(0, Op.CALLDATALOAD(0))
+ Op.MSTORE(
32,
create_opcode(offset=32 - initcode_length, size=initcode_length),
)
+ Op.RETURN(32, 32)
)
code = pre.deploy_contract(
nonce=1,
code=Op.MSTORE(0, Op.PUSH32(bytes(initcode[0])))
+ sum(
[
Op.MSTORE8(23, opcode) # correct the deploy byte
+ Op.CALL(
gas=50_000,
address=create_contract,
args_size=32,
ret_offset=32,
ret_size=32,
)
+ Op.POP # remove call result from stack for vm trace files
+ Op.SSTORE(
opcode,
Op.MLOAD(32),
)
for opcode, _ in initcode.items()
],
)
+ Op.SSTORE(256, 1),
)
created_accounts: dict[int, Address] = {}
for opcode, opcode_init in initcode.items():
ef_exception = opcode == 239 and fork >= London
created_accounts[opcode] = compute_create_address(
address=create_contract,
salt=0,
nonce=opcode + 1,
initcode=opcode_init,
opcode=create_opcode,
)
if not ef_exception:
expect_post[opcode] = created_accounts[opcode]
expect_post[256] = 1
tx = Transaction(
gas_limit=14_000_000,
to=code,
data=b"",
nonce=0,
sender=sender,
protected=fork.supports_protected_txs(),
)
post = {
code: Account(storage=expect_post),
}
for opcode, _ in initcode.items():
ef_exception = opcode == 239 and fork >= London
if not ef_exception:
post[created_accounts[opcode]] = Account(
code=bytes.fromhex(f"{opcode:02x}")
)
state_test(env=Environment(), pre=pre, post=post, tx=tx)
|