Skip to content

Unit tests#1149

Open
RogerTaule wants to merge 1 commit into
pre-develop-1.0.0-betafrom
feature/unit-tests-1.0.0-beta
Open

Unit tests#1149
RogerTaule wants to merge 1 commit into
pre-develop-1.0.0-betafrom
feature/unit-tests-1.0.0-beta

Conversation

@RogerTaule

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings June 25, 2026 11:07
@cla-bot cla-bot Bot added the cla-signed label Jun 25, 2026
@RogerTaule RogerTaule self-assigned this Jun 25, 2026
@RogerTaule RogerTaule added the enhancement New feature or request label Jun 25, 2026
@RogerTaule RogerTaule added this to the Release 1.0.0-beta milestone Jun 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 + fluent VerifyInput builder) 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.

Comment thread Cargo.toml
Comment thread ziskos/entrypoint/Cargo.toml
Comment thread verifier/Cargo.toml
Comment thread unit-tests/tests/hashes.rs
@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown

🔄 ZisK Cycle Tracking

Emulator cost report (ziskemu -X) comparing this PR against the base branch.

Summary

Guest Steps Δ Steps Total Cost Δ Total Cost
bigint 21,918,740 ➖ 0.00% 2,628,054,009 ➖ 0.00%
bls12_381 12,076,495 ➖ 0.00% 1,786,479,337 ➖ 0.00%
bn254 14,345,489 ➖ 0.00% 2,009,186,952 ➖ 0.00%
diagnostic 156,227 ➖ 0.00% 308,621,393 ➖ 0.00%
hashes 3,101,299 ➖ 0.00% 775,831,226 ➖ 0.00%
secp256k1 325,427 ➖ 0.00% 339,894,662 ➖ 0.00%
secp256r1 4,632,811 ➖ 0.00% 1,227,473,058 ➖ 0.00%
uint256 20,823 ➖ 0.00% 295,896,290 ➖ 0.00%

Per-Guest Breakdown

