sw_bls12377

package
v0.9.0-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2023 License: Apache-2.0 Imports: 10 Imported by: 33

Documentation

Overview

Package sw_bls12377 implements the arithmetics of G1, G2 and the pairing computation on BLS12-377 as a SNARK circuit over BW6-761. These two curves form a 2-chain so the operations use native field arithmetic.

References: BW6-761: https://eprint.iacr.org/2020/351 Pairings in R1CS: https://eprint.iacr.org/2022/1162

Index

Constants

This section is empty.

Variables

View Source
var DecomposeScalarG1 = func(scalarField *big.Int, inputs []*big.Int, res []*big.Int) error {
	cc := getInnerCurveConfig(scalarField)
	sp := ecc.SplitScalar(inputs[0], cc.glvBasis)
	res[0].Set(&(sp[0]))
	res[1].Set(&(sp[1]))
	one := big.NewInt(1)

	for res[0].Cmp(cc.lambda) < 1 && res[1].Cmp(cc.lambda) < 1 {
		res[0].Add(res[0], cc.lambda)
		res[0].Add(res[0], one)
		res[1].Add(res[1], cc.lambda)
	}

	res[2].Mul(res[1], cc.lambda).Add(res[2], res[0])
	res[2].Sub(res[2], inputs[0])
	res[2].Div(res[2], cc.fr)

	return nil
}
View Source
var DecomposeScalarG2 = func(scalarField *big.Int, inputs []*big.Int, res []*big.Int) error {
	cc := getInnerCurveConfig(scalarField)
	sp := ecc.SplitScalar(inputs[0], cc.glvBasis)
	res[0].Set(&(sp[0]))
	res[1].Set(&(sp[1]))
	one := big.NewInt(1)

	for res[0].Cmp(cc.lambda) < 1 && res[1].Cmp(cc.lambda) < 1 {
		res[0].Add(res[0], cc.lambda)
		res[0].Add(res[0], one)
		res[1].Add(res[1], cc.lambda)
	}

	res[2].Mul(res[1], cc.lambda).Add(res[2], res[0])
	res[2].Sub(res[2], inputs[0])
	res[2].Div(res[2], cc.fr)

	return nil
}

Functions

This section is empty.

Types

type G1Affine

type G1Affine struct {
	X, Y frontend.Variable
}

G1Affine point in affine coords

func (*G1Affine) AddAssign

func (p *G1Affine) AddAssign(api frontend.API, p1 G1Affine) *G1Affine

AddAssign adds p1 to p using the affine formulas with division, and return p

func (*G1Affine) AssertIsEqual

func (p *G1Affine) AssertIsEqual(api frontend.API, other G1Affine)

AssertIsEqual constraint self to be equal to other into the given constraint system

func (*G1Affine) Assign

func (p *G1Affine) Assign(p1 *bls12377.G1Affine)

Assign a value to self (witness assignment)

func (*G1Affine) Double

func (p *G1Affine) Double(api frontend.API, p1 G1Affine) *G1Affine

Double double a point in affine coords

func (*G1Affine) DoubleAndAdd

func (p *G1Affine) DoubleAndAdd(api frontend.API, p1, p2 *G1Affine) *G1Affine

DoubleAndAdd computes 2*p1+p in affine coords

func (*G1Affine) FromJac

func (p *G1Affine) FromJac(api frontend.API, p1 G1Jac) *G1Affine

FromJac sets p to p1 in affine and returns it

func (*G1Affine) Neg

func (p *G1Affine) Neg(api frontend.API, p1 G1Affine) *G1Affine

Neg outputs -p

func (*G1Affine) ScalarMul

func (P *G1Affine) ScalarMul(api frontend.API, Q G1Affine, s interface{}) *G1Affine

ScalarMul sets P = [s] Q and returns P.

The method chooses an implementation based on scalar s. If it is constant, then the compiled circuit depends on s. If it is variable type, then the circuit is independent of the inputs.

func (*G1Affine) ScalarMulBase

func (P *G1Affine) ScalarMulBase(api frontend.API, s frontend.Variable) *G1Affine

ScalarMulBase computes s * g1 and returns it, where g1 is the fixed generator. It doesn't modify s.

func (*G1Affine) Select

func (p *G1Affine) Select(api frontend.API, b frontend.Variable, p1, p2 G1Affine) *G1Affine

Select sets p1 if b=1, p2 if b=0, and returns it. b must be boolean constrained

type G1Jac

type G1Jac struct {
	X, Y, Z frontend.Variable
}

G1Jac point in Jacobian coords

func (*G1Jac) AddAssign

func (p *G1Jac) AddAssign(api frontend.API, p1 G1Jac) *G1Jac

AddAssign adds 2 point in Jacobian coordinates p=p, a=p1

func (*G1Jac) AssertIsEqual

func (p *G1Jac) AssertIsEqual(api frontend.API, other G1Jac)

AssertIsEqual constraint self to be equal to other into the given constraint system

func (*G1Jac) Assign

func (p *G1Jac) Assign(p1 *bls12377.G1Jac)

Assign a value to self (witness assignment)

func (*G1Jac) DoubleAssign

func (p *G1Jac) DoubleAssign(api frontend.API) *G1Jac

DoubleAssign doubles the receiver point in jacobian coords and returns it

func (*G1Jac) Neg

func (p *G1Jac) Neg(api frontend.API, p1 G1Jac) *G1Jac

Neg outputs -p

type G2Affine

type G2Affine struct {
	X, Y fields_bls12377.E2
}

G2Affine point in affine coords

func (*G2Affine) AddAssign

func (p *G2Affine) AddAssign(api frontend.API, p1 G2Affine) *G2Affine

AddAssign add p1 to p and return p

func (*G2Affine) AssertIsEqual

func (p *G2Affine) AssertIsEqual(api frontend.API, other G2Affine)

AssertIsEqual constraint self to be equal to other into the given constraint system

func (*G2Affine) Assign

func (p *G2Affine) Assign(p1 *bls12377.G2Affine)

Assign a value to self (witness assignment)

func (*G2Affine) Double

func (p *G2Affine) Double(api frontend.API, p1 G2Affine) *G2Affine

Double compute 2*p1, assign the result to p and return it Only for curve with j invariant 0 (a=0).

func (*G2Affine) DoubleAndAdd

func (p *G2Affine) DoubleAndAdd(api frontend.API, p1, p2 *G2Affine) *G2Affine

DoubleAndAdd computes 2*p1+p2 in affine coords

func (*G2Affine) FromJac

func (p *G2Affine) FromJac(api frontend.API, p1 G2Jac) *G2Affine

FromJac sets p to p1 in affine and returns it

func (*G2Affine) Neg

func (p *G2Affine) Neg(api frontend.API, p1 G2Affine) *G2Affine

Neg outputs -p

func (*G2Affine) ScalarMul

func (P *G2Affine) ScalarMul(api frontend.API, Q G2Affine, s interface{}) *G2Affine

ScalarMul sets P = [s] Q and returns P.

The method chooses an implementation based on scalar s. If it is constant, then the compiled circuit depends on s. If it is variable type, then the circuit is independent of the inputs.

func (*G2Affine) ScalarMulBase

func (P *G2Affine) ScalarMulBase(api frontend.API, s frontend.Variable) *G2Affine

ScalarMulBase computes s * g2 and returns it, where g2 is the fixed generator. It doesn't modify s.

func (*G2Affine) Select

func (p *G2Affine) Select(api frontend.API, b frontend.Variable, p1, p2 G2Affine) *G2Affine

Select sets p1 if b=1, p2 if b=0, and returns it. b must be boolean constrained

type G2Jac

type G2Jac struct {
	X, Y, Z fields_bls12377.E2
}

G2Jac point in Jacobian coords

func (*G2Jac) AddAssign

func (p *G2Jac) AddAssign(api frontend.API, p1 *G2Jac) *G2Jac

AddAssign adds 2 point in Jacobian coordinates p=p, a=p1

func (*G2Jac) AssertIsEqual

func (p *G2Jac) AssertIsEqual(api frontend.API, other G2Jac)

AssertIsEqual constraint self to be equal to other into the given constraint system

func (*G2Jac) Assign

func (p *G2Jac) Assign(p1 *bls12377.G2Jac)

Assign a value to self (witness assignment)

func (*G2Jac) Double

func (p *G2Jac) Double(api frontend.API, p1 G2Jac) *G2Jac

Double doubles a point in jacobian coords

func (*G2Jac) Neg

func (p *G2Jac) Neg(api frontend.API, p1 G2Jac) *G2Jac

Neg outputs -p

type GT

type GT = fields_bls12377.E12

GT target group of the pairing

func FinalExponentiation

func FinalExponentiation(api frontend.API, e1 GT) GT

FinalExponentiation computes the exponentiation e1ᵈ where d = (p¹²-1)/r = (p¹²-1)/Φ₁₂(p) ⋅ Φ₁₂(p)/r = (p⁶-1)(p²+1)(p⁴ - p² +1)/r we use instead d=s ⋅ (p⁶-1)(p²+1)(p⁴ - p² +1)/r where s is the cofactor 3 (Hayashida et al.)

func MillerLoop

func MillerLoop(api frontend.API, P []G1Affine, Q []G2Affine) (GT, error)

MillerLoop computes the product of n miller loops (n can be 1) ∏ᵢ { fᵢ_{x₀,Q}(P) }

func MillerLoopFixedQ

func MillerLoopFixedQ(api frontend.API, P G1Affine) (GT, error)

MillerLoopFixed computes the single Miller loop fᵢ_{u,g2}(P), where g2 is fixed.

func Pair

func Pair(api frontend.API, P []G1Affine, Q []G2Affine) (GT, error)

Pair calculates the reduced pairing for a set of points ∏ᵢ e(Pᵢ, Qᵢ).

This function doesn't check that the inputs are in the correct subgroup. See IsInSubGroup.

func PairFixedQ

func PairFixedQ(api frontend.API, P G1Affine) (GT, error)

PairFixedQ calculates the reduced pairing for a set of points e(P, g2), where g2 is fixed.

This function doesn't check that the inputs are in the correct subgroups.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL