BW6FR

Git Source

State Variables

MOD_EXP

MOD_EXP precompile address.

uint256 private constant MOD_EXP = 0x05;

Functions

r

Returns scalar field: r = 0x1ae3a4617c510eac63b05c06ca1493b1a22d9f300f5138f1ef3622fba094800170b5d44300000008508c00000000001

function r() internal pure returns (Bw6Fr memory);

Returns

NameTypeDescription
<none>Bw6FrScalar field.

zero

Returns the additive identity element of Bw6Fr.

function zero() internal pure returns (Bw6Fr memory);

Returns

NameTypeDescription
<none>Bw6FrBw6Fr(0, 0)

one

Returns the multiplicative identity element of Bw6Fr.

function one() internal pure returns (Bw6Fr memory);

Returns

NameTypeDescription
<none>Bw6FrBw6Fr(0, 1)

two

Returns the two of Bw6Fr.

function two() internal pure returns (Bw6Fr memory);

Returns

NameTypeDescription
<none>Bw6FrBw6Fr(0, 2)

is_zero

Returns true if self is equal to the additive identity.

function is_zero(Bw6Fr memory self) internal pure returns (bool);

Parameters

NameTypeDescription
selfBw6FrBw6Fr.

Returns

NameTypeDescription
<none>boolResult of zero check.

is_geq_modulus

Returns true if self is equal or larger than r.

function is_geq_modulus(Bw6Fr memory self) internal pure returns (bool);

Parameters

NameTypeDescription
selfBw6FrBw6Fr.

Returns

NameTypeDescription
<none>boolResult of check.

eq

Returns true if x is equal to y.

function eq(Bw6Fr memory x, Bw6Fr memory y) internal pure returns (bool);

Parameters

NameTypeDescription
xBw6FrBw6Fr.
yBw6FrBw6Fr.

Returns

NameTypeDescription
<none>boolResult of equal check.

gt

Returns true if x is larger than y.

function gt(Bw6Fr memory x, Bw6Fr memory y) internal pure returns (bool);

Parameters

NameTypeDescription
xBw6FrBw6Fr.
yBw6FrBw6Fr.

Returns

NameTypeDescription
<none>boolResult of gt check.

add_nomod

Returns the result of x + y.

function add_nomod(Bw6Fr memory x, Bw6Fr memory y) internal pure returns (Bw6Fr memory z);

Parameters

NameTypeDescription
xBw6FrBw6Fr.
yBw6FrBw6Fr.

Returns

NameTypeDescription
zBw6Frx + y.

add

Returns the result of (x + y) % p.

function add(Bw6Fr memory x, Bw6Fr memory y) internal pure returns (Bw6Fr memory z);

Parameters

NameTypeDescription
xBw6FrBw6Fp.
yBw6FrBw6Fp.

Returns

NameTypeDescription
zBw6Fr(x + y) % p.

subtract_modulus_to_norm

function subtract_modulus_to_norm(Bw6Fr memory self) internal pure returns (Bw6Fr memory z);

sub

Returns the result of (x - y) % p.

function sub(Bw6Fr memory x, Bw6Fr memory y) internal pure returns (Bw6Fr memory z);

Parameters

NameTypeDescription
xBw6FrBls12Fp.
yBw6FrBls12Fp.

Returns

NameTypeDescription
zBw6Fr(x - y) % p.

sub

Returns the result of x - y.

function sub(Bw6Fr[2] memory x, Bw6Fr[2] memory y) internal pure returns (Bw6Fr[2] memory z);

Parameters

NameTypeDescription
xBw6Fr[2]Bls12Fp[2].
yBw6Fr[2]Bls12Fp[2].

Returns

NameTypeDescription
zBw6Fr[2]x - y.

mul

(x * y) = ((x + y)^2 - (x - y)^2) / 4

function mul(Bw6Fr memory x, Bw6Fr memory y) internal view returns (Bw6Fr memory z);

Parameters

NameTypeDescription
xBw6FrBw6Fr.
yBw6FrBw6Fr.

Returns

NameTypeDescription
zBw6FrBw6Fr.

sum

Sum of the list of Bw6Fr.

function sum(Bw6Fr[] memory xs) internal pure returns (Bw6Fr memory);

Parameters

NameTypeDescription
xsBw6Fr[]Bw6Fr[].

