Field Simulation
The Zei library provides an implementation of field simulation (and its constraint systems), which is able to simulate Ristretto scalar field in the BLS12-381 scalar field. As follows, we assume that the order of the Ristretto scalar field is .
Data structure​
The field simulation scheme consists of two data structures: simulated field () and simulated multiplication result (), described as follows.
- Simulated field (): It consists of limbs in the BLS12-381 scalar field. The number of bits in each limb in the standard representation is bits. Associated with each simulated field element is the number of additions over the normal form.
- Simulated multiplication result (): It consists of limbs in the BLS12-381 scalar field. Associated with each simulation multiplication result element is the product of the the number of additions over the normal form.
Operations for :​
The implementation of in the Zei library supports a restricted set of operations, as follows:
:
This is a restricted subtraction, where must satisfy the following requirements:
- Either, is already in the reduced format. That is, each non-top limb has at most bits, and the top limb has at most bits, and the actual number being represented is strictly smaller than the Ristretto scalar field size;
- Or, is in an almost reduced format. That is, each non-top limb has at most bits, and the top limb has at most bits, and the actual number being represented can be larger than the Ristretto scalar field size (in other words, to represent number , it can be ).
Let the limbs of the Ristretto scalar field subtraction pad be , which is a constant element where each limb has one more bit than the reduced format, and the actual number it represents is multiplies of . In our case, it is .
For :
Set as follows:
- If is in the reduced format, set it to be
- If is in the almost reduced format, set it to be
- If has of , set it to be
:
For and :
Set to be as follows:
- If is in the reduced format, set it to be
- If is in the almost reduced format, set it to be
- If has of , set it to be
Set to be as follows:
- If is in the reduced format, set it to be
- If is in the almost reduced format, set it to be
- If has of , set it to be
.
Operations for :​
The implementation of is to allow computation over the multiplied results. Similarly, it supposes a restricted set of operations, as follows:
- :
For :
Set
:
This is a restricted subtraction. It only allows in the reduced format, almost reduced format, or with smaller or equal to
Let the limbs of the Ristretto scalar field subtraction pad be
For :
Increment by
:
This only allows with smaller than
Find such that the actual number of is . Note that we can enforce that
Let the limbs of the Ristretto scalar field subtraction pad be
Let the limb representations of be and check that:
- The non-top limb has at most bits
- The top limb has at most bits
Compute by multiplying the limbs of and , according to the algorithm. Note that has 11 limbs
Create six groups, as follows:
- ,
- ,
- ,
- ,
- ,
- ,
Initialize and
For :
Let be the number of limbs in this group (i.e., one if , two otherwise)
Check
If :
- Check has at most bits
Otherwise:
- Check