circuits

package
v0.0.0-...-386c795 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

README

CircomLib/Circuits

Description

  • This folder contains circuit templates for standard operations and many cryptographic primitives.
  • Below you can find specifications of each function. In the representation of elements, there are three tyes:
    • Binary
    • String
    • Field element (the field is specified in each case. We consider 2 possible fields: Fp and Fr, where p... and r... .)

Table of Contents

[TOC]

Jordi

Circuits

sha256

Folder containing the implementation of sha256 hash circuit.

smt

Folder containing the circuit implementation of Sparse Merkle Trees.

aliascheck
  • AliasCheck()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
babyjub

Arithmetic on Baby Jubjub elliptic curve in twisted Edwards form. (TODO: Expose here the characteristics of the curve?)

  • BabyAdd()

    • DESCRIPTION

      It adds two points on the Baby Jubjub curve. More specifically, given two points P1 = (x1, y1) and P2 = (x2, y2) it returns a point P3 = (xout, yout) such that

      (xout, yout) = (x1,y1) + (x2,y2) = ((x1y2+y1x2)/(1+dx1x2y1y2)),(y1y2-ax1x2)/(1-dx1x2y1y2))

    • SCHEMA

                                       var a     var d
                                         |         |
                                         |         |
                                   ______v_________v_______
                  input x1 ---->  |                        |
                  input y1 ---->  |        BabyAdd()       | ----> output xout
                  input x2 ---->  |                        | ----> output yout
                  input y2 ---->  |________________________|
      
    • INPUTS

      Input Representation Description
      x1 Bigint Field element of Fp First coordinate of a point (x1, y1) on E.
      y1 Bigint Field element of Fp Second coordinate of a point (x1, y1) on E.
      x2 Bigint Field element of Fp First coordinate of a point (x2, y2) on E.
      y2 Bigint Field element of Fp Second coordinate of a point (x2, y2) on E.

      Requirement: at least x1!=x2 or y1!=y2.

    • OUTPUT

      Input Representation Description
      xout Bigint Field element of Fp First coordinate of the addition point (xout, yout) = (x1, y1) + (x2, y2).
      yout Bigint Field element of Fp Second coordinate of the addition point (xout, yout) = (x1, y1) + (x2, y2).
    • BENCHMARKS (constraints)

    • EXAMPLE

  • BabyDbl()

    • DESCRIPTION : doubles a point (xout,yout) = 2*(x,y).
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • BabyCheck()

    • DESCRIPTION : checks if a given point is in the curve.
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • BabyPbk()

    • DESCRIPTION: : given a private key, it returns the associated public key.
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
binsub
  • BinSub(n)

    • DESCRIPTION: binary substraction.
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
binsum
  • nbits(a)

    • DESCRIPTION : binary sum.
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • BinSum(n, ops)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
bitify
  • Num2Bits()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • Num2Bits_strict()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • Bits2Num()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • Bits2Num_strict()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • Num2BitsNeg()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
comparators
  • IsZero()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • IsEqual()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • ForceEqualIfEnabled()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • LessThan()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • GreaterThan()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • GreaterEqThan()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
compconstant
  • CompConstant(ct)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
eddsa

Edwards Digital Signature Algorithm in Baby Jubjbub (link a eddsa)

  • EdDSAVerifier(n)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
eddsamimc
  • EdDSAMiMCVerifier()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
eddsamimcsponge
  • EdDSAMiMCSpongeVerifier()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
eddsaposeidon
  • EdDSAPoseidonVerifier()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
escalarmul
  • EscalarMulWindow(base, k)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • EscalarMul(n, base)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
escalarmulany
  • Multiplexor2()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • BitElementMulAny()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • SegmentMulAny(n)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • EscalarMulAny(n)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
escalarmulfix
  • WindowMulFix()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • SegmentMulFix(nWindows)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • EscalarMulFix(n, BASE)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
escalarmulw4table
  • pointAdd

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • EscalarMulW4Table

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
gates
  • XOR

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • AND

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • OR

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • NOT

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • NAND

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • NOR

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • MultiAND

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
mimc

