Commit Graph

188 Commits

Author SHA1 Message Date
Edward Chen
f1dbab65ab Function Abstractions (#113)
Initial commit for support function abstractions.

`Computations` are maps of function names `str` to computation `Computation`. 

Updates:
- Frontend `Gen` returns `Computations` with only a single main `Computation`.
- Optimizations take in `Computations` instead of a single `Computation`. Optimizations are applied to each `Computation`. 
- Backends take in only the main `Computation`.
2022-10-18 21:27:58 -04:00
Edward Chen
fbbef279e0 Refactored C Frontend to use helper functions to interact with Circify methods (#112)
- Wrapped Circify behind a RefCell
- refactored methods to Circify
2022-10-18 13:04:21 -04:00
Edward Chen
a6bedd4f2d Boilerplate for C AstWalker (#109) 2022-10-18 10:14:03 -04:00
Evan Laufer
84b2f33e5f Update pest parsers to use PrattParser (#108)
pest::prec_climber has been deprecated.
also, fix some clippy lints
2022-10-13 11:25:46 -07:00
Edward Chen
e2edbadd0d Clone audit of the C frontend (#106) 2022-10-12 11:55:44 -07:00
Edward Chen
30c88d55f3 Rotation IR intrinsic for SIMD FHE operations (#107) 2022-10-09 00:11:17 -04:00
Alex Ozdemir
c1bac11486 Broader SHA bitwise ITE optimization (#104)
It detects bitwise BV ITEs expressed using and XOR/OR of ANDs with a
NOT. Now it triggers more often.

This cuts a few percentage points (~10%) worth of constraints on ZoK's
shaRound circuit.
2022-09-12 17:20:20 +02:00
Alex Ozdemir
f6c37b505b R1CS scalability bugfix (#102)
Reduce Restrict::restrict_to_inputs from n*n to n

It needs to compute the set of terms which only on inputs in S.
It did this via *separate* containment checks for each term.
But, of course, there is a simple graph traversal that does O(1) work
per term.
I'm taking this patch now b/c I need it. All credits to Evan.
It passes our ZK tests, and a wrote a few unit tests.

Co-authored-by: Evan Laufer <evan.m.laufer@gmail.com>
2022-09-12 16:56:19 +02:00
Alex Ozdemir
15eadb6110 Fix Linter Warnings (#103) 2022-09-12 16:04:23 +02:00
Alex Ozdemir
4686854248 fmt (#98) 2022-08-12 07:32:57 -04:00
Alex Ozdemir
05ca4eda11 bv uext in smt output (#97) 2022-08-12 07:07:34 -04:00
Riad S. Wahby
20198e9012 add.c: mpc_main -> main (#96) 2022-08-03 17:38:18 -04:00
Alex Ozdemir
e362f9501b change ffOP to ff.OP in SMT backend (#94) 2022-08-01 17:12:04 -07:00
Alex Ozdemir
59d5087ab0 lint (#93) 2022-07-27 13:26:04 -07:00
Alex Ozdemir
106af9e016 integer constant folding (#92) 2022-07-27 13:16:06 -07:00
Alex Ozdemir
0b3c936a40 Integers (#91)
We already had sorts and values. Now we have operators too. These are only really in the SMT backend right now.
2022-07-26 15:12:14 -07:00
Alex Ozdemir
2d0709342e bugfix: pfadd->pfmul (#90) 2022-07-22 09:01:18 -07:00
Alex Ozdemir
8bd4dbaeed ZoKrates assertion bugfix and option to isolate (#89) 2022-06-23 22:14:58 -07:00
Alex Ozdemir
0658102675 RAM extraction (#88) 2022-06-23 07:33:34 -07:00
Alex Ozdemir
e9b777f40e r1cs: lift r1cs to IR term (#87) 2022-06-17 20:12:45 -07:00
Alex Ozdemir
526f5c8675 smt: ff writing & SMT2 query writer (#86) 2022-06-17 16:28:21 -07:00
Edward Chen
f88379f96f Updated binarize optimization pass (#85) 2022-05-23 23:59:03 -04:00
Edward Chen
7693d30975 Updates to C Frontend (#67)
Supporting:
- structs
- ptrs
- n-dimension arrays
- nested structs
- typedef
- sizeof
- shift operations

Benchmarks:
- Original HyCC kmeans testcase (without recursion).
- Original HyCC gauss testcase.

Co-authored-by: Alex Ozdemir <aozdemir@hmc.edu>
Co-authored-by: Ubuntu <ubuntu@neptune2.maas>
2022-05-20 02:20:36 -04:00
Alex Ozdemir
c1293464d2 Precomputations (or, as-known-for-proofs, witness extension) (#80)
Co-authored-by: Riad S. Wahby <rsw@jfet.org>
2022-05-17 08:54:04 -07:00
Alex Ozdemir
2537f4708e function calls (#83) 2022-05-16 09:12:37 -07:00
Riad S. Wahby
028f747f4d concurrency fixes for garbage collection (#81)
* concurrency fixes for garbage collection

* COLLECT lock even when not testing
2022-05-07 17:20:27 -07:00
Alex Ozdemir
fa671673a8 Bugfix: non-recursive type-checking for Op::Map (#82)
Credits to @kwantam for noticing the bug. Thank you!
2022-05-07 12:31:37 -07:00
Riad S. Wahby
a3fa232ba2 improve memory consumption ; add Z# strict unary op, ternary ?:, and type aliases (#77)
* update TODO

* add quiet mode to zxc

* Drop and garbage collection

This commit adds Drop instances and related functionality that force
garbage collection at life cycle end of various structs that contain
Terms.

I didn't implement Drop for Computation because its Terms are generally
moved into a converter. This means that back-ends are responsible for
garbage collecting (see new functionality in ILP, R1cs, and ABY).

* collect the cfold table, too

* prevent double-panic as a result of garbage_collect()

* z# parser: zx is a default extension too

* update Cargo.lock

* strictness un-op #()

also added err messages for asserts and ?: ternary support from ZoK upstream

* for assignments, strict rhs => strict lhs

* zsharp: type definitions WIP

Still missing monomorphization.

* type defns: generic inference

* struct monomorphization for type aliased structs

* different approach: no monomorphization, just canonicalize aliases

* canonicalize struct names

* typedef tests

things work except that importing an alias and not its referent breaks typechecking

* add error message about needing to import referent structs

* update hashconsing pointer in Cargo.toml

* maybe_garbage_collect should also return early when panicking

Co-authored-by: Alex Ozdemir <aozdemir@hmc.edu>
2022-05-04 10:08:23 -07:00
Edward Chen
4b01634d7d Type checks for ABY translation (#76) 2022-04-19 21:32:36 -04:00
Alex Ozdemir
157370f307 Eliminate tuples with persistent vectors (#75)
Change: The tuple elimination pass now represents its *tuple trees*
using nested persistent vectors of non-tuple terms, rather than standard
terms.

Rationale: When large oblivious arrays are transformed to tuples, said
tuples are large, and updates to them use the tuple update operator.
However, when we eliminate those tuples, we essentially replace the
update operator with an explicit tuple (tree). For a large number of
updates, this entails quadratic memory usage.

Of course, it doesn't *need* to: each update only modifies one spot in
the tuple.

Thus, in this patch, we change the representation of tuples in tuple
tree from a standard term---whose children are in a vector---such that
the children are now in a persistent vector from the `im` crate. This
allows for an "update" operation on the vector that takes log time and
log new space.

Effect: This reduces the compiler's memory usage on
`examples/C/mpc/benchmarks/2pc_biomatch_40x.c` from ~28GB to ~1GB. It
also makes the compiler substantially faster on that benchmark.
2022-04-11 13:13:58 -07:00
Alex Ozdemir
0b42f26089 Improve non-recursive type-checking (#74)
In *non-recursive* type-checking, perhaps better called *type computing*
we perform a minimal traversal in order to compute the type of a term,
without recursively type-checking it. Informally, we assume it is well
typed, and do the minimal amount of work needed to compute its type.

Two improvements:
1. No longer implemented with recursion.
2. Caches all intermediate results.

Implementation:
* `check_dependencies(Term) -> Vec<Term>`: maps a terms to the immediate
  children of it whose types are needed to compute its type.
* `check_raw_step(Term, TypeTable) -> Sort`: assumes those children have
  their types in the table, and computes this term's type.
* `check_raw`: glues the two above functions together into a suitable
  traversal. Similar to `rec_check_raw`, but the traversal isn't total.

Significance:

Previously, we had a non-recursive implementation for array stores that
*didn't cache intermediate results* which could cause quadratic
type-checking time (if the type-check callee was doing a top-down
traversal). Edward sent me a benchmark that was experiencing this,
resulting in 74.1% of total compilation time being spent type-checking.
Now it's down to 0.4% of total compilation time.
2022-04-11 11:41:02 -07:00
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
Edward Chen
2052869261 Removing old ABY dependency (#63)
* removing EzPC dependency
* removing old ABY dependencies
2022-04-07 14:03:27 -04:00
Edward Chen
63e3bea1b8 Adding benchmark scripts and logging for ABY backend (#72) 2022-04-06 04:04:52 -04:00
Edward Chen
ffa2ac3dc9 Updated ABY tests to ignore logging code (#71) 2022-04-05 02:08:40 -04:00
Alex Ozdemir
c784bf7054 Typo in CSE project 2022-03-27 20:24:20 -07:00
Alex Ozdemir
bdd3c59a3c Two write-ups (#68) 2022-03-27 18:45:03 -07:00
Riad S. Wahby
8c8e704914 field flexibility ; add limit for linearity reduction (#66)
Co-authored-by: Alex Ozdemir <aozdemir@hmc.edu>
2022-03-25 15:03:09 -07:00
Edward Chen
13f9a092b5 Updated ABY VM to include IN bytecode instruction (#65)
- updated ABY interpreter to include IN gates
- Added tqdm requirement
2022-03-24 15:53:44 -04:00
William Seo
8bceb9a2f2 Merge pull request #55 from circify/IR_Map
Added Map to IR (evaluation and typechecking)
2022-03-17 15:09:40 -04:00
Alex Ozdemir
0d61d45a65 add flamegraph action (#59) 2022-03-10 09:16:40 -08:00
Ubuntu
9462866a34 Fixed linting issues 2022-03-10 07:17:05 +00:00
Ubuntu
0fe65aa6a0 Fixed formatting issue 2022-03-10 05:42:51 +00:00
Ubuntu
90340d89d7 Made edits based on the comments 2022-03-10 05:18:35 +00:00
Edward Chen
9b9a689321 removing EzPC dependency (#58) 2022-03-08 11:04:52 -05:00
Ubuntu
6d8b69c69f Merge branch 'master' into IR_Map 2022-03-06 21:21:36 +00:00
Alex Ozdemir
eaf451e651 Kill dead file (#56) 2022-03-05 02:05:23 -08:00
Edward Chen
8fed29bd32 ABY VM and Interpreter (#47)
Updated ABY testing framework with an ABY bytecode and interpreter
2022-02-28 19:47:50 -05:00
Ubuntu
e3bafe07e9 Ran the linter and formatter 2022-02-28 04:36:48 +00:00
Edward Chen
f66b14a702 Updating build system - 2 (#54)
Fixed linting error
2022-02-26 17:33:22 -05:00