Circuits
Circuits are the main operational units of a Midnight smart contract. They correspond closely to functions in other languages, but are compiled directly into zero-knowledge circuits.
Source: Circuits
In this chapter, you’ll learn:
- How to declare circuits
- Parameters and return values
- Pure circuits for helper functions
- Visibility and exports
Why “Circuits”?
The Compact compiler outputs zero-knowledge circuits used to prove correctness of ledger interactions. When you write a Compact circuit, it gets transformed into an actual ZK circuit that can generate and verify cryptographic proofs.
Source: Writing a contract
Think of circuits as special functions that:
- Define business logic - What the contract can do and how state changes
- Generate ZK proofs - Compiled into circuits that underpin proof generation and verification
- Are callable from TypeScript - Exposed via the generated
Contractclass andCircuits/PureCircuitstypes when markedexport
Source: Writing a contract, TypeScript target