Returns

NameTypeDescription
<none>Bw6FrResult of sum.

mul_sum

Mul and Add.

function mul_sum(Bw6Fr[] memory xs, Bw6Fr[] memory ys) internal view returns (Bw6Fr memory z);

Parameters

NameTypeDescription
xsBw6Fr[]Bw6Fr[].
ysBw6Fr[]Bw6Fr[].

Returns

NameTypeDescription
zBw6FrResult of mul and add.

div2

self / two

function div2(Bw6Fr[2] memory self) internal pure returns (Bw6Fr[2] memory z);

Parameters

NameTypeDescription
selfBw6Fr[2]Bw6Fr[2].

Returns

NameTypeDescription
zBw6Fr[2]Result of div2.

inverse

Constant time inversion using Fermat's little theorem. For a prime p and for any a < p, a^p = a % p => a^(p-1) = 1 % p => a^(p-2) = a^-1 % p

function inverse(Bw6Fr memory self) internal view returns (Bw6Fr memory);

Parameters

NameTypeDescription
selfBw6FrBw6Fr.

Returns

NameTypeDescription
<none>Bw6FrResult of inverse.

square

self^2 % r.

function square(Bw6Fr memory self) internal view returns (Bw6Fr memory);

Parameters

NameTypeDescription
selfBw6FrBw6Fr.

Returns

NameTypeDescription
<none>Bw6FrResult of square.

pow

base^exp % r

function pow(Bw6Fr memory base, uint256 exp) internal view returns (Bw6Fr memory);

Parameters

NameTypeDescription
baseBw6FrBw6Fr.
expuint256Bw6Fr.

Returns

NameTypeDescription
<none>Bw6FrResult of pow.

mod_exp

base^base % modulus

function mod_exp(Bw6Fr memory base, uint256 exp, Bw6Fr memory modulus) internal view returns (Bw6Fr memory);

Parameters

NameTypeDescription
baseBw6FrBw6Fr.
expuint256Bw6Fr.
modulusBw6FrBw6Fr.

Returns

NameTypeDescription
<none>Bw6FrResult of mod_exp.

square_nomod

self^2

function square_nomod(Bw6Fr memory self) internal view returns (Bw6Fr[2] memory);

Parameters

NameTypeDescription
selfBw6FrBw6Fr.

Returns

NameTypeDescription
<none>Bw6Fr[2]Result of square withoud mod.

norm

Normalize Bw6Fr[2].

function norm(Bw6Fr[2] memory self) internal view returns (Bw6Fr memory);

Parameters

NameTypeDescription
selfBw6Fr[2]Bw6Fr[2].

Returns

NameTypeDescription
<none>Bw6Frself % r.

powers

(max_exp+1)-sized vec: 1, base, base^2,... ,base^{max_exp}

function powers(Bw6Fr memory base, uint256 max_exp) internal view returns (Bw6Fr[] memory);

Parameters

NameTypeDescription
baseBw6FrBw6Fr.
max_expuint256uint256.

Returns

NameTypeDescription
<none>Bw6Fr[]Result of powers.

horner_field

Horner field

function horner_field(Bw6Fr[] memory bases, Bw6Fr memory nu) internal view returns (Bw6Fr memory);

Parameters

NameTypeDescription
basesBw6Fr[]Bw6Fr[].
nuBw6FrBw6Fr.

Returns

NameTypeDescription
<none>Bw6FrResult of horner_field.

from_random_bytes

Derive Bw6Fr from bytes in LE order.

function from_random_bytes(bytes16 input) internal pure returns (Bw6Fr memory);

Parameters

NameTypeDescription
inputbytes16bytes16.

Returns

NameTypeDescription
<none>Bw6FrBw6Fr.

serialize

Serialize Bw6Fr.

function serialize(Bw6Fr memory self) internal pure returns (bytes memory);

Parameters

NameTypeDescription
selfBw6FrBw6Fr.

Returns

NameTypeDescription
<none>bytesCompressed serialized bytes of Bls12G1.

debug

Debug Bw6Fr in bytes.

function debug(Bw6Fr memory self) internal pure returns (bytes memory);

Parameters

NameTypeDescription
selfBw6FrBw6Fr.

Returns

NameTypeDescription
<none>bytesUncompressed serialized bytes of Bw6Fr.