Skip to main content
Last updated

Zk

pairing-check

Use pairing-check to perform pairing and final exponentiation on points in points-g1 and points-g2 in the Barreto-Naehrig (BN254) elliptic curve, and check if the result is 1.

Basic syntax

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

pact
(pairing-check points-g1 points-g2)
pact
(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[any]Specifies the list of points in G1.
points-g2[any]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 how to use the pairing-check function 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])

point-add

Use point-add to add two points together that lie on the in the Barreto-Naehrig (BN254) elliptic curve. The BN254 curve is a pairing-friendly curve tht can be used for verifying on-chain zero knowledge proof schemes such as Groth16 and PlonK. You can use this function to add point either in Fq or in Fq2.

Basic syntax

To add two points together that lie on the Barreto-Naehrig (BN254) elliptic curve, use the following syntax:

pact
(point-add type point1 point2)
pact
(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 to perform. The valid values are "g1" and "g2".
point1anySpecifies the first point to be added.
point2anySpecifies 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 how to use the point-add function to add the two specified points together on the BN256 curve in the Pact REPL:

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

In this example, the type of addition is g1 and the points are provided as objects with x and y coordinates.

scalar-mult

Use scalar-mult to multiply a point that lies on the BN254 by a specified scalar integer value.

Basic syntax

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

pact
(scalar-mult type point1 scalar)
pact
(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 to multiply. The valid values are "g1" and "g2".
point1pointSpecifies the point on the BN254 curve 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 scalar value.

Examples

The following example demonstrates how to use the scalar-mult function to multiply the point { 'x: 1, 'y: 2 } on curve 'g1 by the scalar value 3:

pact
pact> (scalar-mult 'g1 {'x: 1, 'y: 2} 3){"x": 3353031288059533942658390886683067124040920775575537747144343083137631628272,"y": 19321533766552368860946552437480515441416830039777911637913418824951667761761}
pact
pact> (scalar-mult 'g1 {'x: 1, 'y: 2} 3){"x": 3353031288059533942658390886683067124040920775575537747144343083137631628272,"y": 19321533766552368860946552437480515441416830039777911637913418824951667761761}