LLZK 2.1.1
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
Tool Guides

llzk-opt

llzk-opt is a version of the mlir-opt tool that supports passes on LLZK IR files. You can refer to the mlir-opt documentation for a general overview of the operation of *-opt tooling, but note that many options and passes available in mlir-opt are not available in llzk-opt. llzk-opt -h will show a list of all available flags and options.

LLZK-Specific Options

-I <directory> : Directory of include files

LLZK Pass Documentation

Analysis Passes

-llzk-print-call-graph

Print the LLZK module's call graph.

Options
-stream : Specifies the stream to which the pass prints.

-llzk-print-call-graph-sccs

Print the SCCs from the LLZK module's call graph.

Options
-stream : Specifies the stream to which the pass prints.

-llzk-print-constraint-dependency-graphs

Print constraint dependency graph for all LLZK structs.

Options
-stream : Specifies the stream to which the pass prints.
-intraprocedural : Whether to run the analysis intra-procedurally only (default is false).

-llzk-print-interval-analysis

Print interval analysis results for all LLZK structs.

Options
-stream : Specifies the stream to which the pass prints.
-field : The field to use for interval analysis. If supplied, this always overrides the module's detected field. If omitted, the pass first tries to detect a single field from the enclosing module's felt usage and otherwise falls back to bn128. Supported fields: bn128/bn254, babybear, goldilocks, grumpkin, koalabear, mersenne31
-propagate-input-constraints : Whether to propagate constraints on inputs from @constrain to @compute functions. This allows for tighter intervals to possibly be found for computed values, assuming that the witness generator would include constraints as assertions during the computation.
-print-solver-constraints : Whether to output SMT solver constraints along with intervals.
-print-compute-intervals : Whether to print compute function intervals (default only prints constrain function intervals).
-print-unreduced-intervals : Whether to print tracked unreduced intervals alongside reduced interval summaries.
-print-ssa-intervals : Whether to print per-SSA intervals for function arguments and scalar op results.

-llzk-print-predecessors

Print the predecessors of all operations.

Options
-stream : Specifies the stream to which the pass prints.
-prerun : Whether to pre-run the required dataflow analyses (e.g., liveness analysis).

-llzk-print-symbol-def-tree

Print symbol definition tree.

Options
-stream : Specifies the stream to which the pass prints.
-saveDot : Whether to dump the graph to DOT format.

-llzk-print-symbol-use-graph

Print symbol use graph.

Options
-stream : Specifies the stream to which the pass prints.
-saveDot : Whether to dump the graph to DOT format.

General Transformation Passes

-llzk-compute-constrain-to-product

_Replace separate @compute and @constrain functions in a struct with a single @product function_

Replace separate @compute and @constrain functions in a struct with a single @product function

Options
-root-struct : Root struct at which to start alignment (default to `@Main`)

-llzk-duplicate-op-elim

Remove redundant operations

Remove llzk and arith dialect operations that produce the same results as previously executed operations.

Pass should be run after llzk-duplicate-read-write-elim for maximum effect.

-llzk-duplicate-read-write-elim

Remove redundant reads and writes

Remove read and write operations to struct members and arrays that are redundant or unnecessary.

-llzk-enforce-no-overwrite

Checks that every struct member is written exactly once

This pass currently reports an error if any struct member may not be written exactly once (i.e. overwritten or left uninitialized), and does not attempt to perform any repairs (e.g. SSA-ifying overwritten struct members, or default-initializing unwritten members). This pass overapproximates conditionals, and can result in false positives.

-llzk-fuse-product-loops

_Fuse matching witness/constraint loops in a @product function_

Fuse matching witness/constraint loops in a @product function

-llzk-inline-structs

Inlines nested structs (i.e., subcomponents).

This pass inlines nested structs (i.e., subcomponents) at struct-type members and at calls to the subcomponent compute/constrain functions. Inlining decisions are guided by the call graph of "constrain" functions.

The max-merge-complexity parameter can be used to limit the complexity of the resulting structs such that a potential inlining will not take place if doing so would push the sum of constraint and multiplications in the combined struct over the limit. The default value 0 indicates no limits which means all structs will be inlined into the Main struct.

This pass should be run after llzk-flatten to ensure structs do not have template parameters because structs with template parameters cannot (currently) be inlined. Inlining is also not (currently) supported for subcomponent structs stored in an array-type member.

This pass also assumes that all subcomponents that are created by calling a struct "@compute" function are ultimately written to exactly one member within the current struct.

Options
-max-merge-complexity : Maximum allowed constraint+multiplications in merged @constrain functions

-llzk-poly-lowering-pass

Lower the degree of all polynomial equations to a specified maximum

Rewrites constraint expressions into an (observationally) equivalent system where the degree of every polynomial is less than or equal to the specified maximum.

High-degree subexpressions are factored into auxiliary struct members. The pass also recurses through degree-neutral roots such as felt.add, felt.sub, and felt.neg, so composite equality operands and struct constrain call arguments satisfy their degree bounds.

This pass is best used as part of the -llzk-full-poly-lowering pipeline, which includes additional cleanup passes to ensure correctness and optimal performance.

Options
-max-degree : Maximum degree of constraint polynomials (default 2, minimum 2)

-llzk-remove-unused-discardable-allocations

Remove unread discardable allocations and their dead stores

Remove ops with the selected allocator operation name when they are marked with MemAlloc<DiscardableAllocationResource>, the allocation has no reads, and every direct user is a discardable allocation accessor that can be erased as a dead store.

