zcash / halo2

The Halo2 zero-knowledge proving system
https://zcash.github.io/halo2/
Other
726 stars 494 forks source link

Any available chips / gadgets? #357

Closed dan-da closed 2 years ago

dan-da commented 3 years ago

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:

Our hope is that less expert users will normally be able to find an existing chip that supports the operations they need, or only have to make minor modifications to an existing chip. Expert users will have full control to do the kind of circuit optimizations that ECC is famous for πŸ™‚.

When implementing a circuit, we could use the features of the chips we've selected directly. Typically, though, we will use them via gadgets.

and also in issue #94:

Let's say that at some point we have a healthy ecosystem of third-party gadget implementations

...

An alternative approach would be to just depend on a Rust crate versioning policy for gadgets

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?

therealyingtong commented 3 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.

dan-da commented 3 years ago

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).

str4d commented 3 years ago

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.

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:

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 πŸ˜…

str4d commented 2 years ago

We now have the halo2_gadgets crate that provides chips and gadgets. #312 covers the documentation aspect.