Skip to content

Commit adfdd10

Browse files
authored
Merge pull request #1447 from ipsilon/eof/stack_height_constants
refactor(tests): Rename stack height constants
2 parents 3b3522f + df66f95 commit adfdd10

File tree

57 files changed

+122
-192
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+122
-192
lines changed

src/ethereum_test_tools/eof/__init__.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/ethereum_test_tools/eof/constants.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/ethereum_test_tools/eof/v1/__init__.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/ethereum_test_tools/eof/v1/constants.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/ethereum_test_types/eof/constants.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,10 @@
2020
"""
2121
Length of the version byte.
2222
"""
23+
24+
MAX_RUNTIME_STACK_HEIGHT = 1024
25+
"""
26+
Maximum height of the EVM runtime operand stack.
27+
Exceeding this value during execution will result in the stack overflow exception.
28+
This value applies to both legacy EVM and EOF.
29+
"""

src/ethereum_test_types/eof/v1/constants.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313

1414
MAX_RETURN_STACK_HEIGHT = 1024
1515

16-
MAX_OPERAND_STACK_HEIGHT = 1023
16+
MAX_STACK_INCREASE_LIMIT = 0x3FF
17+
"""
18+
Maximum value for the max stack increase accepted by the EOF format.
19+
"""
1720

1821
MAX_CODE_INPUTS = 127
1922

tests/cancun/eip1153_tstore/test_tstorage_clear_after_tx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
Initcode,
1818
Transaction,
1919
)
20-
from ethereum_test_tools.eof.v1 import Container
2120
from ethereum_test_tools.vm.opcode import Opcodes as Op
21+
from ethereum_test_types.eof.v1 import Container
2222

2323
from .spec import ref_spec_1153
2424

tests/osaka/eip7692_eof_v1/eip3540_eof_v1/test_all_opcodes_in_container.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
from ethereum_test_tools import EOFException, EOFTestFiller, Opcode, UndefinedOpcodes
99
from ethereum_test_tools import Opcodes as Op
10-
from ethereum_test_tools.eof.v1 import Container, ContainerKind, Section
11-
from ethereum_test_tools.eof.v1.constants import MAX_OPERAND_STACK_HEIGHT
10+
from ethereum_test_types.eof.constants import MAX_RUNTIME_STACK_HEIGHT
11+
from ethereum_test_types.eof.v1 import Container, ContainerKind, Section
12+
from ethereum_test_types.eof.v1.constants import MAX_STACK_INCREASE_LIMIT
1213
from ethereum_test_vm import Bytecode
1314

1415
from .. import EOF_FORK_NAME
@@ -337,7 +338,7 @@ def test_all_opcodes_stack_overflow(
337338
opcode = opcode[0] if opcode.has_data_portion() else opcode
338339

339340
assert opcode.pushed_stack_items - opcode.popped_stack_items == 1
340-
opcode_count = MAX_OPERAND_STACK_HEIGHT + 1 - opcode.min_stack_height
341+
opcode_count = MAX_RUNTIME_STACK_HEIGHT - opcode.min_stack_height
341342

342343
bytecode = Op.PUSH0 * opcode.min_stack_height
343344
bytecode += opcode * opcode_count
@@ -347,7 +348,7 @@ def test_all_opcodes_stack_overflow(
347348

348349
if exception == EOFException.INVALID_MAX_STACK_INCREASE:
349350
# Lie about the max stack height to make the code be checked for stack overflow.
350-
kwargs["max_stack_height"] = MAX_OPERAND_STACK_HEIGHT
351+
kwargs["max_stack_height"] = MAX_STACK_INCREASE_LIMIT
351352

352353
sections = [Section.Code(**kwargs)]
353354

tests/osaka/eip7692_eof_v1/eip3540_eof_v1/test_container_size.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from ethereum_test_tools import EOFException, EOFTestFiller
66
from ethereum_test_tools import Opcodes as Op
7-
from ethereum_test_tools.eof.v1 import Container, Section
8-
from ethereum_test_tools.eof.v1.constants import MAX_INITCODE_SIZE
7+
from ethereum_test_types.eof.v1 import Container, Section
8+
from ethereum_test_types.eof.v1.constants import MAX_INITCODE_SIZE
99

1010
from .. import EOF_FORK_NAME
1111

tests/osaka/eip7692_eof_v1/eip3540_eof_v1/test_container_validation.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
import pytest
66

77
from ethereum_test_tools import EOFException, EOFTestFiller
8-
from ethereum_test_tools.eof.v1 import (
8+
from ethereum_test_tools.vm.opcode import Opcodes as Op
9+
from ethereum_test_types.eof.v1 import (
910
AutoSection,
1011
Container,
1112
ContainerKind,
1213
Section,
1314
SectionKind,
1415
)
15-
from ethereum_test_tools.eof.v1.constants import (
16+
from ethereum_test_types.eof.v1.constants import (
1617
MAX_CODE_INPUTS,
1718
MAX_CODE_OUTPUTS,
1819
MAX_CODE_SECTIONS,
19-
MAX_OPERAND_STACK_HEIGHT,
20+
MAX_STACK_INCREASE_LIMIT,
2021
)
21-
from ethereum_test_tools.vm.opcode import Opcodes as Op
2222

2323
from .. import EOF_FORK_NAME
2424

@@ -37,10 +37,10 @@
3737
name="single_code_section_max_stack_size",
3838
sections=[
3939
Section.Code(
40-
code=(Op.CALLER * MAX_OPERAND_STACK_HEIGHT)
41-
+ (Op.POP * MAX_OPERAND_STACK_HEIGHT)
40+
code=(Op.CALLER * MAX_STACK_INCREASE_LIMIT)
41+
+ (Op.POP * MAX_STACK_INCREASE_LIMIT)
4242
+ Op.STOP,
43-
max_stack_height=MAX_OPERAND_STACK_HEIGHT,
43+
max_stack_height=MAX_STACK_INCREASE_LIMIT,
4444
),
4545
],
4646
),

0 commit comments

Comments
 (0)