Create a new ForeignField from a bigint, number, string or another ForeignField.
let x = new ForeignField(5);
Note: Inputs must be range checked if they originate from a different field with a different modulus or if they are not constants.
Gadgets.ForeignField.assertLessThan() and handle appropriately.The internal representation of a foreign field element, as a tuple of 3 limbs.
Static_Static_modulusStatic_provableStatic_variantsSibling classes that represent different ranges of field elements.
StaticAlmostConstructor for field elements that are "almost reduced", i.e. lie in the range [0, 2^ceil(log2(p))).
StaticBigintStaticCanonicalConstructor for field elements that are fully reduced, i.e. lie in the range [0, p).
StaticmodulusStaticprovableProvable<ForeignField>, see Provable
StaticsizeStaticUnreducedConstructor for unreduced field elements.
Add two Rijndael numbers together, this is equivalent to an xor operation
Assert that this field element lies in the range [0, 2^k), where k = ceil(log2(p)) and p is the foreign field modulus.
Returns the field element as a AlmostForeignField.
For a more efficient version of this for multiple field elements, see assertAlmostReduced.
Note: this does not ensure that the field elements is in the canonical range [0, p). To assert that stronger property, there is assertCanonical. You should typically use assertAlmostReduced though, because it is cheaper to prove and sufficient for ensuring validity of all our non-native field arithmetic methods.
Assert that this field element is fully reduced, i.e. lies in the range [0, p), where p is the foreign field modulus.
Returns the field element as a CanonicalForeignField.
Assert equality with a ForeignField-like value
Optionalmessage: stringAssert equality with a ForeignField-like value
Optionalmessage: stringAssert equality with a ForeignField-like value
Optionalmessage: stringDivides the current number by another. This is equivalent to multiplying by an inverse
the numerator in the division
Computes the inverse of the current value, the inverse always satisifes the relationship p * (p^-1) = 1
Checks whether this field element is a constant.
See FieldVar to understand constants vs variables.
Multiply two Rijndael numbers
the second number to multiply with
result from multiplication
Convert this field element to a bigint.
Unpack a field element to its bits, as a Bool[] array.
This method is provable!
Optionallength: numberConvert this field element to a constant.
See FieldVar to understand constants vs variables.
Warning: This function is only useful in Provable.witness or Provable.asProver blocks, that is, in situations where the prover computes a value outside provable code.
Instance version of Provable<ForeignField>.toFields, see Provable.toFields
Static_multMultiply a Rijndael number by x (represented as 2 in the field)
StaticassertAssert that one or more field elements lie in the range [0, 2^k), where k = ceil(log2(p)) and p is the foreign field modulus.
This is most efficient than when checking a multiple of 3 field elements at once.
StaticcheckStaticfromCoerce the input to a ForeignField.
Coerce the input to a ForeignField.
StaticfromCreate a field element from its bits, as a Bool[] array.
This method is provable!
StaticfromWrap field into RijndaelFiniteField, note that field should be less than 256
Input field to wrap
StaticrandomStaticsumSum (or difference) of multiple finite field elements.
let z = ForeignField.sum([3, 2, 1], [-1, 1]); // 3 - 2 + 1
z.assertEquals(2);
This method expects a list of ForeignField-like values, x0,...,xn,
and a list of "operations" op1,...,opn where every op is 1 or -1 (plus or minus),
and returns
x0 + op1*x1 + ... + opn*xn
where the sum is computed in finite field arithmetic.
Important: For more than two summands, this is significantly more efficient than chaining calls to ForeignField.add and ForeignField.sub.
StaticxorPerforms bitwise xor used in Rijndael addition
first input
second input
resulting xor result
A Finite Field which implements Rijndael's Finite Field operations. Operates on values less than 256 and is used to generate sbox values on the fly Its most important for providing non-linearity within the AES encryption scheme