|
7 | 7 | from ethereum_test_tools.vm.opcode import Opcodes as Op
|
8 | 8 |
|
9 | 9 | from .. import EOF_FORK_NAME
|
| 10 | +from ..eip4750_functions.test_code_validation import MAX_RUNTIME_OPERAND_STACK_HEIGHT |
10 | 11 |
|
11 | 12 | REFERENCE_SPEC_GIT_PATH = "EIPS/eip-6206.md"
|
12 | 13 | REFERENCE_SPEC_VERSION = "2f365ea0cd58faa6e26013ea77ce6d538175f7d0"
|
@@ -136,3 +137,46 @@ def test_returning_section_aborts_jumpf(
|
136 | 137 | ],
|
137 | 138 | )
|
138 | 139 | eof_test(container=container)
|
| 140 | + |
| 141 | + |
| 142 | +@pytest.mark.parametrize("stack_height", [512, 513, 1023]) |
| 143 | +def test_jumpf_self_stack_overflow(eof_test: EOFTestFiller, stack_height: int): |
| 144 | + """Test JUMPF instruction jumping to itself causing validation time stack overflow.""" |
| 145 | + container = Container( |
| 146 | + sections=[ |
| 147 | + Section.Code( |
| 148 | + code=(Op.PUSH0 * stack_height) + Op.JUMPF[0], |
| 149 | + max_stack_height=stack_height, |
| 150 | + ), |
| 151 | + ], |
| 152 | + ) |
| 153 | + stack_overflow = stack_height > MAX_RUNTIME_OPERAND_STACK_HEIGHT // 2 |
| 154 | + eof_test( |
| 155 | + container=container, |
| 156 | + expect_exception=EOFException.STACK_OVERFLOW if stack_overflow else None, |
| 157 | + ) |
| 158 | + |
| 159 | + |
| 160 | +@pytest.mark.parametrize("stack_height_other", [1, 2, 512, 513, 1023]) |
| 161 | +@pytest.mark.parametrize("stack_height", [1, 2, 512, 513, 1023]) |
| 162 | +def test_jumpf_other_stack_overflow( |
| 163 | + eof_test: EOFTestFiller, stack_height: int, stack_height_other: int |
| 164 | +): |
| 165 | + """Test JUMPF instruction jumping to itself causing validation time stack overflow.""" |
| 166 | + container = Container( |
| 167 | + sections=[ |
| 168 | + Section.Code( |
| 169 | + code=(Op.PUSH0 * stack_height) + Op.JUMPF[1], |
| 170 | + max_stack_height=stack_height, |
| 171 | + ), |
| 172 | + Section.Code( |
| 173 | + code=(Op.PUSH0 * stack_height_other) + Op.STOP, |
| 174 | + max_stack_height=stack_height_other, |
| 175 | + ), |
| 176 | + ], |
| 177 | + ) |
| 178 | + stack_overflow = stack_height + stack_height_other > MAX_RUNTIME_OPERAND_STACK_HEIGHT |
| 179 | + eof_test( |
| 180 | + container=container, |
| 181 | + expect_exception=EOFException.STACK_OVERFLOW if stack_overflow else None, |
| 182 | + ) |
0 commit comments