Vyper: Mistake of Compiler

Created on 7 Jan 2020  路  6Comments  路  Source: vyperlang/vyper

Version Information

  • vyper Version (output of vyper --version): 0.1.0b14+commit.c9f6162
  • OS: OSX
  • Python Version (output of python --version): 3.6.2
  • Environment (output of pip freeze):
    asn1crypto==1.2.0
    asttokens==2.0.3
    attrs==19.3.0
    cffi==1.13.2
    coincurve==13.0.0
    coverage==5.0.1
    cytoolz==0.10.1
    eth-hash==0.2.0
    eth-typing==2.2.1
    eth-utils==1.8.4
    ethereum==2.3.1
    future==0.18.2
    importlib-metadata==1.3.0
    more-itertools==8.0.2
    mypy-extensions==0.4.3
    packaging==19.2
    pbkdf2==1.3
    pluggy==0.13.1
    py==1.8.1
    py-ecc==1.7.1
    pycparser==2.19
    pycryptodome==3.9.4
    pyethash==0.1.27
    pyparsing==2.4.6
    pysha3==1.0.2
    pytest==5.3.2
    pytest-cov==2.5.1
    PyYAML==5.2
    repoze.lru==0.7
    rlp==1.2.0
    scrypt==0.8.13
    six==1.13.0
    toolz==0.10.0
    vyper==0.1.0b14
    wcwidth==0.1.8
    zipp==0.6.0

    What's your issue about?

I have a contract like below:

Please include information like:

MAX_SUBS: constant(uint256) = 32
FEE_POOL: constant(wei_value) = 100000000000000000 # 0.1 ETH
STAKE_VALUE: constant(wei_value) = 3200000000000000000 # 3.2 ETH

lockUpBalance: wei_value
feeBalance: wei_value
owner: public(address)

@public
def __init__():
    self.owner = msg.sender


@public
@constant
def getFeePool() -> wei_value:  
    return self.feeBalance

@public
@constant
def getLockUpPool() -> wei_value: 
    return self.lockUpBalance
  • full output of the error you received
Traceback (most recent call last):
  File "/Users/trnhgquan/vyper-venv/bin/vyper", line 8, in <module>
    sys.exit(_parse_cli_args())
  File "/Users/trnhgquan/vyper-venv/lib/python3.6/site-packages/vyper/cli/vyper_compile.py", line 57, in _parse_cli_args
    return _parse_args(sys.argv[1:])
  File "/Users/trnhgquan/vyper-venv/lib/python3.6/site-packages/vyper/cli/vyper_compile.py", line 127, in _parse_args
    args.show_gas_estimates
  File "/Users/trnhgquan/vyper-venv/lib/python3.6/site-packages/vyper/cli/vyper_compile.py", line 241, in compile_files
    interface_codes=get_interface_codes(root_path, contract_sources)
  File "/Users/trnhgquan/vyper-venv/lib/python3.6/site-packages/vyper/compiler.py", line 333, in compile_codes
    exc_handler(contract_name, exc)
  File "/Users/trnhgquan/vyper-venv/lib/python3.6/site-packages/vyper/cli/vyper_compile.py", line 159, in exc_handler
    raise exception
  File "/Users/trnhgquan/vyper-venv/lib/python3.6/site-packages/vyper/compiler.py", line 329, in compile_codes
    source_id=source_id
  File "/Users/trnhgquan/vyper-venv/lib/python3.6/site-packages/vyper/compiler.py", line 225, in _mk_bytecode_output
    return '0x' + __compile(code, interface_codes=interface_codes).hex()
  File "/Users/trnhgquan/vyper-venv/lib/python3.6/site-packages/vyper/compiler.py", line 50, in __compile
    runtime_only=kwargs.get('bytecode_runtime', False)
  File "/Users/trnhgquan/vyper-venv/lib/python3.6/site-packages/vyper/parser/parser.py", line 203, in parse_tree_to_lll
    o, otherfuncs, sigs, external_contracts, origcode, global_ctx, defaultfunc, runtime_only
  File "/Users/trnhgquan/vyper-venv/lib/python3.6/site-packages/vyper/parser/parser.py", line 127, in parse_other_functions
    parse_function(_def, {**{'self': sigs}, **external_contracts}, origcode, global_ctx)
  File "/Users/trnhgquan/vyper-venv/lib/python3.6/site-packages/vyper/parser/function_definitions/parse_function.py", line 79, in parse_function
    context=context,
  File "/Users/trnhgquan/vyper-venv/lib/python3.6/site-packages/vyper/parser/function_definitions/parse_public_function.py", line 280, in parse_public_function
    ] + nonreentrant_post + [['stop']]
  File "/Users/trnhgquan/vyper-venv/lib/python3.6/site-packages/vyper/parser/function_definitions/parse_public_function.py", line 278, in <listcomp>
    for c
  File "/Users/trnhgquan/vyper-venv/lib/python3.6/site-packages/vyper/parser/stmt.py", line 1013, in parse_body
    return parse_stmt(code, context)
  File "/Users/trnhgquan/vyper-venv/lib/python3.6/site-packages/vyper/parser/stmt.py", line 1007, in parse_stmt
    return Stmt(stmt, context).lll_node
  File "/Users/trnhgquan/vyper-venv/lib/python3.6/site-packages/vyper/parser/stmt.py", line 91, in __init__
    self.lll_node = self.stmt_table[stmt_type]()
  File "/Users/trnhgquan/vyper-venv/lib/python3.6/site-packages/vyper/parser/stmt.py", line 809, in parse_return
    if not SizeLimits.in_bounds(self.context.return_type.typ, sub.value):
  File "/Users/trnhgquan/vyper-venv/lib/python3.6/site-packages/vyper/utils.py", line 117, in in_bounds
    return 0 <= value <= cls.MAX_UINT256
