432 Commits

Author SHA1 Message Date
wborgeaud
beb13af5ee
Merge pull request #363 from mir-protocol/reducing_ext_gate
Add `ReducingExtensionGate`
2021-11-15 20:47:03 +01:00
Daniel Lubarov
8ea6c4d392
Different implementation of RandomAccessGate (#360)
The previous code used an equality test for each index. This variant uses a "MUX tree" instead. If we imagine the items as being the leaves of a binary tree, we can compute the `i`th item by splitting `i` into bits, then performing a "select" operation for each node. The bit used in each select is based on the height of the associated node.

This uses fewer wires and is cheaper to evaluate, saving 31 wires in the recursion circuit.

A potential disadvantage is that this uses higher-degree constraints (degree 4 with our params), but I don't think this is much of a concern for us since we use a degree-9 constraint system.
2021-11-15 10:15:55 -08:00
Daniel Lubarov
239c795a9d
Address some more arithmetic gates that have unique constants (#361)
Saves 131 gates, though only when not using `PoseidonMdsGate`, so not relevant for the 2^12 branch.
2021-11-15 10:10:37 -08:00
wborgeaud
49e4307820 Comments + test for reducing 100 extension elements 2021-11-15 13:35:21 +01:00
wborgeaud
3efe2068bc Minor 2021-11-15 11:59:54 +01:00
wborgeaud
a54db66f68 Use arithmetic gate for small reductions 2021-11-15 11:39:24 +01:00
wborgeaud
d44cb96744 Merge branch 'main' into reducing_ext_gate 2021-11-15 09:22:35 +01:00
Daniel Lubarov
26a222bbdf
Fewer wires in PoseidonGate (#356)
Closes #345.
2021-11-14 11:57:36 -08:00
Nicholas Ward
4a5123de81 reduced test sizes 2021-11-12 12:12:58 -08:00
Daniel Lubarov
857b74bac5
Bring back the base field arithmetic gate (#343)
* Bring back the base field arithmetic gate

* fix
2021-11-12 09:48:27 -08:00
wborgeaud
72ef58c19d Add ReducingExtGate 2021-11-12 18:24:08 +01:00
Nicholas Ward
f2ec2cadf4 new fmt 2021-11-10 12:14:23 -08:00
Nicholas Ward
9043a47e1b more fixes 2021-11-10 11:15:00 -08:00
Nicholas Ward
ea4f950d6e fixes and fmt 2021-11-10 10:54:35 -08:00
Nicholas Ward
e838096940 use map; and TODOs 2021-11-10 09:58:16 -08:00
Nicholas Ward
a3d957fa42 addressed comment: more tests for multiple_comparison 2021-11-10 09:58:16 -08:00
Nicholas Ward
6705d81fbd nit 2021-11-10 09:58:16 -08:00
Nicholas Ward
5dd4ed3e1c addressed comments 2021-11-10 09:58:16 -08:00
Nicholas Ward
244543578b fixes to subtraction tests, and documentation 2021-11-10 09:58:16 -08:00
Nicholas Ward
f41c8ee16f fmt 2021-11-10 09:58:15 -08:00
Nicholas Ward
90178b2b0a many fixes 2021-11-10 09:58:15 -08:00
Nicholas Ward
9077c7fa3c BigUint arithmetic, and cleanup 2021-11-10 09:57:32 -08:00
Nicholas Ward
3fff08aa80 U32 subtraction gate 2021-11-10 09:53:29 -08:00
Nicholas Ward
6dd14eb27a comparison gate should also be <= 2021-11-10 09:53:29 -08:00
Nicholas Ward
26959d11c9 range-check the bits 2021-11-10 09:53:28 -08:00
Nicholas Ward
0ff6e6e0a0 fmt 2021-11-10 09:53:28 -08:00
Nicholas Ward
7e8c021b46 comparison gate 2021-11-10 09:53:28 -08:00
Nicholas Ward
ebcfde1d81 updates 2021-11-10 09:53:12 -08:00
Nicholas Ward
d334a924b4 merge new circuit builder stuff 2021-11-09 18:10:47 -08:00
Jakub Nabaglo
168f572804
Fix rustfmt failures on main (#348) 2021-11-09 14:52:05 -08:00
Daniel Lubarov
b2264752de
Optimize combination of gate constraints in recursive circuit (#342)
Just passing the "combined constraints" buffer into `eval_filtered_recursively`, so that we can combine a mul by the filter with an add into the buffer. Saves 56 wires.
2021-11-07 11:29:15 -08:00
Daniel Lubarov
671bb9be2e
Specialize InterpolationGate (#339)
* Specialize `InterpolationGate`

To cosets of subgroups of roots of unity. This way
- `InterpolationGate` needs fewer routed wires, bringing our minimum routed wires down from 28 to 25.
- The recursive `compute_evaluation` avoids some multiplications, saving 100~200 gates depending on `num_routed_wires`.

* Update test

* feedback
2021-11-05 09:29:08 -07:00
Daniel Lubarov
1450ffb29c
Small recursion optimizations (#338)
* Small recursion optimizations

Main thing is memoizing arithmetic operations. Overall savings is ~50 gates.

* feedback
2021-11-04 16:23:01 -07:00
Daniel Lubarov
fdce382af3
Standard configs (#337)
`large_config` was similar to `standard_recursion_config`; let's standardize on the latter.
2021-11-03 14:30:32 -07:00
Daniel Lubarov
e39af10a6b
More wires for ConstantGate (#332)
* More wires for ConstantGate

* fix

* fix
2021-11-02 14:41:12 -07:00
Jakub Nabaglo
bc57a561e6 Delete CrandallField 2021-11-02 12:29:26 -07:00
Daniel Lubarov
c6f91148d5
PoseidonMdsGate (#330)
PoseidonGate's recursive evaluations were using a lot of gates, and the MDS layer was the main culprit.

The other issue is that `constant_layer_recursive` creates a bunch of `ArithmeticGate`s with unique constants. We could either change `ArithmeticGate` to support different constants per operation, or wire in constants from `ConstantGate`, and change `ConstantGate` to support several constants per gate.

This won't really help anything near term since we're still between 2^12 and 2^13, but could have some benefits later, depending on what recursion arities and security settings we end up using.

`PoseidonMdsGate` needs `2 * D * WIDTH = 48` routed wires, and the combination of adding a gate and increasing routed wires slows down the prover a bit. So for now, I kept it at 28 wires, and the old code path is still used.
2021-11-02 08:16:28 -07:00
Jakub Nabaglo
bf421314f9
Batched eval_vanishing_poly_base (#317)
* Batched eval_vanishing_poly_base

* Reduce the number of allocations

* Lints

* Delete unused things

* Minor: fix a debug_assert

* Daniel PR comments

* Lints

* Daniel PR comments
2021-10-25 13:23:05 -07:00
Daniel Lubarov
806641d13f
Small optimizations (#319)
* Small optimizations

* Small optimizations

* feedback

* inline

* feedback

* fix unused import
2021-10-22 19:11:05 -07:00
Daniel Lubarov
7d45c80c03
Have eval_unfiltered_base call the normal Poseidon methods (#316)
* Have eval_unfiltered_base call the normal Poseidon methods

* fmt
2021-10-21 14:28:07 -07:00
wborgeaud
1f1827dae7 Clippy 2021-10-21 14:36:36 +02:00
wborgeaud
318185d1c0 Use only one BaseSumGate 2021-10-21 12:56:02 +02:00
Daniel Lubarov
22ce2da9e1
Add add_const, mul_const, mul_const_add methods (#312)
* Add mul_const, mul_const_add methods

To replace some arithmetic calls; I think it's easier to read.

* One more

* Couple more

* tweak

* tweak
2021-10-20 23:43:52 -07:00
wborgeaud
019ccf537b
Merge pull request #309 from mir-protocol/use_quadratic_extension
Generalize `RandomAccessGate` to allow using quadratic field extensions
2021-10-18 22:00:04 +02:00
wborgeaud
e24285c3b0 Separate random access generators 2021-10-18 21:48:40 +02:00
wborgeaud
5f4a244240 PR feedback 2021-10-18 21:38:57 +02:00
wborgeaud
c7674b24ba Unused imports 2021-10-18 17:27:22 +02:00
wborgeaud
dda14011c5 Forgot a random access check 2021-10-18 17:23:39 +02:00
wborgeaud
5b81006e9a Fill random access gates to make sure all generators are run 2021-10-18 17:11:59 +02:00
wborgeaud
3f0b5ab9d3 Keep track of the last used RAM gate 2021-10-18 16:48:21 +02:00