mirror of
https://github.com/circify/circ.git
synced 2026-01-10 06:08:02 -05:00
39c9c6ae00ac41d7c265403094cbfd0a2e8baa5e
CirC: The Circuit Compiler
This repository holds an in-progress rewrite of CirC.
CirC is a compiler infrastructure which supports compilation from high-level (stateful, uniform) languages to (state-free, non-uniform, existentially quantified) circuits.
It's been used to compile {C, ZoKrates, Circom} to {SMT, R1CS}, but it probably also applies to any statically type high-level language and MPC/constant-time/ILP/FHE.
Requirements
Developing CirC requires the CVC4 SMT solver, which is used in some tests. Its
binary must be on your path. On Arch Linux and Ubuntu you can install the
cvc4 package from official repositories.
You'll also need a Rust nightly compiler. You can set the nightly channel as
Rust's default for the circ directory by running rustup override set nightly
in it.
Architecture
- Components:
src/ir- IR term definition
term/bv.rs: bit-vec literalsterm/field.rs: prime-field literalsterm/ty.rs: type-checkingterm/extras.rs: algorithms: substitutions, etc.
- Optimization
opt/cfold.rs: constant foldingopt/flat.rs: n-ary flatteningopt/inline.rs: inliningopt/sha.rs: replacements for SHA's CH and MAJ operationsopt/tuple.rs: eliminating tuplesopt/mem/obliv.rs: oblivious array eliminationopt/mem/lin.rs: linear-scan array eliminationopt/mem/visit.rs: utility for visiting (and replacing?) all array-related terms
- IR term definition
src/target- R1CS backend
- lowering from IR
- optimization
- connection to bellman
- SMT backend
- based on rsmt2
- R1CS backend
src/circify- Machinery for recursive imports
mem: the stack memory modulemod: the main Circify interface
src/frontzokrates: the ZoKrates front-end
src/util- A once-queue (each item appears at most once)
- Implemented by combining a set with a queue
- hash-consing machinery
- A once-queue (each item appears at most once)
examples/circ.rs- This is the entry point to the zokrates copiler
Todo List
- Intern variable names
- Tweak log system to expect exact target match
- C front-end
- Tune R1CS optimizer
- Less hash maps
- Consider using ff/ark-ff instead of gmp
- Consider a lazy merging strategy
- remove synchronization from term representation (or explore parallelism!)
- More SMT solver support
- Parse cvc4 models
- A more configurable term distribution (for fuzzing)
- Add user-defined (aka opaque) operator to IR
Description
Languages
Rust
95.8%
Shell
2.1%
Python
2%