From 2f17fea1a58caf5f249665c348cf963b3778e1f6 Mon Sep 17 00:00:00 2001 From: Josselin Date: Thu, 3 Jan 2019 17:33:19 +0000 Subject: [PATCH] Factor _unroll for slithIR call operator --- slither/slithir/operations/call.py | 9 ++++++++ slither/slithir/operations/event_call.py | 10 +-------- slither/slithir/operations/high_level_call.py | 11 +--------- slither/slithir/operations/init_array.py | 21 ++++++++++--------- slither/slithir/operations/internal_call.py | 11 +--------- .../operations/internal_dynamic_call.py | 12 +---------- slither/slithir/operations/low_level_call.py | 2 +- slither/slithir/operations/new_array.py | 11 +--------- slither/slithir/operations/new_contract.py | 11 +--------- slither/slithir/operations/new_structure.py | 11 +--------- slither/slithir/operations/solidity_call.py | 2 +- 11 files changed, 29 insertions(+), 82 deletions(-) diff --git a/slither/slithir/operations/call.py b/slither/slithir/operations/call.py index 25d929c92..79dd35613 100644 --- a/slither/slithir/operations/call.py +++ b/slither/slithir/operations/call.py @@ -15,3 +15,12 @@ class Call(Operation): def arguments(self, v): self._arguments = v + # 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 diff --git a/slither/slithir/operations/event_call.py b/slither/slithir/operations/event_call.py index 0c7214d60..991af2cfa 100644 --- a/slither/slithir/operations/event_call.py +++ b/slither/slithir/operations/event_call.py @@ -14,15 +14,7 @@ class EventCall(Call): @property def read(self): - def unroll(l): - ret = [] - for x in l: - if not isinstance(x, list): - ret += [x] - else: - ret += unroll(x) - return ret - return unroll(self.arguments) + return self._unroll(self.arguments) def __str__(self): args = [str(a) for a in self.arguments] diff --git a/slither/slithir/operations/high_level_call.py b/slither/slithir/operations/high_level_call.py index fd54a1113..bdc0e5359 100644 --- a/slither/slithir/operations/high_level_call.py +++ b/slither/slithir/operations/high_level_call.py @@ -58,16 +58,7 @@ class HighLevelCall(Call, OperationWithLValue): @property def read(self): - # if array inside the parameters - def unroll(l): - ret = [] - for x in l: - if not isinstance(x, list): - ret += [x] - else: - ret += unroll(x) - return ret - all_read = [self.destination, self.call_gas, self.call_value] + unroll(self.arguments) + all_read = [self.destination, self.call_gas, self.call_value] + self._unroll(self.arguments) # remove None return [x for x in all_read if x] diff --git a/slither/slithir/operations/init_array.py b/slither/slithir/operations/init_array.py index e85299dba..bf5f543b5 100644 --- a/slither/slithir/operations/init_array.py +++ b/slither/slithir/operations/init_array.py @@ -21,18 +21,19 @@ class InitArray(OperationWithLValue): self._init_values = init_values self._lvalue = lvalue + # if array inside the init values + def _unroll(self, l): + ret = [] + for x in l: + if not isinstance(x, list): + ret += [x] + else: + ret += self._unroll(x) + return ret + @property def read(self): - # if array inside the init values - def unroll(l): - ret = [] - for x in l: - if not isinstance(x, list): - ret += [x] - else: - ret += unroll(x) - return ret - return unroll(self.init_values) + return self._unroll(self.init_values) @property def init_values(self): diff --git a/slither/slithir/operations/internal_call.py b/slither/slithir/operations/internal_call.py index 606059ca6..0af0de2ff 100644 --- a/slither/slithir/operations/internal_call.py +++ b/slither/slithir/operations/internal_call.py @@ -16,16 +16,7 @@ class InternalCall(Call, OperationWithLValue): @property def read(self): - # if array inside the parameters - def unroll(l): - ret = [] - for x in l: - if not isinstance(x, list): - ret += [x] - else: - ret += unroll(x) - return ret - return list(unroll(self.arguments)) + return list(self._unroll(self.arguments)) @property def function(self): diff --git a/slither/slithir/operations/internal_dynamic_call.py b/slither/slithir/operations/internal_dynamic_call.py index 5e40d3e57..258c644a5 100644 --- a/slither/slithir/operations/internal_dynamic_call.py +++ b/slither/slithir/operations/internal_dynamic_call.py @@ -19,17 +19,7 @@ class InternalDynamicCall(Call, OperationWithLValue): @property def read(self): - # if array inside the parameters - def unroll(l): - ret = [] - for x in l: - if not isinstance(x, list): - ret += [x] - else: - ret += unroll(x) - return ret - - return unroll(self.arguments) + [self.function] + return self._unroll(self.arguments) + [self.function] @property def function(self): diff --git a/slither/slithir/operations/low_level_call.py b/slither/slithir/operations/low_level_call.py index 4f6bf6f34..a55482ad7 100644 --- a/slither/slithir/operations/low_level_call.py +++ b/slither/slithir/operations/low_level_call.py @@ -52,7 +52,7 @@ class LowLevelCall(Call, OperationWithLValue): def read(self): all_read = [self.destination, self.call_gas, self.call_value] + self.arguments # remove None - return [x for x in all_read if x] + return self._unroll([x for x in all_read if x]) @property def destination(self): diff --git a/slither/slithir/operations/new_array.py b/slither/slithir/operations/new_array.py index 213a5c487..94fbc5ced 100644 --- a/slither/slithir/operations/new_array.py +++ b/slither/slithir/operations/new_array.py @@ -18,16 +18,7 @@ class NewArray(Call, OperationWithLValue): @property def read(self): - # if array inside the parameters - def unroll(l): - ret = [] - for x in l: - if not isinstance(x, list): - ret += [x] - else: - ret += unroll(x) - return ret - return unroll(self.arguments) + return self._unroll(self.arguments) @property def depth(self): diff --git a/slither/slithir/operations/new_contract.py b/slither/slithir/operations/new_contract.py index 0646a70db..7326a659e 100644 --- a/slither/slithir/operations/new_contract.py +++ b/slither/slithir/operations/new_contract.py @@ -39,16 +39,7 @@ class NewContract(Call, OperationWithLValue): @property def read(self): - # if array inside the parameters - def unroll(l): - ret = [] - for x in l: - if not isinstance(x, list): - ret += [x] - else: - ret += unroll(x) - return ret - return unroll(self.arguments) + return self._unroll(self.arguments) def __str__(self): value = '' diff --git a/slither/slithir/operations/new_structure.py b/slither/slithir/operations/new_structure.py index 302ac7ff6..9005a227a 100644 --- a/slither/slithir/operations/new_structure.py +++ b/slither/slithir/operations/new_structure.py @@ -17,16 +17,7 @@ class NewStructure(Call, OperationWithLValue): @property def read(self): - # if array inside the parameters - def unroll(l): - ret = [] - for x in l: - if not isinstance(x, list): - ret += [x] - else: - ret += unroll(x) - return ret - return unroll(self.arguments) + return self._unroll(self.arguments) @property def structure(self): diff --git a/slither/slithir/operations/solidity_call.py b/slither/slithir/operations/solidity_call.py index 070a70b46..93e62d4d5 100644 --- a/slither/slithir/operations/solidity_call.py +++ b/slither/slithir/operations/solidity_call.py @@ -16,7 +16,7 @@ class SolidityCall(Call, OperationWithLValue): @property def read(self): - return list(self.arguments) + return self._unroll(self.arguments) @property def function(self):