TypeError: '<=' not supported between instances of 'int' and 'str'
  • what command you ran: vyper contract.vy
  • the code that caused the failure (see this link for help with formatting code)

How can it be fixed?

  • When i remove constant variable (comments by #) or remove 2 function getFeePool, getLockUpPool, the issues will dissapear and compiler work. Its so weird.
    Fill this in if you know how to fix it.
bug

Most helpful comment

The issue seems to be related to the use of wei_value as a tyoe on the storage variables. I'm able to compile the contract by making the following change to lines 5-6:

lockUpBalance: uint256(wei)
feeBalance: uint256(wei)

Thanks for letting us know, I will investigate further.

All 6 comments

The issue seems to be related to the use of wei_value as a tyoe on the storage variables. I'm able to compile the contract by making the following change to lines 5-6:

lockUpBalance: uint256(wei)
feeBalance: uint256(wei)

Thanks for letting us know, I will investigate further.

Quite strange indeed; must be an oversight in testing units as well. Closest I found was:
https://github.com/vyperlang/vyper/blob/65d17e6b1ec38b5803493b54fd76212b742ea9c4/tests/parser/globals/test_getters.py#L31

@iamdefinitelyahuman this works for me, maybe that helps your digging?

MAX_SUBS: constant(uint256) = 32
FEE_POOL: constant(uint256(wei)) = 100000000000000000 # 0.1 ETH
STAKE_VALUE: constant(uint256(wei)) = 3200000000000000000 # 3.2 ETH

lockUpBalance: uint256(wei)
feeBalance: uint256(wei)
owner: public(address)

@public
def __init__():
    self.owner = msg.sender


@public
@constant
def getFeePool() -> uint256(wei):  
    a: uint256(wei) = self.feeBalance
    return a

@public
@constant
def getLockUpPool() -> uint256(wei): 
    return self.lockUpBalance



Thank you @iamdefinitelyahuman and @jacqueswww . If wei_value & uint256(wei) is the same, I think should remove wei_value in the future.

Agreed removing wei_value is something I support.

Was this page helpful?
0 / 5 - 0 ratings