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 field simulation scheme consists of two data structures: simulated field (
) and simulated multiplication result (
), described as follows.
- Simulated field (): It consists oflimbs in the BLS12-381 scalar field. The number of bits in each limb in the standard representation isbits. Associated with each simulated field element is the number of additions over the normal form.
- Simulated multiplication result (): It consists oflimbs 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.
The implementation of
in the Zei library supports a restricted set of operations, as follows:
- :
- This is a restricted subtraction, wheremust satisfy the following requirements:
- Either,is already in the reduced format. That is, each non-top limb has at mostbits, and the top limb has at mostbits, 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 mostbits, and the top limb has at mostbits, 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 constantelement 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:
-
- Setas follows:
- Ifis in the reduced format, set it to be
- Ifis in the almost reduced format, set it to be
- Ifhasof, set it to be
- :
- Forand:
-
- Setto be as follows:
- Ifis in the reduced format, set it to be
- Ifis in the almost reduced format, set it to be
- Ifhasof, set it to be
- Setto be as follows:
- Ifis in the reduced format, set it to be
- Ifis in the almost reduced format, set it to be
- Ifhasof, set it to be
- .
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 allowsin the reduced format, almost reduced format, or withsmaller or equal to
- Let the limbs of the Ristretto scalar field subtraction pad be
- For:
-
- Incrementby
- :
- This only allowswithsmaller than
- Findsuch that the actual number ofis. Note that we can enforce that
- Let the limbs of the Ristretto scalar field subtraction pad be
- Let the limb representations of beand check that:
- The non-top limb has at mostbits
- The top limb has at mostbits
- Computeby multiplying the limbs ofand, according to thealgorithm. Note thathas 11 limbs
- Create six groups, as follows:
- ,
- ,
- ,
- ,
- ,
- ,
- Initializeand
- For:
- Letbe the number of limbs in this group (i.e., one if, two otherwise)
-
-
-
-
-
- Check
-
-
- If:
- Checkhas at mostbits
- Otherwise:
- Check
Last modified 4mo ago