Skip to content

Commit 4221724

Browse files
committed
Ported static without hardcoded addresses
1 parent cc21e89 commit 4221724

2,156 files changed

Lines changed: 24332 additions & 37472 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

scripts/filler_to_python/analyzer.py

Lines changed: 302 additions & 41 deletions
Large diffs are not rendered by default.

scripts/filler_to_python/ir.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class AccountIR:
3636
code_expr: str = ""
3737
storage: dict = field(default_factory=dict)
3838
oversized_code: bool = False
39+
use_dynamic: bool = True
3940

4041

4142
@dataclass
@@ -80,6 +81,7 @@ class AccessListEntryIR:
8081

8182
address: str = ""
8283
storage_keys: list = field(default_factory=list)
84+
use_dynamic: bool = False
8385

8486

8587
@dataclass
@@ -108,7 +110,9 @@ class SenderIR:
108110
is_tagged: bool = False
109111
key: int | None = None
110112
balance: int = 0
113+
nonce: int | None = None
111114
not_in_pre: bool = False
115+
use_dynamic: bool = True
112116

113117

114118
@dataclass

scripts/filler_to_python/render.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ def format_storage(d: dict) -> str:
4242
return "{}"
4343
items = []
4444
for k in sorted(d.keys()):
45-
items.append(f"{format_int(k)}: {format_int(d[k])}")
45+
v = d[k]
46+
if isinstance(v, str):
47+
items.append(f"{format_int(k)}: {v}")
48+
else:
49+
items.append(f"{format_int(k)}: {format_int(v)}")
4650
single = "{" + ", ".join(items) + "}"
4751
if len(single) <= 50:
4852
return single

