Closed 0xalpharush closed 2 years ago
Hi @0xalpharush .
Thank you for reporting this. What version of solc and slither are you using? (solc --version
, slither --version
)
When I run Slither 0.8.0, with solc 0.7.6 or solc 0.8.0, I don't have the issue on:
library CastU128I128 {
/// @dev Safely cast an uint128 to an int128
function i128(uint128 x) internal pure returns (int128 y) {
require (x <= uint128(type(int128).max), "Cast overflow");
y = int128(x);
}
}
contract Example {
using CastU128I128 for uint128;
function f(uint128 bar) public{
int128 foo = bar.i128();
}
}
@montyly These results are with Slither 0.8.0 and solc 0.8.1 but I confirmed the error on solc 0.8.0 as well. The example I gave is poor for which I apologize; it works in isolation but didn't work when running slither on the entire repo where this pattern is implemented. I confirmed the function i128
is the cause of the error by adding {ir.function_name}
to the exception output as I noted above.
You can find the contracts here: https://github.com/code-423n4/2021-08-yield/tree/main/contracts
Thanks @0xalpharush. I can reproduce the bug locally, and I will look into it
Hey @montyly, curious if this was ever resolved. I'm seeing the same thing when running slither v0.8.1 against this repo: https://github.com/code-423n4/2021-11-malt
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/slither/core/cfg/node.py", line 902, in _find_read_write_call
self._high_level_calls.append((ir.destination.type.type, ir.function))
AttributeError: 'NoneType' object has no attribute 'type'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/slither/__main__.py", line 741, in main_impl
) = process_all(filename, args, detector_classes, printer_classes)
File "/usr/local/lib/python3.9/site-packages/slither/__main__.py", line 83, in process_all
) = process_single(compilation, args, detector_classes, printer_classes)
File "/usr/local/lib/python3.9/site-packages/slither/__main__.py", line 66, in process_single
slither = Slither(target, ast_format=ast, **vars(args))
File "/usr/local/lib/python3.9/site-packages/slither/slither.py", line 107, in __init__
parser.analyze_contracts()
File "/usr/local/lib/python3.9/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 393, in analyze_contracts
self._convert_to_slithir()
File "/usr/local/lib/python3.9/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 570, in _convert_to_slithir
func.generate_slithir_and_analyze()
File "/usr/local/lib/python3.9/site-packages/slither/core/declarations/function.py", line 1676, in generate_slithir_and_analyze
node.slithir_generation()
File "/usr/local/lib/python3.9/site-packages/slither/core/cfg/node.py", line 714, in slithir_generation
self._find_read_write_call()
File "/usr/local/lib/python3.9/site-packages/slither/core/cfg/node.py", line 905, in _find_read_write_call
raise SlitherException(
slither.exceptions.SlitherException: Function not found on TMP_4873(None) = HIGH_LEVEL_CALL, dest:REF_2187(None), function:add, arguments:['balance'] . Please try compiling with a recent Solidity version. 'NoneType' object has no attribute 'type'
Error:
Function not found on TMP_4873(None) = HIGH_LEVEL_CALL, dest:REF_2187(None), function:add, arguments:['balance'] . Please try compiling with a recent Solidity version. 'NoneType' object has no attribute 'type'
I ran into the same error as #667 when running slither on a contract that uses a casting library.
Library
Example usage
I was able to bypass this by checking that
ir.destination.type is not None
incore/cfg/node.py
, but I don't imagine this is an acceptable fix. https://github.com/crytic/slither/blob/master/slither/core/cfg/node.py#L902It was helpful to add
ir.function_name
to the error message for debugging as the temporary name is arbitrary.I'm not sure what would be involved in fixing this, but I will give it a shot if a maintainer could provide insight.