diff --git a/tests/prague/eip7692_eof_v1/eip3540_eof_v1/container.py b/tests/prague/eip7692_eof_v1/eip3540_eof_v1/container.py index eef7913628..22ad66329e 100644 --- a/tests/prague/eip7692_eof_v1/eip3540_eof_v1/container.py +++ b/tests/prague/eip7692_eof_v1/eip3540_eof_v1/container.py @@ -10,7 +10,9 @@ from ethereum_test_tools.eof.v1.constants import ( MAX_CODE_INPUTS, MAX_CODE_OUTPUTS, + MAX_CODE_SECTIONS, MAX_OPERAND_STACK_HEIGHT, + NON_RETURNING_SECTION, ) from ethereum_test_tools.exceptions import EOFException from ethereum_test_tools.vm.opcode import Opcodes as Op @@ -19,29 +21,95 @@ Container( name="single_code_single_data_section", sections=[ - Section.Code(code=Op.ADDRESS + Op.POP + Op.STOP, code_outputs=128, max_stack_height=1), + Section.Code( + code=Op.ADDRESS + Op.POP + Op.STOP, + code_outputs=NON_RETURNING_SECTION, + max_stack_height=1, + ), Section.Data(data="0xef"), ], ), - # TODO this is the only valid code I managed to produce - # somehow if code is 00 byte it gets rejected - # also if max_stack_height and code_outputs are not set it gets rejected -] - -INVALID: List[Container] = [ Container( name="max_code_sections", - sections=[Section.Code(Op.STOP)] * 1024, - # TODO type section construction probably failed, expected no exception here - validity_error=EOFException.INVALID_FIRST_SECTION_TYPE, + sections=[ + Section.Code( + Op.JUMPF[i + 1] if i < (MAX_CODE_SECTIONS - 1) else Op.STOP, + code_outputs=NON_RETURNING_SECTION, + ) + for i in range(MAX_CODE_SECTIONS) + ], + ), + Container( + name="max_code_sections_plus_data", + sections=[ + Section.Code( + Op.JUMPF[i + 1] if i < (MAX_CODE_SECTIONS - 1) else Op.STOP, + code_outputs=NON_RETURNING_SECTION, + ) + for i in range(MAX_CODE_SECTIONS) + ] + + [Section.Data(data="0x00")], ), + Container( + name="max_code_sections_plus_container", + sections=[ + Section.Code( + Op.JUMPF[i + 1] if i < (MAX_CODE_SECTIONS - 1) else Op.STOP, + code_outputs=NON_RETURNING_SECTION, + ) + for i in range(MAX_CODE_SECTIONS) + ] + + [ + Section.Container( + container=Container( + name="max_code_sections", + sections=[ + Section.Code( + Op.JUMPF[i + 1] if i < (MAX_CODE_SECTIONS - 1) else Op.STOP, + code_outputs=NON_RETURNING_SECTION, + ) + for i in range(MAX_CODE_SECTIONS) + ], + ) + ) + ], + ), + Container( + name="max_code_sections_plus_data_plus_container", + sections=[ + Section.Code( + Op.JUMPF[i + 1] if i < (MAX_CODE_SECTIONS - 1) else Op.STOP, + code_outputs=NON_RETURNING_SECTION, + ) + for i in range(MAX_CODE_SECTIONS) + ] + + [ + Section.Container( + container=Container( + name="max_code_sections", + sections=[ + Section.Code( + Op.JUMPF[i + 1] if i < (MAX_CODE_SECTIONS - 1) else Op.STOP, + code_outputs=NON_RETURNING_SECTION, + ) + for i in range(MAX_CODE_SECTIONS) + ], + ) + ) + ] + + [Section.Data(data="0x00")], + ), + # TODO: Add more valid scenarios +] + +INVALID: List[Container] = [ Container( name="single_code_section_no_data_section", sections=[ - Section.Code(Op.STOP), + Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION), ], - # TODO the exception must be about missing data section - validity_error=EOFException.INVALID_FIRST_SECTION_TYPE, + auto_data_section=False, + validity_error=EOFException.MISSING_DATA_SECTION, ), Container( name="incomplete_magic", @@ -92,12 +160,6 @@ raw_bytes=bytes([0xEF, 0x00, 0x01, 0x01, 0x00, 0x04, 0x02, 0x00, 0x01, 0x00]), validity_error=EOFException.INCOMPLETE_SECTION_SIZE, ), - Container( - name="no_data_section", - raw_bytes=bytes([0xEF, 0x00, 0x01, 0x01, 0x00, 0x04, 0x02, 0x00, 0x01, 0x00, 0x00]), - # TODO the exception must be about data section - validity_error=EOFException.ZERO_SECTION_SIZE, - ), Container( name="no_data_section_size", raw_bytes=bytes( @@ -113,7 +175,7 @@ 0x01, 0x00, 0x00, - 0x03, + 0x04, ] ), # TODO it looks like data section is missing or section header of type 0x00 @@ -150,31 +212,31 @@ Container( name="invalid_magic_01", magic=b"\xef\x01", - sections=[Section.Code(Op.STOP)], + sections=[Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION)], validity_error=EOFException.INVALID_MAGIC, ), Container( name="invalid_magic_ff", magic=b"\xef\xFF", - sections=[Section.Code(Op.STOP)], + sections=[Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION)], validity_error=EOFException.INVALID_MAGIC, ), Container( name="invalid_version_zero", version=b"\x00", - sections=[Section.Code(Op.STOP)], + sections=[Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION)], validity_error=EOFException.INVALID_VERSION, ), Container( name="invalid_version_plus_one", version=int.to_bytes(LATEST_EOF_VERSION + 1, length=1, byteorder="big"), - sections=[Section.Code(Op.STOP)], + sections=[Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION)], validity_error=EOFException.INVALID_VERSION, ), Container( name="invalid_version_high", version=b"\xFF", - sections=[Section.Code(Op.STOP)], + sections=[Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION)], validity_error=EOFException.INVALID_VERSION, ), Container( @@ -188,7 +250,13 @@ ), Container( name="too_many_code_sections", - sections=[Section.Code(Op.STOP)] * 1025, + sections=[ + Section.Code( + Op.JUMPF[i + 1] if i < MAX_CODE_SECTIONS else Op.STOP, + code_outputs=NON_RETURNING_SECTION, + ) + for i in range(MAX_CODE_SECTIONS + 1) + ], validity_error=EOFException.TOO_MANY_CODE_SECTIONS, ), Container( @@ -223,45 +291,45 @@ Container( name="no_section_terminator_1", header_terminator=bytes(), - sections=[Section.Code(code=Op.STOP, custom_size=2)], + sections=[Section.Code(code=Op.STOP, custom_size=2, code_outputs=NON_RETURNING_SECTION)], # TODO the exception must be about terminator validity_error=EOFException.INVALID_SECTION_BODIES_SIZE, ), Container( name="no_section_terminator_2", header_terminator=bytes(), - sections=[Section.Code(code="0x", custom_size=3)], + sections=[Section.Code(code="0x", custom_size=3, code_outputs=NON_RETURNING_SECTION)], # TODO the exception must be about terminator validity_error=EOFException.INVALID_SECTION_BODIES_SIZE, ), Container( name="no_section_terminator_3", header_terminator=bytes(), - sections=[Section.Code(code=Op.PUSH1(0) + Op.STOP)], + sections=[Section.Code(code=Op.PUSH1(0) + Op.STOP, code_outputs=NON_RETURNING_SECTION)], # TODO the exception must be about terminator validity_error=EOFException.INVALID_SECTION_BODIES_SIZE, ), Container( name="no_code_section_contents", - sections=[Section.Code(code="0x", custom_size=0x01)], + sections=[Section.Code(code="0x", custom_size=0x01, code_outputs=NON_RETURNING_SECTION)], validity_error=EOFException.INVALID_SECTION_BODIES_SIZE, ), Container( name="incomplete_code_section_contents", sections=[ - Section.Code(code=Op.STOP, custom_size=0x02), + Section.Code(code=Op.STOP, custom_size=0x02, code_outputs=NON_RETURNING_SECTION), ], validity_error=EOFException.INVALID_SECTION_BODIES_SIZE, ), Container( name="trailing_bytes_after_code_section", - sections=[Section.Code(code=Op.PUSH1(0) + Op.STOP)], + sections=[Section.Code(code=Op.PUSH1(0) + Op.STOP, code_outputs=NON_RETURNING_SECTION)], extra=bytes([0xDE, 0xAD, 0xBE, 0xEF]), validity_error=EOFException.INVALID_SECTION_BODIES_SIZE, ), Container( name="empty_code_section", - sections=[Section.Code(code="0x")], + sections=[Section.Code(code="0x", code_outputs=NON_RETURNING_SECTION)], # TODO the exception must be about code section EOFException.INVALID_CODE_SECTION, validity_error=EOFException.ZERO_SECTION_SIZE, ), @@ -277,11 +345,12 @@ Container( name="data_section_preceding_code_section", auto_data_section=False, + auto_sort_sections=AutoSection.NONE, sections=[ Section.Data(data="0xDEADBEEF"), - Section.Code(Op.STOP), + Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION), ], - validity_error=EOFException.INVALID_FIRST_SECTION_TYPE, + validity_error=EOFException.MISSING_CODE_HEADER, ), Container( name="data_section_without_code_section", @@ -292,7 +361,12 @@ Container( name="no_section_terminator_3a", header_terminator=bytes(), - sections=[Section.Code(code="0x030004")], + sections=[ + Section.Code( + code="0x030004", + code_outputs=NON_RETURNING_SECTION, + ) + ], # TODO the exception must be about terminator validity_error=EOFException.INVALID_SECTION_BODIES_SIZE, ), @@ -300,29 +374,35 @@ name="no_section_terminator_4a", header_terminator=bytes(), sections=[ - Section.Code(Op.STOP), + Section.Code( + Op.STOP, + code_outputs=NON_RETURNING_SECTION, + ), Section.Data(data="0xAABBCCDD"), ], # TODO the exception must be about terminator - validity_error=EOFException.INVALID_SECTION_BODIES_SIZE, - ), - Container( - name="no_data_section_contents", - sections=[ - Section.Code(Op.STOP), - Section.Data(data="0x", custom_size=1), - ], - # TODO: maybe it should detect that it is the data body that is wrong - validity_error=EOFException.INVALID_SECTION_BODIES_SIZE, - ), - Container( - name="data_section_contents_incomplete", - sections=[ - Section.Code(Op.STOP), - Section.Data(data="0xAABBCC", custom_size=4), - ], - validity_error=EOFException.INVALID_SECTION_BODIES_SIZE, + validity_error=EOFException.INVALID_FIRST_SECTION_TYPE, ), + # TODO: Incomplete data section containers are passing validation. + # Perhaps these kinds of containers should be included in a state test where the code is + # actually being deployed and has its final validation. + # Container( + # name="no_data_section_contents", + # sections=[ + # Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION), + # Section.Data(data="0x", custom_size=1), + # ], + # # TODO: maybe it should detect that it is the data body that is wrong + # validity_error=EOFException.INVALID_FIRST_SECTION_TYPE, + # ), + # Container( + # name="data_section_contents_incomplete", + # sections=[ + # Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION), + # Section.Data(data="0xAABBCC", custom_size=4), + # ], + # validity_error=EOFException.INVALID_FIRST_SECTION_TYPE, + # ), Container( name="trailing_bytes_after_data_section", extra=bytes([0xEE]), @@ -345,8 +425,8 @@ Container( name="multiple_code_and_data_sections_1", sections=[ - Section.Code(Op.STOP), - Section.Code(Op.STOP), + Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION), + Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION), Section.Data(data="0xAA"), Section.Data(data="0xAA"), ], @@ -355,26 +435,17 @@ Container( name="multiple_code_and_data_sections_2", sections=[ - Section.Code(Op.STOP), + Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION), Section.Data(data="0xAA"), - Section.Code(Op.STOP), + Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION), Section.Data(data="0xAA"), ], validity_error=EOFException.MISSING_TERMINATOR, ), - Container( - name="code_section_out_of_order", - sections=[ - Section.Code(Op.STOP), - Section.Data(data="0xAA"), - Section.Code(Op.STOP), - ], - validity_error=EOFException.INVALID_FIRST_SECTION_TYPE, - ), Container( name="unknown_section_1", sections=[ - Section.Code(Op.STOP), + Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION), Section.Data(data="0x"), Section(kind=VERSION_MAX_SECTION_KIND + 1, data="0x01"), ], @@ -385,7 +456,7 @@ sections=[ Section(kind=VERSION_MAX_SECTION_KIND + 1, data="0x01"), Section.Data(data="0x"), - Section.Code(Op.STOP), + Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION), ], # TODO the exception should be about unknown section definition validity_error=EOFException.MISSING_TERMINATOR, @@ -393,7 +464,7 @@ Container( name="unknown_section_empty", sections=[ - Section.Code(Op.STOP), + Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION), Section.Data(data="0x"), Section(kind=VERSION_MAX_SECTION_KIND + 1, data="0x"), ], @@ -413,7 +484,7 @@ sections=[ Section(kind=Kind.TYPE, data="0x00000000"), Section(kind=Kind.TYPE, data="0x00000000"), - Section.Code(Op.STOP), + Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION), ], auto_type_section=AutoSection.NONE, validity_error=EOFException.MISSING_CODE_HEADER, @@ -422,7 +493,7 @@ name="empty_type_section", sections=[ Section(kind=Kind.TYPE, data="0x"), - Section.Code(Op.STOP), + Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION), ], auto_type_section=AutoSection.NONE, # TODO the exception must be about type section EOFException.INVALID_TYPE_SECTION_SIZE, @@ -432,7 +503,7 @@ name="type_section_too_small_1", sections=[ Section(kind=Kind.TYPE, data="0x00"), - Section.Code(Op.STOP), + Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION), ], auto_type_section=AutoSection.NONE, validity_error=EOFException.INVALID_TYPE_SECTION_SIZE, @@ -441,7 +512,7 @@ name="type_section_too_small_2", sections=[ Section(kind=Kind.TYPE, data="0x000000"), - Section.Code(Op.STOP), + Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION), ], auto_type_section=AutoSection.NONE, validity_error=EOFException.INVALID_TYPE_SECTION_SIZE, @@ -450,7 +521,7 @@ name="type_section_too_big", sections=[ Section(kind=Kind.TYPE, data="0x0000000000"), - Section.Code(Op.STOP), + Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION), ], auto_type_section=AutoSection.NONE, validity_error=EOFException.INVALID_TYPE_SECTION_SIZE, @@ -463,9 +534,7 @@ EIP-4750 Valid and Invalid Containers """ -VALID += [] - -INVALID += [ +VALID += [ Container( name="single_code_section_max_stack_size", sections=[ @@ -474,12 +543,10 @@ + (Op.POP * MAX_OPERAND_STACK_HEIGHT) + Op.STOP, code_inputs=0, - code_outputs=0, + code_outputs=NON_RETURNING_SECTION, max_stack_height=MAX_OPERAND_STACK_HEIGHT, ), ], - # TODO check the types section construction, this test was supposed to be valid - validity_error=EOFException.INVALID_FIRST_SECTION_TYPE, ), Container( name="single_code_section_input_maximum", @@ -487,7 +554,7 @@ Section.Code( code=((Op.PUSH0 * MAX_CODE_INPUTS) + Op.CALLF[1] + Op.STOP), code_inputs=0, - code_outputs=0, + code_outputs=NON_RETURNING_SECTION, max_stack_height=MAX_CODE_INPUTS, ), Section.Code( @@ -497,8 +564,6 @@ max_stack_height=MAX_CODE_INPUTS, ), ], - # TODO check the types section construction, this test was supposed to be valid - validity_error=EOFException.INVALID_FIRST_SECTION_TYPE, ), Container( name="single_code_section_output_maximum", @@ -506,7 +571,7 @@ Section.Code( code=(Op.CALLF[1] + Op.STOP), code_inputs=0, - code_outputs=0, + code_outputs=NON_RETURNING_SECTION, max_stack_height=MAX_CODE_OUTPUTS, ), Section.Code( @@ -516,13 +581,15 @@ max_stack_height=MAX_CODE_OUTPUTS, ), ], - # TODO check the types section construction, this test was supposed to be valid - validity_error=EOFException.INVALID_FIRST_SECTION_TYPE, ), Container( name="multiple_code_section_max_inputs_max_outputs", sections=[ - Section.Code(Op.STOP), + Section.Code( + (Op.PUSH0 * MAX_CODE_OUTPUTS) + Op.CALLF[1] + Op.STOP, + code_outputs=NON_RETURNING_SECTION, + max_stack_height=MAX_CODE_OUTPUTS, + ), Section.Code( code=Op.RETF, code_inputs=MAX_CODE_INPUTS, @@ -530,41 +597,29 @@ max_stack_height=MAX_CODE_INPUTS, ), ], - # TODO check the types section construction, this test was supposed to be valid - validity_error=EOFException.INVALID_FIRST_SECTION_TYPE, - ), - Container( - name="max_code_sections_1024", - sections=[Section.Code(Op.STOP)] * 1024, - # TODO check the types section construction, this test was supposed to be valid - validity_error=EOFException.INVALID_FIRST_SECTION_TYPE, - ), - Container( - name="max_code_sections_1024_and_data", - sections=([Section.Code(Op.STOP)] * 1024) - + [ - Section.Data("0x00"), - ], - # TODO check the types section construction, this test was supposed to be valid - validity_error=EOFException.INVALID_FIRST_SECTION_TYPE, ), +] + +INVALID += [ Container( name="single_code_section_non_zero_inputs", - sections=[Section.Code(code=Op.POP, code_inputs=1)], + sections=[ + Section.Code(code=Op.POP + Op.RETF, code_inputs=1, code_outputs=NON_RETURNING_SECTION) + ], # TODO the exception must be about code or non, cause it looks legit validity_error=EOFException.INVALID_FIRST_SECTION_TYPE, ), Container( name="single_code_section_non_zero_outputs", - sections=[Section.Code(code=Op.PUSH0, code_outputs=1)], + sections=[Section.Code(code=Op.PUSH0 + Op.RETF, code_outputs=1)], # TODO the exception must be about code or non, cause it looks legit validity_error=EOFException.INVALID_FIRST_SECTION_TYPE, ), Container( name="multiple_code_section_non_zero_inputs", sections=[ - Section.Code(code=Op.POP, code_inputs=1), - Section.Code(Op.STOP), + Section.Code(code=Op.POP + Op.RETF, code_inputs=1, code_outputs=NON_RETURNING_SECTION), + Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION), ], # TODO the actual exception should be EOFException.INVALID_TYPE_BODY, validity_error=EOFException.INVALID_FIRST_SECTION_TYPE, @@ -573,7 +628,7 @@ name="multiple_code_section_non_zero_outputs", sections=[ Section.Code(code=Op.PUSH0, code_outputs=1), - Section.Code(Op.STOP), + Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION), ], # TODO the actual exception should be EOFException.INVALID_TYPE_BODY, validity_error=EOFException.INVALID_FIRST_SECTION_TYPE, @@ -582,7 +637,7 @@ name="data_section_before_code_with_type", sections=[ Section.Data(data="0xAA"), - Section.Code(Op.STOP), + Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION), ], auto_sort_sections=AutoSection.NONE, validity_error=EOFException.MISSING_CODE_HEADER, @@ -591,20 +646,15 @@ name="data_section_listed_in_type", sections=[ Section.Data(data="0x00", force_type_listing=True), - Section.Code(Op.STOP), + Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION), ], validity_error=EOFException.INVALID_TYPE_SECTION_SIZE, ), - Container( - name="code_sections_above_1024", - sections=[Section.Code(Op.STOP)] * 1025, - validity_error=EOFException.TOO_MANY_CODE_SECTIONS, - ), Container( name="single_code_section_incomplete_type", sections=[ Section(kind=Kind.TYPE, data="0x00"), - Section.Code(Op.STOP), + Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION), ], auto_type_section=AutoSection.NONE, validity_error=EOFException.INVALID_TYPE_SECTION_SIZE, @@ -613,7 +663,7 @@ name="single_code_section_incomplete_type_2", sections=[ Section(kind=Kind.TYPE, data="0x00", custom_size=2), - Section.Code(Op.STOP), + Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION), ], validity_error=EOFException.INVALID_SECTION_BODIES_SIZE, ), @@ -623,7 +673,7 @@ Section.Code( code=((Op.PUSH0 * (MAX_CODE_INPUTS + 1)) + Op.CALLF[1] + Op.STOP), code_inputs=0, - code_outputs=0, + code_outputs=NON_RETURNING_SECTION, max_stack_height=(MAX_CODE_INPUTS + 1), ), Section.Code( @@ -634,7 +684,7 @@ ), ], # TODO auto types section generation probably failed. the exception must be about code - validity_error=EOFException.INVALID_FIRST_SECTION_TYPE, + validity_error=EOFException.INPUTS_OUTPUTS_NUM_ABOVE_LIMIT, ), Container( name="single_code_section_output_too_large", @@ -642,18 +692,18 @@ Section.Code( code=(Op.CALLF[1] + Op.STOP), code_inputs=0, - code_outputs=0, - max_stack_height=(MAX_CODE_OUTPUTS + 1), + code_outputs=NON_RETURNING_SECTION, + max_stack_height=(MAX_CODE_OUTPUTS + 2), ), Section.Code( - code=(Op.PUSH0 * (MAX_CODE_OUTPUTS + 1)) + Op.RETF, + code=(Op.PUSH0 * (MAX_CODE_OUTPUTS + 2)) + Op.RETF, code_inputs=0, - code_outputs=(MAX_CODE_OUTPUTS + 1), + code_outputs=(MAX_CODE_OUTPUTS + 2), max_stack_height=(MAX_CODE_OUTPUTS + 1), ), ], # TODO the exception must be about code body - validity_error=EOFException.INVALID_FIRST_SECTION_TYPE, + validity_error=EOFException.INPUTS_OUTPUTS_NUM_ABOVE_LIMIT, ), Container( name="single_code_section_max_stack_size_too_large", @@ -661,11 +711,11 @@ Section.Code( code=Op.CALLER * 1024 + Op.POP * 1024 + Op.STOP, code_inputs=0, - code_outputs=0, + code_outputs=NON_RETURNING_SECTION, max_stack_height=1024, ), ], # TODO auto types section generation probably failed, the exception must be about code - validity_error=EOFException.INVALID_FIRST_SECTION_TYPE, + validity_error=EOFException.MAX_STACK_HEIGHT_ABOVE_LIMIT, ), ]