twistededwards

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package twistededwards implements the arithmetic of twisted Edwards curves in native fields. This uses associated twisted Edwards curves defined over the scalar field of the SNARK curves.

Examples: Jubjub, Bandersnatch (a twisted Edwards) is defined over BLS12-381's scalar field Baby-Jubjub (a twisted Edwards) is defined over BN254's salar fields

Index

Constants

This section is empty.

Variables

View Source
var DecomposeScalar = func(scalarField *big.Int, inputs []*big.Int, res []*big.Int) error {

	if scalarField.Cmp(ecc.BLS12_381.ScalarField()) != 0 {
		return errors.New("no efficient endomorphism is available on this curve")
	}
	var glv glvParams
	var init sync.Once
	init.Do(func() {
		glv.lambda.SetString("8913659658109529928382530854484400854125314752504019737736543920008458395397", 10)
		glv.order.SetString("13108968793781547619861935127046491459309155893440570251786403306729687672801", 10)
		ecc.PrecomputeLattice(&glv.order, &glv.lambda, &glv.glvBasis)
	})

	sp := ecc.SplitScalar(inputs[0], &glv.glvBasis)
	res[0].Neg(&(sp[0]))
	res[1].Set(&(sp[1]))

	res[2].Mul(res[1], &glv.lambda).Sub(res[2], res[0])
	res[2].Sub(res[2], inputs[0])
	res[2].Div(res[2], &glv.order)

	return nil
}

Functions

func GetSnarkField

func GetSnarkField(id twistededwards.ID) (*big.Int, error)

GetSnarkField returns the matching snark curve for a twisted edwards curve

Types

type Curve

type Curve interface {
	Params() *CurveParams
	Endo() *EndoParams
	Add(p1, p2 Point) Point
	Double(p1 Point) Point
	Neg(p1 Point) Point
	AssertIsOnCurve(p1 Point)
	ScalarMul(p1 Point, scalar frontend.Variable) Point
	DoubleBaseScalarMul(p1, p2 Point, s1, s2 frontend.Variable) Point
	API() frontend.API
}

Curve methods implemented by a twisted edwards curve inside a circuit

func NewEdCurve

func NewEdCurve(api frontend.API, id twistededwards.ID) (Curve, error)

NewEdCurve returns a new Edwards curve

type CurveParams

type CurveParams struct {
	A, D, Cofactor, Order *big.Int
	Base                  [2]*big.Int // base point coordinates
}

CurveParams twisted edwards curve parameters ax^2 + y^2 = 1 + d*x^2*y^2 Matches gnark-crypto curve specific params

func GetCurveParams

func GetCurveParams(id twistededwards.ID) (*CurveParams, error)

type EndoParams

type EndoParams struct {
	Endo   [2]*big.Int
	Lambda *big.Int
}

EndoParams endomorphism parameters for the curve, if they exist

type Point

type Point struct {
	X, Y frontend.Variable
}

Point represent a pair of X, Y coordinates inside a circuit

Jump to

Keyboard shortcuts

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