Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Writing Kishu circuits

Kishu’s Arithmetization defines what a node’s circuit is written over: a witness of bits and tribits, and constraints of degree two over them. This page is about expressing a computation in that arithmetization, and what it costs.

Nothing on this page is part of Kishu as a proof system. How a value is held in digits, how a hash is laid out, and how arithmetic in a field larger than Kishu’s own is checked are techniques, and a circuit’s writer may use others. The page describes the ones that the study’s circuits use and that its model prices. Every figure is the model’s (Regenerating the Study’s Numbers).

What the writer pays

As a rule of thumb, costs are counted in doodads, a unit of a little under four word multiplications on the prover. A bit costs 4 doodads and a tribit 7: one for the digit’s commitment, and three or six for its range check. With zero knowledge a digit costs half a doodad more. A transaction with zero knowledge also pays for its mask once: 14 doodads for each digit of the length of the step that it hands off, whatever that step holds. A product term of a constraint costs 4.5 doodads, which covers its coefficients. Where a constraint’s linear combinations are very large, its terms are counted at 2.5 doodads and its nonzero coefficients at half a doodad each. A rough cost model has the costs that the rule approximates, with those of a step and of the merge.

The rule is for a step that proves its digits’ range by the sum-check, as every step with zero knowledge does. Without zero knowledge the frontier page’s best configurations use the projection instead. There a bit costs 2.1 doodads and a tribit 5.3, and a merge costs about 54 million, 2.8 times the sum-check form’s at the same step length.

At the frontier page’s rate of 3 billion word multiplications a second on one core, a doodad is about 1.3 ns, so a million doodads are about 1.3 ms of single-core work for the prover. Proving should scale very well across multiple cores, but Kishu is not yet implemented and so this has not been demonstrated.

A nonzero coefficient costs less when it is small, as are the powers of two that assemble a word from its digits. A sum-check could take higher degrees at a cost per degree, but the model charges degree two. Fusing Keccak’s steps into cubic constraints was found not to pay; a term of higher degree costs an intermediate witness value instead.

Choosing a digit’s width

A digit’s width is the writer’s choice, position by position. A value that is a factor of a product needs the width the product needs: a bit, in the hashes. A value that enters constraints only through linear combinations is written in tribits. That is any integer word: a limb, a quotient, a carry, an amount, or an element of . Bits take the remainder if the width is not a multiple of three. The commitment, the fold, and the mask cost the same per digit at either width.

The range check is what makes a wider digit cost more, and a wider digit is still the cheaper way to hold a value. By the rule of thumb, three bits cost 12 doodads, and a tribit that holds them costs 7. With zero knowledge that is 13.5 against 7.5.

A wider digit also helps zero knowledge indirectly, in a way that the rule’s figures for a digit do not show. The mask’s cost follows the step’s length in digits, and three bits are three digits where a tribit is one. If circuits have fewer digits in general, a shorter step holds them without more merges, and the mask shrinks with the step. Where the step’s length follows the circuits’ digits, that is up to 14 doodads for each digit saved, which is more than any digit’s own cost.

Words and integer arithmetic

A word of  bits is a linear combination of its digits, which costs nothing to form. Bit vectors of any fixed length can be represented directly, as can elements of (non-canonically, in 22 digits). A range check is free: a value held in digits of  bits in all is below by construction.

Since a word is a linear combination in certified digits, a relation holds over the integers whenever it holds in , provided that its two sides, as integers, both lie in a range no larger than , so that they cannot differ by a multiple of . That is how integer arithmetic is written. Adding a value in to one in is safe whenever , for example. A 32-bit addition is with the sum and the carry committed, and a comparison is a subtraction’s carry. A multiplication of two words costs one product term; a constant costs by its nonzeros.

Bit operations

Bit operations are a term each: XOR is and AND is ; rotations and shifts are wiring and cost nothing. A result needs committing only where it is a factor of a later product. A result used linearly, as an addend or as a hash’s output, stays an expression inside the constraint that uses it. In a chain of XORs every other word is committed, each certified against both XORs’ inputs at once at two terms a bit. A third XOR in a chain would need degree three. Bitwise operations keep bits: tribits have no degree-two XOR.

Costs

The costs of the operations above and of the higher-level ones built from them, by the rule of thumb of Kishu’s cost model, each to a whole doodad. A digit is one committed bit or tribit. A term is one product term of a constraint. The rows are in increasing order of doodads without zero knowledge. The last column is a circuit’s own cost with zero knowledge, in whichever step it sits. A transaction’s mask is not in it: that is 14 doodads for each digit of the length of the step that is handed off, once. The sections after the table say how the higher-level counts are obtained.

