57 Commits

Author SHA1 Message Date
wborgeaud
b97ec3bda1 New clippy lint 2022-10-25 10:50:40 +02:00
Daniel Lubarov
443a070003 Clippy fix 2022-10-08 14:09:18 -07:00
Hamish Ivey-Law
d7bb47318c
Modular operations for the EVM arithmetic unit (#755)
* First draft of 256-bit addition.

* Update comment.

* cargo fmt

* Rename addition evaluation file.

* Port ALU logic from SZ.

* Give a name to some magic numbers.

* `addition.rs` -> `add.rs`; fix carry propagation in add; impl sub.

* Clippy.

* Combine hi and lo parts of the output.

* Implement MUL.

* Suppress Clippy's attempt to make my code even harder to read.

* Next draft of MUL.

* Make all limbs (i.e. input and output) 16-bits.

* Tidying.

* Use iterators instead of building arrays.

* Documentation.

* Clippy is wrong; also cargo fmt.

* Un-refactor equality checking, since it was wrong for sub.

* Daniel comments.

* Daniel comments.

* Rename folder 'alu' -> 'arithmetic'.

* Rename file.

* Finish changing name ALU -> Arithmetic Unit.

* Finish removing dependency on array_zip feature.

* Remove operations that will be handled elsewhere.

* Rename var; tidy up.

* Clean up columns; mark places where range-checks need to be done.

* Import all names in 'columns' to reduce verbiage.

* cargo fmt

* Fix aux_in calculation in mul.

* Remove redundant 'allow's; more precise range-check size.

* Document functions.

* Document MUL instruction verification technique.

* Initial tests for ADD.

* Minor test fixes; add test for SUB.

* Fix bugs in generate functions.

* Fix SUB verification; refactor equality verification.

* cargo fmt

* Add test for MUL and fix some bugs.

* Update doc.

* Quiet incorrect clippy error.

* Initial implementation of ADDMOD and MOD.

* Fixes to addmod.

* Update doc.

* Do 1000 random tests instead of just 1.

* Documentation fix.

* Working version of ADDMOD.

* Working version of MOD.

* Name magic number; do multiple MUL tests.

* Add code and test for special case; add some docs.

* Fix spelling mistake.

* Simplify asserts.

* Tidy comment.

* Remove unused module.

* cargo fmt

* Check that output is reduced.

* Add conversion of canonical `i64` to a `Field64`.

* Handle zero modulus within degree constraint.

* cargo fmt

* Fix some comments.

* Check that the top half of the product is zero!

* Start of refactor.

* Refactoring.

* Remove zero and reduction handling from addmod.

* Refactoring; renaming; bug fixes.

* Reuse intermediate calculations across all modular operations; don't negate quot poly unnecessarily.

* Fix bug where last elt of q*m wasn't checked.

* Refactoring.

* Move circuit poly functions to utils.rs.

* Rename ADDMOD stuff to MODULAR.

* Rename module addmod -> modular.

* Handle zero modulus.

* Verify that output is reduced.

* Implement recursive version of modular circuits.

* clippy

* Tidy up i64 -> Field conversion following Jacqui's comments.

* cargo fmt

* Improved documentation.

* Address Jacqui's comments.

* Save some gates by using builder.arithmetic_extension().
2022-10-07 17:15:50 +11:00
Nicholas Ward
33d97eff1c moved sqrt to PrimeField 2022-09-26 11:31:11 -07:00
Nicholas Ward
a053372176 cleanup and documentation 2022-09-26 11:19:09 -07:00
Nicholas Ward
3bc1e65a7a fix 2022-09-26 11:11:41 -07:00
Nicholas Ward
4668e8c5f8 clippy 2022-09-26 10:45:20 -07:00
Nicholas Ward
59acd9436c fmt 2022-09-26 10:44:51 -07:00
Nicholas Ward
880bc87bb1 sqrt 2022-09-26 10:43:18 -07:00
wborgeaud
3007b5e779 Fix DTH_ROOT for degree 1 extension 2022-09-19 11:25:21 +02:00
wborgeaud
a930c1a823 s/l1/l0 2022-09-12 08:09:17 +02:00
Daniel Lubarov
2c77247d43 Keccak sponge STARK
It contains a row for each absorb step of the sponge.
2022-09-01 09:41:19 -07:00
Daniel Lubarov
e87392bdba comment 2022-08-22 11:32:36 -07:00
Daniel Lubarov
464b23297c Check each PolynomialValues len
I.e. that it is the length of some power-of-two subgroup.
2022-08-22 11:16:24 -07:00
Daniel Lubarov
3a6bbd825c
Merge pull request #677 from mir-protocol/u160_comments
Tweak comments
2022-08-19 18:28:49 -07:00
Daniel Lubarov
831a671872 Tweak comments 2022-08-19 10:35:02 -07:00
Daniel Lubarov
2fd5fbbe01 Change from_biguint's behavior with extension fields
These appear to be unused for extension fields, so we're free to change the mapping without breaking anything.

As the TODO says, the mapping that's currently implemented doesn't seem natural or useful. It seems more natural to treat the `BigUint` as a base field element, potentially in a non-canonical form.
2022-08-19 09:21:10 -07:00
Daniel Lubarov
a7618ef7df Merge branch 'licenses' 2022-08-16 09:01:16 -07:00
Daniel Lubarov
bf4e7ff3b7 Feedback 2022-08-15 17:17:05 -07:00
Daniel Lubarov
c56b7c8118 Expand inverse_2exp comment 2022-08-15 16:17:32 -07:00
Daniel Lubarov
faa75178a2 MIT + Apache2 licenses 2022-08-15 07:43:00 -07:00
Sladuca
e7216f2683 feature-gate rand 2022-08-06 11:35:41 -04:00
Daniel Lubarov
e7b480deaf Begin work on witness generation and kernel bootstrapping 2022-07-01 10:09:57 -07:00
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
Nicholas Ward
db6c3fd811 keccak stark 2022-06-07 10:57:06 -07:00
wborgeaud
c505c6759d Fix new clippy lints 2022-04-29 16:58:41 +02:00
Daniel Lubarov
0d118d0f49
STARK recursion timing info (#537)
* STARK recursion timing info

* clippy
2022-04-24 15:35:28 +02: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
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
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
Hamish Ivey-Law
f4ef692aad
Quintic extension fields (#489)
* Initial implementation of quintic extensions.

* Update to/from_biguint() methods.

* cargo fmt

* Fix call to test suite.

* Small optimisation in try_inverse().

* Replace multiplicative group generator and document requirement.
2022-02-16 10:38:24 +11: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
Daniel Lubarov
cfe52ad604
Add PrimeField, PrimeField64 traits (#457)
* Add PrimeField, PrimeField64 traits

* fix

* fixes

* fix

* `to_biguint` -> `to_canonical_biguint`
2022-02-09 21:50:18 -08:00
Daniel Lubarov
b40827e655
trim_to_len helper function (#472)
* trim_to_len helper function

Seems a little nicer IMO to only remove a certain number of zeros, vs removing all trailing zeros then re-adding some.

* PR feedback
2022-02-06 23:35:46 -08:00
Daniel Lubarov
8f21fddd04
Add a PolynomialValues::selector method for convenience (#470)
Also adds a test for `eval_l_1_and_l_last`.
2022-02-06 23:06:04 -08:00
wborgeaud
dd7808e3e6
Merge pull request #455 from mir-protocol/start_stark_verifier
Start of the STARK verifier
2022-02-03 12:15:31 +01:00
wborgeaud
bc5bc8245d PR feedback 2022-02-03 11:49:44 +01:00
Daniel Lubarov
43800ba23d
Rename PrimeField -> Field64 (#454)
* Rename `PrimeField` -> `Field64`

And add TODOs for moving around various methods which aren't well-defined in their current traits, or would be well-defined in a supertrait.

* fix test

* TODOs as per PR feedback
2022-02-01 22:40:19 -08:00
wborgeaud
8ab4f855b2 Add fri_challenges() to Challenger. 2022-02-01 17:02:11 +01:00
wborgeaud
984f44b281 Fix lde -> coset_lde bug 2022-02-01 14:41:27 +01:00
wborgeaud
92ea4b65d1 Constraint check working 2022-01-31 18:00:07 +01:00
wborgeaud
d54cc9a7c8 First try 2022-01-26 16:08:04 +01:00
Jakub Nabaglo
86dc4c933a
Make all FFTs in-place (#439)
* Make all FFTs in-place

* Delete leftover marker
2022-01-21 10:26:43 -08:00