bigint
Metric Base Branch Current PR Diff Diff (%)
Total Steps 21,918,740 21,918,740 0 0.00%
Main Cost 1,490,474,320 1,490,474,320 0 0.00%
Opcodes Cost 136,685,650 136,685,675 25 0.00%
Precompiles Cost 337,634,469 337,634,469 0 0.00%
Memory Cost 369,658,265 369,658,265 0 0.00%
Variable Cost 2,334,452,704 2,334,452,729 25 0.00%
Base Cost 293,601,280 293,601,280 0 0.00%
Total Cost 2,628,053,984 2,628,054,009 25 0.00%
Frops Cost 153,670,359 153,670,359 0 0.00%
bls12_381
Metric Base Branch Current PR Diff Diff (%)
Total Steps 12,076,495 12,076,495 0 0.00%
Main Cost 821,201,660 821,201,660 0 0.00%
Opcodes Cost 24,528,463 24,528,463 0 0.00%
Precompiles Cost 354,130,234 354,130,234 0 0.00%
Memory Cost 293,017,700 293,017,700 0 0.00%
Variable Cost 1,492,878,057 1,492,878,057 0 0.00%
Base Cost 293,601,280 293,601,280 0 0.00%
Total Cost 1,786,479,337 1,786,479,337 0 0.00%
Frops Cost 3,281,392 3,281,392 0 0.00%
bn254
Metric Base Branch Current PR Diff Diff (%)
Total Steps 14,345,489 14,345,489 0 0.00%
Main Cost 975,493,252 975,493,252 0 0.00%
Opcodes Cost 15,945,328 15,945,328 0 0.00%
Precompiles Cost 383,188,849 383,188,849 0 0.00%
Memory Cost 340,958,243 340,958,243 0 0.00%
Variable Cost 1,715,585,672 1,715,585,672 0 0.00%
Base Cost 293,601,280 293,601,280 0 0.00%
Total Cost 2,009,186,952 2,009,186,952 0 0.00%
Frops Cost 3,163,395 3,163,395 0 0.00%
diagnostic
Metric Base Branch Current PR Diff Diff (%)
Total Steps 156,227 156,227 0 0.00%
Main Cost 10,623,436 10,623,436 0 0.00%
Opcodes Cost 3,258,642 3,258,642 0 0.00%
Precompiles Cost 349,417 349,417 0 0.00%
Memory Cost 788,618 788,618 0 0.00%
Variable Cost 15,020,113 15,020,113 0 0.00%
Base Cost 293,601,280 293,601,280 0 0.00%
Total Cost 308,621,393 308,621,393 0 0.00%
Frops Cost 1,986,236 1,986,236 0 0.00%
hashes
Metric Base Branch Current PR Diff Diff (%)
Total Steps 3,101,299 3,101,299 0 0.00%
Main Cost 210,888,332 210,888,332 0 0.00%
Opcodes Cost 107,702,885 107,702,885 0 0.00%
Precompiles Cost 146,463,131 146,463,131 0 0.00%
Memory Cost 17,175,598 17,175,598 0 0.00%
Variable Cost 482,229,946 482,229,946 0 0.00%
Base Cost 293,601,280 293,601,280 0 0.00%
Total Cost 775,831,226 775,831,226 0 0.00%
Frops Cost 9,851,420 9,851,420 0 0.00%
secp256k1
Metric Base Branch Current PR Diff Diff (%)
Total Steps 325,427 325,427 0 0.00%
Main Cost 22,129,036 22,129,036 0 0.00%
Opcodes Cost 4,082,616 4,082,616 0 0.00%
Precompiles Cost 14,219,244 14,219,244 0 0.00%
Memory Cost 5,862,486 5,862,486 0 0.00%
Variable Cost 46,293,382 46,293,382 0 0.00%
Base Cost 293,601,280 293,601,280 0 0.00%
Total Cost 339,894,662 339,894,662 0 0.00%
Frops Cost 3,997,675 3,997,675 0 0.00%
secp256r1
Metric Base Branch Current PR Diff Diff (%)
Total Steps 4,632,811 4,632,811 0 0.00%
Main Cost 315,031,148 315,031,148 0 0.00%
Opcodes Cost 79,204,784 79,204,784 0 0.00%
Precompiles Cost 422,156,730 422,156,730 0 0.00%
Memory Cost 117,479,116 117,479,116 0 0.00%
Variable Cost 933,871,778 933,871,778 0 0.00%
Base Cost 293,601,280 293,601,280 0 0.00%
Total Cost 1,227,473,058 1,227,473,058 0 0.00%
Frops Cost 72,520,183 72,520,183 0 0.00%
uint256
Metric Base Branch Current PR Diff Diff (%)
Total Steps 20,823 20,823 0 0.00%
Main Cost 1,415,964 1,415,964 0 0.00%
Opcodes Cost 92,935 92,935 0 0.00%
Precompiles Cost 429,971 429,971 0 0.00%
Memory Cost 356,140 356,140 0 0.00%
Variable Cost 2,295,010 2,295,010 0 0.00%
Base Cost 293,601,280 293,601,280 0 0.00%
Total Cost 295,896,290 295,896,290 0 0.00%
Frops Cost 142,292 142,292 0 0.00%

🔴 increase (regression) · 🟢 decrease (improvement) · ➖ no change. STEPS and all COSTS are deterministic functions of (ELF, input).

@RogerTaule RogerTaule force-pushed the feature/unit-tests-1.0.0-beta branch from cc6f268 to a1117f7 Compare June 25, 2026 11:48
Copilot AI review requested due to automatic review settings June 25, 2026 15:40
@RogerTaule RogerTaule force-pushed the feature/unit-tests-1.0.0-beta branch from a1117f7 to 8a079b6 Compare June 25, 2026 15:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 69 out of 72 changed files in this pull request and generated 4 comments.

Comment thread Cargo.toml
Comment on lines +136 to +145
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" }
Comment on lines +55 to 57
fields = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch = "feature/verify-constraints-info", features = [
"verify",
] }
Comment thread verifier/Cargo.toml
Comment on lines +11 to 13
proofman-verifier = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", branch = "feature/verify-constraints-info", default-features = false, features = [
"verify",
] }
Comment on lines +187 to +202
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants