Repository: crytic/slither

Issue:
[Bug]: Slither detects already triaged results
### Describe the issue:

Slither seems to be detecting issues that have already been triaged into the `slither.db.json` from time to time.
This makes it difficult to get consistent results between runs after triaging findings, and also generates false positives when running Slither in CI.

This could be related to the ID of the findings that is stored in the DB file, which seems to vary between runs.

### Code example to reproduce the issue:

Public sample to reproduce the issue with instructions here: https://github.com/balancer/balancer-v2-monorepo/pull/2514.

### Version:

`0.9.3`

### Relevant log output:

```shell
# Following the instructions in the PR mentioned above, this is the output after triaging all the results.
# Running slither two times in a row outputs different results:

juan@M16:~/prj/bal/pkg/solidity-utils$ yarn slither
Nothing to compile
INFO:Detectors:
LogExpMath.exp(int256) (contracts/math/LogExpMath.sol#146-281) performs a multiplication on the result of a division:
	- product = (product * a3) / ONE_20 (contracts/math/LogExpMath.sol#198)
	- product = (product * a4) / ONE_20 (contracts/math/LogExpMath.sol#202)
LogExpMath.exp(int256) (contracts/math/LogExpMath.sol#146-281) performs a multiplication on the result of a division:
	- product = (product * a3) / ONE_20 (contracts/math/LogExpMath.sol#198)
	- product = (product * a5) / ONE_20 (contracts/math/LogExpMath.sol#206)
LogExpMath.exp(int256) (contracts/math/LogExpMath.sol#146-281) performs a multiplication on the result of a division:
	- product = (product * a7) / ONE_20 (contracts/math/LogExpMath.sol#214)
	- product = (product * a8) / ONE_20 (contracts/math/LogExpMath.sol#218)
LogExpMath._ln(int256) (contracts/math/LogExpMath.sol#326-458) performs a multiplication on the result of a division:
	- a = (a * ONE_20) / a3 (contracts/math/LogExpMath.sol#372)
	- a = (a * ONE_20) / a4 (contracts/math/LogExpMath.sol#377)
LogExpMath._ln(int256) (contracts/math/LogExpMath.sol#326-458) performs a multiplication on the result of a division:
	- a = (a * ONE_20) / a5 (contracts/math/LogExpMath.sol#382)
	- a = (a * ONE_20) / a6 (contracts/math/LogExpMath.sol#387)
Reference: https://github.com/crytic/slither/wiki/Detector-Documentation#divide-before-multiply
INFO:Slither:. analyzed (72 contracts with 85 detectors), 5 result(s) found


juan@M16:~/prj/bal/pkg/solidity-utils$ yarn slither
Nothing to compile
INFO:Detectors:
LogExpMath.exp(int256) (contracts/math/LogExpMath.sol#146-281) performs a multiplication on the result of a division:
	- product = (product * a3) / ONE_20 (contracts/math/LogExpMath.sol#198)
	- product = (product * a5) / ONE_20 (contracts/math/LogExpMath.sol#206)
LogExpMath.exp(int256) (contracts/math/LogExpMath.sol#146-281) performs a multiplication on the result of a division:
	- product = (product * a4) / ONE_20 (contracts/math/LogExpMath.sol#202)
	- product = (product * a6) / ONE_20 (contracts/math/LogExpMath.sol#210)
LogExpMath.exp(int256) (contracts/math/LogExpMath.sol#146-281) performs a multiplication on the result of a division:
	- product = (product * a7) / ONE_20 (contracts/math/LogExpMath.sol#214)
	- product = (product * a8) / ONE_20 (contracts/math/LogExpMath.sol#218)
Reference: https://github.com/crytic/slither/wiki/Detector-Documentation#divide-before-multiply
INFO:Slither:. analyzed (72 contracts with 85 detectors), 3 result(s) found
juan@M16:~/prj/bal/pkg/solidity-utils$
```



Discussion:
I have the same issue, I hide all results by run triage mode and all saved in slither.db.json, however when I run slither again and again, each time gives me the issues and every run give me different result 
@amrshaban2005 Is it also with the divide before multiply detector or a different one?
> @amrshaban2005 Is it also with the divide before multiply detector or a different one?

@0xalpharush no, it happens with many different detectors like reentrancy-no-eth, unchecked-transfer, unused-return....etc
so don't think it related to specific detector
@0xalpharush Could you kindly provide me with any updates, please?

Resolving patch:
diff --git a/slither/detectors/statements/divide_before_multiply.py b/slither/detectors/statements/divide_before_multiply.py
--- a/slither/detectors/statements/divide_before_multiply.py
+++ b/slither/detectors/statements/divide_before_multiply.py
@@ -2,7 +2,7 @@
 Module detecting possible loss of precision due to divide before multiple
 """
 from collections import defaultdict
-from typing import DefaultDict, List, Set, Tuple
+from typing import DefaultDict, List, Tuple
 
 from slither.core.cfg.node import Node
 from slither.core.declarations.contract import Contract
@@ -63,7 +63,7 @@ def is_assert(node: Node) -> bool:
 
 # pylint: disable=too-many-branches
 def _explore(
-    to_explore: Set[Node], f_results: List[List[Node]], divisions: DefaultDict[LVALUE, List[Node]]
+    to_explore: List[Node], f_results: List[List[Node]], divisions: DefaultDict[LVALUE, List[Node]]
 ) -> None:
     explored = set()
     while to_explore:  # pylint: disable=too-many-nested-blocks
@@ -114,7 +114,7 @@ def _explore(
                 f_results.append(node_results)
 
         for son in node.sons:
-            to_explore.add(son)
+            to_explore.append(son)
 
 
 def detect_divide_before_multiply(
@@ -145,7 +145,7 @@ def detect_divide_before_multiply(
         # track all the division results (and the assignment of the division results)
         divisions: DefaultDict[LVALUE, List[Node]] = defaultdict(list)
 
-        _explore({function.entry_point}, f_results, divisions)
+        _explore([function.entry_point], f_results, divisions)
 
         for f_result in f_results:
             results.append((function, f_result))


Test patch: