Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fw): EOF - Accept initcode_prefix on EOF Container.Init #819

Merged
merged 3 commits into from
Sep 19, 2024
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/ethereum_test_types/eof/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,14 +481,18 @@ def Code(cls, code: BytesConvertible = Bytecode(), **kwargs) -> "Container": #
return cls(sections=[Section.Code(code=code, **kwargs)])

@classmethod
def Init(cls, deploy_container: "Container", **kwargs) -> "Container": # noqa: N802
def Init( # noqa: N802
cls,
deploy_container: "Container",
initcode_prefix: Bytecode = Bytecode(),
) -> "Container":
"""
Creates simple init container that deploys the specified container.
"""
return cls(
sections=[
Section.Code(
code=Op.RETURNCONTRACT[0](0, 0),
code=initcode_prefix + Op.RETURNCONTRACT[0](0, 0),
),
Section.Container(
container=deploy_container,
Expand Down
72 changes: 68 additions & 4 deletions src/ethereum_test_types/tests/test_eof_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from ethereum_test_base_types import to_json
from ethereum_test_base_types.pydantic import CopyValidateModel
from ethereum_test_vm import Opcodes as Op

from ..eof.v1 import AutoSection, Container, Section, SectionKind

Expand Down Expand Up @@ -651,7 +652,7 @@
),
"""
# EOF deployed code
ef0001 # Magic followed by bad version
ef0001 # Magic followed by version
020001 # One code segment
0003 # code seg 0: 3 bytes
010004 # One code segment
Expand Down Expand Up @@ -690,7 +691,7 @@
),
"""
# EOF deployed code
ef0001 # Magic followed by bad version
ef0001 # Magic followed by version
010004 # One code segment
020001 # One code segment
0003 # code seg 0: 3 bytes
Expand Down Expand Up @@ -725,7 +726,7 @@
),
"""
# EOF deployed code
ef0001 # Magic followed by bad version
ef0001 # Magic followed by version
020001 # One code segment
0003 # code seg 0: 3 bytes
040001 # One byte data segment
Expand Down Expand Up @@ -759,7 +760,7 @@
),
"""
# EOF deployed code
ef0001 # Magic followed by bad version
ef0001 # Magic followed by version
010004 # Types section
020001 # One code segment
0003 # code seg 0: 3 bytes
Expand All @@ -774,6 +775,69 @@
ef
""",
),
(
"Container.Init simple test",
Container.Init(deploy_container=Container.Code(b"\0")),
"""
# EOF deployed code
ef0001 # Magic followed by version
010004 # Types section
020001 # One code segment
0006 # code seg 0: 6 bytes
030001 # One container segment
0014 # container seg 0: 20 bytes
040000 # Zero byte data segment
00 # End of header
0080 0002 # Types section
# Code segment 0 code
6000 # 1 PUSH1 0
6000 # 2 PUSH1 0
ee00 # 3 RETURNCONTRACT[0]
# Subcontainer 0
ef0001 # Magic followed by version
010004 # Types section
020001 # One code segment
0001 # code seg 0: 1 byte
040000 # Zero byte data segment
00 # End of header
0080 0000 # Types section
# Code segment 0 code
00 # 1 STOP
""",
),
(
"Container.Init initcode prefix",
Container.Init(deploy_container=Container.Code(b"\0"), initcode_prefix=Op.SSTORE(0, 0)),
"""
# EOF deployed code
ef0001 # Magic followed by version
010004 # Types section
020001 # One code segment
000b # code seg 0: 11 bytes
030001 # One container segment
0014 # container seg 0: 20 bytes
040000 # Zero byte data segment
00 # End of header
0080 0002 # Types section
# Code segment 0 code
6000 # 1 PUSH1 0
6000 # 2 PUSH1 0
55 # 3 SSTORE
6000 # 4 PUSH1 0
6000 # 5 PUSH1 0
ee00 # 6 RETURNCONTRACT[0]
# Subcontainer 0
ef0001 # Magic followed by version
010004 # Types section
020001 # One code segment
0001 # code seg 0: 1 byte
040000 # Zero byte data segment
00 # End of header
0080 0000 # Types section
# Code segment 0 code
00 # 1 STOP
""",
),
]


Expand Down