Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
235 commits
Select commit Hold shift + click to select a range
f7d5d30
fix modulus.circom line-286
matchv Sep 19, 2023
dcff744
fix issue
343415207 Sep 19, 2023
b660679
fix utils.circom Line 236-237
matchv Sep 19, 2023
24e86d0
fix utils.circom Line 3 & Line 7
matchv Sep 19, 2023
d219367
fix 149 binsub.circom - Line 5
matchv Sep 19, 2023
060a96d
fix 148 inversemodulo.circom Line 256,276,298
matchv Sep 19, 2023
c28d149
6,7,8,9 chunkedadd.circom 39-41,45-56,80-82,82
343415207 Sep 20, 2023
bac5675
10,11 chunkedmul.circom 138-141,141
343415207 Sep 20, 2023
23f4186
143-148 inversemodulo.circom - removeing it
matchv Sep 20, 2023
072c4e7
fix 142 batchverify.circom Line 6
matchv Sep 20, 2023
3a7223a
fix 139 verify.circom 17-18
matchv Sep 20, 2023
226c662
fix scalarmul.circom 159-162
matchv Sep 20, 2023
b06b6dc
fix 136 scalarmul.circom 147-150, 152-155
matchv Sep 20, 2023
63e6f1d
fix 135 scalarmul.circom 133-136
matchv Sep 20, 2023
d7c1fd2
12,13,14 lt.circom 9-23,10-24,17-18,20-21
343415207 Sep 21, 2023
79f16b7
remove unusedcode
343415207 Sep 21, 2023
660958c
17 utils.circom 29-30
343415207 Sep 21, 2023
c44566b
18, utils.circom 56
343415207 Sep 21, 2023
6177621
19, utils.circom 131
343415207 Sep 21, 2023
02ff5ca
20,21 utils.circom 153,155
343415207 Sep 21, 2023
3fcc05f
22 utils.circom 172,189
343415207 Sep 21, 2023
11d4190
23 utils.circom 187
343415207 Sep 21, 2023
ecdbd62
24 utils.circom 228,240,249
343415207 Sep 21, 2023
cf43537
25 utils.circom 238,247
343415207 Sep 21, 2023
0ce40d5
26,utils.circom 273,280,289
343415207 Sep 21, 2023
4db883f
29, chunkify.circom 5
343415207 Sep 21, 2023
36cd596
30,binadd.circom 3
343415207 Sep 21, 2023
71f0d0b
31, binadd.circom 45
343415207 Sep 21, 2023
500341d
33 binsub.circom 12
343415207 Sep 21, 2023
53d49ca
34 binsub.circom 15
343415207 Sep 21, 2023
5ccb96d
37 chunkedsub.circom 35-38
343415207 Sep 21, 2023
9a1c47e
40, utils.circom 12
343415207 Sep 21, 2023
9cddcae
45, utils.circom 217,261
343415207 Sep 21, 2023
6325221
47, chunkedadd.circom 149
343415207 Sep 21, 2023
e4be94d
75,binmul.circom 5
343415207 Sep 21, 2023
2c6db9e
80 modinv.circom 8
343415207 Sep 21, 2023
ac8f713
84, chunkify.circom 33-36
343415207 Sep 21, 2023
60ed35a
85 binadd.circom 91,93-94,103-104
343415207 Sep 21, 2023
d55c505
105 utils.circom 221
343415207 Sep 21, 2023
4c10f97
106 utils.circom 229
343415207 Sep 21, 2023
72dcb71
120 modulus.circom 418
343415207 Sep 21, 2023
792d667
82 chunkify.circom 11
343415207 Sep 21, 2023
d0e431c
100 utils.circom 57-59
343415207 Sep 22, 2023
684e462
103 utils.circom 147
343415207 Sep 22, 2023
f5099f6
111 chunkedmul.circom 42-50
343415207 Sep 22, 2023
c77ae4b
123 point-addition.circom 77-98
343415207 Sep 22, 2023
86d3f10
121 point-addition.circom 3-5
343415207 Sep 22, 2023
0a4b007
124 point-addition.circom 172-175,177-180,183-186
343415207 Sep 22, 2023
5674b7c
fix long_scalar_mult issue
343415207 Sep 22, 2023
72ea83f
125 scalarmul.circom 10-13
343415207 Sep 22, 2023
197f302
124 point-addition.circom Ensure all inputs are initialized before ac…
343415207 Sep 22, 2023
3af9464
reset utils.circom
343415207 Sep 23, 2023
e72d1c2
remove main componment
343415207 Sep 23, 2023
992ff2d
remove error assert
343415207 Sep 23, 2023
ffaeb26
fix test error
343415207 Sep 24, 2023
7013979
remove chunkedadd.circom assert
343415207 Sep 24, 2023
4ec2b94
original code
matchv Sep 25, 2023
956bf55
fix [2] binadd.circom Line 96-99, 109-112
matchv Sep 25, 2023
31940ab
fix [3] binadd.circom Line 112
matchv Sep 25, 2023
3b5fd25
fix [5] utils.circom Line 218,220
matchv Sep 25, 2023
ac9f8bf
fix [7] chunkedadd.circom Line 45-46
matchv Sep 25, 2023
a01addd
fix [8] chunkedadd.circom Line 80-82
matchv Sep 25, 2023
2c5c4b0
fix [12,13,14] it.circom Line 9,23 10,24 17–18, 20–21
matchv Sep 25, 2023
cc9d0b6
fix [30] binadd.circom Line 3
matchv Sep 25, 2023
d66d700
fix [29] chunkify.circom Line 5
matchv Sep 25, 2023
6e4e0de
fix [31] binadd.circom Line 45
matchv Sep 25, 2023
2fe78ed
fix [33,34] binsub.circom Line 12,15
matchv Sep 25, 2023
792ddb6
fix [37] chunkedsub.circom Line 35-38
matchv Sep 25, 2023
917628c
fix [40] utils.circom Line 12
matchv Sep 25, 2023
571bca5
fix [45], utils.circom, Line 217,261
matchv Sep 25, 2023
3c06025
fix [47] chunkedmul.circom, Line 149
matchv Sep 25, 2023
7b9b7ae
fix [75,76], binmul.circom, Line 5, 6-7
matchv Sep 25, 2023
8f23d0e
fix [77,78,79,143,144,145,146,147,148], inversemodulo.circom
matchv Sep 25, 2023
8b774ae
fix [80], modinv.circom, Line 8
matchv Sep 25, 2023
cf249f1
fix [82], chunkify.circom, Line 11
matchv Sep 25, 2023
a934be4
fix [83,84], chunkify.circom, Line 32, 33-36
matchv Sep 25, 2023
b65e321
fix [86], binadd.circom, Line 27-43
matchv Sep 25, 2023
ff7a902
fix [106], utils.circom, Line 229
matchv Sep 25, 2023
0e1f7ad
fix [111], chunkedmul.circom, Line 42-50
matchv Sep 25, 2023
5ecf20d
fix [118], modulus.circom, Line 333
matchv Sep 25, 2023
a8910d7
fix [120], modulus.circom, Line 418
matchv Sep 25, 2023
765ea82
fix [124], point-addition.circom, Line 172-175, 177-180, 183-186
matchv Sep 25, 2023
19fd9dc
fix [125], scalarmul.circom, Line 10-13
matchv Sep 25, 2023
b05f28d
fix [135], scalarmul.circom, Line 133-136
matchv Sep 25, 2023
6e500b1
fix [136], scalarmul.circom, Line 147-150, 152-155
matchv Sep 25, 2023
bbf6a9a
fix [137], scalarmul.circom, Line 159-162
matchv Sep 25, 2023
e733c95
fix [142], batchverify.circom, Line 6
matchv Sep 25, 2023
3749359
fix [149], binsub.circom, Line 5
matchv Sep 25, 2023
0b720b5
fix [150], utils.circom, Line 3
matchv Sep 25, 2023
7204668
fix [151], utils.circom, Line 7
matchv Sep 25, 2023
3ede13e
fix [152], utils.circom, Line 236-237
matchv Sep 25, 2023
d5b7aa8
fix [154], modulus.circom, Line 286
matchv Sep 25, 2023
ab72f3f
39 chunkedsub.circom & 112 chunkedmul.circom
343415207 Sep 26, 2023
d1fdbc1
fix [81], chunkify.circom, Line 6,8
matchv Sep 26, 2023
7e55d1e
fix [85, 91], binadd.circom
matchv Sep 26, 2023
9f92e5b
fix [92], binadd.circom, Line 109
matchv Sep 26, 2023
6b0fd56
fix [93], binadd.circom
matchv Sep 26, 2023
3c84412
fix [94], binadd.circom
matchv Sep 26, 2023
382fe01
fix [96], chunkedsub.circom
matchv Sep 26, 2023
1c5d5e4
fix [97], chunkedsub.circom
matchv Sep 26, 2023
23fbcdf
fix [98], utils.circom
matchv Sep 26, 2023
741358f
fix [99], utils.circom
matchv Sep 26, 2023
e0837a0
126 scalarmul.circom 22
Sep 26, 2023
4ec7027
yan lock
Sep 26, 2023
495e065
72 batchverify.circom 9
Sep 26, 2023
513df45
fix [100], utils.circom
matchv Sep 27, 2023
202e73f
fix [101], utils.circom
matchv Sep 27, 2023
b247fdc
fix [102], utils.circom
matchv Sep 27, 2023
ba6111b
fix [103], utils.circom
matchv Sep 27, 2023
34ebba5
fix [104], utils.circom
matchv Sep 27, 2023
afbc986
fix [107], chunkedadd.circom
matchv Sep 27, 2023
05395e2
fix [109], chunkedmul.circom
matchv Sep 27, 2023
69035f6
fix [110], chunkedmul.circom
matchv Sep 27, 2023
edd0f89
fix [114], chunkedmul.circom
matchv Sep 27, 2023
712f4b1
fix [115], it.circom
matchv Sep 27, 2023
ade5c44
fix [117], modulus.circom
matchv Sep 27, 2023
c92f782
fix [121], point-addition.circom
matchv Sep 27, 2023
591d661
fix [122], point-addition.circom
matchv Sep 27, 2023
96acf5f
fix [123], point-addition.circom
matchv Sep 27, 2023
67e902a
fix [127,128,129,130,131], scalarmul.circom
matchv Sep 27, 2023
481347a
fix [132], scalarmul.circom
matchv Sep 27, 2023
e5f9d63
fix [133], scalarmul.circom
matchv Sep 27, 2023
c6e8225
28 modinv.circom 9
343415207 Sep 27, 2023
a9b5251
32 binsub.circom 6-7
343415207 Sep 27, 2023
8f8630c
35 chunkedsub.circom 4,30,42
343415207 Sep 27, 2023
abfa5cf
36 chunkedsub.circom 5-6,31-32,43-45
343415207 Sep 27, 2023
a2d26d0
fix [139], verify.circom
matchv Sep 27, 2023
d54be70
42 utils.circom 28,55,125,149170
343415207 Sep 27, 2023
e20be92
43 utils.circom 70
343415207 Sep 27, 2023
66e1628
50,51 modulus.circom
343415207 Sep 27, 2023
f6be4cc
fix [27], modinv.circom
matchv Sep 27, 2023
4c48d41
52 modulus.circom 179-181
343415207 Sep 27, 2023
db57f6b
53 modulus.circom 180
343415207 Sep 27, 2023
6e9eea6
55,56 modulus.circom 221-223
343415207 Sep 27, 2023
df3f985
57,58 modulus.circom
343415207 Sep 27, 2023
c3f97b7
62,63 modulus.circom
343415207 Sep 27, 2023
923ad70
60,61 modulus.circom 339-340
343415207 Sep 27, 2023
69e2a5f
67 verify.circom
343415207 Sep 27, 2023
9c04758
Add blank lines between functions
matchv Sep 27, 2023
22772c4
11 chunkedmul.circom 141
Sep 27, 2023
4efdb69
fix chunkedadd.circom
matchv Sep 27, 2023
64325dd
fix [6], chunkedadd.circom
matchv Sep 28, 2023
f1c249f
fix [10], chunkedmul.circom
matchv Sep 28, 2023
507c8a6
fix [15], pointcompress.circom
matchv Sep 28, 2023
406db21
fix [49], pointcompress.circom
matchv Sep 28, 2023
f2b102a
fix [59], modulus.circom
matchv Sep 28, 2023
defa633
fix [64], modulus.circom
matchv Sep 28, 2023
c5ce5b6
fix [65], point-addition.circom
matchv Sep 28, 2023
226826d
fix [66], scalarmul.circom
matchv Sep 28, 2023
2159799
153 chunkedmul.circom 52-65
343415207 Sep 28, 2023
43a6660
fix [4, 44], utils.circom
matchv Sep 28, 2023
5df55da
fix [69], verify.circom
matchv Sep 28, 2023
65818b0
fix [68], verify.circom
matchv Sep 28, 2023
90ca566
remove A, R8
matchv Sep 28, 2023
af68e62
fix [74], batchverify.circom
matchv Sep 29, 2023
daa7310
fix [73], batchverify.circom
matchv Sep 29, 2023
95cf60b
recover original verify.circom, fix cvf15
matchv Oct 31, 2023
2a4c223
fix cvf44
matchv Oct 31, 2023
2791544
fix CVF 1
matchv Nov 16, 2023
ac00940
fix cvf-5, chunkedadd.circom
matchv Nov 16, 2023
fe231f6
fix cvf-6, chunkedadd.circom
matchv Nov 16, 2023
88c59f0
fix cvf-7, chunkedadd.circom
matchv Nov 16, 2023
64bd1a5
fix cvf-8, chunkedadd.circom
matchv Nov 16, 2023
a42af92
fix cvf-9, chunkedmul.circom
matchv Nov 16, 2023
9d9b8b5
add assert for chunkedmul.circom
matchv Nov 16, 2023
55c5b05
fix cvf-11, lt.circom
matchv Nov 16, 2023
3616ed7
fix cvf-14, pointcompress.circom
matchv Nov 16, 2023
e9dc2a0
fix cvf-29, binadd.circom
matchv Nov 16, 2023
851b9b2
fix cvf-31, binsub.circom
matchv Nov 16, 2023
fc002cf
add assert for chunkedsub.circom
matchv Nov 16, 2023
04927d3
fix cvf-48, add comments. pointcompress.circom
matchv Nov 16, 2023
8893413
fix cvf-70, verify.circom
matchv Nov 16, 2023
a69ab63
add component main
matchv Nov 16, 2023
e4824bf
declare msg, S as public inputs
matchv Nov 16, 2023
1381306
update lt.circom
matchv Nov 17, 2023
ba7e1b1
batch verify multi msg
matchv Nov 22, 2023
102ff9f
fix CVF4, CVF10
matchv Nov 26, 2023
7a6c481
cvf4 with assert
matchv Nov 26, 2023
7963fc0
delete cvf4 if block
matchv Nov 26, 2023
be15f3f
correct CVF10
matchv Nov 27, 2023
f4a79f5
batch verify multi msg
matchv Nov 27, 2023
0426c04
update batchverify.circom
matchv Nov 27, 2023
c2f66f6
update message amount of batchverify.circom
matchv Nov 27, 2023
b68e866
Execute the entire process of batchverify
matchv Nov 30, 2023
623aed0
update batchVerify README.md
matchv Nov 30, 2023
5f561f3
update batchVerify README.md
matchv Dec 2, 2023
05ed2ba
Verify 4 messages in batches
matchv Dec 2, 2023
f8c7b95
batch verify msg of variable length
matchv Dec 30, 2023
4011b02
fix batchverify
matchv Jan 2, 2024
177eca3
constraint chunkedadd.circom
matchv Jan 4, 2024
e4f0941
add reference to chunkedadd
matchv Jan 4, 2024
8180d6c
fix CVF-7, chunkedadd.circom
matchv Jan 4, 2024
4abdae0
CVF-7, constraint chunkedadd.circom
matchv Jan 4, 2024
5285df0
fix CVF-9, chunkedmul.circom
matchv Jan 4, 2024
bea8767
recover the code of lt.circom & pointcompress.circom
matchv Jan 4, 2024
f892a9a
constrain bitwise operators
matchv Jan 5, 2024
5a63c47
prove bitwise operations
matchv Jan 5, 2024
372bbe0
constrain assignment operators
matchv Jan 8, 2024
4655e15
make public input
matchv Jan 11, 2024
78ab33c
not specify input array size
matchv Jan 11, 2024
68ac21b
fix syntax error
matchv Jan 11, 2024
4b12c8f
CVF 1
matchv Jan 18, 2024
4ae6a73
fix: simplify binadd.circom
vlopes11 Jan 22, 2024
334d194
feat: fixate utils computation to actual usage
vlopes11 Jan 23, 2024
ab35596
add comments for lt
vlopes11 Jan 31, 2024
19f9aa7
prepare binadd
vlopes11 Jan 31, 2024
25651aa
fix remainder nits
vlopes11 Feb 1, 2024
7987ca2
add comment to explain how `carry` is constrained for `fulladder`
vlopes11 Feb 9, 2024
a263e00
assert bits input for batch verify
vlopes11 Feb 9, 2024
58277b9
assert boolean for S input of batch verify
vlopes11 Feb 9, 2024
237f249
fix range constraint for chunked add
vlopes11 Feb 9, 2024
6c7a859
fix chunked sub assertions
vlopes11 Feb 9, 2024
665231f
fix assertion on mobsubthree
vlopes11 Feb 9, 2024
49ea96d
fix constraint on modsub
vlopes11 Feb 9, 2024
f02ad83
add comment to clarify off-circuit assert on modinv
vlopes11 Feb 9, 2024
17d8a0a
remove unnecessary off-circuit assertion
vlopes11 Feb 9, 2024
2d68efe
fix assertion for modulus range check on circuit
vlopes11 Feb 9, 2024
bee2222
fix msg boolean assertion as constraint
vlopes11 Feb 9, 2024
e20395d
fix constraint for chunked add output field range
vlopes11 Feb 9, 2024
d49e3ec
restore previous code that was constraining output chunked add
vlopes11 Feb 9, 2024
a222a61
constrain chunkedadd carry propagation
vlopes11 Feb 9, 2024
0850860
check sum rannge
vlopes11 Feb 9, 2024
f88aaec
simplify & document ChunkAdd
vlopes11 Feb 16, 2024
cdc4d19
improve chunked add docs
vlopes11 Feb 16, 2024
ace405c
improve chunked add docs
vlopes11 Feb 16, 2024
1a04ca8
fix out in chunked add docs
vlopes11 Feb 16, 2024
babb4c6
fix chunked add irregular
vlopes11 Feb 19, 2024
109fc6b
fix chunked sub
vlopes11 Feb 19, 2024
e30df96
assert off-circuit k range for long_sub
vlopes11 Feb 23, 2024
95beab4
range check chunked mul carry
vlopes11 Feb 23, 2024
000d4de
fix npm run test
vlopes11 Mar 1, 2024
bfb1691
add t for extended twisted edwards check
vlopes11 Mar 2, 2024
07240ae
add range check to point verify
vlopes11 Mar 4, 2024
df7e5d6
extend point verify to equation check
vlopes11 Mar 14, 2024
7e6ceaa
add docs for templates
matchv Mar 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ remix-compiler.config.js
*.sym
*.ptau
verify_js/
verify_cpp/
verify_cpp/
.idea
batchverify_js/
batchverify_cpp/
*.zkey
circuits/batchverifier.sol
proof.json
public.json
verification_key.json
248 changes: 248 additions & 0 deletions batchVerify-README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
# Circom Ed25519

