Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50a725c174 | ||
|
|
c4ce4cd946 | ||
|
|
5bf52cda57 | ||
|
|
95abdd06d5 | ||
|
|
9f69fab7c6 | ||
|
|
109cdf4056 | ||
|
|
79d30349b4 | ||
|
|
e3cd0e5aa7 | ||
|
|
86e970b888 | ||
|
|
29e162383d | ||
|
|
97b870b725 | ||
|
|
f9e0484663 | ||
|
|
7bdb254f4f | ||
|
|
024188b638 | ||
|
|
ebbeaebc73 | ||
|
|
25f392c8ae | ||
|
|
ae362ec61b |
17
README.md
17
README.md
@@ -1,4 +1,17 @@
|
|||||||
# cirpedersen
|
# CircomLib
|
||||||
|
|
||||||
Pedersen Hash and Exponentiation circuits using Baby Jub Curve in circom language
|
## Description
|
||||||
|
|
||||||
|
- This repository contains a library of circuit templates.
|
||||||
|
- All files are copyrighted under 2018 0KIMS association and part of the free software [circom](https://github.com/iden3/circom) (Zero Knowledge Circuit Compiler).
|
||||||
|
|
||||||
|
## Organisation
|
||||||
|
|
||||||
|
This respository contains 5 folders:
|
||||||
|
- `circuits`: it contains the implementation of different cryptographic primitives in circom language.
|
||||||
|
- `calcpedersenbases`: set of functions in JavaScript used to find a set of points in [Baby Jubjub](https://github.com/barryWhiteHat/baby_jubjub) elliptic curve that serve as basis for the [Pedersen Hash](https://github.com/zcash/zcash/issues/2234).
|
||||||
|
- `doc`: it contains some circuit schemes in ASCII (must be opened with Monodraw, an ASCII art editor for Mac).
|
||||||
|
- `src`: it contains similar implementation of circuits in JavaScript.
|
||||||
|
- `test`: tests.
|
||||||
|
|
||||||
|
A description of the specific circuit templates for the `circuit` folder will be soon updated.
|
||||||
@@ -1,3 +1,19 @@
|
|||||||
|
# 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
|
||||||
|
|
||||||
* compconstant - Returns 1 if `in` (expanded to binary array) > `ct`
|
* compconstant - Returns 1 if `in` (expanded to binary array) > `ct`
|
||||||
* aliascheck - check if `in` (expanded to binary array) oveflowed its 254 bits (<= -1)
|
* aliascheck - check if `in` (expanded to binary array) oveflowed its 254 bits (<= -1)
|
||||||
* babyjub - twisted Edwards curve 168700.x^2 + y^2 = 1 + 168696.x^2.y^2
|
* babyjub - twisted Edwards curve 168700.x^2 + y^2 = 1 + 168696.x^2.y^2
|
||||||
@@ -11,4 +27,804 @@
|
|||||||
* zcash/zcash#2233
|
* zcash/zcash#2233
|
||||||
* smt - Sparse Merkle Tree
|
* smt - Sparse Merkle Tree
|
||||||
* https://ethresear.ch/t/optimizing-sparse-merkle-trees/3751
|
* https://ethresear.ch/t/optimizing-sparse-merkle-trees/3751
|
||||||
* montgomery https://en.wikipedia.org/wiki/Montgomery_curve
|
* montgomery https://en.wikipedia.org/wiki/Montgomery_curve
|
||||||
|
|
||||||
|
## 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](https://github.com/barryWhiteHat/baby_jubjub) 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)`
|
||||||
|
|
||||||
|
- DESCRIPTION
|
||||||
|
- SCHEMA
|
||||||
|
- INPUT
|
||||||
|
- OUTPUT
|
||||||
|
- BENCHMARKS
|
||||||
|
- EXAMPLE
|
||||||
|
|
||||||
|
- `Mix(t, M)`
|
||||||
|
|
||||||
|
- DESCRIPTION
|
||||||
|
- SCHEMA
|
||||||
|
- INPUT
|
||||||
|
- OUTPUT
|
||||||
|
- BENCHMARKS
|
||||||
|
- EXAMPLE
|
||||||
|
|
||||||
|
- `Poseidon(nInputs, t, nRoundsF, nRoundsP)`
|
||||||
|
|
||||||
|
- DESCRIPTION
|
||||||
|
- SCHEMA
|
||||||
|
- INPUT
|
||||||
|
- OUTPUT
|
||||||
|
- BENCHMARKS
|
||||||
|
- EXAMPLE
|
||||||
|
|
||||||
|
### sign
|
||||||
|
|
||||||
|
- `Sign()`
|
||||||
|
|
||||||
|
- DESCRIPTION
|
||||||
|
- SCHEMA
|
||||||
|
- INPUT
|
||||||
|
- OUTPUT
|
||||||
|
- BENCHMARKS
|
||||||
|
- EXAMPLE
|
||||||
|
|
||||||
|
### switcher
|
||||||
|
|
||||||
|
- `Switcher()`
|
||||||
|
|
||||||
|
- DESCRIPTION
|
||||||
|
- SCHEMA
|
||||||
|
- INPUT
|
||||||
|
- OUTPUT
|
||||||
|
- BENCHMARKS
|
||||||
|
- EXAMPLE
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ template EdDSAPoseidonVerifier() {
|
|||||||
snum2bits.out[i] ==> compConstant.in[i];
|
snum2bits.out[i] ==> compConstant.in[i];
|
||||||
}
|
}
|
||||||
compConstant.in[253] <== 0;
|
compConstant.in[253] <== 0;
|
||||||
compConstant.out === 0;
|
compConstant.out*enabled === 0;
|
||||||
|
|
||||||
// Calculate the h = H(R,A, msg)
|
// Calculate the h = H(R,A, msg)
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ template EdDSAPoseidonVerifier() {
|
|||||||
// We check that A is not zero.
|
// We check that A is not zero.
|
||||||
component isZero = IsZero();
|
component isZero = IsZero();
|
||||||
isZero.in <== dbl3.x;
|
isZero.in <== dbl3.x;
|
||||||
isZero.out === 0;
|
isZero.out*enabled === 0;
|
||||||
|
|
||||||
component mulAny = EscalarMulAny(254);
|
component mulAny = EscalarMulAny(254);
|
||||||
for (i=0; i<254; i++) {
|
for (i=0; i<254; i++) {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
include "montgomery.circom";
|
include "montgomery.circom";
|
||||||
include "babyjub.circom";
|
include "babyjub.circom";
|
||||||
|
include "comparators.circom";
|
||||||
|
|
||||||
template Multiplexor2() {
|
template Multiplexor2() {
|
||||||
signal input sel;
|
signal input sel;
|
||||||
@@ -138,6 +139,8 @@ template EscalarMulAny(n) {
|
|||||||
component doublers[nsegments-1];
|
component doublers[nsegments-1];
|
||||||
component m2e[nsegments-1];
|
component m2e[nsegments-1];
|
||||||
component adders[nsegments-1];
|
component adders[nsegments-1];
|
||||||
|
component zeropoint = IsZero();
|
||||||
|
zeropoint.in <== p[0];
|
||||||
|
|
||||||
var s;
|
var s;
|
||||||
var i;
|
var i;
|
||||||
@@ -154,8 +157,9 @@ template EscalarMulAny(n) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (s==0) {
|
if (s==0) {
|
||||||
p[0] ==> segments[s].p[0];
|
// force G8 point if input point is zero
|
||||||
p[1] ==> segments[s].p[1];
|
segments[s].p[0] <== p[0] + (5299619240641551281634865583518297030282874472190772894086521144482721001553 - p[0])*zeropoint.out;
|
||||||
|
segments[s].p[1] <== p[1] + (16950150798460657717958625567821834550301663161624707787222815936182638968203 - p[1])*zeropoint.out;
|
||||||
} else {
|
} else {
|
||||||
doublers[s-1] = MontgomeryDouble();
|
doublers[s-1] = MontgomeryDouble();
|
||||||
m2e[s-1] = Montgomery2Edwards();
|
m2e[s-1] = Montgomery2Edwards();
|
||||||
@@ -183,10 +187,10 @@ template EscalarMulAny(n) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (nsegments == 1) {
|
if (nsegments == 1) {
|
||||||
segments[0].out[0] ==> out[0];
|
segments[0].out[0]*(1-zeropoint.out) ==> out[0];
|
||||||
segments[0].out[1] ==> out[1];
|
segments[0].out[1]+(1-segments[0].out[1])*zeropoint.out ==> out[1];
|
||||||
} else {
|
} else {
|
||||||
adders[nsegments-2].xout ==> out[0];
|
adders[nsegments-2].xout*(1-zeropoint.out) ==> out[0];
|
||||||
adders[nsegments-2].yout ==> out[1];
|
adders[nsegments-2].yout+(1-adders[nsegments-2].yout)*zeropoint.out ==> out[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -246,7 +246,7 @@ template EscalarMulFix(n, BASE) {
|
|||||||
var s;
|
var s;
|
||||||
var i;
|
var i;
|
||||||
var nseg;
|
var nseg;
|
||||||
var nWindows
|
var nWindows;
|
||||||
|
|
||||||
for (s=0; s<nsegments; s++) {
|
for (s=0; s<nsegments; s++) {
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ template MiMCSponge(nInputs, nRounds, nOutputs) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
outs[0] = S[nInputs - 1].xL_out;
|
outs[0] <== S[nInputs - 1].xL_out;
|
||||||
|
|
||||||
for (var i = 0; i < nOutputs - 1; i++) {
|
for (var i = 0; i < nOutputs - 1; i++) {
|
||||||
S[nInputs + i] = MiMCFeistel(nRounds);
|
S[nInputs + i] = MiMCFeistel(nRounds);
|
||||||
|
|||||||
81
circuits/sha256/sha256.circom
Normal file
81
circuits/sha256/sha256.circom
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
|
||||||
|
|
||||||
|
include "constants.circom";
|
||||||
|
include "sha256compression.circom";
|
||||||
|
|
||||||
|
template Sha256(nBits) {
|
||||||
|
signal input in[nBits];
|
||||||
|
signal output out[256];
|
||||||
|
|
||||||
|
var i;
|
||||||
|
var k;
|
||||||
|
var nBlocks;
|
||||||
|
var bitsLastBlock;
|
||||||
|
|
||||||
|
|
||||||
|
nBlocks = ((nBits + 64)\512)+1;
|
||||||
|
|
||||||
|
signal paddedIn[nBlocks*512];
|
||||||
|
|
||||||
|
for (k=0; k<nBits; k++) {
|
||||||
|
paddedIn[k] <== in[k];
|
||||||
|
}
|
||||||
|
paddedIn[nBits] <== 1;
|
||||||
|
|
||||||
|
for (k=nBits+1; k<nBlocks*512-64; k++) {
|
||||||
|
paddedIn[k] <== 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (k = 0; k< 64; k++) {
|
||||||
|
paddedIn[nBlocks*512 - k -1] <== (nBits >> k)&1;
|
||||||
|
}
|
||||||
|
|
||||||
|
component ha0 = H(0);
|
||||||
|
component hb0 = H(1);
|
||||||
|
component hc0 = H(2);
|
||||||
|
component hd0 = H(3);
|
||||||
|
component he0 = H(4);
|
||||||
|
component hf0 = H(5);
|
||||||
|
component hg0 = H(6);
|
||||||
|
component hh0 = H(7);
|
||||||
|
|
||||||
|
component sha256compression[nBlocks];
|
||||||
|
|
||||||
|
for (i=0; i<nBlocks; i++) {
|
||||||
|
|
||||||
|
sha256compression[i] = Sha256compression() ;
|
||||||
|
|
||||||
|
if (i==0) {
|
||||||
|
for (k=0; k<32; k++ ) {
|
||||||
|
sha256compression[i].hin[0*32+k] <== ha0.out[k];
|
||||||
|
sha256compression[i].hin[1*32+k] <== hb0.out[k];
|
||||||
|
sha256compression[i].hin[2*32+k] <== hc0.out[k];
|
||||||
|
sha256compression[i].hin[3*32+k] <== hd0.out[k];
|
||||||
|
sha256compression[i].hin[4*32+k] <== he0.out[k];
|
||||||
|
sha256compression[i].hin[5*32+k] <== hf0.out[k];
|
||||||
|
sha256compression[i].hin[6*32+k] <== hg0.out[k];
|
||||||
|
sha256compression[i].hin[7*32+k] <== hh0.out[k];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (k=0; k<32; k++ ) {
|
||||||
|
sha256compression[i].hin[32*0+k] <== sha256compression[i-1].out[32*0+31-k];
|
||||||
|
sha256compression[i].hin[32*1+k] <== sha256compression[i-1].out[32*1+31-k];
|
||||||
|
sha256compression[i].hin[32*2+k] <== sha256compression[i-1].out[32*2+31-k];
|
||||||
|
sha256compression[i].hin[32*3+k] <== sha256compression[i-1].out[32*3+31-k];
|
||||||
|
sha256compression[i].hin[32*4+k] <== sha256compression[i-1].out[32*4+31-k];
|
||||||
|
sha256compression[i].hin[32*5+k] <== sha256compression[i-1].out[32*5+31-k];
|
||||||
|
sha256compression[i].hin[32*6+k] <== sha256compression[i-1].out[32*6+31-k];
|
||||||
|
sha256compression[i].hin[32*7+k] <== sha256compression[i-1].out[32*7+31-k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (k=0; k<512; k++) {
|
||||||
|
sha256compression[i].inp[k] <== paddedIn[i*512+k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (k=0; k<256; k++) {
|
||||||
|
out[k] <== sha256compression[nBlocks-1].out[k];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
along with circom. If not, see <https://www.gnu.org/licenses/>.
|
along with circom. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
include "constants.circom";
|
||||||
include "sha256compression.circom";
|
include "sha256compression.circom";
|
||||||
include "../bitify.circom"
|
include "../bitify.circom"
|
||||||
|
|
||||||
@@ -25,6 +26,9 @@ template Sha256_2() {
|
|||||||
signal input b;
|
signal input b;
|
||||||
signal output out;
|
signal output out;
|
||||||
|
|
||||||
|
var i;
|
||||||
|
var k;
|
||||||
|
|
||||||
component bits2num = Bits2Num(216);
|
component bits2num = Bits2Num(216);
|
||||||
component num2bits[2];
|
component num2bits[2];
|
||||||
|
|
||||||
@@ -34,9 +38,28 @@ template Sha256_2() {
|
|||||||
num2bits[0].in <== a;
|
num2bits[0].in <== a;
|
||||||
num2bits[1].in <== b;
|
num2bits[1].in <== b;
|
||||||
|
|
||||||
|
|
||||||
component sha256compression = Sha256compression() ;
|
component sha256compression = Sha256compression() ;
|
||||||
|
|
||||||
var i;
|
component ha0 = H(0);
|
||||||
|
component hb0 = H(1);
|
||||||
|
component hc0 = H(2);
|
||||||
|
component hd0 = H(3);
|
||||||
|
component he0 = H(4);
|
||||||
|
component hf0 = H(5);
|
||||||
|
component hg0 = H(6);
|
||||||
|
component hh0 = H(7);
|
||||||
|
|
||||||
|
for (k=0; k<32; k++ ) {
|
||||||
|
sha256compression.hin[0*32+k] <== ha0.out[k];
|
||||||
|
sha256compression.hin[1*32+k] <== hb0.out[k];
|
||||||
|
sha256compression.hin[2*32+k] <== hc0.out[k];
|
||||||
|
sha256compression.hin[3*32+k] <== hd0.out[k];
|
||||||
|
sha256compression.hin[4*32+k] <== he0.out[k];
|
||||||
|
sha256compression.hin[5*32+k] <== hf0.out[k];
|
||||||
|
sha256compression.hin[6*32+k] <== hg0.out[k];
|
||||||
|
sha256compression.hin[7*32+k] <== hh0.out[k];
|
||||||
|
}
|
||||||
|
|
||||||
for (i=0; i<216; i++) {
|
for (i=0; i<216; i++) {
|
||||||
sha256compression.inp[i] <== num2bits[0].out[215-i];
|
sha256compression.inp[i] <== num2bits[0].out[215-i];
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ include "../binsum.circom";
|
|||||||
include "sigmaplus.circom";
|
include "sigmaplus.circom";
|
||||||
|
|
||||||
template Sha256compression() {
|
template Sha256compression() {
|
||||||
|
signal input hin[256];
|
||||||
signal input inp[512];
|
signal input inp[512];
|
||||||
signal output out[256];
|
signal output out[256];
|
||||||
signal a[65][32];
|
signal a[65][32];
|
||||||
@@ -44,15 +45,6 @@ template Sha256compression() {
|
|||||||
component ct_k[64];
|
component ct_k[64];
|
||||||
for (i=0; i<64; i++) ct_k[i] = K(i);
|
for (i=0; i<64; i++) ct_k[i] = K(i);
|
||||||
|
|
||||||
component ha0 = H(0);
|
|
||||||
component hb0 = H(1);
|
|
||||||
component hc0 = H(2);
|
|
||||||
component hd0 = H(3);
|
|
||||||
component he0 = H(4);
|
|
||||||
component hf0 = H(5);
|
|
||||||
component hg0 = H(6);
|
|
||||||
component hh0 = H(7);
|
|
||||||
|
|
||||||
component t1[64];
|
component t1[64];
|
||||||
for (i=0; i<64; i++) t1[i] = T1();
|
for (i=0; i<64; i++) t1[i] = T1();
|
||||||
|
|
||||||
@@ -88,14 +80,14 @@ template Sha256compression() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (k=0; k<32; k++ ) {
|
for (k=0; k<32; k++ ) {
|
||||||
a[0][k] <== ha0.out[k]
|
a[0][k] <== hin[k];
|
||||||
b[0][k] <== hb0.out[k]
|
b[0][k] <== hin[32*1 + k];
|
||||||
c[0][k] <== hc0.out[k]
|
c[0][k] <== hin[32*2 + k];
|
||||||
d[0][k] <== hd0.out[k]
|
d[0][k] <== hin[32*3 + k];
|
||||||
e[0][k] <== he0.out[k]
|
e[0][k] <== hin[32*4 + k];
|
||||||
f[0][k] <== hf0.out[k]
|
f[0][k] <== hin[32*5 + k];
|
||||||
g[0][k] <== hg0.out[k]
|
g[0][k] <== hin[32*6 + k];
|
||||||
h[0][k] <== hh0.out[k]
|
h[0][k] <== hin[32*7 + k];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (t = 0; t<64; t++) {
|
for (t = 0; t<64; t++) {
|
||||||
@@ -133,21 +125,21 @@ template Sha256compression() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (k=0; k<32; k++) {
|
for (k=0; k<32; k++) {
|
||||||
fsum[0].in[0][k] <== ha0.out[k];
|
fsum[0].in[0][k] <== hin[32*0+k];
|
||||||
fsum[0].in[1][k] <== a[64][k];
|
fsum[0].in[1][k] <== a[64][k];
|
||||||
fsum[1].in[0][k] <== hb0.out[k];
|
fsum[1].in[0][k] <== hin[32*1+k];
|
||||||
fsum[1].in[1][k] <== b[64][k];
|
fsum[1].in[1][k] <== b[64][k];
|
||||||
fsum[2].in[0][k] <== hc0.out[k];
|
fsum[2].in[0][k] <== hin[32*2+k];
|
||||||
fsum[2].in[1][k] <== c[64][k];
|
fsum[2].in[1][k] <== c[64][k];
|
||||||
fsum[3].in[0][k] <== hd0.out[k];
|
fsum[3].in[0][k] <== hin[32*3+k];
|
||||||
fsum[3].in[1][k] <== d[64][k];
|
fsum[3].in[1][k] <== d[64][k];
|
||||||
fsum[4].in[0][k] <== he0.out[k];
|
fsum[4].in[0][k] <== hin[32*4+k];
|
||||||
fsum[4].in[1][k] <== e[64][k];
|
fsum[4].in[1][k] <== e[64][k];
|
||||||
fsum[5].in[0][k] <== hf0.out[k];
|
fsum[5].in[0][k] <== hin[32*5+k];
|
||||||
fsum[5].in[1][k] <== f[64][k];
|
fsum[5].in[1][k] <== f[64][k];
|
||||||
fsum[6].in[0][k] <== hg0.out[k];
|
fsum[6].in[0][k] <== hin[32*6+k];
|
||||||
fsum[6].in[1][k] <== g[64][k];
|
fsum[6].in[1][k] <== g[64][k];
|
||||||
fsum[7].in[0][k] <== hh0.out[k];
|
fsum[7].in[0][k] <== hin[32*7+k];
|
||||||
fsum[7].in[1][k] <== h[64][k];
|
fsum[7].in[1][k] <== h[64][k];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
3
index.js
3
index.js
@@ -4,3 +4,6 @@ exports.mimc7 = require("./src/mimc7");
|
|||||||
exports.mimcsponge = require("./src/mimcsponge");
|
exports.mimcsponge = require("./src/mimcsponge");
|
||||||
exports.babyJub = require("./src/babyjub");
|
exports.babyJub = require("./src/babyjub");
|
||||||
exports.pedersenHash = require("./src/pedersenHash");
|
exports.pedersenHash = require("./src/pedersenHash");
|
||||||
|
exports.SMT = require("./src/smt").SMT;
|
||||||
|
exports.SMTMemDB = require("./src/smt_memdb");
|
||||||
|
exports.poseidon = require("./src/poseidon");
|
||||||
|
|||||||
26
package-lock.json
generated
26
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "circomlib",
|
"name": "circomlib",
|
||||||
"version": "0.0.14",
|
"version": "0.0.19",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -348,9 +348,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"big-integer": {
|
"big-integer": {
|
||||||
"version": "1.6.44",
|
"version": "1.6.46",
|
||||||
"resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.44.tgz",
|
"resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.46.tgz",
|
||||||
"integrity": "sha512-7MzElZPTyJ2fNvBkPxtFQ2fWIkVmuzw41+BZHSzpEq3ymB2MfeKp1+yXl/tS75xCx+WnyV+yb0kp+K1C3UNwmQ=="
|
"integrity": "sha512-Vj2TNtZ8Y0XaL6HCkzJiEqfykjtv/9wVCWIutMe+QVIXLPe2tCLEzULtYvcX9WRtmNIj3Jqi5tNjIsR0N4QOsg=="
|
||||||
},
|
},
|
||||||
"binary-extensions": {
|
"binary-extensions": {
|
||||||
"version": "1.13.1",
|
"version": "1.13.1",
|
||||||
@@ -601,9 +601,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"circom": {
|
"circom": {
|
||||||
"version": "0.0.28",
|
"version": "0.0.34",
|
||||||
"resolved": "https://registry.npmjs.org/circom/-/circom-0.0.28.tgz",
|
"resolved": "https://registry.npmjs.org/circom/-/circom-0.0.34.tgz",
|
||||||
"integrity": "sha512-cYivdFVPUAVsGFgx3/W3BQe50fwiu+w8Mq9rWA/UYLWwjAgY0Ctk+obpxGL5v9ZHJpO6pvmczLnOXmV/KqiB5g==",
|
"integrity": "sha512-R7yNW8PtX2xREtLYWZ/o5cfKHT/qa+CveXsGVAX1ej7mPrTat9mlEMXEy2vX//IuP9/cnYTY/KxJ2SN05PUeGA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"big-integer": "^1.6.32",
|
"big-integer": "^1.6.32",
|
||||||
@@ -3929,9 +3929,9 @@
|
|||||||
"integrity": "sha512-Y3W0wlRPK8ZMRbNq97l4M5otioeA5lm1z7bkNkxCka8HSPjR0xRWmpCmc9utiaLP9Jb1eD8BgeIxTW4AIF45Pg=="
|
"integrity": "sha512-Y3W0wlRPK8ZMRbNq97l4M5otioeA5lm1z7bkNkxCka8HSPjR0xRWmpCmc9utiaLP9Jb1eD8BgeIxTW4AIF45Pg=="
|
||||||
},
|
},
|
||||||
"p-limit": {
|
"p-limit": {
|
||||||
"version": "2.2.0",
|
"version": "2.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.1.tgz",
|
||||||
"integrity": "sha512-pZbTJpoUsCzV48Mc9Nh51VbwO0X9cuPFE8gYwx9BTCt9SF8/b7Zljd2fVgOxhIF/HDTKgpVzs+GPhyKfjLLFRQ==",
|
"integrity": "sha512-85Tk+90UCVWvbDavCLKPOLC9vvY8OwEX/RtKF+/1OADJMVlFfEHOiMTPVyxg7mk/dKa+ipdHm0OUkTvCpMTuwg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"p-try": "^2.0.0"
|
"p-try": "^2.0.0"
|
||||||
}
|
}
|
||||||
@@ -4703,9 +4703,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"snarkjs": {
|
"snarkjs": {
|
||||||
"version": "0.1.18",
|
"version": "0.1.20",
|
||||||
"resolved": "https://registry.npmjs.org/snarkjs/-/snarkjs-0.1.18.tgz",
|
"resolved": "https://registry.npmjs.org/snarkjs/-/snarkjs-0.1.20.tgz",
|
||||||
"integrity": "sha512-JWZMBvPPIL424+QCY0PtreIiHTRoX4h4qYvKv3nqKPVZl0T7sw3B/ZeizrCVRz7Jr9vrwZxmzJ0XIg6D1yC8Mg==",
|
"integrity": "sha512-tYmWiVm1sZiB44aIh5w/3HUaTntTUC4fv+CWs4rR0gfkt2KbHTpArOqZW++/Lxujrn9IypXVhdKVUr/eE6Hxfg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"big-integer": "^1.6.43",
|
"big-integer": "^1.6.43",
|
||||||
"chai": "^4.2.0",
|
"chai": "^4.2.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "circomlib",
|
"name": "circomlib",
|
||||||
"version": "0.0.14",
|
"version": "0.0.19",
|
||||||
"description": "Basic circuits library for Circom",
|
"description": "Basic circuits library for Circom",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"directories": {
|
"directories": {
|
||||||
@@ -26,12 +26,12 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"blake-hash": "^1.1.0",
|
"blake-hash": "^1.1.0",
|
||||||
"blake2b": "^2.1.3",
|
"blake2b": "^2.1.3",
|
||||||
"snarkjs": "^0.1.18",
|
"snarkjs": "^0.1.20",
|
||||||
"typedarray-to-buffer": "^3.1.5",
|
"typedarray-to-buffer": "^3.1.5",
|
||||||
"web3": "^1.0.0-beta.55"
|
"web3": "^1.0.0-beta.55"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"circom": "0.0.28",
|
"circom": "0.0.34",
|
||||||
"eslint-plugin-mocha": "^5.2.0",
|
"eslint-plugin-mocha": "^5.2.0",
|
||||||
"ganache-cli": "^6.4.4",
|
"ganache-cli": "^6.4.4",
|
||||||
"mocha": "^5.2.0"
|
"mocha": "^5.2.0"
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ exports.createHash = (t, nRoundsF, nRoundsP, seed) => {
|
|||||||
const M = exports.getMatrix(t, seed, nRoundsF + nRoundsP);
|
const M = exports.getMatrix(t, seed, nRoundsF + nRoundsP);
|
||||||
return function(inputs) {
|
return function(inputs) {
|
||||||
let state = [];
|
let state = [];
|
||||||
assert(inputs.length < t);
|
assert(inputs.length <= t);
|
||||||
assert(inputs.length > 0);
|
assert(inputs.length > 0);
|
||||||
for (let i=0; i<inputs.length; i++) state[i] = bigInt(inputs[i]);
|
for (let i=0; i<inputs.length; i++) state[i] = bigInt(inputs[i]);
|
||||||
for (let i=inputs.length; i<t; i++) state[i] = F.zero;
|
for (let i=inputs.length; i<t; i++) state[i] = F.zero;
|
||||||
|
|||||||
@@ -309,3 +309,5 @@ async function newMemEmptyTrie() {
|
|||||||
|
|
||||||
module.exports.loadFromFile = loadFromFile;
|
module.exports.loadFromFile = loadFromFile;
|
||||||
module.exports.newMemEmptyTrie = newMemEmptyTrie;
|
module.exports.newMemEmptyTrie = newMemEmptyTrie;
|
||||||
|
module.exports.SMT = SMT;
|
||||||
|
module.exports.SMTMemDB = SMTMemDB;
|
||||||
|
|||||||
@@ -27,6 +27,14 @@ class SMTMemDb {
|
|||||||
return this.nodes[keyS];
|
return this.nodes[keyS];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async multiGet(keys) {
|
||||||
|
const promises = [];
|
||||||
|
for (let i=0; i<keys.length; i++) {
|
||||||
|
promises.push(this.get(keys[i]));
|
||||||
|
}
|
||||||
|
return await Promise.all(promises);
|
||||||
|
}
|
||||||
|
|
||||||
async setRoot(rt) {
|
async setRoot(rt) {
|
||||||
this.root = rt;
|
this.root = rt;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,776 +0,0 @@
|
|||||||
{
|
|
||||||
"mainCode": "{\n {\n }\n}\n",
|
|
||||||
"signalName2Idx": {
|
|
||||||
"one": 0,
|
|
||||||
"main.in": 33,
|
|
||||||
"main.out[0][0]": 1,
|
|
||||||
"main.out[0][1]": 2,
|
|
||||||
"main.out[1][0]": 3,
|
|
||||||
"main.out[1][1]": 4,
|
|
||||||
"main.out[2][0]": 5,
|
|
||||||
"main.out[2][1]": 6,
|
|
||||||
"main.out[3][0]": 7,
|
|
||||||
"main.out[3][1]": 8,
|
|
||||||
"main.out[4][0]": 9,
|
|
||||||
"main.out[4][1]": 10,
|
|
||||||
"main.out[5][0]": 11,
|
|
||||||
"main.out[5][1]": 12,
|
|
||||||
"main.out[6][0]": 13,
|
|
||||||
"main.out[6][1]": 14,
|
|
||||||
"main.out[7][0]": 15,
|
|
||||||
"main.out[7][1]": 16,
|
|
||||||
"main.out[8][0]": 17,
|
|
||||||
"main.out[8][1]": 18,
|
|
||||||
"main.out[9][0]": 19,
|
|
||||||
"main.out[9][1]": 20,
|
|
||||||
"main.out[10][0]": 21,
|
|
||||||
"main.out[10][1]": 22,
|
|
||||||
"main.out[11][0]": 23,
|
|
||||||
"main.out[11][1]": 24,
|
|
||||||
"main.out[12][0]": 25,
|
|
||||||
"main.out[12][1]": 26,
|
|
||||||
"main.out[13][0]": 27,
|
|
||||||
"main.out[13][1]": 28,
|
|
||||||
"main.out[14][0]": 29,
|
|
||||||
"main.out[14][1]": 30,
|
|
||||||
"main.out[15][0]": 31,
|
|
||||||
"main.out[15][1]": 32,
|
|
||||||
"main.escalarMul.out[0][0]": 34,
|
|
||||||
"main.escalarMul.out[0][1]": 35,
|
|
||||||
"main.escalarMul.out[1][0]": 36,
|
|
||||||
"main.escalarMul.out[1][1]": 37,
|
|
||||||
"main.escalarMul.out[2][0]": 38,
|
|
||||||
"main.escalarMul.out[2][1]": 39,
|
|
||||||
"main.escalarMul.out[3][0]": 40,
|
|
||||||
"main.escalarMul.out[3][1]": 41,
|
|
||||||
"main.escalarMul.out[4][0]": 42,
|
|
||||||
"main.escalarMul.out[4][1]": 43,
|
|
||||||
"main.escalarMul.out[5][0]": 44,
|
|
||||||
"main.escalarMul.out[5][1]": 45,
|
|
||||||
"main.escalarMul.out[6][0]": 46,
|
|
||||||
"main.escalarMul.out[6][1]": 47,
|
|
||||||
"main.escalarMul.out[7][0]": 48,
|
|
||||||
"main.escalarMul.out[7][1]": 49,
|
|
||||||
"main.escalarMul.out[8][0]": 50,
|
|
||||||
"main.escalarMul.out[8][1]": 51,
|
|
||||||
"main.escalarMul.out[9][0]": 52,
|
|
||||||
"main.escalarMul.out[9][1]": 53,
|
|
||||||
"main.escalarMul.out[10][0]": 54,
|
|
||||||
"main.escalarMul.out[10][1]": 55,
|
|
||||||
"main.escalarMul.out[11][0]": 56,
|
|
||||||
"main.escalarMul.out[11][1]": 57,
|
|
||||||
"main.escalarMul.out[12][0]": 58,
|
|
||||||
"main.escalarMul.out[12][1]": 59,
|
|
||||||
"main.escalarMul.out[13][0]": 60,
|
|
||||||
"main.escalarMul.out[13][1]": 61,
|
|
||||||
"main.escalarMul.out[14][0]": 62,
|
|
||||||
"main.escalarMul.out[14][1]": 63,
|
|
||||||
"main.escalarMul.out[15][0]": 64,
|
|
||||||
"main.escalarMul.out[15][1]": 65
|
|
||||||
},
|
|
||||||
"components": [
|
|
||||||
{
|
|
||||||
"name": "main",
|
|
||||||
"params": {},
|
|
||||||
"template": "Main",
|
|
||||||
"inputSignals": 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "main.escalarMul",
|
|
||||||
"params": {
|
|
||||||
"base": [
|
|
||||||
"5299619240641551281634865583518297030282874472190772894086521144482721001553",
|
|
||||||
"16950150798460657717958625567821834550301663161624707787222815936182638968203"
|
|
||||||
],
|
|
||||||
"k": "0"
|
|
||||||
},
|
|
||||||
"template": "EscalarMulW4Table",
|
|
||||||
"inputSignals": 0
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"componentName2Idx": {
|
|
||||||
"main": 0,
|
|
||||||
"main.escalarMul": 1
|
|
||||||
},
|
|
||||||
"signals": [
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"one"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[0][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[0][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[1][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[1][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[2][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[2][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[3][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[3][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[4][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[4][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[5][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[5][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[6][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[6][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[7][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[7][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[8][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[8][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[9][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[9][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[10][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[10][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[11][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[11][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[12][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[12][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[13][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[13][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[14][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[14][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[15][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.out[15][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.in"
|
|
||||||
],
|
|
||||||
"triggerComponents": [
|
|
||||||
0
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[0][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[0][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[1][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[1][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[2][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[2][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[3][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[3][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[4][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[4][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[5][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[5][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[6][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[6][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[7][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[7][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[8][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[8][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[9][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[9][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[10][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[10][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[11][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[11][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[12][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[12][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[13][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[13][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[14][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[14][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[15][0]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"names": [
|
|
||||||
"main.escalarMul.out[15][1]"
|
|
||||||
],
|
|
||||||
"triggerComponents": []
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"constraints": [
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"33": "1"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"1": "21888242871839275222246405745257275088548364400416034343698204186575808495616"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"2": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "1"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"3": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "5299619240641551281634865583518297030282874472190772894086521144482721001553"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"4": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "16950150798460657717958625567821834550301663161624707787222815936182638968203"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"5": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "10031262171927540148667355526369034398030886437092045105752248699557385197826"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"6": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "633281375905621697187330766174974863687049529291089048651929454608812697683"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"7": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "2763488322167937039616325905516046217694264098671987087929565332380420898366"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"8": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "15305195750036305661220525648961313310481046260814497672243197092298550508693"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"9": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "12252886604826192316928789929706397349846234911198931249025449955069330867144"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"10": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "1286140751908834028607023759717162073146610688084909004843365841635476459484"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"11": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "11480966271046430430613841218147196773252373073876138147006741179837832100836"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"12": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "15148236048131954717802795400425086368006776860859772698778589175317365693546"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"13": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "10483991165196995731760716870725509190315033255344071753161464961897900552628"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"14": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "16822899191463256771813724222715007505997804748105685077895991386716774358231"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"15": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "20092560661213339045022877747484245238324772779820628739268223482659246842641"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"16": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "12112450042127193446189577552007703839818242727902437791835414514847797088033"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"17": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "7582035475627193640797276505418002166691739036475590846121162698650004832581"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"18": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "7801528930831391612913542953849263092120765287178679640990215688947513841260"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"19": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "4705897243203718691035604313913899717760209962238015362153877735592901317263"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"20": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "11533909001000295577818857040682494493436124051895563619976413559559984357704"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"21": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "153240920024090527149238595127650983736082984617707450012091413752625486998"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"22": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "4020276081434545615309760015178511782232038136121596626881988383789905359767"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"23": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "21605515851820432880964235241069234202284600780825340516808373216881770219365"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"24": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "18856460861531942120859708048677603751294231190189224157283439874962410808705"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"25": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "13745444942333935831105476262872495530232646590228527111681360848540626474828"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"26": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "12593235468414968750242085888471035041062129592669413010808753916989521208231"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"27": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "2645068156583085050795409844793952496341966587935372213947442411891928926825"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"28": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "18721023485287444620535873833099074300132272004358512346950884094158923211889"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"29": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "6271573312546148160329629673815240458676221818610765478794395550121752710497"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"30": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "20729133862440981855920571719405839551572203482913253618619962546642052100217"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"31": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "5958787406588418500595239545974275039455545059833263445973445578199987122248"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"32": "21888242871839275222246405745257275088548364400416034343698204186575808495616",
|
|
||||||
"33": "6291453822075498887551694851992571215511219854100590306020486222643399599966"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
],
|
|
||||||
"templates": {
|
|
||||||
"EscalarMulW4Table": "function(ctx) {\n ctx.setVar(\"dbl\", [], ctx.getVar(\"base\",[]));\n for (ctx.setVar(\"i\", [], \"0\");bigInt(bigInt(ctx.getVar(\"i\",[])).lt(bigInt(bigInt(ctx.getVar(\"k\",[])).mul(bigInt(\"4\")).mod(__P__))) ? 1 : 0).neq(bigInt(0));(ctx.setVar(\"i\", [], bigInt(ctx.getVar(\"i\",[])).add(bigInt(\"1\")).mod(__P__))).add(__P__).sub(bigInt(1)).mod(__P__)) { \n {\n ctx.setVar(\"dbl\", [], ctx.callFunction(\"pointAdd\", [ctx.getVar(\"dbl\",[\"0\"]),ctx.getVar(\"dbl\",[\"1\"]),ctx.getVar(\"dbl\",[\"0\"]),ctx.getVar(\"dbl\",[\"1\"])]));\n }\n\n }\n ctx.setSignal(\"out\", [\"0\",\"0\"], \"0\");\n ctx.assert(ctx.getSignal(\"out\", [\"0\",\"0\"]), \"0\");\n ctx.setSignal(\"out\", [\"0\",\"1\"], \"1\");\n ctx.assert(ctx.getSignal(\"out\", [\"0\",\"1\"]), \"1\");\n for (ctx.setVar(\"i\", [], \"1\");bigInt(bigInt(ctx.getVar(\"i\",[])).lt(bigInt(\"16\")) ? 1 : 0).neq(bigInt(0));(ctx.setVar(\"i\", [], bigInt(ctx.getVar(\"i\",[])).add(bigInt(\"1\")).mod(__P__))).add(__P__).sub(bigInt(1)).mod(__P__)) { \n {\n ctx.setVar(\"p\", [], ctx.callFunction(\"pointAdd\", [ctx.getSignal(\"out\", [bigInt(ctx.getVar(\"i\",[])).add(__P__).sub(bigInt(\"1\")).mod(__P__),\"0\"]),ctx.getSignal(\"out\", [bigInt(ctx.getVar(\"i\",[])).add(__P__).sub(bigInt(\"1\")).mod(__P__),\"1\"]),ctx.getVar(\"dbl\",[\"0\"]),ctx.getVar(\"dbl\",[\"1\"])]));\n ctx.setSignal(\"out\", [ctx.getVar(\"i\",[]),\"0\"], ctx.getVar(\"p\",[\"0\"]));\n ctx.assert(ctx.getSignal(\"out\", [ctx.getVar(\"i\",[]),\"0\"]), ctx.getVar(\"p\",[\"0\"]));\n ctx.setSignal(\"out\", [ctx.getVar(\"i\",[]),\"1\"], ctx.getVar(\"p\",[\"1\"]));\n ctx.assert(ctx.getSignal(\"out\", [ctx.getVar(\"i\",[]),\"1\"]), ctx.getVar(\"p\",[\"1\"]));\n }\n\n }\n}\n",
|
|
||||||
"Main": "function(ctx) {\n ctx.setVar(\"base\", [], [\"5299619240641551281634865583518297030282874472190772894086521144482721001553\",\"16950150798460657717958625567821834550301663161624707787222815936182638968203\"]);\n for (ctx.setVar(\"i\", [], \"0\");bigInt(bigInt(ctx.getVar(\"i\",[])).lt(bigInt(\"16\")) ? 1 : 0).neq(bigInt(0));(ctx.setVar(\"i\", [], bigInt(ctx.getVar(\"i\",[])).add(bigInt(\"1\")).mod(__P__))).add(__P__).sub(bigInt(1)).mod(__P__)) { \n {\n ctx.setSignal(\"out\", [ctx.getVar(\"i\",[]),\"0\"], bigInt(ctx.getPin(\"escalarMul\", [], \"out\", [ctx.getVar(\"i\",[]),\"0\"])).mul(bigInt(ctx.getSignal(\"in\", []))).mod(__P__));\n ctx.assert(ctx.getSignal(\"out\", [ctx.getVar(\"i\",[]),\"0\"]), bigInt(ctx.getPin(\"escalarMul\", [], \"out\", [ctx.getVar(\"i\",[]),\"0\"])).mul(bigInt(ctx.getSignal(\"in\", []))).mod(__P__));\n ctx.setSignal(\"out\", [ctx.getVar(\"i\",[]),\"1\"], bigInt(ctx.getPin(\"escalarMul\", [], \"out\", [ctx.getVar(\"i\",[]),\"1\"])).mul(bigInt(ctx.getSignal(\"in\", []))).mod(__P__));\n ctx.assert(ctx.getSignal(\"out\", [ctx.getVar(\"i\",[]),\"1\"]), bigInt(ctx.getPin(\"escalarMul\", [], \"out\", [ctx.getVar(\"i\",[]),\"1\"])).mul(bigInt(ctx.getSignal(\"in\", []))).mod(__P__));\n }\n\n }\n}\n"
|
|
||||||
},
|
|
||||||
"functions": {
|
|
||||||
"pointAdd": {
|
|
||||||
"params": [
|
|
||||||
"x1",
|
|
||||||
"y1",
|
|
||||||
"x2",
|
|
||||||
"y2"
|
|
||||||
],
|
|
||||||
"func": "function(ctx) {\n ctx.setVar(\"a\", [], \"168700\");\n ctx.setVar(\"d\", [], \"168696\");\n ctx.setVar(\"res\", [\"0\"], bigInt(bigInt(bigInt(ctx.getVar(\"x1\",[])).mul(bigInt(ctx.getVar(\"y2\",[]))).mod(__P__)).add(bigInt(bigInt(ctx.getVar(\"y1\",[])).mul(bigInt(ctx.getVar(\"x2\",[]))).mod(__P__))).mod(__P__)).mul( bigInt(bigInt(\"1\").add(bigInt(bigInt(bigInt(bigInt(bigInt(ctx.getVar(\"d\",[])).mul(bigInt(ctx.getVar(\"x1\",[]))).mod(__P__)).mul(bigInt(ctx.getVar(\"x2\",[]))).mod(__P__)).mul(bigInt(ctx.getVar(\"y1\",[]))).mod(__P__)).mul(bigInt(ctx.getVar(\"y2\",[]))).mod(__P__))).mod(__P__)).inverse(__P__) ).mod(__P__));\n ctx.setVar(\"res\", [\"1\"], bigInt(bigInt(bigInt(ctx.getVar(\"y1\",[])).mul(bigInt(ctx.getVar(\"y2\",[]))).mod(__P__)).add(__P__).sub(bigInt(bigInt(bigInt(ctx.getVar(\"a\",[])).mul(bigInt(ctx.getVar(\"x1\",[]))).mod(__P__)).mul(bigInt(ctx.getVar(\"x2\",[]))).mod(__P__))).mod(__P__)).mul( bigInt(bigInt(\"1\").add(__P__).sub(bigInt(bigInt(bigInt(bigInt(bigInt(ctx.getVar(\"d\",[])).mul(bigInt(ctx.getVar(\"x1\",[]))).mod(__P__)).mul(bigInt(ctx.getVar(\"x2\",[]))).mod(__P__)).mul(bigInt(ctx.getVar(\"y1\",[]))).mod(__P__)).mul(bigInt(ctx.getVar(\"y2\",[]))).mod(__P__))).mod(__P__)).inverse(__P__) ).mod(__P__));\n return ctx.getVar(\"res\",[]);;\n}\n"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nPrvInputs": 0,
|
|
||||||
"nPubInputs": 1,
|
|
||||||
"nInputs": 1,
|
|
||||||
"nOutputs": 32,
|
|
||||||
"nVars": 34,
|
|
||||||
"nConstants": 32,
|
|
||||||
"nSignals": 66
|
|
||||||
}
|
|
||||||
3
test/circuits/sha256_test448.circom
Normal file
3
test/circuits/sha256_test448.circom
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
include "../../circuits/sha256/sha256.circom";
|
||||||
|
|
||||||
|
component main = Sha256(448);
|
||||||
3
test/circuits/sha256_test512.circom
Normal file
3
test/circuits/sha256_test512.circom
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
include "../../circuits/sha256/sha256.circom";
|
||||||
|
|
||||||
|
component main = Sha256(512);
|
||||||
@@ -12,7 +12,7 @@ describe("EdDSA js test", function () {
|
|||||||
|
|
||||||
this.timeout(100000);
|
this.timeout(100000);
|
||||||
|
|
||||||
it("Sign a single 10 bytes from 0 to 9", () => {
|
it("Sign (using Mimc7) a single 10 bytes from 0 to 9", () => {
|
||||||
const msgBuf = Buffer.from("00010203040506070809", "hex");
|
const msgBuf = Buffer.from("00010203040506070809", "hex");
|
||||||
const msg = bigInt.leBuff2int(msgBuf);
|
const msg = bigInt.leBuff2int(msgBuf);
|
||||||
|
|
||||||
@@ -46,4 +46,37 @@ describe("EdDSA js test", function () {
|
|||||||
assert(eddsa.verifyMiMC(msg, uSignature, pubKey));
|
assert(eddsa.verifyMiMC(msg, uSignature, pubKey));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Sign (using Poseidon) a single 10 bytes from 0 to 9", () => {
|
||||||
|
const msgBuf = Buffer.from("00010203040506070809", "hex");
|
||||||
|
const msg = bigInt.leBuff2int(msgBuf);
|
||||||
|
|
||||||
|
const prvKey = Buffer.from("0001020304050607080900010203040506070809000102030405060708090001", "hex");
|
||||||
|
|
||||||
|
const pubKey = eddsa.prv2pub(prvKey);
|
||||||
|
|
||||||
|
assert.equal(pubKey[0].toString(),
|
||||||
|
"13277427435165878497778222415993513565335242147425444199013288855685581939618");
|
||||||
|
assert.equal(pubKey[1].toString(),
|
||||||
|
"13622229784656158136036771217484571176836296686641868549125388198837476602820");
|
||||||
|
|
||||||
|
const pPubKey = babyJub.packPoint(pubKey);
|
||||||
|
|
||||||
|
const signature = eddsa.signPoseidon(prvKey, msg);
|
||||||
|
assert.equal(signature.R8[0].toString(),
|
||||||
|
"11384336176656855268977457483345535180380036354188103142384839473266348197733");
|
||||||
|
assert.equal(signature.R8[1].toString(),
|
||||||
|
"15383486972088797283337779941324724402501462225528836549661220478783371668959");
|
||||||
|
assert.equal(signature.S.toString(),
|
||||||
|
"248298168863866362217836334079793350221620631973732197668910946177382043688");
|
||||||
|
|
||||||
|
const pSignature = eddsa.packSignature(signature);
|
||||||
|
assert.equal(pSignature.toString("hex"), ""+
|
||||||
|
"dfedb4315d3f2eb4de2d3c510d7a987dcab67089c8ace06308827bf5bcbe02a2"+
|
||||||
|
"28506bce274aa1b3f7e7c2fd7e4fe09bff8f9aa37a42def7994e98f322888c00");
|
||||||
|
|
||||||
|
const uSignature = eddsa.unpackSignature(pSignature);
|
||||||
|
assert(eddsa.verifyPoseidon(msg, uSignature, pubKey));
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
23
test/rawsmt3.circom
Normal file
23
test/rawsmt3.circom
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
|
||||||
|
include "../circuits/smt/smtverifier.circom";
|
||||||
|
template SMT(nLevels) {
|
||||||
|
signal input root;
|
||||||
|
signal input mtp[nLevels];
|
||||||
|
signal input hi;
|
||||||
|
signal input hv;
|
||||||
|
|
||||||
|
component smtClaimExists = SMTVerifier(nLevels);
|
||||||
|
smtClaimExists.enabled <== 1;
|
||||||
|
smtClaimExists.fnc <== 0;
|
||||||
|
smtClaimExists.root <== root;
|
||||||
|
for (var i=0; i<nLevels; i++) {
|
||||||
|
smtClaimExists.siblings[i] <== mtp[i];
|
||||||
|
}
|
||||||
|
smtClaimExists.oldKey <== 0;
|
||||||
|
smtClaimExists.oldValue <== 0;
|
||||||
|
smtClaimExists.isOld0 <== 0;
|
||||||
|
|
||||||
|
smtClaimExists.key <== hi;
|
||||||
|
smtClaimExists.value <== hv;
|
||||||
|
}
|
||||||
|
component main = SMT(4);
|
||||||
@@ -12,8 +12,43 @@ const sha256 = require("./helpers/sha256");
|
|||||||
// const printSignal = require("./helpers/printsignal");
|
// const printSignal = require("./helpers/printsignal");
|
||||||
|
|
||||||
|
|
||||||
|
function buffer2bitArray(b) {
|
||||||
|
const res = [];
|
||||||
|
for (let i=0; i<b.length; i++) {
|
||||||
|
for (let j=0; j<8; j++) {
|
||||||
|
res.push((b[i] >> (7-j) &1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
function bitArray2buffer(a) {
|
||||||
|
const len = Math.floor((a.length -1 )/8)+1;
|
||||||
|
const b = new Buffer.alloc(len);
|
||||||
|
|
||||||
|
for (let i=0; i<a.length; i++) {
|
||||||
|
const p = Math.floor(i/8);
|
||||||
|
b[p] = b[p] | (Number(a[i]) << ( 7 - (i%8) ));
|
||||||
|
}
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
describe("SHA256 test", () => {
|
describe("SHA256 test", () => {
|
||||||
it("Should calculate a hash", async () => {
|
|
||||||
|
|
||||||
|
it("Should work bits to array and array to bits", async () => {
|
||||||
|
const b = new Buffer.alloc(64);
|
||||||
|
for (let i=0; i<64; i++) {
|
||||||
|
b[i] = i+1;
|
||||||
|
}
|
||||||
|
const a = buffer2bitArray(b);
|
||||||
|
const b2 = bitArray2buffer(a);
|
||||||
|
|
||||||
|
assert.equal(b.toString("hex"), b2.toString("hex"));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should calculate a hash of 1 compressor", async () => {
|
||||||
const cirDef = await compiler(path.join(__dirname, "circuits", "sha256_2_test.circom"));
|
const cirDef = await compiler(path.join(__dirname, "circuits", "sha256_2_test.circom"));
|
||||||
const circuit = new snarkjs.Circuit(cirDef);
|
const circuit = new snarkjs.Circuit(cirDef);
|
||||||
|
|
||||||
@@ -38,5 +73,64 @@ describe("SHA256 test", () => {
|
|||||||
assert(witness[1].equals(snarkjs.bigInt(r)));
|
assert(witness[1].equals(snarkjs.bigInt(r)));
|
||||||
}).timeout(1000000);
|
}).timeout(1000000);
|
||||||
|
|
||||||
|
it("Should calculate a hash of 2 compressor", async () => {
|
||||||
|
const cirDef = await compiler(path.join(__dirname, "circuits", "sha256_test512.circom"), {reduceConstraints:false} );
|
||||||
|
const circuit = new snarkjs.Circuit(cirDef);
|
||||||
|
|
||||||
|
console.log("Vars: "+circuit.nVars);
|
||||||
|
console.log("Constraints: "+circuit.nConstraints);
|
||||||
|
|
||||||
|
/*
|
||||||
|
const testStr = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
|
||||||
|
|
||||||
|
const b = Buffer.from(testStr, 'utf8');
|
||||||
|
*/
|
||||||
|
const b = new Buffer.alloc(64);
|
||||||
|
for (let i=0; i<64; i++) {
|
||||||
|
b[i] = i+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const hash = crypto.createHash("sha256")
|
||||||
|
.update(b)
|
||||||
|
.digest("hex");
|
||||||
|
|
||||||
|
const arrIn = buffer2bitArray(b);
|
||||||
|
const witness = circuit.calculateWitness({ "in": arrIn } /*, {logOutput: true} */);
|
||||||
|
|
||||||
|
const arrOut = witness.slice(1, 257);
|
||||||
|
const hash2 = bitArray2buffer(arrOut).toString("hex");
|
||||||
|
|
||||||
|
assert.equal(hash, hash2);
|
||||||
|
|
||||||
|
}).timeout(1000000);
|
||||||
|
|
||||||
|
|
||||||
|
it("Should calculate a hash of 2 compressor", async () => {
|
||||||
|
const cirDef = await compiler(path.join(__dirname, "circuits", "sha256_test448.circom"), {reduceConstraints:false} );
|
||||||
|
const circuit = new snarkjs.Circuit(cirDef);
|
||||||
|
|
||||||
|
console.log("Vars: "+circuit.nVars);
|
||||||
|
console.log("Constraints: "+circuit.nConstraints);
|
||||||
|
|
||||||
|
|
||||||
|
const testStr = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
|
||||||
|
|
||||||
|
const b = Buffer.from(testStr, 'utf8');
|
||||||
|
for (let i=0; i<64; i++) {
|
||||||
|
b[i] = i+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const hash = crypto.createHash("sha256")
|
||||||
|
.update(b)
|
||||||
|
.digest("hex");
|
||||||
|
|
||||||
|
const arrIn = buffer2bitArray(b);
|
||||||
|
const witness = circuit.calculateWitness({ "in": arrIn } /*, {logOutput: true} */);
|
||||||
|
|
||||||
|
const arrOut = witness.slice(1, 257);
|
||||||
|
const hash2 = bitArray2buffer(arrOut).toString("hex");
|
||||||
|
|
||||||
|
assert.equal(hash, hash2);
|
||||||
|
|
||||||
|
}).timeout(1000000);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -111,5 +111,28 @@ describe("SMT test", function () {
|
|||||||
assert(circuit.checkWitness(w));
|
assert(circuit.checkWitness(w));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Check inclussion Adria case", async () => {
|
||||||
|
const e1_hi= bigInt("17124152697573569611556136390143205198134245887034837071647643529178599000839");
|
||||||
|
const e1_hv= bigInt("19650379996168153643111744440707177573540245771926102415571667548153444658179");
|
||||||
|
|
||||||
|
const e2ok_hi= bigInt("16498254692537945203721083102154618658340563351558973077349594629411025251262");
|
||||||
|
const e2ok_hv= bigInt("19650379996168153643111744440707177573540245771926102415571667548153444658179");
|
||||||
|
|
||||||
|
const e2fail_hi= bigInt("17195092312975762537892237130737365903429674363577646686847513978084990105579");
|
||||||
|
const e2fail_hv= bigInt("19650379996168153643111744440707177573540245771926102415571667548153444658179");
|
||||||
|
|
||||||
|
const tree1 = await smt.newMemEmptyTrie();
|
||||||
|
await tree1.insert(e1_hi,e1_hv);
|
||||||
|
await tree1.insert(e2ok_hi,e2ok_hv);
|
||||||
|
|
||||||
|
await testInclusion(tree1, e2ok_hi, circuit);
|
||||||
|
|
||||||
|
const tree2 = await smt.newMemEmptyTrie();
|
||||||
|
await tree2.insert(e1_hi,e1_hv);
|
||||||
|
await tree2.insert(e2fail_hi,e2fail_hv);
|
||||||
|
|
||||||
|
await testInclusion(tree2, e2fail_hi, circuit);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
98
test/smtverifier_adria.js
Normal file
98
test/smtverifier_adria.js
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
const path = require("path");
|
||||||
|
const snarkjs = require("snarkjs");
|
||||||
|
const compiler = require("circom");
|
||||||
|
const fs = require("fs")
|
||||||
|
|
||||||
|
const bigInt = snarkjs.bigInt;
|
||||||
|
const smt = require("../src/smt.js");
|
||||||
|
|
||||||
|
const circuitSource = `
|
||||||
|
include "../circuits/smt/smtverifier.circom";
|
||||||
|
template SMT(nLevels) {
|
||||||
|
signal input root;
|
||||||
|
signal input mtp[nLevels];
|
||||||
|
signal input hi;
|
||||||
|
signal input hv;
|
||||||
|
|
||||||
|
component smtClaimExists = SMTVerifier(nLevels);
|
||||||
|
smtClaimExists.enabled <== 1;
|
||||||
|
smtClaimExists.fnc <== 0;
|
||||||
|
smtClaimExists.root <== root;
|
||||||
|
for (var i=0; i<nLevels; i++) {
|
||||||
|
smtClaimExists.siblings[i] <== mtp[i];
|
||||||
|
}
|
||||||
|
smtClaimExists.oldKey <== 0;
|
||||||
|
smtClaimExists.oldValue <== 0;
|
||||||
|
smtClaimExists.isOld0 <== 0;
|
||||||
|
|
||||||
|
smtClaimExists.key <== hi;
|
||||||
|
smtClaimExists.value <== hv;
|
||||||
|
}
|
||||||
|
component main = SMT(4);
|
||||||
|
`;
|
||||||
|
|
||||||
|
describe("smt3test", function () {
|
||||||
|
this.timeout(200000);
|
||||||
|
|
||||||
|
let circuitFileName;
|
||||||
|
|
||||||
|
before( async () => {
|
||||||
|
circuitFileName = path.join(__dirname, ".", "rawsmt3.circom");
|
||||||
|
fs.writeFileSync(circuitFileName,circuitSource);
|
||||||
|
});
|
||||||
|
|
||||||
|
const levels = 4;
|
||||||
|
async function testsmt3(e1, e2) {
|
||||||
|
let tree = await smt.newMemEmptyTrie();
|
||||||
|
|
||||||
|
// insert e1, e2
|
||||||
|
await tree.insert(e1.hi, e1.hv);
|
||||||
|
await tree.insert(e2.hi, e2.hv);
|
||||||
|
|
||||||
|
// generate proof for e1
|
||||||
|
const findInfo = await tree.find(e1.hi);
|
||||||
|
const siblings = findInfo.siblings;
|
||||||
|
while (siblings.length < levels) siblings.push(bigInt(0));
|
||||||
|
|
||||||
|
const input = {
|
||||||
|
root: tree.root,
|
||||||
|
mtp: siblings,
|
||||||
|
hi: e1.hi,
|
||||||
|
hv: e1.hv,
|
||||||
|
};
|
||||||
|
|
||||||
|
const compiledCircuit = await compiler(
|
||||||
|
circuitFileName,
|
||||||
|
{ reduceConstraints: false }
|
||||||
|
);
|
||||||
|
|
||||||
|
const circuit = new snarkjs.Circuit(compiledCircuit);
|
||||||
|
const witness = circuit.calculateWitness(input);
|
||||||
|
circuit.checkWitness(witness);
|
||||||
|
}
|
||||||
|
|
||||||
|
it("TestSmts", async () => {
|
||||||
|
|
||||||
|
const e1 = {
|
||||||
|
hi: bigInt("17124152697573569611556136390143205198134245887034837071647643529178599000839"),
|
||||||
|
hv: bigInt("19650379996168153643111744440707177573540245771926102415571667548153444658179"),
|
||||||
|
};
|
||||||
|
|
||||||
|
const e2ok = {
|
||||||
|
hi: bigInt("16498254692537945203721083102154618658340563351558973077349594629411025251262"),
|
||||||
|
hv: bigInt("19650379996168153643111744440707177573540245771926102415571667548153444658179"),
|
||||||
|
};
|
||||||
|
|
||||||
|
const e2fail = {
|
||||||
|
hi: bigInt("17195092312975762537892237130737365903429674363577646686847513978084990105579"),
|
||||||
|
hv: bigInt("19650379996168153643111744440707177573540245771926102415571667548153444658179"),
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log("test e1, e2ok");
|
||||||
|
await testsmt3(e1, e2ok);
|
||||||
|
|
||||||
|
console.log("test e1, e2fail");
|
||||||
|
await testsmt3(e1, e2fail);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
Reference in New Issue
Block a user