Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://github.com/yacovm/ZKAT-VDP
20 March 2024, 19:29:05 UTC
  • Code
  • Branches (1)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/main
    No releases to show
  • 48554d7
  • /
  • xicircuit
  • /
  • xicircuit.go
Raw File Download
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge Iframe embedding
swh:1:cnt:4cb402893264a94d8305e532b6bd96cd85e4ba9f
origin badgedirectory badge Iframe embedding
swh:1:dir:5084f53e62d1bd2daba0a6488785bf26b743fb78
origin badgerevision badge
swh:1:rev:721f52b1b74f8e0aa60799bd1436865f8020258e
origin badgesnapshot badge
swh:1:snp:979a5772312db4ab61b637ed766bbc6a3f369470

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: 721f52b1b74f8e0aa60799bd1436865f8020258e authored by yacovm on 14 August 2023, 13:43:45 UTC
Create README.md
Tip revision: 721f52b
xicircuit.go
package xicircuit

import (
	fr "github.com/consensys/gnark-crypto/ecc/bn254/fr"
	tedwards "github.com/consensys/gnark-crypto/ecc/twistededwards"
	"github.com/consensys/gnark/frontend"
	"github.com/consensys/gnark/std/algebra/twistededwards"
	"github.com/consensys/gnark/std/hash/mimc"
	eddsa "github.com/consensys/gnark/std/signature/eddsa"
)

type xiCircuit struct {
	curveID tedwards.ID
	Omega   []frontend.Variable
	CMOmega frontend.Variable `gnark:",public"`
	Nu1     frontend.Variable
	Nu2     frontend.Variable `gnark:",public"`

	AskList   []frontend.Variable
	SNOldList []frontend.Variable `gnark:",public"`

	// Variables needed for obtainRND
	XiUser           frontend.Variable
	CMXiUser         frontend.Variable
	XiCensus         frontend.Variable
	Xi               frontend.Variable
	CMXi             frontend.Variable `gnark:",public"`
	CensusSignedData frontend.Variable
	CensusPK         eddsa.PublicKey `gnark:",public"`
	CensusSignature  eddsa.Signature
}

func (circuit *xiCircuit) Define(api frontend.API) error {

	curve, err := twistededwards.NewEdCurve(api, circuit.curveID)
	if err != nil {
		return err
	}

	// Check that xi = Add(xiUser, xiRegulator)
	xiRes := api.Add(circuit.XiUser, circuit.XiCensus)
	api.AssertIsEqual(xiRes, circuit.Xi)

	// Check that cmXi = Commit(xi)
	err = Commit(api, circuit.Xi, circuit.CMXi)
	if err != nil {
		return err
	}

	// Check that cmXiUser = Commit(xiUser)
	err = Commit(api, circuit.XiUser, circuit.CMXiUser)
	if err != nil {
		return err
	}

	for i := 0; i < len(circuit.Omega)-1; i++ {
		api.AssertIsLessOrEqual(circuit.Omega[i], circuit.Omega[i+1])
	}

	for i := 0; i < len(circuit.Omega); i++ {
		err := PRFSNOld(api, circuit.SNOldList[i], circuit.AskList[i], circuit.Omega[i])
		if err != nil {
			return err
		}
	}

	// Check that Nu1 = PRF(omega||1)
	err = PRFNu(api, circuit.Omega, circuit.Nu1, frontend.Variable(fr.NewElement(1)))
	if err != nil {
		return err
	}

	// Check that Nu1 = PRF(omega||2)
	err = PRFNu(api, circuit.Omega, circuit.Nu2, frontend.Variable(fr.NewElement(2)))

	// Check that CMomega = Commit(omega)
	mimcCMOmega, err := mimc.NewMiMC(api)
	if err != nil {
		return err
	}
	mimcCMOmega.Write(circuit.Omega[:]...)
	cmOmega := mimcCMOmega.Sum()
	api.AssertIsEqual(cmOmega, circuit.CMOmega)

	// Hash(cm_u||nu_1||xi_R)
	hfunc, err2 := mimc.NewMiMC(api)
	if err2 != nil {
		return err2
	}
	hfunc.Write(circuit.CMXiUser, circuit.Nu1, circuit.XiCensus)
	signData := hfunc.Sum()

	api.AssertIsEqual(signData, circuit.CensusSignedData)

	// Verify sign_R
	mimcSign, err3 := mimc.NewMiMC(api)
	if err3 != nil {
		return err3
	}
	err3 = eddsa.Verify(curve, circuit.CensusSignature, circuit.CensusSignedData, circuit.CensusPK, &mimcSign)
	if err3 != nil {
		return err3
	}

	return nil
}

func Commit(api frontend.API, data frontend.Variable, cmData frontend.Variable) error {

	hfunc, err := mimc.NewMiMC(api)
	if err != nil {
		return err
	}
	hfunc.Write(data)
	result := hfunc.Sum()

	api.AssertIsEqual(result, cmData)

	return nil
}

func PRFSNOld(api frontend.API, snOld, sk, rho frontend.Variable) error {

	// Compute H(sk||01||rho)
	hfunc, err := mimc.NewMiMC(api)
	if err != nil {
		return err
	}
	hfunc.Write(sk)
	hfunc.Write(frontend.Variable([]byte{0b0, 0b1}))
	hfunc.Write(rho)
	result := hfunc.Sum()

	// Check SN_old = H(sk||01||rho)
	api.AssertIsEqual(result, snOld)
	return nil
}

func PRFNu(api frontend.API, omega []frontend.Variable, nu, i frontend.Variable) error {

	mimcNu1, err := mimc.NewMiMC(api)
	if err != nil {
		return err
	}
	mimcNu1.Write(omega[:]...)
	mimcNu1.Write(i)
	result := mimcNu1.Sum()
	api.AssertIsEqual(result, nu)

	return nil
}

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API