Skip to content

[QF_UF] Stack overflow / SIGABRT (exit 134) on a satisfiable EUF formula #18

Closed

Description

@0kenx

Summary

oxiz aborts with a stack overflow (SIGABRT, exit code 134) on a satisfiable QF_UF formula that z3 solves instantly. This is a robustness/crash bug in the EUF handling, surfaced by grammar-driven differential fuzzing against z3.

Reproducer

(set-logic QF_UF)
(declare-sort U 0)
(declare-const c0 U)
(declare-const c1 U)
(declare-const c2 U)
(declare-const c3 U)
(declare-fun f (U) U)
(declare-fun g (U U) U)
(assert (and (and (not (distinct (f (g c0 c3)) (g (f c3) (f c3)))) (distinct (g c3 (f c2)) (g c3 (f c3))) (=> (distinct (g c3 (g c0 c2)) (f c1)) (= c0 (g (f c2) c3)))) (xor (and (distinct (f (f c3)) (f (f c3))) (distinct (g (f c0) (f c2)) (f c0)) (distinct c3 (g c2 (g c3 c1)))) (xor (distinct (g (f c2) (g c3 c2)) (g (f c2) c0)) (distinct (f c0) c2))) (distinct (g (f c1) (f c3)) c2)))
(assert (distinct (g (g c0 c1) (f c2)) (g (g c1 c0) (g c2 c0))))
(assert (= c1 (g (f c0) c2)))
(assert (xor (and (ite (distinct c1 c0) (distinct (f (f c2)) (f (g c3 c2))) (distinct (g (f c2) (f c3)) (f (g c3 c3)))) (not (= (f (f c0)) c3)) (= c1 c0)) (distinct c2 (f (g c0 c1)))))
(assert (not (=> (= c2 (f (f c0))) (=> (= (g (g c3 c2) (g c1 c3)) (f (g c3 c1))) (= c2 c3)))))
(assert (and (xor (or (= c2 (g (g c2 c0) c3)) (= (g (g c2 c1) (f c3)) c1) (distinct c2 (g (f c0) (f c2)))) (not (= (f (f c1)) c1))) (not (distinct (g c2 c0) (g (f c2) c1))) (or (not (distinct (f c2) (g c3 (f c1)))) (and (= (g c1 (f c3)) (g (g c1 c0) c1)) (distinct (g c0 (f c1)) (f (f c2)))) (=> (distinct (f c3) (f (f c2))) (= (f (f c1)) c1)))))
(check-sat)
(exit)

Expected

sat

(z3 -in returns sat immediately.)

Actual (oxiz 0.3.0)

The process aborts with a stack overflow:

thread 'main' has overflowed its stack
fatal runtime error: stack overflow, aborting
Aborted (core dumped)

Exit code 134 (SIGABRT). No (error …) is produced and no result is printed — the solver simply crashes.

How found

Grammar-driven differential testing against z3. Of 200 generated QF_UF cases this one caused oxiz to abort while z3 returned sat. The formula is moderately nested (uninterpreted f/g applied to other applications of f/g), which suggests unbounded recursion in term traversal / congruence closure rather than a genuine logic error.

Environment

  • oxiz: 0.3.0 (built at commit cc28ee2)
  • z3 (reference): 4.16.0
  • reproducer also attached as cases/uf01_stack_overflow.smt2 on branch feat/grammar-fuzzer

Activity

  1. 0kenx commented on Jul 26, 2026

    @0kenx
    Author

    Confirmed fixed. Re-ran the grammar fuzzer over 200 fresh QF_UF cases on the build at 8e930b3: all 200 now agree with z3 (no aborts, no soundness discrepancies). The original reproducer (cases/uf01_stack_overflow.smt2) returns sat as expected instead of aborting. Thanks!

  2. cool-japan commented on Jul 29, 2026

    @cool-japan
    Owner

    Thanks @0kenx — a real crash, and the case pinned it precisely. Reproduced on 0.3.1: exit 134, fatal runtime error: stack overflow. An lldb backtrace showed the stack filled with one frame, EufSolver::explain_equality, and instrumenting the node pairs it was asked to explain revealed a repeating cycle — (3,0) → (19,2) → (1,0) → (12,6) → (3,0) → …. So this was unbounded recursion, not merely deep recursion. Your read — "unbounded recursion in term traversal / congruence closure rather than a genuine logic error" — was correct on both counts.

    Root cause: two defects in oxiz-theories/src/euf/solver.rs that only bite in combination.

    1. propagate appended a congruence proof-forest edge at detection time, during the use-list scan, while the union itself was only queued on pending. If another propagation joined those two classes first, the queued merge was skipped by the root_a == root_b guard — but the edge stayed. The proof forest must be a spanning forest (one path between any two nodes); a leftover edge gives two, i.e. a cycle.
    2. explain_equality searched the proof forest for a path from a to b and, for every Congruence edge on that path, called itself to explain each argument pair, keeping no record of pairs already being explained. With a cycle present, the path chosen to justify an argument equality could run back through the very congruence edge under explanation, so the self-calls never bottomed out.

    Fix:

    • propagate: both assertion and congruence edges are now appended in the main loop after the root_a == root_b guard, immediately before the union. A merge that turns out to be already satisfied no longer leaves an edge behind, so the proof forest stays a true spanning forest.
    • explain_equality: converted from recursion to an explicit worklist. Congruence argument sub-goals are pushed onto explain_todo instead of being discharged by a self-call, and a companion explain_enqueued set expands each node pair at most once, which bounds the loop by the number of distinct pairs. This follows the shape of Z3's euf_egraph.cpp explain_todo loop.

    No recursion-depth limit was added: the formula is satisfiable and now answers as such.

    Related, found later in the same subsystem and also fixed, since it is the kind of thing your fuzzer would eventually have surfaced: intern_app implemented congruence by aliasing — on a signature-table hit it pointed the new term at an older node. That congruence depends on the argument classes holding at that instant, but the dependency was recorded nowhere retractable, and pop drops term_to_node entries by node index, so an alias to a still-live older node survived the pop that retracted the merge. The result was a term with no node, no use-list entry and no signature of its own, and a second-level congruence that could never be rediscovered — a false sat. Congruence is now recorded as a retractable merge, matching Z3's egraph::mk. Separately, congruence argument sub-goals were matched positionally while a commutative symbol's canonical signature is sorted, which produced an under-justified (and therefore unsound) conflict core; that is now multiset matching over equivalence classes.

    Verification: your reproducer now prints sat with exit code 0, matching z3. test_issue_18_qf_uf_deep_nesting_no_overflow in oxiz-cli/tests/cli_integration.rs runs the exact formula through the real oxiz binary as a subprocess — a genuine 8 MiB main-thread stack — and asserts both a clean exit (not 134) and sat. test_issue_18_deep_congruence_explanation_terminates explains a 3000-deep congruence cascade, a depth at which the old recursion overran the stack, and checks the explanation still cites the driving assertion.

    Will ship with the 0.3.1 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions