Skip to content

CompilerPanic if as_wei_value is passed a numeric type other than uint256, uint8, int128, decimal #3281

@trocher

Description

@trocher

Version Information

  • vyper Version (output of vyper --version): 0.3.8+commit.d76c6ed2
  • OS: OSX
  • Python Version (output of python --version): 3.8.0

What's your issue about?

Although as_wei_value accepts any numeric types, its build_IR function only defines logic for uint256, uint8, int128 and decimal leading the compiler to panic for other numeric types.

For example, compiling the following contract leads to the given output.

@external
def test()->uint256:
    fd:int16 = 1
    x:uint256 = as_wei_value(fd, "kether")
    return x
Traceback (most recent call last):
  File "tester/tester.py", line 28, in <module>
    do()
  File "tester/tester.py", line 23, in do
    abi_a, bytecode_a,_ = compile(code)
  File "tester/tester.py", line 8, in compile
    res = vyper.compile_code(
  File "/Users/trocher/Documents/thesis/vyper/vyper/compiler/__init__.py", line 192, in compile_code
    return compile_codes(
  File "/Users/trocher/Documents/thesis/vyper/vyper/evm/opcodes.py", line 226, in _wrapper
    return fn(*args, **kwargs)
  File "/Users/trocher/Documents/thesis/vyper/vyper/compiler/__init__.py", line 143, in compile_codes
    raise exc
  File "/Users/trocher/Documents/thesis/vyper/vyper/compiler/__init__.py", line 138, in compile_codes
    out[contract_name][output_format] = OUTPUT_FORMATS[output_format](compiler_data)
  File "/Users/trocher/Documents/thesis/vyper/vyper/compiler/output.py", line 248, in build_bytecode_output
    return f"0x{compiler_data.bytecode.hex()}"
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/functools.py", line 966, in __get__
    val = self.func(instance)
  File "/Users/trocher/Documents/thesis/vyper/vyper/compiler/phases.py", line 150, in bytecode
    self.assembly, is_runtime=False, no_bytecode_metadata=self.no_bytecode_metadata
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/functools.py", line 966, in __get__
    val = self.func(instance)
  File "/Users/trocher/Documents/thesis/vyper/vyper/compiler/phases.py", line 141, in assembly
    return generate_assembly(self.ir_nodes, self.no_optimize)
  File "/Users/trocher/Documents/thesis/vyper/vyper/compiler/phases.py", line 126, in ir_nodes
    ir, ir_runtime, sigs = self._ir_output
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/functools.py", line 966, in __get__
    val = self.func(instance)
  File "/Users/trocher/Documents/thesis/vyper/vyper/compiler/phases.py", line 122, in _ir_output
    return generate_ir_nodes(self.global_ctx, self.no_optimize)
  File "/Users/trocher/Documents/thesis/vyper/vyper/compiler/phases.py", line 258, in generate_ir_nodes
    ir_nodes, ir_runtime, function_sigs = module.generate_ir_for_module(global_ctx)
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/module.py", line 162, in generate_ir_for_module
    runtime, internal_functions = _runtime_ir(runtime_functions, all_sigs, global_ctx)
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/module.py", line 103, in _runtime_ir
    func_ir = generate_ir_for_function(func_ast, all_sigs, global_ctx, skip_nonpayable_check)
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/function_definitions/common.py", line 62, in generate_ir_for_function
    o = generate_ir_for_external_function(code, sig, context, skip_nonpayable_check)
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/function_definitions/external_function.py", line 199, 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 414, in parse_body
    ir = parse_stmt(stmt, context)
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/stmt.py", line 388, in parse_stmt
    return Stmt(stmt, context).ir_node
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/stmt.py", line 40, in __init__
    self.ir_node = fn()
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/stmt.py", line 67, in parse_AnnAssign
    rhs = Expr(self.stmt.value, self.context).ir_node
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/expr.py", line 77, in __init__
    self.ir_node = fn()
  File "/Users/trocher/Documents/thesis/vyper/vyper/codegen/expr.py", line 632, in parse_Call
    return DISPATCH_TABLE[function_name].build_IR(self.expr, self.context)
  File "/Users/trocher/Documents/thesis/vyper/vyper/builtins/_signatures.py", line 72, in decorator_fn
    return wrapped_fn(self, node, subs, kwsubs, context)
  File "/Users/trocher/Documents/thesis/vyper/vyper/builtins/functions.py", line 1075, in build_IR
    raise CompilerPanic(f"Unexpected type: {value.typ}")
vyper.exceptions.CompilerPanic: Unexpected type: uint16

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

How can it be fixed?

Extending the buildIR function for all numeric types should fix the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug - type 0compiler halts or panics instead of generating code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions