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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157 | @pytest.mark.ported_from(
[
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stCreateTest/CREATE_AcreateB_BSuicide_BStoreFiller.json",
],
pr=["https://github.com/ethereum/execution-spec-tests/pull/1867"],
coverage_missed_reason="Converting solidity code result in following "
"opcode not being used: PUSH29, DUP4, DUP8, SWAP2, ISZERO, AND, MUL, DIV, "
"CALLVALUE, EXTCODESIZE. Changed 0x11 address to new address (no check "
"for precompile).",
)
@pytest.mark.valid_from("Frontier")
@pytest.mark.with_all_create_opcodes
@pytest.mark.eels_base_coverage
def test_create_suicide_store(
state_test: StateTestFiller,
fork: Fork,
pre: Alloc,
create_opcode: Op,
) -> None:
"""
Create a dynamic contract that self-destructs, then call it to store some
data and then call it again to return that storage value.
"""
tload_support = fork.valid_opcodes().count(Op.TLOAD)
subcall_storage = 0x12
suicide_initcode: Initcode = Initcode(
deploy_code=Switch(
cases=[
CalldataCase(
value=Operation.SUICIDE,
action=Op.SELFDESTRUCT(pre.nonexistent_account()),
),
CalldataCase(
value=Operation.ADD_STORAGE,
action=Op.SSTORE(1, Op.ADD(Op.SLOAD(1), subcall_storage))
+ (
Op.TSTORE(1, Op.ADD(Op.TLOAD(1), subcall_storage))
if tload_support
else Op.STOP
),
),
CalldataCase(
value=Operation.GET_STORAGE,
action=(
Op.MSTORE(0, Op.ADD(Op.SLOAD(1), Op.TLOAD(1)))
if tload_support
else Op.MSTORE(0, Op.SLOAD(1))
)
+ Op.RETURN(0, 32),
),
],
default_action=None,
)
)
sender = pre.fund_eoa()
expect_post = Storage()
slot_create_result = 0
slot_after_suicide_sstore_return = 1
slot_program_success = 2
create_contract = pre.deploy_contract(
code=Op.CALLDATACOPY(size=Op.CALLDATASIZE())
+ Op.SSTORE(slot_create_result, create_opcode(size=Op.CALLDATASIZE()))
# Put some storage before suicide
+ Op.MSTORE(64, Operation.ADD_STORAGE)
+ Op.CALL(
gas=Op.SUB(Op.GAS, 300_000),
address=Op.SLOAD(slot_create_result),
args_offset=64,
args_size=32,
)
+ Op.MSTORE(64, Operation.SUICIDE)
+ Op.CALL(
gas=Op.SUB(Op.GAS, 300_000),
address=Op.SLOAD(slot_create_result),
args_offset=64,
args_size=32,
)
# Put some storage after suicide
+ Op.MSTORE(64, Operation.ADD_STORAGE)
+ Op.CALL(
gas=Op.SUB(Op.GAS, 300_000),
address=Op.SLOAD(slot_create_result),
args_offset=64,
args_size=32,
)
+ Op.MSTORE(64, Operation.GET_STORAGE)
+ Op.CALL(
gas=Op.SUB(Op.GAS, 300_000),
address=Op.SLOAD(0),
args_offset=64,
args_size=32,
ret_offset=100,
ret_size=32,
)
+ Op.SSTORE(slot_after_suicide_sstore_return, Op.MLOAD(100))
+ Op.SSTORE(slot_program_success, 1)
)
expected_create_address = compute_create_address(
address=create_contract,
nonce=1,
initcode=suicide_initcode,
opcode=create_opcode,
)
expect_post[slot_create_result] = expected_create_address
expect_post[slot_after_suicide_sstore_return] = (
subcall_storage * 2 # added value before and after suicide
+ (subcall_storage * 2 if tload_support else 0) # tload value added
)
expect_post[slot_program_success] = 1
tx = Transaction(
gas_limit=1_000_000,
to=create_contract,
data=suicide_initcode,
sender=sender,
protected=fork.supports_protected_txs(),
)
post = {
create_contract: Account(storage=expect_post),
expected_create_address: Account.NONEXISTENT,
}
state_test(pre=pre, post=post, tx=tx)
|