8000 GitHub - dxnn/fizzjolt: A fuzzer for jolt lang. Compares outcomes with JVM Clojure. · GitHub
[go: up one dir, main page]

Skip to content
dxnnPublic

About

A fuzzer for jolt lang. Compares outcomes with JVM Clojure.

Resources

Stars

5 stars

Watchers

0 watching

Forks

Latest commit

 

History

21 Commits

Folders and files

Repository files navigation

fizzjolt

Differential fuzzing of jolt against JVM Clojure. Forms are generated from a seed, evaluated on both runtimes, and every form whose results differ is recorded, classified, and shrunk to a small reproduction.

How it works

  1. Generate (src/fizzjolt/gen.clj). A form is built as data from a kind (:num, :str, :coll, :xform, …): a literal from the kind's pool, or a call from a catalog of about 400 signatures whose result has that kind, so most forms are well typed. The pools hold the awkward values: -0.0, NaN, the long and fixnum boundaries, BigDecimals at several scales, ratios, floats, quoted and Unicode strings, metadata, sorted collections, records. Templates cover what random composition rarely lands on: transducers that stop early, format and cl-format directives, regexes, printing under the print vars, read round trips, destructuring, sorted collections, metadata through collection ops, equality and hashing of related values, BigDecimal under with-precision, hash iteration order, transients, arrays, exceptions, reference types, hierarchies and protocols. No form can allocate without bound or hang on its own: infinite sources only appear under take.
  2. Run (runner/runner.clj, src/fizzjolt/exec.clj). The same runner file runs on both runtimes. It evaluates each form and prints one canonical rendering per line, flushed as it goes. The rendering keeps what a program can observe and drops what is incidental (identity hashes, which integer class holds a value). A watchdog kills a process that stalls, records the form as a hang, and resumes after it.
  3. Compare (src/fizzjolt/compare.clj). Results are normalized and bucketed: value (both answered, differently), jolt-throws, jolt-hang, jolt-crash (high severity), and jvm-throws (jolt's documented permissive superset), throw-class, ulp, jvm-hang (low). Divergences jolt documents in test/conformance/known-divergences.edn are matched by rules that cite the entry, and counted rather than reported. Divergences already filed are matched by known rules.
  4. Shrink (src/fizzjolt/shrink.clj). Each round proposes every one-step reduction (hoist a subform, replace one with a child or a literal, drop an argument or element, simplify a number or string), runs them as one batch, and keeps the smallest that still diverges the same way.

Use

Needs babashka, a JDK with Clojure 1.12 jars in ~/.m2, and a jolt binary.

bb fuzz :seed 1 :batches 40 :size 500 :parallel 4 :out out/run-1
bb reclassify :out out/run-1    # re-apply edited rules without re-running
bb shrink :out out/run-1        # minimal forms for undocumented divergences
bb report :out out/run-1        # out/run-1/catalog.md
bb scripts/show.clj out/run-1   # high-severity divergences, shortest first
bb -cp src scripts/recheck.clj out/recheck out/run-1   # re-run them on a new FUZZ_JOLT
bb test                         # self-tests (runs both runtimes)

Paths come from the environment: FUZZ_JOLT (default ../tmp/jolt-integ4/jolt), FUZZ_JAVA, FUZZ_CLOJURE_CP, FUZZ_STALL_MS (default 10000).

The findings, triaged, are in catalog/, and scripts/publish.sh pushes the fix branches and files the PRs and issues upstream.

Future work

The current generator mostly finds known bugs again. Of run c's 1,963 divergences, about half were bugs already filed and a third were documented. Only 26 of its 50,000 forms gave a high-severity divergence that no rule matched. These directions should find new bugs, roughly in order of expected yield.

  1. Hide literals from the compiler. jolt's passes (jolt-core/jolt/passes/) emit different code depending on what they can prove. Constant folding is always on, numeric hints select fixnum and flonum arithmetic, transducer stages and let-threaded edit chains are fused, loop maps are lowered, and direct linking inlines. Nearly every generated argument is a literal, so many forms are probably folded at compile time, and the code that runs on values the compiler cannot see is rarely reached. Evaluating each form a second time with its literals out of the compiler's sight (behind a deref of an atom, say) would reach it. If jolt gives the two forms different results, that is a bug whatever the JVM says.

  2. Record side effects. Only results are compared. A template that appends each step to an atom and returns the log would show how far a lazy seq is realized (chunks of 32), the order in which arguments and bindings are evaluated, and how often a transducer's completion step runs. Upstream fixed one such bug in jolt-lang/jolt#1984 (reduce realized an unchunked seq too far).

  3. Close the coverage gap. Of the public vars the runner loads, these never appear in gen.clj:

    • clojure.core: 300 of 600 functions and 51 of 79 macros
    • clojure.math: 37 of 45
    • clojure.pprint: 18 of 20

    Agents, IO, randomness and the dynamic vars are out of scope, but many of the missing vars are deterministic:

    • macros: ->>, as->, some->>, when-let, if-some, letfn, doseq, lazy-cat, doto, with-redefs, with-local-vars
    • functions: juxt, every-pred, some-fn, memoize, trampoline, key and val, reduced? and unreduced, the qualified-* and simple-* predicates, hash-ordered-coll, vector-of, make-array, tagged-literal, alter-var-root, the unchecked-*-int family

    Sizes are a gap too. A generated collection holds at most 7 elements, except in the hash-order template, and no generated vector reaches 33 elements, so the sizes where JVM collections change representation (33 and 1,057 elements for a vector, 9 entries for a map) are mostly untested.

  4. Add Gambit as a third runtime. host/gambit/ runs the same overlay on a second Scheme. It has its own adapter and kernel, its seed is cross-minted from Chez's, and its kernel rt-core.ss is a hand port of host/chez/rt.ss. With every form run on the JVM, jolt on Chez and jolt on Gambit, the fuzzer could tell a backend that has drifted from a bug in the shared code. A backend that lacks a capability raises by contract (host/scheme-adapter/CONTRACT.txt lists the tiers), so those differences are expected and need rules. This needs Gambit 4.9.8, the version jolt's CI builds.

  5. Use jolt's documented divergences as an oracle, not only a filter. test/conformance/known-divergences.edn lists where jolt differs from the JVM and why. Most entries are one of two kinds:

    • Chosen outcomes. jolt gives a different answer and documents the choice: the integer, string and host models, and the places where it is stricter.
    • Superset behaviour. The JVM has no answer to compare with:
      • jolt answers where the JVM throws (:permissive, 51 entries)
      • it resolves names the JVM cannot (:namespace-model)
      • it accepts type hints the JVM refuses (:type-hint-model)
      • it reads syntax the JVM rejects (:reader-model)
      • it ships namespaces with no JVM counterpart (stdlib/jolt/)

    Today the rules set these aside without looking at jolt's answer. Sixteen of the seventeen documented rules match on the bucket, the JVM's side or the form's text, so a wrong jolt result behind a documented divergence goes unseen. Each kind can become a test instead:

    • For a chosen outcome, check jolt's answer. 123 entries carry a :check with an expression and both renderings. jolt's make documented already holds each of those expressions to its rendering on Chez. The fuzzer could generate variations around each one and require jolt's answer to keep the documented shape, on both backends.
    • For superset behaviour, compare backends. The JVM is no oracle here, but Chez and Gambit should agree, on the capabilities both implement. This needs the Gambit leg from 4.

    Put together, each kind of form gets its own test:

    Form Expectation
    Portable all three runtimes agree
    Chosen outcome both backends behave as documented
    Superset the two backends agree

License

Eclipse Public License 2.0, the license jolt uses. The text is in LICENSE.

About

A fuzzer for jolt lang. Compares outcomes with JVM Clojure.

Resources

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0