vyperlang / vyper

Pythonic Smart Contract Language for the EVM
https://vyperlang.org
Other
4.87k stars 799 forks source link

"Invalid Jump Destination" #1091

Closed haydenadams closed 5 years ago

haydenadams commented 5 years ago

I've noticed that ever since switching to a vyper version using #901 the only error I get (on transactions that should fail) is eth.exceptions.InvalidJumpDestination: Invalid Jump Destination

Here is my testing setup: https://github.com/Uniswap/contracts-vyper/blob/master/tests/conftest.py

Version Information

Error Output:

test_eth_to_token.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../env/lib/python3.6/site-packages/web3/eth.py:263: in sendTransaction
    get_buffered_gas_estimate(self.web3, transaction),
../../env/lib/python3.6/site-packages/web3/utils/transactions.py:84: in get_buffered_gas_estimate
    gas_estimate = web3.eth.estimateGas(gas_estimate_transaction)
../../env/lib/python3.6/site-packages/web3/eth.py:304: in estimateGas
    [transaction],
../../env/lib/python3.6/site-packages/web3/manager.py:107: in request_blocking
    response = self._make_request(method, params)
../../env/lib/python3.6/site-packages/web3/manager.py:90: in _make_request
    return request_func(method, params)
../../env/lib/python3.6/site-packages/web3/middleware/gas_price_strategy.py:18: in middleware
    return make_request(method, params)
cytoolz/functoolz.pyx:232: in cytoolz.functoolz.curry.__call__
    ???
../../env/lib/python3.6/site-packages/web3/middleware/formatting.py:48: in apply_formatters
    response = make_request(method, formatted_params)
../../env/lib/python3.6/site-packages/web3/middleware/attrdict.py:18: in middleware
    response = make_request(method, params)
cytoolz/functoolz.pyx:232: in cytoolz.functoolz.curry.__call__
    ???
../../env/lib/python3.6/site-packages/web3/middleware/formatting.py:48: in apply_formatters
    response = make_request(method, formatted_params)
../../env/lib/python3.6/site-packages/web3/middleware/normalize_errors.py:9: in middleware
    result = make_request(method, params)
cytoolz/functoolz.pyx:232: in cytoolz.functoolz.curry.__call__
    ???
../../env/lib/python3.6/site-packages/web3/middleware/formatting.py:48: in apply_formatters
    response = make_request(method, formatted_params)
cytoolz/functoolz.pyx:232: in cytoolz.functoolz.curry.__call__
    ???
../../env/lib/python3.6/site-packages/web3/middleware/formatting.py:48: in apply_formatters
    response = make_request(method, formatted_params)
../../env/lib/python3.6/site-packages/web3/providers/eth_tester/middleware.py:320: in middleware
    return make_request(method, [filled_transaction] + params[1:])
../../env/lib/python3.6/site-packages/web3/middleware/fixture.py:12: in middleware
    return make_request(method, params)
cytoolz/functoolz.pyx:232: in cytoolz.functoolz.curry.__call__
    ???
../../env/lib/python3.6/site-packages/web3/middleware/formatting.py:48: in apply_formatters
    response = make_request(method, formatted_params)
../../env/lib/python3.6/site-packages/web3/providers/eth_tester/main.py:46: in make_request
    response = delegator(self.ethereum_tester, params)
cytoolz/functoolz.pyx:232: in cytoolz.functoolz.curry.__call__
    ???
../../env/lib/python3.6/site-packages/web3/providers/eth_tester/defaults.py:36: in call_eth_tester
    return getattr(eth_tester, fn_name)(*fn_args, **fn_kwargs)
../../env/lib/python3.6/site-packages/eth_tester/main.py:445: in estimate_gas
    raw_gas_estimate = self.backend.estimate_gas(raw_transaction)
../../env/lib/python3.6/site-packages/eth_tester/utils/formatting.py:85: in wrapper
    return to_wrap(*args, **kwargs)
../../env/lib/python3.6/site-packages/eth_tester/backends/pyevm/main.py:511: in estimate_gas
    return self.chain.estimate_gas(spoofed_transaction)
../../env/lib/python3.6/site-packages/eth/chains/base.py:615: in estimate_gas
    return self.gas_estimator(state, transaction)
cytoolz/functoolz.pyx:232: in cytoolz.functoolz.curry.__call__
    ???
../../env/lib/python3.6/site-packages/eth/estimators/gas.py:65: in binary_gas_search
    raise error
../../env/lib/python3.6/site-packages/eth/vm/computation.py:560: in apply_computation
    opcode_fn(computation=computation)
../../env/lib/python3.6/site-packages/eth/vm/opcode.py:49: in wrapped_logic_fn
    return logic_fn(computation)

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

computation = <eth.vm.forks.byzantium.computation.ByzantiumComputation object at 0x10fcc6400>

    def jumpi(computation):
        jump_dest, check_value = computation.stack_pop(num_items=2, type_hint=constants.UINT256)

        if check_value:
            computation.code.pc = jump_dest

            next_opcode = computation.code.peek()

            if next_opcode != JUMPDEST:
>               raise InvalidJumpDestination("Invalid Jump Destination")
E               eth.exceptions.InvalidJumpDestination: Invalid Jump Destination

../../env/lib/python3.6/site-packages/eth/vm/logic/flow.py:39: InvalidJumpDestination
jacqueswww commented 5 years ago

@haydenadams does this occur on assert statements? I think this is probably related to our get_revert function if so: https://github.com/ethereum/vyper/blob/master/vyper/compile_lll.py#L30

haydenadams commented 5 years ago

@jacqueswww It occurs on failing web3 function calls that are not constant.

haydenadams commented 5 years ago

@jacqueswww wait sorry I misunderstood. You mean Vyper asserts not pytest asserts.

Yeah I think thats the case.

jacqueswww commented 5 years ago

After a lot of digging, I have figured out what is causing this. Doing an invalid jump, was the old method of throwing in a contract, before REVERT came to be. create_with_code_of still uses this type of exception after the delegatcall returns a failure. So here are the steps to fix this issue: