package bn256

import "github.com/ethereum/go-ethereum/crypto/bn256/gnark"

Index

Functions

func PairingCheck

func PairingCheck(a_ []*G1, b_ []*G2) bool

PairingCheck computes the following relation: ∏ᵢ e(Pᵢ, Qᵢ) =? 1

To explain why gnark returns a (bool, error):

We therefore check for an error, and return false if its non-nil and then return the value of the boolean if not.

Types

type G1

type G1 struct {
	// contains filtered or unexported fields
}

G1 is the affine representation of a G1 group element.

Since this code is used for precompiles, using Jacobian points are not beneficial because there are no intermediate points to allow us to save on inversions.

Note: We also use this struct so that we can conform to the existing API that the precompiles want.

func (*G1) Add

func (g *G1) Add(a, b *G1)

Add adds `a` and `b` together, storing the result in `g`

func (*G1) Marshal

func (p *G1) Marshal() []byte

Marshal serializes the point into a byte slice.

The output is in EVM format: 64 bytes total. [32-byte x coordinate][32-byte y coordinate] where each coordinate is a big-endian integer padded to 32 bytes.

func (*G1) ScalarMult

func (g *G1) ScalarMult(a *G1, scalar *big.Int)

ScalarMult computes the scalar multiplication between `a` and `scalar`, storing the result in `g`

func (*G1) Unmarshal

func (g *G1) Unmarshal(buf []byte) (int, error)

Unmarshal deserializes `buf` into `g`

The input is expected to be in the EVM format: 64 bytes: [32-byte x coordinate][32-byte y coordinate] where each coordinate is in big-endian format.

This method also checks whether the point is on the curve and in the prime order subgroup.

type G2

type G2 struct {
	// contains filtered or unexported fields
}

G2 is the affine representation of a G2 group element.

Since this code is used for precompiles, using Jacobian points are not beneficial because there are no intermediate points and G2 in particular is only used for the pairing input.

Note: We also use this struct so that we can conform to the existing API that the precompiles want.

func (*G2) Marshal

func (g *G2) Marshal() []byte

Marshal serializes the point into a byte slice.

The output is in EVM format: 128 bytes total. [32-byte x.1][32-byte x.0][32-byte y.1][32-byte y.0] where each value is a big-endian integer.

func (*G2) Unmarshal

func (g *G2) Unmarshal(buf []byte) (int, error)

Unmarshal deserializes `buf` into `g`

The input is expected to be in the EVM format: 128 bytes: [32-byte x.1][32-byte x.0][32-byte y.1][32-byte y.0] where each value is a big-endian integer.

This method also checks whether the point is on the curve and in the prime order subgroup.

type GT

type GT struct {
	// contains filtered or unexported fields
}

GT is the affine representation of a GT field element.

Note: GT is not explicitly used in mainline code. It is needed for fuzzing.

func Pair

func Pair(a_ *G1, b_ *G2) *GT

Pair compute the optimal Ate pairing between a G1 and G2 element.

Note: This method is not explicitly used in mainline code. It is needed for fuzzing. It should also be noted, that the output of this function may not match other

func (*GT) Exp

func (g *GT) Exp(base GT, exponent *big.Int) *GT

Exp raises `base` to the power of `exponent`

Note: This method is not explicitly used in mainline code. It is needed for fuzzing.

func (*GT) Marshal

func (g *GT) Marshal() []byte

Marshal serializes the point into a byte slice.

Note: This method is not explicitly used in mainline code. It is needed for fuzzing.

func (*GT) Unmarshal

func (g *GT) Unmarshal(buf []byte) error

Unmarshal deserializes `buf` into `g`

Note: This method is not explicitly used in mainline code. It is needed for fuzzing.

Source Files

g1.go g2.go gt.go pairing.go

Version
v1.16.1 (latest)
Published
Jul 2, 2025
Platform
linux/amd64
Imports
4 packages
Last checked
3 days ago

Tools for package owners.