WhatDigitsTermsDoodadsWith zk,
less the mask
a 32-bit addition331136153
a 32-bit addition of three addends341140158
an XOR of two 32-bit words, uncommitted032, inside the constraint that consumes it144144
a multiplication in , its result committed221156166
an XOR of two 32-bit words, committed3232272288
the same, where the next XOR’s word is left uncommitted3264416432
a Pasta value, as tribits85595638
a Pasta multiplication by the fingerprint route17031,2041,288
a Pasta multiplication by the limb route374983,0083,195
a Sinsemilla chunk22261012,33312,444
a Poseidon permutation over 276 × 2227642,91845,954
a BLAKE3 compression11,34411,12095,416101,088
a BLAKE2s compression16,09616,032136,528144,576
a BLAKE2b compression38,52838,272326,336345,600
a Keccak-f[1600] permutation, as in SHA-392,160184,3201,198,0801,244,160
the recovery circuit by the fingerprint route2.3 million19.3 million20.4 million
the recovery circuit by the limb route4.3 million37.7 million39.9 million

So the circuits that suit Kishu are the hash-heavy ones.

Filling a step

A step is one committed witness of a chosen length in digits, with one evaluation claim, since the constraints are a sum-check over the whole table. The frontier page’s configurations are at lengths from to  digits. A transaction’s first step holds the application alone. In each later step the merge’s digits take the first part, and the application’s nodes fill the rest, as many as fit, as the Zoodles page’s packing shows. Zero knowledge asks nothing of the circuit’s writer: the scheme hides the witness, and no randomizer or blinding wire is needed.

Three costs follow a step’s length and not the circuits in it: the zk mask, the merge, and the fingerprint route’s column sums. The table gives the model’s costs for them in doodads, with BLAKE3 as the merge’s hash, for the step lengths that are a power of two or one and a half times one. A length between two of the table’s can be interpolated. A dash marks a length that has no configuration.

Step length,
digits
Mask,
doodads
Merge of a first step,
doodads
Any other merge,
doodads
Fingerprint route
without zkwith zkwithout zkwith zkdigitsdoodadswith zk, less mask
–7,744,204–19,175,697–460,8092,082,425–
29,553,2027,744,2048,367,57019,175,69720,662,734473,0312,168,2882,440,764
43,487,4337,883,6708,520,16019,445,36120,945,522510,8582,381,5372,675,802
57,421,6667,883,6708,520,16019,445,36120,945,522528,1202,502,8062,807,015
85,290,1298,023,1368,672,75119,715,02421,228,309574,5152,776,2483,107,181
113,158,5938,023,1368,672,75119,715,02421,228,309598,9592,947,9733,292,986
168,895,5218,162,6028,825,34119,984,68721,511,096657,3243,305,5063,684,139
224,632,4498,324,1658,825,34120,197,69821,511,096691,8483,645,1973,946,565
336,106,3058,466,8318,977,93120,470,56021,793,884767,2234,132,8144,467,015
447,580,1618,466,8318,977,93120,470,56021,793,884816,1114,483,1284,838,625
670,527,8728,609,4979,130,52120,743,42322,076,671915,4895,142,7425,541,528

The mask is paid once by a transaction with zero knowledge, at the length of the step that it hands off, whatever that step holds and whichever route its multiplications take.

A merge is paid in each step after the first. The steps are a chain, so the first merge takes in a first step. That step’s claim is carried on as it stands, and the merge has nothing to fold: it is the succinct verifier of the first step alone. It costs 40% to 42% of a merge that has a fold. Every later merge takes in a step and the accumulator, and checks their fold as well. Such a merge also pays 5.7 doodads for each digit in use in the step that it merges, since the fold’s sum-checks run over those digits, and that rate is the same at every length. The merge says what a merge consists of.

The last three columns are specific to The fingerprint route. Each step that has multiplications by that route pays for its column sums and for their transcripts, which the next merge absorbs, and their digits take room in the step.

So a transaction’s cost has four parts:

  • its circuits, by the rule of thumb, from the table under Costs;
  • a merge in each step after the first: of a first step in the second, and in each later one a merge with a fold, with the digits in use in the step that it merges;
  • the fingerprint route’s cost in each step that has multiplications by that route; and
  • with zero knowledge, one mask.

