示例#1
0
def k_induction_attempt_inductive():
    # Create an smt_switch.SmtSolver with Boolector as the backend
    # and no logging
    s = ss.create_btor_solver(False)
    s.set_opt('produce-models', 'true')
    s.set_opt('incremental', 'true')
    prop, fts = build_simple_alu_fts(s)

    # store sets of states in a dictionary for accessing below
    states = {str(sv): sv for sv in fts.statevars}

    # make the property inductive manually
    prop = pono.Property(
        s,
        s.make_term(
            And,
            s.make_term(Equal, states['cfg'],
                        s.make_term(0, s.make_sort(BV, 1))), prop.prop))

    print(
        '\n============== Running k-induction on inductively strengthened property =============='
    )
    print('INIT\n\t{}'.format(fts.init))
    print('TRANS\n\t{}'.format(fts.trans))
    print('PROP\n\t{}'.format(prop.prop))

    # Create KInduction engine -- using same solver (in future can change the solver)
    kind = pono.KInduction(prop, fts, s)
    res = kind.check_until(20)

    print(res)

    assert res is True, "Expecting k-induction to prove the inductively strengthened property"
    print("KInduction returned true")
示例#2
0
def k_induction_attempt():
    # Create an smt_switch.SmtSolver with Boolector as the backend
    # and no logging
    s = ss.create_btor_solver(False)
    s.set_opt('produce-models', 'true')
    s.set_opt('incremental', 'true')
    prop, fts = build_simple_alu_fts(s)

    print('\n============== Running k-induction ==============')
    print('INIT\n\t{}'.format(fts.init))
    print('TRANS\n\t{}'.format(fts.trans))
    print('PROP\n\t{}'.format(prop.prop))

    # Create KInduction engine -- using same solver (in future can change the solver)
    kind = pono.KInduction(prop, fts, s)
    res = kind.check_until(20)

    print(res)

    assert res is None, "Expecting k-induction not to prove property in 20 steps"
    print("KInduction returned unknown")
示例#3
0
    def run(self, actions):
        # Create solver/interpolator
        solver = ss.create_btor_solver(False)

        # set solver options
        solver.set_opt('produce-models', 'true')
        solver.set_opt('incremental', 'true')

        # Load compile result
        context = coreir.Context()
        context.load_library("commonlib")
        top_mod = context.load_from_file(str(self.directory /
                                             Path(f"{self.circuit_name}.json")))

        rts = pono.RelationalTransitionSystem(solver)
        pono.CoreIREncoder(top_mod, rts)
        ports = {}
        for name, port in self.circuit.interface.ports.items():
            if name == "CLK":
                continue
            width = get_width(port)
            if width is None:
                sort = solver.make_sort(ss.sortkinds.BOOL)
            else:
                sort = solver.make_sort(ss.sortkinds.BV, width)
            if port.is_input():
                ports[name] = rts.make_statevar(f"{name}_out", sort)
                rts.assign_next(ports[name], rts.named_terms[f"self.{name}"])
            else:
                ports[name] = rts.make_statevar(f"{name}_in", sort)
                rts.assign_next(ports[name], rts.named_terms[name])
                rts.constrain_inputs(
                    solver.make_term(Equal, rts.named_terms[name],
                                     ports[name]))

        at_end_state_flag = self.generate_code(actions, solver, rts, ports)
        self.process_guarantees(solver, rts, at_end_state_flag, ports)
示例#4
0
#!/usr/bin/env python3
import smt_switch as ss
from smt_switch.primops import Apply, Distinct, Equal, Extract, BVAnd, BVUge

if __name__ == "__main__":
    s = ss.create_btor_solver(True)
    s.set_logic('QF_UFBV')
    s.set_opt('incremental', 'true')
    s.set_opt('produce-models', 'true')
    s.set_opt('produce-unsat-assumptions', 'true')
    bvs = s.make_sort(ss.sortkinds.BV, 32)
    funs = s.make_sort(ss.sortkinds.FUNCTION, [bvs, bvs])

    x = s.make_symbol('x', bvs)
    y = s.make_symbol('y', bvs)
    f = s.make_symbol('f', funs)

    ext = ss.Op(Extract, 15, 0)
    x0 = s.make_term(ext, x)
    y0 = s.make_term(ext, y)

    fx = s.make_term(Apply, f, x)
    fy = s.make_term(Apply, f, y)
    s.assert_formula(s.make_term(Distinct, fx, fy))

    s.push(1)
    s.assert_formula(s.make_term(Equal, x0, y0))
    print(s.check_sat())
    print(s.get_value(x))
    s.pop(1)