Skip to content

Deprecate invertible MiMC gadget family for removal and update docs - #122

Merged
satran004 merged 2 commits into
mainfrom
fix/deprecate-broken-mimc
Nov 21, 2026
Merged

satran004 merged 2 commits into
mainfrom
fix/deprecate-broken-mimc

Conversation

@satran004

Copy link
Copy Markdown
Member

Summary

  • Deprecate the entire legacy MiMC gadget family (@Deprecated(forRemoval = true)):
    • MiMC, SignalMiMC, MiMCSponge, ZkMiMC, and ZkMerkle.HashType.MIMC.
    • MiMC.hash(api, left, right) computes a 91-round keyed bijection E_right(left) ((state + rc_i + key)^7, returning state + key) without Miyaguchi–Preneel / Davies–Meyer feed-forward. Because gcd(7, r - 1) = 1 on BN254, anyone can invert all 91 rounds for any target output and chosen right in milliseconds to forge preimages, collisions, and Merkle membership proofs.
    • Corrected false Javadoc claims: MiMC.roundConstant uses SHA-256 ("mimc_round_" + round), not Keccak-256, and neither MiMC nor MiMCSponge is circomlib-compatible.
  • Remove all MiMC recommendations across documentation and site catalog:
    • Updated README.md, zeroj-circuit-lib/README.md, zeroj-circuit-annotation-api/README.md, docs/ guides, docs/adr/circuit-annotation/cardano-gadget-support-matrix.md, www/scripts/circuit-catalog.mjs, and www/src/content/docs/... pages (gadgets.md, annotations.md, circuit-dsl.md, api-cheatsheet.md, private-allowlist.mdx, ai/starter-pack.md).
    • Also fixed stale docs/getting-started.md and docs/pure-java-prover-guide.md entries where SealedBid and AnonymousVoting already use BLS12-381 Poseidon.
  • Tests:
    • Added MiMCDeprecationAndInvertibilityTest asserting @Deprecated(forRemoval = true) on all five public symbols and demonstrating exact 91-round R1CS preimage inversion and collision forgery.
    • Annotated intentional legacy MiMC test callers with @SuppressWarnings("removal") and fixed NewStdlibTest Javadoc.

Verification

  • ./gradlew :zeroj-circuit-lib:check :zeroj-circuit-annotation-processor:test :zeroj-integration-tests:compileTestJava --stacktrace — PASSED
  • ./gradlew :zeroj-circuit-lib:test --tests 'org.zeroj.circuit.lib.MiMCDeprecationAndInvertibilityTest' :zeroj-integration-tests:test --tests '*AnnotatedCircuitExamplesTest' --tests '*ParameterizedCircuitE2ETest' --stacktrace — PASSED
  • node -e "import('./www/scripts/circuit-catalog.mjs').then(m => m.buildCatalog())..." — PASSED (catalog extracts ZkMiMC with deprecation warning and note)

@satran004

Copy link
Copy Markdown
Member Author

[reviewer1] Changes requested on 1c879378cd3e02172fe54a12a375bc94d8e8ee50. The deprecation annotations cover the four gadget classes and the symbolic Merkle enum value. The legacy constraint behavior is preserved. I ran the removal-annotation check, parameterized Poseidon tests, and the annotated and parameterized circuit example suites on this SHA. All 36 selected tests passed with zero skips.

  1. Fix the replacement APIs linked from the deprecations. Merkle labels Poseidon.hash(api, left, right) as BLS12-381. ZkMerkle.HashType.MIMC directs users to HashType.POSEIDON on BLS12-381. Both select BN254. The no-parameter method references in SignalMerkle, SignalMiMC, and ZkMiMC have the same problem. Link to the overload taking PoseidonParams, show PoseidonParamsBLS12_381T3.INSTANCE, and use the explicit computeRootPoseidon or verifyPoseidon helper for symbolic Merkle trees. This is the migration advice IDEs display at the affected call sites.
  2. Explain what existing circuit owners need to replace. A dependency upgrade adds a warning but leaves every existing MiMC commitment, root, circuit, and verification key usable under the old relation. Add a short migration note to the gadget guide or amended support-matrix ADR: recompute commitments and roots from trusted source data, recompile the circuit, regenerate circuit-specific keys (including new Groth16 phase 2 where applicable), and retire acceptance under the old VK. Also update the retained NWayMerkleCircuit.HashType.MIMC example and standalone MiMCHash helper to identify them as legacy regression fixtures. The current template still describes MiMC as a supported inclusion-proof hash while suppressing its removal warning.

Copy link
Copy Markdown

Initial automated review · Aster

Hi @satran004, thanks for the PR! 🙏 This is an automatic first check by an AI reviewer. It does not replace maintainer review and may be wrong.

Reviewed commit: 1c879378cd3e02172fe54a12a375bc94d8e8ee50

Issues found:

  • zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/zk/ZkMerkle.java:24 — The recommended HashType.POSEIDON selects BN254 parameters, so following this advice on BLS12-381 fails with a field mismatch. Could we link to the explicit-parameter Merkle helpers using PoseidonParamsBLS12_381T3.INSTANCE and correct the other migration links?

Not tested: Code and tests were read only; I did not run the build, tests, or migration examples.

@satran004

Copy link
Copy Markdown
Member Author

[reviewer3] Review of head 1c879378 — CHANGES REQUESTED (one small, focused fix)

What I verified

  • Tests. Clean worktree at 1c879378:

    ./gradlew :zeroj-circuit-lib:test :zeroj-circuit-annotation-processor:test :zeroj-integration-tests:compileTestJava \
      :zeroj-integration-tests:test --tests '*AnnotatedCircuitExamplesTest' --tests '*ParameterizedCircuitE2ETest'
    

    BUILD SUCCESSFUL. zeroj-circuit-lib + processor: 1,346 tests, 0 failures. The 26 skips are the existing benchmark and heavy Ed25519/Jubjub suites. MiMCDeprecationAndInvertibilityTest 2/2, AnnotatedCircuitExamplesTest 13/13, ParameterizedCircuitE2ETest 10/10. :zeroj-circuit-lib:javadoc passes, and all new {@link}s resolve.

  • Deprecation coverage. @Deprecated(forRemoval = true) is on every public entry point: MiMC, SignalMiMC, MiMCSponge (all four overloads), ZkMiMC, and ZkMerkle.HashType.MIMC. @SuppressWarnings("removal") is applied only to internal delegation and to tests. The false Keccak-256 and circomlib claims are gone from the Javadoc.

  • Docs. README.md, the module READMEs, docs/circuit-dsl-user-guide.md and the www gadgets / circuit-dsl / annotations / cheatsheet / AI pack / private-allowlist pages all point to the explicit PoseidonParamsBLS12_381T3.INSTANCE overloads. The new Merkle example (ctx, l, r) -> Poseidon.hash(ctx, PoseidonParamsBLS12_381T3.INSTANCE, l, r) matches Merkle.HashFunction.

Blocking: the in-code migration targets point at the BN254 overloads

The source Javadoc, which is what IDEs show in the deprecation tooltip, sends users to the no-params Poseidon overloads. Those use the back-compat PoseidonParamsBN254T3.INSTANCE (see Poseidon.java:108-115, SignalPoseidon.java:25-28, ZkPoseidon.java:28). Two of these pointers also label the target "BLS12-381":

Location Current text
Merkle.java:10 "{@link Poseidon#hash(CircuitAPI, Variable, Variable)} (BLS12-381)"
MiMC.java:43 @deprecated … Use {@link Poseidon#hash(CircuitAPI, Variable, Variable)}
SignalMiMC.java:28 @deprecated … Use {@link SignalPoseidon#hash(SignalBuilder, Signal, Signal)}
zk/ZkMiMC.java:24 @deprecated … Use {@link ZkPoseidon#hash(ZkContext, ZkField, ZkField)}
SignalMerkle.java:10 example SignalMerkle.verifyProof(c, leaf, root, siblings, pathBits, SignalPoseidon::hash). The method reference binds to the no-params BN254 overload, so on a BLS12-381 circuit it fails requireField.

This contradicts the PR's own docs, which say "never use the no-params Poseidon overload … for Cardano". For a security-motivated deprecation, the migration target in the deprecation text should be right.

Please point these at the explicit-params overloads:

  • Poseidon#hash(CircuitAPI, PoseidonParams, Variable, Variable)
  • SignalPoseidon#hash(SignalBuilder, PoseidonParams, Signal, Signal)
  • ZkPoseidon#hash(ZkContext, PoseidonParams, ZkField, ZkField)

Each should be used with PoseidonParamsBLS12_381T3.INSTANCE. In the SignalMerkle example, use a lambda: (cb, l, r) -> SignalPoseidon.hash(cb, PoseidonParamsBLS12_381T3.INSTANCE, l, r).

Non-blocking (P3)

  1. www/scripts/ai-artifacts.mjs:245 (not touched by this PR) still says only that "MiMC and the no-params Poseidon overload are BN254-oriented; do not use them for Cardano". That under-states the issue now that MiMC is insecure for any use. Align it with the circuit-catalog.mjs wording.
  2. The PR description says "0 removal warnings", but CircuitAnnotationProcessorTest.java:479 (ZkMerkle.HashType.MIMC) still emits warning: [removal] MIMC in HashType has been deprecated and marked for removal. A @SuppressWarnings("removal") on that test fixes it.
  3. zeroj-integration-tests/.../dsl/common/MiMCHash.java, the off-circuit reference copy used by tests, still presents itself as a plain "MiMC-7 hash". A one-line Javadoc note ("legacy, insecure, test-only") would match the rest of the PR.

@satran004

Copy link
Copy Markdown
Member Author

Addressed all review items in commit e30e71ff:

  1. Explicit BLS12-381 Poseidon migration targets in Javadocs: Updated MiMC, SignalMiMC, MiMCSponge, ZkMiMC, ZkMerkle.HashType.MIMC, Merkle, and SignalMerkle Javadoc @link targets and examples to reference the explicit PoseidonParams overloads with PoseidonParamsBLS12_381T3.INSTANCE (and ZkMerkle.computeRootPoseidon / verifyPoseidon / isMemberPoseidon for symbolic Merkle trees) instead of the BN254 no-parameter overloads.
  2. Existing-deployment migration guidance: Added explicit migration notes to www/src/content/docs/guides/circuits/gadgets.md, docs/adr/circuit-annotation/cardano-gadget-support-matrix.md, and zeroj-circuit-lib/README.md covering recomputing commitments/Merkle roots from trusted source data with BLS12-381 Poseidon, recompiling the circuit, regenerating circuit-specific keys (including a new Groth16 phase-2 ceremony where applicable), and retiring acceptance under the old VK.
  3. Legacy test fixtures & AI artifacts: Marked NWayMerkleCircuit.HashType.MIMC and MiMCHash as @Deprecated(forRemoval = true) legacy regression fixtures; updated www/scripts/ai-artifacts.mjs (KEY_FACTS) so MiMC is explicitly described as deprecated for removal (insecure); added @SuppressWarnings("removal") on CircuitAnnotationProcessorTest.parameterizedMerkleMembershipGeneratesBuildWithCircuitParams and the legacy integration-test callers.

Verification (e30e71ff):

  • ./gradlew :zeroj-circuit-lib:javadoc :zeroj-circuit-lib:test --tests 'org.zeroj.circuit.lib.MiMCDeprecationAndInvertibilityTest' :zeroj-circuit-annotation-processor:test :zeroj-integration-tests:test --tests '*AnnotatedCircuitExamplesTest' --tests '*ParameterizedCircuitE2ETest' --rerun-tasks --stacktrace — PASSED (zero javadoc/removal warnings in modified files)
  • www/scripts/circuit-catalog.mjs (buildCatalog) and www/scripts/ai-artifacts.mjs (buildAiArtifacts) — PASSED

@satran004

Copy link
Copy Markdown
Member Author

[reviewer1] Approved on e30e71ff053c7d5738e676f54c6ef485f3dc55da. The deprecation Javadocs now direct callers to overloads that take explicit BLS12-381 Poseidon parameters, including the symbolic Merkle helpers. The migration note covers recomputing state from trusted data, regenerating circuit-specific keys, and retiring the old VK. The retained template and host-side helper now identify their legacy regression purpose.

I built the circuit-library Javadocs and reran the deprecation-annotation check, parameterized Poseidon tests, and both circuit-example suites on this SHA. All 36 selected tests passed with zero skips.

@satran004

Copy link
Copy Markdown
Member Author

[reviewer3] Re-review of head e30e71ff — APPROVED

The blocking item and all P3s from my review of 1c879378 are resolved.

  • Migration targets. Every deprecation tooltip and example in MiMC, SignalMiMC, MiMCSponge, ZkMiMC, ZkMerkle.HashType.MIMC, Merkle and SignalMerkle now names the explicit-params overloads with PoseidonParamsBLS12_381T3.INSTANCE:

    • Poseidon#hash(CircuitAPI, PoseidonParams, …)
    • PoseidonN#hash(…, PoseidonParams, Variable[])
    • SignalPoseidon#hash(SignalBuilder, PoseidonParams, …)
    • ZkPoseidon#hash(ZkContext, PoseidonParams, …)
    • ZkMerkle#{computeRoot,verify,isMember}Poseidon(…, PoseidonParams, …)

    HashType.MIMC now notes explicitly that POSEIDON selects the BN254 default. SignalMerkle uses a BLS lambda. grep finds no remaining no-params pointers in the zeroj-circuit-lib sources. The one left, ZkMerkle.java:52, is the documented BN254 implementation of HashType.POSEIDON itself.

  • The other notes. ai-artifacts.mjs now says the MiMC family is insecure. CircuitAnnotationProcessorTest no longer warns, and MiMCHash / NWayMerkleCircuit.HashType.MIMC are marked as legacy fixtures.

  • Migration section. The new "existing-deployment migration" text in gadgets.md, the support matrix and the zeroj-circuit-lib README gives the right steps: recompute roots and commitments from trusted data, recompile, regenerate keys or redo phase 2, and retire the old VK.

  • Tests. Clean worktree at e30e71ff:

    ./gradlew :zeroj-circuit-lib:javadoc :zeroj-circuit-lib:test (MiMC/Merkle/ZkGadgetAdapters/Stdlib/SignalStyle/CircuitLib) \
      :zeroj-circuit-annotation-processor:test :zeroj-integration-tests:test (AnnotatedCircuitExamples, ParameterizedCircuitE2E)
    

    BUILD SUCCESSFUL, 0 [removal] warnings in the build output. MiMCDeprecationAndInvertibilityTest 2, ZkGadgetAdaptersTest 28, processor 31, AnnotatedCircuitExamplesTest 13, ParameterizedCircuitE2ETest 10: all pass, 0 skipped. The only javadoc warning left (PoseidonHash.java:95, PoseidonN reference) predates this PR and is in an untouched file.

No further findings.

@satran004
satran004 merged commit 534c629 into main Nov 21, 2026
8 of 9 checks passed
@satran004
satran004 deleted the fix/deprecate-broken-mimc branch November 21, 2026 09:58
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.

2 participants