Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 verifier/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ public class PolicyVerifierExample {
System.out.println(result.message());
// Output:
// Equivalence violation detected. Counterexample input:
// country = "a"
// role = "editor"
// country = "a"
// port = 443
break;
case INCONCLUSIVE:
Expand Down
1 change: 1 addition & 0 deletions verifier/src/main/java/dev/cel/verifier/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ java_library(
"//common/ast",
"//common/ast:cel_block",
"//common/internal:cel_descriptor_pools",
"//common/internal:proto_time_utils",
"//common/internal:well_known_proto",
"//common/types",
"//common/types:cel_types",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ CelZ3TypeSystem getTypeSystem() {
return typeSystem;
}

/** Returns the input variables, in order of first appearance. */
Set<Expr<?>> getInputVariables() {
return context.inputVariables();
}

/**
* Returns a Z3 boolean expression asserting that the provided CEL value is a boolean and is true.
*/
Expand Down
23 changes: 14 additions & 9 deletions verifier/src/main/java/dev/cel/verifier/CelVerifierZ3Impl.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public CelVerificationResult verifyEquivalence(
"Equivalence violation detected.",
getCounterexampleString(
ctx,
translator.getTypeSystem(),
translator,
result.model,
/* isApproximate= */ false,
/* isCounterexample= */ true));
Expand All @@ -269,7 +269,7 @@ public CelVerificationResult verifyEquivalence(
+ " theories, or loop bounds.",
getCounterexampleString(
ctx,
translator.getTypeSystem(),
translator,
result.model,
/* isApproximate= */ true,
/* isCounterexample= */ true));
Expand Down Expand Up @@ -345,7 +345,7 @@ CelVerificationResult verifyImplication(
String.format("%s violation detected.", subjectName),
getCounterexampleString(
ctx,
translator.getTypeSystem(),
translator,
result.model,
/* isApproximate= */ false,
/* isCounterexample= */ true));
Expand All @@ -355,7 +355,7 @@ CelVerificationResult verifyImplication(
+ " theories, or loop bounds.",
getCounterexampleString(
ctx,
translator.getTypeSystem(),
translator,
result.model,
/* isApproximate= */ true,
/* isCounterexample= */ true));
Expand Down Expand Up @@ -408,15 +408,15 @@ private CelVerificationResult checkSatisfiability(
"Condition is not always true.",
getCounterexampleString(
ctx,
translator.getTypeSystem(),
translator,
result.model,
/* isApproximate= */ false,
/* isCounterexample= */ true))
: CelVerificationResult.verified(
"Condition is satisfiable."
+ getCounterexampleString(
ctx,
translator.getTypeSystem(),
translator,
result.model,
/* isApproximate= */ false,
/* isCounterexample= */ false));
Expand All @@ -432,7 +432,7 @@ private CelVerificationResult checkSatisfiability(
prefix,
getCounterexampleString(
ctx,
translator.getTypeSystem(),
translator,
result.model,
/* isApproximate= */ true,
/* isCounterexample= */ searchForCounterexample));
Expand Down Expand Up @@ -540,12 +540,17 @@ private CelAstToZ3Translator newTranslator(Context ctx, boolean parameterizeUnkn

private static String getCounterexampleString(
Context ctx,
CelZ3TypeSystem typeSystem,
CelAstToZ3Translator translator,
Model model,
boolean isApproximate,
boolean isCounterexample) {
return CelZ3CounterexampleGenerator.generate(
ctx, typeSystem, model, isApproximate, isCounterexample);
ctx,
translator.getTypeSystem(),
model,
translator.getInputVariables(),
isApproximate,
isCounterexample);
}

private enum SolverOutcome {
Expand Down
Loading
Loading