Special thanks to Eli Ben-Sasson and Siemen Dhooghe for reviewing this post before its publication.
Tomorrow (Oct. 31, 2018) at the 4th Ethereum Devcon, Eli Ben-Sasson will reveal Jarvis and Friday, two STARK-friendly cryptographic primitives developed in collaboration between COSIC (Siemen Dhooghe and Tomer Ashur) and StarkWare Industries Ltd. This post provides a schematic overview of these two designs and their design methodology and is aimed for a casual reader. A complete specification for the purpose of cryptanalysis can be found here: https://eprint.iacr.org/2018/1098.
If you’re an Ethereum enthusiast, you’ve probably already heard about Zk-SNARKs and Zk-STARKs and Ethereum’s interest in using them. If you’re not <wink wink>, here’s a three parts blog post by Ethereum’s co-founder Vitalik Buterin: Part 1, Part 2, Part 3.
In Part 3 Buterin explores the possibility of building a Zk-STARK proof for the execution trace of MiMC. Choosing MiMC in this example seems reasonable. In the words of MiMC’s own designers:
Due to its very low number of multiplications, the design lends itself well to a large class of new applications, especially when the depth does not matter but the total number of multiplications in the circuit dominates all aspects of the implementation. With a number of rounds which we deem secure based on our security analysis, we report on significant performance improvements in a representative use-case involving SNARKs.
And indeed, MiMC is a natural candidate for Zk-SNARK and Zk-STARK applications due to its step-wise low degree (meaning that each round of MiMC can be represented by a low-degree polynomial), while at the same time the overall design remains robust against cryptanalytic attacks. It is truly a clever design.
A natural question then is whether something even more efficient than MiMC can be designed, and the answer seems to be positive. The STARK-friendliness of an algorithm can generally be measured through its execution trace. For MiMC, this number is roughly between 100-150 constraints, for the parameter choices made e.g., here. Another somewhat STARK-friendly algorithm is Rijndael, with an execution trace size in the ballpark of 3000 constraints.1 In this post we explain how Rijndael can be generalized by working in a different algebraic field while preserving the cipher’s SPN structure and security argument. The resulting design, Jarvis, is extremely STARK-friendly and has an execution trace size of 30-60 constraints.
Jarvis – A Rijndael-inspired STARK-friendly Block Cipher
The well-known algorithm Rijndael, also known as the Advanced Encryption Standard (AES) is also STARK-friendly. AES, as we all know <wink wink> encrypts 128-bit blocks by viewing them as a 4×4 matrix of bytes (AES’s generalized version, Rijndael, views the state as an NxM matrix of bytes):
The round function of Rijndael is a composition of 4 steps: SubBytes, ShiftRows, MixColumns, and AddRoundKey.
SubBytes. The SubBytes step provides the non-linearity of the round function. It is composed of taking the inverse (i.e., 1/x with zero mapped to zero) of each element of the matrix over GF(28). To avoid certain attacks, an affine layer is composed over the inversion, to increase the degree of the function.
ShiftRows. The ShiftRows step operates on full rows of the matrix. The first row is left untouched, the second row is cyclically shifted by a single byte to the left, the third row by two bytes and the fourth by three bytes.
MixColumns. In the MixColumns step the state matrix is multiplied by a fixed matrix. Put together, the ShiftRows and MixColumns steps form the linear layer of the round function, and are crucial in AES’s security argument (we will get back to this).
AddRoundKey. This step, as suggested by its name, adds the round key into the state. The round key itself is derived from a master key using a key expansion mechanism.
For the casual reader interested in a more elaborate description of AES, Wikipedia gives quite a good overview. For those still finding this lacking, there’s even a book: The Design of Rijndael.2
One of the things which make AES so appealing is its security argument which uses a technique called the wide trail strategy. In essence, the designers bound the differential and linear probabilities of the inversion function, i.e., for a single active S-box. They also show that after applying the round function four times to an input, at least 25 S-boxes are active. Multiplying these 25 active S-boxes with the bound on the maximum transition probability of the differential and linear properties gives a bound on the amount of resources required to attack the cipher. Then, by showing that this amount is not available to an adversary, the cipher is argued to be secure against differential and linear attacks. This is excellent news since differential cryptanalysis and linear cryptanalysis are two very powerful attack methods.
On the other hand, what makes Rijndael STARK-friendly is that its non-linear operation is of low degree. Verifying the inverse function in STARK requires only 1 constraint (1/x = y → xy = 1) and verifying the entire S-box can be done by considering a relatively small number of constraints.
As explained in Buterin’s post linked above, to avoid explosion, STARKs use fixed length field elements. This observation already suggests a possible improvement for AES. Whereas an AES state is an element in GF(28)16, we can instead view the entire state as a single field element in GF(2128).
As a result, rather than applying the inverse function 16 times in every round, we apply it only once to the entire state:
Now that the state is viewed as an element of GF(2128) the affine layer of the S-box needs also be adapted. For efficiency we chose to describe the affine layer as a composition of two polynomials, B(x) and C(x). Both B(x) and C(x) are of low degree, but their inverses are of almost maximal degree. By setting the affine layer to be the composition of C(B-1(x)) we allow a STARK verifier to work separately on B(x) and C(x), thus keep the set of constraints low degree, while preserving the security properties required to resist algebraic attacks.
For the rest of the operations, the purpose of the ShiftRows and MixColumns steps is to spread whatever happens inside a single byte onto the rest of the state. But now, seeing the state as one big field element with no “rest”, these two steps are not necessary anymore and can be discarded.
We are left with the AddRoundKey step which needs to be adapted to the new design. Following the same reasoning as for the state, the key expansion algorithm can be stripped off its diffusion layers, and we are left with a single inversion and an addition of a constant in each round.
Making all these changes, the Jarvis round function becomes:
Where the key expansion function is:
Friday – From Encryption to Hashing
If you’ve read the blog posts I linked earlier <wink wink> you already know that a Zk-STARK proof requires a hash function, and more particularly, that it uses a Merkle-tree. There are several ways to construct a hash function from a block cipher. The most famous of those methods is the Merkle-Damgård construction which incidentally introduces no overhead (in terms of STARK efficiency) over the underlying block cipher.
Wikipedia provides a rather good explanation on how the Merkle–Damgård construction works. In short, the algorithm takes an input of arbitrary length, pads it appropriately, then breaks the input into chunks of fixed length and feeds them iteratively to a compression function. Building a compression function is again something for which generic constructions exist and we opted to using the Miyaguchi-Preneel one:
Where the message-to-be-hashed is fed via the plaintext interface and the chaining value is injected via the key interface.
The resulting hash function, Friday, is obtained from iterating this one-way compression-function with different input blocks:
Is this secure?
As has been shown over and over in recent history, designing an efficient algorithm is a relatively easy task3, as long as security is prioritized lower than efficiency. In building Jarvis and Friday we tried to stick to known design methodologies: both the Merkle-Damgård construction and the Miyaguchi-Preneel one-way compression-function come with a security proof reducing their security to that of their underlying block cipher.
What is left is to argue the security of Jarvis. Unfortunately, at this day and age, the security of block ciphers is always argued but never proved. The difference between the two is that proving the security of an algorithm means that a mathematical proof is provided where a reduction is used to show that breaking the algorithm is at least as hard as something else. For example, the security of the RSA encryption scheme is reduced to the prime factorization problem which is believed to be hard. In our context, the security of the Merkle-Damgård construction is reduced to the security of its underlying compression function.
On the other hand, arguing the security of a primitive consists of providing a set of argument as to why the designers believe it to resist known attacks. Being Rijndael-inspired we adapted the security arguments of AES (most notably, the wide trail strategy) to Jarvis. In doing so, we see that the cryptanalytic properties of Jarvis improve over those of Rijndael and resistance against linear and differential attacks is achieved already after 3 rounds.4 Likewise, due to the high degree of the affine layer (both in the forward and the backward directions), resistance against algebraic attacks is achieved after a very small number of rounds.
The state size
As we noted in the beginning, this post aims to provide a high-level overview of the design of Jarvis and Friday. In fact, using a 128-bit state provides only a 64-bit collision resistance which is considered insecure even for the short term. It is usually accepted that 80-bit security is the minimum for short term security.
To meet this requirement (as well as requirements for longer term security, e.g., 128-bit and even 256-bit), versions of Jarvis-X can be built straightforwardly by making the necessary changes to the field, polynomials, and round constants. Specific instantiations of Jarvis and Friday including all necessary parameters will be provided shortly as part of the complete description.
Choosing the number of rounds
Choosing the right number of rounds is a crucial aspect in ensuring the security of an algorithm. For Rijndael, the number of rounds is determined by 2x(the minimal number of rounds resisting differential and linear cryptanalysis + 1). For AES-128 this results in 10 rounds.
A similar approach would set the number of rounds of Jarvis-128 to 6 rounds. Wanting to be highly conservative due to the novelty in Jarvis’s structure, we decided to initially set the number of rounds to be equal to that of AES and solicit cryptanalysis to determine whether this number can be reduced.
Footnotes
- For more details on what an execution trace of an algorithm is, and how its size is calculated, we refer the curious reader to the original STARK paper by Ben-Sasson et al. Table 4, in particular, provides a comparison of the execution trace size of some widely used algorithms.
- While I would never condone any form of pirating , a friend of a friend told me that a .pdf version is available online.
- Using the identity function for encryption (i.e., E(x) = x) is the most efficient algorithm one can hope for, but is completely insecure.
- As noted before, we will shortly publish the full specification of Jarvis, including the its full security argumentation and specific parameters.






