From 98288da43cc8c48a49cdf64d550d7628f7373699 Mon Sep 17 00:00:00 2001 From: Nikhil Parasaram Date: Thu, 27 Sep 2018 02:24:31 +0530 Subject: [PATCH] optimize memory by copy on write --- .../modules/dependence_on_predictable_vars.py | 2 +- mythril/laser/ethereum/state.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mythril/analysis/modules/dependence_on_predictable_vars.py b/mythril/analysis/modules/dependence_on_predictable_vars.py index 370a8db2..ed377938 100644 --- a/mythril/analysis/modules/dependence_on_predictable_vars.py +++ b/mythril/analysis/modules/dependence_on_predictable_vars.py @@ -48,7 +48,7 @@ def execute(statespace): found = [] for var in vars: - for constraint in call.node.constraints + [call.to]: + for constraint in call.node.constraints[:] + [call.to]: if var in str(constraint): found.append(var) diff --git a/mythril/laser/ethereum/state.py b/mythril/laser/ethereum/state.py index 21da6e47..40acce37 100644 --- a/mythril/laser/ethereum/state.py +++ b/mythril/laser/ethereum/state.py @@ -147,6 +147,7 @@ class Constraints(list): def append(self, constraint): self.__possibility = None super(Constraints, self).append(constraint) + self.solver = copy(self.solver) self.solver.add(constraint) def pop(self, index=-1): @@ -154,19 +155,18 @@ class Constraints(list): def __copy__(self): constraint_list = super(Constraints, self).copy() - solver = self.solver.translate(self.solver.ctx) - return Constraints(constraint_list, solver, self.__possibility) + return Constraints(constraint_list, self.solver, self.__possibility) def __deepcopy__(self, memodict={}): constraint_list = super(Constraints, self).copy() - solver = self.solver.translate(self.solver.ctx) - return Constraints(constraint_list, solver) + return Constraints(constraint_list, self.solver, self.__possibility) def __add__(self, constraints): - """ - Implement constraint concatenation if needed - """ - raise NotImplementedError + constraints_list = super(Constraints, self).__add__(constraints) + new_solver = copy(self.solver) + for constraint in constraints: + new_solver.add(constraint) + return Constraints(constraint_list=constraints_list, solver=new_solver) def __iadd__(self, other): """