vyperlang / titanoboa

a vyper interpreter
https://titanoboa.readthedocs.io
Other
242 stars 41 forks source link

KeyError: 'pc_pos_map' #191

Closed hollowgrahm closed 3 months ago

hollowgrahm commented 4 months ago

Error I get when running a test on an external function that accesses storage.

================================================================================================================== test session starts ==================================================================================================================
platform darwin -- Python 3.12.2, pytest-8.1.1, pluggy-1.4.0 -- /Users/madblocks/labs/boa/parimutuel/venv/bin/python3.12
cachedir: .pytest_cache
hypothesis profile 'default' -> 
![Screen Shot 2024-03-31 at 12 19 56 AM](https://github.com/vyperlang/titanoboa/assets/65835385/51ac5b03-192a-463b-9614-3067b191a518)
![Screen Shot 2024-03-31 at 12 19 56 AM](https://github.com/vyperlang/titanoboa/assets/65835385/ba3ecf1d-5b6c-40da-8a53-71e1bb0dd0e7)
database=DirectoryBasedExampleDatabase(PosixPath('/Users/madblocks/labs/boa/parimutuel/.hypothesis/examples'))
rootdir: /Users/madblocks/labs/boa/parimutuel
plugins: cov-5.0.0, titanoboa-0.1.9, hypothesis-6.99.13
collected 3 items                                                                                                                                                                                                                                       

tests/test_parimutuel.py::test_initial_state PASSED                                                                                                                                                                                               [ 33%]
tests/test_parimutuel.py::test_faucet PASSED                                                                                                                                                                                                      [ 66%]
tests/test_parimutuel.py::test_open_short FAILED                                                                                                                                                                                                  [100%]

======================================================================================================================= FAILURES ========================================================================================================================
____________________________________________________________________________________________________________________ test_open_short ____________________________________________________________________________________________________________________

parimutuel = <contracts/Parimutuel.vy at 0x3d06E92f20305D9a2D71a1D479E9EE22690Ae7E4, compiled with vyper-0.4.0b6+45959387>
<storage...0, short_shares=0, short_profits=0, long_tokens=0, long_shares=0, long_profits=0, user_balance={}, shorts={}, longs={}>
user = Address('0xA73d7cddCf77c00827459f986bf828999B58C6Fe')

    def test_open_short(parimutuel, user):
        position = parimutuel.shorts(user)

        assert parimutuel.user_balance(user) == 0
        assert position[ACTIVE] == False

        with boa.reverts("Not enough funds."):
>           parimutuel.open_short(MARGIN, LEVERAGE, sender=user)

tests/test_parimutuel.py:34: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
venv/lib/python3.12/site-packages/boa/contracts/vyper/vyper_contract.py:1010: in __call__
    return self.contract.marshal_to_python(computation, typ)
venv/lib/python3.12/site-packages/boa/contracts/vyper/vyper_contract.py:713: in marshal_to_python
    self.handle_error(computation)
venv/lib/python3.12/site-packages/boa/contracts/base_evm_contract.py:32: in handle_error
    raise BoaError(self.stack_trace(computation))
venv/lib/python3.12/site-packages/boa/contracts/vyper/vyper_contract.py:734: in stack_trace
    ret = StackTrace([ErrorDetail.from_computation(self, computation)])
venv/lib/python3.12/site-packages/boa/contracts/vyper/vyper_contract.py:232: in from_computation
    ast_source = contract.find_source_of(computation)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <contracts/Parimutuel.vy at 0x3d06E92f20305D9a2D71a1D479E9EE22690Ae7E4, compiled with vyper-0.4.0b6+45959387>
<storage...0, short_shares=0, short_profits=0, long_tokens=0, long_shares=0, long_profits=0, user_balance={}, shorts={}, longs={}>
computation = <abc.TitanoboaComputation object at 0x11367db80>, is_initcode = False

    def find_source_of(self, computation, is_initcode=False):
        if hasattr(computation, "vyper_source_pos"):
            # this is set by ir executor currently.
            return self.ast_map.get(computation.vyper_source_pos)

        code_stream = computation.code
>       pc_map = self.source_map["pc_pos_map"]
E       KeyError: 'pc_pos_map'

venv/lib/python3.12/site-packages/boa/contracts/vyper/vyper_contract.py:639: KeyError
=================================================================================================================== warnings summary ====================================================================================================================
tests/test_parimutuel.py: 25 warnings
  /Users/madblocks/labs/boa/parimutuel/venv/lib/python3.12/site-packages/vyper/ast/parse.py:238: DeprecationWarning: ast.Str is deprecated and will be removed in Python 3.14; use ast.Constant instead
    if isinstance(n, python_ast.Expr) and isinstance(n.value, python_ast.Str):

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================================================================================ short test summary info ================================================================================================================
FAILED tests/test_parimutuel.py::test_open_short - KeyError: 'pc_pos_map'
======================================================================================================= 1 failed, 2 passed, 25 warnings in 0.86s ========================================================================================================
charles-cooper commented 3 months ago

what version / commit of titanoboa and vyper is this?

Leminkay commented 3 months ago

Getting the same error for reverting executions on vyper-0.4.0 branch and vyper@v0.4.0b6. E.g. for a = 3 will throw an error, while for other inputs it will work correctly

import boa

test = """
@external
def foo(a: uint256) -> uint256:
    if a == 3:
        raise
    return a
"""

ct = boa.loads(test)
res = ct.foo(3)
print(res)
charles-cooper commented 3 months ago

@hollowgrahm @Leminkay should be fixed in 50ac0fa9f9b3744c283eb9e21447e8c1b83ccb1e. please re-open if you run into any more issues