|
1 | 1 | import pytest
|
2 | 2 |
|
3 | 3 | from ethereum_test_exceptions import EOFException
|
4 |
| -from ethereum_test_types.eof.v1 import Container |
| 4 | +from ethereum_test_types.eof.v1 import Container, Section |
| 5 | +from ethereum_test_tools.vm.opcode import Opcodes as Op |
5 | 6 |
|
6 | 7 | REFERENCE_SPEC_GIT_PATH = "EIPS/eip-663.md"
|
7 | 8 | REFERENCE_SPEC_VERSION = "b658bb87fe039d29e9475d5cfaebca9b92e0fca2"
|
|
12 | 13 | [
|
13 | 14 | Container(
|
14 | 15 | name="EOF1_embedded_container_invalid_0",
|
15 |
| - raw_bytes="ef0001010004020001000603", |
| 16 | + raw_bytes=( |
| 17 | + [ |
| 18 | + 0xEF, 0x00, 0x01, # Version: 1 |
| 19 | + 0x01, 0x00, 0x04, # Types Length: 4 |
| 20 | + 0x02, 0x00, 0x01, # Code Sections (Length: 1) |
| 21 | + 0x00, 0x06, # Code Section 0 (Length: 6) |
| 22 | + # --- Error: Invalid Container Header ---# |
| 23 | + 0x03, |
| 24 | + ] |
| 25 | + ), |
16 | 26 | validity_error=EOFException.INCOMPLETE_SECTION_NUMBER,
|
17 | 27 | ),
|
18 | 28 | Container(
|
19 | 29 | name="EOF1_embedded_container_invalid_1",
|
20 |
| - raw_bytes="ef000101000402000100060300", |
| 30 | + raw_bytes=( |
| 31 | + [ |
| 32 | + 0xEF, 0x00, 0x01, # Version: 1 |
| 33 | + 0x01, 0x00, 0x04, # Types Length: 4 |
| 34 | + 0x02, 0x00, 0x01, # Code Sections (Length: 1) |
| 35 | + 0x00, 0x06, # Code Section 0 (Length: 6) |
| 36 | + # --- Error: Invalid Container Header ---# |
| 37 | + 0x03, |
| 38 | + 0x00, |
| 39 | + ] |
| 40 | + ), |
21 | 41 | validity_error=EOFException.INCOMPLETE_SECTION_NUMBER,
|
22 | 42 | ),
|
23 | 43 | Container(
|
24 | 44 | name="EOF1_embedded_container_invalid_2",
|
25 |
| - raw_bytes="ef00010100040200010006030001", |
| 45 | + raw_bytes=( |
| 46 | + [ |
| 47 | + 0xEF, 0x00, 0x01, # Version: 1 |
| 48 | + 0x01, 0x00, 0x04, # Types Length: 4 |
| 49 | + 0x02, 0x00, 0x01, # Code Sections (Length: 1) |
| 50 | + 0x00, 0x06, # Code Section 0 (Length: 6) |
| 51 | + # --- Error: Invalid Container Header ---# |
| 52 | + 0x03, |
| 53 | + 0x00, |
| 54 | + 0x01, |
| 55 | + ] |
| 56 | + ), |
26 | 57 | validity_error=EOFException.MISSING_HEADERS_TERMINATOR,
|
27 | 58 | ),
|
28 | 59 | Container(
|
29 | 60 | name="EOF1_embedded_container_invalid_3",
|
30 |
| - raw_bytes="ef0001010004020001000603000100", |
| 61 | + raw_bytes=( |
| 62 | + [ |
| 63 | + 0xEF, 0x00, 0x01, # Version: 1 |
| 64 | + 0x01, 0x00, 0x04, # Types Length: 4 |
| 65 | + 0x02, 0x00, 0x01, # Code Sections (Length: 1) |
| 66 | + 0x00, 0x06, # Code Section 0 (Length: 6) |
| 67 | + # --- Error: Invalid Container Header ---# |
| 68 | + 0x03, |
| 69 | + 0x00, |
| 70 | + 0x01, |
| 71 | + 0x00, |
| 72 | + ] |
| 73 | + ), |
31 | 74 | validity_error=EOFException.INCOMPLETE_SECTION_SIZE,
|
32 | 75 | ),
|
33 | 76 | Container(
|
34 | 77 | name="EOF1_embedded_container_invalid_4",
|
35 |
| - raw_bytes="ef000101000402000100060300010014", |
| 78 | + raw_bytes=( |
| 79 | + [ |
| 80 | + 0xEF, 0x00, 0x01, # Version: 1 |
| 81 | + 0x01, 0x00, 0x04, # Types Length: 4 |
| 82 | + 0x02, 0x00, 0x01, # Code Sections (Length: 1) |
| 83 | + 0x00, 0x06, # Code Section 0 (Length: 6) |
| 84 | + 0x03, 0x00, 0x01, # Container Sections (Length: 1) |
| 85 | + 0x00, 0x00, |
| 86 | + 0x00, 0x14, # Container Section 0 (Length: 20) |
| 87 | + # --- Error: Invalid Data Header ---# |
| 88 | + ] |
| 89 | + ), |
36 | 90 | validity_error=EOFException.MISSING_HEADERS_TERMINATOR,
|
37 | 91 | ),
|
38 | 92 | Container(
|
39 | 93 | name="EOF1_embedded_container_invalid_5",
|
40 |
| - raw_bytes="ef00010100040200010006030000040000000080000160005d000000", |
| 94 | + raw_bytes=( |
| 95 | + [ |
| 96 | + 0xEF, 0x00, 0x01, # Version: 1 |
| 97 | + 0x01, 0x00, 0x04, # Types Length: 4 |
| 98 | + 0x02, 0x00, 0x01, # Code Sections (Length: 1) |
| 99 | + 0x00, 0x06, # Code Section 0 (Length: 6) |
| 100 | + # --- Error: Invalid Container Header ---# |
| 101 | + 0x03, |
| 102 | + 0x00, |
| 103 | + 0x00, |
| 104 | + 0xFF, |
| 105 | + 0x00, |
| 106 | + 0x00, |
| 107 | + 0x00, |
| 108 | + 0x00, |
| 109 | + 0x80, |
| 110 | + 0x00, |
| 111 | + 0x01, |
| 112 | + 0x60, |
| 113 | + 0x00, |
| 114 | + 0xE1, |
| 115 | + 0x00, |
| 116 | + 0x00, |
| 117 | + 0x00, |
| 118 | + ] |
| 119 | + ), |
41 | 120 | validity_error=EOFException.ZERO_SECTION_SIZE,
|
42 | 121 | ),
|
43 | 122 | Container(
|
44 | 123 | name="EOF1_embedded_container_invalid_6",
|
45 |
| - raw_bytes="ef000101000402000100060300010000040000000080000160005d000000", |
| 124 | + sections=[ |
| 125 | + Section.Code( |
| 126 | + code=Op.PUSH1[0] + Op.RJUMPI[0] + Op.STOP, |
| 127 | + max_stack_height=1, |
| 128 | + ), |
| 129 | + Section.Container( |
| 130 | + container=Container( |
| 131 | + name="EOFV1_0001", |
| 132 | + raw_bytes=([]), # Empty subcontainer |
| 133 | + ) |
| 134 | + ), |
| 135 | + ], |
46 | 136 | validity_error=EOFException.ZERO_SECTION_SIZE,
|
47 | 137 | ),
|
48 | 138 | Container(
|
49 | 139 | name="EOF1_embedded_container_invalid_7",
|
50 |
| - raw_bytes="ef000101000402000100060300010014040000000080000160005d000000", |
| 140 | + raw_bytes=( |
| 141 | + [ |
| 142 | + 0xEF, 0x00, 0x01, # Version: 1 |
| 143 | + 0x01, 0x00, 0x04, # Types Length: 4 |
| 144 | + 0x02, 0x00, 0x01, # Code Sections (Length: 1) |
| 145 | + 0x00, 0x06, # Code Section 0 (Length: 6) |
| 146 | + 0x03, 0x00, 0x01, # Container Sections (Length: 1) |
| 147 | + 0x00, 0x00, |
| 148 | + 0x00, 0x14, # Container Section 0 (Length: 20) |
| 149 | + 0xFF, 0x00, 0x00, # Data Length: 0 |
| 150 | + 0x00, # Terminator |
| 151 | + # Code Section 0 types |
| 152 | + 0x00, # Inputs: 0 |
| 153 | + 0x80, # Outputs: 0 (Non-returning function) |
| 154 | + 0x00, 0x01, # Max Stack Height: 1 |
| 155 | + # Code Section 0 |
| 156 | + 0x60,0x00, # [0] PUSH1(0) |
| 157 | + 0xE1,0x00,0x00, # [2] RJUMPI(0) |
| 158 | + 0x00, # [5] STOP |
| 159 | + # --- Error: Invalid Container Content ---# |
| 160 | + ] |
| 161 | + ), |
51 | 162 | validity_error=EOFException.INVALID_SECTION_BODIES_SIZE,
|
52 | 163 | ),
|
53 | 164 | Container(
|
54 | 165 | name="EOF1_embedded_container_invalid_8",
|
55 |
| - raw_bytes="ef0001010004020001000603010100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001040000000080000160005d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", |
| 166 | + sections=[ |
| 167 | + Section.Code( |
| 168 | + code=Op.PUSH1[0] + Op.RJUMPI[0] + Op.STOP, |
| 169 | + max_stack_height=1, |
| 170 | + ), |
| 171 | + ] + [ |
| 172 | + Section.Container( |
| 173 | + container=Container( |
| 174 | + raw_bytes=([0x00]), |
| 175 | + ) |
| 176 | + ), |
| 177 | + ] * 257, |
56 | 178 | validity_error=EOFException.TOO_MANY_CONTAINERS,
|
57 | 179 | ),
|
58 | 180 | ],
|
|
0 commit comments