Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions verifier/src/main/java/dev/cel/verifier/CelAstAlphaHasher.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.jspecify.annotations.Nullable;

/**
Expand Down Expand Up @@ -75,20 +76,25 @@ static AlphaSignature computeSignature(CelExpr expr, CelAbstractSyntaxTree ast)
}

private static void hashAst(CelExpr expr, @Nullable Scope scope, HasherContext context) {
CelConstant refValue =
context.ast.getReference(expr.id()).flatMap(CelReference::value).orElse(null);
Optional<CelReference> reference = context.ast.getReference(expr.id());
CelConstant refValue = reference.flatMap(CelReference::value).orElse(null);
if (refValue != null) {
context.hasher.putString(CelExpr.ExprKind.Kind.CONSTANT.name(), UTF_8);
hashConstant(refValue, context);
return;
}
context.hasher.putString(expr.exprKind().getKind().name(), UTF_8);
switch (expr.exprKind().getKind()) {
CelExpr.ExprKind.Kind kind = expr.exprKind().getKind();
// Without namespaced declarations, a qualified variable stays a select with a reference.
if (kind == CelExpr.ExprKind.Kind.SELECT && reference.isPresent()) {
kind = CelExpr.ExprKind.Kind.IDENT;
}
context.hasher.putString(kind.name(), UTF_8);
switch (kind) {
case CONSTANT:
hashConstant(expr.constant(), context);
break;
case IDENT:
String name = expr.ident().name();
String name = context.ast.getReferenceOrThrow(expr.id()).name();
int bIdx = scope == null ? -1 : scope.indexOf(name);
if (bIdx >= 0) {
context.hasher.putByte((byte) 0); // 0 = bound
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ Set<BoolExpr> getTypeConstraints() {
return context.constraints();
}

BoolExpr hasTruncation() {
return context.hasTruncation();
BoolExpr hasUnmodeledResult() {
return context.hasUnmodeledResult();
}

ImmutableList<String> approximationSources(Model model, BoolExpr taint) {
Expand Down Expand Up @@ -183,6 +183,10 @@ private TranslatedValue translateExpr(CelExpr celExpr, CelAbstractSyntaxTree ast
case IDENT:
return translateIdent(celExpr, ast);
case SELECT:
// Without namespaced declarations, a qualified variable stays a select with a reference.
if (ast.getReference(celExpr.id()).isPresent()) {
return translateIdent(celExpr, ast);
}
return structTranslator.translateSelect(celExpr, ast);
case CALL:
return translateCall(celExpr, ast);
Expand Down Expand Up @@ -231,13 +235,12 @@ private TranslatedValue translateConstant(CelExpr celExpr) {
}

private TranslatedValue translateIdent(CelExpr celExpr, CelAbstractSyntaxTree ast) {
CelExpr.CelIdent ident = celExpr.ident();
long exprId = celExpr.id();
CelConstant refValue = ast.getReference(exprId).flatMap(CelReference::value).orElse(null);
if (refValue != null) {
return translateConstant(CelExpr.ofConstant(exprId, refValue));
}
String name = ident.name();
String name = ast.getReferenceOrThrow(exprId).name();
CelType type = ast.getTypeOrThrow(exprId);
if (type instanceof TypeType) {
TypeType typeType = (TypeType) type;
Expand Down Expand Up @@ -266,10 +269,7 @@ private TranslatedValue translateIdent(CelExpr celExpr, CelAbstractSyntaxTree as
}

return TranslatedValue.create(
v,
CelExpr.newBuilder().setIdent(ident).setId(exprId).build(),
typeSystem,
/* isApproximate= */ ctx.mkFalse());
v, celExpr, typeSystem, /* isApproximate= */ ctx.mkFalse());
});

return TranslatedValue.create(tv.z3Expr(), celExpr, typeSystem, tv.isApproximate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public enum VerificationStatus {
VERIFIED,
/** The property was disproven. A concrete counterexample was found. */
VIOLATED,
/** The property could not be verified due to loop truncation or timeout. */
/** The property could not be verified because it depends on what the verifier doesn't model. */
INCONCLUSIVE
}

Expand Down
Loading
Loading