Skip to content

#416 Improvement: propertybased tests for circuits fuzz witnesses aga… - #495

Open
Kappa16 wants to merge 1 commit into
ToluLabs:mainfrom
Kappa16:#416-Improvement--property-based-tests-for-circuits-fuzz-witnesses-against-constraints-FIX
Open

#416 Improvement: propertybased tests for circuits fuzz witnesses aga…#495
Kappa16 wants to merge 1 commit into
ToluLabs:mainfrom
Kappa16:#416-Improvement--property-based-tests-for-circuits-fuzz-witnesses-against-constraints-FIX

Conversation

@Kappa16

@Kappa16 Kappa16 commented Aug 31, 2026

Copy link
Copy Markdown

CLOSE #416

What does this PR do?

Adds property-based fuzzing tests for all Noir circuits to catch constraint gaps that fixed example tests miss. Introduces a Node.js fuzzing harness (circuits/scripts/fuzz_circuits.js) that generates randomized valid/invalid witnesses — computes real Poseidon2 commitments, signs with secp256k1 ECDSA, and runs nargo execute to assert pass/fail outcomes across 8 credential circuits. Adds 86 new Noir-native boundary tests (126 total, up from 40) covering threshold off-by-one, date boundaries, tampered commitments, salt mismatches, and commitment collision resistance. Integrates both nargo test and the fuzz harness into CI as a new circuit-fuzz job.

Closes #

Type of change

  • Bug fix
  • New feature / credential type
  • Refactor / cleanup
  • Docs
  • CI / tooling

Merge requirements

  • CI is greencargo test (contracts), pnpm tsc --noEmit (frontend), pnpm build (frontend), circuit tests — all green
  • Greptile confidence ≥ 4/5 — all review comments addressed, no unresolved threads
  • Circuit changes: fixtures/<type>/ artifacts updated
  • No NEXT_PUBLIC_ prefix on server-only env vars
  • No identity fields stored or logged after KYC provider call
  • prehash:false preserved on any issuer signing path touched
  • Issuer private key never referenced from client-bundled code

✅ Merge requirements

  • All CI checks pass (contracts / frontend / circuits as applicable)
  • Every Greptile review comment is addressed — no unresolved review threads
  • Greptile confidence score is 4/5 or higher

Notes for reviewers

Two-layer testing strategy:

  1. Noir-native tests (in each circuit's main.nr) — 86 new #[test] / #[test(should_fail)] cases that exercise constraint logic directly without the expensive ECDSA overhead. These run fast via nargo test and cover boundary conditions systematically: threshold exact, ±1, zero, max, date epoch, large values, commitment collision resistance, salt binding.

  2. External fuzzing harness (circuits/scripts/fuzz_circuits.js, 1,267 lines) — generates random witnesses using crypto.randomBytes, computes Poseidon2 commitments locally (same round constants as merkle_tree.js), signs with the demo issuer key via sign.js, writes Prover.toml, and runs nargo execute end-to-end. Covers pass space (valid commitment + signature + satisfied constraint) and fail space (tampered commitment, wrong salt, threshold violations). Backs up and restores Prover.toml files so the fuzz run never corrupts committed fixtures.

Key design decisions:

  • The fuzz harness computes commitments in JS rather than invoking nargo execute on the commit circuit — this reuses the Poseidon2 implementation already in merkle_tree.js and avoids a round-trip to the Noir compiler per test case.
  • --iterations N flag controls random test count (default 20); CI runs with --iterations 10 to stay within time budget.
  • --circuit NAME flag targets a single circuit for local debugging.
  • The set_membership circuit has a pre-existing test failure (test_merkle_path_produces_correct_root) on main — confirmed via git stash + nargo test on clean branch. Not introduced by this PR.

Circuits covered by fuzz harness: age_proof, income_proof, funds_proof, accreditation_proof, kyc_proof, jurisdiction_proof, range_proof, employment_proof.

Circuits covered by Noir boundary tests: all of the above + commit, commit3, aggregate_proof (11 total, 126 tests passing).

@drips-wave

drips-wave Bot commented Aug 31, 2026

Copy link
Copy Markdown

@Kappa16 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improvement: property-based tests for circuits (fuzz witnesses against constraints)

1 participant