Implementation of MiMC-7 hash in Fp being... (link to description of the hash)

  • MiMC7(nrounds)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • MultiMiMC7(nInputs, nRounds)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
mimcsponge
  • MiMCSponge(nInputs, nRounds, nOutputs)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • MiMCFeistel(nrounds)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
montgomery
  • Edwards2Montgomery()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • Montgomery2Edwards()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • MontgomeryAdd()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • MontgomeryDouble()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
multiplexer
  • log2(a)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • EscalarProduct(w)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • Decoder(w)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • Multiplexer(wIn, nIn)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
mux1
  • MultiMux1(n)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • Mux1()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
mux2
  • MultiMux2(n)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • Mux2()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
mux3
  • MultiMux3(n)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • Mux3()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
mux4
  • MultiMux4(n)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • Mux4()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
pedersen_old

Old version of the Pedersen hash (do not use any more?).

pedersen
  • Window4()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • Segment(nWindows)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • Pedersen(n)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
pointbits
  • sqrt(n)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • Bits2Point()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • Bits2Point_Strict()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • Point2Bits

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • Point2Bits_Strict

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
poseidon

Implementation of Poseidon hash function (LINK)

  • Sigma()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • Ark(t, C, r)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • Mix(t, M)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
  • Poseidon(nInputs)

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
sign
  • Sign()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE
switcher
  • Switcher()

    • DESCRIPTION
    • SCHEMA
    • INPUT
    • OUTPUT
    • BENCHMARKS
    • EXAMPLE

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AliasCheck

func AliasCheck(api frontend.API, in []frontend.Variable)

func And

func Ark

func Ark(api frontend.API, in []frontend.Variable, c []*big.Int, r int) []frontend.Variable

func BabyAdd

func BabyAdd(api frontend.API, x1, y1, x2, y2 frontend.Variable) (frontend.Variable, frontend.Variable)

func BigAdd

func BigAdd(x *big.Int, y *big.Int) *big.Int

func BigAnd

func BigAnd(x *big.Int, y *big.Int) *big.Int

func BigDiv

func BigDiv(x *big.Int, y *big.Int) *big.Int

func BigLsh

func BigLsh(k *big.Int, n uint) *big.Int

func BigMul

func BigMul(x *big.Int, y *big.Int, c ...*big.Int) *big.Int

func BigRsh

func BigRsh(k *big.Int, n uint) *big.Int

func BigSub

func BigSub(x *big.Int, y *big.Int) *big.Int

func BinSub

func BinSub(api frontend.API, a, b []frontend.Variable) []frontend.Variable

func BinSum

func BinSum(api frontend.API, in [][]frontend.Variable) []frontend.Variable

func Bits2Num

func Bits2Num(api frontend.API, in []frontend.Variable) frontend.Variable

func Bits2NumStrict

func Bits2NumStrict(api frontend.API, in []frontend.Variable) frontend.Variable

func BoolNeg

func CompConstant

func CompConstant(api frontend.API, in []frontend.Variable, ct *big.Int) frontend.Variable

CompConstant returns 1 if in (in binary) > ct

func Decoder

func Edwards2Montgomery

func Edwards2Montgomery(api frontend.API, in []frontend.Variable) []frontend.Variable

func EscalarMulW4Table

func EscalarMulW4Table(base [2]*big.Int, k int) [][]*big.Int

func EscalarProduct

func EscalarProduct(api frontend.API, in1, in2 []frontend.Variable) frontend.Variable

func ForceEqualIfEnabled

func ForceEqualIfEnabled(api frontend.API, a, b, enabled frontend.Variable)

func IsZero

func Lsh

func Lsh(k int64, n uint) *big.Int

func Make2DVariableArray

func Make2DVariableArray(n, m int) [][]frontend.Variable

func Make3DVariableArray

func Make3DVariableArray(n, m, o int) [][][]frontend.Variable

func MakeVariableArray

func MakeVariableArray(n int) []frontend.Variable

func MiMC7

func MiMC7(api frontend.API, nRounds int, xIn, k frontend.Variable) frontend.Variable

func MiMCFeistel

func MiMCFeistel(api frontend.API, nRounds int, xLIn, xRIn, k frontend.Variable) (frontend.Variable, frontend.Variable)

func MiMCSponge

func MiMCSponge(api frontend.API, nRounds, nOutputs int, ins []frontend.Variable, k frontend.Variable) []frontend.Variable

func Mix

func Mix(api frontend.API, in []frontend.Variable, m [][]*big.Int) []frontend.Variable

func MixLast

func MixLast(api frontend.API, in []frontend.Variable, m [][]*big.Int, s int) frontend.Variable

func MixS

func MixS(api frontend.API, in []frontend.Variable, s []*big.Int, r int) []frontend.Variable

func Montgomery2Edwards

func Montgomery2Edwards(api frontend.API, in []frontend.Variable) []frontend.Variable

func MontgomeryAdd

func MontgomeryAdd(api frontend.API, in1, in2 []frontend.Variable) []frontend.Variable

func MontgomeryDouble

func MontgomeryDouble(api frontend.API, in []frontend.Variable) []frontend.Variable

func MultiAnd

func MultiAnd(api frontend.API, in []frontend.Variable) frontend.Variable

func MultiMiMC7

func MultiMiMC7(api frontend.API, nRounds int, in []frontend.Variable, k frontend.Variable) frontend.Variable

func MultiMux1

func MultiMux1(api frontend.API, c [][]frontend.Variable, sel frontend.Variable) []frontend.Variable

func MultiMux2

func MultiMux2(api frontend.API, c [][]frontend.Variable, sel []frontend.Variable) []frontend.Variable

func MultiMux3

func MultiMux3(api frontend.API, c [][]frontend.Variable, sel []frontend.Variable) []frontend.Variable

func MultiMux4

func MultiMux4(api frontend.API, c [][]frontend.Variable, sel []frontend.Variable) []frontend.Variable

func Multiplexer

func Multiplexer(api frontend.API, inp [][]frontend.Variable, sel frontend.Variable) []frontend.Variable

func NAND

func NewMiMC7

func NewMiMC7(api frontend.API) hash.Hash

func NewMimcSpongeHash

func NewMimcSpongeHash(api frontend.API) hash.Hash

func NewPoseidonHash

func NewPoseidonHash(api frontend.API) hash.Hash

func Nor

func Num2Bits

func Num2Bits(api frontend.API, in frontend.Variable, n int) []frontend.Variable

func Num2BitsNeg

func Num2BitsNeg(api frontend.API, in frontend.Variable, n int) []frontend.Variable

func Num2BitsStrict

func Num2BitsStrict(api frontend.API, in frontend.Variable, n int) []frontend.Variable

func Or

func POSEIDON_C

func POSEIDON_C(t int) []*big.Int

func POSEIDON_M

func POSEIDON_M(t int) [][]*big.Int

func POSEIDON_P

func POSEIDON_P(t int) [][]*big.Int

func POSEIDON_S

func POSEIDON_S(t int) []*big.Int

func Pedersen

func Pedersen(api frontend.API, in []frontend.Variable) []frontend.Variable

func Point2BitsStrict

func Point2BitsStrict(api frontend.API, in []frontend.Variable) []frontend.Variable

func Poseidon

func Poseidon(api frontend.API, inputs []frontend.Variable) frontend.Variable

func PoseidonEx

func PoseidonEx(api frontend.API, inputs []frontend.Variable, initialState frontend.Variable, nOuts int) []frontend.Variable

func Segment

func Segment(api frontend.API, in []frontend.Variable, base []frontend.Variable) []frontend.Variable

func Sigma

func Sign

Sign returns 1 if in is positive, or 0 otherwise

func Switcher

func Switcher(api frontend.API, sel, l, r frontend.Variable) (frontend.Variable, frontend.Variable)

func Window4

func Window4(api frontend.API, in []frontend.Variable, base []frontend.Variable) ([]frontend.Variable, []frontend.Variable)

func Xor

Types

This section is empty.

Jump to

Keyboard shortcuts

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