Commit 52cd668
authored
Merge pull request privacy-ethereum#178 from input-output-hk/dev-feature/gl-133-plonk-gate
Add generic arithmetic gate / Plonk gadget
# Project Context
This is a partial resolution of privacy-ethereum#58: that issue is concerned with creating a generic arithmetic gadget and using it where possible. Here we create the gadget, but only use it in a few places. Using it everywhere that makes sense will be a later PR.
The corresponding Galois internal issue is [Galois#133](https://gitlab-ext.galois.com/iog-midnight/halo2/-/issues/133).
# Issue Description
See privacy-ethereum#58.
This PR includes a generic arithmetic / Plonk gadget that provides an API that allows user to implement circuits without needing custom gates, or to directly work with layouters or regions. This is not a good match for unrolled loops (e.g. variable base scalar mul), where a custom gate gives a more efficient encoding. But for gadgets that are not used in a loop, the API provided here both simplifies the programming task and eases the review process.
To demonstrate the API, this PR includes refactoring of three existing gadgets to eliminate all their custom gates: the power-of-2 range check, the generic range check, and the $k$-high-low decomposition.
# Notes for Reviewers
This PR includes several different implementations of the internals, i.e. of the custom gates. I've left these intermediate states in the Git history so that reviewers can see that trying to do something closer to what's in the original Plonk paper doesn't work as well as what we end up with. The main reasons for the mismatch with the original Plonk paper are:
1) vanilla Plonk selectors take values over the whole field, but Halo 2 selectors are binary;
2) Halo 2 has an optimization called "selector combining" that combines multiple binary selectors into a single non-binary selector behind the scenes, but for this optimization to trigger, the selectors must be used in a restricted way.
See the commit messages along the way for details; I've attempted to keep the commits small and focused, with descriptive messages.
# Update
Via review feedback, we ended up with an implementation that is closer to the original Plonk paper, by using fixed columns to implement the selectors, instead of using the actual selector API. According to cost modeling, this is slightly more expensive than the implementation using simple selectors (via the standard the Halo2 selector API), where the selector combining optimization reduces them all to a single selector behind the scenes, but the difference is negligible.File tree
62 files changed
+1046
-1000
lines changed- book/src
- design/gadgets
- halo2_gadgets
- benches
- ecc_circuits
- examples
- goldenfiles/cost-model
- src
- ecc
- chip
- mul_fixed
- endoscale
- chip
- recursive_circuits
- ipa
- transcript
- utilities
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
62 files changed
+1046
-1000
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| |||
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
38 | | - | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| |||
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
| 67 | + | |
65 | 68 | | |
66 | 69 | | |
67 | 70 | | |
68 | | - | |
69 | | - | |
70 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
71 | 75 | | |
72 | 76 | | |
73 | 77 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
| 73 | + | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
162 | | - | |
| 162 | + | |
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
| |||
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
171 | | - | |
| 171 | + | |
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| |||
138 | 139 | | |
139 | 140 | | |
140 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
141 | 147 | | |
142 | | - | |
| 148 | + | |
143 | 149 | | |
144 | 150 | | |
145 | 151 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
383 | 384 | | |
384 | 385 | | |
385 | 386 | | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
386 | 392 | | |
387 | | - | |
| 393 | + | |
388 | 394 | | |
389 | 395 | | |
390 | 396 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
| 322 | + | |
322 | 323 | | |
323 | 324 | | |
324 | 325 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
0 commit comments