scripts/filler_to_python/templates/state_test.py.j2

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,13 @@ def {{ test_name }}(
176176
{% for addr in address_constants %}
177177
{{ addr.var_name }} = Address({{ addr.hex }})
178178
{% endfor %}
179-
{% if sender.not_in_pre %}
179+
{% if sender.use_dynamic %}
180+
{% if sender.nonce %}
181+
sender = pre.fund_eoa(amount={{ sender.balance | format_int }}, nonce={{ sender.nonce }})
182+
{% else %}
183+
sender = pre.fund_eoa(amount={{ sender.balance | format_int }})
184+
{% endif %}
185+
{% elif sender.not_in_pre %}
180186
sender = pre.fund_eoa(amount=0)
181187
{% else %}
182188
sender = EOA(
@@ -205,15 +211,19 @@ def {{ test_name }}(
205211

206212
{# Pre-state account setup #}
207213
{% for account in accounts %}
208-
{% if account.is_sender %}
214+
{% if account.is_sender and sender.use_dynamic %}
215+
{# Sender balance already set via pre.fund_eoa() above #}
216+
{% elif account.is_sender %}
209217
pre[sender] = Account(balance={{ account.balance | format_int }}{{ ", nonce=%d" | format(account.nonce) if account.nonce }}{{ ", storage=%s" | format(account.storage | format_storage) if account.storage }}{{ ", code=%s" | format(account.code_expr | wrap_op_chain(indent=8)) if account.code_expr }})
218+
{% elif account.is_eoa and account.use_dynamic %}
219+
{{ account.var_name }} = pre.fund_eoa(amount={{ account.balance | format_int }})
210220
{% elif account.is_eoa %}
211221
pre[{{ account.var_name }}] = Account(balance={{ account.balance | format_int }}{{ ", nonce=%d" | format(account.nonce) if account.nonce }}{{ ", storage=%s" | format(account.storage | format_storage) if account.storage }}{{ ", code=%s" | format(account.code_expr | wrap_op_chain(indent=8)) if account.code_expr }})
212222
{% else %}
213223
{# Contract: source comment + deploy #}
214224
{{ account.source_comment }}
215225
{% if account.oversized_code %}
216-
{{ account.var_name }} = Address({{ account.address }})
226+
{{ account.var_name }} = Address({{ account.address }}) # oversized contract
217227
pre[{{ account.var_name }}] = Account(
218228
code={{ account.code_expr | wrap_op_chain(indent=8) }},
219229
{% if account.storage %}
@@ -238,7 +248,9 @@ def {{ test_name }}(
238248
{% if account.nonce is not none %}
239249
nonce={{ account.nonce }},
240250
{% endif %}
251+
{% if not account.use_dynamic %}
241252
address=Address({{ account.address }}), # noqa: E501
253+
{% endif %}
242254
)
243255
{% endif %}
244256
{% endif %}
@@ -287,7 +299,11 @@ def {{ test_name }}(
287299
{{ d_idx }}: [
288300
{% for al in al_entries %}
289301
AccessList(
302+
{% if al.use_dynamic %}
303+
address={{ al.address }},
304+
{% else %}
290305
address=Address({{ al.address }}),
306+
{% endif %}
291307
storage_keys=[
292308
{% for sk in al.storage_keys %}
293309
Hash("{{ sk }}"), # noqa: E501
@@ -357,7 +373,11 @@ def {{ test_name }}(
357373
access_list=[
358374
{% for al in tx.access_list %}
359375
AccessList(
376+
{% if al.use_dynamic %}
377+
address={{ al.address }},
378+
{% else %}
360379
address=Address({{ al.address }}),
380+
{% endif %}
361381
storage_keys=[
362382
{% for sk in al.storage_keys %}
363383
Hash(
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
# Verify that filler_to_python with dynamic addresses produces
3+
# trace-equivalent tests. Assumes output/traces_baseline/ already
4+
# exists (generated once before any code changes).
5+
set -euo pipefail
6+
7+
export TMPDIR=./.tmp
8+
mkdir -p "$TMPDIR" output/traces_new
9+
10+
if [ ! -d "output/traces_baseline" ]; then
11+
echo "ERROR: output/traces_baseline/ not found."
12+
echo "Generate baseline first (before code changes):"
13+
echo " TMPDIR=./.tmp uv run fill tests/ported_static/ --evm-dump-dir output/traces_baseline -n 10 -m 'not slow'"
14+
exit 1
15+
fi
16+
17+
# Step 1: Run filler_to_python (overwrites tests/ported_static/)
18+
echo "=== Step 1: Running filler_to_python ==="
19+
uv run python -m scripts.filler_to_python \
20+
--fillers tests/static/static/state_tests/ \
21+
--output tests/ported_static/
22+
23+
# Step 2: Fill new tests + verify against baseline
24+
echo "=== Step 2: Filling new tests and verifying traces ==="
25+
uv run fill \
26+
tests/ported_static/ \
27+
--evm-dump-dir output/traces_new \
28+
--verify-traces output/traces_baseline \
29+
--verify-traces-comparator exact-no-stack \
30+
-n 10 \
31+
-m "not slow"
32+
33+
echo "=== Done. Check output above for trace mismatches ==="
34+
echo "=== Use 'git diff tests/ported_static/' to see code changes ==="

tests/ported_static/stArgsZeroOneBalance/test_add_non_const.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import pytest
99
from execution_testing import (
10-
EOA,
1110
Account,
1211
Address,
1312
Alloc,
@@ -58,9 +57,7 @@ def test_add_non_const(
5857
) -> None:
5958
"""Test_add_non_const."""
6059
coinbase = Address(0x2ADC25665018AA1FE0E6BC666DAC8FC2697FF9BA)
61-
sender = EOA(
62-
key=0xB1F4CBC3A50042184425A6F9E996D0910F7BA879457CE5DAC5C71E498AD3C005
63-
)
60+
sender = pre.fund_eoa(amount=0xDE0B6B3A7640000)
6461

6562
env = Environment(
6663
fee_recipient=coinbase,
@@ -85,7 +82,6 @@ def test_add_non_const(
8582
nonce=0,
8683
address=Address(0xF1722FE346FA35E045DE07E47CF6AF9BAE8ADE0A), # noqa: E501
8784
)
88-
pre[sender] = Account(balance=0xDE0B6B3A7640000)
8985

9086
expect_entries_: list[dict] = [
9187
{

tests/ported_static/stArgsZeroOneBalance/test_addmod_non_const.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import pytest
99
from execution_testing import (
10-
EOA,
1110
Account,
1211
Address,
1312
Alloc,
@@ -58,9 +57,7 @@ def test_addmod_non_const(
5857
) -> None:
5958
"""Test_addmod_non_const."""
6059
coinbase = Address(0x2ADC25665018AA1FE0E6BC666DAC8FC2697FF9BA)
61-
sender = EOA(
62-
key=0xB1F4CBC3A50042184425A6F9E996D0910F7BA879457CE5DAC5C71E498AD3C005
63-
)
60+
sender = pre.fund_eoa(amount=0xDE0B6B3A7640000)
6461

6562
env = Environment(
6663
fee_recipient=coinbase,
@@ -86,7 +83,6 @@ def test_addmod_non_const(
8683
nonce=0,
8784
address=Address(0x92D2FC80312ACD8C37857696D2224AF18CE6F966), # noqa: E501
8885
)
89-
pre[sender] = Account(balance=0xDE0B6B3A7640000)
9086

9187
expect_entries_: list[dict] = [
9288
{

tests/ported_static/stArgsZeroOneBalance/test_and_non_const.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import pytest
99
from execution_testing import (
10-
EOA,
1110
Account,
1211
Address,
1312
Alloc,
@@ -58,9 +57,7 @@ def test_and_non_const(
5857
) -> None:
5958
"""Test_and_non_const."""
6059
coinbase = Address(0x2ADC25665018AA1FE0E6BC666DAC8FC2697FF9BA)
61-
sender = EOA(
62-
key=0xB1F4CBC3A50042184425A6F9E996D0910F7BA879457CE5DAC5C71E498AD3C005
63-
)
60+
sender = pre.fund_eoa(amount=0xDE0B6B3A7640000)
6461

6562
env = Environment(
6663
fee_recipient=coinbase,
@@ -85,7 +82,6 @@ def test_and_non_const(
8582
nonce=0,
8683
address=Address(0x4C26357E0D164B702BCEB18690FC742EE1D36913), # noqa: E501
8784
)
88-
pre[sender] = Account(balance=0xDE0B6B3A7640000)
8985

9086
expect_entries_: list[dict] = [
9187
{

tests/ported_static/stArgsZeroOneBalance/test_balance_non_const.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import pytest
99
from execution_testing import (
10-
EOA,
1110
Account,
1211
Address,
1312
Alloc,
@@ -58,9 +57,7 @@ def test_balance_non_const(
5857
) -> None:
5958
"""Test_balance_non_const."""
6059
coinbase = Address(0x2ADC25665018AA1FE0E6BC666DAC8FC2697FF9BA)
61-
sender = EOA(
62-
key=0xB1F4CBC3A50042184425A6F9E996D0910F7BA879457CE5DAC5C71E498AD3C005
63-
)
60+
sender = pre.fund_eoa(amount=0xDE0B6B3A7640000)
6461

6562
env = Environment(
6663
fee_recipient=coinbase,
@@ -86,7 +83,6 @@ def test_balance_non_const(
8683
nonce=0,
8784
address=Address(0xEE6A324B2ECE5EACDF881ABFDCC62B5361D0FB50), # noqa: E501
8885
)
89-
pre[sender] = Account(balance=0xDE0B6B3A7640000)
9086

9187
expect_entries_: list[dict] = [
9288
{

tests/ported_static/stArgsZeroOneBalance/test_byte_non_const.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import pytest
99
from execution_testing import (
10-
EOA,
1110
Account,
1211
Address,
1312
Alloc,
@@ -58,9 +57,7 @@ def test_byte_non_const(
5857
) -> None:
5958
"""Test_byte_non_const."""
6059
coinbase = Address(0x2ADC25665018AA1FE0E6BC666DAC8FC2697FF9BA)
61-
sender = EOA(
62-
key=0xB1F4CBC3A50042184425A6F9E996D0910F7BA879457CE5DAC5C71E498AD3C005
63-
)
60+
sender = pre.fund_eoa(amount=0xDE0B6B3A7640000)
6461

6562
env = Environment(
6663
fee_recipient=coinbase,
@@ -85,7 +82,6 @@ def test_byte_non_const(
8582
nonce=0,
8683
address=Address(0x86D606901085BA78C64D2E0B16831E6AFD89DE2D), # noqa: E501
8784
)
88-
pre[sender] = Account(balance=0xDE0B6B3A7640000)
8985

9086
expect_entries_: list[dict] = [
9187
{

0 commit comments

Comments
 (0)