34 Commits

Author SHA1 Message Date
Daniel Lubarov
e73d01a037
packed_field -> packed (#584)
* `packed_field` -> `packed`

For cleaner imports; "field" is usually clear from context

* fix
2022-06-27 15:07:52 -07:00
Daniel Lubarov
3346d3f902
field_types -> types (#583)
* `field_types` -> `types`

Here too, I think "field" is usually clear from context, e.g. in `use plonky2::field::types::Field;`.

* fixes

* fmt
2022-06-27 12:24:09 -07:00
Daniel Lubarov
410e03349c
extension_field -> extension (#581)
It seems redundant in most contexts, e.g. `use plonky2::field::extension_field::Extendable;`. One could import `extension_field`, but it's not that common in Rust, and `field::extension` is now about as short.
2022-06-27 07:18:21 -07:00
wborgeaud
ccc9c024a2 Change some fn to take iterators instead of slices 2022-06-03 19:20:19 +02:00
wborgeaud
7676f907bf Missed some 2022-05-17 11:15:53 +02:00
wborgeaud
b606d99e07 Use *_circuit suffix for gadgets 2022-05-17 11:04:35 +02:00
Hamish Ivey-Law
ed3f0d546f
System Zero bit rotate and shift operations (#535)
* Complete versions of rotate left and shift left.

* Implement rotate/shift right.

* cargo fmt

* Fix documentation.

* Reduce visibility of helper functions.

* Address Jaqui's PR comments.

* Disable fall-through check as the run test assumes no failure here.

* Try to fix doctest failure.
2022-05-04 15:54:47 +10:00
Remco Bloemen
7769c269bf
Do not export global allocator (#533)
* Do not export allocator

* Make sure to use jemalloc in all downstream tests

* Update readme

* Remove test jemalloc boilerplate

* One more

* Fix clippies

* One more

* Clippy

Co-authored-by: Daniel Lubarov <daniel@lubarov.com>
2022-05-03 13:16:53 -07:00
Hamish Ivey-Law
76c86c55b3
System Zero binary bitwise operations (#529)
* First draft of bitwise AND.

* Refactor everything; add support for other binary bitops.

* Documentation; fix integration into rest of ALU.

* Allow `cargo fmt` to make code harder to read.

* Refactor following Jakub's suggestions.

* Fix variable name.

* Minor documentation.

* Basic tests.

* Address Daniel's PR comments.

* Remove the 'BIT' prefix from the BIT{AND,IOR,XOR,ANDNOT} names.

* cargo fmt/clippy

* Simplify bit test.
2022-04-08 14:54:33 +10:00
Daniel Lubarov
4fc6fdadd3
Stop suppressing unused/dead warnings globally (#527)
Most of them were trivial to address; for the remaining warnings I suppressed just the relevant line and added TODOs.
2022-03-31 22:53:47 -07:00
Jakub Nabaglo
06fef55bfb
u32 division (#517)
* First draft for division.

* `eval_division` work

* Division

* Minor: outdated fixme

* Tests and better column names

* Minor lints

* Remove redundant constraint

* Make division proof more formal

* Minor proof and comments

Co-authored-by: Hamish Ivey-Law <hamish@ivey-law.name>
2022-03-23 10:41:36 -07:00
Daniel Lubarov
7d6c0a448d
Halo2 style lookup arguments in System Zero (#513)
* Halo2 style lookup arguments in System Zero

It's a really nice and simple protocol, particularly for the verifier since the constraints are trivial (aside from the underlying batched permutation checks, which we already support). See the [Halo2 book](https://zcash.github.io/halo2/design/proving-system/lookup.html) and this [talk](https://www.youtube.com/watch?v=YlTt12s7vGE&t=5237s) by @daira.

Previously we generated the whole trace in row-wise form, but it's much more efficient to generate these "permuted" columns column-wise. So I changed our STARK framework to accept the trace in column-wise form. STARK impls now have the flexibility to do some generation row-wise and some column-wise (without extra costs; there's a single transpose as before).

* sorting

* fixes

* PR feedback

* into_iter

* timing
2022-03-16 17:37:34 -07:00
Daniel Lubarov
627e80bfd5
Filter mul-add constraints (#512) 2022-03-15 09:24:10 -07:00
Daniel Lubarov
7329dade94
IS_MUL -> IS_MUL_ADD (#510) 2022-03-02 22:49:57 -08:00
Hamish Ivey-Law
2644f5f74a
System Zero subtraction operation (#508)
* First draft of subtraction operation.

* Daniel comments.

* Fix constraint calculation.

* cargo fmt

* Align native and recursive eval functions; fix typo.
2022-03-03 14:18:19 +11:00
Daniel Lubarov
6072fab077
Implement a mul-add circuit in the ALU (#495)
* Implement a mul-add circuit in the ALU

The inputs are assumed to be `u32`s, while the output is encoded as four `u16 limbs`. Each output limb is range-checked.

So, our basic mul-add constraint looks like

    out_0 + 2^16 out_1 + 2^32 out_2 + 2^48 out_3 = in_1 * in_2 + in_3

The right hand side will never overflow, since `u32::MAX * u32::MAX + u32::MAX < |F|`. However, the left hand side could overflow, even though we know each limb is less than `2^16`.

For example, an operation like `0 * 0 + 0` could have two possible outputs, 0 and `|F|`, both of which would satisfy the constraint above. To prevent these non-canonical outputs, we need a comparison to enforce that `out < |F|`.

Thankfully, `F::MAX` has all zeros in its low 32 bits, so `x <= F::MAX` is equivalent to `x_lo == 0 || x_hi != u32::MAX`. `x_hi != u32::MAX` can be checked by showing that `u32::MAX - x_hi` has an inverse. If `x_hi != u32::MAX`, the prover provides this (purported) inverse in an advice column.

See @bobbinth's [post](https://hackmd.io/NC-yRmmtRQSvToTHb96e8Q#Checking-element-validity) for details. That post calls the purported inverse column `m`; I named it `canonical_inv` in this code.

* fix

* PR feedback

* naming
2022-02-21 00:39:04 -08:00
Daniel Lubarov
bc3685587c
Rename constraint methods (#497)
Most of our constraints apply to all rows, and it seems safest to make that the "default".
2022-02-20 16:48:31 -08:00
Daniel Lubarov
bedd2aa711
Rename arithmetic unit to ALU (#496) 2022-02-19 17:32:11 -08:00
Daniel Lubarov
72d13d0ded
Prover code for permutation argument (#485)
* Batch multiple perm args into one Z and compute Z columnwise

It's slightly complex because we batch `constraint_degree - 1` permutation arguments into a single `Z` polynomial. This is a slight generalization of the [technique](https://zcash.github.io/halo2/design/proving-system/lookup.html) described in the Halo2 book.

Without this batching, we would simply have `num_challenges` random challenges (betas and gammas). With this batching, however, we need to use different randomness for each permutation argument within the same batch. Hence we end up generating `batch_size * num_challenges` challenges for all permutation arguments.

* Feedback + updates for recursion code
2022-02-16 01:33:59 -08:00
wborgeaud
42d6532120 PR feedback 2022-02-15 08:35:57 +01:00
Daniel Lubarov
8d699edf21
Move some methods outside impl System (#484)
I didn't really have a good reason for putting there; seems more idiomatic to make them global since they don't need `self`/`Self`.
2022-02-14 13:47:33 -08:00
wborgeaud
7c71eb6690 Fix mul_add -> mul_sub typo 2022-02-11 10:25:51 +01:00
Daniel Lubarov
645d45f227
Column definitions for addition, range checks & lookups (#477)
* Column definitions for addition, range checks & lookups

I implemented addition (unsigned for now) as an example of how the arithmetic unit can interact with the 16-bit range check unit.

Range checks and lookups aren't implemented yet.

* Missing constraints

* Tweaks to get tests passing

* Reorg registers into files

* Minor
2022-02-10 12:05:04 -08:00
Jakub Nabaglo
efb1365021
Split system_zero::column_layout into submodules (#475) 2022-02-07 14:29:31 -08:00
Jakub Nabaglo
83a572717e
Implement Poseidon in system_zero/permutation_unit (#459)
* Implement Poseidon in system_zero/permutation_unit

* Minor cleanup

* Daniel PR comments

* Update dependencies
2022-02-04 16:50:57 -08:00
wborgeaud
1c30a5a84e Typo 2022-02-04 17:16:18 +01:00
wborgeaud
1011c302ac Add test for system zero 2022-02-04 16:02:45 +01:00
wborgeaud
d99cabded9 Working 2022-02-04 15:56:59 +01:00
wborgeaud
bff763e3e7 Add distinction between (non-)wrapping constraints 2022-02-02 11:23:03 +01:00
wborgeaud
1e04f4f5a4 Comments 2022-02-01 17:34:03 +01:00
wborgeaud
92ea4b65d1 Constraint check working 2022-01-31 18:00:07 +01:00
wborgeaud
e78630ae81 PR feedback 2022-01-28 05:02:31 +01:00
wborgeaud
1770e83c63 Clippy 2022-01-27 13:02:36 +01:00
Daniel Lubarov
c0ac79e2e1
Beginning of STARK implementation (#413)
* Beginning of STARK implementation

* PR feedback

* minor

* Suppress warnings for now
2022-01-26 00:09:29 -08:00