Skip to content

codegen panic when converting literal bytes to decimal #4604

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

Open
cyberthirst opened this issue Apr 25, 2025 · 1 comment
Open

codegen panic when converting literal bytes to decimal #4604

cyberthirst opened this issue Apr 25, 2025 · 1 comment
Labels
needs triage needs triage

Comments

@cyberthirst
Copy link
Collaborator

Version Information

  • vyper Version (output of vyper --version): b635696

What's your issue about?

Per @trocher
when calling _literal_decimal(), the compiler will crash:

@_input_types(IntegerT, BoolT, BytesM_T, BytesT)
def to_decimal(expr, arg, out_typ):
    _check_bytes(expr, arg, out_typ, 32)

    if isinstance(expr, vy_ast.Constant):
        return _literal_decimal(expr, arg.typ, out_typ)
    ...

This happens as trying to construct a Decimal from a bytes is not supported:

val = decimal.Decimal(expr.value)  # should work for Int, Decimal

The following code lead the compiler to panic:

# pragma enable-decimals
@external
def foo():
    a: decimal = convert(b'\x01\x02', decimal)
    b: decimal = convert(x'0102', decimal)
@cyberthirst cyberthirst added the needs triage needs triage label Apr 25, 2025
@cyberthirst
Copy link
Collaborator Author

this issue should not be fixed before: #4608

this is because:

Similarly, in convert.py::_literal_decimal(), in case the out type is signed, the HexBytes value is not sign-extended, note that in the current state of the codebase, this is not reachable because of Codegen panic when Converting literal bytes to decimal:
if isinstance(expr, (vy_ast.Hex, vy_ast.Bytes)) and out_typ.is_signed:
val = _signextend(expr, val, arg_typ)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage needs triage
Projects
None yet
Development

No branches or pull requests

1 participant