Skip to content
You are reading gnark development version documentation and some displayed features may not be available in the stable release. You can switch to stable version using the version box at screen bottom.

Updated on April 21, 2021

gnark standard library

Note

gnark/std will be improved in the v0.5.0 release. See this Github issue for more details.

We provide the following functions in gnark/std:

func (circuit *mimcCircuit) Define(curveID ecc.ID, cs *frontend.ConstraintSystem) error {
    // ...
    hFunc, _ := mimc.NewMiMC("seed", curveID)
    computedHash := hFunc.Hash(cs, circuit.Data)
    // ...
}
type eddsaCircuit struct {
    PublicKey eddsa.PublicKey           `gnark:",public"`
    Signature eddsa.Signature           `gnark:",public"`
    Message   frontend.Variable         `gnark:",public"`
}

func (circuit *eddsaCircuit) Define(curveID ecc.ID, cs *frontend.ConstraintSystem) error {
    edCurve, _ := twistededwards.NewEdCurve(curveID)
    circuit.PublicKey.Curve = edCurve

    eddsa.Verify(cs, circuit.Signature, circuit.Message, circuit.PublicKey)
    return nil
}
type merkleCircuit struct {
    RootHash     frontend.Variable `gnark:",public"`
    Path, Helper []frontend.Variable
}

func (circuit *merkleCircuit) Define(curveID ecc.ID, cs *frontend.ConstraintSystem) error {
    hFunc, _ := mimc.NewMiMC("seed", curveID)
    merkle.VerifyProof(cs, hFunc, circuit.RootHash, circuit.Path, circuit.Helper)
    return nil
}

Enables verifying a BLS12_377 Groth16 Proof inside a BW6_761 circuit

type verifierCircuit struct {
    InnerProof Proof
    InnerVk    VerifyingKey
    Hash       frontend.Variable
}

func (circuit *verifierCircuit) Define(curveID ecc.ID, cs *frontend.ConstraintSystem) error {
    // pairing data
    var pairingInfo sw.PairingContext
    pairingInfo.Extension = fields.GetBLS377ExtensionFp12(cs)
    pairingInfo.AteLoop = 9586122913090633729

    // create the verifier cs
    groth16.Verify(cs, pairingInfo, circuit.InnerVk, circuit.InnerProof, []frontend.Variable{circuit.Hash})

    return nil
}
Questions or feedback? You can discuss issues and obtain free support on gnark discussions channel.
For paid professional support by Consensys, contact us at [email protected]