def ResetZ3(): z3._main_ctx = None z3.main_ctx() z3.set_param('smt.random_seed', random.SystemRandom().randint(0, sys.maxint)) z3.set_param('smt.mbqi.max_iterations', 10000) z3.set_param('smt.mbqi.max_cexs', 100)
def ResetZ3 (): z3._main_ctx = None z3.main_ctx() z3.set_param('auto_config', False) z3.set_param('smt.mbqi', True) z3.set_param('model.compact', True) z3.set_param('smt.pull_nested_quantifiers', True) z3.set_param('smt.mbqi.max_iterations', 10000) z3.set_param('smt.random_seed', random.SystemRandom().randint(0, sys.maxint))
def define_fun_to_lambda(env, cmd): converter = pyz3.Z3Converter(env, z3.main_ctx()) name, params, ret_sort, body = cmd.args zparams = [converter.convert(p) for p in params] zbody = converter.convert(body) res = z3.Lambda(zparams, zbody) return res
def _context(self): try: return self._tls.context except AttributeError: self._tls.context = z3.Context() if threading.current_thread( ).name != 'MainThread' else z3.main_ctx() return self._tls.context
def __init__(self, environment, logic=None): QuantifierEliminator.__init__(self) self.environment = environment self.logic = logic self.converter = Z3Converter(environment, z3.main_ctx()) self._cache = {} self._cache_term = {}
def is_sat(solver,f): solver.push() ctx = z3.main_ctx() z3.Z3_solver_assert(ctx.ref(), solver.solver, f.as_ast()) #solver.add(f) res = solver.check() != z3.unsat solver.pop() return res
def is_sat(solver, f): solver.push() ctx = z3.main_ctx() z3.Z3_solver_assert(ctx.ref(), solver.solver, f.as_ast()) #solver.add(f) res = solver.check() != z3.unsat solver.pop() return res
def __init__(self, name="horn", simplify_queries=True, ctx=z3.main_ctx(), env = None): self._ctx = ctx self._name = name self._rules = [] self._queries = [] self._rels_set = frozenset() self._rels = dict() self._sealed = True self._fp = None self._env = env self._simple_query = simplify_queries
def __init__( self, params: Params, formula_params: FormulaParamsZ3, ): super().__init__( params, FormulaParamsZ3( # translates the contexts, thus the formula and variables need not be created with the context # the z3 runner will use formula=formula_params.formula.translate(z3.main_ctx()) if formula_params.formula.ctx != z3.main_ctx() else formula_params.formula, variables=[ x.translate(z3.main_ctx()) if x.ctx != z3.main_ctx() else x for x in formula_params.variables ], )) # maps q to a solver that has a q-times conjunction asserted self._solver_map: Dict[int, Tuple[z3.Solver, List[z3.BitVecRef]]] = {}
def get_behaviour_change_dt_from_constraintset(solver, constraints, dt, ctx=z3.main_ctx()): times = { cs: cs.check_behaviour_change(solver, dt, ctx) for cs in constraints } times = {cs: time for cs, time in times.items() if time is not None} if len(times) > 0: minimum = min(times, key=times.get) return times[minimum], minimum.label else: return None, None
def main(): db = load_horn_db_from_file(sys.argv[1], z3.main_ctx()) print(db) print(db.get_rels()) print(db._rels) rel = db.get_rel("main@_bb723") lemma_stream = io.StringIO( "(=> (< main@_bb723_0_n 1) (>= (+ main@_bb723_4_n main@_bb723_5_n) 0))" ) lemma = rel.pysmt_parse_lemma(lemma_stream) print(lemma) print(lemma._content._asdict()) # import json # json.dumps(lemma._content._asdict()) return 0
def z3_translate(x, ctx): """ A version of z3.AstRef.translate that handles sorts and function declarations correctly""" if x.ctx == ctx: return x if isinstance(x, z3.BoolSortRef): return z3.BoolSort(ctx=ctx) if z3.is_arith_sort(x): if x.is_int(): return z3.IntSort(ctx=ctx) else: assert x.is_real() return z3.RealSort(ctx=ctx) if isinstance(x, z3.FuncDeclRef): sorts = [z3_translate(x.domain(i), ctx) for i in range(x.arity())] sorts.append(z3_translate(x.range(), ctx)) return z3.Function(x.name(), *sorts) if ctx is None: return x.translate(ctx=z3.main_ctx()) return x.translate(ctx)
def btn_stop_thread_clicked(self): if self.current_worker_thread and self.current_worker_thread.isRunning(): self.plugin.stop_analysis = True # woow hacky try: import z3 frames = sys._current_frames().values() for f in frames: if 'a0' in f.f_locals: #print("Found Z3 frame: {}".format(f.f_code)) c = f.f_locals['a0'] ctx = z3.main_ctx() ctx.ctx = c ctx.interrupt() break self.current_worker_thread.terminate() except: print("Ex: {}, {}".format(sys.exc_info(), frame.f_code)) #print("Bla 2") if self.current_worker_thread.isRunning(): print("Termination failed") else: print("Terminated thread")
z3strlib.z3str_regexunion_decl.argtypes = [] z3strlib.z3str_regexconcat_decl.restype = z3.FuncDecl z3strlib.z3str_regexconcat_decl.argtypes = [] z3strlib.z3str_unroll_decl.restype = z3.FuncDecl z3strlib.z3str_unroll_decl.argtypes = [] z3strlib.z3str_regexdigit_decl.restype = z3.FuncDecl z3strlib.z3str_regexdigit_decl.argtypes = [] z3strlib.z3str_register_vars.restype = None z3strlib.z3str_register_vars.argtypes = [z3.Ast] z3strlib.setAlphabet.restype = None z3strlib.setAlphabet.argtypes = [] z3strlib.setAlphabet7bit.restype = None z3strlib.setAlphabet7bit.argtypes = [] ## Set the default Z3py context to use z3str ctx = z3.main_ctx() ctx.ctx = z3strlib.z3str_context() z3strlib.setAlphabet7bit() ## Wrappers around the various z3str_*() functions in libz3str2.so def StringSort(): ctx = z3.main_ctx() sort = z3strlib.z3str_mk_string_sort() return z3.SortRef(sort, ctx) def RegexSort(): ctx = z3.main_ctx() sort = z3strlib.z3str_mk_regex_sort() return z3.SortRef(sort, ctx) def string_concat():
def ResetZ3 (seed): z3._main_ctx = None z3.main_ctx() z3.set_param('smt.random_seed', seed)
def ResetZ3(seed): z3._main_ctx = None z3.main_ctx() z3.set_param('smt.random_seed', seed)
def __init__(self, environment, logic=None): Interpolator.__init__(self) self.environment = environment self.logic = logic self.converter = Z3Converter(environment, z3_ctx=z3.main_ctx())
def ResetZ3 (): z3._main_ctx = None z3.main_ctx() z3.set_param('smt.random_seed', random.SystemRandom().randint(0, sys.maxint)) z3.set_param('smt.mbqi.max_iterations', 10000) z3.set_param('smt.mbqi.max_cexs', 100)
def ResetZ3(): z3._main_ctx = None z3.main_ctx() z3.set_param('smt.random_seed', random.SystemRandom().randint(0, sys.maxint))
def my_and(*args): ctx = z3.main_ctx() _args, sz = z3._to_ast_array(args) return z3.BoolRef(z3.Z3_mk_and(ctx.ref(), sz, _args), ctx)
def ResetZ3(): z3._main_ctx = None z3.main_ctx()
def load_horn_db_from_file(fname, context = z3.main_ctx(), env = None): fp = z3.Fixedpoint(ctx = context) queries = fp.parse_file(fname) db = HornClauseDb(fname, ctx = context, env = env) db.load_from_fp(fp, queries) return db
def string_concat(): ctx = z3.main_ctx() decl = z3strlib.z3str_concat_decl() return z3.FuncDeclRef(decl, ctx)
def StringSort(): ctx = z3.main_ctx() sort = z3strlib.z3str_mk_string_sort() return z3.SortRef(sort, ctx)
def string_lastindexof(): ctx = z3.main_ctx() decl = z3strlib.z3str_lastindexof_decl() return z3.FuncDeclRef(decl, ctx)
def string_replace(): ctx = z3.main_ctx() decl = z3strlib.z3str_replace_decl() return z3.FuncDeclRef(decl, ctx)
def string_unroll(): ctx = z3.main_ctx() decl = z3strlib.z3str_unroll_decl() return z3.FuncDeclRef(decl, ctx)
def string_endswith(): ctx = z3.main_ctx() decl = z3strlib.z3str_endswith_decl() return z3.FuncDeclRef(decl, ctx)
def my_eq(x, y): ctx = z3.main_ctx() # print "my_eq: {} = {}".format(x,y) return z3.BoolRef(z3.Z3_mk_eq(ctx.ref(), x.as_ast(), y.as_ast()), ctx)
def my_eq(x, y): ctx = z3.main_ctx() return z3.BoolRef(z3.Z3_mk_eq(ctx.ref(), x.as_ast(), y.as_ast()), ctx)
#z3strlib.z3str_regexconcat_decl.argtypes = [] #z3strlib.z3str_unroll_decl.restype = z3.FuncDecl #z3strlib.z3str_unroll_decl.argtypes = [] #z3strlib.z3str_regexdigit_decl.restype = z3.FuncDecl #z3strlib.z3str_regexdigit_decl.argtypes = [] z3strlib.z3str_register_vars.restype = None z3strlib.z3str_register_vars.argtypes = [z3.Ast] z3strlib.setAlphabet.restype = None z3strlib.setAlphabet.argtypes = [] z3strlib.setAlphabet7bit.restype = None z3strlib.setAlphabet7bit.argtypes = [] z3strlib.z3str_basic_str_var_axioms.restype = None z3strlib.z3str_basic_str_var_axioms.argtypes = [] ## Set the default Z3py context to use z3str ctx = z3.main_ctx() ctx.ctx = z3strlib.z3str_mk_context() z3strlib.setAlphabet7bit() ## Wrappers around the various z3str_*() functions in libz3str2.so def StringSort(): ctx = z3.main_ctx() sort = z3strlib.z3str_mk_string_sort() return z3.SortRef(sort, ctx) """ def RegexSort(): ctx = z3.main_ctx() sort = z3strlib.z3str_mk_regex_sort()
def __init__(self, environment, logic=None): QuantifierEliminator.__init__(self) self.environment = environment self.logic = logic self.converter = Z3Converter(environment, z3.main_ctx())
def string_substring(): ctx = z3.main_ctx() decl = z3strlib.z3str_substring_decl() return z3.FuncDeclRef(decl, ctx)
def _context(self): try: return self._tls.context except AttributeError: self._tls.context = z3.Context() if threading.current_thread().name != 'MainThread' else z3.main_ctx() return self._tls.context
def convertAstToZ3(triton_ctx, ast_node): return z3.ExprRef(_convertAstToZ3(triton_ctx, z3.main_ctx().ctx, ast_node))
#!/usr/bin/env python3 import z3 from z3 import * import sys import random z3._main_ctx = None z3.main_ctx() z3.set_param('smt.random_seed', random.SystemRandom().randint(0, sys.maxsize)) a = z3.Int('a') b = z3.Int('b') c = z3.Int('c') f = z3.Function('f', IntSort(), IntSort()) s = z3.Solver() # s.add(ForAll([a, b], (c == f(a+b)) == (c == a+f(b)) == (c == f(a)+b))) s.add(ForAll([a, b], f(a + b) == a + f(b))) x = z3.Int('x') y = z3.Int('y') s.add(f(x + y) != x + f(y)) print(s.check())
def ResetZ3 (): z3._main_ctx = None z3.main_ctx() z3.set_param('smt.random_seed', random.SystemRandom().randint(0, sys.maxint))
def string_regexdigit(): ctx = z3.main_ctx() decl = z3strlib.z3str_regexdigit_decl() return z3.FuncDeclRef(decl, ctx)
def string_indexof2(): ctx = z3.main_ctx() decl = z3strlib.z3str_indexof2_decl() return z3.FuncDeclRef(decl, ctx)
def RegexSort(): ctx = z3.main_ctx() sort = z3strlib.z3str_mk_regex_sort() return z3.SortRef(sort, ctx)
def string_length(): ctx = z3.main_ctx() decl = z3strlib.z3str_length_decl() return z3.FuncDeclRef(decl, ctx)
def my_eq(x,y): ctx = z3.main_ctx() return z3.BoolRef(z3.Z3_mk_eq(ctx.ref(), x.as_ast(), y.as_ast()), ctx)
def string_indexof(): ctx = z3.main_ctx() decl = z3strlib.z3str_indexof_decl() return z3.FuncDeclRef(decl, ctx)
def ResetZ3 (): z3._main_ctx = None z3.main_ctx()