Thanks to Zac Williamson and Kev for explaining ideas that helped form this document. Thanks to Han for spotting a mistake in "Approach 2" of the MiMC custom gate that could lead to breaking soundness.
PLONK has flexible arithmetization, and can quite easily express complex polynomial gates. "Basic PLONK", as defined in the paper, defines only fan-in 2 arithmetic gates. The purpose of this document is to show what are custom gates and how they affect the performance of a PLONK proof.
At a high level, PLONK defines the gates as part of a "quotient polynomial" - if this polynomial is zero at the points that represents gates, then the constraint system is satisfied.
The arithmetic gate contribution to the quotient polynomial is defined as:
For example, a multiplication gate that calculates is going to have:
"Basic PLONK" has the following performance characteristics:
Given being the number of arithmetic gates, basic PLONK has a quotient polynomial of degree . The arithmetic gate part itself has only degree , and the degree stems from the permutation argument on the wire polynomials.
When designing a custom gate, you can change multiple characteristics.
If you're introducing a new polynomial gate on existing wires, you affect:
If you increase the degree of the quotient polynomial, you will affect:
Additionally, you pay a scalar multiplication in verification for each selector polynomial you introduce.
If you're introducing adjacent wires (), you need to add the opening of these values at , so 1 additional field element for each of the required openings, but no significant increase in prover/verifier times - the prover needs to evaluate at the new points, and the verifier already has a polynomial commitment opening at , so it folds into that
If you want access to more wires, e.g. , you similarly needs an opening at , so 1 additionaly field element for each of the required openings. The prover similarly to the adjacent wires case needs to evaluate at additional points. There is another significant cost increase for both the prover and the verifier though - the prover needs to commit to the opening polynomial at , which is another degree exponentiation and an additional group element in the proof, and the verifier has to open it, requiring an additional scalar multiplication.
If you'd like to introduce additional wires above , you could do it in multiple ways.
One way is to introduce wires that are accessible throughout all the gates - introduce more degree polynomials, e.g. and so on. This would cause:
Another way is to introduce wires that are accessible only for half of the gates, i.e. for the use in exotic gates.
Zac wrote about it:
The trick is to add a second verification equation for your basic plonk gates.
Split each degree-n A(X), B(X), C(X) into two degree n/2 polynomials A1(X), A2(X), B1(X), B2(X), C1(X), C2(X).
Also do this splitting process with the selector polynomials Qm(X), Ql(X), Qr(X), Qo(X), Qc(X).
In addition to the original plonk gate equation, add a second:
Qm2(X).A2(X).B2(X) + Ql2(X).A2(X) + Qr2(X).B2(X) + Qo2(X).C2(X) + Qc2(X) + 0 mod Z_H(X)
You can then add in additional verification equations for exotic gates with 6 wires.
Because the degrees of your polynomials are half what they used to be, prover compute times haven’t increased (2x the polynomials, but the degrees have been halved).
The permutation check now operates on six witness polynomials instead of three - so the maximum degree of your quotient polynomial is still degree 3n.
This also gives you some extra wiggle room - your exotic 6-wire gate equation can be a degree-6 polynomial, without increasing the degree of the quotient polynomial
The trade off with all of this, is increased verification time and increased proof size - each new selector polynomial and each new wire commitment will add 1 scalar mul into the verification equations, which starts to add up
To calculate a MiMC7 round function for round , we need to calculate , where are inputs and is a constant
We would define the following gates:
In total, 5 constraints.
We augment the quotient polynomial with the following contribution:
This makes the quotient polynomial of degree .
Assuming we're still using the fast-proving method, this adds 2 scalar multiplications for the verifier, for the two new selector gates. The verifier also pays by 4 additional scalar multiplications because of the 4 degree increase in the quotient polynomial.
The proof becomes larger by 4 group elements.
We augment the quotient polynomial with the following contribution:
This gate works by verifying that contains the , and proceeds to put in .
The random coefficients enforce that each individual term will be .
This doesn't increase the quotient polynomial degree, and thererfore proving times are similar - only a few more evaluations.
We pay in:
We've listed a few methods to use the flexibility of the arithmetization step and listed different trade-offs a custom gate designer can take, together with an example of a MiMC7 gate.
We hope that this note proves useful for those learning and using custom gates.