For a recovery transaction with zero knowledge, of one, two, or four inputs proved separately, the four parts sum to within a twentieth of the model’s transaction.

Conventional hashes

A BLAKE3 compression is seven rounds of eight G functions. Every word of a G function is used once as a factor, in an XOR, and once linearly, in an addition, and only a factor needs committing:

  • each 32-bit addition is one relation over word entries, with the 32 sum bits and the carry committed, two bits of carry where there are three addends;
  • of each chain of two XORs in a G function, the first’s word is left uncommitted: its bits are the expressions inside the addition that takes the word, 32 terms there;
  • the second’s word is committed, each bit certified against both XORs’ inputs at two terms;
  • rotations are free, being wiring; and
  • the finalisation XORs two state words into each of the eight output words, and what is committed depends on what consumes them.

Where the output is the next compression’s chaining value, within one message, four of its words are that compression’s factors in its first round and are committed at one term a bit. The other four enter its first additions as expressions. That is 11,216 digits a compression, or 94,904 doodads.

Where the output is data, all eight words are committed at one term a bit. A Merkle node’s output and a hash call’s are message words of the next compression, addends in each of its seven rounds, and a transcript’s last output is a challenge. That is 128 digits more, 11,344, and 95,416 doodads. Either way a compression is 11,120 constraints, with 37,760 nonzeros where the output is data.

BLAKE2b has the same G function at 64 bits, each addition in two halves since a 64-bit sum can wrap modulo . Its finalisation differs: it XORs the old chaining word in with the two state words, a chain of two XORs. So all eight output words are committed, each bit certified at two terms. That gives BLAKE2b 38,528 digits and 38,272 constraints: 326,336 doodads, or 345,600 with zero knowledge.

SHA-3’s permutation, Keccak-f[1600], has no additions: it is XORs, rotations, and one AND a bit in each round. Each of its 24 rounds commits 60 lanes of 64 bits: in the step , two parity lanes for each of the five columns and then the 25 lanes of the state; and the 25 output lanes of the step . Each committed bit is certified against three inputs at two terms. The steps and are wiring, and is a constant. So a permutation is 92,160 digits and 184,320 terms: 1,198,080 doodads, or 1,244,160 with zero knowledge. SHA3-256 absorbs 136 bytes a permutation, where a BLAKE3 compression takes 64.

Poseidon

A Poseidon permutation over , at width 12 and rate 8 with the S-box, is 276 multiplications, each a constraint of one term whose output is 22 digits. That is 42,918 doodads a permutation, or 45,954 with zero knowledge. The merge compares it with BLAKE3 as the transcript’s hash.

Arithmetic in a larger field

Arithmetic in a prime field other than , such as Pasta’s base field, is a relation with a committed quotient. Each multiplication carries a quotient and carries, which Kishu commits as tribits. An R1CS emulation of the same arithmetic pays mostly for the boolean constraints on the bits of those values, which Kishu’s digits do not need, so in Kishu’s arithmetization it is expensive but not prohibitively so.

The study prices two ways of checking such a relation, with Pasta’s field as its example. Both are techniques for a circuit’s writer. The limbs’ width and the primes’ size are choices that suit a 255-bit field over Kishu’s 64-bit one, and another field or another writer could choose differently.

Pasta multiplication by two routes

Akita’s claimed evaluations are in one fixed field, so a Pasta multiplication over committed digits cannot be checked modulo that field alone: the prover could choose . Kishu therefore has separate configurations for each of two routes.

The limb route

The relation is checked coefficient by coefficient over 29-bit limbs, which are linear in the digits and cost nothing to commit. That is 17 constraints of up to nine product terms each, bounded below half the modulus so that they hold over the integers, with a committed carry of 34 bits each. A multiplication is then 374 digits and 98 product terms, 3,008 doodads.

The fingerprint route

The relation is one constraint in each of 3 PIOP instances over random 52-bit primes, as BitZ checks it, at 170 digits, 1,204 doodads.

The route has a further price, which belongs to a step and not to a circuit. Each step that has multiplications pays it, so a step of hashes alone pays nothing and the routes tie on the path applications. Each instance’s evaluation claim becomes about integer column sums by BitZ’s tensor split, each exact as one linear claim in the 64-bit field and committed as a word of 61 bits, 21 digits. The merge above has three more transcripts to absorb. Filling a step has the column sums’ cost by step length.

The recovery circuit by each route

