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]: Echidna printer fails with certain constants #2577

Open
elopez opened this issue Oct 7, 2024 · 0 comments
Open

[Bug]: Echidna printer fails with certain constants #2577

elopez opened this issue Oct 7, 2024 · 0 comments
Labels
bug-candidate Bugs reports that are not yet confirmed

Comments

@elopez
Copy link
Member

elopez commented Oct 7, 2024

Describe the issue:

With the example code, the Echidna printer fails. Removing the "-1" fixes it but the type inference also seems off (it says the constant is an uint112 while A is uint256?). Replacing the value of A by a numeric constant also fixes it.

Code example to reproduce the issue:

contract C {
  uint256 constant A = type(uint112).max;

  function f() public returns (uint256) {
    return A - 1;
  }
}

Version:

0.10.4

Relevant log output:

% slither foo.sol --print echidna
...
Traceback (most recent call last):
  File "/opt/homebrew/bin/slither", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/homebrew/Cellar/slither-analyzer/0.10.4/libexec/lib/python3.12/site-packages/slither/__main__.py", line 776, in main
    main_impl(all_detector_classes=detectors, all_printer_classes=printers)
  File "/opt/homebrew/Cellar/slither-analyzer/0.10.4/libexec/lib/python3.12/site-packages/slither/__main__.py", line 882, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/slither-analyzer/0.10.4/libexec/lib/python3.12/site-packages/slither/__main__.py", line 107, in process_all
    ) = process_single(compilation, args, detector_classes, printer_classes)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/slither-analyzer/0.10.4/libexec/lib/python3.12/site-packages/slither/__main__.py", line 87, in process_single
    return _process(slither, detector_classes, printer_classes)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/slither-analyzer/0.10.4/libexec/lib/python3.12/site-packages/slither/__main__.py", line 143, in _process
    printer_results = slither.run_printers()
                      ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/slither-analyzer/0.10.4/libexec/lib/python3.12/site-packages/slither/slither.py", line 302, in run_printers
    return [p.output(self._crytic_compile.target).data for p in self._printers]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/slither-analyzer/0.10.4/libexec/lib/python3.12/site-packages/slither/printers/guidance/echidna.py", line 428, in output
    (cst_used, cst_used_in_binary) = _extract_constants(contracts)
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/slither-analyzer/0.10.4/libexec/lib/python3.12/site-packages/slither/printers/guidance/echidna.py", line 259, in _extract_constants
    _extract_constants_from_irs(
  File "/opt/homebrew/Cellar/slither-analyzer/0.10.4/libexec/lib/python3.12/site-packages/slither/printers/guidance/echidna.py", line 201, in _extract_constants_from_irs
    cst = ConstantFolding(ir.expression, type_).result()
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/slither-analyzer/0.10.4/libexec/lib/python3.12/site-packages/slither/visitors/expression/constants_folding.py", line 52, in __init__
    super().__init__(expression)
  File "/opt/homebrew/Cellar/slither-analyzer/0.10.4/libexec/lib/python3.12/site-packages/slither/visitors/expression/expression.py", line 59, in __init__
    self._visit_expression(self.expression)
  File "/opt/homebrew/Cellar/slither-analyzer/0.10.4/libexec/lib/python3.12/site-packages/slither/visitors/expression/expression.py", line 76, in _visit_expression
    visitor(expression)
  File "/opt/homebrew/Cellar/slither-analyzer/0.10.4/libexec/lib/python3.12/site-packages/slither/visitors/expression/expression.py", line 87, in _visit_binary_operation
    self._visit_expression(expression.expression_left)
  File "/opt/homebrew/Cellar/slither-analyzer/0.10.4/libexec/lib/python3.12/site-packages/slither/visitors/expression/expression.py", line 78, in _visit_expression
    self._post_visit(expression)
  File "/opt/homebrew/Cellar/slither-analyzer/0.10.4/libexec/lib/python3.12/site-packages/slither/visitors/expression/expression.py", line 267, in _post_visit
    self._post_identifier(expression)
  File "/opt/homebrew/Cellar/slither-analyzer/0.10.4/libexec/lib/python3.12/site-packages/slither/visitors/expression/constants_folding.py", line 84, in _post_identifier
    assert isinstance(expr, Literal)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
@elopez elopez added the bug-candidate Bugs reports that are not yet confirmed label Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-candidate Bugs reports that are not yet confirmed
Projects
None yet
Development

No branches or pull requests

2 participants
@elopez and others