Arithmetic state machine
The Arithmetic state machine is a secondary state machine that also has an executor (the Arithmetic SM executor) and an internal Arithmetic program (a set of ve
The Arithmetic state machine is a secondary state machine that also has an executor (the Arithmetic SM executor) and an internal Arithmetic program (a set of verification rules written in the PIL language). The Arithmetic SM executor is available in two languages: Javascript and C/C++.
It is one of the six secondary state machines receiving instructions from the Main SM executor. The main purpose of the Arithmetic SM is to carry out elliptic curve arithmetic operations, such as Point Addition and Point Doubling as well as performing 256-bit operations like addition, product or division.
Standard elliptic curve arithmetic
Consider an elliptic curve defined by over the finite field , where is the prime,
Set the coefficients and , so that reduces to
Point addition
Given two points, and , on the curve with , the point is computed as follows,
Point doubling
Given a point on the curve such that , the point is computed as follows,
where,
Field arithmetic
Several 256-bit operations can be expressed in the following form:
where and are 256-bit integers.
For instance, if , then states that the result of multiplying and is with a carry of . That is, is the chunk that exceeds 256 bits.
Or, if , states that the result of adding and is the same as before: with a carry of . Similarly, division and modular reductions can also be expressed as derivatives of .
These operations are performed in the Arithmetic state machine, with registers satisfying the following PIL relation,
Remark
Since the above elliptic curve operations are implemented in the PIL language, it is more convenient to express them in terms of the constraints they must satisfy. These constraints are:
where , implying that these equations hold true over the integers.
This approach is taken because of the need to compute divisions by . Note that only three possible computation scenarios can arise:
- is activated while the rest are deactivated,
- , and are activated but and are deactivated,
- , and are activated and and are deactivated.
Since at most, one of and are activated in any scenario, we can afford "sharing'' the same for both.
Motivated by the implemented operations, the Arithmetic SM is composed of 6 registers, each of which is composed of 16 sub-registers of 16-bit (2 byte) capacity, adding up to a total of 256 bits per register.
There is also a need to provide and , which are also 256-bit field elements.
How operations are performed
Compute the previous operations at 2-byte level. For instance, if one is performing the multiplication of and , at the first clock is computed.
Then, is computed in the second clock, followed by in the third, and so on.
As depicted in the below figure, this process is completely analogous to the schoolbook multiplication. However, it is performed at 2-byte level, instead of decimal level.

Use the following notation:
But then, the carry generated by has to be taken into account by .
Going back to our equations ; let's see how the operation is performed in .
-
Compute
-
Compute
-
This is continued until one reaches the computation, .
At this stage comes into place.
Since the first 256 bits of the result of the operation have been filled (and the result can be made of more than 256-bits), a new register is needed to store the rest of the output. We change the addition of by .
Therefore, we obtain that:
and so on.
Continuing until the last two:
Now, notice that the carry generated by the 's is not important for them. That means, if , then what we really want the result to be is and save as a carry for the next operation. To express this fact as a constraint, we say that the following has to be satisfied:
where represents the carry taken into account in the actual clock, and represents the carry generated by the actual operation.
Remark
A technicality is that is subdivided into two other and such that:
Source code
The Polygon zkEVM repository is available on GitHub.
Arithmetic SM executor: sm_arith folder
Arithmetic SM PIL: arith.pil
Last updated on
Executor and PIL
The Storage executor is to the Storage Assembly code a like a slave-worker to the master. It carries out all _Storage Actions_ in accordance with rules and logi
Binary state machine
The Binary state machine is one of the six secondary state machines receiving instructions from the Main SM executor. It is responsible for the execution of all