-
Notifications
You must be signed in to change notification settings - Fork 0
Raghav/weakest precondition #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
a310fff
Added cvc5 dependency
203bed2
Test run of cvc5 expression building
e6f8e1c
lmao
d02582c
First pass of WP calculator is done, but memory issues
0b6e96c
oops
9f9508f
ugh
3f42d7b
Trying without StringMap
3040840
Fixed stupid lifetimes issue
1e88de7
fixed memory errors, and (a -> (b -> c)) to (a && b) -> c
ce20c74
Reducing mod p now, still need to fix field inference
3924fe6
Refactor with TermBuilder
a930ab8
Bump LLZK, clean up field detection
a907c77
update comment
6bfbcd2
Merge remote-tracking branch 'origin' into raghav/weakest-precondition
38451d3
Updated tests for optimized SMT encoding
30f63a1
Bump LLZK
f0ac14b
Don't spuriously require field
9de175e
Rename
a7e98a0
Properly handle WP for arrays
9ca279e
Made array flattening optional
ab4d657
marked regression
47ca8f5
Emitting extra declarations, added some TODOs
9d74420
Array equality works after adding bounds
54ea022
Some refactoring, whatever
88786a9
Emit extra [0, p-1] bounds
3cc4806
Add readwrite array test
aef14fe
Really stupid handling of subcomponents, not emitting extra uninterpr…
f605017
Always doing write-once semantics for signal arrays, still need to ma…
e051c39
Some better subcomponent support in WP
7dec5d4
Fixed testcases
84cf9cd
syntax error in test I guess
b42f2c1
Subcomponent store
raghav198 5be597b
Loop invariants (#43)
raghav198 3170dd3
Raghav/public release (#50)
raghav198 75574f7
Revert "Raghav/public release (#50)"
6f6d829
Raghav/public release (#55)
raghav198 e44c79b
Correctly read from a subcomponent member
6782c4c
Correctly read from a subcomponent member
671df15
Implemented solver portfolio
d9c8227
bn128
02e6765
git module
12180d3
Fixed portfolio issues, added benchmark importing
933157c
Remove hardcoded benchmarks
fe1dbdc
Remove unused file
a282a5c
Documentation
7b02d16
Veridise Inc -> Project LLZK
201a78c
Comments
30f3f55
Comments, got rid of missing file from cmake
81acba7
Code review comments
d910d3d
Veridise Inc -> Project LLZK
9ae3cdb
Build instructions clearer
150fba3
Reword
9139dda
Reword
85c12a5
Veridise Inc -> Project LLZK
4da703a
Updated report syntax
82dbeb7
Updated report syntax
4c48099
Bump LLZK
130f29a
default to release build
19463dc
Code review comments
1fb7557
Code review comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [submodule "circom-benchmarks"] | ||
| path = circom-benchmarks | ||
| url = git@github.com:project-llzk/circom-benchmarks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,123 @@ | ||
| # LLZK-Verifier | ||
| Porting [ZEQUAL](https://www.cs.utexas.edu/~isil/zequal.pdf) to LLZK | ||
| # LLEQ | ||
|
|
||
| LLEQ is an equivalence verifier for zero-knowledge circuits in LLZK IR, based on [Zequal](https://veridise.com/wp-content/uploads/2025/08/zequal.pdf). LLEQ consumes **LLZK IR**, not high-level circuit languages directly. If your circuit is written in another language, first lower it to LLZK using an appropriate frontend (see [Frontends](https://github.com/project-llzk/.github/blob/main/profile/README.md)), then run LLEQ on the resulting `.llzk` file | ||
|
|
||
| ## Quick Links | ||
|
|
||
| - [Build](#build) | ||
| - [Usage](#usage) | ||
| - [Examples](#examples) | ||
| - [Capabilities and Limitations](#capabilities-and-limitations) | ||
|
|
||
| ## Build | ||
|
|
||
| LLEQ can be built with Nix, or manually with CMake. | ||
|
|
||
| ### Nix (Recommended) | ||
|
|
||
| This repository is configured with a Nix flakes environment. The flake was built using Nix version 2.31; older/newer versions may or may not. | ||
| Once you have a Nix installation (See [Installation](https://nix.dev/manual/nix/2.31/installation/index.html)), you can run `nix build .#lleq` from the repository root, or `nix develop` to enter a developer shell. Inside the dev shell, the built `lleq` binary is added to `PATH` for | ||
| convenience. | ||
|
|
||
| ### Manual | ||
|
|
||
| For a manual build, you will need the following: | ||
|
|
||
| - LLVM | ||
| - MLIR | ||
| - LLZK | ||
| - a C++23-capable compiler | ||
| - `cvc5` | ||
| - `z3` | ||
| - Python 3 | ||
|
|
||
| Both LLZK and MLIR must be built and installed in a way that CMake can discover with `find_package(LLZK)` (See [project-llzk/llzk-lib](https://github.com/project-llzk/llzk-lib/blob/main/doc/doxygen/01_setup.md#manual-build-setup) for instructions on how to build LLVM/MLIR/LLZK). | ||
|
|
||
| At runtime, LLEQ expects both `cvc5` and `z3` to be available on `PATH`. Solver | ||
| discovery can also be overridden by setting the following environment variables: | ||
|
|
||
| ``` | ||
| LLEQ_CVC5=/path/to/cvc5 | ||
| LLEQ_Z3=/path/to/z3 | ||
| ``` | ||
|
|
||
| #### Build with CMake | ||
|
|
||
| Configure: | ||
|
|
||
| ```bash | ||
| cmake -G Ninja -S . -B build -DCMAKE_BUILD_TYPE=Release | ||
| ``` | ||
|
|
||
| If LLVM, MLIR, or LLZK are installed in nonstandard locations, point CMake at | ||
| their package configuration directories with `-DLLVM_DIR=...`, | ||
| `-DMLIR_DIR=...`, and `-DLLZK_DIR=...`. | ||
|
|
||
| Build: | ||
|
|
||
| ```bash | ||
| cmake --build build | ||
| ``` | ||
|
|
||
| ### Run the Test Suite | ||
|
|
||
| To run the LIT regression tests after a manual build: | ||
|
|
||
| ```bash | ||
| cmake --build build --target check | ||
| ``` | ||
|
|
||
| The Nix package build also runs the test suite. | ||
|
|
||
| ## Usage | ||
|
|
||
| LLEQ operates on an input `.llzk` file and a selected struct: | ||
|
|
||
| ```bash | ||
| lleq <subcommand> --struct <StructName> [options] input.llzk | ||
| ``` | ||
|
|
||
| Available subcommands: | ||
|
|
||
| - `dump-store`: print the symbolic store constructed for the selected struct | ||
| - `verify`: prove equivalence of signal members | ||
| - `dump-smt`: print the SMT-LIB query generated for deductive verification | ||
| - `wp`: infer loop invariants and emit weakest-precondition-style verification conditions as SMT-LIB | ||
|
|
||
| Common options: | ||
|
|
||
| - `--struct <name>`: required; selects the struct to analyze | ||
| - `--field <field-name>`: selects the prime field when it cannot be inferred | ||
| - `--flatten`: run LLZK flattening and array-to-scalar lowering before analysis | ||
| - `--enable-store`: available for `verify` and `dump-smt`; adds extra symbolic-store facts | ||
|
|
||
| ### Verify Output | ||
|
|
||
| `lleq verify` reports one line per signal member: | ||
|
|
||
| - `+ @Struct::member`: proven equivalent | ||
| - `- @Struct::member`: proven inequivalent | ||
| - `* @Struct::member`: unknown | ||
|
|
||
| For inequivalent members, LLEQ also prints a witness/constraint counterexample model. | ||
|
|
||
| Note that `lleq verify` does not perform loop invariant inference. To verify a struct containing loops or arrays, pass the `--flatten` argument to first unroll and scalarize the struct. | ||
|
|
||
| ### Weakest-Precondition Queries | ||
|
|
||
| `lleq wp` emits an SMT-LIB query that can be sent directly to an SMT solver to | ||
| check the verification condition and, when it fails, obtain a counterexample. | ||
|
|
||
| For example: | ||
|
|
||
| ```bash | ||
| lleq wp --struct DecomposeProduct_1 --field babybear examples/circom-examples/DecomposeProduct.llzk | z3 -in | ||
| ``` | ||
|
|
||
| ## Examples | ||
|
|
||
| See [Examples](examples/README.md) | ||
|
|
||
| ## Capabilities and Limitations | ||
|
|
||
| Analysis of structs with multidimensional arrays or subcomponent calls is not currently well-supported. Verification may also fail for structs where LLZK's product alignment produces poor alignments. | ||
Submodule circom-benchmarks
added at
f6b9cb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # Examples | ||
|
|
||
| This directory collects example circuits and benchmark artifacts used for LLEQ | ||
| development, demos, and evaluation. | ||
|
|
||
| ## `circom-examples` | ||
|
|
||
| To import and generate benchmarks from [`project-llzk/circom-benchmarks`](https://github.com/project-llzk/circom-benchmarks), run: | ||
|
|
||
| ```bash | ||
| python3 scripts/import_circom_demo_examples.py --circom-frontend <circom> --llzk <llzk-opt> | ||
| ``` | ||
|
|
||
| Each imported benchmark is lowered to LLZK and then normalized with the | ||
| following pass pipeline before being checked into this repository: | ||
|
|
||
| ```text | ||
| --llzk-while-to-for | ||
| --llzk-compute-constrain-to-product=root-struct=<RootStruct> | ||
| --llzk-fuse-product-loops | ||
| --canonicalize | ||
| ``` | ||
|
|
||
| Here, `<RootStruct>` is the benchmark's `llzk.main` root struct. The resulting | ||
| normalized `.llzk` files are stored flat in [`circom-examples`](./circom-examples). | ||
|
|
||
| The subdirectory also includes `verification_results.csv`, which records LLEQ | ||
| verification outcomes for the imported set. | ||
|
|
||
| ## Collecting Verification Data | ||
|
|
||
| Run: | ||
|
|
||
| ```bash | ||
| python3 scripts/collect_circom_demo_results.py --lleq-bin <lleq> --z3-bin <z3> | ||
| ``` | ||
|
|
||
| For each imported benchmark, the script currently runs: | ||
|
|
||
| ```text | ||
| lleq wp --struct <RootStruct> | z3 -in | ||
| ``` | ||
|
|
||
| Each run uses a 120-second timeout and reports one of: | ||
|
|
||
| - `verified` | ||
| - `counterexample` | ||
| - `partial` | ||
| - `timeout` | ||
| - `error` | ||
|
|
||
| `wp` is classified as `partial` when z3 returns `unknown`. | ||
|
|
||
| Results are saved in `examples/verification_results.csv`. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /** | ||
| * Copyright 2026 Veridise Inc. | ||
| * Copyright 2026 Project LLZK | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /** | ||
| * Copyright 2025 Veridise Inc. | ||
| * Copyright 2025 Project LLZK | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /** | ||
| * Copyright 2026 Veridise Inc. | ||
| * Copyright 2026 Project LLZK | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /** | ||
| * Copyright 2026 Veridise Inc. | ||
| * Copyright 2026 Project LLZK | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /** | ||
| * Copyright 2025 Veridise Inc. | ||
| * Copyright 2025 Project LLZK | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /** | ||
| * Copyright 2026 Veridise Inc. | ||
| * Copyright 2026 Project LLZK | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /** | ||
| * Copyright 2026 Veridise Inc. | ||
| * Copyright 2026 Project LLZK | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /** | ||
| * Copyright 2026 Veridise Inc. | ||
| * Copyright 2026 Project LLZK | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /** | ||
| * Copyright 2026 Veridise Inc. | ||
| * Copyright 2026 Project LLZK | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /** | ||
| * Copyright 2026 Veridise Inc. | ||
| * Copyright 2026 Project LLZK | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /** | ||
| * Copyright 2026 Veridise Inc. | ||
| * Copyright 2026 Project LLZK | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.