The recovery circuit is 4.3 million digits by the limb route and 2.3 million by the fingerprint route: 37.7 million and 19.3 million doodads, or 39.9 million and 20.4 million with zero knowledge. The mask adds 44.0 million doodads for a step of  digits, the length that is best for the recovery transaction by the fingerprint route. Its constraint PIOPs take 0.0123 and 0.00611 s on one core. The range checks of its tribits take 0.0149 and 0.00735 s more, beyond the one product a digit that every digit pays.

Selecting a fixed point

Sinsemilla and fixed-base scalar multiplication both select one of a table of fixed curve points by some bits of the witness. For  bits the table has points.

A coordinate of the selected point is a 255-bit value, which one constraint in cannot pin. So both coordinates are committed, as tribits, and each is checked limb by limb, in the nine limbs of the limb route. A limb of the selected coordinate is a fixed linear form in the subset products of the  bits, with one small coefficient for each subset. It is an exact integer, since exactly one point is selected, so the limb’s constraint holds over the integers.

Only a subset product that is a factor of another has to be committed. The bits are split into two halves, and the subset products within each half are committed as bits, at one term each. A subset that spans both halves is the product of one from each half, and is not committed. A limb’s constraint is then a sum of products: for each nonempty subset of the smaller half, that subset’s product times a linear form in the subsets of the other half. So it has terms, and a nonzero coefficient for every subset of the  bits, in all.

These linear forms are far larger than the few coefficients that the rule of thumb allows a term. So a selection’s terms and nonzeros are counted precisely, as A rough cost model says. Its cost is close to linear in the table’s size: each further point of the table adds 9.0 doodads, the nonzeros of the 18 limb constraints. The rest is the two committed coordinates, and the constraints’ terms and the committed subset products, which grow with the square root of the table size.

BitsPoints in the tableDoodadsWith zk,
less the mask
Doodads
per point
With zk,
less the mask
381,4061,491180190
6642,2392,3283536
95126,8786,9811314
101,02412,33312,4441212
112,04821,81221,9391111
124,09641,94842,0901010

Compared with a lookup in Halo 2. The Orchard circuit selects a Sinsemilla generator with Halo 2’s lookup argument [Halo2]. There a lookup costs about as much as a few of the circuit’s other constraints, whatever the table’s size, so long as the table fits in the circuit’s rows: the prover commits the cells that are looked up, and the argument adds a fixed number of committed columns. The looked-up coordinates are native to Halo 2’s field, and need no limbs. So in Halo 2 a selection from a large table is cheap relative to arithmetic, and a table’s size is limited only by the circuit’s.

Kishu has no lookup argument, and a selection is built from the same constraints as everything else. Its cost grows in proportion to the table, so a table’s size is a trade: a wider window of a scalar multiplication saves complete additions and pays for a larger selection. A selection is still cheap beside a complete addition here, for a different reason than in Halo 2. Arithmetic in Pasta’s field is not cheaper in Kishu to the same extent as bit operations are, and a selection is made of bit operations and linear forms.

Curve operations

The elliptic-curve operations of the Orchard and Ironwood circuits, as this page’s techniques would write them. These costs are provisional: the counts of field multiplications are from straightforward affine formulas, not optimized for this arithmetization, and not checked against an implementation. Each operation’s name links to its description in the Halo 2 book [Halo2], which says how the Orchard circuit implements it. A field multiplication is costed as a Pasta multiplication by either route above. The fingerprint route’s further price for each step that has multiplications, its column sums, is not in these figures. For a step of  digits, the length that is best for the Ironwood recovery transaction with zero knowledge, the column sums are 111,762 digits, which is 766,368 doodads, or 822,249 with zero knowledge.

AdditionField mulsDoodads,
fingerprint route
With zk,
less the mask
Doodads,
limb route
With zk,
less the mask
incomplete33,6103,8669,0249,585
complete1518,05219,32845,12047,925

The modelling assumptions:

  • An incomplete addition takes one multiplication each for the slope, which is a witness, and for the sum’s two coordinates.
  • A complete addition takes both slopes, with their inverses as multiplication checks; the selection between them; the sum’s coordinates; and the identity cases.
Scalar multiplicationField mulsDoodads,
fingerprint route
With zk,
less the mask
Doodads,
limb route
With zk,
less the mask
fixed-base, short105 or 105180,222189,910369,694390,093
fixed-base, full-width435 or 390709,401749,4601,467,5201,543,426
variable-base, full-width5,3556,445,7626,901,06516,108,86017,110,372

