Skip to main content
@tevm/voltaire
@tevm/voltaire / crypto/Bls12381 / Fp

Fp

Functions

add()

add(a, b): bigint
Defined in: src/crypto/Bls12381/Fp/add.js:10 Add two field elements

Parameters

a
bigint First operand
b
bigint Second operand

Returns

bigint (a + b) mod p

inv()

inv(a): bigint
Defined in: src/crypto/Bls12381/Fp/inv.js:12 Compute modular inverse using Fermat’s little theorem a^(-1) = a^(p-2) mod p

Parameters

a
bigint Value to invert

Returns

bigint a^(-1) mod p

Throws

If a is zero

mod()

mod(a): bigint
Defined in: src/crypto/Bls12381/Fp/mod.js:9 Reduce a bigint modulo the field prime p

Parameters

a
bigint Value to reduce

Returns

bigint Value reduced to [0, p-1]

mul()

mul(a, b): bigint
Defined in: src/crypto/Bls12381/Fp/mul.js:10 Multiply two field elements

Parameters

a
bigint First operand
b
bigint Second operand

Returns

bigint (a * b) mod p

neg()

neg(a): bigint
Defined in: src/crypto/Bls12381/Fp/neg.js:9 Negate a field element

Parameters

a
bigint Value to negate

Returns

bigint -a mod p

pow()

pow(base, exp): bigint
Defined in: src/crypto/Bls12381/Fp/pow.js:10 Modular exponentiation using square-and-multiply

Parameters

base
bigint Base value
exp
bigint Exponent

Returns

bigint base^exp mod p

sqrt()

sqrt(a): bigint | null
Defined in: src/crypto/Bls12381/Fp/sqrt.js:19 Compute square root in Fp (if it exists) For BLS12-381, p = 3 mod 4, so we use Tonelli-Shanks simplification: sqrt(a) = a^((p+1)/4) mod p

Parameters

a
bigint Value to take square root of

Returns

bigint | null Square root if it exists, null otherwise

sub()

sub(a, b): bigint
Defined in: src/crypto/Bls12381/Fp/sub.js:10 Subtract two field elements

Parameters

a
bigint First operand
b
bigint Second operand

Returns

bigint (a - b) mod p