Skip to content

Commit

Permalink
fix(tests): Adjust to container size limit
Browse files Browse the repository at this point in the history
  • Loading branch information
pdobacz committed Jun 24, 2024
1 parent dabf597 commit 113b9f4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ def test_max_size(
"""
Verify EOF container valid at maximum size, invalid above
"""
minimal_code = bytearray(bytes(VALID_CONTAINER))
# Expand the minimal EOF code by more noop code, reaching the desired target container size.
code = Container(
sections=[
Section.Code(
code=Op.JUMPDEST * (MAX_INITCODE_SIZE - len(minimal_code) + over_limit) + Op.STOP
code=Op.JUMPDEST * (MAX_INITCODE_SIZE - len(VALID_CONTAINER) + over_limit)
+ Op.STOP
)
]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@

pytestmark = pytest.mark.valid_from(EOF_FORK_NAME)

smallest_runtime_subcontainer = Container(
name="Runtime Subcontainer",
sections=[
Section.Code(code=Op.STOP),
],
)

VALID: List[Container] = [
Container(
name="empty_data_section",
Expand Down Expand Up @@ -48,10 +55,9 @@
Container(
name="max_data_section",
sections=[
Section.Code(
code=Op.ADDRESS + Op.POP + Op.STOP,
),
Section.Data(data=("1122334455667788" * 8 * 1024)[2:]),
Section.Code(code=Op.STOP),
# Hits the 49152 bytes limit for the entire container
Section.Data(data=(b"12345678" * 6 * 1024)[len(smallest_runtime_subcontainer) :]),
],
),
Container(
Expand Down Expand Up @@ -81,15 +87,6 @@
Section.Data(data="1122334455667788" * 16),
],
),
Container(
name="DATALOADN_max",
sections=[
Section.Code(
code=Op.DATALOADN[0xFFFF - 32] + Op.POP + Op.STOP,
),
Section.Data(data=("1122334455667788" * 8 * 1024)[2:]),
],
),
]

INVALID: List[Container] = [
Expand Down Expand Up @@ -122,6 +119,15 @@
],
validity_error=EOFException.INVALID_DATALOADN_INDEX,
),
Container(
name="data_section_over_container_limit",
sections=[
Section.Code(code=Op.STOP),
# Over the 49152 bytes limit for the entire container
Section.Data(data=(b"12345678" * 6 * 1024)[len(smallest_runtime_subcontainer) - 1 :]),
],
validity_error=EOFException.CONTAINER_SIZE_ABOVE_LIMIT,
),
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def test_initcode_aborts(
Size of the factory portion of test_eofcreate_deploy_sizes, but as the runtime code is dynamic, we
have to use a pre-calculated size
"""
factory_size = 30
factory_size = 74


@pytest.mark.parametrize(
Expand Down Expand Up @@ -199,26 +199,26 @@ def test_eofcreate_deploy_sizes(
],
)

factory_container = Container(
sections=[
Section.Code(
code=Op.SSTORE(slot_create_address, Op.EOFCREATE[0](0, 0, 0, 0))
+ Op.SSTORE(slot_code_worked, value_code_worked)
+ Op.STOP,
),
Section.Container(container=initcode_subcontainer),
]
)

assert factory_size == (
len(initcode_subcontainer) - len(runtime_container)
len(factory_container) - len(runtime_container)
), "factory_size is wrong, expected factory_size is %d, calculated is %d" % (
factory_size,
len(initcode_subcontainer),
len(factory_container),
)

sender = pre.fund_eoa()
contract_address = pre.deploy_contract(
code=Container(
sections=[
Section.Code(
code=Op.SSTORE(slot_create_address, Op.EOFCREATE[0](0, 0, 0, 0))
+ Op.SSTORE(slot_code_worked, value_code_worked)
+ Op.STOP,
),
Section.Container(container=initcode_subcontainer),
]
)
)
contract_address = pre.deploy_contract(code=factory_container)
# Storage in 0 should have the address,
# Storage 1 is a canary of 1 to make sure it tried to execute, which also covers cases of
# data+code being greater than initcode_size_max, which is allowed.
Expand Down

0 comments on commit 113b9f4

Please sign in to comment.