You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The AST node HexBytes is used to represent byte arrays in the Vyper AST, similar to the Bytes node, but with a hexadecimal representation. There should be no reason to have different behavior for these two nodes, but the HexBytes node is not always handled in the same way as the Bytes node.
In convert.py::_literal_int(), there are no paths to handle the HexBytes node, which means that upon converting a HexBytes node to an integer (convert(x'0102', uint256)), the compiler will fail with CompilerPanic: unreachable. Furthermore, in case the out type is signed, the HexBytes value would not sign-extend if the first issue was fixed.
def_literal_int(expr, arg_typ, out_typ):
# TODO: possible to reuse machinery from expr.py?ifisinstance(expr, vy_ast.Hex):
val=int(expr.value, 16)
elifisinstance(expr, vy_ast.Bytes): # Missing HexBytesval=int.from_bytes(expr.value, "big")
elifisinstance(expr, (vy_ast.Int, vy_ast.Decimal, vy_ast.NameConstant)):
val=expr.valueelse: # pragma: no coverraiseCompilerPanic("unreachable")
# Missing HexBytesifisinstance(expr, (vy_ast.Hex, vy_ast.Bytes)) andout_typ.is_signed:
val=_signextend(expr, val, arg_typ)
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:
In the len builtin defined in functions.py, a special path to constant fold Bytes nodes is defined, but not for HexBytes nodes. This means that the following code will not be folded:
@externaldeffoo():
a: uint256=len(x'0102')
The text was updated successfully, but these errors were encountered:
Version Information
vyper --version
): b635696What's your issue about?
Per @trocher
The AST node
HexBytes
is used to represent byte arrays in the Vyper AST, similar to theBytes
node, but with a hexadecimal representation. There should be no reason to have different behavior for these two nodes, but theHexBytes
node is not always handled in the same way as theBytes
node.convert.py::_literal_int()
, there are no paths to handle theHexBytes
node, which means that upon converting aHexBytes
node to an integer (convert(x'0102', uint256)
), the compiler will fail withCompilerPanic: unreachable
. Furthermore, in case the out type is signed, theHexBytes
value would not sign-extend if the first issue was fixed.convert.py::_literal_decimal()
, in case the out type is signed, theHexBytes
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:len
builtin defined infunctions.py
, a special path to constant foldBytes
nodes is defined, but not forHexBytes
nodes. This means that the following code will not be folded:The text was updated successfully, but these errors were encountered: