diff --git a/README.md b/README.md
index fd9462d6..c1956e02 100644
--- a/README.md
+++ b/README.md
@@ -54,7 +54,7 @@ remaining production gates are tracked in
- **CircuitSpec Java DSL** (recommended) — define circuits as reusable Java classes with `CircuitSpec`
- **Inline lambda DSL** — quick prototyping with `CircuitBuilder.define(api -> ...)`
- **circom interop** — use externally compiled circom/snarkjs artifacts (`.r1cs`, `.zkey`, `.wtns`)
-- **Standard library** — Poseidon, MiMC, Merkle, Comparators, Binary, Mux, AliasCheck; in-circuit **Blake2b / SHA-256 / SHA-512 / HMAC-SHA512** and **Ed25519 / BIP32 / CIP-1852** key-derivation gadgets (prove Cardano key ownership without revealing the seed); symbolic `Zk*` adapters, plus operation-specific Poseidon MPF/JMT circuits in their authenticated-state modules; see the [`zeroj-circuit-lib`](zeroj-circuit-lib/README.md) gadget table and [large-state guide](docs/merkle/practical-large-state-guide.md)
+- **Standard library** — Poseidon, Merkle, Comparators, Binary, Mux, AliasCheck; in-circuit **Blake2b / SHA-256 / SHA-512 / HMAC-SHA512** and **Ed25519 / BIP32 / CIP-1852** key-derivation gadgets (prove Cardano key ownership without revealing the seed); symbolic `Zk*` adapters, plus operation-specific Poseidon MPF/JMT circuits in their authenticated-state modules; see the [`zeroj-circuit-lib`](zeroj-circuit-lib/README.md) gadget table and [large-state guide](docs/merkle/practical-large-state-guide.md)
- **Multi-backend compilation** — one Java circuit can compile to R1CS for Groth16 or to PlonK
### Generate Proofs
@@ -261,7 +261,7 @@ The **pure Java prover and verifier require no optional dependencies**.
| [`zeroj-crypto-blst`](zeroj-crypto-blst/) | **Opt-in blst prover backend** — thin bridge wiring `zeroj-blst`'s native MSM into the `zeroj-crypto` prover SPI (keeps `zeroj-crypto` pure-Java by default; pure Java matches blst at large sizes since ADR-0033/0034) |
| [`zeroj-tools`](zeroj-tools/) | Reusable operator tools and the `zeroj-ceremony` CLI — snarkjs-compatible Groth16 phase-2 contributor (`ZkeyContributor`), hash-to-G2 challenge derivation; embeddable in coordinator services and wallets |
| [`zeroj-circuit-dsl`](zeroj-circuit-dsl/) | Java Circuit DSL — define circuits with CircuitSpec, compile to R1CS/PlonK |
-| [`zeroj-circuit-lib`](zeroj-circuit-lib/) | Circuit standard library — Poseidon, MiMC, Merkle, Comparators, Binary, Mux, AliasCheck; in-circuit Blake2b / SHA-256 / SHA-512 / HMAC-SHA512 and Ed25519 / BIP32 / CIP-1852 key derivation; symbolic adapters; [per-gadget status](zeroj-circuit-lib/README.md#gadget-status) |
+| [`zeroj-circuit-lib`](zeroj-circuit-lib/) | Circuit standard library — Poseidon, Merkle, Comparators, Binary, Mux, AliasCheck; in-circuit Blake2b / SHA-256 / SHA-512 / HMAC-SHA512 and Ed25519 / BIP32 / CIP-1852 key derivation; symbolic adapters; [per-gadget status](zeroj-circuit-lib/README.md#gadget-status) |
| [`zeroj-onchain-julc`](zeroj-onchain-julc/) | Reusable Plutus V3 on-chain verifiers and libraries via Julc; Groth16 is the primary supported path, PlonK BLS12-381 validators/libraries are experimental opt-in |
#### Explicit Opt-In Product Modules
diff --git a/docs/adr/circuit-annotation/cardano-gadget-support-matrix.md b/docs/adr/circuit-annotation/cardano-gadget-support-matrix.md
index 5f594741..4b97f494 100644
--- a/docs/adr/circuit-annotation/cardano-gadget-support-matrix.md
+++ b/docs/adr/circuit-annotation/cardano-gadget-support-matrix.md
@@ -108,12 +108,12 @@ Relevant source:
| `Mux` | Conditional select and array access | Generic | Direct scalar select through `ZkBool.select` | Yes on BLS12-381 Groth16 | Add `ZkArray.select` or dynamic array access helper if needed. |
| `AliasCheck` | Canonical field representation check | Generic | Mostly covered by `ZkUInt` range checks | Yes on BLS12-381 Groth16 | Optional `ZkAliasCheck` for raw `ZkField`. |
| `Sha256`, `Sha512` | Full standard SHA-2 digests of fixed-length byte-aligned messages | Bit-oriented; supported scalar fields | `ZkSha256.hash`, `ZkSha512.hash` | BLS12-381 Groth16 building blocks; SHA-256 experimental pending external review | Bind the complete digest with constrained packing; use exact byte serialization. Official vectors, compiled-relation negatives and optional Circom assurance in ADR-0063. |
-| `MiMC` / `SignalMiMC` | MiMC-7 two-input hash | BN254 only in current circuit lib | Direct through `ZkMiMC` | No for Cardano on-chain, because the circuit requires BN254 | Use Poseidon for Cardano. Consider a separate BLS12-381 MiMC variant only if there is a concrete interop need. |
-| `MiMCSponge` | Variable-length MiMC sponge | BN254 only, because it calls `MiMC` | No direct `ZkMiMCSponge` | No for Cardano on-chain | Add symbolic wrapper only for BN254/off-chain legacy use. |
+| `MiMC` / `SignalMiMC` | Legacy MiMC-7 keyed permutation (**deprecated for removal — insecure**) | BN254 only | Deprecated (`ZkMiMC`) | **Do not use** — trivially invertible keyed bijection (no Davies-Meyer / Miyaguchi-Preneel feed-forward), not a collision-resistant hash or circomlib-compatible | Deprecated for removal (`@Deprecated(forRemoval = true)`). Use `Poseidon` with explicit `PoseidonParamsBLS12_381T3.INSTANCE`. |
+| `MiMCSponge` | Legacy MiMC-7 sponge wrapper (**deprecated for removal — insecure**) | BN254 only | None | **Do not use** — wraps broken `MiMC`, not circomlib-compatible | Deprecated for removal (`@Deprecated(forRemoval = true)`). Use `Poseidon` / `PoseidonN`. |
| `Poseidon` | Two-input Poseidon T3 hash | BN254 default; BLS12-381 supported with explicit params | Direct through `ZkPoseidon` for two inputs | Yes if `PoseidonParamsBLS12_381T3.INSTANCE` is used | Make BLS12-381 params prominent in Cardano examples. |
| `PoseidonN` | Variable-arity folded Poseidon | BN254 default; BLS12-381 supported with explicit params | Direct through `ZkPoseidonN` with explicit params | Yes if `PoseidonParamsBLS12_381T3.INSTANCE` is used | None. |
| `Merkle` / `SignalMerkle` | Fixed-depth Merkle membership | Hash-dependent | Direct through `ZkMerkle`; params-aware Poseidon helpers are available | Yes when `ZkMerkle.*Poseidon(..., PoseidonParamsBLS12_381T3.INSTANCE, ...)` is used | None. |
-| `ZkMerkle.HashType.MIMC` | Merkle with MiMC | BN254 only | Direct | No for Cardano on-chain | Mark as BN254/off-chain in docs. |
+| `ZkMerkle.HashType.MIMC` | Legacy Merkle with MiMC (**deprecated for removal — insecure**) | BN254 only | Deprecated | **Do not use** — delegates to broken invertible `MiMC` | Deprecated for removal (`@Deprecated(forRemoval = true)`). Use `ZkMerkle.*Poseidon(..., PoseidonParamsBLS12_381T3.INSTANCE, ...)`. |
| `ZkMerkle.HashType.POSEIDON` | Merkle with default Poseidon | BN254 by default today | Direct | No if using default enum path | Use params-aware `ZkMerkle.*Poseidon(...)` for Cardano. |
| `ZkMerkle` with custom hash lambda | Merkle with caller-provided hash | Depends on lambda | Direct | Yes with a BLS12-381-compatible lambda | Keep as advanced escape hatch. |
| `ZkMpf*` / `zeroj-mpf-poseidon` | CCL Poseidon MPF inclusion, two non-inclusion forms, value update, and split insertion | BLS12-381 Poseidon authenticated-state v1 only | Strict CCL verification plus canonical operation-specific witnesses/templates | Pure-Java Groth16 and Julc VM paths passed on a retained 5M root; external review, production setup, Yaci, and public-network gates remain. Not compatible with native Aiken/Blake2b MPF roots. | S9 covered the measured 5M root at 56,635 constraints and ~4.17 s prove. Physical delete/canonical collapse is deferred. See ADR-0042. |
@@ -190,18 +190,25 @@ The verifier rejects empty `IC` lists and any mismatch where
Generated fixed-count validators remain a possible future optimization if
budget-critical circuits need lower script cost.
-### MiMC Is BN254-Only in the Circuit Library
-
-The current `MiMC`, `SignalMiMC`, `ZkMiMC`, and `MiMCSponge` path is BN254-only.
-`MiMC.hash(...)` calls `api.requireField(FieldConfig.BN254)`.
-
-This is not a problem for off-chain BN254 circuits, but it is not a good default
-for Cardano. Cardano-facing examples should use BLS12-381 Poseidon instead.
-
-Existing examples that compute MiMC with a BLS12-381 prime outside the circuit
-should be treated as legacy/test code that needs migration or clarification.
-The in-circuit gadget now correctly prevents compiling that path as a
-BLS12-381 circuit.
+### MiMC Is Deprecated for Removal (Insecure Invertible Bijection)
+
+The legacy `MiMC`, `SignalMiMC`, `ZkMiMC`, `MiMCSponge`, and `ZkMerkle.HashType.MIMC`
+APIs are **deprecated for removal (`@Deprecated(forRemoval = true)`)** and must not be
+used in new or existing circuits. `MiMC.hash(...)` computes a 91-round keyed bijection
+on BN254 without Miyaguchi–Preneel / Davies–Meyer feed-forward (allowing trivial
+preimage, collision, and Merkle-proof forgery), derives round constants with SHA-256
+rather than Keccak-256, and is not circomlib-compatible.
+
+**Existing-deployment migration:** upgrading ZeroJ only emits compile-time deprecation
+warnings — existing MiMC commitments, Merkle roots, compiled circuits, and verification
+keys remain usable under the broken relation. Deployments that ever used MiMC must:
+
+1. Recompute all commitments and Merkle roots from trusted source data using BLS12-381
+ Poseidon (`PoseidonParamsBLS12_381T3.INSTANCE`).
+2. Recompile the circuit with `Poseidon` / `ZkPoseidon` / `ZkMerkle.*Poseidon(...)`.
+3. Regenerate circuit-specific proving and verifying keys (including a new Groth16
+ phase-2 ceremony where applicable).
+4. Retire acceptance under the old MiMC verification key.
### Poseidon Defaults Are BN254 for Back Compatibility
diff --git a/docs/architecture-overview.md b/docs/architecture-overview.md
index f440ca3c..e72a4417 100644
--- a/docs/architecture-overview.md
+++ b/docs/architecture-overview.md
@@ -115,7 +115,7 @@ Java circuit definition and compilation:
- `CircuitBuilder` / `CircuitAPI` -- define circuits in Java
- `SignalBuilder` -- OO Signal-style API
- Compiles to R1CS (Groth16) or PlonK gates
-- `zeroj-circuit-lib` -- Poseidon, MiMC, Merkle, comparators, binary ops
+- `zeroj-circuit-lib` -- Poseidon, Merkle, comparators, binary ops, SHA-2, BLAKE2b, Jubjub/Ed25519 gadgets
### Layer 6: Orchestration (`zeroj-backend-spi`)
`VerifierRegistry` and `VerifierOrchestrator` route verification requests to the
diff --git a/docs/circuit-annotation-user-guide.md b/docs/circuit-annotation-user-guide.md
index 3e4fee63..0b4c3b2f 100644
--- a/docs/circuit-annotation-user-guide.md
+++ b/docs/circuit-annotation-user-guide.md
@@ -71,9 +71,11 @@ ZkPoseidonN.hash(zk, PoseidonParamsBLS12_381T3.INSTANCE, owner, assetId, nonce);
ZkMerkle.isMemberPoseidon(zk, PoseidonParamsBLS12_381T3.INSTANCE, leaf, root, siblings, pathBits);
```
-Do not use no-params Poseidon or MiMC as Cardano defaults. The no-params
-Poseidon overload is retained for BN254 compatibility, and `ZkMiMC` delegates
-to the BN254-only MiMC gadget. The full gadget and curve support matrix is in
+Do not use no-params Poseidon as a Cardano default, and do not use `ZkMiMC` or
+`ZkMerkle.HashType.MIMC` in any circuit. The no-params Poseidon overload is
+retained for BN254 compatibility, while the `MiMC` gadget family is deprecated
+for removal as an insecure, invertible keyed permutation (not a hash function).
+The full gadget and curve support matrix is in
[`docs/adr/circuit-annotation/cardano-gadget-support-matrix.md`](adr/circuit-annotation/cardano-gadget-support-matrix.md).
## Authoring Rules
@@ -156,9 +158,10 @@ circuits, the rendered `nameTemplate` is a readable prefix; generated names also
append a canonical parameter suffix to avoid collisions between different
parameter sets.
-`ZkMerkle.HashType.MIMC` and `ZkMerkle.HashType.POSEIDON` remain useful for
-BN254/off-chain compatibility. Today they are not the Cardano default path:
-`MIMC` is BN254-only, and `POSEIDON` uses the no-params Poseidon overload. Use
+`ZkMerkle.HashType.MIMC` is **deprecated for removal (insecure)** because the
+underlying `MiMC` gadget is an invertible keyed bijection rather than a
+collision-resistant hash. `ZkMerkle.HashType.POSEIDON` uses the no-params
+BN254-oriented Poseidon overload. For Cardano and all new Merkle circuits, use
`ZkMerkle.computeRootPoseidon`, `isMemberPoseidon`, or `verifyPoseidon` with
explicit BLS12-381 Poseidon params.
@@ -330,11 +333,12 @@ bind them as secret `ZkUInt` inputs, using 252 bits for `kModL` and 4 bits for
variable-arity hashing. For Cardano, pass
`PoseidonParamsBLS12_381T3.INSTANCE` explicitly; there is intentionally no
no-params symbolic overload.
-- `ZkMiMC` is BN254-only because the underlying MiMC gadget is BN254-only.
- Treat MiMC-based annotated circuits as BN254/off-chain unless a separate
- BLS12-381 MiMC variant is added.
-- `ZkMerkle.HashType.MIMC` and the no-params `HashType.POSEIDON` path are not
- Cardano defaults today. Use `ZkMerkle.*Poseidon(...)` with explicit
- BLS12-381 Poseidon params for Cardano Merkle circuits.
+- `ZkMiMC` and `ZkMerkle.HashType.MIMC` are **deprecated for removal (insecure)**:
+ the underlying `MiMC` gadget is an invertible keyed bijection (not a
+ collision-resistant hash) and is scheduled for removal. Use `ZkPoseidon` /
+ `ZkMerkle.*Poseidon(...)` with explicit `PoseidonParamsBLS12_381T3.INSTANCE`.
+- The no-params `ZkMerkle.HashType.POSEIDON` path is not a Cardano default
+ today. Use `ZkMerkle.*Poseidon(...)` with explicit BLS12-381 Poseidon params
+ for Cardano Merkle circuits.
- `ZkBits` and `ZkBytes` store one constrained field element per bit or byte;
packed byte encodings are deferred.
diff --git a/docs/circuit-dsl-user-guide.md b/docs/circuit-dsl-user-guide.md
index 1304a0dd..fe0929f1 100644
--- a/docs/circuit-dsl-user-guide.md
+++ b/docs/circuit-dsl-user-guide.md
@@ -379,13 +379,14 @@ Poseidon parameters, also import
### Hash Functions
-MiMC is BN254-only in the current circuit library. For Cardano/BLS12-381
-circuits, use Poseidon with explicit BLS12-381 parameters.
+For Cardano/BLS12-381 circuits (and all new circuits), use Poseidon with explicit BLS12-381
+parameters (`PoseidonParamsBLS12_381T3.INSTANCE`).
-```java
-// MiMC-7 hash (2 inputs -> 1 output, ~364 constraints, BN254-only)
-var hash = MiMC.hash(api, api.var("left"), api.var("right"));
+> **Do not use `MiMC`, `SignalMiMC`, `MiMCSponge`, or `ZkMiMC`:** they are deprecated for removal
+> because `MiMC.hash` computes an invertible keyed bijection without feed-forward (allowing trivial
+> preimage and Merkle proof forgery) and is not circomlib-compatible.
+```java
// Poseidon hash (2 inputs -> 1 output, ~330 constraints, Cardano/BLS12-381)
var hash = Poseidon.hash(
api,
@@ -393,7 +394,7 @@ var hash = Poseidon.hash(
api.var("in0"),
api.var("in1"));
-// Variable-arity Poseidon (N inputs via left-fold)
+// Fixed-arity folded Poseidon (N inputs via left-fold)
var hash = PoseidonN.hash(
api,
PoseidonParamsBLS12_381T3.INSTANCE,
@@ -401,18 +402,12 @@ var hash = PoseidonN.hash(
api.var("b"),
api.var("c"),
api.var("d"));
-
-// MiMC Sponge (variable-length input, single or multi-output)
-var hash = MiMCSponge.hash(api, new Variable[]{api.var("in0"), api.var("in1"), api.var("in2")});
-var outputs = MiMCSponge.hashMulti(api, inputs, 2); // 2 outputs
```
Signal API equivalents:
```java
-Signal hash = SignalMiMC.hash(c, left, right);
Signal hash = SignalPoseidon.hash(c, PoseidonParamsBLS12_381T3.INSTANCE, in0, in1);
Signal hash = PoseidonN.hash(c, PoseidonParamsBLS12_381T3.INSTANCE, a, b, inputC, inputD);
-Signal hash = MiMCSponge.hash(c, new Signal[]{in0, in1, in2});
```
### Comparators
@@ -426,13 +421,12 @@ var smallest = Comparators.min(api, a, b, 8);
### Merkle Proof
```java
-// Verify a Merkle proof with any hash function
-Merkle.verifyProof(api, leaf, root, siblings, pathBits, MiMC::hash);
+// Verify a Merkle proof with BLS12-381 Poseidon
Merkle.verifyProof(api, leaf, root, siblings, pathBits,
(ctx, l, r) -> Poseidon.hash(ctx, PoseidonParamsBLS12_381T3.INSTANCE, l, r));
```
-For a depth-20 tree: 20 × 364 ≈ 7,280 constraints with MiMC, or 20 × 330 ≈ 6,600 with Poseidon.
+For a depth-20 tree: 20 × 330 ≈ 6,600 constraints with Poseidon.
### Binary Utilities
@@ -787,7 +781,7 @@ See the [Pure Java Prover Guide](pure-java-prover-guide.md) for the complete pip
4. **Prefer `select` over branching** — ZK circuits can't branch. Use `api.select(cond, a, b)` for conditional logic.
-5. **Use ZK-friendly hashes** — Poseidon (~300 constraints) and MiMC (~364 constraints) are much cheaper than SHA-256 (~25,000 constraints) inside circuits. For Cardano/BLS12-381 circuits, use Poseidon with explicit BLS12-381 parameters; MiMC is BN254-only in the current circuit library.
+5. **Use ZK-friendly hashes** — Poseidon (~330 constraints on BLS12-381) is much cheaper than SHA-256 (~25,000 constraints) inside circuits. For Cardano/BLS12-381 circuits, use Poseidon with explicit BLS12-381 parameters (`PoseidonParamsBLS12_381T3.INSTANCE`). Do not use the deprecated `MiMC` gadgets.
## Module Dependencies
@@ -797,7 +791,7 @@ implementation platform('org.zeroj:zeroj-bom-core:0.1.0')
// Circuit DSL (define and compile circuits)
implementation 'org.zeroj:zeroj-circuit-dsl'
-// Standard library (Poseidon, MiMC, Merkle, Comparators, Binary, Mux, AliasCheck)
+// Standard library (Poseidon, Merkle, Comparators, Binary, Mux, AliasCheck)
implementation 'org.zeroj:zeroj-circuit-lib'
// Pure Java prover
diff --git a/docs/getting-started.md b/docs/getting-started.md
index a1e1215b..f6824173 100644
--- a/docs/getting-started.md
+++ b/docs/getting-started.md
@@ -274,9 +274,8 @@ regression tests first — the runnable applications and tutorials live in
### Example Circuits
- **Sealed Bid Auction** -- prove bid >= reserve without revealing bid amount
-- **Anonymous Voting** -- prove vote is 0/1 with a MiMC commitment in the
- BN254/off-chain reference flow. For Cardano/BLS12-381 circuits, use Poseidon
- with explicit BLS12-381 parameters.
+- **Anonymous Voting** -- prove vote is 0/1 with a BLS12-381 Poseidon commitment
+ (`PoseidonParamsBLS12_381T3.INSTANCE`)
- **Balance Threshold** -- prove balance >= threshold without revealing exact balance
See the [integration-tests README](../zeroj-integration-tests/README.md) for what each test protects.
diff --git a/docs/pure-java-prover-guide.md b/docs/pure-java-prover-guide.md
index 1363f746..cf175121 100644
--- a/docs/pure-java-prover-guide.md
+++ b/docs/pure-java-prover-guide.md
@@ -440,8 +440,8 @@ testImplementation 'com.bloxbean.cardano:cardano-client-lib'
| Test | Circuit | What It Proves |
|------|---------|---------------|
-| `SealedBidPureJavaE2ETest` | Sealed bid auction (497 constraints) | MiMC hash + range comparison; BN254/off-chain reference unless migrated to BLS12-381 Poseidon |
-| `AnonymousVotingPureJavaE2ETest` | Anonymous voting (367 constraints) | MiMC commitment + boolean; BN254/off-chain reference unless migrated to BLS12-381 Poseidon |
+| `SealedBidPureJavaE2ETest` | Sealed bid auction | BLS12-381 Poseidon commitment + range comparison |
+| `AnonymousVotingPureJavaE2ETest` | Anonymous voting | BLS12-381 Poseidon commitment + boolean constraint |
| `BalanceThresholdPureJavaE2ETest` | Balance threshold (132 constraints) | Range comparison |
| `PureJavaProverYaciE2ETest` | Multiplier | **Full stack: prove → Yaci DevKit on-chain** |
| `Groth16BLS381ZkeyEndToEndTest` | Multiplier + Cubic | snarkjs .zkey import → Java prove → pairing verify |
diff --git a/www/scripts/ai-artifacts.mjs b/www/scripts/ai-artifacts.mjs
index df62aa2b..9f5edcd6 100644
--- a/www/scripts/ai-artifacts.mjs
+++ b/www/scripts/ai-artifacts.mjs
@@ -242,7 +242,7 @@ const KEY_FACTS = [
`Maven group and Java packages are \`org.zeroj\` (from 0.1.0-pre12). Current version: ${ZEROJ_VERSION}${ZEROJ_RELEASED ? '' : ' (not on Maven Central yet; build from source meanwhile)'}. Import the BOM \`org.zeroj:zeroj-bom-core:${ZEROJ_VERSION}\`; opt-in modules (zeroj-verifier-plonk, zeroj-bbs, zeroj-mpf-poseidon, zeroj-jmt-poseidon) need explicit versions. Releases up to 0.1.0-pre11 used \`com.bloxbean.cardano\`.`,
'Java 25+. Nothing beyond a JDK is required for the default path (no Rust, Node.js, native toolchain or external CLIs); blst acceleration and snarkjs/circom interop are optional. `zeroj-verifier-groth16` bundles a source-built libblst (FFM, no JNI) for its native verifier on Linux amd64/aarch64 and Apple-silicon macOS; `VerifierRegistry.withServiceLoader()` picks that verifier where the library is bundled and the pure-Java one elsewhere: construct `Groth16BLS12381PureJavaVerifier` explicitly for a pure-Java path everywhere.',
'Write application circuits with annotations: `@ZKCircuit`, `@Prove`, `@Public`/`@Secret`, symbolic types `ZkField`, `ZkBool`, `ZkUInt` (always with `@UInt(bits = N)`), `ZkArray`/`ZkBits`/`ZkBytes` (with `@FixedSize`). The annotation processor generates a `Circuit` companion. Never use Java `if`, `&&`, `||` on secret values — use `ZkBool.and/or/not/select`.',
- 'For Cardano circuits hash with Poseidon using explicit BLS12-381 parameters (`PoseidonParamsBLS12_381T3.INSTANCE`). MiMC and the no-params Poseidon overload are BN254-oriented; do not use them for Cardano.',
+ 'For Cardano circuits hash with Poseidon using explicit BLS12-381 parameters (`PoseidonParamsBLS12_381T3.INSTANCE`). The no-params Poseidon overload is BN254-oriented, and the entire `MiMC` gadget family (`MiMC`, `SignalMiMC`, `MiMCSponge`, `ZkMiMC`, `ZkMerkle.HashType.MIMC`) is deprecated for removal as an insecure invertible bijection — do not use it.',
'Single-party trusted setup (`PowersOfTauBLS381.generate`, `Groth16Keys.setupInMemory`) is for development and tests only and requires `-Dzeroj.allowInsecureTrustedSetup=true`. Production keys come from a multi-party ceremony (snarkjs `.zkey`, imported into ZeroJ).',
'Every proof is freshly blinded; there is no public deterministic/unblinded prove API.',
'A valid proof is not authorization. On-chain, the reusable `Groth16BLS12381Verifier` only checks the math; real validators compose `Groth16BLS12381Lib`, bind the proof to the spend and recipient using values computed from ScriptContext, prevent replay with nullifiers or state, and enforce business policy. Do not lock funds with `Groth16BLS12381TxOutRefBindingVerifier`: it reads its spend binding from the guarded UTxO\'s own datum, which no real UTxO can satisfy.',
diff --git a/www/scripts/circuit-catalog.mjs b/www/scripts/circuit-catalog.mjs
index 4b2a59dc..d3a90c66 100644
--- a/www/scripts/circuit-catalog.mjs
+++ b/www/scripts/circuit-catalog.mjs
@@ -55,10 +55,10 @@ const GROUPS = [
];
const NOTES = {
- ZkMiMC: 'BN254-only. Do not use for Cardano (BLS12-381) circuits.',
+ ZkMiMC: 'DEPRECATED FOR REMOVAL (INSECURE): invertible keyed bijection on BN254 without feed-forward. Do not use; use ZkPoseidon on BLS12-381.',
ZkPoseidon: 'For Cardano pass PoseidonParamsBLS12_381T3.INSTANCE explicitly.',
ZkPoseidonN: 'For Cardano pass PoseidonParamsBLS12_381T3.INSTANCE explicitly.',
- ZkMerkle: 'For Cardano use the *Poseidon methods with PoseidonParamsBLS12_381T3.INSTANCE; HashType.MIMC and no-params POSEIDON are BN254/off-chain paths.',
+ ZkMerkle: 'For Cardano use the *Poseidon methods with PoseidonParamsBLS12_381T3.INSTANCE; HashType.MIMC is deprecated for removal (insecure) and no-params POSEIDON is BN254.',
ZkUInt: 'Declare inputs with @UInt(bits = N); construction adds range constraints.',
};
diff --git a/www/src/content/docs/ai/starter-pack.md b/www/src/content/docs/ai/starter-pack.md
index 54f47b79..9448a81f 100644
--- a/www/src/content/docs/ai/starter-pack.md
+++ b/www/src/content/docs/ai/starter-pack.md
@@ -181,7 +181,7 @@ The annotation processor generates `Circuit` with: `build(...)`, `sch
- Poseidon **with explicit BLS12-381 parameters**: `ZkPoseidon.hash(zk, PoseidonParamsBLS12_381T3.INSTANCE, left, right)`, `ZkPoseidonN.hash(zk, PoseidonParamsBLS12_381T3.INSTANCE, x, y, z)`.
- Merkle: `ZkMerkle.isMemberPoseidon`, `verifyPoseidon`, `computeRootPoseidon` with the same params.
-- **Never** for Cardano: `ZkMiMC` (BN254-only), the no-params Poseidon overload, `ZkMerkle.HashType.MIMC` or `HashType.POSEIDON`.
+- **Never use:** `MiMC`, `SignalMiMC`, `MiMCSponge`, `ZkMiMC`, or `ZkMerkle.HashType.MIMC` (**deprecated for removal — insecure**, invertible keyed bijection). Also never use the no-params Poseidon overload or `HashType.POSEIDON` for Cardano.
- Heavier gadgets exist for real-world cryptography: `ZkSha512`, `ZkHmacSha512`, `ZkBlake2b`, `ZkCip1852` (BIP32-Ed25519 / CIP-1852 derivation), `ZkPedersen`, `ZkJubjubPoint`, `ZkEdDSAJubjub`. Bind prover-supplied Jubjub points with `ZkJubjubPoint.witnessAffine(zk, u, v)`. See [Gadget library](/guides/circuits/gadgets/).
### Commitments and encryption (new in 0.1.0-pre13, experimental)
@@ -268,7 +268,7 @@ var p = ProverToCardano.compressProof(proof); // piA (48 B), piB (96 B)
| --- | --- |
| `if (age.gte(t)) …` or `a && b` on symbolic values | `age.gte(t)`, `x.and(y)`, `cond.select(...)` |
| `ZkUInt` without `@UInt(bits = N)` | Always declare the bit width |
-| `ZkMiMC`, no-params Poseidon, BN254, `-Dzeroj.allowLegacyBn254=true` for Cardano | Poseidon with `PoseidonParamsBLS12_381T3.INSTANCE`, BLS12-381 |
+| `MiMC` / `ZkMiMC` / `MiMCSponge` (deprecated, insecure), no-params Poseidon, BN254, `-Dzeroj.allowLegacyBn254=true` for Cardano | Poseidon with `PoseidonParamsBLS12_381T3.INSTANCE`, BLS12-381 |
| Recommending PlonK because it has a universal setup | Groth16; mention PlonK only as experimental |
| `PowersOfTauBLS381.generate` / `setupInMemory` in production | Multi-party ceremony `.zkey` imported with `ZkeyPkStoreImporter` |
| Setting `zeroj.allowInsecureTrustedSetup` in production config | Only in tests, local demos and CI |
diff --git a/www/src/content/docs/guides/circuits/annotations.md b/www/src/content/docs/guides/circuits/annotations.md
index 10edf696..75ea0258 100644
--- a/www/src/content/docs/guides/circuits/annotations.md
+++ b/www/src/content/docs/guides/circuits/annotations.md
@@ -321,7 +321,9 @@ When the symbolic types can't express something, drop to `CircuitSpec` and the `
- `ZkArray` elements must be `ZkField`, `ZkBool`, `ZkUInt`, or one nested `ZkArray` of those.
- `ZkBits` and `ZkBytes` store one constrained field element per bit or byte. Packed encodings
aren't available yet, and symbolic bitwise operations on `ZkBits` are limited.
-- `ZkMiMC` and `ZkMerkle.HashType.MIMC` are BN254-only, so they aren't usable for Cardano circuits.
+- `ZkMiMC` and `ZkMerkle.HashType.MIMC` are **deprecated for removal (insecure)** — the underlying
+ `MiMC` gadget is an invertible keyed bijection rather than a collision-resistant hash. Use
+ `ZkPoseidon` / `ZkMerkle.*Poseidon(...)` with explicit `PoseidonParamsBLS12_381T3.INSTANCE`.
## Next steps
diff --git a/www/src/content/docs/guides/circuits/circuit-dsl.md b/www/src/content/docs/guides/circuits/circuit-dsl.md
index 7e45530e..afcf62e1 100644
--- a/www/src/content/docs/guides/circuits/circuit-dsl.md
+++ b/www/src/content/docs/guides/circuits/circuit-dsl.md
@@ -143,7 +143,7 @@ byte[] iden3 = R1CSSerializer.serialize(r1cs); // .r1cs file for snarkjs tooli
| `compileR1CSWithDiagnostics(curve)` | `R1CSCompiler.CompilationResult` | Same compilation plus diagnostics. Use it in build tooling to catch changes in the R1CS shape before you generate keys. |
| `compilePlonK(curve)` | `PlonKConstraintSystem` | Experimental. See [Prove with PlonK](/guides/proving/plonk/). |
-Gadgets that depend on field constants (Poseidon, MiMC) record the field they need. If you
+Gadgets that depend on field constants (such as Poseidon) record the field they need. If you
compile or compute a witness for a different curve, `CircuitBuilder` throws
`IllegalStateException` instead of producing a circuit with mismatched constants.
diff --git a/www/src/content/docs/guides/circuits/gadgets.md b/www/src/content/docs/guides/circuits/gadgets.md
index ec2c42a5..8746411d 100644
--- a/www/src/content/docs/guides/circuits/gadgets.md
+++ b/www/src/content/docs/guides/circuits/gadgets.md
@@ -54,8 +54,19 @@ permutation, so its outputs differ from a native `t = N + 1` Poseidon. `ZkPoseid
no-parameter overload at all. `PoseidonHash` is host-side code: it computes values, it doesn't
constrain anything.
-**MiMC is BN254-only.** `MiMC`, `SignalMiMC`, `ZkMiMC` and `MiMCSponge` require the BN254 field
-and refuse to compile for BLS12-381. Treat them as legacy, off-chain gadgets.
+**Do not use MiMC (`MiMC`, `SignalMiMC`, `ZkMiMC`, `MiMCSponge`) — deprecated for removal.**
+`MiMC.hash` computes an invertible keyed bijection without feed-forward on BN254 (allowing trivial
+preimage and Merkle proof forgery) and is not circomlib-compatible. Use `Poseidon` / `ZkPoseidon`
+with `PoseidonParamsBLS12_381T3.INSTANCE` instead.
+
+:::caution[Migrating an existing MiMC deployment]
+Upgrading ZeroJ adds compile-time deprecation warnings, but any existing MiMC commitments, Merkle
+roots, compiled circuits, and verification keys remain bound to the broken relation. To migrate:
+(1) recompute commitments and Merkle roots from trusted source data with BLS12-381 Poseidon
+(`PoseidonParamsBLS12_381T3.INSTANCE`), (2) recompile the circuit, (3) regenerate circuit-specific
+proving and verifying keys (including a new Groth16 phase-2 ceremony where applicable), and
+(4) retire acceptance under the old MiMC verification key.
+:::
## Merkle membership
@@ -95,8 +106,9 @@ for (int i = 0; i < siblings.size(); i++) {
}
```
-`ZkMerkle.HashType.MIMC` and the enum `HashType.POSEIDON` path are BN254-oriented conveniences.
-Avoid them for Cardano. For large, updatable state (millions of entries, inclusion and
+`ZkMerkle.HashType.MIMC` is **deprecated for removal (insecure)** because `ZkMiMC` is invertible,
+and the enum `HashType.POSEIDON` path is a BN254-oriented convenience. Avoid both for Cardano; use
+the explicit `*Poseidon(..., PoseidonParamsBLS12_381T3.INSTANCE, ...)` methods. For large, updatable state (millions of entries, inclusion and
non-inclusion, updates), see the experimental Poseidon MPF/JMT modules in
[Authenticated state](/guides/credentials/authenticated-state/).
@@ -483,7 +495,7 @@ authorization or replay rules.
| Binary decomposition, comparators, selection | Any | Ready on BLS12-381 Groth16 |
| Poseidon T3, folded Poseidon N | BN254 default; BLS12-381 with explicit params | Ready with `PoseidonParamsBLS12_381T3.INSTANCE` |
| Merkle membership | Hash-dependent | Ready with the params-aware Poseidon helpers |
-| MiMC, MiMC sponge | BN254 only | Not Cardano-ready |
+| MiMC, MiMC sponge | BN254 only | **Deprecated for removal (insecure)** — invertible keyed bijection, not a collision-resistant hash |
| Jubjub point arithmetic | BLS12-381 only | Ready for algebraic and public-data use, pending external review |
| Pedersen commitment (in-circuit, `ZkPedersen`) | BLS12-381 only | Ready, pending external review |
| Pedersen homomorphic API (`ZkPedersenCommitment`, `ZkPedersen.assertBalanced`) and vector commitments (`ZkPedersenVector`) | BLS12-381 only | Experimental |
diff --git a/www/src/content/docs/reference/api-cheatsheet.md b/www/src/content/docs/reference/api-cheatsheet.md
index 6d86d8fa..6ea29843 100644
--- a/www/src/content/docs/reference/api-cheatsheet.md
+++ b/www/src/content/docs/reference/api-cheatsheet.md
@@ -25,7 +25,8 @@ See [Annotations](/guides/circuits/annotations/) and [Circuit DSL](/guides/circu
| `PoseidonHash.hash(PoseidonParamsBLS12_381T3.INSTANCE, a, b)` (off-circuit, same hash) | `PoseidonHash` (`org.zeroj.circuit.lib.poseidon`) |
For Cardano circuits, always pass the BLS12-381 Poseidon parameters explicitly. The overloads
-without parameters and MiMC are oriented to legacy BN254 use.
+without parameters are oriented to legacy BN254 use; the `MiMC` gadget family is deprecated for
+removal as an insecure invertible bijection and must not be used.
## Compile and compute the witness
diff --git a/www/src/content/docs/tutorials/private-allowlist.mdx b/www/src/content/docs/tutorials/private-allowlist.mdx
index 31666431..bf5e646b 100644
--- a/www/src/content/docs/tutorials/private-allowlist.mdx
+++ b/www/src/content/docs/tutorials/private-allowlist.mdx
@@ -192,8 +192,8 @@ the trapdoor.
`ZkPoseidon`, `ZkMerkle.*Poseidon` and the off-circuit `PoseidonHash` all take a
`PoseidonParams` argument. For Cardano (BLS12-381) pass `PoseidonParamsBLS12_381T3.INSTANCE`
- explicitly. The no-params Poseidon overloads and MiMC are aimed at BN254 and aren't Cardano
- defaults.
+ explicitly. The no-params Poseidon overloads are aimed at legacy BN254 use, and the `MiMC`
+ gadget family is deprecated for removal (insecure).
diff --git a/zeroj-circuit-annotation-api/README.md b/zeroj-circuit-annotation-api/README.md
index c1261d24..631e91ce 100644
--- a/zeroj-circuit-annotation-api/README.md
+++ b/zeroj-circuit-annotation-api/README.md
@@ -61,9 +61,11 @@ ZkPoseidonN.hash(zk, PoseidonParamsBLS12_381T3.INSTANCE, owner, assetId, nonce);
ZkMerkle.isMemberPoseidon(zk, PoseidonParamsBLS12_381T3.INSTANCE, leaf, root, siblings, pathBits);
```
-Do not rely on no-params Poseidon or MiMC for Cardano defaults. The no-params
-Poseidon path is BN254-compatible behavior, and `ZkMiMC` delegates to the
-BN254-only MiMC gadget.
+Do not rely on no-params Poseidon for Cardano defaults, and do not use `ZkMiMC`
+or `ZkMerkle.HashType.MIMC` at all: the no-params Poseidon path is
+BN254-compatible behavior, and the entire `MiMC` gadget family is deprecated
+for removal as an insecure, invertible keyed bijection (not a collision-resistant
+hash).
Important API rules:
@@ -93,13 +95,16 @@ Known limitations:
commitments. For Cardano, pass BLS12-381 Poseidon params explicitly; the
symbolic API intentionally does not provide a no-params `ZkPoseidonN`
overload.
-- `ZkMiMC` is BN254-only because it delegates to the existing MiMC gadget. Use
- `ZkPoseidon` with explicit BLS12-381 parameters for Cardano/BLS12-381
- circuits.
-- `ZkMerkle.HashType.MIMC` and the no-params `HashType.POSEIDON` convenience
- path are BN254-oriented today. For Cardano Merkle circuits, use
- `ZkMerkle.computeRootPoseidon`, `isMemberPoseidon`, or `verifyPoseidon` with
- explicit BLS12-381 Poseidon params.
+- `ZkMiMC` and `ZkMerkle.HashType.MIMC` are **deprecated for removal (insecure)**:
+ the underlying `MiMC` gadget is a trivially invertible keyed permutation
+ (missing Davies-Meyer / Miyaguchi-Preneel feed-forward) and is not a
+ collision-resistant hash or circomlib-compatible. Use `ZkPoseidon` /
+ `ZkMerkle.*Poseidon(...)` with explicit `PoseidonParamsBLS12_381T3.INSTANCE`
+ instead.
+- The no-params `ZkMerkle.HashType.POSEIDON` convenience path is BN254-oriented
+ today. For Cardano Merkle circuits, use `ZkMerkle.computeRootPoseidon`,
+ `isMemberPoseidon`, or `verifyPoseidon` with explicit BLS12-381 Poseidon
+ params.
- Elliptic-curve composite symbolic types are available for the shipped Jubjub
use cases (`ZkJubjubPoint`, Pedersen, EdDSA-Jubjub). Add a curve-specific
symbolic wrapper before using another curve family. Their readiness is tracked
diff --git a/zeroj-circuit-annotation-processor/src/test/java/org/zeroj/circuit/annotation/processor/CircuitAnnotationProcessorTest.java b/zeroj-circuit-annotation-processor/src/test/java/org/zeroj/circuit/annotation/processor/CircuitAnnotationProcessorTest.java
index c092ac8b..76a012a3 100644
--- a/zeroj-circuit-annotation-processor/src/test/java/org/zeroj/circuit/annotation/processor/CircuitAnnotationProcessorTest.java
+++ b/zeroj-circuit-annotation-processor/src/test/java/org/zeroj/circuit/annotation/processor/CircuitAnnotationProcessorTest.java
@@ -388,6 +388,7 @@ ZkBool prove(@Public ZkBool wait) {
}
@Test
+ @SuppressWarnings("removal")
void parameterizedMerkleMembershipGeneratesBuildWithCircuitParams() throws Exception {
var compilation = compile("test.MerkleMembership", """
package test;
diff --git a/zeroj-circuit-lib/README.md b/zeroj-circuit-lib/README.md
index 09d139f1..2d9ab822 100644
--- a/zeroj-circuit-lib/README.md
+++ b/zeroj-circuit-lib/README.md
@@ -11,14 +11,14 @@ or Jubjub-style primitives.
| Area | Key Types |
|------|-----------|
-| Hashes | `Poseidon`, `PoseidonN`, optimized `FastPoseidonBls12381T3`, `MiMC`, `MiMCSponge`, `Blake2b`, `Sha256`, `Sha512`, `HmacSha512` |
+| Hashes | `Poseidon`, `PoseidonN`, optimized `FastPoseidonBls12381T3`, `Blake2b`, `Sha256`, `Sha512`, `HmacSha512` (legacy `MiMC`, `MiMCSponge` deprecated for removal — insecure) |
| Cardano key derivation | `Cip1852Derivation`, `Bip32Ed25519`, `Ed25519Point`, `Fe25519` — in-circuit root key → payment key hash |
| Merkle proofs | `Merkle`, `SignalMerkle` |
| Comparisons | `Comparators`, `SignalComparators` |
| Binary gadgets | `Binary`, `SignalBinary`, `AliasCheck` |
| Selection | `Mux` |
-| Signal helpers | `SignalPoseidon`, `SignalMiMC` |
-| Annotation helpers | `ZkPoseidon`, `ZkPoseidonN`, `ZkMiMC`, `ZkMerkle`, `ZkJubjubPoint`, `ZkPedersen`, `ZkEdDSAJubjub`, `ZkBlake2b`, `ZkSha256`, `ZkSha512`, `ZkHmacSha512`, `ZkCip1852` |
+| Signal helpers | `SignalPoseidon` (`SignalMiMC` deprecated for removal — insecure) |
+| Annotation helpers | `ZkPoseidon`, `ZkPoseidonN`, `ZkMerkle`, `ZkJubjubPoint`, `ZkPedersen`, `ZkEdDSAJubjub`, `ZkBlake2b`, `ZkSha256`, `ZkSha512`, `ZkHmacSha512`, `ZkCip1852` (`ZkMiMC` deprecated for removal — insecure) |
| Jubjub primitives | `JubjubCurve`, `PedersenCommitment`, `PedersenBytesCommitment`, `PedersenScalarCommitment`, `PedersenVectorBoundPolicy`, opening codecs, `EdDSAJubjub`, in-circuit variants |
| Poseidon parameters | `PoseidonParams*`, `PoseidonHash`, Grain LFSR generation helpers |
@@ -40,11 +40,11 @@ final proof, verification key data, and public inputs.
| Binary decomposition | `Binary`, `SignalBinary`, `AliasCheck` | Partly via `ZkUInt`, `ZkBits`, `ZkBool` | Generic | Ready on BLS12-381 Groth16 | `AliasCheck` remains a lower-level helper for canonical field representation checks. |
| Comparators and ranges | `Comparators`, `SignalComparators` | Mostly through `ZkUInt` | Generic | Ready on BLS12-381 Groth16 | Optional symbolic `min`/`max` helpers can be added later if needed. |
| Selection / mux | `Mux` | `ZkBool.select(...)` | Generic for scalar values | Ready on BLS12-381 Groth16 | Dynamic array access remains a lower-level `Mux.arrayAccess(...)` pattern (bounds-constrained `0 <= index < arr.length`, rejects empty arrays; use `CircuitAPI.arrayAccessOrZero` only for independently bounded / masked padding rows per ADR-0065). `ZkJubjubPoint.select(...)` inherits the Jubjub-row status below, not this one. |
-| MiMC | `MiMC`, `SignalMiMC` | `ZkMiMC` | BN254 only | Not Cardano-ready | `MiMC` and `SignalMiMC` call `requireField(FieldConfig.BN254)`. Use Poseidon for Cardano circuits. |
-| MiMC sponge | `MiMCSponge` | No direct `ZkMiMCSponge` | BN254 only, because it uses MiMC | Not Cardano-ready | Useful for BN254/off-chain legacy circuits only. |
+| MiMC | `MiMC`, `SignalMiMC` | `ZkMiMC` | BN254 only | **Deprecated for removal (INSECURE)** | Computes an invertible keyed bijection without feed-forward; preimages and Merkle proofs are trivially forgeable. Not circomlib-compatible. Use `Poseidon` on BLS12-381. |
+| MiMC sponge | `MiMCSponge` | No direct `ZkMiMCSponge` | BN254 only | **Deprecated for removal (INSECURE)** | Inherits the broken `MiMC` construction and is not circomlib-compatible. Do not use. |
| Poseidon T3 | `Poseidon`, `SignalPoseidon` | `ZkPoseidon` | BN254 default; BLS12-381 with explicit params | Ready when using `PoseidonParamsBLS12_381T3.INSTANCE` | No-params overloads are BN254 for backward compatibility. |
| Folded Poseidon N | `PoseidonN` | `ZkPoseidonN` | BN254 default in DSL overloads; symbolic API requires explicit params | Ready when using `PoseidonParamsBLS12_381T3.INSTANCE` | Folded two-input Poseidon, not a separate variable-width Poseidon permutation. |
-| Merkle membership | `Merkle`, `SignalMerkle` | `ZkMerkle` | Hash-dependent | Ready with params-aware BLS12-381 Poseidon helpers | Use `ZkMerkle.*Poseidon(..., PoseidonParamsBLS12_381T3.INSTANCE, ...)` for Cardano. `HashType.MIMC` and default `HashType.POSEIDON` are BN254-oriented convenience paths. |
+| Merkle membership | `Merkle`, `SignalMerkle` | `ZkMerkle` | Hash-dependent | Ready with params-aware BLS12-381 Poseidon helpers | Use `ZkMerkle.*Poseidon(..., PoseidonParamsBLS12_381T3.INSTANCE, ...)` for Cardano. `HashType.MIMC` is **deprecated for removal (insecure)**; default `HashType.POSEIDON` is BN254-oriented. |
| Poseidon MPF/JMT authenticated state | Operation APIs live in `zeroj-mpf-poseidon` and `zeroj-jmt-poseidon` | Named `ZkMpf*` / `ZkJmt*` operation classes in those modules | BLS12-381 Poseidon profile only | Experimental; pure-Java Groth16 and Julc paths locally benchmarked at 5M entries | Kept outside the generic circuit library to preserve host/profile boundaries. Inclusion, two non-inclusion forms, update, and split insert primitives are implemented; see ADR-0042. Not compatible with native Aiken/Blake2b roots. |
| Jubjub point arithmetic | `InCircuitJubjub`, `JubjubPoint` | `ZkJubjubPoint` | BLS12-381 scalar field only | Ready for algebraic/public-data use on BLS12-381 Groth16, pending external review (ADR-0037/0038) | Generic off-circuit secret-scalar use remains offline/isolated because `BigInteger` arithmetic is variable-time. Bind every prover-supplied in-circuit point with `witnessAffine(...)` (curve equation, `Z = 1`, `T = u·v`; 5 constraints) or `assertWellFormed(...)` for projective input (13 constraints, idempotent). The raw `Point` constructor is unchecked and documented as gadget-internal. Neither binder establishes subgroup membership. `ZkJubjubPoint.fromTrustedAffine` is deprecated and delegates to `witnessAffine`. |
| Pedersen commitment (in-circuit) | `InCircuitPedersen` | `ZkPedersen` | BLS12-381 scalar field only | Ready on BLS12-381 Groth16, pending external review | Profile spec: [`pedersen-jubjub-v1`](../docs/specs/pedersen-jubjub-v1.md). The blinding is always 252 bits and may not be a public input or constant (ADR-0051 D2); only the value has a caller-chosen width. 3,020 constraints for two 252-bit vectors in the gadget alone; the complete `ZkPedersen` commitment with public `(u, v)` costs 2,410 (64-bit value) / 4,042 (252-bit value). `InCircuitPedersen` proves the represented residues but does not establish integer `< l`; `ZkPedersen` adds that canonicality check. |
@@ -241,13 +241,20 @@ See [ADR-0063](../docs/adr/0063-sha256-gadget-and-sha2-assurance.md), the
Curve and parameter guidance:
-- **MiMC** — `ZkMiMC` is guarded as BN254-only. Use Poseidon when targeting BLS12-381.
+- **MiMC (deprecated for removal — insecure)** — `MiMC`, `SignalMiMC`, `MiMCSponge`,
+ `ZkMiMC`, and `ZkMerkle.HashType.MIMC` are deprecated for removal because `MiMC.hash`
+ computes an invertible keyed bijection without feed-forward (not a collision-resistant
+ hash). Do not use; use Poseidon with explicit `PoseidonParamsBLS12_381T3.INSTANCE`.
+ *Migrating existing MiMC deployments:* upgrading only adds compile-time deprecation
+ warnings; recompute commitments and Merkle roots from trusted source data, recompile
+ the circuit with BLS12-381 Poseidon, regenerate circuit-specific keys (including a new
+ Groth16 phase-2 ceremony where applicable), and retire acceptance under the old VK.
- **Poseidon** — `ZkPoseidonN` requires explicit Poseidon params and is the
symbolic path for folded multi-input commitments. The no-params Poseidon
helpers are BN254-oriented for backward compatibility.
-- **Merkle** — `ZkMerkle.HashType.MIMC` and the no-params `HashType.POSEIDON`
- paths are BN254/off-chain conveniences. For Cardano Merkle circuits, use
- `ZkMerkle.computeRootPoseidon`, `isMemberPoseidon`, or `verifyPoseidon` with
+- **Merkle** — `ZkMerkle.HashType.MIMC` is **deprecated for removal (insecure)**, and the
+ no-params `HashType.POSEIDON` path is a BN254/off-chain convenience. For Cardano Merkle
+ circuits, use `ZkMerkle.computeRootPoseidon`, `isMemberPoseidon`, or `verifyPoseidon` with
explicit BLS12-381 Poseidon params.
- **Jubjub / Pedersen / EdDSA-Jubjub** — hardened by
[ADR-0037](../docs/adr/0037-jubjub-soundness-and-hardening.md); the normative scheme is
diff --git a/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/Merkle.java b/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/Merkle.java
index 8c2dc78e..85dc5986 100644
--- a/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/Merkle.java
+++ b/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/Merkle.java
@@ -2,11 +2,15 @@
import org.zeroj.circuit.CircuitAPI;
import org.zeroj.circuit.Variable;
+import org.zeroj.circuit.lib.poseidon.PoseidonParams;
+import org.zeroj.circuit.lib.poseidon.PoseidonParamsBLS12_381T3;
/**
* Merkle tree proof verification circuit.
*
- * Parameterized by hash function — works with any 2-to-1 hash (Poseidon, MiMC, etc.).
+ * Parameterized by hash function — use a cryptographically sound 2-to-1 hash such as
+ * {@link Poseidon#hash(CircuitAPI, PoseidonParams, Variable, Variable)} with
+ * {@link PoseidonParamsBLS12_381T3#INSTANCE} on BLS12-381.
*/
public final class Merkle {
diff --git a/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/MiMC.java b/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/MiMC.java
index 99406b1d..57e7ece6 100644
--- a/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/MiMC.java
+++ b/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/MiMC.java
@@ -3,6 +3,8 @@
import org.zeroj.circuit.CircuitAPI;
import org.zeroj.circuit.FieldConfig;
import org.zeroj.circuit.Variable;
+import org.zeroj.circuit.lib.poseidon.PoseidonParams;
+import org.zeroj.circuit.lib.poseidon.PoseidonParamsBLS12_381T3;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
@@ -10,12 +12,25 @@
import java.security.NoSuchAlgorithmException;
/**
- * MiMC hash function circuit (MiMC-7 variant).
+ * DEPRECATED FOR REMOVAL — INSECURE / INVERTIBLE — DO NOT USE.
*
- * MiMC uses x^7 S-box with 91 rounds for BN254.
- * Each round: state = (state + round_constant + key)^7.
- * Approximately 364 multiplication constraints for one hash.
+ * {@link #hash(CircuitAPI, Variable, Variable)} computes a keyed bijection {@code E_right(left)}
+ * (91 rounds of {@code (state + rc_i + key)^7}, returning {@code state + key}) with no
+ * Miyaguchi–Preneel feed-forward. Given any target output and chosen {@code right}, an attacker
+ * can invert all 91 rounds in milliseconds to compute a matching {@code left}, making preimages
+ * and Merkle membership proofs trivially forgeable. Round constants are derived with SHA-256
+ * ({@code "mimc_round_" + round}), not Keccak-256, and this gadget is not compatible with
+ * circomlib.
+ *
+ * Use {@link Poseidon#hash(CircuitAPI, PoseidonParams, Variable, Variable)} with
+ * {@link PoseidonParamsBLS12_381T3#INSTANCE} on BLS12-381 instead.
+ *
+ * @deprecated Scheduled for removal because this construction is an invertible keyed bijection
+ * rather than a one-way hash function. Use
+ * {@link Poseidon#hash(CircuitAPI, PoseidonParams, Variable, Variable)} with
+ * {@link PoseidonParamsBLS12_381T3#INSTANCE} instead.
*/
+@Deprecated(forRemoval = true)
public final class MiMC {
private MiMC() {}
@@ -23,13 +38,18 @@ private MiMC() {}
private static final int NUM_ROUNDS = 91;
/**
- * MiMC hash of two field elements using MiMC-7 Feistel.
+ * INSECURE: Computes an invertible keyed bijection {@code E_right(left)} on BN254
+ * without feed-forward. Do not use for commitments, preimage proofs, or Merkle trees.
*
- * @param api circuit API
+ * @param api circuit API (BN254 only)
* @param left first input
* @param right second input (used as key)
- * @return hash output
+ * @return bijection output (trivially invertible in {@code left})
+ * @deprecated Scheduled for removal. Use
+ * {@link Poseidon#hash(CircuitAPI, PoseidonParams, Variable, Variable)} with
+ * {@link PoseidonParamsBLS12_381T3#INSTANCE} instead.
*/
+ @Deprecated(forRemoval = true)
public static Variable hash(CircuitAPI api, Variable left, Variable right) {
api.requireField(FieldConfig.BN254);
@@ -55,7 +75,8 @@ public static Variable hash(CircuitAPI api, Variable left, Variable right) {
}
/**
- * MiMC round constants — keccak256 hash of sequential strings.
+ * MiMC round constants — SHA-256 digest of {@code "mimc_round_" + round} (not Keccak-256, not
+ * circomlib-compatible).
*/
static BigInteger roundConstant(int round) {
if (round == 0) return BigInteger.ZERO; // first round constant is 0
diff --git a/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/MiMCSponge.java b/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/MiMCSponge.java
index 04dc0d1e..710457c7 100644
--- a/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/MiMCSponge.java
+++ b/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/MiMCSponge.java
@@ -4,49 +4,51 @@
import org.zeroj.circuit.Signal;
import org.zeroj.circuit.SignalBuilder;
import org.zeroj.circuit.Variable;
-
-import java.math.BigInteger;
+import org.zeroj.circuit.lib.poseidon.PoseidonParams;
+import org.zeroj.circuit.lib.poseidon.PoseidonParamsBLS12_381T3;
/**
- * MiMC Sponge construction — variable-length input hashing using MiMC-7 as the permutation.
- *
- * The sponge absorbs an arbitrary number of field elements and squeezes one or more
- * output elements. Uses a rate of 1 and capacity of 1 (state width = 2).
+ * DEPRECATED FOR REMOVAL — INSECURE — DO NOT USE.
*
- * Algorithm (matching iden3/circomlib MiMCSponge):
- *
- * - Initialize state: [0, 0]
- * - Absorb phase: for each input, state[0] += input, then permute via MiMC
- * - Squeeze phase: output state[0], permute, repeat for nOutputs
- *
+ * This gadget delegates to {@link MiMC#hash}, which computes a broken, non-standard BN254
+ * permutation with SHA-256 round constants rather than circomlib's Feistel/Keccak-256 MiMCSponge.
+ * It is NOT compatible with {@code iden3/circomlib} {@code MiMCSponge} and should not be
+ * used for any cryptographic purpose.
*
- * Constraint cost: ~364 per absorption (one MiMC-7 invocation per input element).
+ * Use {@link Poseidon#hash(CircuitAPI, PoseidonParams, Variable, Variable)} (or
+ * {@link PoseidonN#hash(CircuitAPI, PoseidonParams, Variable[])} for fixed-arity inputs) with
+ * {@link PoseidonParamsBLS12_381T3#INSTANCE} on BLS12-381 instead.
*
- * Circom equivalent: {@code MiMCSponge(nInputs, nRounds, nOutputs)} from circomlib.
+ * @deprecated Scheduled for removal. Inherits the broken {@link MiMC} construction and is not
+ * circomlib-compatible. Use
+ * {@link Poseidon#hash(CircuitAPI, PoseidonParams, Variable, Variable)} or
+ * {@link PoseidonN#hash(CircuitAPI, PoseidonParams, Variable[])} with
+ * {@link PoseidonParamsBLS12_381T3#INSTANCE} instead.
*/
+@Deprecated(forRemoval = true)
+@SuppressWarnings("removal")
public final class MiMCSponge {
private MiMCSponge() {}
/**
- * Hash variable-length input to a single output.
- *
- * @param api circuit API
- * @param inputs array of field elements to hash (length >= 1)
- * @return single hash output
+ * @deprecated Scheduled for removal. Use
+ * {@link Poseidon#hash(CircuitAPI, PoseidonParams, Variable, Variable)} or
+ * {@link PoseidonN#hash(CircuitAPI, PoseidonParams, Variable[])} with
+ * {@link PoseidonParamsBLS12_381T3#INSTANCE} instead.
*/
+ @Deprecated(forRemoval = true)
public static Variable hash(CircuitAPI api, Variable[] inputs) {
return hashMulti(api, inputs, 1)[0];
}
/**
- * Hash variable-length input with multiple squeeze outputs.
- *
- * @param api circuit API
- * @param inputs array of field elements to absorb (length >= 1)
- * @param nOutputs number of output elements to squeeze (>= 1)
- * @return array of output field elements
+ * @deprecated Scheduled for removal. Use
+ * {@link Poseidon#hash(CircuitAPI, PoseidonParams, Variable, Variable)} or
+ * {@link PoseidonN#hash(CircuitAPI, PoseidonParams, Variable[])} with
+ * {@link PoseidonParamsBLS12_381T3#INSTANCE} instead.
*/
+ @Deprecated(forRemoval = true)
public static Variable[] hashMulti(CircuitAPI api, Variable[] inputs, int nOutputs) {
if (inputs.length == 0) throw new IllegalArgumentException("inputs must not be empty");
if (nOutputs < 1) throw new IllegalArgumentException("nOutputs must be >= 1");
@@ -55,18 +57,16 @@ public static Variable[] hashMulti(CircuitAPI api, Variable[] inputs, int nOutpu
Variable left = api.constant(0);
Variable right = api.constant(0);
- // Absorb phase: add input into rate (left), then Feistel permute
+ // Absorb phase: add input into rate (left), then apply deprecated MiMC round function
for (Variable input : inputs) {
left = api.add(left, input);
- // Feistel permutation: left' = MiMC(left, right) + right, right' = left (pre-MiMC)
- // This matches circomlib MiMCSponge Feistel construction
Variable oldLeft = left;
Variable mimc = MiMC.hash(api, left, right);
left = api.add(mimc, right);
right = oldLeft;
}
- // Squeeze phase: output left, then Feistel permute for additional outputs
+ // Squeeze phase: output left, then permute for additional outputs
Variable[] outputs = new Variable[nOutputs];
outputs[0] = left;
for (int i = 1; i < nOutputs; i++) {
@@ -82,12 +82,24 @@ public static Variable[] hashMulti(CircuitAPI api, Variable[] inputs, int nOutpu
// --- Signal API wrappers ---
+ /**
+ * @deprecated Scheduled for removal. Use
+ * {@link SignalPoseidon#hash(SignalBuilder, PoseidonParams, Signal, Signal)} with
+ * {@link PoseidonParamsBLS12_381T3#INSTANCE} instead.
+ */
+ @Deprecated(forRemoval = true)
public static Signal hash(SignalBuilder c, Signal[] inputs) {
Variable[] vars = new Variable[inputs.length];
for (int i = 0; i < inputs.length; i++) vars[i] = inputs[i].variable();
return c.wrap(hash(c.api(), vars));
}
+ /**
+ * @deprecated Scheduled for removal. Use
+ * {@link SignalPoseidon#hash(SignalBuilder, PoseidonParams, Signal, Signal)} with
+ * {@link PoseidonParamsBLS12_381T3#INSTANCE} instead.
+ */
+ @Deprecated(forRemoval = true)
public static Signal[] hashMulti(SignalBuilder c, Signal[] inputs, int nOutputs) {
Variable[] vars = new Variable[inputs.length];
for (int i = 0; i < inputs.length; i++) vars[i] = inputs[i].variable();
diff --git a/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/SignalMerkle.java b/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/SignalMerkle.java
index 5d329532..35ffec4d 100644
--- a/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/SignalMerkle.java
+++ b/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/SignalMerkle.java
@@ -7,7 +7,8 @@
* Merkle proof verification using the Signal API.
*
* {@code
- * SignalMerkle.verifyProof(c, leaf, root, siblings, pathBits, SignalMiMC::hash);
+ * SignalMerkle.verifyProof(c, leaf, root, siblings, pathBits,
+ * (cb, l, r) -> SignalPoseidon.hash(cb, PoseidonParamsBLS12_381T3.INSTANCE, l, r));
* }
*/
public final class SignalMerkle {
diff --git a/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/SignalMiMC.java b/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/SignalMiMC.java
index d00c8f92..c7e615a8 100644
--- a/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/SignalMiMC.java
+++ b/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/SignalMiMC.java
@@ -1,16 +1,26 @@
package org.zeroj.circuit.lib;
+import org.zeroj.circuit.FieldConfig;
import org.zeroj.circuit.Signal;
import org.zeroj.circuit.SignalBuilder;
-import org.zeroj.circuit.FieldConfig;
+import org.zeroj.circuit.lib.poseidon.PoseidonParams;
+import org.zeroj.circuit.lib.poseidon.PoseidonParamsBLS12_381T3;
/**
- * MiMC hash using the Signal API.
+ * DEPRECATED FOR REMOVAL — INSECURE / INVERTIBLE — DO NOT USE.
+ *
+ * Signal API copy of {@link MiMC}: computes an invertible keyed bijection {@code E_right(left)}
+ * without feed-forward on BN254. Preimages and Merkle membership proofs are trivially forgeable.
+ * Use {@link SignalPoseidon#hash(SignalBuilder, PoseidonParams, Signal, Signal)} with
+ * {@link PoseidonParamsBLS12_381T3#INSTANCE} on BLS12-381 instead.
*
- * {@code
- * Signal hash = SignalMiMC.hash(c, left, right);
- * }
+ * @deprecated Scheduled for removal because the underlying permutation omits feed-forward and is
+ * trivially invertible. Use
+ * {@link SignalPoseidon#hash(SignalBuilder, PoseidonParams, Signal, Signal)} with
+ * {@link PoseidonParamsBLS12_381T3#INSTANCE} instead.
*/
+@Deprecated(forRemoval = true)
+@SuppressWarnings("removal")
public final class SignalMiMC {
private SignalMiMC() {}
@@ -18,8 +28,13 @@ private SignalMiMC() {}
private static final int NUM_ROUNDS = 91;
/**
- * MiMC-7 hash of two signals.
+ * INSECURE: Invertible MiMC-7 keyed bijection on BN254. Do not use.
+ *
+ * @deprecated Scheduled for removal. Use
+ * {@link SignalPoseidon#hash(SignalBuilder, PoseidonParams, Signal, Signal)} with
+ * {@link PoseidonParamsBLS12_381T3#INSTANCE} instead.
*/
+ @Deprecated(forRemoval = true)
public static Signal hash(SignalBuilder c, Signal left, Signal right) {
c.api().requireField(FieldConfig.BN254);
diff --git a/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/zk/ZkMerkle.java b/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/zk/ZkMerkle.java
index 71e9ef63..ac059e58 100644
--- a/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/zk/ZkMerkle.java
+++ b/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/zk/ZkMerkle.java
@@ -7,6 +7,7 @@
import org.zeroj.circuit.Signal;
import org.zeroj.circuit.lib.SignalMerkle;
import org.zeroj.circuit.lib.poseidon.PoseidonParams;
+import org.zeroj.circuit.lib.poseidon.PoseidonParamsBLS12_381T3;
import java.util.Objects;
@@ -18,6 +19,17 @@ public final class ZkMerkle {
private ZkMerkle() {}
public enum HashType {
+ /**
+ * @deprecated Scheduled for removal — {@link ZkMiMC} is an invertible keyed bijection on
+ * BN254, making Merkle membership proofs trivially forgeable. For BLS12-381 /
+ * Cardano circuits, use
+ * {@link ZkMerkle#computeRootPoseidon(ZkContext, PoseidonParams, ZkField, ZkArray, ZkArray)},
+ * {@link ZkMerkle#verifyPoseidon(ZkContext, PoseidonParams, ZkField, ZkField, ZkArray, ZkArray)},
+ * or {@link ZkMerkle#isMemberPoseidon(ZkContext, PoseidonParams, ZkField, ZkField, ZkArray, ZkArray)}
+ * with {@link PoseidonParamsBLS12_381T3#INSTANCE} (note that {@link #POSEIDON}
+ * selects the BN254 default overload).
+ */
+ @Deprecated(forRemoval = true)
MIMC,
POSEIDON
}
@@ -27,6 +39,7 @@ public interface HashFn {
ZkField hash(ZkContext zk, ZkField left, ZkField right);
}
+ @SuppressWarnings("removal")
public static ZkField computeRoot(
ZkContext zk,
ZkField leaf,
diff --git a/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/zk/ZkMiMC.java b/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/zk/ZkMiMC.java
index 2f9b446c..8f25168e 100644
--- a/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/zk/ZkMiMC.java
+++ b/zeroj-circuit-lib/src/main/java/org/zeroj/circuit/lib/zk/ZkMiMC.java
@@ -3,16 +3,35 @@
import org.zeroj.circuit.annotation.ZkContext;
import org.zeroj.circuit.annotation.ZkField;
import org.zeroj.circuit.lib.SignalMiMC;
+import org.zeroj.circuit.lib.poseidon.PoseidonParams;
+import org.zeroj.circuit.lib.poseidon.PoseidonParamsBLS12_381T3;
import java.util.Objects;
/**
- * Symbolic MiMC adapter for annotation-based circuits.
+ * DEPRECATED FOR REMOVAL — INSECURE / INVERTIBLE — DO NOT USE.
+ *
+ * Delegates to {@link SignalMiMC#hash}, which computes an invertible keyed bijection without
+ * feed-forward on BN254. Preimages and Merkle membership proofs are trivially forgeable.
+ * Use {@link ZkPoseidon#hash(ZkContext, PoseidonParams, ZkField, ZkField)} with
+ * {@link PoseidonParamsBLS12_381T3#INSTANCE} on BLS12-381 instead.
+ *
+ * @deprecated Scheduled for removal. Use
+ * {@link ZkPoseidon#hash(ZkContext, PoseidonParams, ZkField, ZkField)} with
+ * {@link PoseidonParamsBLS12_381T3#INSTANCE} instead.
*/
+@Deprecated(forRemoval = true)
+@SuppressWarnings("removal")
public final class ZkMiMC {
private ZkMiMC() {}
+ /**
+ * @deprecated Scheduled for removal. Use
+ * {@link ZkPoseidon#hash(ZkContext, PoseidonParams, ZkField, ZkField)} with
+ * {@link PoseidonParamsBLS12_381T3#INSTANCE} instead.
+ */
+ @Deprecated(forRemoval = true)
public static ZkField hash(ZkContext zk, ZkField left, ZkField right) {
Objects.requireNonNull(zk, "zk");
Objects.requireNonNull(left, "left");
diff --git a/zeroj-circuit-lib/src/test/java/org/zeroj/circuit/lib/CircuitLibTest.java b/zeroj-circuit-lib/src/test/java/org/zeroj/circuit/lib/CircuitLibTest.java
index 13a37806..42662123 100644
--- a/zeroj-circuit-lib/src/test/java/org/zeroj/circuit/lib/CircuitLibTest.java
+++ b/zeroj-circuit-lib/src/test/java/org/zeroj/circuit/lib/CircuitLibTest.java
@@ -14,6 +14,7 @@
/**
* Tests for the circuit standard library components.
*/
+@SuppressWarnings("removal")
class CircuitLibTest {
// --- Comparators ---
diff --git a/zeroj-circuit-lib/src/test/java/org/zeroj/circuit/lib/MiMCDeprecationAndInvertibilityTest.java b/zeroj-circuit-lib/src/test/java/org/zeroj/circuit/lib/MiMCDeprecationAndInvertibilityTest.java
new file mode 100644
index 00000000..cd99d4d9
--- /dev/null
+++ b/zeroj-circuit-lib/src/test/java/org/zeroj/circuit/lib/MiMCDeprecationAndInvertibilityTest.java
@@ -0,0 +1,120 @@
+package org.zeroj.circuit.lib;
+
+import org.junit.jupiter.api.Test;
+import org.zeroj.api.CurveId;
+import org.zeroj.api.R1CSConstraint;
+import org.zeroj.circuit.CircuitBuilder;
+import org.zeroj.circuit.FieldConfig;
+import org.zeroj.circuit.lib.zk.ZkMerkle;
+import org.zeroj.circuit.lib.zk.ZkMiMC;
+import org.zeroj.circuit.r1cs.R1CSConstraintSystem;
+
+import java.lang.reflect.Field;
+import java.math.BigInteger;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Verifies that the entire legacy MiMC gadget family is marked
+ * {@code @Deprecated(forRemoval = true)} and documents the exact algebraic
+ * invertibility / collision-forgery property that motivates removal.
+ */
+@SuppressWarnings("removal")
+class MiMCDeprecationAndInvertibilityTest {
+
+ private static final BigInteger BN254_FR = FieldConfig.BN254.prime();
+ private static final BigInteger INV_SEVEN =
+ BigInteger.valueOf(7).modInverse(BN254_FR.subtract(BigInteger.ONE));
+
+ @Test
+ void allLegacyMiMCSymbolsAreDeprecatedForRemoval() throws Exception {
+ assertDeprecatedForRemoval(MiMC.class);
+ assertDeprecatedForRemoval(SignalMiMC.class);
+ assertDeprecatedForRemoval(MiMCSponge.class);
+ assertDeprecatedForRemoval(ZkMiMC.class);
+
+ Field mimcEnum = ZkMerkle.HashType.class.getField("MIMC");
+ Deprecated dep = mimcEnum.getAnnotation(Deprecated.class);
+ assertNotNull(dep, "ZkMerkle.HashType.MIMC must be @Deprecated");
+ assertTrue(dep.forRemoval(), "ZkMerkle.HashType.MIMC must have forRemoval = true");
+ }
+
+ @Test
+ void mimcHashIsTriviallyInvertibleAndCollisionForgeableInR1cs() {
+ var circuit = CircuitBuilder.create("mimc-invertibility-proof")
+ .publicVar("out")
+ .secretVar("left")
+ .secretVar("right")
+ .define(api -> {
+ var h = MiMC.hash(api, api.var("left"), api.var("right"));
+ api.assertEqual(h, api.var("out"));
+ });
+
+ var r1cs = circuit.compileR1CS(CurveId.BN254);
+
+ BigInteger target = new BigInteger("123456789012345678901234567890");
+ BigInteger right1 = BigInteger.valueOf(17);
+ BigInteger right2 = BigInteger.valueOf(42);
+
+ BigInteger forgedLeft1 = invertMiMC(target, right1);
+ BigInteger forgedLeft2 = invertMiMC(target, right2);
+
+ assertNotEquals(forgedLeft1, forgedLeft2,
+ "Distinct keys must yield distinct forged preimages for the same target");
+
+ BigInteger[] w1 = circuit.calculateWitness(Map.of(
+ "out", List.of(target),
+ "left", List.of(forgedLeft1),
+ "right", List.of(right1)
+ ), CurveId.BN254);
+ BigInteger[] w2 = circuit.calculateWitness(Map.of(
+ "out", List.of(target),
+ "left", List.of(forgedLeft2),
+ "right", List.of(right2)
+ ), CurveId.BN254);
+
+ assertAllConstraintsSatisfied(r1cs, w1);
+ assertAllConstraintsSatisfied(r1cs, w2);
+ assertEquals(target, w1[1]);
+ assertEquals(target, w2[1]);
+ }
+
+ private static void assertAllConstraintsSatisfied(R1CSConstraintSystem r1cs, BigInteger[] w) {
+ BigInteger p = r1cs.prime();
+ for (R1CSConstraint c : r1cs.constraints()) {
+ BigInteger a = dot(c.a(), w, p);
+ BigInteger b = dot(c.b(), w, p);
+ BigInteger rhs = dot(c.c(), w, p);
+ assertEquals(rhs, a.multiply(b).mod(p), "Every R1CS constraint must hold");
+ }
+ }
+
+ private static BigInteger dot(Map vec, BigInteger[] w, BigInteger p) {
+ BigInteger sum = BigInteger.ZERO;
+ for (Map.Entry e : vec.entrySet()) {
+ sum = sum.add(e.getValue().multiply(w[e.getKey()])).mod(p);
+ }
+ return sum;
+ }
+
+ private static BigInteger invertMiMC(BigInteger target, BigInteger key) {
+ BigInteger state = target.subtract(key).mod(BN254_FR);
+ for (int i = 90; i >= 0; i--) {
+ BigInteger t = state.modPow(INV_SEVEN, BN254_FR);
+ BigInteger rc = MiMC.roundConstant(i).mod(BN254_FR);
+ state = t.subtract(rc).subtract(key).mod(BN254_FR);
+ }
+ return state;
+ }
+
+ private static void assertDeprecatedForRemoval(Class> type) {
+ Deprecated dep = type.getAnnotation(Deprecated.class);
+ assertNotNull(dep, type.getName() + " must be @Deprecated");
+ assertTrue(dep.forRemoval(), type.getName() + " must have forRemoval = true");
+ }
+}
diff --git a/zeroj-circuit-lib/src/test/java/org/zeroj/circuit/lib/NewStdlibTest.java b/zeroj-circuit-lib/src/test/java/org/zeroj/circuit/lib/NewStdlibTest.java
index 6f9920b1..22cadf9d 100644
--- a/zeroj-circuit-lib/src/test/java/org/zeroj/circuit/lib/NewStdlibTest.java
+++ b/zeroj-circuit-lib/src/test/java/org/zeroj/circuit/lib/NewStdlibTest.java
@@ -13,8 +13,9 @@
import static org.junit.jupiter.api.Assertions.*;
/**
- * Tests for production-ready stdlib functions: AliasCheck, MiMCSponge, PoseidonN.
+ * Tests for stdlib gadgets: AliasCheck, deprecated legacy MiMCSponge, and PoseidonN.
*/
+@SuppressWarnings("removal")
class NewStdlibTest {
private static final BigInteger BN254_FR = FieldConfig.BN254.prime();
diff --git a/zeroj-circuit-lib/src/test/java/org/zeroj/circuit/lib/SignalStyleTest.java b/zeroj-circuit-lib/src/test/java/org/zeroj/circuit/lib/SignalStyleTest.java
index 1a2d2be0..d120d2a2 100644
--- a/zeroj-circuit-lib/src/test/java/org/zeroj/circuit/lib/SignalStyleTest.java
+++ b/zeroj-circuit-lib/src/test/java/org/zeroj/circuit/lib/SignalStyleTest.java
@@ -13,6 +13,7 @@
/**
* Tests for the Signal-based stdlib — all using the OO (Signal chaining) style.
*/
+@SuppressWarnings("removal")
class SignalStyleTest {
// ========================================================================
diff --git a/zeroj-circuit-lib/src/test/java/org/zeroj/circuit/lib/StdlibUsageExamplesTest.java b/zeroj-circuit-lib/src/test/java/org/zeroj/circuit/lib/StdlibUsageExamplesTest.java
index 75992e3f..442a5fd5 100644
--- a/zeroj-circuit-lib/src/test/java/org/zeroj/circuit/lib/StdlibUsageExamplesTest.java
+++ b/zeroj-circuit-lib/src/test/java/org/zeroj/circuit/lib/StdlibUsageExamplesTest.java
@@ -16,6 +16,7 @@
*
* Each test is a self-contained example that a developer can copy and adapt.
*/
+@SuppressWarnings("removal")
class StdlibUsageExamplesTest {
// ========================================================================
diff --git a/zeroj-circuit-lib/src/test/java/org/zeroj/circuit/lib/zk/ZkGadgetAdaptersTest.java b/zeroj-circuit-lib/src/test/java/org/zeroj/circuit/lib/zk/ZkGadgetAdaptersTest.java
index f889c501..c0ddca83 100644
--- a/zeroj-circuit-lib/src/test/java/org/zeroj/circuit/lib/zk/ZkGadgetAdaptersTest.java
+++ b/zeroj-circuit-lib/src/test/java/org/zeroj/circuit/lib/zk/ZkGadgetAdaptersTest.java
@@ -33,6 +33,7 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
+@SuppressWarnings("removal")
class ZkGadgetAdaptersTest {
private static final BigInteger EDDSA_SK = new BigInteger(
"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef", 16)
diff --git a/zeroj-integration-tests/src/test/java/org/zeroj/examples/annotation/AnnotatedCircuitExamplesTest.java b/zeroj-integration-tests/src/test/java/org/zeroj/examples/annotation/AnnotatedCircuitExamplesTest.java
index 21964fdc..d33f3013 100644
--- a/zeroj-integration-tests/src/test/java/org/zeroj/examples/annotation/AnnotatedCircuitExamplesTest.java
+++ b/zeroj-integration-tests/src/test/java/org/zeroj/examples/annotation/AnnotatedCircuitExamplesTest.java
@@ -30,6 +30,7 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
+@SuppressWarnings("removal")
class AnnotatedCircuitExamplesTest {
@Test
@@ -304,6 +305,7 @@ void annotatedAnonymousVotingMirrorsReferenceDslCircuit() {
}
@Test
+ @SuppressWarnings("removal")
void parameterizedMerkleMembershipUsesBn254MiMCDepthAndHashType() {
int depth = 2;
var hashType = ZkMerkle.HashType.MIMC;
diff --git a/zeroj-integration-tests/src/test/java/org/zeroj/examples/annotation/AnnotatedHashCommitment.java b/zeroj-integration-tests/src/test/java/org/zeroj/examples/annotation/AnnotatedHashCommitment.java
index b529f632..ee9e74f2 100644
--- a/zeroj-integration-tests/src/test/java/org/zeroj/examples/annotation/AnnotatedHashCommitment.java
+++ b/zeroj-integration-tests/src/test/java/org/zeroj/examples/annotation/AnnotatedHashCommitment.java
@@ -10,11 +10,12 @@
import org.zeroj.circuit.lib.zk.ZkMiMC;
/**
- * BN254/off-chain MiMC adapter example.
+ * Legacy BN254/off-chain MiMC adapter example (exercises deprecated {@link ZkMiMC}).
*
- * Cardano-facing hash examples use explicit BLS12-381 Poseidon params
- * instead. This class remains as the small MiMC symbolic adapter example.
+ * Do not use MiMC in real circuits; Cardano-facing hash examples use explicit
+ * BLS12-381 Poseidon params instead.
*/
+@SuppressWarnings("removal")
@ZKCircuit(name = "annotation-hash-commitment")
public class AnnotatedHashCommitment {
@Prove
diff --git a/zeroj-integration-tests/src/test/java/org/zeroj/examples/dsl/common/MiMCHash.java b/zeroj-integration-tests/src/test/java/org/zeroj/examples/dsl/common/MiMCHash.java
index 4b97651b..06743d4a 100644
--- a/zeroj-integration-tests/src/test/java/org/zeroj/examples/dsl/common/MiMCHash.java
+++ b/zeroj-integration-tests/src/test/java/org/zeroj/examples/dsl/common/MiMCHash.java
@@ -6,16 +6,17 @@
import java.security.NoSuchAlgorithmException;
/**
- * Standalone BN254/off-chain MiMC-7 hash computation (outside ZK circuits).
+ * LEGACY TEST REGRESSION FIXTURE ONLY — INSECURE / INVERTIBLE — DO NOT USE IN REAL CIRCUITS.
*
- * Produces the same output as the circuit-based {@code SignalMiMC.hash()} / {@code MiMC.hash()},
- * allowing the prover to compute hash values before constructing the witness.
+ * Host-side mirror of the deprecated {@code MiMC.hash()} / {@code SignalMiMC.hash()} gadgets,
+ * retained solely so legacy BN254 regression tests can compute expected outputs for the deprecated
+ * invertible keyed bijection (91 rounds of {@code (state + rc_i + key)^7}, returning
+ * {@code state + key}, with SHA-256 round constants and no Miyaguchi–Preneel feed-forward).
*
- * MiMC-7 parameters: 91 rounds, S-box x^7, round constants = SHA-256("mimc_round_N").
- *
- * The in-circuit MiMC gadget is BN254-only. Cardano-facing examples should
- * use BLS12-381 Poseidon instead.
+ * Do not copy this helper into application code; use
+ * {@code PoseidonHash.hash(PoseidonParamsBLS12_381T3.INSTANCE, left, right)} instead.
*/
+@Deprecated(forRemoval = true)
public final class MiMCHash {
private MiMCHash() {}
diff --git a/zeroj-integration-tests/src/test/java/org/zeroj/examples/dsl/templates/NWayMerkleCircuit.java b/zeroj-integration-tests/src/test/java/org/zeroj/examples/dsl/templates/NWayMerkleCircuit.java
index 4ef8419b..74ca66a3 100644
--- a/zeroj-integration-tests/src/test/java/org/zeroj/examples/dsl/templates/NWayMerkleCircuit.java
+++ b/zeroj-integration-tests/src/test/java/org/zeroj/examples/dsl/templates/NWayMerkleCircuit.java
@@ -30,17 +30,27 @@
* more flexible than Circom templates which only support integer parameters.
*
* @param depth tree depth (number of sibling levels)
- * @param hashFn hash function to use (MiMC, Poseidon, or any 2-to-1 hash)
+ * @param hashFn hash function to use (use {@link HashType#POSEIDON} with BLS12-381;
+ * {@link HashType#MIMC} is retained solely as a legacy regression fixture)
*/
public class NWayMerkleCircuit implements CircuitSpec {
/**
- * Supported hash functions for Merkle nodes.
+ * Hash function selector for the parameterized Merkle template fixture.
*
- * `MIMC` is the BN254/off-chain path. `POSEIDON` uses explicit BLS12-381
- * params and is the Cardano-oriented path.
+ * {@code POSEIDON} uses explicit BLS12-381 params and is the Cardano-oriented path.
+ * {@code MIMC} is retained only as a legacy BN254 regression fixture (exercising the
+ * deprecated invertible {@code SignalMiMC} gadget) and must not be used in real circuits.
*/
- public enum HashType { MIMC, POSEIDON }
+ public enum HashType {
+ /**
+ * @deprecated Legacy regression fixture only — delegates to the deprecated, invertible
+ * {@code SignalMiMC} gadget. Use {@link #POSEIDON} instead.
+ */
+ @Deprecated(forRemoval = true)
+ MIMC,
+ POSEIDON
+ }
private final int depth;
private final HashType hashType;
@@ -67,6 +77,7 @@ public void define(SignalBuilder c) {
// Hash function selection — resolved at circuit build time (not runtime).
// Poseidon binds to BLS12-381 params since this example compiles for BLS12-381;
// the BN254 default would trip CircuitBuilder's field check at compile time.
+ @SuppressWarnings("removal")
SignalMerkle.HashFn hashFn = switch (hashType) {
case MIMC -> SignalMiMC::hash;
case POSEIDON -> (cb, l, r) -> SignalPoseidon.hash(cb, PoseidonParamsBLS12_381T3.INSTANCE, l, r);
diff --git a/zeroj-integration-tests/src/test/java/org/zeroj/examples/dsl/templates/ParameterizedCircuitE2ETest.java b/zeroj-integration-tests/src/test/java/org/zeroj/examples/dsl/templates/ParameterizedCircuitE2ETest.java
index 3b74a80c..2091292f 100644
--- a/zeroj-integration-tests/src/test/java/org/zeroj/examples/dsl/templates/ParameterizedCircuitE2ETest.java
+++ b/zeroj-integration-tests/src/test/java/org/zeroj/examples/dsl/templates/ParameterizedCircuitE2ETest.java
@@ -136,6 +136,7 @@ void merkle_depth3_poseidon_proveAndVerify() {
}
@Test
+ @SuppressWarnings("removal")
void merkle_mimcIsBn254Only_poseidonIsBlsCardanoPath() {
int mimcC = NWayMerkleCircuit.build(2, NWayMerkleCircuit.HashType.MIMC)
.compileR1CS(CurveId.BN254).numConstraints();