Commit Graph

246 Commits

Author SHA1 Message Date
Alex Ozdemir
cafb02b848 optimize bellman ZK prover backend (#182)
three changes:
* faster integer->ff conversion
* parallel construction of bellman LCs
* parallel R1CS checking (on the CirC side)

The first change is the most important, by far. Our previous integer->ff
conversion was very slow.
2024-01-03 16:39:05 -08:00
Alex Ozdemir
6133414b44 lint (#181) 2023-12-13 08:17:41 -08:00
Alex Ozdemir
697c240148 mem notes 2023-12-12 19:24:05 -08:00
Alex Ozdemir
a26533baad zxi now takes optional inputs (#180) 2023-11-15 13:46:09 -08:00
Alex Ozdemir
fca98ddc5a add sample_challenge builtin (#179) 2023-11-15 09:59:29 -08:00
Alex Ozdemir
7a805323d0 Optimized transcript checking for covering ROMs (#178) 2023-11-14 18:20:39 -08:00
Alex Ozdemir
68b0b45556 User-directed transcript-based RAM checking. (#176)
* user-directed transcript-based RAM checking

when the `transcript` type qualifier is used.

* fix ram tests

* fmt & lint

* rm incomplete test
2023-11-02 23:50:16 -07:00
Alex Ozdemir
c0355299df r1cs optimization bugfix: use tracking (#175)
The R1CS optimizer tracks variable uses so that it can run faster.

Our tracker would sometimes think that a variable has cancelled from a
constraint when it had not.

Now, the tracker is conservative, but correct.
2023-10-31 11:41:38 -07:00
Alex Ozdemir
805a7f424f RAM for non-scalar values (#174)
It is very naive. It assumes that any top-level array should be represented as a RAM, and that all internal structure should be unfolded.
2023-10-17 22:04:38 -07:00
Alex Ozdemir
4c5dafee95 A Waksman-based RAM permutation argument (#171)
This allows folks to use the RAM machinery while sticking with (non-interactive) R1CS output.

We're going to need this anyway when we benchmark our new approach.
2023-09-19 02:39:24 -07:00
Alex Ozdemir
64dcc18175 Improve RAM: oblivious & volatile (#170)
* Improve the oblivious RAM pass by killing the hack where we treat selects as arrays.
* Fix a bug where the volatile RAM pass would not place selects before stores against the same array
* Improve that volatile RAM pass by placing selects against the same array literal in the same RAM. Before, they would each end up in different RAMs, which sucks. This is especially bad for ROMs.
2023-09-18 11:07:19 -07:00
Alex Ozdemir
fb198eeadd ram structure example (#169) 2023-09-14 13:34:27 -07:00
Alex Ozdemir
a586f7f95d GC after each optimization (#167)
Flag: `--ir-frequent-gc true`

Reduces memory usage on Jess & Eli's pgm from 398MB to 285MB.
2023-08-11 16:37:46 -07:00
Alex Ozdemir
d7217e559e Optimize GC (#166)
Previously, a GC call would scan the HC table, identifying dead nodes.

Now, whenever a Node is destroyed, if it's ready to be GC'd, it gets added to a list. That list is used at GC time instead of the scan.

This substantially decreases the cost of running GC many times (as the Z# FE does).
2023-07-09 14:45:14 -07:00
Alex Ozdemir
bf3d9c601e Remove dead r1cs vars after opt (#164)
We were already removing those that are explicitly eliminated, but they
can become dead in other ways too.
2023-06-22 19:44:35 -07:00
Alex Ozdemir
079eea1ae9 r1cs: fix boolean majority (#163)
* r1cs: fix boolean majority

for m = majority(a,b,c),
we were lowering

    (-ab + bc + ac - 2abc)

instead of

    (ab + bc + ac - 2abc)

Whoops! This is a functional correctness bug: we were lowering
soundly and completely, for the wrong specification.

Credit to Anna for raising the issue!

* add test_sha256 (commented out b/c it is slow)

* fmt + lint
2023-06-14 15:14:05 -07:00
Edward Chen
bd9cec31fb Replaced third party dependencies with binaries to reduce CI build times (#162)
To reduce CI build time:
- Replaced ABY dependency with corresponding binary.
- Removed dependencies on KaHIP and KaHyPar for now because these dependencies aren't used upstream.
Minor updates:
- Updated ABY source to Public branch
Note: 
- The aby_interpreter binary will only work on Linux. We can rebuild the binary from this repo.
2023-06-14 14:58:39 -04:00
Alex Ozdemir
961fda6fb3 Fix bug in r1cs lowering for bv cmps (#161)
We called the wrong function...
This is a soundness bug.

Credit to Anna for reporting this.
2023-06-14 09:53:10 -07:00
Alex Ozdemir
e404c13468 Access array without it cloning it. (#160)
All credits to Evan for finding this.

Co-authored-by: Evan Laufer <evan.m.laufer@gmail.com>
2023-05-26 15:33:05 -07:00
Alex Ozdemir
18990d079e Inline small elements in FieldV. (#156)
reduces memory usage during R1CS lowering by ~40%.
2023-03-20 08:59:23 -07:00
Edward Chen
2e2bf85399 Linker Optimization Pass Documentation clean-up (#155) 2023-03-15 22:27:25 -04:00
Alex Ozdemir
706405fd4f Committed witnesses & randomness in Z# (& tests) (#154)
A basic implementation of committed witnesses & volatile RAM extraction in the Z# front-end.

The passes in question are still a bit brittle, so I left them behind a flag.
2023-03-15 16:28:19 -07:00
Edward Chen
a49e03abfb Linker Optimization Pass clean-up (#153) 2023-03-15 15:21:19 -04:00
Edward Chen
06a34c8cc5 Linker Optimization Pass (#152) 2023-03-15 15:03:51 -04:00
Alex Ozdemir
cd1be1ea1c Optimizations for interaction, randomness and RAM (#151)
List of optimizations:
* challenge skolemization
* condition store parsing/expansion
* volatile RAM extraction
* persistent RAM extraction
* RAM checking (for both)
2023-03-14 11:15:42 -07:00
Alex Ozdemir
450c37b896 Add extension operators and new operators (#150)
modifies some opt passes w/ new ops
2023-03-14 01:09:46 -07:00
Alex Ozdemir
155794c2bf Committed witnesses, CP link implementation (#149) 2023-03-13 14:39:35 -07:00
Alex Ozdemir
ad11eb311e Update dependencies (#148)
Clears sec advisory on a transitive dep: remove_dir_all. It was
(transitively) dead anyways.
2023-03-09 15:54:24 -08:00
Edward Chen
bb8e6e3673 KaHIP and kahypar binaries for MPC backend (#147)
- Upgraded ci pipeline to [v3](https://github.com/actions/cache/blob/main/README.md)
- Included installation and build scripts  for KaHIP and kahypar in driver.py
- Used absolute paths for caching in ci pipeline (relative paths don't work). 

Average ci time brought down from 15 minutes to 8 minutes!
2023-02-27 12:31:35 -05:00
Alex Ozdemir
77e7040047 Mirage, variable rounds, randomness, zk opt (#146)
Adds:

    an implementation of the Mirage proof system
        generalized to multiple round of interaction
    a notion of rounds for variables
    a notion of randomness for variables
    to the R1CS layer:
        committed witnesses
        rounds
    new witness computation machinery (to support multiple rounds)
2023-02-06 09:58:19 -08:00
Alex Ozdemir
c900b79afb challenge operator (#145) 2023-01-29 21:09:34 -08:00
Alex Ozdemir
e4d19b358a Operator statistics (#144) 2023-01-29 19:39:02 -08:00
Alex Ozdemir
63f950a795 eval_op (#143)
separate evaluation from terms

its now a fn(operator, child values) -> value
2023-01-29 19:38:51 -08:00
Alex Ozdemir
8608e03e90 Option to hide all fields when printing IR (#142) 2023-01-29 19:16:42 -08:00
Edward Chen
c06e938c41 Introducing SV Comp-style tests for C Frontend (#140)
Integrating SV comp tests for C Frontend

---------

Co-authored-by: Alex Ozdemir <aozdemir@hmc.edu>
2023-01-29 21:30:55 -05:00
Edward Chen
20b91a6601 Clippy: uninlined_format_args (#141) 2023-01-29 21:05:15 -05:00
Alex Ozdemir
5e36d4ba03 features: add bellman, spartan, aby (#139)
Also, add ./driver --check-all, which checks every single-feature build.
2023-01-19 00:13:09 -08:00
Alex Ozdemir
d11b92ae0f Add rounds & challenges to Computation (#138) 2023-01-18 12:03:26 -08:00
Alex Ozdemir
d15db74f04 change metadata serialization & representation (#137)
In the new approach, all variable metadata is stored per-variable.

This makes it easier to add new kinds of metadata, and to serialize that metadata.
2023-01-18 11:22:43 -08:00
Alex Ozdemir
b28123115b lazy debitification in r1cs::trans (#136)
Before, whenever we constructed a bit-wise encoding of a BV, we also
debitified it into a UINT encoding.

Now, we do the debitification on-demand. This saves ~10-15% of compilation
time.

While debitification is free from the perspective of R1CS, it is costly
for compilation time.

I measured compile time for the sha2 round function.

```terminal
Benchmark #1: ./circ-old third_party/ZoKrates/zokrates_stdlib/stdlib/hashes/sha256/shaRound.zok r1cs
  Time (mean ± σ):      1.219 s ±  0.019 s    [User: 1.145 s, System: 0.071 s]
  Range (min … max):    1.180 s …  1.240 s    10 runs

Benchmark #2: ./circ-new third_party/ZoKrates/zokrates_stdlib/stdlib/hashes/sha256/shaRound.zok r1cs
  Time (mean ± σ):      1.055 s ±  0.024 s    [User: 987.1 ms, System: 65.9 ms]
  Range (min … max):    1.026 s …  1.094 s    10 runs

Summary
  './circ-new third_party/ZoKrates/zokrates_stdlib/stdlib/hashes/sha256/shaRound.zok r1cs' ran
    1.15 ± 0.03 times faster than './circ-old third_party/ZoKrates/zokrates_stdlib/stdlib/hashes/sha256/shaRound.zok r1cs'
```
2023-01-17 10:58:41 -08:00
Alex Ozdemir
62ee97b240 missed a datalog feature (#135) 2023-01-17 09:49:42 -08:00
Alex Ozdemir
5f3d2b95fe Split hash-consing into its own crate & reimplement (#134)
I split the hash-consing implementation into its own crate and re-implemented it.

In the new implementation, the table is thread-local. Terms are not Send, but linear terms are.

Decreased used of atomics gives a non-trivial speed-up. I tested on Z#'s sha2 round function, with an exit after IR optimization:

Benchmark #1: ./circ-old third_party/ZoKrates/zokrates_stdlib/stdlib/hashes/sha256/shaRound.zok r1cs
  Time (mean ± σ):     236.2 ms ±  16.1 ms    [User: 223.3 ms, System: 12.4 ms]
  Range (min … max):   221.1 ms … 264.1 ms    11 runs

Benchmark #2: ./circ-new third_party/ZoKrates/zokrates_stdlib/stdlib/hashes/sha256/shaRound.zok r1cs
  Time (mean ± σ):     141.8 ms ±  13.1 ms    [User: 131.3 ms, System: 10.0 ms]
  Range (min … max):   125.4 ms … 160.4 ms    18 runs

Summary
  './circ-new third_party/ZoKrates/zokrates_stdlib/stdlib/hashes/sha256/shaRound.zok r1cs' ran
    1.67 ± 0.19 times faster than './circ-old third_party/ZoKrates/zokrates_stdlib/stdlib/hashes/sha256/shaRound.zok r1cs'
2023-01-17 02:17:58 -08:00
Alex Ozdemir
c4cfa50cf9 retarget bellman dependency to our fork (mirage impl) (#132) 2023-01-12 12:13:21 -08:00
Alex Ozdemir
500b9157f4 Upload Braun's thesis & fix link (#133) 2023-01-12 12:04:01 -08:00
Alex Ozdemir
838b8a6791 Include Anna's test cases and fix (#131)
The first bug is a disagreement between our bellman circuit and our bellman
verify function. The circuit omit unused variables (public or private). The
verify function includes unused public variables.

Now, the circuit includes unused public variables.

The second bug is related to large BV comparisons. The fix is to emit a
bitwise comparator. We could optimize further in the future.

closes #125
2023-01-09 23:00:35 -08:00
Alex Ozdemir
ebfd6853d3 Avoid R1CS copy (#130)
Co-authored-by: Riad S. Wahby <rsw@jfet.org>
2023-01-06 09:11:27 -08:00
Alex Ozdemir
1a1cdc5858 Add option to panic on OOB PfToBv (#129) 2023-01-05 19:57:04 -08:00
Alex Ozdemir
f9bedf0787 Alternative formatter (#128)
* Configuration system. Kill DFL_T

* add circ::cfg::CircCfg that holds cfg info
   * it's constructible from circ_opt::CircOpt
      * implements clap::Args, so you can set it from your compiler's
        CLI/envvars
      * defined in external crate to keep clap out of our main build
      * organized by circ module, but not feature gated
         *  no point: the build wouldn't meaningfully change
      * includes a way to set the default field
* added circ::cfg::set and circ::cfg::cfg
   * also circ::cfg::set_default and circ::cfg::set_cfg
   * access a sync::once_cell, static configuration
* killed DFL_T

* workflows
   * unit-tested component probably need to not read circ::cfg::cfg.
   * compilers need to call circ::cfg::set or circ::cfg::set_default.

* rm dead features

* WIP

* Alternate formatting machinery.

* fmt & lint

* rm Letified

* ilp
2023-01-03 21:51:28 -08:00
Alex Ozdemir
be8741c615 Configuration system. Kill DFL_T (#127)
* Configuration system. Kill DFL_T

* add circ::cfg::CircCfg that holds cfg info
   * it's constructible from circ_opt::CircOpt
      * implements clap::Args, so you can set it from your compiler's
        CLI/envvars
      * defined in external crate to keep clap out of our main build
      * organized by circ module, but not feature gated
         *  no point: the build wouldn't meaningfully change
      * includes a way to set the default field
* added circ::cfg::set and circ::cfg::cfg
   * also circ::cfg::set_default and circ::cfg::set_cfg
   * access a sync::once_cell, static configuration
* killed DFL_T

* workflows
   * unit-tested component probably need to not read circ::cfg::cfg.
   * compilers need to call circ::cfg::set or circ::cfg::set_default.

* rm dead features
2022-12-25 20:53:27 -08:00
Alex Ozdemir
05b793d565 Bugfixes: R1CS lowering (includes a soundness bugfix) (#124)
Fixes 4 bugs in R1CS lowering:
* division-by-zero in finite fields: previously, this always caused
  incompleteness. Now, the behavior depends on the CIRC_RELAXATION
  envvar:
  * CIRC_RELAXATION=incomplete: divide-by-0 causes incompletenes
  * CIRC_RELAXATION=nondet: divide-by-0 allows the output to take any value
  * CIRC_RELAXATION=det: divide-by-0 forces the output to 0
* bit-vector overshift: previously, this cause incompleteness. Now,
  we follow the semantics of SMT-LIB (the result saturates).
* bit-vector udiv-by-zero: previously, the output value was an
  unconstrained bit-vector. Now, it is MAX (following SMT-LIB).
* bit-vector comparisons: previously, the prover could lie, claiming
  that x < y when actually x >= y. All bit-vector comparisons are
  affected, including those in udiv and urem.
  * soundness bug!
2022-12-19 09:35:57 -08:00