Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
807 changes: 765 additions & 42 deletions scripts/filler_to_python/analyzer.py

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions scripts/filler_to_python/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class AccountIR:
code_expr: str = ""
storage: dict = field(default_factory=dict)
oversized_code: bool = False
use_dynamic: bool = True


@dataclass
Expand Down Expand Up @@ -80,6 +81,7 @@ class AccessListEntryIR:

address: str = ""
storage_keys: list = field(default_factory=list)
use_dynamic: bool = False


@dataclass
Expand Down Expand Up @@ -108,7 +110,9 @@ class SenderIR:
is_tagged: bool = False
key: int | None = None
balance: int = 0
nonce: int | None = None
not_in_pre: bool = False
use_dynamic: bool = True


@dataclass
Expand Down Expand Up @@ -136,6 +140,7 @@ class IntermediateTestModel:
is_slow: bool = False
is_multi_case: bool = False
is_fork_dependent: bool = False
needs_mutable_pre: bool = False
environment: EnvironmentIR = field(
default_factory=lambda: EnvironmentIR(
coinbase_var="coinbase", number=0, timestamp=0
Expand Down
7 changes: 6 additions & 1 deletion scripts/filler_to_python/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ def format_storage(d: dict) -> str:
return "{}"
items = []
for k in sorted(d.keys()):
items.append(f"{format_int(k)}: {format_int(d[k])}")
v = d[k]
if isinstance(v, str):
items.append(f"{format_int(k)}: {v}")
else:
items.append(f"{format_int(k)}: {format_int(v)}")
single = "{" + ", ".join(items) + "}"
if len(single) <= 50:
return single
Expand Down Expand Up @@ -271,6 +275,7 @@ def render_test(ir: IntermediateTestModel) -> str:
"is_slow": ir.is_slow,
"is_multi_case": ir.is_multi_case,
"is_fork_dependent": ir.is_fork_dependent,
"needs_mutable_pre": ir.needs_mutable_pre,
"has_exceptions": has_exceptions,
"env": ir.environment,
"accounts": ir.accounts,
Expand Down
28 changes: 25 additions & 3 deletions scripts/filler_to_python/templates/state_test.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ def _storage_with_any(base: dict, any_keys: list) -> Storage:
{% if has_exceptions and not is_multi_case %}
@pytest.mark.exception_test
{% endif %}
{% if needs_mutable_pre %}
@pytest.mark.pre_alloc_mutable
{% endif %}
def {{ test_name }}(
state_test: StateTestFiller,
pre: Alloc,
Expand All @@ -176,7 +178,13 @@ def {{ test_name }}(
{% for addr in address_constants %}
{{ addr.var_name }} = Address({{ addr.hex }})
{% endfor %}
{% if sender.not_in_pre %}
{% if sender.use_dynamic %}
{% if sender.nonce %}
sender = pre.fund_eoa(amount={{ sender.balance | format_int }}, nonce={{ sender.nonce }})
{% else %}
sender = pre.fund_eoa(amount={{ sender.balance | format_int }})
{% endif %}
{% elif sender.not_in_pre %}
sender = pre.fund_eoa(amount=0)
{% else %}
sender = EOA(
Expand Down Expand Up @@ -205,15 +213,19 @@ def {{ test_name }}(

{# Pre-state account setup #}
{% for account in accounts %}
{% if account.is_sender %}
{% if account.is_sender and sender.use_dynamic %}
{# Sender balance already set via pre.fund_eoa() above #}
{% elif account.is_sender %}
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 }})
{% elif account.is_eoa and account.use_dynamic %}
{{ account.var_name }} = pre.fund_eoa(amount={{ account.balance | format_int }}) # noqa: F841
{% elif account.is_eoa %}
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 }})
{% else %}
{# Contract: source comment + deploy #}
{{ account.source_comment }}
{% if account.oversized_code %}
{{ account.var_name }} = Address({{ account.address }})
{{ account.var_name }} = Address({{ account.address }}) # oversized contract
pre[{{ account.var_name }}] = Account(
code={{ account.code_expr | wrap_op_chain(indent=8) }},
{% if account.storage %}
Expand All @@ -238,7 +250,9 @@ def {{ test_name }}(
{% if account.nonce is not none %}
nonce={{ account.nonce }},
{% endif %}
{% if not account.use_dynamic %}
address=Address({{ account.address }}), # noqa: E501
{% endif %}
)
{% endif %}
{% endif %}
Expand Down Expand Up @@ -287,7 +301,11 @@ def {{ test_name }}(
{{ d_idx }}: [
{% for al in al_entries %}
AccessList(
{% if al.use_dynamic %}
address={{ al.address }},
{% else %}
address=Address({{ al.address }}),
{% endif %}
storage_keys=[
{% for sk in al.storage_keys %}
Hash("{{ sk }}"), # noqa: E501
Expand Down Expand Up @@ -357,7 +375,11 @@ def {{ test_name }}(
access_list=[
{% for al in tx.access_list %}
AccessList(
{% if al.use_dynamic %}
address={{ al.address }},
{% else %}
address=Address({{ al.address }}),
{% endif %}
storage_keys=[
{% for sk in al.storage_keys %}
Hash(
Expand Down
34 changes: 34 additions & 0 deletions scripts/verify_dynamic_addresses.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
# Verify that filler_to_python with dynamic addresses produces
# trace-equivalent tests. Assumes output/traces_baseline/ already
# exists (generated once before any code changes).
set -euo pipefail

export TMPDIR=./.tmp
mkdir -p "$TMPDIR" output/traces_new

if [ ! -d "output/traces_baseline" ]; then
echo "ERROR: output/traces_baseline/ not found."
echo "Generate baseline first (before code changes):"
echo " TMPDIR=./.tmp uv run fill tests/ported_static/ --evm-dump-dir output/traces_baseline -n 10 -m 'not slow'"
exit 1
fi

# Step 1: Run filler_to_python (overwrites tests/ported_static/)
echo "=== Step 1: Running filler_to_python ==="
uv run python -m scripts.filler_to_python \
--fillers tests/static/static/state_tests/ \
--output tests/ported_static/

# Step 2: Fill new tests + verify against baseline
echo "=== Step 2: Filling new tests and verifying traces ==="
uv run fill \
tests/ported_static/ \
--evm-dump-dir output/traces_new \
--verify-traces output/traces_baseline \
--verify-traces-comparator exact-no-stack \
-n 10 \
-m "not slow"

echo "=== Done. Check output above for trace mismatches ==="
echo "=== Use 'git diff tests/ported_static/' to see code changes ==="
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import pytest
from execution_testing import (
EOA,
Account,
Address,
Alloc,
Expand Down Expand Up @@ -58,9 +57,7 @@ def test_add_non_const(
) -> None:
"""Test_add_non_const."""
coinbase = Address(0x2ADC25665018AA1FE0E6BC666DAC8FC2697FF9BA)
sender = EOA(
key=0xB1F4CBC3A50042184425A6F9E996D0910F7BA879457CE5DAC5C71E498AD3C005
)
sender = pre.fund_eoa(amount=0xDE0B6B3A7640000)

env = Environment(
fee_recipient=coinbase,
Expand All @@ -85,7 +82,6 @@ def test_add_non_const(
nonce=0,
address=Address(0xF1722FE346FA35E045DE07E47CF6AF9BAE8ADE0A), # noqa: E501
)
pre[sender] = Account(balance=0xDE0B6B3A7640000)

expect_entries_: list[dict] = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import pytest
from execution_testing import (
EOA,
Account,
Address,
Alloc,
Expand Down Expand Up @@ -58,9 +57,7 @@ def test_addmod_non_const(
) -> None:
"""Test_addmod_non_const."""
coinbase = Address(0x2ADC25665018AA1FE0E6BC666DAC8FC2697FF9BA)
sender = EOA(
key=0xB1F4CBC3A50042184425A6F9E996D0910F7BA879457CE5DAC5C71E498AD3C005
)
sender = pre.fund_eoa(amount=0xDE0B6B3A7640000)

env = Environment(
fee_recipient=coinbase,
Expand All @@ -86,7 +83,6 @@ def test_addmod_non_const(
nonce=0,
address=Address(0x92D2FC80312ACD8C37857696D2224AF18CE6F966), # noqa: E501
)
pre[sender] = Account(balance=0xDE0B6B3A7640000)

expect_entries_: list[dict] = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import pytest
from execution_testing import (
EOA,
Account,
Address,
Alloc,
Expand Down Expand Up @@ -58,9 +57,7 @@ def test_and_non_const(
) -> None:
"""Test_and_non_const."""
coinbase = Address(0x2ADC25665018AA1FE0E6BC666DAC8FC2697FF9BA)
sender = EOA(
key=0xB1F4CBC3A50042184425A6F9E996D0910F7BA879457CE5DAC5C71E498AD3C005
)
sender = pre.fund_eoa(amount=0xDE0B6B3A7640000)

env = Environment(
fee_recipient=coinbase,
Expand All @@ -85,7 +82,6 @@ def test_and_non_const(
nonce=0,
address=Address(0x4C26357E0D164B702BCEB18690FC742EE1D36913), # noqa: E501
)
pre[sender] = Account(balance=0xDE0B6B3A7640000)

expect_entries_: list[dict] = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import pytest
from execution_testing import (
EOA,
Account,
Address,
Alloc,
Expand Down Expand Up @@ -58,9 +57,7 @@ def test_balance_non_const(
) -> None:
"""Test_balance_non_const."""
coinbase = Address(0x2ADC25665018AA1FE0E6BC666DAC8FC2697FF9BA)
sender = EOA(
key=0xB1F4CBC3A50042184425A6F9E996D0910F7BA879457CE5DAC5C71E498AD3C005
)
sender = pre.fund_eoa(amount=0xDE0B6B3A7640000)

env = Environment(
fee_recipient=coinbase,
Expand All @@ -86,7 +83,6 @@ def test_balance_non_const(
nonce=0,
address=Address(0xEE6A324B2ECE5EACDF881ABFDCC62B5361D0FB50), # noqa: E501
)
pre[sender] = Account(balance=0xDE0B6B3A7640000)

expect_entries_: list[dict] = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import pytest
from execution_testing import (
EOA,
Account,
Address,
Alloc,
Expand Down Expand Up @@ -58,9 +57,7 @@ def test_byte_non_const(
) -> None:
"""Test_byte_non_const."""
coinbase = Address(0x2ADC25665018AA1FE0E6BC666DAC8FC2697FF9BA)
sender = EOA(
key=0xB1F4CBC3A50042184425A6F9E996D0910F7BA879457CE5DAC5C71E498AD3C005
)
sender = pre.fund_eoa(amount=0xDE0B6B3A7640000)

env = Environment(
fee_recipient=coinbase,
Expand All @@ -85,7 +82,6 @@ def test_byte_non_const(
nonce=0,
address=Address(0x86D606901085BA78C64D2E0B16831E6AFD89DE2D), # noqa: E501
)
pre[sender] = Account(balance=0xDE0B6B3A7640000)

expect_entries_: list[dict] = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import pytest
from execution_testing import (
EOA,
Account,
Address,
Alloc,
Expand Down Expand Up @@ -58,9 +57,7 @@ def test_call_non_const(
) -> None:
"""Test_call_non_const."""
coinbase = Address(0x2ADC25665018AA1FE0E6BC666DAC8FC2697FF9BA)
sender = EOA(
key=0xB1F4CBC3A50042184425A6F9E996D0910F7BA879457CE5DAC5C71E498AD3C005
)
sender = pre.fund_eoa(amount=0xDE0B6B3A7640000)

env = Environment(
fee_recipient=coinbase,
Expand Down Expand Up @@ -104,7 +101,6 @@ def test_call_non_const(
nonce=0,
address=Address(0x7D7E1645AF7DF916DA558F0695E9DEDD23B1215E), # noqa: E501
)
pre[sender] = Account(balance=0xDE0B6B3A7640000)

expect_entries_: list[dict] = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import pytest
from execution_testing import (
EOA,
Account,
Address,
Alloc,
Expand Down Expand Up @@ -58,9 +57,7 @@ def test_callcode_non_const(
) -> None:
"""Test_callcode_non_const."""
coinbase = Address(0x2ADC25665018AA1FE0E6BC666DAC8FC2697FF9BA)
sender = EOA(
key=0xB1F4CBC3A50042184425A6F9E996D0910F7BA879457CE5DAC5C71E498AD3C005
)
sender = pre.fund_eoa(amount=0xDE0B6B3A7640000)

env = Environment(
fee_recipient=coinbase,
Expand Down Expand Up @@ -104,7 +101,6 @@ def test_callcode_non_const(
nonce=0,
address=Address(0x443A994E18105C3EA686D3931729A1AC3D8FDD93), # noqa: E501
)
pre[sender] = Account(balance=0xDE0B6B3A7640000)

expect_entries_: list[dict] = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import pytest
from execution_testing import (
EOA,
Account,
Address,
Alloc,
Expand Down Expand Up @@ -70,9 +69,7 @@ def test_calldatacopy_non_const(
) -> None:
"""Test_calldatacopy_non_const."""
coinbase = Address(0x2ADC25665018AA1FE0E6BC666DAC8FC2697FF9BA)
sender = EOA(
key=0xB1F4CBC3A50042184425A6F9E996D0910F7BA879457CE5DAC5C71E498AD3C005
)
sender = pre.fund_eoa(amount=0xDE0B6B3A7640000)

env = Environment(
fee_recipient=coinbase,
Expand Down Expand Up @@ -101,7 +98,6 @@ def test_calldatacopy_non_const(
nonce=0,
address=Address(0x444C2681920E1105C9104FB32249DDBB41CBA4A0), # noqa: E501
)
pre[sender] = Account(balance=0xDE0B6B3A7640000)

expect_entries_: list[dict] = [
{
Expand Down
Loading
Loading