diff --git a/verifier/README.md b/verifier/README.md
index 7d9d7f899..b3b376d52 100644
--- a/verifier/README.md
+++ b/verifier/README.md
@@ -408,6 +408,18 @@ by the Z3 solver during its search phase.
If the solver times out, the verifier will throw a `CelVerificationException`
which should be explicitly caught and handled by the caller.
+### Validating Counterexamples with the CEL Runtime
+
+`enableCegar(true)` checks the inputs the solver finds with the CEL
+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.
+
### Comprehensions and Bounded Model Checking
Because CEL lists/maps can be dynamically sized, the verifier cannot
diff --git a/verifier/src/main/java/dev/cel/verifier/BUILD.bazel b/verifier/src/main/java/dev/cel/verifier/BUILD.bazel
index 2d2549456..b23b6f2c5 100644
--- a/verifier/src/main/java/dev/cel/verifier/BUILD.bazel
+++ b/verifier/src/main/java/dev/cel/verifier/BUILD.bazel
@@ -170,6 +170,7 @@ java_library(
"CelZ3StructTranslator.java",
"CelZ3TranslationContext.java",
"CelZ3TypeConstraintGenerator.java",
+ "RuntimeOracle.java",
"TranslatedValue.java",
],
compatible_with = [],
@@ -184,10 +185,12 @@ java_library(
"//bundle:cel",
"//common:cel_ast",
"//common:compiler_common",
+ "//common:error_codes",
"//common:operator",
"//common/ast",
"//common/ast:cel_block",
"//common/internal:cel_descriptor_pools",
+ "//common/internal:map_keys",
"//common/internal:proto_time_utils",
"//common/internal:well_known_proto",
"//common/types",
@@ -198,6 +201,10 @@ java_library(
"//optimizer",
"//optimizer:optimization_exception",
"//optimizer:optimizer_builder",
+ "//runtime",
+ "//runtime:function_resolver",
+ "//runtime:resolved_overload",
+ "//runtime:unknown_attributes",
"//verifier/axioms",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
diff --git a/verifier/src/main/java/dev/cel/verifier/CelVerifierBuilder.java b/verifier/src/main/java/dev/cel/verifier/CelVerifierBuilder.java
index c49bb4343..e520ea647 100644
--- a/verifier/src/main/java/dev/cel/verifier/CelVerifierBuilder.java
+++ b/verifier/src/main/java/dev/cel/verifier/CelVerifierBuilder.java
@@ -82,6 +82,23 @@ public interface CelVerifierBuilder {
@CanIgnoreReturnValue
CelVerifierBuilder setComprehensionUnrollLimit(int unrollLimit);
+ /**
+ * Checks the inputs the solver finds by evaluating them with the CEL runtime of the verifier's
+ * environment (off by default). For now this only validates them, without refining the solver
+ * (counterexample-guided abstraction refinement, CEGAR). An {@code INCONCLUSIVE} counterexample
+ * or satisfying input that the runtime confirms becomes {@code VIOLATED} (or {@code VERIFIED} for
+ * satisfiability), and any counterexample or satisfying input it disagrees with becomes {@code
+ * INCONCLUSIVE} with no witness.
+ *
+ *
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.
+ */
+ @CanIgnoreReturnValue
+ CelVerifierBuilder enableCegar(boolean value);
+
/** Builds the {@link CelVerifier} instance. */
CelVerifier build();
}
diff --git a/verifier/src/main/java/dev/cel/verifier/CelVerifierZ3Impl.java b/verifier/src/main/java/dev/cel/verifier/CelVerifierZ3Impl.java
index 900821e92..41d64c19d 100644
--- a/verifier/src/main/java/dev/cel/verifier/CelVerifierZ3Impl.java
+++ b/verifier/src/main/java/dev/cel/verifier/CelVerifierZ3Impl.java
@@ -18,6 +18,7 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.ImmutableList.toImmutableList;
+import com.google.auto.value.AutoValue;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@@ -41,12 +42,15 @@
import dev.cel.optimizer.CelOptimizationException;
import dev.cel.optimizer.CelOptimizer;
import dev.cel.optimizer.CelOptimizerFactory;
+import dev.cel.runtime.CelEvaluationException;
import dev.cel.verifier.axioms.CelZ3FunctionAxiom;
import dev.cel.verifier.axioms.CelZ3StandardAxioms;
import java.time.Duration;
import java.util.Arrays;
+import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.function.Predicate;
/** Z3 implementation of the CelVerifier. */
@Immutable
@@ -91,6 +95,7 @@ public Optional findType(String typeName) {
private final ImmutableSet unknownIdentifiers;
private final CelZ3FunctionRegistry functionRegistry;
private final CelTypeProvider typeProvider;
+ private final boolean enableCegar;
@SuppressWarnings("Immutable") // Cel environment is immutable, just not marked as such
private final Cel cel;
@@ -111,6 +116,7 @@ static final class Builder implements CelVerifierBuilder {
private final ImmutableList.Builder functionAxioms;
private final Cel cel;
private CelTypeProvider typeProvider;
+ private boolean enableCegar;
@Override
@CanIgnoreReturnValue
@@ -144,6 +150,13 @@ public CelVerifierBuilder setComprehensionUnrollLimit(int unrollLimit) {
return this;
}
+ @Override
+ @CanIgnoreReturnValue
+ public CelVerifierBuilder enableCegar(boolean value) {
+ this.enableCegar = value;
+ return this;
+ }
+
@CanIgnoreReturnValue
Builder addFunctionAxioms(CelZ3FunctionAxiom... axioms) {
return addFunctionAxioms(Arrays.asList(axioms));
@@ -170,6 +183,7 @@ public CelVerifier build() {
unknownIdentifiers.build(),
registry,
typeProvider,
+ enableCegar,
cel);
}
@@ -208,17 +222,19 @@ public CelVerificationResult verifyEquivalence(
CanonicalizationOptimizer.newInstance(
CanonicalizationOptimizer.CanonicalizationOptions.newBuilder().build()))
.build();
+ CelAbstractSyntaxTree canonicalA = astA;
+ CelAbstractSyntaxTree canonicalB = astB;
try {
- astA = optimizer.optimize(astA);
- astB = optimizer.optimize(astB);
+ canonicalA = optimizer.optimize(astA);
+ canonicalB = optimizer.optimize(astB);
} catch (CelOptimizationException e) {
// Fall back to original ASTs if canonicalization or re-typechecking fails
}
try (Context ctx = new Context(ImmutableMap.of("model", "true"))) {
CelAstToZ3Translator translator = newTranslator(ctx, /* parameterizeUnknowns= */ true);
- TranslatedValue tvA = translator.translate(astA);
- TranslatedValue tvB = translator.translate(astB);
+ TranslatedValue tvA = translator.translate(canonicalA);
+ TranslatedValue tvB = translator.translate(canonicalB);
BoolExpr divergenceCondition = ctx.mkNot(ctx.mkEq(tvA.z3Expr(), tvB.z3Expr()));
// Parameterized unknowns are keyed on the operation producing them, whereas CEL identifies
@@ -243,7 +259,8 @@ public CelVerificationResult verifyEquivalence(
/* unknownCondition= */ ctx.mkFalse(),
/* isCounterexample= */ true,
/* candidate= */ "a divergence",
- /* exactMatchMessage= */ "Equivalence violation detected.");
+ /* exactMatchMessage= */ "Equivalence violation detected.",
+ runtimeCheck(results -> !results.get(0).equals(results.get(1)), astA, astB));
}
}
@@ -295,7 +312,8 @@ CelVerificationResult verifyImplication(
unknownCondition,
/* isCounterexample= */ true,
/* candidate= */ "a counterexample",
- /* exactMatchMessage= */ String.format("%s violation detected.", subjectName));
+ /* exactMatchMessage= */ String.format("%s violation detected.", subjectName),
+ /* runtimeCheck= */ RuntimeChecker.UNCHECKED);
}
}
@@ -316,7 +334,8 @@ private CelVerificationResult checkSatisfiability(
/* unknownCondition= */ ctx.mkFalse(),
/* isCounterexample= */ true,
/* candidate= */ "a counterexample",
- /* exactMatchMessage= */ "Condition is not always true.");
+ /* exactMatchMessage= */ "Condition is not always true.",
+ runtimeCheck(results -> !results.get(0).equals(true), ast));
}
BoolExpr isUnmodeledUnknown = ctx.mkAnd(tv.isZ3Unknown(), tv.isApproximate());
return search(
@@ -327,13 +346,16 @@ private CelVerificationResult checkSatisfiability(
isUnmodeledUnknown,
/* isCounterexample= */ false,
/* candidate= */ "a satisfying input",
- /* exactMatchMessage= */ "Condition is satisfiable.");
+ /* exactMatchMessage= */ "Condition is satisfiable.",
+ runtimeCheck(results -> results.get(0).equals(true), ast));
}
}
/**
* Searches for a {@code condition} match: first an exact one, then an approximate one, then an
- * unmodeled result satisfying {@code unknownCondition} that may stand in for one.
+ * unmodeled result satisfying {@code unknownCondition} that may stand in for one. {@code
+ * runtimeCheck} checks a witness with the runtime, noting why if it couldn't. Confirming an
+ * approximate match doesn't count internal runtime errors.
*/
private CelVerificationResult search(
Context ctx,
@@ -343,7 +365,8 @@ private CelVerificationResult search(
BoolExpr unknownCondition,
boolean isCounterexample,
String candidate,
- String exactMatchMessage)
+ String exactMatchMessage,
+ RuntimeChecker runtimeCheck)
throws CelVerificationException {
Solver solver = newSolver(ctx);
solver.add(translator.getTypeConstraints().toArray(new BoolExpr[0]));
@@ -353,9 +376,12 @@ private CelVerificationResult search(
Status status = checkSat(solver, typeSystem, condition, ctx.mkNot(taint));
if (status == Status.SATISFIABLE) {
CelWitness witness = extractWitness(ctx, translator, solver.getModel());
- return isCounterexample
- ? CelVerificationResult.failed(exactMatchMessage, witness)
- : CelVerificationResult.verified(exactMatchMessage, witness);
+ RuntimeCheck check = runtimeCheck.check(witness, /* countInternalErrors= */ true);
+ if (!check.isMatch().orElse(true)) {
+ return CelVerificationResult.inconclusive(
+ "Inconclusive: the CEL runtime disagrees with " + candidate + " the verifier found.");
+ }
+ return match(isCounterexample, exactMatchMessage + check.note(), witness);
} else if (status == Status.UNKNOWN) {
// Depends on solver internals; not deterministically testable.
return solverGaveUp(solver);
@@ -365,10 +391,20 @@ private CelVerificationResult search(
status = checkSat(solver, typeSystem, condition);
if (status == Status.SATISFIABLE) {
Model model = solver.getModel();
- return CelVerificationResult.inconclusive(
- inconclusiveReason(candidate, translator, model, taint),
- extractWitness(ctx, translator, model),
- isCounterexample);
+ CelWitness witness = extractWitness(ctx, translator, model);
+ RuntimeCheck check = runtimeCheck.check(witness, /* countInternalErrors= */ false);
+ if (check.isMatch().orElse(false)) {
+ return match(
+ isCounterexample,
+ String.format(
+ "%s The CEL runtime confirmed %s the verifier approximated.",
+ exactMatchMessage, candidate),
+ witness);
+ }
+ String reason = inconclusiveReason(candidate, translator, model, taint);
+ return check.isMatch().isPresent()
+ ? CelVerificationResult.inconclusive(reason)
+ : CelVerificationResult.inconclusive(reason + check.note(), witness, isCounterexample);
} else if (status == Status.UNKNOWN) {
// Depends on solver internals; not deterministically testable.
return solverGaveUp(solver);
@@ -389,6 +425,61 @@ private CelVerificationResult search(
: CelVerificationResult.failed("Condition is not satisfiable.");
}
+ private static CelVerificationResult match(
+ boolean isCounterexample, String reason, CelWitness witness) {
+ return isCounterexample
+ ? CelVerificationResult.failed(reason, witness)
+ : CelVerificationResult.verified(reason, witness);
+ }
+
+ private interface RuntimeChecker {
+ RuntimeChecker UNCHECKED = (witness, countInternalErrors) -> RuntimeCheck.UNCHECKED;
+
+ RuntimeCheck check(CelWitness witness, boolean countInternalErrors);
+ }
+
+ // Whether the runtime agrees a witness is a match, if it checked it, and a note for the message.
+ @AutoValue
+ abstract static class RuntimeCheck {
+ static final RuntimeCheck UNCHECKED =
+ new AutoValue_CelVerifierZ3Impl_RuntimeCheck(Optional.empty(), "");
+
+ abstract Optional isMatch();
+
+ abstract String note();
+
+ static RuntimeCheck of(boolean isMatch) {
+ return new AutoValue_CelVerifierZ3Impl_RuntimeCheck(Optional.of(isMatch), "");
+ }
+
+ static RuntimeCheck failed(String reason) {
+ return new AutoValue_CelVerifierZ3Impl_RuntimeCheck(
+ Optional.empty(),
+ " The CEL runtime couldn't check it: " + reason + (reason.endsWith(".") ? "" : "."));
+ }
+ }
+
+ // 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) {
+ if (!enableCegar || !unknownIdentifiers.isEmpty()) {
+ return RuntimeChecker.UNCHECKED;
+ }
+ return (witness, countInternalErrors) -> {
+ Optional> inputs = RuntimeOracle.exactInputs(witness);
+ if (!inputs.isPresent()) {
+ return RuntimeCheck.UNCHECKED;
+ }
+ try {
+ return RuntimeCheck.of(
+ isMatch.test(RuntimeOracle.evaluate(cel, inputs.get(), countInternalErrors, asts)));
+ } catch (CelEvaluationException e) {
+ return RuntimeCheck.failed(e.getMessage());
+ }
+ };
+ }
+
// Throws on a timeout. Leaves the assertions in place unless they're unsatisfiable, so the model
// or the reason the solver gave up can be read.
private static Status checkSat(Solver solver, CelZ3TypeSystem typeSystem, BoolExpr... assertions)
@@ -468,12 +559,14 @@ private CelVerifierZ3Impl(
ImmutableSet unknownIdentifiers,
CelZ3FunctionRegistry functionRegistry,
CelTypeProvider typeProvider,
+ boolean enableCegar,
Cel cel) {
this.timeout = timeout;
this.comprehensionUnrollLimit = comprehensionUnrollLimit;
this.unknownIdentifiers = unknownIdentifiers;
this.functionRegistry = functionRegistry;
this.typeProvider = typeProvider;
+ this.enableCegar = enableCegar;
this.cel = cel;
}
}
diff --git a/verifier/src/main/java/dev/cel/verifier/CelZ3CounterexampleGenerator.java b/verifier/src/main/java/dev/cel/verifier/CelZ3CounterexampleGenerator.java
index c7aef6643..94bcef460 100644
--- a/verifier/src/main/java/dev/cel/verifier/CelZ3CounterexampleGenerator.java
+++ b/verifier/src/main/java/dev/cel/verifier/CelZ3CounterexampleGenerator.java
@@ -26,6 +26,7 @@
import com.microsoft.z3.FuncDecl;
import com.microsoft.z3.IntNum;
import com.microsoft.z3.Model;
+import dev.cel.common.internal.MapKeys;
import dev.cel.common.internal.ProtoTimeUtils;
import dev.cel.common.values.CelByteString;
import dev.cel.common.values.NullValue;
@@ -265,6 +266,7 @@ private Value extractMap(Expr> mapRef) {
ImmutableMap.Builder values = ImmutableMap.builder();
List entries = new ArrayList<>();
Set> seenKeys = new HashSet<>();
+ Set runtimeKeys = new HashSet<>();
ArrayExpr keySet = ctx.mkConstArray(typeSystem.celValueSort(), ctx.mkFalse());
for (long i = 0; i < limit; i++) {
Expr> key = evaluate(ctx.mkNth(typeSystem.getMapKeys(mapRef), ctx.mkInt(i)));
@@ -276,7 +278,10 @@ private Value extractMap(Expr> mapRef) {
Value keyValue = extract(key);
Value value =
extract(evaluate(ctx.mkSelect((ArrayExpr) typeSystem.getMapValues(mapRef), key)));
- if (keyValue.runtimeValue.isPresent() && value.runtimeValue.isPresent()) {
+ if (keyValue.runtimeValue.isPresent()
+ && value.runtimeValue.isPresent()
+ && MapKeys.isValidKeyType(keyValue.runtimeValue.get())
+ && runtimeKeys.add(MapKeys.normalize(keyValue.runtimeValue.get()))) {
values.put(keyValue.runtimeValue.get(), value.runtimeValue.get());
} else {
isExact = false;
diff --git a/verifier/src/main/java/dev/cel/verifier/RuntimeOracle.java b/verifier/src/main/java/dev/cel/verifier/RuntimeOracle.java
new file mode 100644
index 000000000..00ac15ca3
--- /dev/null
+++ b/verifier/src/main/java/dev/cel/verifier/RuntimeOracle.java
@@ -0,0 +1,108 @@
+// Copyright 2026 Google LLC
+//
+// 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
+//
+// https://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 dev.cel.verifier;
+
+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.runtime.CelEvaluationException;
+import dev.cel.runtime.CelFunctionResolver;
+import dev.cel.runtime.CelResolvedOverload;
+import dev.cel.runtime.CelRuntime;
+import dev.cel.runtime.CelRuntime.Program;
+import dev.cel.runtime.CelUnknownSet;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * Evaluates expressions with the CEL runtime on a witness's inputs, to check the solver's
+ * candidates.
+ */
+final class RuntimeOracle {
+
+ // Stands for every evaluation error, matching the verifier's single error value.
+ private enum EvaluationError {
+ ERROR
+ }
+
+ /** The witness's inputs, if every value is exact. */
+ static Optional> exactInputs(CelWitness witness) {
+ return witness.variables().values().stream().allMatch(v -> v.value().isPresent())
+ ? Optional.of(
+ ImmutableMap.copyOf(Maps.transformValues(witness.variables(), v -> v.value().get())))
+ : Optional.empty();
+ }
+
+ /**
+ * 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.
+ */
+ static ImmutableList evaluate(
+ CelRuntime runtime,
+ Map inputs,
+ boolean countInternalErrors,
+ CelAbstractSyntaxTree... asts)
+ throws CelEvaluationException {
+ ImmutableList.Builder results = ImmutableList.builder();
+ for (CelAbstractSyntaxTree ast : asts) {
+ Program program = runtime.createProgram(ast);
+ // Notes calls to late-bound functions, which have no binding here. The legacy interpreter
+ // also consults them after any failed dispatch, so its dispatch errors go unchecked.
+ AtomicBoolean callsLateBound = new AtomicBoolean();
+ CelFunctionResolver lateBoundFunctions =
+ new CelFunctionResolver() {
+ @Override
+ public Optional findOverloadMatchingArgs(
+ String functionName, Collection overloadIds, Object[] args) {
+ return findOverloadMatchingArgs(functionName, args);
+ }
+
+ @Override
+ public Optional findOverloadMatchingArgs(
+ String functionName, Object[] args) {
+ callsLateBound.set(true);
+ return Optional.empty();
+ }
+ };
+ Object result;
+ try {
+ result = program.eval(inputs, lateBoundFunctions);
+ } catch (CelEvaluationException e) {
+ CelErrorCode code = e.getErrorCode();
+ // The runtime reports some CEL errors as internal, but also misused bindings (e.g. async).
+ if (callsLateBound.get()
+ || code == CelErrorCode.ITERATION_BUDGET_EXCEEDED
+ || (!countInternalErrors && code == CelErrorCode.INTERNAL_ERROR)) {
+ throw e;
+ }
+ result = EvaluationError.ERROR;
+ }
+ // A binding may return null or unknowns.
+ if (result == null || result instanceof CelUnknownSet) {
+ throw new CelEvaluationException(
+ result == null ? "a function returned null" : "it evaluated to unknowns");
+ }
+ results.add(result);
+ }
+ return results.build();
+ }
+
+ private RuntimeOracle() {}
+}
diff --git a/verifier/src/test/java/dev/cel/verifier/BUILD.bazel b/verifier/src/test/java/dev/cel/verifier/BUILD.bazel
index 91a24c23d..da198b15e 100644
--- a/verifier/src/test/java/dev/cel/verifier/BUILD.bazel
+++ b/verifier/src/test/java/dev/cel/verifier/BUILD.bazel
@@ -47,8 +47,8 @@ java_library(
"//policy:parser_factory",
"//policy:validation_exception",
"//policy/testing:k8s_test_tag_handler",
- "//runtime",
- "//runtime:evaluation_exception",
+ "//runtime:function_binding",
+ "//runtime:unknown_attributes",
"//testing/protos:single_file_java_proto",
"@bazel_tools//tools/java/runfiles",
"@maven//:com_google_errorprone_error_prone_annotations",
diff --git a/verifier/src/test/java/dev/cel/verifier/CelVerifierZ3ImplTest.java b/verifier/src/test/java/dev/cel/verifier/CelVerifierZ3ImplTest.java
index dca0d8d88..a1ef49882 100644
--- a/verifier/src/test/java/dev/cel/verifier/CelVerifierZ3ImplTest.java
+++ b/verifier/src/test/java/dev/cel/verifier/CelVerifierZ3ImplTest.java
@@ -22,6 +22,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.Immutable;
import com.google.testing.junit.testparameterinjector.TestParameter;
import com.google.testing.junit.testparameterinjector.TestParameterInjector;
// import com.google.testing.testsize.MediumTest;
@@ -38,6 +39,7 @@
import dev.cel.common.CelAbstractSyntaxTree;
import dev.cel.common.CelContainer;
import dev.cel.common.CelFunctionDecl;
+import dev.cel.common.CelOptions;
import dev.cel.common.CelOverloadDecl;
import dev.cel.common.CelVarDecl;
import dev.cel.common.Operator;
@@ -62,6 +64,8 @@
import dev.cel.optimizer.optimizers.SubexpressionOptimizer;
import dev.cel.parser.CelMacro;
import dev.cel.parser.CelStandardMacro;
+import dev.cel.runtime.CelFunctionBinding;
+import dev.cel.runtime.CelUnknownSet;
import dev.cel.verifier.CelVerificationResult.VerificationStatus;
import dev.cel.verifier.axioms.CelZ3FunctionAxiom;
import dev.cel.verifier.axioms.CelZ3OverloadResult;
@@ -71,7 +75,6 @@
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
-import java.util.function.UnaryOperator;
import java.util.stream.IntStream;
import org.junit.Before;
import org.junit.Test;
@@ -144,15 +147,35 @@ public final class CelVerifierZ3ImplTest {
TestAllTypes.getDescriptor(), TestAllTypes.NestedMessage.getDescriptor()))
.build();
- private static final CelVerifier VERIFIER = withRuntimeOracle(CEL, b -> b);
+ private static final CelVerifier VERIFIER = checkedVerifier(CEL).build();
- // For ASTs with functions the runtime can't plan, and for verifyImplication.
- private static final CelVerifier VERIFIER_WITHOUT_ORACLE =
- CelVerifierFactory.newVerifier(CEL).build();
+ // Doesn't check witnesses with the runtime: for approximate results, which it may confirm, for
+ // functions it has no bindings for, and for verifyImplication.
+ private static final CelVerifier UNCHECKED_VERIFIER = CelVerifierFactory.newVerifier(CEL).build();
- // Builds a verifier whose exact witnesses are checked against the runtime of the same `cel`.
- private static CelVerifier withRuntimeOracle(Cel cel, UnaryOperator config) {
- return RuntimeOracle.wrap(cel, config.apply(CelVerifierFactory.newVerifier(cel)).build());
+ private static final CelFunctionDecl ZERO_DECL =
+ CelFunctionDecl.newFunctionDeclaration(
+ "zero", CelOverloadDecl.newGlobalOverload("zero_int", SimpleType.INT, SimpleType.INT));
+
+ private static final Cel UNBOUND_ZERO_CEL =
+ CEL.toCelBuilder().addFunctionDeclarations(ZERO_DECL).build();
+
+ // The verifier doesn't model `zero`, but the runtime has a binding for it.
+ private static final Cel ZERO_CEL =
+ UNBOUND_ZERO_CEL
+ .toCelBuilder()
+ .addFunctionBindings(CelFunctionBinding.from("zero_int", Long.class, x -> 0L))
+ .build();
+
+ // A verifier builder that checks witnesses with the runtime of the same `cel`.
+ private static CelVerifierBuilder checkedVerifier(Cel cel) {
+ return CelVerifierFactory.newVerifier(cel).enableCegar(true);
+ }
+
+ // An exact verdict the runtime didn't refute or fail to check.
+ private static void assertExact(CelVerificationResult result, VerificationStatus status) {
+ assertWithMessage(result.message()).that(result.status()).isEqualTo(status);
+ assertThat(result.message()).doesNotContain("CEL runtime");
}
@Before
@@ -263,7 +286,7 @@ public void isSatisfiable_success(@TestParameter IsSatisfiableTestCase testCase)
CelVerificationResult result = VERIFIER.isSatisfiable(ast);
- assertThat(result.status()).isEqualTo(VerificationStatus.VERIFIED);
+ assertExact(result, VerificationStatus.VERIFIED);
for (String fragment : testCase.expectedFragments) {
assertThat(result.message()).containsMatch(fragment);
}
@@ -275,7 +298,7 @@ public void isSatisfiable_withVariable_returnsSatisfyingModel() throws Exception
CelVerificationResult result = VERIFIER.isSatisfiable(ast);
- assertThat(result.status()).isEqualTo(VerificationStatus.VERIFIED);
+ assertExact(result, VerificationStatus.VERIFIED);
assertThat(result.message()).contains("Condition is satisfiable.");
assertThat(result.message()).contains("Satisfying input:");
assertThat(result.message()).containsMatch("x = (?:[6-9]|[1-9]\\d+)");
@@ -343,6 +366,7 @@ public void isSatisfiable_witnessValueSatisfiesExpressionAndDisplayRoundTrips(
CelVerificationResult result = VERIFIER.isSatisfiable(ast);
+ assertExact(result, VerificationStatus.VERIFIED);
CelWitness.Variable variable = result.witness().get().variables().get(testCase.variableName);
assertThat(variable.displayValue()).isEqualTo(testCase.expectedDisplayValue);
ImmutableMap input =
@@ -380,6 +404,7 @@ public void isSatisfiable_noExactRuntimeValue_witnessValueEmpty(
CelVerificationResult result = VERIFIER.isSatisfiable(ast);
+ assertExact(result, VerificationStatus.VERIFIED);
assertThat(result.witness().get().variables().get(testCase.variableName).value()).isEmpty();
}
@@ -443,6 +468,7 @@ public void isSatisfiable_listAtDisplayLimit_displaysAllElements() throws Except
CelVerificationResult result = VERIFIER.isSatisfiable(ast);
+ assertExact(result, VerificationStatus.VERIFIED);
assertThat(result.message())
.endsWith("int_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]");
}
@@ -450,12 +476,13 @@ public void isSatisfiable_listAtDisplayLimit_displaysAllElements() throws Except
@Test
public void isSatisfiable_listPastDisplayLimit_elidesRemainingElements() throws Exception {
// Within the unroll limit the whole list is extracted, so the display must still elide it.
- CelVerifier verifier = withRuntimeOracle(CEL, b -> b.setComprehensionUnrollLimit(16));
+ CelVerifier verifier = checkedVerifier(CEL).setComprehensionUnrollLimit(16).build();
CelAbstractSyntaxTree ast =
CEL.compile("int_list == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]").getAst();
CelVerificationResult result = verifier.isSatisfiable(ast);
+ assertExact(result, VerificationStatus.VERIFIED);
assertThat(result.message())
.endsWith(
"int_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, ... (1 more"
@@ -468,7 +495,7 @@ public void isSatisfiable_mapNoContainerError_returnsSatisfyingModel() throws Ex
CelVerificationResult result = VERIFIER.isSatisfiable(ast);
- assertThat(result.status()).isEqualTo(VerificationStatus.VERIFIED);
+ assertExact(result, VerificationStatus.VERIFIED);
assertThat(result.message()).contains("Condition is satisfiable.");
assertThat(result.message()).contains("Satisfying input:");
assertThat(result.message()).contains("string_int_map = {");
@@ -481,7 +508,7 @@ public void isSatisfiable_listNoContainerError_returnsSatisfyingModel() throws E
CelVerificationResult result = VERIFIER.isSatisfiable(ast);
- assertThat(result.status()).isEqualTo(VerificationStatus.VERIFIED);
+ assertExact(result, VerificationStatus.VERIFIED);
assertThat(result.message()).contains("Condition is satisfiable.");
assertThat(result.message()).contains("Satisfying input:");
assertThat(result.message()).contains("dyn_list = [");
@@ -494,7 +521,7 @@ public void isSatisfiable_dynMapNoContainerError_returnsSatisfyingModel() throws
CelVerificationResult result = VERIFIER.isSatisfiable(ast);
- assertThat(result.status()).isEqualTo(VerificationStatus.VERIFIED);
+ assertExact(result, VerificationStatus.VERIFIED);
assertThat(result.message()).contains("Condition is satisfiable.");
assertThat(result.message()).contains("Satisfying input:");
assertThat(result.message()).contains("dyn_map = {");
@@ -507,7 +534,7 @@ public void counterexample_nullValueFormattedAsNull() throws Exception {
CelVerificationResult result = VERIFIER.isSatisfiable(ast);
- assertThat(result.status()).isEqualTo(VerificationStatus.VERIFIED);
+ assertExact(result, VerificationStatus.VERIFIED);
assertThat(result.message()).contains("request = null");
}
@@ -518,7 +545,7 @@ public void counterexample_mapFormattedCorrectly() throws Exception {
CelVerificationResult result = VERIFIER.isSatisfiable(ast);
- assertThat(result.status()).isEqualTo(VerificationStatus.VERIFIED);
+ assertExact(result, VerificationStatus.VERIFIED);
assertThat(result.message()).containsMatch("string_int_map = \\{[^}]*,[^}]*\\}");
assertThat(result.message()).contains("\"a\": 1");
}
@@ -545,7 +572,7 @@ public void isAlwaysTrue_counterexampleNeverContainsError(
CelVerificationResult result = VERIFIER.isAlwaysTrue(ast);
- assertThat(result.status()).isEqualTo(VerificationStatus.VIOLATED);
+ assertExact(result, VerificationStatus.VIOLATED);
assertThat(result.message()).doesNotContain("Error");
}
@@ -555,7 +582,7 @@ public void isSatisfiable_unconditional_returnsUnconditionalMessage() throws Exc
CelVerificationResult result = VERIFIER.isSatisfiable(ast);
- assertThat(result.status()).isEqualTo(VerificationStatus.VERIFIED);
+ assertExact(result, VerificationStatus.VERIFIED);
assertThat(result.message())
.isEqualTo(
"Condition is satisfiable. (The expression is satisfiable unconditionally, regardless"
@@ -635,7 +662,7 @@ public void isSatisfiable_approximate_listsApproximationSources(
@TestParameter ApproximationSourceTestCase testCase) throws Exception {
CelAbstractSyntaxTree ast = CEL.compile(testCase.expr).getAst();
- CelVerificationResult result = VERIFIER.isSatisfiable(ast);
+ CelVerificationResult result = UNCHECKED_VERIFIER.isSatisfiable(ast);
assertThat(result.status()).isEqualTo(VerificationStatus.INCONCLUSIVE);
assertThat(result.reason())
@@ -675,7 +702,7 @@ public void isSatisfiable_uninterpretedFunctions_listsApproximationSources(
.build();
CelAbstractSyntaxTree ast = celCompiler.compile(testCase.expr).getAst();
- CelVerificationResult result = VERIFIER_WITHOUT_ORACLE.isSatisfiable(ast);
+ CelVerificationResult result = UNCHECKED_VERIFIER.isSatisfiable(ast);
assertThat(result.status()).isEqualTo(VerificationStatus.INCONCLUSIVE);
assertThat(result.reason())
@@ -690,7 +717,7 @@ public void isSatisfiable_uninterpretedFunctions_listsApproximationSources(
public void isSatisfiable_approximate_returnsPotentialSatisfyingInput() throws Exception {
CelAbstractSyntaxTree ast = CEL.compile("int('123') == 123 ? x > 5 : false").getAst();
- CelVerificationResult result = VERIFIER.isSatisfiable(ast);
+ CelVerificationResult result = UNCHECKED_VERIFIER.isSatisfiable(ast);
assertThat(result.status()).isEqualTo(VerificationStatus.INCONCLUSIVE);
assertThat(result.message()).contains("Inconclusive: a satisfying input may exist");
@@ -799,7 +826,7 @@ public void isSatisfiable_inconclusive(@TestParameter IsSatisfiableInconclusiveT
throws Exception {
CelAbstractSyntaxTree ast = CEL.compile(testCase.expr).getAst();
- CelVerificationResult result = VERIFIER.isSatisfiable(ast);
+ CelVerificationResult result = UNCHECKED_VERIFIER.isSatisfiable(ast);
assertThat(result.status()).isEqualTo(VerificationStatus.INCONCLUSIVE);
}
@@ -814,7 +841,8 @@ public void isSatisfiable_mapLiteralWithDynMapBeyondBmcLimit_inconclusive(
throws Exception {
CelAbstractSyntaxTree ast = CEL.compile(expr).getAst();
// A small unroll limit keeps the solver fast; the maps are still past it.
- CelVerifier verifier = withRuntimeOracle(CEL, b -> b.setComprehensionUnrollLimit(1));
+ CelVerifier verifier =
+ CelVerifierFactory.newVerifier(CEL).setComprehensionUnrollLimit(1).build();
CelVerificationResult result = verifier.isSatisfiable(ast);
@@ -829,8 +857,10 @@ public void isSatisfiable_maskedByBmcNested_inconclusive() throws Exception {
CelAbstractSyntaxTree ast = CEL.compile(expr).getAst();
CelVerifier customVerifier =
- withRuntimeOracle(
- CEL, b -> b.setComprehensionUnrollLimit(3).setTypeProvider(TYPE_PROVIDER));
+ CelVerifierFactory.newVerifier(CEL)
+ .setComprehensionUnrollLimit(3)
+ .setTypeProvider(TYPE_PROVIDER)
+ .build();
CelVerificationResult result = customVerifier.isSatisfiable(ast);
@@ -842,7 +872,8 @@ public void isSatisfiable_comprehensionZeroUnrollLimit_inconclusive() throws Exc
String expr = "int_list == [1] ? int_list.exists(x, x == 1) : false";
CelAbstractSyntaxTree ast = CEL.compile(expr).getAst();
- CelVerifier verifier = withRuntimeOracle(CEL, b -> b.setComprehensionUnrollLimit(0));
+ CelVerifier verifier =
+ CelVerifierFactory.newVerifier(CEL).setComprehensionUnrollLimit(0).build();
CelVerificationResult result = verifier.isSatisfiable(ast);
assertThat(result.status()).isEqualTo(VerificationStatus.INCONCLUSIVE);
@@ -975,7 +1006,7 @@ public void isSatisfiable_failure(@TestParameter IsUnsatisfiableTestCase testCas
CelVerificationResult result = VERIFIER.isSatisfiable(ast);
- assertThat(result.status()).isEqualTo(VerificationStatus.VIOLATED);
+ assertExact(result, VerificationStatus.VIOLATED);
assertThat(result.message()).isEqualTo("Condition is not satisfiable.");
}
@@ -1602,7 +1633,8 @@ public void isAlwaysTrue_withUnknownIdentifier_evaluatesToUnknown(
throws Exception {
CelAbstractSyntaxTree ast = CEL.compile(expression).getAst();
- CelVerifier verifierWithUnknown = withRuntimeOracle(CEL, b -> b.addUnknownIdentifier("x"));
+ CelVerifier verifierWithUnknown =
+ CelVerifierFactory.newVerifier(CEL).addUnknownIdentifier("x").build();
// 'x == x' is not a tautology if it can be unknown
// i.e: CelUnknown == CelUnknown is unknown.
@@ -1636,7 +1668,8 @@ private enum ApproximateBesideUnknownTestCase {
public void isAlwaysTrue_approximateBesideUnknown_inconclusive(
@TestParameter ApproximateBesideUnknownTestCase testCase) throws Exception {
CelAbstractSyntaxTree ast = CEL.compile(testCase.expr).getAst();
- CelVerifier verifier = withRuntimeOracle(CEL, b -> b.addUnknownIdentifier("unknown_var"));
+ CelVerifier verifier =
+ CelVerifierFactory.newVerifier(CEL).addUnknownIdentifier("unknown_var").build();
CelVerificationResult result = verifier.isAlwaysTrue(ast);
@@ -1657,9 +1690,9 @@ public void isAlwaysTrue_dynamicComprehensionNonBoolYieldsError() throws Excepti
+ " dyn_list.all(x, x.not_a_bool) == false) : true";
CelAbstractSyntaxTree ast = CEL.compile(expr).getAst();
CelVerificationResult result =
- withRuntimeOracle(CEL, b -> b.setComprehensionUnrollLimit(1)).isAlwaysTrue(ast);
+ checkedVerifier(CEL).setComprehensionUnrollLimit(1).build().isAlwaysTrue(ast);
- assertThat(result.status()).isEqualTo(VerificationStatus.VIOLATED);
+ assertExact(result, VerificationStatus.VIOLATED);
assertThat(result.message())
.matches(
"Condition is not always true\\. Counterexample input:\n"
@@ -1671,7 +1704,8 @@ public void isAlwaysTrue_comprehensionExceedsMaxIterations_returnsUnknown() thro
String expr = "int_list == [1, 2, 3] ? int_list.all(x, x > 0) : true";
CelAbstractSyntaxTree ast = CEL.compile(expr).getAst();
- CelVerifier verifier = withRuntimeOracle(CEL, b -> b.setComprehensionUnrollLimit(2));
+ CelVerifier verifier =
+ CelVerifierFactory.newVerifier(CEL).setComprehensionUnrollLimit(2).build();
CelVerificationResult verifiedValue = verifier.isAlwaysTrue(ast);
// Truncated loops return Unknown, which negates to Unknown.
@@ -1688,7 +1722,7 @@ public void isAlwaysTrue_comprehensionZeroUnrollLimit_emptyList() throws Excepti
String expr = "int_list == [] ? int_list.all(x, x > 0) : true";
CelAbstractSyntaxTree ast = CEL.compile(expr).getAst();
- CelVerifier verifier = withRuntimeOracle(CEL, b -> b.setComprehensionUnrollLimit(0));
+ CelVerifier verifier = checkedVerifier(CEL).setComprehensionUnrollLimit(0).build();
CelVerificationResult verifiedValue = verifier.isAlwaysTrue(ast);
assertThat(verifiedValue.status()).isEqualTo(VerificationStatus.VERIFIED);
@@ -1718,7 +1752,7 @@ public void isAlwaysTrue_strictCustomFunction_errorPropagates() throws Exception
CelAbstractSyntaxTree ast =
celWithCustomFunc.compile("custom_func(1 / 0) == 5 || !(custom_func(1 / 0) == 5)").getAst();
- CelVerificationResult result = VERIFIER_WITHOUT_ORACLE.isAlwaysTrue(ast);
+ CelVerificationResult result = UNCHECKED_VERIFIER.isAlwaysTrue(ast);
// Should fail verification because the error propagates through custom_func,
// so the whole expression evaluates to an error, not true.
@@ -1783,12 +1817,11 @@ public void verifyEquivalence_withUnknownIdentifiers_inconclusive(
CelAbstractSyntaxTree astA = CEL.compile(testCase.exprA).getAst();
CelAbstractSyntaxTree astB = CEL.compile(testCase.exprB).getAst();
CelVerifier verifier =
- withRuntimeOracle(
- CEL,
- b ->
- b.addUnknownIdentifier("a")
- .addUnknownIdentifier("x")
- .addUnknownIdentifier("unknown_var"));
+ CelVerifierFactory.newVerifier(CEL)
+ .addUnknownIdentifier("a")
+ .addUnknownIdentifier("x")
+ .addUnknownIdentifier("unknown_var")
+ .build();
CelVerificationResult result = verifier.verifyEquivalence(astA, astB);
@@ -1815,7 +1848,7 @@ public void verifyEquivalence_freeVariableIndicesDeduplicated() throws Exception
CelAbstractSyntaxTree astB =
CEL.compile("x == y && y == port ? dyn_list.all(e, y == port) : false").getAst();
- CelVerificationResult result = VERIFIER.verifyEquivalence(astA, astB);
+ CelVerificationResult result = UNCHECKED_VERIFIER.verifyEquivalence(astA, astB);
assertThat(result.status()).isEqualTo(VerificationStatus.INCONCLUSIVE);
}
@@ -1835,7 +1868,7 @@ public void isSatisfiable_approximateIterRangeInMap_inconclusive() throws Except
CelAbstractSyntaxTree ast =
celWithCustomFunc.compile("approx_list(1).map(x, x * 2) == []").getAst();
- CelVerificationResult result = VERIFIER_WITHOUT_ORACLE.isSatisfiable(ast);
+ CelVerificationResult result = UNCHECKED_VERIFIER.isSatisfiable(ast);
assertThat(result.status()).isEqualTo(VerificationStatus.INCONCLUSIVE);
}
@@ -1855,7 +1888,7 @@ public void isSatisfiable_mapWithUnusedApproximateIteration_verified() throws Ex
CelAbstractSyntaxTree ast =
celWithCustomFunc.compile("y == [] && y.map(x, approx_func(1)) == y").getAst();
- CelVerificationResult result = VERIFIER_WITHOUT_ORACLE.isSatisfiable(ast);
+ CelVerificationResult result = UNCHECKED_VERIFIER.isSatisfiable(ast);
assertThat(result.status()).isEqualTo(VerificationStatus.VERIFIED);
}
@@ -1904,7 +1937,7 @@ public void isAlwaysTrue_unconditionalError_failsVerification(
CelVerificationResult result = VERIFIER.isAlwaysTrue(ast);
- assertThat(result.status()).isEqualTo(VerificationStatus.VIOLATED);
+ assertExact(result, VerificationStatus.VIOLATED);
assertThat(result.message())
.isEqualTo(
"Condition is not always true. (The expression fails unconditionally, regardless of"
@@ -1919,7 +1952,7 @@ public void verifyEquivalence_unconditionalError_failsVerification(
CelVerificationResult result = VERIFIER.verifyEquivalence(astA, astB);
- assertThat(result.status()).isEqualTo(VerificationStatus.VIOLATED);
+ assertExact(result, VerificationStatus.VIOLATED);
assertThat(result.message())
.isEqualTo(
"Equivalence violation detected. (The expression fails unconditionally, regardless of"
@@ -1934,7 +1967,7 @@ public void verifyEquivalence_dynamicMapEquality_enforcesExtensionalityOnPresent
CelVerificationResult result = VERIFIER.verifyEquivalence(astA, astB);
- assertThat(result.status()).isEqualTo(VerificationStatus.VIOLATED);
+ assertExact(result, VerificationStatus.VIOLATED);
assertThat(result.message()).contains("string_int_map =");
assertThat(result.message()).doesNotContain("string_int_map = {'a': 1}");
}
@@ -2008,7 +2041,7 @@ public void verifyEquivalence_infinityConstants_notEquivalent() throws Exception
CelVerificationResult result = VERIFIER.verifyEquivalence(astA, astB);
- assertThat(result.status()).isEqualTo(VerificationStatus.VIOLATED);
+ assertExact(result, VerificationStatus.VIOLATED);
}
private enum IsAlwaysTrueViolationTestCase {
@@ -2374,7 +2407,7 @@ public void isAlwaysTrue_violation_returnsFalse(
CelVerificationResult result = VERIFIER.isAlwaysTrue(ast);
- assertThat(result.status()).isEqualTo(VerificationStatus.VIOLATED);
+ assertExact(result, VerificationStatus.VIOLATED);
for (String fragment : testCase.expectedFragments) {
assertThat(result.message()).containsMatch(fragment);
}
@@ -2391,11 +2424,11 @@ public void isAlwaysTrue_dynValuesComparedWithIntConstant_verified(
CelAbstractSyntaxTree ast = CEL.compile(expression).getAst();
// A tighter timeout than the default, so that removing the fast path for comparing doubles with
// exact integer constants fails as a performance regression (~0.3 s with it, 19-45 s without).
- CelVerifier verifier = withRuntimeOracle(CEL, b -> b.setTimeout(Duration.ofSeconds(5)));
+ CelVerifier verifier = checkedVerifier(CEL).setTimeout(Duration.ofSeconds(5)).build();
CelVerificationResult result = verifier.isAlwaysTrue(ast);
- assertThat(result.status()).isEqualTo(VerificationStatus.VERIFIED);
+ assertExact(result, VerificationStatus.VERIFIED);
}
@Test
@@ -2410,11 +2443,11 @@ public void isAlwaysTrue_dynamicMapComprehensionNestedEquality_violated() throws
// (longer on GitHub runners).
// TODO: Restore 20 s once the slowdown since map literal key validation is
// recovered.
- CelVerifier verifier = withRuntimeOracle(CEL, b -> b.setTimeout(Duration.ofSeconds(60)));
+ CelVerifier verifier = checkedVerifier(CEL).setTimeout(Duration.ofSeconds(60)).build();
CelVerificationResult result = verifier.isAlwaysTrue(ast);
- assertThat(result.status()).isEqualTo(VerificationStatus.VIOLATED);
+ assertExact(result, VerificationStatus.VIOLATED);
assertThat(result.message()).contains("request = ");
}
@@ -2533,7 +2566,7 @@ public void isAlwaysTrue_inconclusive(@TestParameter IsInconclusiveTestCase test
throws Exception {
CelAbstractSyntaxTree ast = CEL.compile(testCase.expr).getAst();
- CelVerificationResult result = VERIFIER.isAlwaysTrue(ast);
+ CelVerificationResult result = UNCHECKED_VERIFIER.isAlwaysTrue(ast);
assertThat(result.status()).isEqualTo(VerificationStatus.INCONCLUSIVE);
}
@@ -2542,7 +2575,7 @@ public void isAlwaysTrue_inconclusive(@TestParameter IsInconclusiveTestCase test
public void isAlwaysTrue_inconclusive_containsPotentialCounterexample() throws Exception {
CelAbstractSyntaxTree ast = CEL.compile("request.matches('^[a-z]+$') == true").getAst();
- CelVerificationResult result = VERIFIER.isAlwaysTrue(ast);
+ CelVerificationResult result = UNCHECKED_VERIFIER.isAlwaysTrue(ast);
assertThat(result.status()).isEqualTo(VerificationStatus.INCONCLUSIVE);
assertThat(result.message())
@@ -2646,7 +2679,7 @@ public void verifyEquivalence_dynComprehensionRange_listedAsApproximationSource(
CelAbstractSyntaxTree astA = CEL.compile("dyn_var.all(e, e > 0)").getAst();
CelAbstractSyntaxTree astB = CEL.compile("dyn_var.all(e, e < 0)").getAst();
- CelVerificationResult result = VERIFIER.verifyEquivalence(astA, astB);
+ CelVerificationResult result = UNCHECKED_VERIFIER.verifyEquivalence(astA, astB);
assertThat(result.reason())
.isEqualTo(
@@ -2658,7 +2691,8 @@ public void verifyEquivalence_dynComprehensionRange_listedAsApproximationSource(
public void verifyEquivalence_unknownResults_listedAsApproximationSource() throws Exception {
CelAbstractSyntaxTree astA = CEL.compile("unknown_var * 1").getAst();
CelAbstractSyntaxTree astB = CEL.compile("unknown_var + 0").getAst();
- CelVerifier verifier = withRuntimeOracle(CEL, b -> b.addUnknownIdentifier("unknown_var"));
+ CelVerifier verifier =
+ CelVerifierFactory.newVerifier(CEL).addUnknownIdentifier("unknown_var").build();
CelVerificationResult result = verifier.verifyEquivalence(astA, astB);
@@ -2674,7 +2708,7 @@ public void verifyEquivalence_inconclusive(
CelAbstractSyntaxTree astA = CEL.compile(testCase.exprA).getAst();
CelAbstractSyntaxTree astB = CEL.compile(testCase.exprB).getAst();
- CelVerificationResult result = VERIFIER.verifyEquivalence(astA, astB);
+ CelVerificationResult result = UNCHECKED_VERIFIER.verifyEquivalence(astA, astB);
assertThat(result.status()).isEqualTo(VerificationStatus.INCONCLUSIVE);
}
@@ -3322,7 +3356,7 @@ public void verifyEquivalence_violation_returnsFalse(
CelVerificationResult result = VERIFIER.verifyEquivalence(astA, astB);
- assertThat(result.status()).isEqualTo(VerificationStatus.VIOLATED);
+ assertExact(result, VerificationStatus.VIOLATED);
assertThat(result.message()).contains("Equivalence violation detected.");
}
@@ -3333,7 +3367,7 @@ public void verifyEquivalence_violation_hasCounterexampleMessage() throws Except
CelVerificationResult result = VERIFIER.verifyEquivalence(astA, astB);
- assertThat(result.status()).isEqualTo(VerificationStatus.VIOLATED);
+ assertExact(result, VerificationStatus.VIOLATED);
String message = result.message();
assertThat(message).contains("Equivalence violation detected. Counterexample input:");
assertThat(message).containsMatch(" {2}x = -?\\d+");
@@ -3349,7 +3383,7 @@ public void verifyEquivalence_divergesOnTernaryErrorSemantics() throws Exception
CelVerificationResult result = VERIFIER.verifyEquivalence(astA, astB);
- assertThat(result.status()).isEqualTo(VerificationStatus.VIOLATED);
+ assertExact(result, VerificationStatus.VIOLATED);
}
@Test
@@ -3361,7 +3395,7 @@ public void verifyEquivalence_dynamicIndexingWithExplicitMap_hydratesMap() throw
CelVerificationResult result = VERIFIER.verifyEquivalence(astA, astB);
- assertThat(result.status()).isEqualTo(VerificationStatus.VIOLATED);
+ assertExact(result, VerificationStatus.VIOLATED);
assertThat(result.message()).contains("string_int_list_map = {");
assertThat(result.message()).contains("\"a\": [1, 2]");
assertThat(result.message()).containsMatch("\"b\": \\[3, [45]]");
@@ -3372,7 +3406,7 @@ public void verifyEquivalence_logicalAndShortCircuitError_isVerified() throws Ex
CelAbstractSyntaxTree astA = CEL.compile("false && (1 / 0 == 0)").getAst();
CelAbstractSyntaxTree astB = CEL.compile("false").getAst();
CelVerificationResult result = VERIFIER.verifyEquivalence(astA, astB);
- assertThat(result.status()).isEqualTo(VerificationStatus.VERIFIED);
+ assertExact(result, VerificationStatus.VERIFIED);
}
@Test
@@ -3380,7 +3414,7 @@ public void verifyEquivalence_logicalOrShortCircuitUnknown_isVerified() throws E
CelAbstractSyntaxTree astA = CEL.compile("true || unknown_var").getAst();
CelAbstractSyntaxTree astB = CEL.compile("true").getAst();
CelVerificationResult result = VERIFIER.verifyEquivalence(astA, astB);
- assertThat(result.status()).isEqualTo(VerificationStatus.VERIFIED);
+ assertExact(result, VerificationStatus.VERIFIED);
}
@Test
@@ -3388,7 +3422,7 @@ public void verifyEquivalence_deepListExtensionality_isVerified() throws Excepti
CelAbstractSyntaxTree astA = CEL.compile("[[[[1]]]] == [[[[1]]]]").getAst();
CelAbstractSyntaxTree astB = CEL.compile("true").getAst();
CelVerificationResult result = VERIFIER.verifyEquivalence(astA, astB);
- assertThat(result.status()).isEqualTo(VerificationStatus.VERIFIED);
+ assertExact(result, VerificationStatus.VERIFIED);
}
@Test
@@ -3397,7 +3431,7 @@ public void verifyEquivalence_stringConcatenationExplosion_isVerified() throws E
CEL.compile("(\"a\" + \"b\" + \"c\" + \"d\" + \"e\") == \"abcde\"").getAst();
CelAbstractSyntaxTree astB = CEL.compile("true").getAst();
CelVerificationResult result = VERIFIER.verifyEquivalence(astA, astB);
- assertThat(result.status()).isEqualTo(VerificationStatus.VERIFIED);
+ assertExact(result, VerificationStatus.VERIFIED);
}
@Test
@@ -3409,7 +3443,7 @@ public void verifyEquivalence_divergesOnShortCircuitingErrors() throws Exception
CelVerificationResult result = VERIFIER.verifyEquivalence(astA, astB);
- assertThat(result.status()).isEqualTo(VerificationStatus.VERIFIED);
+ assertExact(result, VerificationStatus.VERIFIED);
}
@Test
@@ -3420,7 +3454,7 @@ public void verifyEquivalence_distinctErrorEquivalence_failsVerification() throw
CelAbstractSyntaxTree astB = CEL.compile("role + role == \"abc\"").getAst();
CelVerificationResult result = VERIFIER.verifyEquivalence(astA, astB);
- assertThat(result.status()).isEqualTo(VerificationStatus.VIOLATED);
+ assertExact(result, VerificationStatus.VIOLATED);
}
private enum CounterexampleFormatTestCase {
@@ -3528,7 +3562,7 @@ public void verifyEquivalence_counterexampleFormat(
CelAbstractSyntaxTree astB = CEL.compile(testCase.exprB).getAst();
CelVerificationResult result = VERIFIER.verifyEquivalence(astA, astB);
- assertThat(result.status()).isEqualTo(VerificationStatus.VIOLATED);
+ assertExact(result, VerificationStatus.VIOLATED);
boolean matched =
testCase.expectedFragments.stream()
.anyMatch(
@@ -3551,7 +3585,7 @@ public void verifyEquivalence_structCounterexampleFormat() throws Exception {
CEL.compile("test_all_types == TestAllTypes{single_int32: 2}").getAst();
CelVerificationResult result = VERIFIER.verifyEquivalence(astA, astB);
- assertThat(result.status()).isEqualTo(VerificationStatus.VIOLATED);
+ assertExact(result, VerificationStatus.VIOLATED);
assertThat(result.message())
.isAnyOf(
"Equivalence violation detected. Counterexample input:\n"
@@ -3568,7 +3602,7 @@ public void isAlwaysTrue_operationError_counterexampleFormat() throws Exception
CelAbstractSyntaxTree ast = CEL.compile("x / x == x / x").getAst();
CelVerificationResult result = VERIFIER.isAlwaysTrue(ast);
- assertThat(result.status()).isEqualTo(VerificationStatus.VIOLATED);
+ assertExact(result, VerificationStatus.VIOLATED);
assertThat(result.message()).contains("x = 0");
}
@@ -3585,7 +3619,7 @@ public void isAlwaysTrue_dynamicFunction_inconclusive() throws Exception {
CelOverloadDecl.newGlobalOverload("request_overload", SimpleType.DYN)))
.build();
CelAbstractSyntaxTree ast = celCompiler.compile("request() == request()").getAst();
- CelVerificationResult result = VERIFIER.isAlwaysTrue(ast);
+ CelVerificationResult result = UNCHECKED_VERIFIER.isAlwaysTrue(ast);
assertThat(result.status()).isEqualTo(VerificationStatus.INCONCLUSIVE);
assertThat(result.message()).contains("doesn't model exactly: calls to `request`.");
@@ -3604,7 +3638,7 @@ public void isAlwaysTrue_dynamicFunctionShortCircuited_violated() throws Excepti
.build();
CelAbstractSyntaxTree ast = celCompiler.compile("x != 0 && request() == 1").getAst();
- CelVerificationResult result = VERIFIER_WITHOUT_ORACLE.isAlwaysTrue(ast);
+ CelVerificationResult result = UNCHECKED_VERIFIER.isAlwaysTrue(ast);
assertThat(result.status()).isEqualTo(VerificationStatus.VIOLATED);
assertThat(result.message()).contains("x = 0");
@@ -3621,7 +3655,7 @@ public void isAlwaysTrue_boolFunction_verified() throws Exception {
CelOverloadDecl.newGlobalOverload("bool_func_overload", SimpleType.BOOL)))
.build();
CelAbstractSyntaxTree ast = celCompiler.compile("bool_func() == bool_func()").getAst();
- CelVerificationResult result = VERIFIER_WITHOUT_ORACLE.isAlwaysTrue(ast);
+ CelVerificationResult result = UNCHECKED_VERIFIER.isAlwaysTrue(ast);
assertThat(result.status()).isEqualTo(VerificationStatus.VERIFIED);
}
@@ -3656,7 +3690,7 @@ public void isAlwaysTrue_distinctFunctionSymbols_inconclusive(
"f_list_string", SimpleType.INT, ListType.create(SimpleType.STRING))))
.build();
CelAbstractSyntaxTree ast = celCompiler.compile(expression).getAst();
- CelVerificationResult result = VERIFIER.isAlwaysTrue(ast);
+ CelVerificationResult result = UNCHECKED_VERIFIER.isAlwaysTrue(ast);
assertThat(result.status()).isEqualTo(VerificationStatus.INCONCLUSIVE);
}
@@ -3672,7 +3706,7 @@ public void isAlwaysTrue_zeroArityFunctionAndSameNamedVariable_inconclusive() th
.build();
CelAbstractSyntaxTree ast = celCompiler.compile("g() == g").getAst();
- CelVerificationResult result = VERIFIER.isAlwaysTrue(ast);
+ CelVerificationResult result = UNCHECKED_VERIFIER.isAlwaysTrue(ast);
assertThat(result.status()).isEqualTo(VerificationStatus.INCONCLUSIVE);
}
@@ -3690,9 +3724,9 @@ public void verifyEquivalence_identicalFunctionCalls_equivalent() throws Excepti
.build();
CelAbstractSyntaxTree astA = celCompiler.compile("request()").getAst();
CelAbstractSyntaxTree astB = celCompiler.compile("request()").getAst();
- CelVerificationResult result = VERIFIER.verifyEquivalence(astA, astB);
+ CelVerificationResult result = UNCHECKED_VERIFIER.verifyEquivalence(astA, astB);
- assertThat(result.status()).isEqualTo(VerificationStatus.VERIFIED);
+ assertExact(result, VerificationStatus.VERIFIED);
}
@Test
@@ -3711,7 +3745,7 @@ public void isSatisfiable_customOperatorOverload_inconclusive() throws Exception
.build();
CelAbstractSyntaxTree ast = celCompiler.compile("!(int_list < int_list_2)").getAst();
- CelVerificationResult result = VERIFIER.isSatisfiable(ast);
+ CelVerificationResult result = UNCHECKED_VERIFIER.isSatisfiable(ast);
assertThat(result.status()).isEqualTo(VerificationStatus.INCONCLUSIVE);
}
@@ -3733,7 +3767,7 @@ public void isSatisfiable_divisionByZero_failsInCelWithErrors() throws Exception
CelVerificationResult result = VERIFIER.isSatisfiable(ast);
- assertThat(result.status()).isEqualTo(VerificationStatus.VIOLATED);
+ assertExact(result, VerificationStatus.VIOLATED);
}
@Test
@@ -3746,7 +3780,7 @@ public void isSatisfiable_timeoutReached_throwsCelVerificationException() throws
.addVar("d4", SimpleType.DOUBLE)
.build();
CelVerifier timeoutVerifier =
- withRuntimeOracle(customCel, b -> b.setTimeout(Duration.ofMillis(1)));
+ checkedVerifier(customCel).setTimeout(Duration.ofMillis(1)).build();
// An overly complex double multiplication to guarantee Z3 FPA theory solver timeouts.
CelAbstractSyntaxTree ast =
@@ -4043,7 +4077,7 @@ public void isAlwaysTrue_nanAndInfinityConstants_isFalse(
CelAbstractSyntaxTree ast = CEL.compile(expr).getAst();
CelAbstractSyntaxTree optimizedAst = optimizer.optimize(ast);
- assertThat(VERIFIER.isAlwaysTrue(optimizedAst).status()).isEqualTo(VerificationStatus.VIOLATED);
+ assertExact(VERIFIER.isAlwaysTrue(optimizedAst), VerificationStatus.VIOLATED);
}
@Test
@@ -4071,7 +4105,7 @@ public void isSatisfiable_typeVariable_mayHoldAnyType() throws Exception {
CelAbstractSyntaxTree ast = CEL.compile("type_var == int").getAst();
// The planner can't evaluate a variable typed type(dyn), so the runtime can't check witnesses.
- CelVerificationResult result = VERIFIER_WITHOUT_ORACLE.isSatisfiable(ast);
+ CelVerificationResult result = UNCHECKED_VERIFIER.isSatisfiable(ast);
assertThat(result.status()).isEqualTo(VerificationStatus.VERIFIED);
}
@@ -4091,11 +4125,281 @@ public void isAlwaysTrue_blockIndexLiteralPastUnrollLimit_verified(
.build();
CelAbstractSyntaxTree ast = optimizer.optimize(CEL.compile(expr).getAst());
- CelVerificationResult result = VERIFIER_WITHOUT_ORACLE.isAlwaysTrue(ast);
+ CelVerificationResult result = UNCHECKED_VERIFIER.isAlwaysTrue(ast);
assertThat(result.status()).isEqualTo(VerificationStatus.VERIFIED);
}
+ @FunctionalInterface
+ @Immutable
+ private interface VerifierCall {
+ CelVerificationResult call(CelVerifier verifier) throws Exception;
+ }
+
+ private static VerifierCall alwaysTrue(String expr) {
+ return v -> v.isAlwaysTrue(ZERO_CEL.compile(expr).getAst());
+ }
+
+ private static VerifierCall satisfiable(String expr) {
+ return v -> v.isSatisfiable(ZERO_CEL.compile(expr).getAst());
+ }
+
+ // Models `zero(x)` as `value`.
+ private static CelZ3FunctionAxiom zeroAxiom(long value) {
+ return CelZ3FunctionAxiom.newBuilder(ZERO_DECL)
+ .addUnaryOverloadTranslator(
+ "zero_int",
+ (ctx, typeSystem, constraintSink, arg) -> Optional.of(typeSystem.mkInt(value)))
+ .build();
+ }
+
+ private static VerifierCall equivalent(String exprA, String exprB) {
+ return v ->
+ v.verifyEquivalence(ZERO_CEL.compile(exprA).getAst(), ZERO_CEL.compile(exprB).getAst());
+ }
+
+ private enum CegarTestCase {
+ COUNTEREXAMPLE_CONFIRMED(
+ alwaysTrue("zero(x) == 1"),
+ VerificationStatus.VIOLATED,
+ "Condition is not always true. The CEL runtime confirmed a counterexample the verifier"
+ + " approximated. Counterexample input:"),
+ ERROR_COUNTEREXAMPLE_CONFIRMED(
+ alwaysTrue("zero(x) / zero(x) == 1"),
+ VerificationStatus.VIOLATED,
+ "The CEL runtime confirmed a counterexample the verifier approximated."),
+ // `0 + 'a'` has no overload at runtime.
+ DISPATCH_ERROR_COUNTEREXAMPLE_CONFIRMED(
+ alwaysTrue("dyn(zero(x)) + 'a' == 'a'"),
+ VerificationStatus.VIOLATED,
+ "The CEL runtime confirmed a counterexample the verifier approximated."),
+ BAD_FORMAT_COUNTEREXAMPLE_CONFIRMED(
+ alwaysTrue("int('abc') == zero(x)"),
+ VerificationStatus.VIOLATED,
+ "The CEL runtime confirmed a counterexample the verifier approximated."),
+ EXACT_COUNTEREXAMPLE(
+ alwaysTrue("x != 1"),
+ VerificationStatus.VIOLATED,
+ "Condition is not always true. Counterexample input:"),
+ SATISFYING_INPUT_CONFIRMED(
+ satisfiable("zero(x) == 0"),
+ VerificationStatus.VERIFIED,
+ "Condition is satisfiable. The CEL runtime confirmed a satisfying input the verifier"
+ + " approximated. Satisfying input:"),
+ DIVERGENCE_CONFIRMED(
+ equivalent("zero(x)", "1"),
+ VerificationStatus.VIOLATED,
+ "Equivalence violation detected. The CEL runtime confirmed a divergence the verifier"
+ + " approximated. Counterexample input:"),
+ // Maps can't have numerically equal keys, or bytes keys.
+ NUMERICALLY_EQUAL_KEYS(
+ satisfiable(
+ "zero(x) == 0 && 0 in dyn_int_map && 0u in dyn_int_map"
+ + " && dyn_int_map[0] != dyn_int_map[0u]"),
+ VerificationStatus.INCONCLUSIVE,
+ "Potential satisfying input:"),
+ BYTES_KEY(
+ satisfiable("zero(x) == 0 && b'a' in dyn_int_map"),
+ VerificationStatus.INCONCLUSIVE,
+ "Potential satisfying input:"),
+ NEGATIVE_KEY(
+ satisfiable("zero(x) == 0 && -1 in dyn_int_map"),
+ VerificationStatus.VERIFIED,
+ "The CEL runtime confirmed a satisfying input the verifier approximated."),
+ // Proto message inputs aren't exact witness values yet.
+ INEXACT_WITNESS(
+ alwaysTrue("zero(test_all_types.single_int64) == 1"),
+ VerificationStatus.INCONCLUSIVE,
+ "Potential counterexample input:");
+
+ private final VerifierCall call;
+ private final VerificationStatus status;
+ private final String message;
+
+ CegarTestCase(VerifierCall call, VerificationStatus status, String message) {
+ this.call = call;
+ this.status = status;
+ this.message = message;
+ }
+ }
+
+ @Test
+ public void cegar_checksWitnessWithRuntime(@TestParameter CegarTestCase testCase)
+ throws Exception {
+ CelVerifier verifier = checkedVerifier(ZERO_CEL).build();
+
+ CelVerificationResult result = testCase.call.call(verifier);
+
+ assertThat(result.status()).isEqualTo(testCase.status);
+ assertThat(result.message()).contains(testCase.message);
+ }
+
+ private enum RefutedCegarTestCase {
+ COUNTEREXAMPLE(alwaysTrue("zero(x) == 0")),
+ SATISFYING_INPUT(satisfiable("zero(x) == 1")),
+ DIVERGENCE(equivalent("zero(x)", "0")),
+ // Both sides divide by zero at runtime, and all errors are one value.
+ ERROR_DIVERGENCE(equivalent("zero(x) / zero(x)", "1 / zero(x)"));
+
+ private final VerifierCall call;
+
+ RefutedCegarTestCase(VerifierCall call) {
+ this.call = call;
+ }
+ }
+
+ @Test
+ public void cegar_runtimeRefutesWitness_omitsIt(@TestParameter RefutedCegarTestCase testCase)
+ throws Exception {
+ CelVerifier verifier = checkedVerifier(ZERO_CEL).build();
+
+ CelVerificationResult result = testCase.call.call(verifier);
+
+ assertThat(result.status()).isEqualTo(VerificationStatus.INCONCLUSIVE);
+ assertThat(result.message()).endsWith("doesn't model exactly: calls to `zero`.");
+ assertThat(result.witness()).isEmpty();
+ }
+
+ private static final CelFunctionDecl MAYBE_DECL =
+ CelFunctionDecl.newFunctionDeclaration(
+ "maybe", CelOverloadDecl.newGlobalOverload("maybe_int", SimpleType.BOOL, SimpleType.INT));
+
+ private enum NotAttemptedCegarTestCase {
+ OFF(CelVerifierFactory.newVerifier(ZERO_CEL).build()),
+ UNKNOWN_IDENTIFIERS(checkedVerifier(ZERO_CEL).addUnknownIdentifier("unknown_var").build());
+
+ private final CelVerifier verifier;
+
+ NotAttemptedCegarTestCase(CelVerifier verifier) {
+ this.verifier = verifier;
+ }
+ }
+
+ @Test
+ public void cegar_notAttempted_staysInconclusive(
+ @TestParameter NotAttemptedCegarTestCase testCase) throws Exception {
+ CelVerificationResult result =
+ testCase.verifier.isAlwaysTrue(ZERO_CEL.compile("zero(x) == 1").getAst());
+
+ assertThat(result.status()).isEqualTo(VerificationStatus.INCONCLUSIVE);
+ assertThat(result.message()).doesNotContain("CEL runtime");
+ }
+
+ private enum CantEvaluateCegarTestCase {
+ UNBOUND_FUNCTION(UNBOUND_ZERO_CEL, "zero(x) == 1", "No matching overload for function 'zero'"),
+ LATE_BOUND_FUNCTION(
+ UNBOUND_ZERO_CEL.toCelBuilder().addLateBoundFunctions("zero").build(),
+ "zero(x) == 1",
+ "No matching overload for function 'zero'"),
+ // The runtime's iteration limit isn't a CEL error.
+ ITERATION_LIMIT(
+ ZERO_CEL
+ .toCelBuilder()
+ .setOptions(CelOptions.current().comprehensionMaxIterations(0).build())
+ .build(),
+ "[1].all(i, zero(i) == 0)",
+ "Iteration budget exceeded"),
+ // Async bindings fail with an internal error when evaluated synchronously.
+ ASYNC_FUNCTION(
+ UNBOUND_ZERO_CEL
+ .toCelBuilder()
+ .addFunctionBindings(CelFunctionBinding.fromAsync("zero_int", Long.class, x -> null))
+ .build(),
+ "zero(x) == 1",
+ "evaluated in synchronous mode"),
+ NULL_RESULT(
+ CEL.toCelBuilder()
+ .addFunctionDeclarations(MAYBE_DECL)
+ .addFunctionBindings(CelFunctionBinding.from("maybe_int", Long.class, x -> null))
+ .build(),
+ "maybe(x)",
+ "a function returned null"),
+ UNKNOWN_RESULT(
+ CEL.toCelBuilder()
+ .addFunctionDeclarations(MAYBE_DECL)
+ .addFunctionBindings(
+ CelFunctionBinding.from("maybe_int", Long.class, x -> CelUnknownSet.create(1L)))
+ .build(),
+ "maybe(x)",
+ "it evaluated to unknowns");
+
+ private final Cel cel;
+ private final String expr;
+ private final String reason;
+
+ CantEvaluateCegarTestCase(Cel cel, String expr, String reason) {
+ this.cel = cel;
+ this.expr = expr;
+ this.reason = reason;
+ }
+ }
+
+ @Test
+ public void cegar_cantEvaluate_saysWhy(@TestParameter CantEvaluateCegarTestCase testCase)
+ throws Exception {
+ CelVerifier verifier = checkedVerifier(testCase.cel).build();
+
+ CelVerificationResult result =
+ verifier.isAlwaysTrue(testCase.cel.compile(testCase.expr).getAst());
+
+ assertThat(result.status()).isEqualTo(VerificationStatus.INCONCLUSIVE);
+ assertThat(result.message())
+ .containsMatch(
+ "The CEL runtime couldn't check it: .*\\. (Potential counterexample input:|\\(The)");
+ assertThat(result.message()).contains(testCase.reason);
+ }
+
+ @Test
+ public void cegar_exactMatchCantEvaluate_saysWhy() throws Exception {
+ // Models `zero(x)` as 0, but the runtime has no binding for it.
+ CelVerifier verifier =
+ CelVerifierZ3Impl.newBuilder(UNBOUND_ZERO_CEL)
+ .addFunctionAxioms(zeroAxiom(0))
+ .enableCegar(true)
+ .build();
+
+ CelVerificationResult result =
+ verifier.isAlwaysTrue(UNBOUND_ZERO_CEL.compile("zero(x) == 1").getAst());
+
+ assertThat(result.status()).isEqualTo(VerificationStatus.VIOLATED);
+ assertThat(result.message())
+ .containsMatch(
+ "Condition is not always true\\. The CEL runtime couldn't check it: .*No matching"
+ + " overload for function 'zero'.*\\. Counterexample input:");
+ }
+
+ private enum RefutedExactMatchTestCase {
+ COUNTEREXAMPLE(alwaysTrue("zero(x) == 0"), "a counterexample the verifier found."),
+ SATISFYING_INPUT(satisfiable("zero(x) == 1"), "a satisfying input the verifier found."),
+ DIVERGENCE(equivalent("zero(x)", "0"), "a divergence the verifier found.");
+
+ private final VerifierCall call;
+ private final String message;
+
+ RefutedExactMatchTestCase(VerifierCall call, String message) {
+ this.call = call;
+ this.message = message;
+ }
+ }
+
+ @Test
+ public void cegar_runtimeDisagreesWithExactMatch_inconclusive(
+ @TestParameter RefutedExactMatchTestCase testCase) throws Exception {
+ // Models `zero(x)` as 1, which the runtime disagrees with.
+ CelVerifier verifier =
+ CelVerifierZ3Impl.newBuilder(ZERO_CEL)
+ .addFunctionAxioms(zeroAxiom(1))
+ .enableCegar(true)
+ .build();
+
+ CelVerificationResult result = testCase.call.call(verifier);
+
+ assertThat(result.status()).isEqualTo(VerificationStatus.INCONCLUSIVE);
+ assertThat(result.message())
+ .isEqualTo("Inconclusive: the CEL runtime disagrees with " + testCase.message);
+ assertThat(result.witness()).isEmpty();
+ }
+
@Test
public void translateFunctionCall_staticallyResolved_skipsDeadOverloads() throws Exception {
CelFunctionDecl spyFuncDecl =
@@ -4201,11 +4505,11 @@ public void isAlwaysTrue_largeListCounterexample_truncatesOutput() throws Except
listLiteral.append("]");
CelAbstractSyntaxTree ast = cel.compile("!(large_list == " + listLiteral + ")").getAst();
- CelVerifier verifier = withRuntimeOracle(cel, b -> b.setTimeout(Duration.ofSeconds(10)));
+ CelVerifier verifier = checkedVerifier(cel).setTimeout(Duration.ofSeconds(10)).build();
CelVerificationResult result = verifier.isAlwaysTrue(ast);
- assertThat(result.status()).isEqualTo(VerificationStatus.VIOLATED);
+ assertExact(result, VerificationStatus.VIOLATED);
assertThat(result.message()).contains("... (5 more elements)");
}
@@ -4225,11 +4529,11 @@ public void isAlwaysTrue_largeMapCounterexample_truncatesOutput() throws Excepti
mapLiteral.append("}");
CelAbstractSyntaxTree ast = cel.compile("!(large_map == " + mapLiteral + ")").getAst();
- CelVerifier verifier = withRuntimeOracle(cel, b -> b.setTimeout(Duration.ofSeconds(10)));
+ CelVerifier verifier = checkedVerifier(cel).setTimeout(Duration.ofSeconds(10)).build();
CelVerificationResult result = verifier.isAlwaysTrue(ast);
- assertThat(result.status()).isEqualTo(VerificationStatus.VIOLATED);
+ assertExact(result, VerificationStatus.VIOLATED);
assertThat(result.message()).contains("... (5 more entries)");
}
@@ -4245,9 +4549,9 @@ public void counterexample_messageTwoFieldsFormatted() throws Exception {
CelAbstractSyntaxTree ast =
cel.compile("!(msg == TestAllTypes{single_int32: 1, single_int64: 2})").getAst();
- CelVerificationResult result = withRuntimeOracle(cel, b -> b).isAlwaysTrue(ast);
+ CelVerificationResult result = checkedVerifier(cel).build().isAlwaysTrue(ast);
- assertThat(result.status()).isEqualTo(VerificationStatus.VIOLATED);
+ assertExact(result, VerificationStatus.VIOLATED);
assertThat(result.message()).contains("single_int32: 1");
assertThat(result.message()).contains("single_int64: 2");
}
@@ -4276,11 +4580,11 @@ public void isAlwaysTrue_customComprehensionWithTrueAccuInit() throws Exception
.build();
CelAbstractSyntaxTree ast =
cel.compile("dyn_list == [1, 2] ? dyn_list.custom_fold(x) == true : true").getAst();
- CelVerifier verifier = withRuntimeOracle(cel, b -> b);
+ CelVerifier verifier = checkedVerifier(cel).build();
CelVerificationResult result = verifier.isAlwaysTrue(ast);
- assertThat(result.status()).isEqualTo(VerificationStatus.VERIFIED);
+ assertExact(result, VerificationStatus.VERIFIED);
}
@Test
@@ -4291,7 +4595,7 @@ public void isAlwaysTrue_customComprehensionWithLoopCondition_inconclusive() thr
CelAbstractSyntaxTree ast =
CEL.compile("int_list == [1, 2] ? int_list.first_elem() == 2 : true").getAst();
- CelVerificationResult result = VERIFIER.isAlwaysTrue(ast);
+ CelVerificationResult result = UNCHECKED_VERIFIER.isAlwaysTrue(ast);
assertThat(result.reason())
.isEqualTo(
@@ -4373,7 +4677,7 @@ public void verifyImplication_exactUnknownAssumption_verified() throws Exception
public void isSatisfiable_exactUnknownBesideUnmodeledComprehension_violated() throws Exception {
CelAbstractSyntaxTree ast =
CEL.compile("(false && int_list.first_elem() == 1) || (b && !b)").getAst();
- CelVerifier verifier = withRuntimeOracle(CEL, b -> b.addUnknownIdentifier("b"));
+ CelVerifier verifier = CelVerifierFactory.newVerifier(CEL).addUnknownIdentifier("b").build();
CelVerificationResult result = verifier.isSatisfiable(ast);
@@ -4416,10 +4720,10 @@ public void isSatisfiable_maskedByBmcButAlwaysFalse_returnsFailed() throws Excep
String expr = "int_list == [1, 2, 3, 4] ? int_list.exists(x, x == 42) && false : false";
CelAbstractSyntaxTree ast = CEL.compile(expr).getAst();
- CelVerifier verifier = withRuntimeOracle(CEL, b -> b.setComprehensionUnrollLimit(3));
+ CelVerifier verifier = checkedVerifier(CEL).setComprehensionUnrollLimit(3).build();
CelVerificationResult result = verifier.isSatisfiable(ast);
- assertThat(result.status()).isEqualTo(VerificationStatus.VIOLATED);
+ assertExact(result, VerificationStatus.VIOLATED);
}
@Test
@@ -4431,10 +4735,10 @@ public void verifyEquivalence_maskedByBmcButAlwaysEqual_returnsVerified() throws
CelAbstractSyntaxTree astA = CEL.compile(exprA).getAst();
CelAbstractSyntaxTree astB = CEL.compile(exprB).getAst();
- CelVerifier verifier = withRuntimeOracle(CEL, b -> b.setComprehensionUnrollLimit(3));
+ CelVerifier verifier = checkedVerifier(CEL).setComprehensionUnrollLimit(3).build();
CelVerificationResult result = verifier.verifyEquivalence(astA, astB);
- assertThat(result.status()).isEqualTo(VerificationStatus.VERIFIED);
+ assertExact(result, VerificationStatus.VERIFIED);
}
private enum EquivalenceZeroUnrollLimitTestCase {
@@ -4457,7 +4761,8 @@ public void verifyEquivalence_zeroUnrollLimit_returnsInconclusive(
@TestParameter EquivalenceZeroUnrollLimitTestCase testCase) throws Exception {
CelAbstractSyntaxTree astA = CEL.compile(testCase.exprA).getAst();
CelAbstractSyntaxTree astB = CEL.compile(testCase.exprB).getAst();
- CelVerifier verifier = withRuntimeOracle(CEL, b -> b.setComprehensionUnrollLimit(0));
+ CelVerifier verifier =
+ CelVerifierFactory.newVerifier(CEL).setComprehensionUnrollLimit(0).build();
CelVerificationResult result = verifier.verifyEquivalence(astA, astB);
@@ -4495,7 +4800,7 @@ public void verifyEquivalence_zeroUnrollLimit_twoVarComprehensions_returnsVerifi
@TestParameter EquivalenceZeroUnrollLimitVerifiedTestCase testCase) throws Exception {
CelAbstractSyntaxTree astA = CEL.compile(testCase.exprA).getAst();
CelAbstractSyntaxTree astB = CEL.compile(testCase.exprB).getAst();
- CelVerifier verifier = withRuntimeOracle(CEL, b -> b.setComprehensionUnrollLimit(0));
+ CelVerifier verifier = checkedVerifier(CEL).setComprehensionUnrollLimit(0).build();
CelVerificationResult result = verifier.verifyEquivalence(astA, astB);
@@ -4543,7 +4848,8 @@ public void verifyEquivalence_comprehensionScopeShadowing_returnsInconclusive()
.build();
CelAbstractSyntaxTree astA = customCel.compile("dyn_list.my_macro_1(true)").getAst();
CelAbstractSyntaxTree astB = customCel.compile("dyn_list.my_macro_2(true)").getAst();
- CelVerifier verifier = withRuntimeOracle(customCel, b -> b.setComprehensionUnrollLimit(0));
+ CelVerifier verifier =
+ CelVerifierFactory.newVerifier(customCel).setComprehensionUnrollLimit(0).build();
CelVerificationResult result = verifier.verifyEquivalence(astA, astB);
@@ -4585,7 +4891,8 @@ public void verifyEquivalence_comprehensionResultScopeIsolation_returnsInconclus
customCel.compile("cel.bind(x, 10, dyn_list.my_macro(1))").getAst();
CelAbstractSyntaxTree astB =
customCel.compile("cel.bind(x, 20, dyn_list.my_macro(1))").getAst();
- CelVerifier verifier = withRuntimeOracle(customCel, b -> b.setComprehensionUnrollLimit(0));
+ CelVerifier verifier =
+ CelVerifierFactory.newVerifier(customCel).setComprehensionUnrollLimit(0).build();
CelVerificationResult result = verifier.verifyEquivalence(astA, astB);
@@ -4602,7 +4909,7 @@ public void verifyEquivalence_timeoutReached_throwsCelVerificationException() th
.addVar("d4", SimpleType.DOUBLE)
.build();
CelVerifier timeoutVerifier =
- withRuntimeOracle(customCel, b -> b.setTimeout(Duration.ofMillis(1)));
+ checkedVerifier(customCel).setTimeout(Duration.ofMillis(1)).build();
CelAbstractSyntaxTree astA =
customCel
.compile(
@@ -4630,7 +4937,7 @@ public void isAlwaysTrue_constantVarDecl_verified() throws Exception {
.setConstant(CelConstant.ofValue(42L))
.build())
.build();
- CelVerifier verifier = withRuntimeOracle(celWithConstVar, b -> b);
+ CelVerifier verifier = checkedVerifier(celWithConstVar).build();
CelAbstractSyntaxTree ast =
celWithConstVar
.compile("CONST_INT == 42 && [1, 2].all(x, .CONST_INT == 42 && x > 0)")
@@ -4663,10 +4970,10 @@ private static CelMacro firstElemMacro() {
exprFactory.newIdentifier("accu"))));
}
- // verifyImplication isn't part of CelVerifier, so it can't go through the runtime oracle.
+ // verifyImplication isn't part of CelVerifier.
private static CelVerificationResult verifyImplication(
CelCompiler compiler, String assume, String assertion) throws Exception {
- return ((CelVerifierZ3Impl) VERIFIER_WITHOUT_ORACLE)
+ return ((CelVerifierZ3Impl) UNCHECKED_VERIFIER)
.verifyImplication(
compiler.compile(assume).getAst(),
compiler.compile(assertion).getAst(),
diff --git a/verifier/src/test/java/dev/cel/verifier/RuntimeOracle.java b/verifier/src/test/java/dev/cel/verifier/RuntimeOracle.java
deleted file mode 100644
index 67d746a6f..000000000
--- a/verifier/src/test/java/dev/cel/verifier/RuntimeOracle.java
+++ /dev/null
@@ -1,145 +0,0 @@
-// Copyright 2026 Google LLC
-//
-// 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
-//
-// https://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 dev.cel.verifier;
-
-import static com.google.common.collect.ImmutableList.toImmutableList;
-import static java.util.Arrays.stream;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-import com.google.errorprone.annotations.CanIgnoreReturnValue;
-import dev.cel.common.CelAbstractSyntaxTree;
-import dev.cel.runtime.CelEvaluationException;
-import dev.cel.runtime.CelRuntime;
-import dev.cel.runtime.CelRuntime.Program;
-import dev.cel.verifier.CelVerificationResult.VerificationStatus;
-import java.util.List;
-import java.util.Optional;
-import java.util.function.Predicate;
-
-/**
- * Evaluates every exact witness a verifier returns with the CEL runtime, and fails if the runtime
- * disagrees with the verdict.
- */
-final class RuntimeOracle implements CelVerifier {
-
- // All errors compare equal, matching the verifier's single error value.
- private enum EvaluationError {
- ERROR
- }
-
- @SuppressWarnings("Immutable") // CelRuntime is immutable, just not marked as such
- private final CelRuntime runtime;
-
- private final CelVerifier delegate;
-
- static CelVerifier wrap(CelRuntime runtime, CelVerifier delegate) {
- return new RuntimeOracle(runtime, delegate);
- }
-
- @Override
- public CelVerificationResult isSatisfiable(CelAbstractSyntaxTree ast)
- throws CelVerificationException {
- return check(
- delegate.isSatisfiable(ast), VerificationStatus.VERIFIED, r -> r.get(0).equals(true), ast);
- }
-
- @Override
- public CelVerificationResult isAlwaysTrue(CelAbstractSyntaxTree ast)
- throws CelVerificationException {
- return check(
- delegate.isAlwaysTrue(ast), VerificationStatus.VIOLATED, r -> !r.get(0).equals(true), ast);
- }
-
- @Override
- public CelVerificationResult verifyEquivalence(
- CelAbstractSyntaxTree astA, CelAbstractSyntaxTree astB) throws CelVerificationException {
- return check(
- delegate.verifyEquivalence(astA, astB),
- VerificationStatus.VIOLATED,
- r -> !r.get(0).equals(r.get(1)),
- astA,
- astB);
- }
-
- @CanIgnoreReturnValue
- private CelVerificationResult check(
- CelVerificationResult result,
- VerificationStatus checkedStatus,
- Predicate> agrees,
- CelAbstractSyntaxTree... asts) {
- Optional> inputs = exactInputs(result);
- if (result.status() != checkedStatus || !inputs.isPresent()) {
- return result;
- }
- ImmutableList results =
- stream(asts).map(ast -> evaluate(ast, inputs.get())).collect(toImmutableList());
- if (agrees.test(results)) {
- return result;
- }
- StringBuilder message =
- new StringBuilder("The CEL runtime disagrees with ")
- .append(result.status())
- .append(" for inputs ")
- .append(inputs.get())
- .append(':');
- for (int i = 0; i < asts.length; i++) {
- message
- .append("\n ")
- .append(asts[i].getSource().getContent())
- .append(" evaluates to ")
- .append(results.get(i));
- }
- throw new AssertionError(message.append('\n').append(result.message()).toString());
- }
-
- // The witness's inputs, if every value is exact.
- private static Optional> exactInputs(CelVerificationResult result) {
- return result
- .witness()
- .map(CelWitness::variables)
- .filter(vars -> vars.values().stream().allMatch(v -> v.value().isPresent()))
- .map(vars -> ImmutableMap.copyOf(Maps.transformValues(vars, v -> v.value().get())));
- }
-
- private Object evaluate(CelAbstractSyntaxTree ast, ImmutableMap inputs) {
- Program program;
- try {
- program = runtime.createProgram(ast);
- } catch (CelEvaluationException e) {
- throw new AssertionError(
- "Can't plan "
- + ast.getSource().getContent()
- + "; verify it with a verifier for its own environment",
- e);
- }
- try {
- return program.eval(inputs);
- } catch (CelEvaluationException e) {
- // A witness missing a variable would otherwise pass as an error result.
- if (e.getMessage().contains("No such attribute(s): ")) {
- throw new AssertionError(
- "Incomplete witness " + inputs + " for " + ast.getSource().getContent(), e);
- }
- return EvaluationError.ERROR;
- }
- }
-
- private RuntimeOracle(CelRuntime runtime, CelVerifier delegate) {
- this.runtime = runtime;
- this.delegate = delegate;
- }
-}
diff --git a/verifier/src/test/java/dev/cel/verifier/RuntimeOracleTest.java b/verifier/src/test/java/dev/cel/verifier/RuntimeOracleTest.java
deleted file mode 100644
index 0bc3a36b9..000000000
--- a/verifier/src/test/java/dev/cel/verifier/RuntimeOracleTest.java
+++ /dev/null
@@ -1,165 +0,0 @@
-// Copyright 2026 Google LLC
-//
-// 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
-//
-// https://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 dev.cel.verifier;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertThrows;
-
-import com.google.common.collect.ImmutableMap;
-import dev.cel.bundle.Cel;
-import dev.cel.bundle.CelFactory;
-import dev.cel.common.CelAbstractSyntaxTree;
-import dev.cel.common.CelFunctionDecl;
-import dev.cel.common.CelOverloadDecl;
-import dev.cel.common.types.SimpleType;
-import dev.cel.runtime.CelEvaluationException;
-import java.util.Optional;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-@RunWith(JUnit4.class)
-public final class RuntimeOracleTest {
-
- private static final Cel CEL = CelFactory.plannerCelBuilder().addVar("x", SimpleType.INT).build();
-
- @Test
- public void isSatisfiable_runtimeRefutesSatisfyingInput_throws() throws Exception {
- CelAbstractSyntaxTree ast = CEL.compile("x == 1").getAst();
- CelVerifier verifier =
- checking(CelVerificationResult.verified("Condition is satisfiable.", witness(2L)));
-
- AssertionError e = assertThrows(AssertionError.class, () -> verifier.isSatisfiable(ast));
-
- assertThat(e).hasMessageThat().contains("x == 1 evaluates to false");
- }
-
- @Test
- public void isAlwaysTrue_runtimeRefutesCounterexample_throws() throws Exception {
- CelAbstractSyntaxTree ast = CEL.compile("x == 1").getAst();
- CelVerifier verifier = checking(CelVerificationResult.failed("Violated.", witness(1L)));
-
- AssertionError e = assertThrows(AssertionError.class, () -> verifier.isAlwaysTrue(ast));
-
- assertThat(e).hasMessageThat().contains("x == 1 evaluates to true");
- }
-
- @Test
- public void verifyEquivalence_runtimeRefutesDivergence_throws() throws Exception {
- CelAbstractSyntaxTree astA = CEL.compile("x + 0").getAst();
- CelAbstractSyntaxTree astB = CEL.compile("x").getAst();
- CelVerifier verifier = checking(CelVerificationResult.failed("Violated.", witness(1L)));
-
- AssertionError e =
- assertThrows(AssertionError.class, () -> verifier.verifyEquivalence(astA, astB));
-
- assertThat(e).hasMessageThat().contains("x + 0 evaluates to 1");
- assertThat(e).hasMessageThat().contains("\n x evaluates to 1");
- }
-
- @Test
- public void isSatisfiable_inexactSatisfyingInput_notChecked() throws Exception {
- CelAbstractSyntaxTree ast = CEL.compile("x == 1").getAst();
- CelVerificationResult result =
- CelVerificationResult.verified(
- "Condition is satisfiable.",
- CelWitness.create(
- ImmutableMap.of("x", CelWitness.Variable.create(Optional.empty(), "Unknown"))));
-
- assertThat(checking(result).isSatisfiable(ast)).isSameInstanceAs(result);
- }
-
- @Test
- public void verifyEquivalence_bothExpressionsError_throws() throws Exception {
- CelAbstractSyntaxTree astA = CEL.compile("1 / x").getAst();
- CelAbstractSyntaxTree astB = CEL.compile("2 / x").getAst();
- CelVerifier verifier = checking(CelVerificationResult.failed("Violated.", witness(0L)));
-
- AssertionError e =
- assertThrows(AssertionError.class, () -> verifier.verifyEquivalence(astA, astB));
-
- assertThat(e).hasMessageThat().contains("1 / x evaluates to ERROR");
- assertThat(e).hasMessageThat().contains("2 / x evaluates to ERROR");
- }
-
- @Test
- public void isSatisfiable_inconclusiveResult_notChecked() throws Exception {
- CelAbstractSyntaxTree ast = CEL.compile("x == 1").getAst();
- CelVerificationResult result =
- CelVerificationResult.inconclusive(
- "Inconclusive.", witness(2L), /* isCounterexample= */ false);
-
- assertThat(checking(result).isSatisfiable(ast)).isSameInstanceAs(result);
- }
-
- @Test
- public void isSatisfiable_unplannableExpression_throws() throws Exception {
- Cel celWithFunction =
- CEL.toCelBuilder()
- .addFunctionDeclarations(
- CelFunctionDecl.newFunctionDeclaration(
- "f",
- CelOverloadDecl.newGlobalOverload("f_int", SimpleType.BOOL, SimpleType.INT)))
- .build();
- CelAbstractSyntaxTree ast = celWithFunction.compile("f(x)").getAst();
- CelVerifier verifier =
- checking(CelVerificationResult.verified("Condition is satisfiable.", witness(1L)));
-
- AssertionError e = assertThrows(AssertionError.class, () -> verifier.isSatisfiable(ast));
-
- assertThat(e).hasMessageThat().contains("Can't plan f(x)");
- assertThat(e).hasCauseThat().isInstanceOf(CelEvaluationException.class);
- }
-
- @Test
- public void isAlwaysTrue_missingVariableInWitness_throws() throws Exception {
- CelAbstractSyntaxTree ast = CEL.compile("x == 1").getAst();
- CelVerifier verifier =
- checking(CelVerificationResult.failed("Violated.", CelWitness.create(ImmutableMap.of())));
-
- AssertionError e = assertThrows(AssertionError.class, () -> verifier.isAlwaysTrue(ast));
-
- assertThat(e).hasMessageThat().contains("Incomplete witness {} for x == 1");
- assertThat(e).hasCauseThat().isInstanceOf(CelEvaluationException.class);
- }
-
- private static CelWitness witness(long x) {
- return CelWitness.create(
- ImmutableMap.of("x", CelWitness.Variable.create(Optional.of(x), Long.toString(x))));
- }
-
- @SuppressWarnings("Immutable") // Test fake; the result is never mutated.
- private static CelVerifier checking(CelVerificationResult result) {
- return RuntimeOracle.wrap(
- CEL,
- new CelVerifier() {
- @Override
- public CelVerificationResult isSatisfiable(CelAbstractSyntaxTree ast) {
- return result;
- }
-
- @Override
- public CelVerificationResult isAlwaysTrue(CelAbstractSyntaxTree ast) {
- return result;
- }
-
- @Override
- public CelVerificationResult verifyEquivalence(
- CelAbstractSyntaxTree astA, CelAbstractSyntaxTree astB) {
- return result;
- }
- });
- }
-}