Riad S. Wahby 50b97f6acb zsharp fixes ; speed improvements (#73)
This PR does two things:

- Fixes some scoping issues in Z# having to do with the context in which function and struct definitions are interpreted.
- Improves speed and reduces TermTable memory consumption by 2x (by keying on Arc<TermData> rather than TermData)
- Improves speed for Z# array handling with a BTreeMap -> HashMap swap
- Adds intrinsic widening casts in Z#. These were previously handled by bit-splitting, which is wasteful.
 
On array-heavy Z# programs, this PR improves speed by about 5x and memory consumption by roughly the same.

---

* zsharp::term::ir_array should use HashMap (faster, less memory)

* perf improvements

constant folding: get rid of redundant clones
bitvector: impl arith for refs
TermTable: don't store redundant term as key

* EMBED widening casts

* generic inf: need to push fn defn context onto filestack

* canonicalize path in err msg

* need struct defn on filestack, too

* no need to warn about U32 indexing in zsharp

* fix warning
2022-04-08 21:16:35 -04:00
2022-03-27 20:24:20 -07:00
2021-12-07 09:44:17 -08:00
2021-12-20 00:13:43 -08:00
2021-12-07 09:44:17 -08:00
2021-12-07 09:44:17 -08:00
2022-02-25 17:13:10 -05:00
2022-02-15 23:19:46 -08:00
2021-12-19 22:35:02 -08:00
2022-02-06 22:47:30 -05:00
2022-02-25 17:13:10 -05:00

CirC: The Circuit Compiler

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, ILP, R1CS, MPC}, but it probably also applies to any statically type high-level language and constant-time/FHE.

If you want to learn more about CirC, see our paper or slides.

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 the COIN-OR CBC solver. On Arch linux, this is coin-or-cbc. On Ubuntu coinor-cbc and coinor-libcbc-dev.

You'll also need a stable Rust compiler.

Architecture

  • Components:
    • src/ir
      • IR term definition
        • term/bv.rs: bit-vec literals
        • term/field.rs: prime-field literals
        • term/ty.rs: type-checking
        • term/extras.rs: algorithms: substitutions, etc.
      • Optimization
        • opt/cfold.rs: constant folding
        • opt/flat.rs: n-ary flattening
        • opt/inline.rs: inlining
        • opt/sha.rs: replacements for SHA's CH and MAJ operations
        • opt/tuple.rs: eliminating tuples
        • opt/mem/obliv.rs: oblivious array elimination
        • opt/mem/lin.rs: linear-scan array elimination
        • opt/mem/visit.rs: utility for visiting (and replacing?) all array-related terms
    • src/target
      • R1CS backend
        • lowering from IR
        • optimization
        • connection to bellman
      • SMT backend
        • based on rsmt2
    • src/circify
      • Machinery for recursive imports
      • mem: the stack memory module
      • mod: the main Circify interface
    • src/front
      • zokrates: 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
    • examples/circ.rs
      • This is the entry point to the zokrates copiler

Backends

SMT

The SMT backend can be changed between CVC4 and cvc5 by setting the RSMT2_CVC4_CMD environmental variable to the SMT solver's invocation command (cvc4 or cvc5).

Description
No description provided
Readme 15 MiB
Languages
Rust 95.8%
Shell 2.1%
Python 2%