Skip to content

Understand how to optimize a circuit implementation of Groth16 verification #3425

@daira

Description

@daira

This ticket will be a discussion of optimizations for implementing recursive SNARKs.

For Groth16 verification we need pairings, and for pairings we need extension field arithmetic. Assume that the base field arithmetic is efficient in the circuit — which in practice requires it to be the same as the R1CS field. Call that field Fp. We'll use C to refer to the cost of an R1CS constraint.

Table 1 of Beuchat, González-Díaz, Mitsunari, Okamoto, Rodríguez-Henríquez, and Teruya gives costs for operations in Fp2, Fp6, and Fp12, using Karatsuba multiplication and squaring. (This part, and in fact most of the pairing algorithm, doesn't differ between BN and BLS curves.)

Let (a, m, s, d), (a~, m~, s~, d~), and (A, M, S, D) denote the cost of field addition, multiplication, squaring, and division in Fp, Fp2, and Fp6, respectively. This matches the paper except that we use "d" for division instead of "i" for inversion, since a division is its own operation which need not be decomposed into a multiplication and an inversion. In the circuit we have a = 0 and m = s = d = 1C.

Karatsuba is certainly optimal for multiplication and squaring in Fp2, so that gives m~ = 3C and s~ = 2C. [Edit: I was thinking of Complex squaring and calling it Karatsuba here.] Division (or inversion) can be implemented via multiplication: d~ = 3C.

It isn't clear to me that Karatsuba is optimal for the extension of Fp2 to Fp6. That gives 18C for multiplication, but I believe we can do it more efficiently by applying Toom-3 to get M = 5m~ = 15C. Note that the reduction from 5 Fp2 terms to 3 terms is linear, and so free. On the other hand, that appears to beat Montgomery's 17C here, so maybe I made a mistake. (Major impostor syndrome here :-p )

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-circuitArea: zk-SNARK circuitsA-cryptoArea: CryptographyC-researchCategory: Engineering notes in support of design choicesI-performanceProblems and improvements with respect to performance

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions