Skip to content

Commit d3dfac5

Browse files
authored
fix(tests): Prevent EOF max stack height above number of inputs (#1380)
When building EOF code section assert that `max_stack_height` is at least `code_inputs`. It will be impossible to encode such code types after ipsilon/eof#134
1 parent ce28bd5 commit d3dfac5

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

src/ethereum_test_types/eof/v1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ def type_definition(self) -> bytes:
200200
auto_code_outputs,
201201
)
202202

203+
assert max_stack_height >= code_inputs, "incorrect max_stack_height value"
204+
203205
return (
204206
code_inputs.to_bytes(length=TYPES_INPUTS_BYTE_LENGTH, byteorder="big")
205207
+ code_outputs.to_bytes(length=TYPES_OUTPUTS_BYTE_LENGTH, byteorder="big")

src/ethereum_test_types/tests/test_eof_v1.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,13 @@
287287
Section.Code(
288288
"0x00",
289289
code_inputs=1,
290+
max_stack_height=1,
290291
),
291292
],
292293
),
293294
"""
294295
ef0001 01 0004 02 0001 0001 04 0000 00
295-
01800000
296+
01800001
296297
00
297298
""",
298299
),
@@ -303,12 +304,13 @@
303304
Section.Code(
304305
"0x00",
305306
code_inputs=0xFF,
307+
max_stack_height=0xFF,
306308
),
307309
],
308310
),
309311
"""
310312
ef0001 01 0004 02 0001 0001 04 0000 00
311-
ff800000
313+
ff8000ff
312314
00
313315
""",
314316
),

tests/osaka/eip7692_eof_v1/eip3540_eof_v1/test_container_validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ def test_valid_containers(
10811081
code=(Op.POP * (MAX_CODE_INPUTS + 1)) + Op.RETF,
10821082
code_inputs=(MAX_CODE_INPUTS + 1),
10831083
code_outputs=0,
1084-
max_stack_height=0,
1084+
max_stack_height=(MAX_CODE_INPUTS + 1),
10851085
),
10861086
],
10871087
validity_error=EOFException.INPUTS_OUTPUTS_NUM_ABOVE_LIMIT,

tests/osaka/eip7692_eof_v1/eip6206_jumpf/test_nonreturning_validation.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,14 @@ def test_first_section_with_inputs(
6666
"""Test EOF validation failing because the first section has non-zero number of inputs."""
6767
eof_test(
6868
container=Container(
69-
sections=[Section.Code(code, code_inputs=inputs, code_outputs=outputs)],
69+
sections=[
70+
Section.Code(
71+
code,
72+
code_inputs=inputs,
73+
code_outputs=outputs,
74+
max_stack_height=max(inputs, outputs),
75+
)
76+
],
7077
validity_error=EOFException.INVALID_FIRST_SECTION_TYPE,
7178
)
7279
)

0 commit comments

Comments
 (0)