[Bug]: AttributeError: 'NoneType' object has no attribute 'can_reenter'

1
closed
mehtaculous
mehtaculous
Posted 1 month ago

[Bug]: AttributeError: 'NoneType' object has no attribute 'can_reenter' #1253

Describe the issue:

I seem to be getting the following error message for contracts with custom revert errors that are declared inside an imported interface but the contract itself does not directly inherit from the interface:

Example: revert IContract.InvalidSender(...)

AttributeError: 'NoneType' object has no attribute 'can_reenter'

This error goes away when the custom revert is either declared directly inside the contract itself or inside an interface that it inherits from. Is there a possible fix for this without having to make either of the specified changes?

Code example to reproduce the issue:

pragma solidity 0.8.13;

interface IContract {
    error InvalidSender(address required, address provided);
}

import {IContract} from "../interfaces/IContract.sol";

contract Metadata {
    address immutable controller;
    mapping(uint256 => string) private tokenMetadata;

    constructor(address _controller) {
        controller = _controller;
    }

    function setURI(uint256 _id, string memory _uri) external {
        if (msg.sender != controller)
            revert IContract.InvalidSender({required: controller, provided: msg.sender});

        tokenMetadata[_id] = _uri;
    }
}

Version:

0.8.3

Relevant log output:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/slither/__main__.py", line 744, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/usr/local/lib/python3.9/site-packages/slither/__main__.py", line 87, in process_all
    ) = process_single(compilation, args, detector_classes, printer_classes)
  File "/usr/local/lib/python3.9/site-packages/slither/__main__.py", line 72, in process_single
    return _process(slither, detector_classes, printer_classes)
  File "/usr/local/lib/python3.9/site-packages/slither/__main__.py", line 113, in _process
    detector_results = slither.run_detectors()
  File "/usr/local/lib/python3.9/site-packages/slither/slither.py", line 201, in run_detectors
    results = [d.detect() for d in self._detectors]
  File "/usr/local/lib/python3.9/site-packages/slither/slither.py", line 201, in <listcomp>
    results = [d.detect() for d in self._detectors]
  File "/usr/local/lib/python3.9/site-packages/slither/detectors/abstract_detector.py", line 152, in detect
    for r in [output.data for output in self._detect()]:
  File "/usr/local/lib/python3.9/site-packages/slither/detectors/reentrancy/reentrancy_eth.py", line 93, in _detect
    super()._detect()
  File "/usr/local/lib/python3.9/site-packages/slither/detectors/reentrancy/reentrancy.py", line 303, in _detect
    self.detect_reentrancy(c)
  File "/usr/local/lib/python3.9/site-packages/slither/detectors/reentrancy/reentrancy.py", line 290, in detect_reentrancy
    self._explore(function.entry_point, [])
  File "/usr/local/lib/python3.9/site-packages/slither/detectors/reentrancy/reentrancy.py", line 282, in _explore
    self._explore(son, visited)
  File "/usr/local/lib/python3.9/site-packages/slither/detectors/reentrancy/reentrancy.py", line 282, in _explore
    self._explore(son, visited)
  File "/usr/local/lib/python3.9/site-packages/slither/detectors/reentrancy/reentrancy.py", line 282, in _explore
    self._explore(son, visited)
  File "/usr/local/lib/python3.9/site-packages/slither/detectors/reentrancy/reentrancy.py", line 267, in _explore
    contains_call = fathers_context.analyze_node(node, self)
  File "/usr/local/lib/python3.9/site-packages/slither/detectors/reentrancy/reentrancy.py", line 159, in analyze_node
    if detector.can_callback(ir):
  File "/usr/local/lib/python3.9/site-packages/slither/detectors/reentrancy/reentrancy.py", line 228, in can_callback
    return isinstance(ir, Call) and ir.can_reenter()
  File "/usr/local/lib/python3.9/site-packages/slither/slithir/operations/library_call.py", line 27, in can_reenter
    return self.function.can_reenter(callstack)
AttributeError: 'NoneType' object has no attribute 'can_reenter'
0xalpharush
0xalpharush
Created 1 month ago

I believe this is the same as https://github.com/crytic/slither/issues/1001. Thanks for providing a test case! That's very helpful