diff --git a/verifier/README.md b/verifier/README.md
index b3b376d52..e29693324 100644
--- a/verifier/README.md
+++ b/verifier/README.md
@@ -415,10 +415,10 @@ runtime of the verifier's environment: a confirmed `INCONCLUSIVE` counterexample
(or satisfying input) becomes `VIOLATED` (or `VERIFIED`), and any refuted one
becomes `INCONCLUSIVE` with no witness. Only exact inputs are checked, when no unknown
identifiers are registered; when the runtime can't evaluate them (e.g. a
-function has no binding), the message says why. Policy invariants aren't
-checked yet. The runtime must follow the CEL spec (e.g. `CelOptions.DEFAULT`, which has no
-iteration limit), and a function with bindings must have one for each overload,
-which is synchronous, deterministic and doesn't throw.
+function has no binding), the message says why. The runtime must follow the CEL
+spec (e.g. `CelOptions.DEFAULT`, which has no iteration limit), and a function
+with bindings must have one for each overload, which is synchronous,
+deterministic and doesn't throw.
### Comprehensions and Bounded Model Checking
diff --git a/verifier/src/main/java/dev/cel/verifier/BUILD.bazel b/verifier/src/main/java/dev/cel/verifier/BUILD.bazel
index b23b6f2c5..ae3bca752 100644
--- a/verifier/src/main/java/dev/cel/verifier/BUILD.bazel
+++ b/verifier/src/main/java/dev/cel/verifier/BUILD.bazel
@@ -189,6 +189,7 @@ java_library(
"//common:operator",
"//common/ast",
"//common/ast:cel_block",
+ "//common/exceptions:runtime_exception",
"//common/internal:cel_descriptor_pools",
"//common/internal:map_keys",
"//common/internal:proto_time_utils",
diff --git a/verifier/src/main/java/dev/cel/verifier/CelVerifierBuilder.java b/verifier/src/main/java/dev/cel/verifier/CelVerifierBuilder.java
index e520ea647..751d8014b 100644
--- a/verifier/src/main/java/dev/cel/verifier/CelVerifierBuilder.java
+++ b/verifier/src/main/java/dev/cel/verifier/CelVerifierBuilder.java
@@ -92,9 +92,9 @@ public interface CelVerifierBuilder {
*
*
Inputs are checked only when all their values are exact and no unknown identifiers are
* registered. When the runtime can't evaluate them, e.g. a function has no binding, the message
- * says why. Policy invariants aren't checked yet. The runtime must follow the CEL spec (e.g.
- * {@code CelOptions.DEFAULT}, which has no iteration limit), and a function with bindings must
- * have one for each overload, which is synchronous, deterministic and doesn't throw.
+ * says why. The runtime must follow the CEL spec (e.g. {@code CelOptions.DEFAULT}, which has no
+ * iteration limit), and a function with bindings must have one for each overload, which is
+ * synchronous, deterministic and doesn't throw.
*/
@CanIgnoreReturnValue
CelVerifierBuilder enableCegar(boolean value);
diff --git a/verifier/src/main/java/dev/cel/verifier/CelVerifierZ3Impl.java b/verifier/src/main/java/dev/cel/verifier/CelVerifierZ3Impl.java
index 41d64c19d..75a54f314 100644
--- a/verifier/src/main/java/dev/cel/verifier/CelVerifierZ3Impl.java
+++ b/verifier/src/main/java/dev/cel/verifier/CelVerifierZ3Impl.java
@@ -260,14 +260,15 @@ public CelVerificationResult verifyEquivalence(
/* isCounterexample= */ true,
/* candidate= */ "a divergence",
/* exactMatchMessage= */ "Equivalence violation detected.",
- runtimeCheck(results -> !results.get(0).equals(results.get(1)), astA, astB));
+ runtimeCheck(
+ ImmutableMap.of(), results -> !results.get(0).equals(results.get(1)), astA, astB));
}
}
CelVerificationResult verifyImplication(
CelAbstractSyntaxTree assumeAst,
CelAbstractSyntaxTree assertAst,
- Map boundSymbols,
+ ImmutableMap boundSymbols,
String subjectName)
throws CelVerificationException {
checkArgument(assumeAst.isChecked(), "assumeAst must be type-checked.");
@@ -313,7 +314,11 @@ CelVerificationResult verifyImplication(
/* isCounterexample= */ true,
/* candidate= */ "a counterexample",
/* exactMatchMessage= */ String.format("%s violation detected.", subjectName),
- /* runtimeCheck= */ RuntimeChecker.UNCHECKED);
+ runtimeCheck(
+ boundSymbols,
+ results -> results.get(0).equals(true) && !results.get(1).equals(true),
+ assumeAst,
+ assertAst));
}
}
@@ -335,7 +340,7 @@ private CelVerificationResult checkSatisfiability(
/* isCounterexample= */ true,
/* candidate= */ "a counterexample",
/* exactMatchMessage= */ "Condition is not always true.",
- runtimeCheck(results -> !results.get(0).equals(true), ast));
+ runtimeCheck(ImmutableMap.of(), results -> !results.get(0).equals(true), ast));
}
BoolExpr isUnmodeledUnknown = ctx.mkAnd(tv.isZ3Unknown(), tv.isApproximate());
return search(
@@ -347,7 +352,7 @@ private CelVerificationResult checkSatisfiability(
/* isCounterexample= */ false,
/* candidate= */ "a satisfying input",
/* exactMatchMessage= */ "Condition is satisfiable.",
- runtimeCheck(results -> results.get(0).equals(true), ast));
+ runtimeCheck(ImmutableMap.of(), results -> results.get(0).equals(true), ast));
}
}
@@ -433,8 +438,6 @@ private static CelVerificationResult match(
}
private interface RuntimeChecker {
- RuntimeChecker UNCHECKED = (witness, countInternalErrors) -> RuntimeCheck.UNCHECKED;
-
RuntimeCheck check(CelWitness witness, boolean countInternalErrors);
}
@@ -462,9 +465,11 @@ static RuntimeCheck failed(String reason) {
// Checks the witness's inputs with the runtime, if refinement is on and they're exact. Unknowns
// aren't inputs the runtime can take.
private RuntimeChecker runtimeCheck(
- Predicate> isMatch, CelAbstractSyntaxTree... asts) {
+ ImmutableMap boundSymbols,
+ Predicate> isMatch,
+ CelAbstractSyntaxTree... asts) {
if (!enableCegar || !unknownIdentifiers.isEmpty()) {
- return RuntimeChecker.UNCHECKED;
+ return (witness, countInternalErrors) -> RuntimeCheck.UNCHECKED;
}
return (witness, countInternalErrors) -> {
Optional> inputs = RuntimeOracle.exactInputs(witness);
@@ -473,7 +478,9 @@ private RuntimeChecker runtimeCheck(
}
try {
return RuntimeCheck.of(
- isMatch.test(RuntimeOracle.evaluate(cel, inputs.get(), countInternalErrors, asts)));
+ isMatch.test(
+ RuntimeOracle.evaluate(
+ cel, inputs.get(), boundSymbols, countInternalErrors, asts)));
} catch (CelEvaluationException e) {
return RuntimeCheck.failed(e.getMessage());
}
diff --git a/verifier/src/main/java/dev/cel/verifier/RuntimeOracle.java b/verifier/src/main/java/dev/cel/verifier/RuntimeOracle.java
index 00ac15ca3..40c0c76c8 100644
--- a/verifier/src/main/java/dev/cel/verifier/RuntimeOracle.java
+++ b/verifier/src/main/java/dev/cel/verifier/RuntimeOracle.java
@@ -14,11 +14,14 @@
package dev.cel.verifier;
+import com.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import dev.cel.common.CelAbstractSyntaxTree;
import dev.cel.common.CelErrorCode;
+import dev.cel.common.exceptions.CelRuntimeException;
import dev.cel.runtime.CelEvaluationException;
import dev.cel.runtime.CelFunctionResolver;
import dev.cel.runtime.CelResolvedOverload;
@@ -28,7 +31,7 @@
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
-import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
/**
* Evaluates expressions with the CEL runtime on a witness's inputs, to check the solver's
@@ -41,6 +44,14 @@ private enum EvaluationError {
ERROR
}
+ private final CelRuntime runtime;
+ private final Map inputs;
+ private final ImmutableMap> boundSymbols;
+ private final boolean countInternalErrors;
+ // Why the runtime can't evaluate the expression, even if `||` or `&&` keeps another error.
+ private final AtomicReference uncheckableCause;
+ private final CelFunctionResolver lateBoundFunctions;
+
/** The witness's inputs, if every value is exact. */
static Optional> exactInputs(CelWitness witness) {
return witness.variables().values().stream().allMatch(v -> v.value().isPresent())
@@ -50,59 +61,133 @@ static Optional> exactInputs(CelWitness witness) {
}
/**
- * Returns the values of {@code asts} for {@code inputs}, with errors as one value. Throws if the
- * runtime can't evaluate one, e.g. a function has no binding or its iteration limit is hit, or if
- * it fails with an internal error and {@code countInternalErrors} is false.
+ * Returns the values of {@code asts} for {@code inputs} and {@code boundSymbols}, with errors as
+ * one value. Throws if the runtime can't evaluate one, e.g. a function has no binding or its
+ * iteration limit is hit, or if it fails with an internal error and {@code countInternalErrors}
+ * is false.
*/
static ImmutableList