Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler Panics When Overflowing the Memory #3631

Closed
trocher opened this issue Sep 29, 2023 · 1 comment
Closed

Compiler Panics When Overflowing the Memory #3631

trocher opened this issue Sep 29, 2023 · 1 comment
Labels
bug - type 0 compiler halts or panics instead of generating code bug - typechecker issue with typechecker

Comments

@trocher
Copy link
Contributor

trocher commented Sep 29, 2023

Version Information

  • vyper Version (output of vyper --version): 0.3.10rc3
  • OS: osx
  • Python Version (output of python --version): 3.11.4

What's your issue about?

Given some expression that overflows the memory, the compiler panics instead of exiting with some custom error.
For example, compiling the following contract results in vyper.exceptions.CompilerPanic: out of range.

@external
def bar():
    s: String[max_value(uint256)] = "a"
Error compiling: tests/customs/code.vy
Traceback (most recent call last):
  File "/Users/trocher/Documents/thesis/vyper/vyper/cli/vyper_compile.py", line 338, in <module>
    _parse_args(sys.argv[1:])
  File "/Users/trocher/Documents/thesis/vyper/vyper/cli/vyper_compile.py", line 185, in _parse_args
    compiled = compile_files(
               ^^^^^^^^^^^^^^
  File "/Users/trocher/Documents/thesis/vyper/vyper/cli/vyper_compile.py", line 321, in compile_files
    compiler_data = vyper.compile_codes(
                    ^^^^^^^^^^^^^^^^^^^^
  File "/Users/trocher/Documents/thesis/vyper/vyper/compiler/__init__.py", line 143, in compile_codes
    exc_handler(contract_name, exc)
  File "/Users/trocher/Documents/thesis/vyper/vyper/cli/vyper_compile.py", line 219, in exc_handler
    raise exception
  File "/Users/trocher/Documents/thesis/vyper/vyper/compiler/__init__.py", line 140, in compile_codes
    out[contract_name][output_format] = formatter(compiler_data)
                                        ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/trocher/Documents/thesis/vyper/vyper/compiler/output.py", line 82, in build_ir_output
    return compiler_data.ir_nodes
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/trocher/Documents/thesis/vyper/vyper/compiler/phases.py", line 160, in ir_nodes
    ir, ir_runtime = self._ir_output
                     ^^^^^^^^^^^^^^^
  File "/Users/trocher/.pyenv/versions/3.11.4/lib/python3.11/functools.py", line 1001, in __get__
    val = self.func(instance)
          ^^^^^^^^^^^^^^^^^^^
  File "/Users/trocher/Documents/thesis/vyper/vyper/compiler/phases.py", line 156, in _ir_output
    return generate_ir_nodes(self.global_ctx, self.settings.optimize)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/trocher/Documents/thesis/vyper/vyper/compiler/phases.py", line 294, in generate_ir_nodes
    ir_nodes, ir_runtime = module.generate_ir_for_module(global_ctx)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/module.py", line 427, in generate_ir_for_module
    selector_section = _selector_section_sparse(external_functions, global_ctx)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/module.py", line 266, in _selector_section_sparse
    entry_points, sig_of = _generate_external_entry_points(external_functions, global_ctx)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/module.py", line 94, in _generate_external_entry_points
    func_ir = generate_ir_for_function(code, global_ctx)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/function_definitions/common.py", line 133, in generate_ir_for_function
    kwarg_handlers, common = generate_ir_for_external_function(code, func_t, context)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/function_definitions/external_function.py", line 168, in generate_ir_for_external_function
    body += [parse_body(code.body, context, ensure_terminated=True)]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/stmt.py", line 444, in parse_body
    ir = parse_stmt(stmt, context)
         ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/stmt.py", line 418, in parse_stmt
    return Stmt(stmt, context).ir_node
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/stmt.py", line 41, in __init__
    self.ir_node = fn()
                   ^^^^
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/stmt.py", line 68, in parse_AnnAssign
    rhs = Expr(self.stmt.value, self.context).ir_node
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/expr.py", line 80, in __init__
    self.ir_node = fn()
                   ^^^^
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/expr.py", line 129, in parse_Str
    return self._make_bytelike(typ, bytez, bytez_length)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/expr.py", line 150, in _make_bytelike
    return IRnode.from_list(
           ^^^^^^^^^^^^^^^^^
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/ir_node.py", line 562, in from_list
    [cls.from_list(o, source_pos=source_pos) for o in obj[1:]],
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/ir_node.py", line 562, in <listcomp>
    [cls.from_list(o, source_pos=source_pos) for o in obj[1:]],
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/ir_node.py", line 562, in from_list
    [cls.from_list(o, source_pos=source_pos) for o in obj[1:]],
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/ir_node.py", line 562, in <listcomp>
    [cls.from_list(o, source_pos=source_pos) for o in obj[1:]],
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/ir_node.py", line 547, in from_list
    return cls(
           ^^^^
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/ir_node.py", line 147, in __init__
    _check(-(2**255) <= self.value < 2**256, "out of range")
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/ir_node.py", line 135, in _check
    raise CompilerPanic(str(err))
vyper.exceptions.CompilerPanic: out of range

This is an unhandled internal compiler error. Please create an issue on Github to notify the developers.
https://github.com/vyperlang/vyper/issues/new?template=bug.md
@charles-cooper charles-cooper added bug - codegen bug - type 0 compiler halts or panics instead of generating code bug - typechecker issue with typechecker and removed bug - codegen labels Sep 29, 2023
@charles-cooper
Copy link
Member

this was fixed in #3639 (the new behavior is to raise a MemoryAllocationException)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug - type 0 compiler halts or panics instead of generating code bug - typechecker issue with typechecker
Projects
None yet
Development

No branches or pull requests

2 participants