Options
-allocator-op : Operation name of the discardable allocator to remove

-llzk-unused-declaration-elim

Remove unused member and struct declarations

Remove member and struct declarations that are unused within the current compilation unit. Note that this pass may cause linking issues with external modules that depend on any unused member and struct declarations from this compilation unit.

Pass should be run after llzk-duplicate-read-write-elim and llzk-duplicate-op-elim for maximum effect.

Options
-remove-structs : Whether to remove unused struct definitions as well. Requires module to declare a Main component, otherwise all components will appear unused.

-llzk-while-to-for

Converts scf.while loops to equivalent scf.for loops when possible

This pass identifies scf.while loops that have an induction variable and a uniform step, and converts them to equivalent scf.for loops, which are preferred by some analyses. This pass may introduce some spurious felt/index casts which should be cleaned up by –canonicalize.

'array' Dialect Transformation Passes

-llzk-array-to-scalar

Replace arrays with scalar values

Replace known-shape arrays with the proper number of scalar values

'polymorphic' Dialect Transformation Passes

-llzk-drop-empty-templates

Remove empty templates

Performs the following transformations:

  • Convert templates with no constant parameters or expressions into modules.
  • Remove templates with no struct or function definitions.

-llzk-flatten

Flatten structs and unroll loops

Performs the following transformations:

  • Instantiate affine_map parameters of StructType and ArrayType to constant values using the arguments at the instantiation site
  • Replace parameterized structs with flattened (i.e., no parameter) versions of those structs based on requested return type at calls to compute() functions and unroll loops
  • Unroll loops
Options
-max-iter : Maximum number of times the pass will run if a fixpoint is not reached earlier. Unrolling loops can provide more opportunities for instantiating structs but the converse is true as well. Thus, the pass will run multiple times until no further changes can be made or the upper limit provided in this option is reached.
-cleanup : Specifies the extent to which unused parameterized definitions (i.e. structs or free functions within a `poly.template`) are removed during the flattening pass.

Validation Passes

-llzk-validate-member-writes

Detect multiple and missing writes to the same member of a component.

Detect multiple and missing writes to the same member of a component.

Note that this is overapproximate (i.e., some writes may erroneously be flagged as overwrites, and some members may erroneously be marked unwritten).

llzk-witgen

llzk-witgen executes LLZK witness-generation logic for the concrete main component declared by llzk.main. It evaluates compute() and prints JSON for either the public outputs of the main component or the full generated witness signal set.

Basic Usage

llzk-witgen <input.llzk> --inputs <input.json>

LLZK-Specific Options

--inputs <file> JSON file containing main compute inputs
-I <directory> Directory of include files
--backend=<name> Execution backend: interpreter or execution-engine
--output-scope=<name> Output scope: public or full-witness
--dump-jit-core Print the pre-LLVM JIT module
--dump-jit-llvm Print the post-LLVM JIT module
--uninitialized-behavior Control default handling of uninitialized witness values
--uninitialized-seed Seed used for randomized uninitialized witness values

Input Format

The --inputs file must contain a top-level JSON object or JSON array.

  • A JSON object is keyed by function.arg_name attributes on the main compute() function arguments.
  • A JSON array is interpreted positionally in declared argument order.

At the main boundary, llzk-witgen only supports felt and array<... x felt> inputs, due to the restrictions posed on llzk.main components. Field element values are accepted in the same JSON form used by the witgen tests, namely JSON integers or decimal strings.

Output Format

llzk-witgen writes one JSON object to stdout. The exact shape depends on --output-scope.

  • --output-scope=public is the default.
    • The output JSON contains only the public outputs of the main component.
    • Public struct members become JSON object fields.
    • Public felt arrays become JSON arrays.
    • Field element leaves are rendered as decimal strings.
  • --output-scope=full-witness
    • The output JSON contains two top-level objects: inputs and signals.
    • inputs records the main compute() arguments using their function.arg_name attributes when available, or stable fallback names such as arg0, arg1, and so on for positional inputs.
    • signals records all witness signals reachable from the returned main struct, including both public and private signals.
    • Non-signal leaves are omitted, though non-signal struct containers may still appear when needed to reach nested signals.
    • Felt arrays remain JSON arrays and field element leaves remain decimal strings.

Backends

llzk-witgen currently supports two execution backends:

  • --backend=interpreter Executes LLZK @compute logic directly over the preprocessed MLIR.
  • --backend=execution-engine Lowers preprocessed LLZK @compute IR to built-in MLIR dialects that can be natively converted to LLVM IR, then executes it with mlir::ExecutionEngine.

The default backend is interpreter, as the execution-engine does not currently support all LLZK features due to existing lowering limitations (e.g., in the -llzk-flattening pass).

Preprocessing

Before execution, llzk-witgen performs the preprocessing needed to make witness generation concrete and executable:

  • include inlining
  • flattening rooted at llzk.main when required
  • affine lowering for execution-engine mode
  • subcomponent inlining for execution-engine mode

Template parameters and affine instantiations are therefore supported only when they can be fully resolved by the preprocessing pipeline before execution.

llzk-lsp-server

cmake --build <build dir> --target llzk-lsp-server will produce an LLZK-specific LSP server that can be used in an IDE to provide language information for LLZK. Refer to the MLIR LSP documentation for a more detailed explanation of the MLIR LSP tools and how to set them up in your IDE.

Previous Next
Setup Contribution Guide