1752 Commits

Author SHA1 Message Date
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
wborgeaud
2cedd1b02a
Merge pull request #521 from mir-protocol/fix_inv_mod_xn
Fix inv mod xn
2022-03-21 06:13:06 +01:00
wborgeaud
163053b8fa Use truncate instead of drain 2022-03-21 05:34:36 +01:00
Daniel Lubarov
482dfe559a
Vectorize constraint evaluation in Starky (#520) 2022-03-20 08:58:23 -07:00
wborgeaud
3b767ca42f a_deg should be degree of a 2022-03-20 07:26:40 +01:00
wborgeaud
6a6414163a Fix inv_mod_xn 2022-03-20 07:23:51 +01: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
wborgeaud
660d785ed1
Merge pull request #515 from mir-protocol/fix_salt_issue
Fix salt issues
2022-03-16 03:40:59 +01:00
Daniel Lubarov
627e80bfd5
Filter mul-add constraints (#512) 2022-03-15 09:24:10 -07:00
wborgeaud
cc9a43b574 Fix salt issues 2022-03-15 17:14:45 +01:00
Hamish Ivey-Law
310493c293
Faster extension field multiplication (#500)
* Initial implementation of quintic extensions.

* Update to/from_biguint() methods.

* Draft of fast multiplication on quintic extensions over 64-bit base.

* cargo fmt

* Typo.

* Document functions (a bit).

* Refactor reduction step.

* Change multiplication call so that LLVM generates better assembly.

* Use one main accumulator instead of two minor ones; faster reduce.

* Use one main accumulator in square too; clean up redundant code.

* Call faster routines from Mul and Square impls.

* Fix reduction function.

* Fix square calculation.

* Slightly faster reduction.

* Clean up names and types.

* cargo fmt

* Move extension field mul/sqr specialisations to their own file.

* Rename functions to have unique prefix.

* Add faster quadratic multiplication/squaring.

* Faster quartic multiplication and squaring.

* cargo fmt

* clippy

* Alternative reduce160 function.

* Typo.

* Remove alternative reduction function.

* Remove delayed reduction implementation of squaring.

* Enforce assumptions about extension generators.

* Make the accumulation variable a u32 instead of u64.

* Add test to trigger carry branch in reduce160.

* cargo fmt

* Some documentation.

* Clippy; improved comments.

* cargo fmt

* Remove redundant Square specialisations.

* Fix reduce*() visibility.

* Faster reduce160 from Jakub.

* Change mul-by-const functions to operate on 160 bits instead of 128.

* Move code for extensions of GoldilocksField to its own file.
2022-03-04 09:34:31 +11: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
Nicholas Ward
6b386e756a
Merge pull request #503 from mir-protocol/ecdsa_target_visibility
ECDSA targets visibility
2022-02-24 12:44:03 -08:00
Nicholas Ward
bd7f43adc2 visibility 2022-02-24 10:19:16 -08:00
Nicholas Ward
7b4ddf852c
Merge pull request #502 from mir-protocol/ecdsa_secret_to_public
ECDSA secret_to_public fn
2022-02-24 10:09:08 -08:00
Nicholas Ward
383b8b68b3 secret_to_public fn 2022-02-24 10:01:38 -08:00
wborgeaud
517d26e4c1
Merge pull request #499 from mir-protocol/stark_permutation_checks
Stark verifier permutation checks
2022-02-23 09:56:02 +01:00
wborgeaud
dd4cc21309 PR feedback 2022-02-23 09:36:28 +01:00
wborgeaud
8c5cbbc7c6 Add first row Z check 2022-02-22 17:40:48 +01:00
wborgeaud
17bbc6f3e4 Minor 2022-02-22 17:30:08 +01:00
wborgeaud
a31c58b69d Use ReducingFactor 2022-02-22 17:23:55 +01:00
wborgeaud
150d764440 Simplification 2022-02-22 17:00:08 +01:00
wborgeaud
4ea418a486 Clippy 2022-02-22 16:35:20 +01:00
wborgeaud
064b3c07a8 Forgot to set permutation cap 2022-02-22 16:18:41 +01:00
wborgeaud
6cd2fc62b5 Should work (does not) 2022-02-22 11:44:24 +01:00
wborgeaud
ed4aef0fa0 Fill permutation todos 2022-02-22 10:46:51 +01:00
wborgeaud
56e269e27a Working (not recursively) 2022-02-22 10:37:08 +01:00
Jakub Nabaglo
c7af639579
Restore vectorization to full Poseidon rounds on Aarch64 (#498)
* Restore vectorization to full Poseidon layers on Aarch64

* Typos
2022-02-21 17:45:01 -08:00
wborgeaud
85c1e1d5e0 Should work (does not) 2022-02-21 18:00:03 +01:00
wborgeaud
5c1173379e Compiles 2022-02-21 16:05:24 +01:00
wborgeaud
79ba85eb08 Compiles 2022-02-21 10:52:04 +01:00
wborgeaud
f4a29a0249 Merge branch 'main' into stark_permutation_checks 2022-02-21 10:19:12 +01:00
wborgeaud
d52fabaf26 First pass 2022-02-21 10:18:05 +01: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
wborgeaud
9516e14c3e
Merge pull request #491 from mir-protocol/fix_reduction_strategy
Fix reduction strategy
2022-02-18 17:07:03 +01:00
Jakub Nabaglo
a736aa8e70
Update MDS matrix and round consts in Poseidon; disable vectorization (#493) 2022-02-17 22:01:07 -08:00
wborgeaud
67cb5dfd58 PR feedback 2022-02-17 08:26:23 +01:00
Daniel Lubarov
431faccbdb
Change compute_permutation_z_polys to batch permutation checks (#492)
* Change `compute_permutation_z_polys` to batch permutation checks

* feedback
2022-02-16 23:37:20 -07:00
wborgeaud
56336e396d Fix 2022-02-16 14:17:14 +01:00
wborgeaud
ea9006f52e Add rate_bits 2022-02-16 13:51:10 +01:00
wborgeaud
c9185d92bb Merge branch 'main' into fix_reduction_strategy
# Conflicts:
#	starky/src/prover.rs
2022-02-16 13:38:54 +01:00
wborgeaud
b28cd55326 Fix reduction strategy 2022-02-16 13:37:01 +01: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
c6f80ba59a
Merge pull request #490 from mir-protocol/batchable
Simplify batched gate code
2022-02-16 09:36:47 +01:00
wborgeaud
f8dfc3986b PR feedback 2022-02-16 09:26:16 +01:00
wborgeaud
08e255a2bb Remove params in GateInstance 2022-02-16 09:02:21 +01:00
wborgeaud
661a6b44ef Delete GMiMC files 2022-02-16 08:33:52 +01:00