Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EmergenTheta Update #314

Draft
wants to merge 57 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
13ffb90
use domainsize in MddChecker
mondokm Aug 7, 2024
b3724dd
add function for litexpr creation
mondokm Aug 7, 2024
d6f4e7b
add new tests
mondokm Aug 7, 2024
d4c0fa5
use interpreter in relprod
mondokm Aug 7, 2024
af55d09
Fix for when the constraint is terminal 1
mondokm Aug 7, 2024
f288371
Add level skip for unbounded domain
mondokm Aug 12, 2024
94c17d1
Update delta jar
mondokm Aug 12, 2024
d470b4b
Add toString
mondokm Aug 12, 2024
8f33a93
Reenable tests
mondokm Aug 12, 2024
a31f8ce
Use nodeInterpreter for level skips in finite domains
mondokm Aug 12, 2024
c80a182
Reformat files
mondokm Aug 12, 2024
5497271
Add new test cases
mondokm Aug 15, 2024
d265f9a
Simplify case when lhs is level-skip
mondokm Aug 15, 2024
302b8ce
Simplify lhs level-skip and fix statespaceinfo
mondokm Aug 15, 2024
18595f8
Add constrained cursor tests
mondokm Aug 15, 2024
b91fb99
Add new test case
mondokm Aug 15, 2024
fee5a29
Add statespaceinfo tests
mondokm Aug 15, 2024
81d9b20
Handle level skips in bounds collection
mondokm Aug 15, 2024
29ed1b7
Disable not supported tests
mondokm Aug 15, 2024
d903eb4
Improve caching of valuation
mondokm Aug 15, 2024
84e37c2
Use unbounded domains for now
mondokm Aug 15, 2024
fbc035d
Don't include tmp vars
mondokm Aug 15, 2024
91a582e
Add state vars and temp vars to XSTS
mondokm Aug 15, 2024
07353cc
Reformat files
mondokm Aug 15, 2024
08963dd
Rename temp vars to local
mondokm Aug 15, 2024
5ce63e9
Use default nodeToString
mondokm Aug 15, 2024
ea0d2b2
Change Preconditions check to assertion
mondokm Aug 15, 2024
f7bf171
Add default values to CFA monolithic, fix division by zero in simplif…
mondokm Nov 5, 2024
763b2fe
Merged mdd-dev
leventeBajczi Nov 5, 2024
880cf8b
Added MDD backend to XCFA frontend
leventeBajczi Nov 5, 2024
5ed25cc
Fixed some bugs
leventeBajczi Nov 5, 2024
adb190b
Version bump
leventeBajczi Nov 5, 2024
fe44378
Added xcfa tests, modified cfa tests, removed offending stmttoexpr tests
leventeBajczi Nov 5, 2024
a626d21
re-added failing tests
leventeBajczi Nov 5, 2024
98b7473
Add default values to CfaToMonolithicExpr.kt
mondokm Nov 5, 2024
ef9654b
Add var ordering for cfa and xcfa
mondokm Nov 5, 2024
48fc830
Fix formatting
mondokm Nov 5, 2024
13c6069
fixed vars for mdd
leventeBajczi Nov 6, 2024
ef3de32
Merged some files from kszi2/ic3-update
dantpu Nov 6, 2024
09d16e2
Fixed Witness->Proof
leventeBajczi Nov 6, 2024
c5e2fec
Change var ordering
mondokm Nov 6, 2024
a2af700
Use var ordering properly
mondokm Nov 6, 2024
8256648
Fixed stateToAction
leventeBajczi Nov 6, 2024
c362fd6
var -> globalVar
leventeBajczi Nov 6, 2024
8cad4c5
Instead of keeping metadata, combine it with meaningful edges
leventeBajczi Nov 6, 2024
2bbba4d
Removed infinite state spaces from mdd test
leventeBajczi Nov 7, 2024
612fc4c
Add input validation to MddChecker
mondokm Nov 7, 2024
c6039f8
Fixed bug relating to multi-variable definitions in a single statement
leventeBajczi Nov 7, 2024
b56d417
Fix MddNodeInitializer caching
mondokm Nov 7, 2024
f155e8b
Added reversed and abstract checkers
leventeBajczi Nov 7, 2024
f5cb264
Add identityexprs to transRel
mondokm Nov 7, 2024
deae12f
Add semantic equals to MddExpressionRepresentation
mondokm Nov 7, 2024
6b0aff3
Merge remote-tracking branch 'origin/emergent-2025' into emergent-2025
mondokm Nov 7, 2024
6c56d77
Remove edge and loc vars from defaultvalues
mondokm Nov 7, 2024
36083c3
Add FORCE var ordering
mondokm Nov 7, 2024
8a0dfb7
Add XSTS var ordering
mondokm Nov 7, 2024
a23046d
Remove collect
mondokm Nov 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ buildscript {

allprojects {
group = "hu.bme.mit.theta"
version = "6.7.0"
version = "6.8.0"

apply(from = rootDir.resolve("gradle/shared-with-buildSrc/mirrors.gradle.kts"))
}
Expand Down
Binary file modified lib/hu.bme.mit.delta-0.0.1-all.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,22 @@ import hu.bme.mit.theta.cfa.CFA
import hu.bme.mit.theta.core.decl.Decls
import hu.bme.mit.theta.core.model.Valuation
import hu.bme.mit.theta.core.stmt.*
import hu.bme.mit.theta.core.type.Expr
import hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Eq
import hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Neq
import hu.bme.mit.theta.core.type.booltype.BoolExprs.And
import hu.bme.mit.theta.core.type.inttype.IntExprs.*
import hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool
import hu.bme.mit.theta.core.type.booltype.BoolType
import hu.bme.mit.theta.core.type.bvtype.BvType
import hu.bme.mit.theta.core.type.fptype.FpExprs.*
import hu.bme.mit.theta.core.type.fptype.FpType
import hu.bme.mit.theta.core.type.inttype.IntExprs.Int
import hu.bme.mit.theta.core.type.inttype.IntLitExpr
import hu.bme.mit.theta.core.type.inttype.IntType
import hu.bme.mit.theta.core.utils.BvUtils
import hu.bme.mit.theta.core.utils.StmtUtils
import hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory
import java.math.BigInteger
import java.util.*

fun CFA.toMonolithicExpr(): MonolithicExpr {
Expand All @@ -36,7 +47,11 @@ fun CFA.toMonolithicExpr(): MonolithicExpr {
for ((i, x) in this.locs.withIndex()) {
map[x] = i
}
val locVar = Decls.Var("__loc__", Int())
val locVar =
Decls.Var(
"__loc__",
Int(),
) // TODO: add edge var as well, to avoid parallel edges causing problems
val tranList =
this.edges
.map { e ->
Expand All @@ -49,15 +64,40 @@ fun CFA.toMonolithicExpr(): MonolithicExpr {
)
}
.toList()

val defaultValues =
this.vars
.map {
when (it.type) {
is IntType -> Eq(it.ref, Int(0))
is BoolType -> Eq(it.ref, Bool(false))
is BvType ->
Eq(
it.ref,
BvUtils.bigIntegerToNeutralBvLitExpr(BigInteger.ZERO, (it.type as BvType).size),
)
is FpType -> FpAssign(it.ref as Expr<FpType>, NaN(it.type as FpType))
else -> throw IllegalArgumentException("Unsupported type")
}
}
.toList()
.let { And(it) }

val trans = NonDetStmt.of(tranList)
val transUnfold = StmtUtils.toExpr(trans, VarIndexingFactory.indexing(0))
val transExpr = And(transUnfold.exprs)
val initExpr = Eq(locVar.ref, Int(map[this.initLoc]!!))
val initExpr = And(Eq(locVar.ref, Int(map[this.initLoc]!!)), defaultValues)
val propExpr = Neq(locVar.ref, Int(map[this.errorLoc.orElseThrow()]!!))

val offsetIndex = transUnfold.indexing

return MonolithicExpr(initExpr, transExpr, propExpr, offsetIndex)
return MonolithicExpr(
initExpr,
transExpr,
propExpr,
offsetIndex,
vars = this.vars.toList() + listOf(locVar),
)
}

fun CFA.valToAction(val1: Valuation, val2: Valuation): CfaAction {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* Copyright 2024 Budapest University of Technology and Economics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package hu.bme.mit.theta.cfa.analysis;

import static hu.bme.mit.theta.cfa.analysis.config.CfaConfigBuilder.Domain.*;
import static hu.bme.mit.theta.cfa.analysis.config.CfaConfigBuilder.Refinement.*;

import hu.bme.mit.theta.analysis.algorithm.SafetyResult;
import hu.bme.mit.theta.analysis.algorithm.mdd.MddCex;
import hu.bme.mit.theta.analysis.algorithm.mdd.MddChecker;
import hu.bme.mit.theta.analysis.algorithm.mdd.MddProof;
import hu.bme.mit.theta.analysis.expr.ExprAction;
import hu.bme.mit.theta.cfa.CFA;
import hu.bme.mit.theta.cfa.dsl.CfaDslManager;
import hu.bme.mit.theta.common.OsHelper;
import hu.bme.mit.theta.common.logging.ConsoleLogger;
import hu.bme.mit.theta.common.logging.Logger;
import hu.bme.mit.theta.common.logging.NullLogger;
import hu.bme.mit.theta.core.type.Expr;
import hu.bme.mit.theta.core.type.booltype.BoolType;
import hu.bme.mit.theta.core.utils.indexings.VarIndexing;
import hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory;
import hu.bme.mit.theta.solver.SolverFactory;
import hu.bme.mit.theta.solver.SolverManager;
import hu.bme.mit.theta.solver.SolverPool;
import hu.bme.mit.theta.solver.smtlib.SmtLibSolverManager;
import hu.bme.mit.theta.solver.z3legacy.Z3SolverManager;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

@RunWith(value = Parameterized.class)
public class CfaMddCheckerTest {

@Parameterized.Parameter(value = 0)
public String filePath;

@Parameterized.Parameter(value = 1)
public boolean isSafe;

@Parameterized.Parameters(name = "{index}: {0}, {1}")
public static Collection<Object[]> data() {
return Arrays.asList(
new Object[][] {
{"src/test/resources/arithmetic-bool00.cfa", false},
{"src/test/resources/arithmetic-bool01.cfa", false},
{"src/test/resources/arithmetic-bool10.cfa", false},
{"src/test/resources/arithmetic-bool11.cfa", false},
{"src/test/resources/arithmetic-mod.cfa", true},
{"src/test/resources/counter5_true.cfa", true},
{"src/test/resources/counter_bv_true.cfa", true},
{"src/test/resources/counter_bv_false.cfa", false},
{"src/test/resources/ifelse.cfa", false},
});
}

@Test
public void test() throws Exception {
final Logger logger = new ConsoleLogger(Logger.Level.SUBSTEP);

SolverManager.registerSolverManager(Z3SolverManager.create());
if (OsHelper.getOs().equals(OsHelper.OperatingSystem.LINUX)) {
SolverManager.registerSolverManager(
SmtLibSolverManager.create(SmtLibSolverManager.HOME, NullLogger.getInstance()));
}

final SolverFactory solverFactory;
try {
solverFactory = SolverManager.resolveSolverFactory("Z3");
} catch (Exception e) {
Assume.assumeNoException(e);
return;
}

try {
CFA cfa = CfaDslManager.createCfa(new FileInputStream(filePath));
var monolithicExpr = CfaToMonolithicExprKt.toMonolithicExpr(cfa);

final SafetyResult<MddProof, MddCex> status;
try (var solverPool = new SolverPool(solverFactory)) {
final MddChecker<ExprAction> checker =
MddChecker.create(
monolithicExpr.getInitExpr(),
VarIndexingFactory.indexing(0),
new ExprAction() {
@Override
public Expr<BoolType> toExpr() {
return monolithicExpr.getTransExpr();
}

@Override
public VarIndexing nextIndexing() {
return VarIndexingFactory.indexing(1);
}
},
monolithicExpr.getPropExpr(),
monolithicExpr.getVars(),
solverPool,
logger,
MddChecker.IterationStrategy.GSAT);
status = checker.check(null);
}

Assert.assertEquals(isSafe, status.isSafe());
} finally {
SolverManager.closeAll();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright 2024 Budapest University of Technology and Economics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package hu.bme.mit.theta.analysis.algorithm.bounded

import hu.bme.mit.theta.analysis.pred.PredPrec
import hu.bme.mit.theta.analysis.pred.PredState
import hu.bme.mit.theta.core.decl.Decl
import hu.bme.mit.theta.core.decl.Decls
import hu.bme.mit.theta.core.decl.VarDecl
import hu.bme.mit.theta.core.model.Valuation
import hu.bme.mit.theta.core.type.Expr
import hu.bme.mit.theta.core.type.anytype.Exprs
import hu.bme.mit.theta.core.type.booltype.BoolExprs
import hu.bme.mit.theta.core.type.booltype.BoolLitExpr
import hu.bme.mit.theta.core.type.booltype.BoolType
import hu.bme.mit.theta.core.type.booltype.IffExpr
import hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.And
import hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.Not
import hu.bme.mit.theta.core.utils.ExprUtils
import hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory
import java.util.HashMap

fun MonolithicExpr.createAbstract(prec: PredPrec): MonolithicExpr {
// TODO: handle initOffsetIndex in abstract initExpr
val lambdaList = ArrayList<IffExpr>()
val lambdaPrimeList = ArrayList<IffExpr>()
val activationLiterals = ArrayList<VarDecl<*>>()
val literalToPred = HashMap<Decl<*>, Expr<BoolType>>()

prec.preds.forEachIndexed { index, expr ->
run {
val v = Decls.Var("v$index", BoolType.getInstance())
activationLiterals.add(v)
literalToPred[v] = expr
lambdaList.add(IffExpr.of(v.ref, expr))
lambdaPrimeList.add(
BoolExprs.Iff(Exprs.Prime(v.ref), ExprUtils.applyPrimes(expr, this.transOffsetIndex))
)
}
}

var indexingBuilder = VarIndexingFactory.indexingBuilder(1)
this.vars
.filter { it !in ctrlVars }
.forEach { decl ->
repeat(transOffsetIndex.get(decl)) { indexingBuilder = indexingBuilder.inc(decl) }
}

return MonolithicExpr(
initExpr = And(And(lambdaList), initExpr),
transExpr = And(And(lambdaList), And(lambdaPrimeList), transExpr),
propExpr = Not(And(And(lambdaList), Not(propExpr))),
transOffsetIndex = indexingBuilder.build(),
initOffsetIndex = VarIndexingFactory.indexing(0),
vars = activationLiterals + ctrlVars,
valToState = { valuation: Valuation ->
PredState.of(
valuation
.toMap()
.entries
.stream()
.filter { it.key !in ctrlVars }
.map {
when ((it.value as BoolLitExpr).value) {
true -> literalToPred[it.key]
false -> Not(literalToPred[it.key])
}
}
.toList()
)
},
biValToAction = this.biValToAction,
ctrlVars = ctrlVars,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ constructor(
private val logger: Logger,
) : SafetyChecker<EmptyProof, Trace<S, A>, UnitPrec> {

private val vars = monolithicExpr.vars()
private val vars = monolithicExpr.vars
private val unfoldedInitExpr =
PathUtils.unfold(monolithicExpr.initExpr, VarIndexingFactory.indexing(0))
private val unfoldedPropExpr = { i: VarIndexing -> PathUtils.unfold(monolithicExpr.propExpr, i) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,36 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package hu.bme.mit.theta.analysis.algorithm.bounded

import hu.bme.mit.theta.analysis.expl.ExplState
import hu.bme.mit.theta.analysis.expr.ExprAction
import hu.bme.mit.theta.analysis.expr.ExprState
import hu.bme.mit.theta.core.decl.VarDecl
import hu.bme.mit.theta.core.model.Valuation
import hu.bme.mit.theta.core.type.Expr
import hu.bme.mit.theta.core.type.booltype.BoolType
import hu.bme.mit.theta.core.utils.ExprUtils.getVars
import hu.bme.mit.theta.core.utils.indexings.VarIndexing
import hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory

data class MonolithicExpr(
val initExpr: Expr<BoolType>,
val transExpr: Expr<BoolType>,
val propExpr: Expr<BoolType>,
val transOffsetIndex: VarIndexing = VarIndexingFactory.indexing(1),
val initOffsetIndex: VarIndexing = VarIndexingFactory.indexing(0)
) {
data class MonolithicExpr
@JvmOverloads
constructor(
val initExpr: Expr<BoolType>,
val transExpr: Expr<BoolType>,
val propExpr: Expr<BoolType>,
val transOffsetIndex: VarIndexing = VarIndexingFactory.indexing(1),
val initOffsetIndex: VarIndexing = VarIndexingFactory.indexing(0),
val vars: List<VarDecl<*>> =
(getVars(initExpr) union getVars(transExpr) union getVars(propExpr)).toList(),
val valToState: (Valuation) -> ExprState = ExplState::of,
val biValToAction: (Valuation, Valuation) -> ExprAction = { _: Valuation, _: Valuation ->
object : ExprAction {
override fun toExpr(): Expr<BoolType> = transExpr

fun vars(): Collection<VarDecl<*>> {
return getVars(initExpr) union getVars(transExpr) union getVars(propExpr)
override fun nextIndexing(): VarIndexing = transOffsetIndex
}
}
},
val ctrlVars: Collection<VarDecl<*>> = listOf(),
)
Loading
Loading