Enclave is now The Interfold. Documentation is being updated.
Noir Circuits

Noir Circuits & Libraries

The Interfold ships a dedicated Noir workspace under circuits/ plus reusable libraries (SAFE sponge API, polynomial utilities, modular arithmetic, PVSS circuit primitives, etc.). Use these circuits as-is or vendor them into your own E3 programs.

Workspace layout

circuits/
├── lib/
│   ├── Nargo.toml              # library manifest
│   └── src/
│       ├── lib.nr              # top-level library entry
│       ├── configs/            # BFV parameter configurations (default, insecure, secure, committee)
│       ├── core/               # DKG and threshold PVSS circuit implementations
│       │   ├── dkg/            # pk, share_computation, share_encryption, share_decryption
│       │   └── threshold/      # pk_generation, pk_aggregation, share_decryption,
│       │                       # decrypted_shares_aggregation, user_data_encryption_ct0/ct1
│       └── math/               # polynomial, SAFE sponge, modular arithmetic (U128), commitments
├── bin/
│   ├── config/                 # configuration validation circuit
│   ├── dkg/                    # DKG sub-circuits (pk, sk_share_computation, e_sm_share_computation,
│   │                           # share_encryption, share_decryption)
│   ├── threshold/              # threshold sub-circuits (pk_generation, pk_aggregation,
│   │                           # share_decryption, user_data_encryption_ct0/ct1,
│   │                           # decrypted_shares_aggregation)
│   ├── insecure/               # legacy insecure-parameter circuits for development
│   ├── production/             # production-parameter circuits (placeholder)
│   └── recursive_aggregation/  # recursive proof aggregation
│       ├── fold/               # fold circuit (uses Aztec bb_proof_verification)
│       └── wrapper/            # recursive wrappers for DKG and threshold circuits
│           ├── dkg/            # pk, share_computation, share_encryption, share_decryption
│           └── threshold/      # pk_generation, pk_aggregation, share_decryption,
│                               # decrypted_shares_aggregation, user_data_encryption
├── benchmarks/                 # benchmark scripts and results
└── .gitignore

The core library at circuits/lib/ contains reusable modules for polynomial arithmetic, the SAFE sponge API, modular reduction helpers (including U128 large-integer operations), and BFV DKG/threshold PVSS primitives. Binary circuits under circuits/bin/ implement specific proof programs (DKG key generation, share encryption/decryption, threshold aggregation, recursive folding, etc.). The library depends on poseidon, keccak256 (from noir-lang), and bignum (from gnosisguild/noir-bignum).

To reference the library from an external project:

[dependencies]
enclave_lib = { git = "https://github.com/gnosisguild/enclave", tag = "v0.1.15", directory = "circuits/lib" }

Tooling requirements

Install the Noir toolchain:

curl -L https://noir-lang.org/install | bash   # installs nargo + bb
nargo --version                                # v1.0.0-beta.16+ (see zk-prover Cargo.toml for exact tag)
bb --version                                   # v3.0.0-nightly.20260102+ (see crates/zk-prover/versions.json)

Tip: Use enclave noir setup instead of manual installation — it downloads and verifies the exact versions of bb and pre-compiled circuit artifacts needed by the Enclave ZK prover.

CLI ZK Prover Setup

The Enclave CLI can manage the ZK prover toolchain (Barretenberg and circuits) for you:

# Check current ZK prover status (installed versions, paths)
enclave noir status
 
# Install or update the ZK prover components (bb binary, circuit artifacts)
enclave noir setup
 
# Force reinstall all components
enclave noir setup --force

enclave noir status shows installation paths, versions, and whether all components are present. enclave noir setup downloads and installs the correct versions of bb and pre-compiled circuit artifacts needed for proof generation.

Formatting & compilation

Run the helper scripts from the repo root or reproduce them in your project:

pnpm tsx scripts/build-circuits.ts  # compile circuits, generate VKs, prepare release artifacts
./scripts/lint-circuits.sh          # nargo fmt --check && nargo check across all circuit directories
./scripts/test-circuits.sh          # run circuit unit tests (nargo test on circuits/lib)

lint-circuits.sh checks formatting and validates circuits across lib, bin/config, bin/recursive_aggregation, bin/dkg, and bin/threshold. Both shell scripts exit early (without failing the whole build) if nargo is not installed, which makes CI happy when Noir is optional.

Exporting verifiers

Projects such as CRISP compile Noir circuits into Solidity verifiers using bb:

cd examples/CRISP
./scripts/compile_circuits.sh

The script performs:

  1. Compiles enclave dependency circuits (user_data_encryption_ct0, user_data_encryption_ct1, and the recursive wrapper for user_data_encryption)
  2. Compiles the CRISP-specific circuit and fold circuit (recursive aggregation)
  3. bb write_vk with --oracle_hash keccak on the fold circuit to emit the verification key
  4. bb write_solidity_verifier to produce CRISPVerifier.sol from the fold VK
  5. Copies the generated verifier into packages/crisp-contracts/contracts/
  6. Replaces the license header and formats with Prettier

Adapt the script for your own circuits by changing the circuit paths and output directory. On-chain verification uses the ICircuitVerifier interface:

interface ICircuitVerifier {
  function verify(
    bytes calldata _proof,
    bytes32[] calldata _publicInputs
  ) external view returns (bool);
}

Integrating with E3 programs

  • Import the library in your circuit's Nargo.toml (see the dependency snippet above)
  • Generate Solidity verifiers and deploy them as ICircuitVerifier implementations
  • Reference the compiled artifacts when deploying via the template or CRISP scripts
  • For Rust-side proof generation, the e3-zk-prover crate handles witness generation, proof generation (via bb prove), and verification (via bb verify) automatically

When adding new circuits, remember to update package.json scripts (e.g., pnpm dev:all) so they call your compile script before spinning up the dev environment. This keeps your verifiers in sync with the Noir source.