Skip to content

Commit c5ccd54

Browse files
committed
add stride stale contract storage slots
Signed-off-by: Ignacio Hagopian <[email protected]>
1 parent 06f3ba3 commit c5ccd54

File tree

1 file changed

+74
-4
lines changed

1 file changed

+74
-4
lines changed

tests/verkle/eip7748/modified_accounts.py

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@
3232
[True, False],
3333
)
3434
def test_modified_contract(
35-
blockchain_test: BlockchainTestFiller,
36-
storage_slot_write: int,
37-
tx_send_value: bool,
35+
blockchain_test: BlockchainTestFiller, storage_slot_write: int, tx_send_value: bool
3836
):
3937
"""
4038
Test converting a modified contract where a previous transaction writes to:
@@ -99,4 +97,76 @@ def _convert_modified_account(
9997
gas_price=10,
10098
)
10199

102-
_state_conversion(blockchain_test, pre_state, stride, 1, [ConversionTx(tx, 0)])
100+
_state_conversion(blockchain_test, pre_state, stride, 2, [ConversionTx(tx, 0)])
101+
102+
103+
@pytest.mark.valid_from("EIP6800Transition")
104+
def test_modified_eoa_conversion_units(blockchain_test: BlockchainTestFiller):
105+
"""
106+
Test stale EOA are properly counted as used conversion units.
107+
"""
108+
pre_state = {}
109+
pre_state[TestAddress] = Account(balance=1000000000000000000000)
110+
111+
# TODO(hack): today the testing-framework does not support us signaling that we want to
112+
# put the `ConversionTx(tx, **0**)` at the first block after genesis. To simulate that, we have
113+
# to do this here so we "shift" the target account to the second block in the fork.
114+
# If this is ever supported, remove this.
115+
for i in range(stride):
116+
pre_state[accounts[i]] = Account(balance=100 + 1000 * i)
117+
118+
txs = []
119+
for i in range(stride + 3):
120+
pre_state[accounts[stride + i]] = Account(balance=1_000, nonce=0)
121+
if i < stride:
122+
tx = Transaction(
123+
ty=0x0,
124+
chain_id=0x01,
125+
nonce=i,
126+
to=accounts[stride + i],
127+
value=100,
128+
gas_limit=100_000,
129+
gas_price=10,
130+
)
131+
txs.append(ConversionTx(tx, 0))
132+
133+
_state_conversion(blockchain_test, pre_state, stride, 3, txs)
134+
135+
136+
@pytest.mark.valid_from("EIP6800Transition")
137+
def test_modified_contract_conversion_units(blockchain_test: BlockchainTestFiller):
138+
"""
139+
Test stale contract storage slots are properly counted as used conversion units.
140+
"""
141+
pre_state = {}
142+
pre_state[TestAddress] = Account(balance=1000000000000000000000)
143+
144+
# TODO(hack): today the testing-framework does not support us signaling that we want to
145+
# put the `ConversionTx(tx, **0**)` at the first block after genesis. To simulate that, we have
146+
# to do this here so we "shift" the target account to the second block in the fork.
147+
# If this is ever supported, remove this.
148+
for i in range(stride):
149+
pre_state[accounts[i]] = Account(balance=100 + 1000 * i)
150+
151+
target_account = accounts[stride]
152+
pre_state[target_account] = Account(
153+
balance=1_000,
154+
nonce=0,
155+
code=sum([Op.SSTORE(ss, 10_000 + i) for i, ss in enumerate(range(stride))]),
156+
storage={ss: 100 + i for i, ss in enumerate(range(stride))},
157+
)
158+
for i in range(3):
159+
pre_state[accounts[stride + 1 + i]] = Account(balance=1_000 + i, nonce=0)
160+
161+
# Send tx that writes all existing storage slots.
162+
tx = Transaction(
163+
ty=0x0,
164+
chain_id=0x01,
165+
nonce=0,
166+
to=target_account,
167+
value=100,
168+
gas_limit=100_000,
169+
gas_price=10,
170+
)
171+
172+
_state_conversion(blockchain_test, pre_state, stride, 3, [ConversionTx(tx, 0)])

0 commit comments

Comments
 (0)