The modelling assumptions:

  • Every addition inside a scalar multiplication is complete, as [ZIP-2005] requires of the recovery circuit.
  • A fixed-base multiplication has a window for each few bits of the scalar. A window selects one of a table of fixed points by its bits and adds it. The selection is as Selecting a fixed point describes, and it is cheap beside a complete addition. The Orchard circuit uses windows of three bits, but for Kishu it pays to use wider windows. The scalar’s bits are divided among the windows as evenly as they go, so that the widths differ by at most a bit. That costs less than equal windows with a short last one, since a selection’s cost about doubles with each bit. The figures here take the number of windows of least cost with zero knowledge, by the rule of thumb for a circuit’s own digits; the mask does not enter, since the step’s length fixes it. That is the best for a circuit alone. A transaction can do better with wider windows where fewer digits let it fit a shorter step or one step fewer, so on the frontier page a configuration’s windows are chosen with its step length. For a full-width scalar that is 29 windows by the fingerprint route, 23 of 9 bits and 6 of 8 bits, and 26 windows by the limb route, 21 of 10 bits and 5 of 9 bits. A short scalar is of 64 bits, and its windows are divided the same way: 7 by the fingerprint route and 7 by the limb route. Its sign is not counted.
  • A variable-base multiplication takes 21 field multiplications a bit: a doubling, a complete addition, and the selection between them. Its overflow check is not counted.
  • The scalar’s bits are committed.

The recovery circuit’s curve arithmetic is five full-width fixed-base multiplications, one variable-base multiplication, and 160 complete additions for its Sinsemilla chunks. Each window of a fixed-base multiplication costs it a complete addition. So its count of field multiplications falls with the number of windows, which differs by arithmetization.

ArithmetizationWindows for a full-width scalarField muls in the recovery circuit
Boolean circuits, the Flock configurations19: 8 of 14 bits and 11 of 13 bits9,550
BitZ25: 5 of 11 bits and 20 of 10 bits10,000
Kishu, limb route26: 21 of 10 bits and 5 of 9 bits10,075
Kishu, fingerprint route29: 23 of 9 bits and 6 of 8 bits10,300
over a prime field85 of 3 bits14,500

In a Boolean circuit and in BitZ a selection costs only the subset products of a window’s bits, as AND gates. Their windows are capped at 14 bits, the widest that Kishu tries, because a count of AND gates does not see the cost of the XORs that assemble a coordinate from a large table. BitZ’s windows are narrower than a Boolean circuit’s because its multiplication is cheaper, so a selection’s cost matters sooner.

The families whose witness values are field elements have not had their scalar multiplications optimized to the same extent as Kishu; they keep the Orchard circuit’s windows of three bits, and their costs for selection have not been fully modelled.

Sinsemilla

A Sinsemilla chunk selects one of 1,024 generators by ten bits, as Selecting a fixed point describes. The committed products are the 52 subsets within the two halves of five bits, and each of the 18 limb constraints has 31 terms. A chunk is then 222 digits with its coordinates, 610 terms, and 18,612 nonzeros, which is 12,333 doodads.

The chunk’s point is then added to the running sum by a complete addition, as Curve operations costs it.

Every chunk selects from the same table, and each pays for it again. The table’s part of a chunk, the nonzeros of its limb constraints, is 9,216 doodads, so the recovery circuit’s 160 chunks pay 1,474,560 doodads for one table, which a lookup argument would pay for once. That is 7.6 percent of the recovery circuit by the fingerprint route, or 7.2 percent with zero knowledge. It is the only table in these circuits that is used many times. A window of a fixed-base multiplication uses its table once, or twice where two multiplications share a base, and the Zoodles circuits themselves have no curve arithmetic. So a lookup argument would gain little here, and the study does not model one.

The recovery circuit

The Ironwood recovery circuit itself is hash-heavy: its expensive parts are seven BLAKE2b-512 compressions (the cost section of [ZIP-2005]; beside two Sinsemilla commitments, two full-width Pallas scalar multiplications, a Merkle path, and a BLAKE3 compression in the quantum-key signature). In Kishu a bit-oriented hash is one bit per wire against many Pasta gates per round in the others, and the integer arithmetic simulates without a bit decomposition per operation, with range checks free. Costed component by component in this arithmetization, with a committed bit at 4 doodads and a multiplication at 3,008 doodads by the limb route or 1,204 by the fingerprint route, the recovery circuit is 37.7 million or 19.3 million doodads, in 4.3 million or 2.3 million digits. In Pasta arithmetic it is 560,000 gates. The frontier page’s transaction measure uses those counts together with the constraint PIOP’s work.

References