Curve operations and signature verification for Ed25519 digital signature scheme in circom

**WARNING:** This is a research project. It has not been audited and may contain bugs and security flaws. This implementation is NOT ready for production use.

The circuits follow the reference implementation from [IETF RFC8032](https://datatracker.ietf.org/doc/html/rfc8032#section-6)

## 1. Installing dependencies
- `npm install -g snarkjs`
- Install Rust: `curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh`
- Clone and install circom - [circom docs](https://docs.circom.io/getting-started/installation/)
- If you want to build the `verify` circuit, you'll need to download a Powers of Tau file with `2^22` constraints and copy it into the `circuits` subdirectory of the project, with the name `pot22_final.ptau`. You can download Powers of Tau files from the Hermez trusted setup from [this repository](https://github.com/iden3/snarkjs#7-prepare-phase-2)

## 2. Run the project

### 2.1. Clone code and install dependencies

```bash=
git clone this-project-code
```

```bash=
cd /path/to/this/project/folder/
```

Run command to install package dependencies

```bash=
npm install
```

### 2.2. Compile circuits

Enter the `circuits` directory, we can compile the circuit with the following command:

```bash=
circom batchverify.circom --r1cs --wasm --sym --c
```

With these options we generate three types of files:

- `--r1cs`: it generates the file `batchverify.r1cs` that contains the [R1CS constraint system](https://docs.circom.io/background/background#rank-1-constraint-system) of the circuit in binary format.
- `--wasm`: it generates the directory `batchverify_js` that contains the Wasm code (batchverify.wasm) and other files needed to generate the [witness](https://docs.circom.io/background/background#witness).
- `--sym` : it generates the file batchverify.sym , a symbols file required for debugging or for printing the constraint system in an annotated mode.
- `--c` : it generates the directory batchverify_cpp that contains several files (batchverify.cpp, batchverify.dat, and other common files for every compiled program like main.cpp, MakeFile, etc) needed to compile the C code to generate the witness.

`Notice`: If you encounter `JavaScript Heap Out of Memory Error` during operation, please refer to the [documentation](https://www.makeuseof.com/javascript-heap-out-of-memory-error-fix/) to solve it.

### 2.3. Computing the witness

Enter in the directory `batchverify_js`, add the input in a file `batchinput.json` (Simply copy the `batchinput.json` in the root directory of the project) and execute:

```bash=
node generate_witness.js batchverify.wasm batchinput.json witness.wtns
```

### 2.4. Proving circuits

#### 2.4.1. Powers of Tau

First, re-enter the `circuits` directory, we start a new "powers of tau" ceremony:

```bash=
snarkjs powersoftau new bn128 23 pot23_0000.ptau -v
```

Then, we contribute to the ceremony:

```bash=
snarkjs powersoftau contribute pot23_0000.ptau pot23_0001.ptau --name="First contribution" -v
```

Now, we have the contributions to the powers of tau in the file `pot23_0001.ptau` and we can proceed with the `Phase 2`.

#### 2.4.2. Phase 2

The **phase 2** is **circuit-specific**. Execute the following command to start the generation of this phase:

```bash=
snarkjs powersoftau prepare phase2 pot23_0001.ptau pot23_final.ptau -v
```

Next, we generate a `.zkey` file that will contain the proving and verification keys together with all phase 2 contributions. Execute the following command to start a new zkey:

```bash=
snarkjs groth16 setup batchverify.r1cs pot23_final.ptau batchverify_0000.zkey
```
**Notice:** Run `export NODE_OPTIONS=--max-old-space-size=8192` to Fix **JavaScript Heap Out of Memory Error**

Contribute to the phase 2 of the ceremony:

```bash=
snarkjs zkey contribute batchverify_0000.zkey batchverify_0001.zkey --name="1st Contributor Name" -v
```

Export the verification key:

```bash=
snarkjs zkey export verificationkey batchverify_0001.zkey verification_key.json
```

#### 2.4.3. Generating a Proof

Once the witness is computed and the trusted setup is already executed, we can **generate a zk-proof** associated to the circuit and the witness:

```bash=
use snarkjs:
snarkjs groth16 prove batchverify_0001.zkey ./batchverify_js/witness.wtns proof.json public.json
```

This command generates a [Groth16](https://eprint.iacr.org/2016/260) proof and outputs two files:

- `proof.json`: it contains the proof.
- `public.json`: it contains the values of the public inputs and outputs.

This step can use `rapidsnark` to speed up the generation of zkSnark proofs, please refer to the documentation of [rapidsnark](https://github.com/iden3/rapidsnark).

So you can replace snarkjs command by this one:

```bash=
./package/bin/prover <batchverify_0001.zkey> <witness.wtns> <proof.json> <public.json>

example:
./package/bin/prover batchverify_0001.zkey ./batchverify_js/witness.wtns proof.json public.json
```

#### 2.4.4. Verifying a Proof

To **verify the proof**, execute the following command:

```bash=
snarkjs groth16 verify verification_key.json public.json proof.json
```

The command uses the files `verification_key.json` we exported earlier,`proof.json` and `public.json` to check if the proof is valid. If the proof is valid, the command outputs an `OK`.

A valid proof not only proves that we know a set of signals that satisfy the circuit, but also that the public inputs and outputs that we use match the ones described in the `public.json` file.

#### 2.4.5. Verifying from a Smart Contract

It is also possible to generate a **Solidity verifier** that allows **verifying proofs on Ethereum blockchain**.

First, we need to generate the Solidity code using the command:

```bash=
snarkjs zkey export solidityverifier batchverify_0001.zkey batchverifier.sol
```

This command takes validation key `batchverify_0001.zkey` and outputs Solidity code in a file named `batchverifier.sol`. You can take the code from this file and cut and paste it in Remix.

The `Verifier` has a `view` function called `verifyProof` that returns `TRUE` if and only if the proof and the inputs are valid. To facilitate the call, you can use `snarkJS` to generate the parameters of the call by typing:

```bash=
snarkjs generatecall
```

You can get something like the following in return:

```json=
["0x19721bf1e6a40b14b136daba5af87aff4f1d9c614dd12796c79f447f0dcdddba", "0x2a4bc5255eae8cfc33d8bce60244258b5160377d73f9f292b27842246d144f70"],[["0x23807555c654ec10dd9de1184fd585b0f235c64c83b0d2b9dc4f7f3934b083d6", "0x2af0c2dd9b462b7b63c0682646422b526d9b82608456ef09eadfd5bf2e3e9fa2"],["0x1688a3c4ded94b6d5958886feeeb697201fde9e6919f5bd6408a865af46de162", "0x07677f9ee01dcd2637a1e690caa8c40db5488ac0c45ba33bc5489c700db676b0"]],["0x27f0ddc72eca4525c42b39feaac1c159909cc09918beb7f63af68451750af042", "0x04ae2a4c2ef49ac3f01a0240eab924079406f552746cf4d18e32654d39101a79"],["0x0000000000000000000000000000000000000000000000000000000000000000"]
```
Cut and paste the output of the command to the parameters field of the `verifyProof` method in Remix. If everything works fine, this method should return `TRUE`. You can try to change just a single bit of the parameters, and you will see that the result is verifiable `FALSE`.

## Appendix

### 1. Inputs explanation
`msg` is the data for the signature

`R8` is the first 256 bits of the signature (LSB to MSB)

`S` is the first 255 bits of the last 256 bits of the signature (LSB to MSB)

`A` is the public key in binary (LSB to MSB)

`PointA` is the point representing the public key on the elliptic curve (encoded in base 2^85 for brevity)

`PointR` is the point representing the R8 value on the elliptic curve (encoded in base 2^85)

The [algorithm](https://datatracker.ietf.org/doc/html/rfc8032#section-6) we follow only takes in `A` and `R8` in binary form, and is decompressed to get `PointA` and `PointR` respectively. However, decompression is an expensive algorithm to perform in a circuit. On the other hand, compression is cheap and easy to implement. So, we use a nifty little trick to push the onus of providing both on the `prover` and perform equality checks after compressing the points within the circuit. [Ref](https://github.com/Electron-Labs/ed25519-circom/blob/532f638b4d6ae4684a1f0907df6c92676f0ae8df/circuits/verify.circom#L57)

You can find all helper functions to change encodings from well-known formats to circuit friendly formats [here](https://github.com/Electron-Labs/ed25519-circom/blob/master/test/utils.js)

### 2. Input.json format

In your JSON file, you'll structure the input data like this:

`
{
"msg": [
[/* Your first message bytes here */],
[/* Your second message bytes here */],
[/* Your third message bytes here */],
[/* Your fourth message bytes here */]
],
"msgLengths": [
/* Lengths of your messages corresponding to msg array */
],
"S": [
[/* Your S values for message 1 */],
[/* Your S values for message 2 */],
[/* Your S values for message 3 */],
[/* Your S values for message 4 */]
],
"PointA": [
[/* Your PointA values for message 1 */],
[/* Your PointA values for message 2 */],
[/* Your PointA values for message 3 */],
[/* Your PointA values for message 4 */]
],
"PointR": [
[/* Your PointR values for message 1 */],
[/* Your PointR values for message 2 */],
[/* Your PointR values for message 3 */],
[/* Your PointR values for message 4 */]
]
}
`

### 2. Circuit information

#### 2.1. `1 message`

```bash=
template instances: 216
non-linear constraints: 1307374
linear constraints: 0
public inputs: 0
public outputs: 1
private inputs: 295
private outputs: 0
wires: 1380186
labels: 13089531
```

#### 2.2. `2 messages`

```bash=
template instances: 216
non-linear constraints: 2614748
linear constraints: 0
public inputs: 0
public outputs: 1
private inputs: 590
private outputs: 0
wires: 2760371
labels: 26179059
```
Loading