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

[bug]:version 0.9.1 crashes "AttributeError: 'NoneType' object has no attribute 'context'" related to using for/ constant folding #1467

Open
thedavidmeister opened this issue Nov 13, 2022 · 3 comments
Labels
bug Something isn't working High Priority

Comments

@thedavidmeister
Copy link

Describe the issue:

slither can't compile my code errors with "AttributeError: 'NoneType' object has no attribute 'context'"

this is with version 0.9.1

the stacktrace from slither is too cryptic to me to figure out which contract or why it is caused

Code example to reproduce the issue:

issue is visible on this CI run https://github.com/beehive-innovation/rain-protocol/actions/runs/3456654052/jobs/5769538607

Version:

0.9.1

Relevant log output:

https://github.com/beehive-innovation/rain-protocol/actions/runs/3456654052/jobs/5769538607
@thedavidmeister thedavidmeister added the bug-candidate Bugs reports that are not yet confirmed label Nov 13, 2022
@0xalpharush
Copy link
Contributor

Thanks for opening a bug report! This likely has to do with "using for" imports e.g. using LibStackTop for uint256[], using LibUint256Array for uint256[]. We are working on improving support for this feature #1378.

packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 627, in _analyze_struct_events
    contract.analyze_using_for()
  File "/nix/store/c4dqipmm3hpf0386zx4i56sysmmp47zj-python3.10-slither-analyzer-0.9.1/lib/python3.10/site-packages/slither/solc_parsing/declarations/contract.py", line 586, in analyze_using_for
    type_name = parse_type(using_for["typeName"], self)
  File "/nix/store/c4dqipmm3hpf0386zx4i56sysmmp47zj-python3.10-slither-analyzer-0.9.1/lib/python3.10/site-packages/slither/solc_parsing/solidity_types/type_parsing.py", line 426, in parse_type
    return ArrayType(array_type, length)
  File "/nix/store/c4dqipmm3hpf0386zx4i56sysmmp47zj-python3.10-slither-analyzer-0.9.1/lib/python3.10/site-packages/slither/core/solidity_types/array_type.py", line 22, in __init__
    cf = ConstantFolding(length, "uint256")
  File "/nix/store/c4dqipmm3hpf0386zx4i56sysmmp47zj-python3.10-slither-analyzer-0.9.1/lib/python3.10/site-packages/slither/visitors/expression/constants_folding.py", line 27, in __init__
    super().__init__(expression)
  File "/nix/store/c4dqipmm3hpf0386zx4i56sysmmp47zj-python3.10-slither-analyzer-0.9.1/lib/python3.10/site-packages/slither/visitors/expression/expression.py", line 30, in __init__
    self._visit_expression(self.expression)
  File "/nix/store/c4dqipmm3hpf0386zx4i56sysmmp47zj-python3.10-slither-analyzer-0.9.1/lib/python3.10/site-packages/slither/visitors/expression/expression.py", line 48, in _visit_expression
    self._visit_binary_operation(expression)
  File "/nix/store/c4dqipmm3hpf0[386](https://github.com/beehive-innovation/rain-protocol/actions/runs/3456654052/jobs/5769538607#step:4:387)zx4i56sysmmp47zj-python3.10-slither-analyzer-0.9.1/lib/python3.10/site-packages/slither/visitors/expression/expression.py", line 104, in _visit_binary_operation
    self._visit_expression(expression.expression_left)
  File "/nix/store/c4dqipmm3hpf0386zx4i56sysmmp47zj-python3.10-slither-analyzer-0.9.1/lib/python3.10/site-packages/slither/visitors/expression/expression.py", line 95, in _visit_expression
    self._post_visit(expression)
  File "/nix/store/c4dqipmm3hpf0386zx4i56sysmmp47zj-python3.10-slither-analyzer-0.9.1/lib/python3.10/site-packages/slither/visitors/expression/expression.py", line 280, in _post_visit
    self._post_identifier(expression)
  File "/nix/store/c4dqipmm3hpf0386zx4i56sysmmp47zj-python3.10-slither-analyzer-0.9.1/lib/python3.10/site-packages/slither/visitors/expression/constants_folding.py", line 39, in _post_identifier
    expr = cf.result()
  File "/nix/store/c4dqipmm3hpf0386zx4i56sysmmp47zj-python3.10-slither-analyzer-0.9.1/lib/python3.10/site-packages/slither/visitors/expression/constants_folding.py", line 30, in result
    return Literal(int(get_val(self._expression)), self._type)
  File "/nix/store/c4dqipmm3hpf0386zx4i56sysmmp47zj-python3.10-slither-analyzer-0.9.1/lib/python3.10/site-packages/slither/visitors/expression/constants_folding.py", line 14, in get_val
    val = expression.context[KEY]
AttributeError: 'NoneType' object has no attribute 'context'

@0xalpharush 0xalpharush added bug Something isn't working and removed bug-candidate Bugs reports that are not yet confirmed labels Nov 14, 2022
@0xalpharush 0xalpharush changed the title [Bug-Candidate]: version 0.9.1 crashes "AttributeError: 'NoneType' object has no attribute 'context'" [bug]:version 0.9.1 crashes "AttributeError: 'NoneType' object has no attribute 'context'" related to using for/ constant folding Nov 14, 2022
@0xalpharush
Copy link
Contributor

The first issue pertains to this code where a top level variable is not yet analyzed but accessed during _analyze_struct_events. If the call to _analyze_top_level_variables is moved prior, it works.

However, there's a second issue:

File "/Users/alpharush/tob/slither/slither/solc_parsing/solidity_types/type_parsing.py", line 194, in _find_from_type_name
  raise ParsingError("Type not found " + str(name))
slither.solc_parsing.exceptions.ParsingError: Type not found Operand
Error:
Type not found Operand

This is caused by accessing a type alias in a top level struct . Since the structure isn't associated with a contract, it doesn't have any type aliases in its scope to lookup here.

@thedavidmeister
Copy link
Author

thanks for looking into this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working High Priority
Projects
None yet
Development

No branches or pull requests

2 participants