Unit tests#1149
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a per-AIR “unit test” framework that can run constraint verification directly against hand-authored state-machine inputs (no ELF/ROM/emulation), together with example tests and supporting executor/prover plumbing. It also updates the workspace to a pil2-proofman branch that contains the required verification/constraint-reporting capabilities.
Changes:
- Add a unit-test backend (
UnitTestProver+ fluentVerifyInputbuilder) and a unit-test executor (ZiskExecutorTest) that plans AIR instances and dispatches typed witness computation, hooks, and trace overrides. - Add a new
unit-tests/workspace crate with initial per-AIR integration tests and documentation/examples for authoring tests. - Improve constraint-verification reporting and add a CLI dev command to list constraint ids/source lines (
cargo-zisk-dev get-constraints).
Reviewed changes
Copilot reviewed 69 out of 72 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
Cargo.toml |
Adds unit-tests to workspace and switches pil2-proofman dependencies to the feature branch used by the new unit-test/constraints flow. |
Cargo.lock |
Updates workspace lockfile due to dependency changes (pil2-proofman branch + crate updates). |
ziskos/entrypoint/Cargo.toml |
Updates fields dependency to the pil2-proofman feature branch for non-zkvm builds. |
verifier/Cargo.toml |
Updates proofman-verifier dependency to the pil2-proofman feature branch. |
unit-tests/Cargo.toml |
Adds new workspace crate to host per-AIR integration tests (no library code beyond docs). |
unit-tests/src/lib.rs |
Documents the purpose of the unit-tests crate and points to example tests. |
unit-tests/tests/add256.rs |
Adds an ignored Add256 “honest input verifies” unit test via the new test API. |
unit-tests/tests/arith.rs |
Adds an ignored Arith “honest inputs verify” unit test via the new test API. |
unit-tests/tests/arith_eq.rs |
Adds ArithEq template tests covering honest input, hook-based corruption, and raw trace authoring. |
unit-tests/tests/arith_eq_384.rs |
Adds an ignored ArithEq384 “honest input verifies” unit test. |
unit-tests/tests/binary.rs |
Adds ignored unit tests for Binary/BinaryAdd/BinaryExtension via typed inputs. |
unit-tests/tests/dma.rs |
Adds ignored unit tests across multiple DMA family SMs using typed inputs and encoded DMA info. |
unit-tests/tests/hashes.rs |
Adds ignored unit tests for Keccakf/Sha256f/Blake2 via typed inputs. |
unit-tests/tests/mem.rs |
Adds ignored MemAlign unit test and documents why other mem-module SMs aren’t supported yet. |
test-artifacts/programs/Cargo.lock |
Updates program lockfile to the pil2-proofman feature branch and related dependency bumps. |
common/Cargo.toml |
Adds pil-std-lib dependency to support unit-test trace authoring and std hooks. |
common/src/lib.rs |
Exposes the new unit-test SM framework (traits + macros) from zisk-common. |
common/src/unit_test_sm.rs |
Introduces UnitTestSm/DynUnitTestSm + trace override support and macros to generate per-SM markers. |
common/src/zisk_precompile.rs |
Adds accessor for inner precompile SM and adapts witness calls for the unit-test registry and new signature. |
executor/src/lib.rs |
Exposes ZiskExecutorTest and publishes unit-test hook/override/registry modules. |
executor/src/executor_test.rs |
Implements the unit-test executor component: input planning, witness dispatch, hooks, air/proof values mutation, and trace overrides. |
executor/src/unit_test_hooks.rs |
Adds post-witness typed trace-row mutation hooks (type-erased at storage). |
executor/src/unit_test_trace_override.rs |
Adds raw trace-authoring override registration and storage for unit-test execution. |
executor/src/unit_test_targets/mod.rs |
Adds registry lookup by AIR id/name and builds AIR-id → erased-manager registry from the SM bundle. |
executor/src/sm/mod.rs |
Exposes iteration over registered SMs for unit-test registry construction. |
executor/src/sm/builtins.rs |
Wires in built-in unit-test registry definitions. |
executor/src/sm/builtins/unit_tests.rs |
Declaratively maps built-in AIR ids to the correct inner witness-producing SMs for unit tests. |
executor/src/sm/precompiles.rs |
Imports precompile *Sm markers for unit-test registry generation. |
executor/src/sm/register_precompiles.rs |
Extends precompile registration macro to generate unit-test manager wiring + marker/override slices. |
state-machines/arith/src/arith.rs |
Exposes inner Arith SM accessor for unit-test manager registry extraction. |
state-machines/arith/src/lib.rs |
Registers Arith as a unit-test target via unit_test_sm!. |
state-machines/binary/src/binary.rs |
Exposes inner Binary SM accessors for unit-test manager registry extraction. |
state-machines/binary/src/binary_input.rs |
Adds Debug, Default derives needed by the unit-test input workflow. |
state-machines/binary/src/lib.rs |
Re-exports binary input and registers Binary SMs as unit-test targets via unit_test_sm!. |
state-machines/mem/src/mem.rs |
Exposes inner mem-module SM accessors for the unit-test manager registry extraction. |
state-machines/mem/src/mem_align_sm.rs |
Adds rows_per_input helper for MemAlign planning/used-row calculation in unit tests. |
state-machines/mem/src/mem_inputs.rs |
Adds Clone, Default derives for mem inputs used by unit-test workflow. |
state-machines/mem/src/lib.rs |
Re-exports mem input/types and registers mem SMs for unit-test framework (MemAlign supported; others return clear error). |
precompiles/big_int/src/add256.rs |
Updates Add256 witness signature to match new call shape and unit-test integration. |
precompiles/big_int/src/lib.rs |
Registers Add256 as a unit-test SM target via unit_test_sm!. |
precompiles/blake2/src/blake2.rs |
Updates Blake2 witness signature to match new call shape and unit-test integration. |
precompiles/blake2/src/lib.rs |
Registers Blake2 as a unit-test SM target via unit_test_sm!. |
precompiles/dma/src/dma/dma_input.rs |
Adds Default derive to DMA input for easier test construction. |
precompiles/dma/src/dma_64_aligned/dma_64_aligned_input.rs |
Adds Default derive to DMA64Aligned input for easier test construction. |
precompiles/dma/src/dma_manager.rs |
Exposes inner DMA SM accessors for unit-test manager registry extraction. |
precompiles/dma/src/dma_pre_post/dma_pre_post_input.rs |
Adds Default derive to DMA pre/post input for easier test construction. |
precompiles/dma/src/dma_unaligned/dma_unaligned_input.rs |
Adds Default derive to DMA unaligned input for easier test construction. |
precompiles/dma/src/lib.rs |
Registers the DMA family as unit-test SM targets via unit_test_sm! with custom compute wiring. |
precompiles/keccakf/src/keccakf.rs |
Updates Keccakf witness signature to match new call shape and unit-test integration. |
precompiles/keccakf/src/lib.rs |
Registers Keccakf as a unit-test SM target via unit_test_sm!. |
precompiles/poseidon/src/poseidon.rs |
Updates Poseidon witness signature to match new call shape and unit-test integration. |
precompiles/poseidon/src/lib.rs |
Registers Poseidon as a unit-test SM target via unit_test_sm!. |
precompiles/sha256f/src/sha256f.rs |
Updates Sha256f witness signature to match new call shape and unit-test integration. |
precompiles/sha256f/src/lib.rs |
Registers Sha256f as a unit-test SM target via unit_test_sm!. |
precompiles/arith_eq/src/arith_eq.rs |
Updates ArithEq witness signature to match new call shape and unit-test integration. |
precompiles/arith_eq/src/arith_eq_input.rs |
Adds Default derives for ArithEq typed inputs used in unit tests/examples. |
precompiles/arith_eq/src/lib.rs |
Registers ArithEq as a unit-test SM target via unit_test_sm!. |
precompiles/arith_eq_384/src/arith_eq_384.rs |
Updates ArithEq384 witness signature to match new call shape and unit-test integration. |
precompiles/arith_eq_384/src/arith_eq_384_input.rs |
Adds Default derives for ArithEq384 typed inputs used in unit tests/examples. |
precompiles/arith_eq_384/src/lib.rs |
Registers ArithEq384 as a unit-test SM target via unit_test_sm!. |
prover-backend/Cargo.toml |
Adds dependencies needed for the unit-test backend API surface (SM crates, pil-std-lib, precompiles). |
prover-backend/src/lib.rs |
Re-exports constraint-verification result types and publishes the testing module. |
prover-backend/src/testing.rs |
Adds shared UnitTestProver singleton + proving-key presence guard for tests. |
prover-backend/src/prover/backend.rs |
Improves error reporting when constraint verification returns an invalid result. |
prover-backend/src/prover/mod.rs |
Exposes the unit-test prover API, SM markers, and convenience re-exports for inputs/rows/traces. |
prover-backend/src/prover/unit_test.rs |
Implements UnitTestProver that runs proofman in verify-constraints mode using the unit-test executor. |
prover-backend/src/prover/verify_input.rs |
Adds the fluent builder for typed inputs, hooks, trace overrides, air/proof values, and global-constraint selection. |
cli/src/commands/dev.rs |
Registers the new get-constraints dev command. |
cli/src/commands/dev/get_constraints.rs |
Implements cargo-zisk-dev get-constraints to list per-AIR and global constraints with ids/lines. |
cli/examples/unit-test/README.md |
Adds detailed documentation for the per-AIR unit-test framework and how to run/write tests. |
cli/examples/unit-test/example.json |
Provides example JSON shapes for SM inputs (documentation-only; not consumed yet). |
verifier/Cargo.toml |
(Also listed above) Updates proofman-verifier dependency to match new proofman branch. |
ziskos/entrypoint/Cargo.toml |
(Also listed above) Updates fields dependency to match new proofman branch. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
🔄 ZisK Cycle TrackingEmulator cost report ( Summary
Per-Guest Breakdownbigint
bls12_381
bn254
diagnostic
hashes
secp256k1
secp256r1
uint256
🔴 increase (regression) · 🟢 decrease (improvement) · ➖ no change. |
cc6f268 to
a1117f7
Compare
a1117f7 to
8a079b6
Compare
| proofman = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch = "feature/verify-constraints-info" } | ||
| proofman-common = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch = "feature/verify-constraints-info" } | ||
| proofman-macros = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch = "feature/verify-constraints-info" } | ||
| proofman-verifier = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch = "feature/verify-constraints-info" } | ||
| proofman-util = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch = "feature/verify-constraints-info" } | ||
| proofman-starks-lib-c = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch = "feature/verify-constraints-info" } | ||
| pil-std-lib = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch = "feature/verify-constraints-info" } | ||
| witness = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch = "feature/verify-constraints-info" } | ||
| fields = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch = "feature/verify-constraints-info" } | ||
| pil2-stark-setup = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch = "feature/verify-constraints-info" } |
| fields = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch = "feature/verify-constraints-info", features = [ | ||
| "verify", | ||
| ] } |
| proofman-verifier = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch = "feature/verify-constraints-info", default-features = false, features = [ | ||
| "verify", | ||
| ] } |
| 2. **In the executor**, add `NewSm` to the `registry![ … ]` list in | ||
| [`executor/src/unit_test_targets/mod.rs`](../../../executor/src/unit_test_targets/mod.rs). | ||
| The macro expands it into both the `REGISTRY` and `OVERRIDE_REGISTRY`. | ||
|
|
||
| 3. **In the same file**, add one match arm to `build_manager_registry` so the | ||
| executor can extract the inner SM `Arc` from the bundle: | ||
|
|
||
| ```rust | ||
| StateMachines::Precompile(Precompiles::New(p)) => { | ||
| map.insert(NEW_AIR_IDS[0], erase(p.new_sm())); | ||
| } | ||
| ``` | ||
|
|
||
| That's it — the new SM is usable from Rust tests via | ||
| `prover.input::<NewSm>(input)`. No edits to `ZiskExecutorTest`, the dispatcher, | ||
| or the trait file. |
No description provided.