Python z3.unsat() Examples
The following are 5
code examples of z3.unsat().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
z3
, or try the search function
.
Example #1
Source File: simplifications.py From miasm with GNU General Public License v2.0 | 5 votes |
def check(expr_in, expr_out): """Check that expr_in is always equals to expr_out""" print("Ensure %s = %s" % (expr_in, expr_out)) solver = z3.Solver() solver.add(trans.from_expr(expr_in) != trans.from_expr(expr_out)) result = solver.check() if result != z3.unsat: print("ERROR: a counter-example has been founded:") model = solver.model() print(model) print("Reinjecting in the simplifier:") to_rep = {} expressions = expr_in.get_r().union(expr_out.get_r()) for expr in expressions: value = model.eval(trans.from_expr(expr)) if hasattr(value, "as_long"): new_val = ExprInt(value.as_long(), expr.size) else: raise RuntimeError("Unable to reinject %r" % value) to_rep[expr] = new_val new_expr_in = expr_in.replace_expr(to_rep) new_expr_out = expr_out.replace_expr(to_rep) print("Check %s = %s" % (new_expr_in, new_expr_out)) simp_in = expr_simp_explicit(new_expr_in) simp_out = expr_simp_explicit(new_expr_out) print("[%s] %s = %s" % (simp_in == simp_out, simp_in, simp_out)) # Either the simplification does not stand, either the test is wrong raise RuntimeError("Bad simplification")
Example #2
Source File: svm.py From ilf with Apache License 2.0 | 5 votes |
def trim_unrechable_states(self): # (parent, trace, child) tuples pending_parent_trace_child_tuples = [(None, None, self.root_wstate)] deleted_counter = 0 s = Solver() while(len(pending_parent_trace_child_tuples)): s.push() parent_wstate, trace, curr_wstate = pending_parent_trace_child_tuples.pop() if curr_wstate.status != WorldStateStatus.REACHABLE: s.add(curr_wstate.constraints) res = s.check() if res == sat: curr_wstate.status = WorldStateStatus.REACHABLE elif res == unsat: curr_wstate.status = WorldStateStatus.UNREACHABLE elif res == z3.unknown: print(curr_wstate.get_full_trace()) raise Exception("pdb") if curr_wstate.status == WorldStateStatus.REACHABLE: if curr_wstate != self.root_wstate: parent_wstate.trace_to_children[trace].append(curr_wstate) for child_trace, children in curr_wstate.trace_to_children.items(): for child_wstate in children: pending_parent_trace_child_tuples.append((curr_wstate, child_trace, child_wstate)) curr_wstate.trace_to_children.clear() else: curr_wstate.status = WorldStateStatus.DELETED self.gen_to_wstates[curr_wstate.gen].remove(curr_wstate) deleted_counter += 1 s.pop() logging.info('%d WorldStates are deleted', deleted_counter) logging.info('SVM initialized')
Example #3
Source File: svm_utils.py From ilf with Apache License 2.0 | 5 votes |
def resolve_address(wstate, address_bv, frame_predicates=[]): if is_bv_concrete(address_bv): return get_concrete_int(address_bv) frame_constraints = [wstate.predicate_to_constraints[fpred] for fpred in frame_predicates] solver = z3.Solver() solver.set('timeout', 2000) solver.add(frame_constraints) res = solver.check() assert res != z3.unsat model = solver.model() address = model.evaluate(address_bv) if not is_bv_concrete(address): return None address = address.as_long() return address if address in wstate.address_to_account else None
Example #4
Source File: svm_utils.py From ilf with Apache License 2.0 | 5 votes |
def check_wstate_reachable(wstate, timeout=None): s = z3.Solver() if timeout is not None: s.set('timeout', timeout) s.add(wstate.constraints) res = s.check() if res != z3.unsat: return True else: logging.debug(f'deleted wstate {wstate.trace}; len constraints:{len(wstate.constraints)}') return False
Example #5
Source File: Z3.py From jeeves with MIT License | 5 votes |
def isSatisfiable(self): r = self.solver.check() if r == z3.sat: return True elif r == z3.unsat: return False else: raise ValueError("got neither sat nor unsat from solver")