Skip to content
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

Unexpected exception in call trace generation of __default__ function #339

Open
Leminkay opened this issue Oct 28, 2024 · 0 comments
Open

Comments

@Leminkay
Copy link

Boa commit: f58c33cde50f6deaaeefff1136b18f92ef747c6b

Example:

import boa

name = "__default__"

code = f"""
@external
@pure
def {name}() -> uint256:
    raise
"""

ct = boa.loads(code)

try:
    res = getattr(ct, name)()
    print(res)
except Exception as e:
    print(e)

Reverting in the __default__ function will raise an exception:

Traceback (most recent call last):
  File "/home/lemy/otitanoboa/titanoboa/test_except.py", line 15, in <module>
    res = getattr(ct, name)()
  File "/home/lemy/otitanoboa/titanoboa/boa/contracts/vyper/vyper_contract.py", line 1075, in __call__
    return self.contract.marshal_to_python(computation, typ)
  File "/home/lemy/otitanoboa/titanoboa/boa/contracts/vyper/vyper_contract.py", line 782, in marshal_to_python
    self.handle_error(computation)
  File "/home/lemy/otitanoboa/titanoboa/boa/contracts/base_evm_contract.py", line 51, in handle_error
    raise strip_internal_frames(b) from b
  File "/home/lemy/otitanoboa/titanoboa/test_except.py", line 15, in <module>
    res = getattr(ct, name)()
boa.contracts.base_evm_contract.BoaError: <exception str() failed>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/lemy/otitanoboa/titanoboa/test_except.py", line 18, in <module>
    print(e)
  File "/home/lemy/otitanoboa/titanoboa/boa/contracts/base_evm_contract.py", line 132, in __str__
    call_tree = str(self.call_trace)
  File "/home/lemy/otitanoboa/titanoboa/boa/contracts/call_trace.py", line 97, in __str__
    text = f"{' ' * self.depth * 4}{self.text}"
  File "/home/lemy/otitanoboa/titanoboa/boa/contracts/call_trace.py", line 103, in text
    text = self.source.format(self.input_data, self.output, self.is_error)
  File "/home/lemy/otitanoboa/titanoboa/boa/contracts/call_trace.py", line 15, in format
    in_ = self._format_input(input_)
  File "/home/lemy/otitanoboa/titanoboa/boa/contracts/call_trace.py", line 25, in _format_input
    decoded = abi_decode(self.args_abi_type, input_)
  File "/usr/lib/python3.10/functools.py", line 981, in __get__
    val = self.func(instance)
  File "/home/lemy/otitanoboa/titanoboa/boa/contracts/vyper/vyper_contract.py", line 1135, in args_abi_type
    schema, fn_t = self._func_t_helper
  File "/usr/lib/python3.10/functools.py", line 981, in __get__
    val = self.func(instance)
  File "/home/lemy/otitanoboa/titanoboa/boa/contracts/vyper/vyper_contract.py", line 1123, in _func_t_helper
    method_id_int = int(self.method_id.hex(), 16)
ValueError: invalid literal for int() with base 16: ''

Meanwhile, using the non-default function will work as expected:

========================================================================
[E] [52] <unknown>.foo:5() <0x>
========================================================================

Revert(b'')

<<unknown> at 0x0880cf17Bd263d3d3a5c09D2D86cCecA3CcbD97c, compiled with vyper-0.4.0+e9db8d9>
 <compiler: user raise>

  function "foo", line 5:4 
       4 def foo() -> uint256:
  ---> 5     raise
  -----------^
       6

Provides an empty method_id for the default function and hence crashes.

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

No branches or pull requests

1 participant