From b539a5f199f4333013116d94c1bc5cb72496fa2e Mon Sep 17 00:00:00 2001 From: Josselin Date: Fri, 8 Feb 2019 07:57:54 -0500 Subject: [PATCH] Add slithir.operation.unroll as a general util (slither.utils.utils). Use unroll on fix_phi operations --- slither/slithir/operations/operation.py | 12 ++++-------- slither/solc_parsing/declarations/function.py | 2 ++ slither/utils/utils.py | 8 ++++++++ 3 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 slither/utils/utils.py diff --git a/slither/slithir/operations/operation.py b/slither/slithir/operations/operation.py index 02e240644..b127bd715 100644 --- a/slither/slithir/operations/operation.py +++ b/slither/slithir/operations/operation.py @@ -1,6 +1,7 @@ import abc from slither.core.context.context import Context from slither.core.children.child_node import ChildNode +from slither.utils.utils import unroll class AbstractOperation(abc.ABC): @@ -30,11 +31,6 @@ class Operation(Context, ChildNode, AbstractOperation): return self.read # if array inside the parameters - def _unroll(self, l): - ret = [] - for x in l: - if not isinstance(x, list): - ret += [x] - else: - ret += self._unroll(x) - return ret + @staticmethod + def _unroll(l): + return unroll(l) diff --git a/slither/solc_parsing/declarations/function.py b/slither/solc_parsing/declarations/function.py index 7ad6c4ba7..73974cf07 100644 --- a/slither/solc_parsing/declarations/function.py +++ b/slither/solc_parsing/declarations/function.py @@ -29,6 +29,7 @@ from slither.visitors.expression.has_conditional import HasConditional from slither.core.declarations.contract import Contract from slither.slithir.variables import StateIRVariable, LocalIRVariable, Constant +from slither.utils.utils import unroll logger = logging.getLogger("FunctionSolc") @@ -971,6 +972,7 @@ class FunctionSolc(Function): idx = self.parameters.index(ir.lvalue.non_ssa_version) # find non ssa version of that index additional = [n.ir.arguments[idx] for n in self.reachable_from_nodes] + additional = unroll(additional) additional = [a for a in additional if not isinstance(a, Constant)] ir.rvalues = list(set(additional + ir.rvalues)) if isinstance(ir, PhiCallback): diff --git a/slither/utils/utils.py b/slither/utils/utils.py new file mode 100644 index 000000000..adb318a4b --- /dev/null +++ b/slither/utils/utils.py @@ -0,0 +1,8 @@ +def unroll(l): + ret = [] + for x in l: + if not isinstance(x, list): + ret += [x] + else: + ret += unroll(x) + return ret