Skip to main content
Last updated

Zk

pairing-check

Use pairing-check to perform pairing and final exponentiation on points in G1 and G2 in BN254, and check if the result is 1.

Basic syntax

To perform pairing and final exponentiation on points in G1 and G2, and check if the result is 1, use the following syntax:

(pairing-check points-g1 points-g2)

Arguments

Use the following arguments to specify the lists of points in G1 and G2 for which you want to perform the pairing check using the pairing-check Pact function.

ArgumentTypeDescription
points-g1[<a>]Specifies the list of points in G1.
points-g2[<b>]Specifies the list of points in G2.

Return value

The pairing-check function returns a boolean value indicating whether the result of the pairing and final exponentiation is 1.

Examples

The following example demonstrates the use of pairing-check in the Pact REPL:

pact
pact>(pairing-check [point1_g1 point2_g1] [point1_g2 point2_g2])
pact
pact>(pairing-check [point1_g1 point2_g1] [point1_g2 point2_g2])

In this example, pairing-check is used to perform pairing and final exponentiation on the specified points in G1 and G2. The function returns a boolean value indicating whether the result is 1.

point-add

Use point-add to add two points together that lie on the curve BN254. Point addition can be performed either in Fq or in Fq2.

Basic syntax

To add two points together that lie on the curve BN254, use the following syntax:

(point-add type point1 point2)

Arguments

Use the following arguments to specify the type of addition and the points to be added using the point-add Pact function.

ArgumentTypeDescription
typestringSpecifies the type of point addition (either 'g1' or 'g2').
point1<a>Specifies the first point to be added.
point2<a>Specifies the second point to be added.

Return value

The point-add function returns the result of adding the specified points together.

Examples

The following example demonstrates the use of point-add in the Pact REPL:

pact
pact>(point-add 'g1 {'x': 1, 'y': 2} {'x': 1, 'y': 2})
pact
pact>(point-add 'g1 {'x': 1, 'y': 2} {'x': 1, 'y': 2})

In this example, point-add is used to add the two specified points together on the curve BN254. The type of addition is 'g1', and the points are provided as dictionaries with 'x' and 'y' coordinates.

scalar-mult

The scalar-mult function multiplies a point that lies on the curve BN254 by an integer value.

Basic syntax

To multiply a point by an integer value, use the following syntax:

(scalar-mult TYPE POINT1 SCALAR)

Arguments

Use the following arguments to specify the TYPE, POINT, and SCALAR value for multiplication using the scalar-mult Pact function.

ArgumentTypeDescription
TYPEstringSpecifies the type of point (e.g., 'g1).
POINT1<a>Specifies the point on the curve BN254 to be multiplied.
SCALARintegerSpecifies the integer value to multiply the point by.

Return value

The scalar-mult function returns the result of multiplying the specified point by the integer scalar value.

Examples

The following example demonstrates the usage of the scalar-mult function within a Pact script. It multiplies the point { 'x: 1, 'y: 2 } on curve 'g1 by the scalar value 2:

pact
pact>(scalar-mult 'g1 {'x: 1, 'y: 2} 2){"x":1368015179489954701390400359078579693043519447331113978918064868415326638035, "y":9918110051302171585080402603319702774565515993150576347155970296011118125764}
pact
pact>(scalar-mult 'g1 {'x: 1, 'y: 2} 2){"x":1368015179489954701390400359078579693043519447331113978918064868415326638035, "y":9918110051302171585080402603319702774565515993150576347155970296011118125764}

This example illustrates how to use the scalar-mult function to perform scalar multiplication on points lying on the curve BN254 in Pact.