Midnight Circuits
Midnight Circuits is a library designed for implementing circuits with Halo2. It is built on the PSE v0.4.0 release of Halo2, incorporating a few minor additions required to support Midnight Circuits.
Disclaimer: This library has not been audited. Use it at your own risk.
Features
Midnight Circuits provides several tools to facilitate circuit development with Halo2. These include:
- Native and non-native field operations.
- Native and non-native elliptic-curve operations.
- Native and non-native hash-to-curve functionality.
- Bit/Byte decomposition tools and range-checks.
- SHA-256.
- SHA-512.
- Set (non-)membership.
- BigUInt.
- Variable length vectors (see explanation below).
- Finite-state automata parsing.
- In-circuit verification of PLONK proofs (a.k.a. recursion).
We aim to expose these functionalities via traits, which can be found in [src/instructions].
Variable length vectors
We provide support for variable-length vectors in-circuit, even when the exact size of the vector is unknown
at compilation time. Each variable-length vector is parameterized with a MAX_LENGTH attribute, which
specifies the maximum allowed size.
The cost of using these structures in-circuit is proportional to the MAX_LENGTH, while the computed result
is guaranteed to correspond to the operation applied to the actual vector values. For example, operations
such as hashing or parsing are performed over the full vector of length MAX_LENGTH, and the final result
is conditionally selected to reflect the operation applied only to the actual elements of the vector.
Usage
Midnight Circuits provides low-level building blocks for constructing zero-knowledge circuits.
For a higher-level abstraction that simplifies circuit development, see the midnight-zk-stdlib
crate.
Versioning
We use Semantic Versioning. To capture
the changes that do not affect the API, do not add any new functionality, but
are breaking changes, we increment the MAJOR version. This happens when the
circuit is modified for performance or bug fixes; the modification of the
verification keys break backwards compatibility.
- MAJOR: Incremented when you make incompatible API or VK changes
- MINOR: Incremented when you add functionality in a backward-compatible manner
- PATCH: Incremented when you make backward-compatible bug fixes