Closed dan-da closed 2 years ago
We have a few gadgets in the Orchard repo: Poseidon, Sinsemilla, ECC addition and multiplication, and some utilities. These are used in the Orchard circuit.
Some of the gadget implementations are quite specific to Orchard (for example, ECC variable-base scalar mul only takes in a base field element as scalar). I think any plans to upstream them would involve more generic versions.
thx for the pointer. yeah it would be nice to see these extracted out into general purpose crate(s).
I find myself a bit unclear on the distinction between chips and gadgets. In particular:
So it would seem that "Gadget" is sort of a meta concept of a grouping of chips/circuits that exists mainly in the programmer's mind, or possibly in a namespace. Is that right?
Since they are referred to quite a bit in the book, perhaps the examples should comment about what constitutes a gadget (vs a chip).
So it would seem that "Gadget" is sort of a meta concept of a grouping of chips/circuits that exists mainly in the programmer's mind
Correct. From the outside, a gadget is the same kind of thing as in any other ZKP system: a common reusable unit that corresponds to some useful logical operation. However, in PLONK-style circuits there are a lot of low-level details that the top-level circuit builder might need to care about. We use the "Chip" abstraction to represent these.
Layouter
s through).The boundary between a Gadget and a Chip is therefore context-dependent; you need to decide how much of the logical operation makes sense to tightly control, and how much can just be implemented generically and reusably.
Take the Poseidon gadget as an example:
poseidon.rs
defines traits specifying the required instructions (permute
being the main one, and then some sponge-related instructions), and then implements the user-facing gadgets in terms of them.poseidon/pow5t3.rs
contains a chip that implements the instructions for a specific optimisation context: it requires 4 advice columns and processes two partial rounds per row (requiring a higher degree bound to do so).Someone with a different set of optimisation requirements (e.g. needing a lower degree bound, or reusing some of the internal Poseidon circuit logic for some other purpose) could implement their own chip that provides those properties, and then reuse all of the gadget logic we implemented.
Since they are referred to quite a bit in the book, perhaps the examples should comment about what constitutes a gadget (vs a chip).
We've had a long-standing issue to document this more clearly (#312) that we haven't had time for yet π
We now have the halo2_gadgets
crate that provides chips and gadgets. #312 covers the documentation aspect.
I was wondering if there are any chips or gadgets available besides those in the examples? in other crate(s) perhaps...
I see these quotes in the halo2 book that led me to believe this is intended:
and also in issue #94:
...
Under halo2/src, I do not see any chips or gadgets subdir. I was wondering if it is planned to have some defaults included with the crate? Or at least a sample gadget crate to kind of point the way for anyone interested in making one.
I guess a related question would be: where are the chips/gadgets that zcash itself uses?