Commit Graph

147 Commits

Author SHA1 Message Date
William Seo
1fa5d91580 working taint analysis 2022-11-01 21:12:57 +00:00
William Seo
d909bf0fc7 Implemented vismap generation 2022-10-09 04:57:05 +00:00
William Seo
94b65fdd91 Cleaned up directory, changed test names 2022-04-27 06:29:08 +00:00
William Seo
6c590db47e Fixed linting issue 2022-04-26 01:00:00 +00:00
William Seo
cdc2ea8967 Merge branch 'fhe' of wys.github.com:circify/circ into fhe 2022-04-26 00:23:22 +00:00
William Seo
afd8bf200f Added support for addition, multiplication, and simple vectorized operations 2022-04-26 00:22:34 +00:00
Edward Chen
277c2c0394 Merge branch 'master' into fhe 2022-04-19 11:06:33 -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
William Seo
cb53d1a7e6 Deleted extraneous content. Fixed a bug 2022-03-31 06:05:34 +00:00
William Seo
2159c20ff3 Added building/testing for FHE backend 2022-03-31 05:13:24 +00: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
William Seo
3c3f2037d8 Fixed linting issue 2022-03-25 02:02:42 +00:00
William Seo
eb796061dc Removed extraneous code 2022-03-25 01:55:14 +00:00
William Seo
a66a508c98 Fixed Merge Conflicts 2022-03-25 01:28:06 +00:00
William Seo
248d746ca6 Updated backend to support SEAL interpreter 2022-03-25 00:59:56 +00: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
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
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
Edward Chen
8b4ff8ff93 Updating build system (#51) 2022-02-26 02:21:53 -05:00
Edward Chen
b9526234ac Updating build system (#44)
`python3 driver.py -h`
2022-02-25 17:13:10 -05:00
Ubuntu
b7b2491d78 Added Map to IR (evaluation and typechecking) 2022-02-25 21:04:37 +00:00
William Seo
0404c6e395 Implemented typechecking for Map IR 2022-02-25 01:51:01 +00:00
William Seo
1cb736f6df Merged with main 2022-02-21 20:26:28 +00:00
William Seo
3c59444ad7 Map Operation changed indices to bitvectors 2022-02-21 20:13:07 +00:00
William Seo
ea4b7ed5f2 Added Map operation to IR 2022-02-16 20:13:26 +00:00
Edward Chen
76539bf05d Function and Import support for C Frontend (#45)
Co-authored-by: Alex Ozdemir <aozdemir@hmc.edu>
Co-authored-by: Ubuntu <ubuntu@neptune2.maas>
2022-02-16 12:15:51 -05:00
Alex Ozdemir
2e9c70a32a IR textual format: parser & serializer. (#48)
For the love of test cases everywhere, and perhaps interop with other tools...

Floating-point support is incomplete.
2022-02-15 09:49:30 -08:00
Riad S. Wahby
52f793f3a0 feature branch: zsharp (#30)
* macos deps script (broken on M1 for now)

* arch dep should be coin-or-cbc

* ZoK 0.7.6 support megat status-commit

- bring in ZoK 0.7.6 libraries

- port in diffs from old thirdparty

- first-cut const and literal support

- add toposort for includes so that we can resolve const values in next pass

- statement handling, include-walking fix

- type should cover u64 case, too

- structs: store for now

- const handling

- flatten import map up-front to make later derefs easier to handle

- stash note

- need array consts, too

- rough in const array support, I think

- error message

- small cleanups: change type of ZGen::constants and make comments more meaningful

- generics in fn calls

- small: better error message

- need to resolve exprs as const in const_type_

- wip simple typing pass

- ast visitor wip

- zokrates ast visitor 1st cut

- double check that we cover all product types

- const typing visitor ; visitor error handling

- reorg visit_files ; unification infra wip

- unification infra wip

- need to walk accesses for an assignment

- walk_accesses wip

- small q

- refactor: data structs should be Hash(Hash), not flat

- walk_accesses wip

- monomorphize structs on LHS of declarations

- check identifiers when monomorphizing structs

- unification wip

- unification wip

- inline struct members must declare all fields

- unification for array_initializer

- unify postfix

- unify fdef with call

- ZExpressionTyper wip

- ZExpressionTyper wip

- ZExpressionTyper first cut

- type equality first cut

- type equality improved

- update struct handling

- stash note

- zok_fe trivial

- error msg fix

- params in scope during stmt visiting

- stash note

- and_then rather than unwrap in flatten_import_map

- handle special names (e.g. EMBED) in toposort

- types for EMBED

- EMBED is now a valid file in stdlib

- rewriter should handle Types, too

- need to rewrite literals on LHS of def stmts

- iteration: fix type of iter var

- for now, allow indexing with both Field and u*

- add warning for indexing with Field

- impl pow

- don't add ITE when unconditionally assigning

- oops, Uint takes bv_lit not pf_lit

- simplify

- fix arg order to bv_lit, improve new_<integral> functions

- use constant folding for term::const_int

- EMBED rework wip

- EMBED rework wip

- EMBED rework wip

- EMBED rework wip

- EMBED rework wip

- prep for generic inf push

- generic inf wip

- generic inf wip

- generic inf wip

- struct generic inference

- struct array inference wip

- make const_expr_ return Result<> rather than blowing up

- finish first-cut generic inf for Array

- turn on fn generic inf

- rework struct monomorphization code

- add support for const asserts

- process declarations lexically

    previously we'd processed all consts, then structs, then fns.
    now we want to add const initialization via function call,
    which is easiest to implement if we simply process declarations
    in-order as they appear in the file and require that all uses
    follow defs lexically.

    This seems to rule out mutual recursion, so we may want to revisit.

- add const initialization via ternary

- const fn call wip

- ZGen interior mutability

    this lets us call expr, const_expr_ without mut ref.
    this seems to be the right way to go here.

- small touches after rebase

- reorganize zvisit code

- generic lookup: should go through whole stack! (and not panic if stack is empty)

- wip bugfixes

- const_identifier_ should consult generics ; generic_lookup shouldn't traverse the whole stack

- expr type inf for array accesses

- small

- const_stmt_ infra

- const_stmt_ most var infra in place

- cvar_assign handles AssigneeAccesses now

- split type_ and const_type_ using const generics

- cvar_assign: build up list of accesses before resolving them, so that we don't try to double-borrow cvars_stack

- interpreter intf

- zoki --- zok interpreter front-end

- const_expr direct access vs through term impl

- very quick zsharp readme

- feature gate ILP back-end

    this makes it easier to build CirC on M1 macs (otherwise,
    need to build coin-or from source, which is not hard but
    is annoying)

- rename zokrates to zsharp

- heavy hitting stuff here

- update z# readme

- turn off ci for zsharp branch

- small

- add cfg to switch to bn254 curve

- zsharp readme quick

- struct consts

- handle literals on LHS of const decls

- typechecker: ! can take U*, too

- refactor typechecking in InlineStructExpression handling, const_eexpr_ (this is going to move, though)

- support inline structs in ZConstLiteralRewriter

- really turn of ci this time, don't just induce a failure

- don't build circ or opa_bench examples when 'lp' option is off ; fix example builds given renamed zokrates module

- unify_inline_array: respect array dims!

- better InlineArray len handling

- check fn return type

- small, plus a few tiny test cases

- redefinition is an error

- update thinking / status on uglinesses

- explicit generic literals are U32

- remove redundant typechecking in InlineStruct const expr handling

- array and struct equality

- generic-in-generic const test

- inline array and struct generic tests

- small

- sticky notes

- stash note

- small cleanup in zstmtwalker

- support ZSHARP_STDLIB_PATH envvar in ZStdLib

- get_field_size in EMBED ; field comparisons

- test runner

- hex literal fix

- inconsistent array test

- literals test

- TODO quick update

* generic inf refactor wip

* generic inf refactor

- keep plugging away at revamped generic inference

- generic inf refactor wip

- generic inf rework wip

- stash note about divrem

- generic inf wip

- build up one term rather than a vec; walk struct members; remove old crap

- small

- generic inf rework wip

- generic inf refactor wip

- partially hook up new generic inf

- zgenericinf: invoke solver, return result

- ZGenericInf hooked up

- stash a note

- find_unique_model function

- enable incremental mode for find_unique_model

- hook up find_unique_model in zgenericinf

* go over TODOs and small cleanup

* field %

- field to bv should use full width

- need to make sure MSB is 0 when lowering to R1CS\!

* update todos

* unify const and non-const code paths

- unify function_call and const_function_call

- unify stmt and const_stmt

- type_impl_ returns Result<>

- unify expr and const_expr

* update TODO

* rework after rebase

* fix circ example and clippies

* constant folding for array select and store

* cfold: Tuple and extend Eq

* more informative generic params error message in function call

* array accesses should be Field if not otherwise typed

* support Uxx array indexing (automatic type coercion) ; check array index and value for consistency

* tuple const folding

* stash note about array construction

* todos

* more todos

* IR tuple repr: use boxed slices rather than vecs

this enforces the invariant that tuple lengths cannot be changed

closes #39

* IR tuple typing checks

the value in a given tuple slot has a fixed type.
this invariant isn't fully captured right now---it's
up to front- and back-ends to enforce this.

[ EDIT: I think the above is wrong. `ir::term::ty::rec_check_raw`
  appears to enforce this. ]

I've added a couple extra safety checks for this.

* todo update

* const fold bvconcat and booltobv

* IR array key_sort and bounds checks

* array oob todos / tests

* ZGenericInf early exit for monomorphized calls

* self.unwrap cleanup

* cache generic inference results

* small debug/assert

* array construction optimization

when constructing an array, push leaf terms directly into the array
rather than building up a huge term. This reduces memory pressure and
reduces constant folding cost in the (common) case of large const
arrays

* todos

* clippy

* bit order consistency fix / tests

to_bits and from_bits functions use msb0 ordering
(i.e., index 0 of the bool array is the MSB)

* clippy small

* update TODOs

* clippy for zsharp frontend

* cargo fmt ; pretty-printing T

* add span for error context in expr and stmt

* update TODOs

* add s_divisible and s_remainder in 'field' in stdlib

* comment on signed field fns

* superfluous front-end example

* zxi unused imports

* zxc first cut

* zxc: in count mode, dump out constraints

* sidestep stack blowup in ir::term::ty::check_raw

* add option to skip linearity reduction in zxc with -L

* debug messages... darn

* lru caching for cfold

* unbounded/bounded cache

unbounded during a single fold_cache call, bounded between

* rebase fixes

feature gate aby back-end with lp
changes in zxi/zxc, and some clippies

* don't check-in non-top-level Cargo.lock

* increase LRU cache size for cfold to avoid n^2 behavior

* heuristic term/type cache collector

* tidy

* fmt

* small bugfix

* small fixes ; move zx_tests

* re-enable ci

* fmt

* tentative obliv-fix

* more obliv-fix

* clippy (for tests)

* Polish the obliv fix a bit. Document

* Addressing my unsolicited comment

* fix build

* typo

* stash Alex's idea about modeling RAM transformations

* back to upstream hashconsing

Co-authored-by: Alex Ozdemir <aozdemir@hmc.edu>

Co-authored-by: Riad S. Wahby <rsw@jfet.org>
Co-authored-by: Alex Ozdemir <aozdemir@hmc.edu>
2022-02-06 22:47:30 -05:00
William Seo
cfc2235d66 fhe and, or, xor test cases 2022-02-03 20:47:42 +00:00
William Seo
f644be097d Implemented the generation of the code for initializing SEAL parameters, encryption, making the server function call, decryption. 2022-01-27 22:46:30 +00:00
Alex Ozdemir
0eea91ea45 Remove un-needed casts (#42) 2022-01-20 14:46:02 -05:00
Edward Chen
75572c6a2c C Frontend (#22) 2022-01-20 10:16:27 -08:00
William Seo
e7cc59d676 Made new fhe folder in src/target 2022-01-17 17:39:13 +00:00
William Seo
83f34b2bf6 Made changes suggested by Alex 2022-01-14 00:25:00 +00:00
William Seo
8f15540509 Added SEAL library and FHE mode 2022-01-07 23:04:47 +00:00
Alex Ozdemir
a9fd7888c4 Resolve lints and add clippy to CI (#35)
`front::zokrates` is currently excluded
2022-01-01 12:27:36 -08:00
Alex Ozdemir
f2744e0c06 IR-based Zokrates front-end (#33)
The ZoKrates front-end now represents ZoK arrays as IR arrays, and ZoK structures as (type-tagged) IR tuples.

During this change, I discovered that IR support for eliminating tuples and arrays was not complete.

Thus the change list is:

    The ZoK front-end uses IR arrays and tuples
    Improve IR passes for array and tuple elimination
    Enforce cargo fmt in CI
    Bugfix: handle ZoK accessors in L-values in the correct order
    Bugfix: add array evaluation to the IR

This PR does not:

    implement an array flattening pass
    implement permutation-based memory-checking

Benefits:

    The ZoK->R1CS compiler is now ~5.88x faster (as defined by the time it takes to run the tests in master's scripts/zokrates_test.zsh script: this goes from 8.59s to 1.46s)
        For benchmarks with multi-dimensional arrays, the ZoK->R1CS compiler can now compile them with reasonable speed. Before it it would time out on even tiny examples.
    The ZoK->R1CS compiler will be able to benefit from future memory-checking improvements
    IR support for arrays and tuples is complete now, making those parts of the IR more accessible to future front-ends.

alex-ozdemir added 21 commits 11 days ago
2022-01-01 11:44:56 -08:00
Alex Ozdemir
aadd6b7c2d Make the SMT solver configurable. (#34) 2021-12-29 12:22:52 -08:00
Alex Ozdemir
81b364c2a7 Switch to stable (#32) 2021-12-19 22:35:02 -08:00