package bn256
import "github.com/ethereum/go-ethereum/crypto/bn256/gnark"
Index ¶
- func PairingCheck(a_ []*G1, b_ []*G2) bool
- type G1
- func (g *G1) Add(a, b *G1)
- func (p *G1) Marshal() []byte
- func (g *G1) ScalarMult(a *G1, scalar *big.Int)
- func (g *G1) Unmarshal(buf []byte) (int, error)
- type G2
- type GT
Functions ¶
func PairingCheck ¶
PairingCheck computes the following relation: ∏ᵢ e(Pᵢ, Qᵢ) =? 1
To explain why gnark returns a (bool, error):
- If the function `e` does not return a result then internally an error is returned.
- If `e` returns a result, then error will be nil, but if this value is not `1` then the boolean value will be false
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 ¶
Add adds `a` and `b` together, storing the result in `g`
func (*G1) Marshal ¶
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 ¶
ScalarMult computes the scalar multiplication between `a` and `scalar`, storing the result in `g`
func (*G1) Unmarshal ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Unmarshal deserializes `buf` into `g`
Note: This method is not explicitly used in mainline code. It is needed for fuzzing.
Source Files ¶
- Version
- v1.16.1 (latest)
- Published
- Jul 2, 2025
- Platform
- linux/amd64
- Imports
- 4 packages
- Last checked
- 3 days ago –
Tools for package owners.