Documentation
¶
Overview ¶
Package fieldextension provides operations over an extension field of the native field.
The operations inside the circuit are performed in the native field. In case of small fields, we need to perform some operations over an extension field to achieve the required soundness level. This package provides some primitives to perform such operations.
NB! This is not a general purpose field extension package. It is designed to help in specific use-cases inside the field emulation, range checking and log-derivative packages when operating over small fields.
NB! This is an experimental package. The API is not stable and may change in backwards incompatible way. We also may change the extension construction for better performance.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Element ¶
Element is the extension field element.
func ValueOf ¶
ValueOf converts a value of type any to an extension field element. If the type is not supported, it panics.
Currently supported types are:
- github.com/consensys/gnark-crypto/field/koalabear.Element -- returns extension field element with only one coefficient
- github.com/consensys/gnark-crypto/field/koalabear/extensions.E4 -- returns extension field element with four coefficients
func (*Element) Initialize ¶
Initialize initializes the extension field element when using with default field extension constructor. Otherwise, when using a custom extension, the user should use [AllocateElement] function.
type Field ¶
type Field interface {
// Reduce reduces the extension field element modulo the defining polynomial.
Reduce(a Element) Element
// Mul multiplies two extension field elements and reduces the result.
Mul(a, b Element) Element
// MulNoReduce multiplies two extension field elements without reducing the
// result. The degree of the result is the sum of the degrees of the two
// operands.
//
// This method may be no-op if using extension using towers.
MulNoReduce(a, b Element) Element
// Add adds two extension field elements. The result is not reduced. The
// degree of the result is the max of the degrees of the two operands.
Add(a, b Element) Element
// Sub subtracts two extension field elements. The result is not reduced. The
// degree of the result is the max of the degrees of the two operands.
Sub(a, b Element) Element
// MulByElement multiplies an extension field element by a native field
// element. The result is not reduced. The degree of the result is the
// degree of the extension field element.
MulByElement(a Element, b frontend.Variable) Element
// AssertIsEqual asserts that two extension field elements are strictly equal.
// For equality in the extension field, reduce the elements first.
AssertIsEqual(a, b Element)
// Zero returns the zero element of the extension field. By convention it is
// an empty polynomial.
Zero() Element
// One returns the one element of the extension field. By convention it is a
// polynomial of degree 0.
One() Element
// AsExtensionVariable returns the native field element as an extension
// field element of degree 0.
AsExtensionVariable(a frontend.Variable) Element
// Degree returns the degree of the extension field.
Degree() int
// Inverse returns the multiplicative inverse of an extension field element.
Inverse(a Element) Element
}
Field is the extension field interface over native field. It provides the basic operations over the extension field.
type Option ¶
type Option func(*config) error
Option allows to configure the extension field at initialization time.
func WithDegree ¶
WithDegree forces the degree of the extension field. If not set then we choose the degree which provides soundness over the native field.
This option is a no-op when the extension is provided with the WithDirectExtension option.
func WithDirectExtension ¶
WithDirectExtension sets the extension of the field. The input should be a slice of the polynomial coefficients defining the extension in LSB order. The coefficient of the highest degree must be 1.
Example, the extension x^3 + 2x^2 + 3x + 1 is represented as
[1, 3, 2, 1].
This option overrides the WithDegree option.