zkjson 0.6.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/README.md +537 -0
  2. package/assets/collection.png +0 -0
  3. package/assets/db.png +0 -0
  4. package/assets/encode.png +0 -0
  5. package/assets/query.png +0 -0
  6. package/assets/rollup.png +0 -0
  7. package/assets/structure.png +0 -0
  8. package/assets/weavedb.png +0 -0
  9. package/assets/zkjson.png +0 -0
  10. package/benchmark/components/ui/avatar.jsx +49 -0
  11. package/benchmark/components/ui/checkbox.jsx +17 -0
  12. package/benchmark/components/ui/close-button.jsx +20 -0
  13. package/benchmark/components/ui/color-mode.jsx +89 -0
  14. package/benchmark/components/ui/dialog.jsx +54 -0
  15. package/benchmark/components/ui/drawer.jsx +44 -0
  16. package/benchmark/components/ui/field.jsx +22 -0
  17. package/benchmark/components/ui/input-group.jsx +39 -0
  18. package/benchmark/components/ui/popover.jsx +49 -0
  19. package/benchmark/components/ui/provider.jsx +12 -0
  20. package/benchmark/components/ui/radio.jsx +17 -0
  21. package/benchmark/components/ui/slider.jsx +107 -0
  22. package/benchmark/components/ui/tooltip.jsx +35 -0
  23. package/benchmark/jsconfig.json +7 -0
  24. package/benchmark/lib/cbor.js +387 -0
  25. package/benchmark/lib/msgpack.js +651 -0
  26. package/benchmark/next.config.mjs +6 -0
  27. package/benchmark/package.json +22 -0
  28. package/benchmark/pages/_app.js +9 -0
  29. package/benchmark/pages/_document.js +13 -0
  30. package/benchmark/pages/api/hello.js +5 -0
  31. package/benchmark/pages/index.js +438 -0
  32. package/benchmark/public/favicon.ico +0 -0
  33. package/benchmark/public/file.svg +1 -0
  34. package/benchmark/public/globe.svg +1 -0
  35. package/benchmark/public/next.svg +1 -0
  36. package/benchmark/public/vercel.svg +1 -0
  37. package/benchmark/public/window.svg +1 -0
  38. package/benchmark/yarn.lock +2448 -0
  39. package/circom/collection/collection.circom +32 -0
  40. package/circom/collection/compile.sh +10 -0
  41. package/circom/collection/gen.js +34 -0
  42. package/circom/collection/generateInput.js +10 -0
  43. package/circom/collection/index.circom +4 -0
  44. package/circom/collection/test.js +21 -0
  45. package/circom/collection/verifier.sol +247 -0
  46. package/circom/db/compile.sh +10 -0
  47. package/circom/db/db.circom +39 -0
  48. package/circom/db/gen.js +30 -0
  49. package/circom/db/generateInput.js +10 -0
  50. package/circom/db/index.circom +4 -0
  51. package/circom/db/test.js +21 -0
  52. package/circom/db/verifier.sol +261 -0
  53. package/circom/ipfs/calculate_total.circom +17 -0
  54. package/circom/ipfs/compile.sh +10 -0
  55. package/circom/ipfs/gen.js +18 -0
  56. package/circom/ipfs/generateInput.js +10 -0
  57. package/circom/ipfs/index.circom +4 -0
  58. package/circom/ipfs/ipfs.circom +62 -0
  59. package/circom/ipfs/parse.circom +289 -0
  60. package/circom/ipfs/sha256.circom +99 -0
  61. package/circom/ipfs/test.js +167 -0
  62. package/circom/ipfs/verifier.sol +261 -0
  63. package/circom/json/compile.sh +10 -0
  64. package/circom/json/gen.js +22 -0
  65. package/circom/json/gen2.js +21 -0
  66. package/circom/json/generateInput.js +20 -0
  67. package/circom/json/index.circom +4 -0
  68. package/circom/json/json.circom +81 -0
  69. package/circom/json/test.js +100 -0
  70. package/circom/json/verifier.sol +247 -0
  71. package/circom/query/compile.sh +10 -0
  72. package/circom/query/gen.js +28 -0
  73. package/circom/query/generateInput.js +11 -0
  74. package/circom/query/index.circom +4 -0
  75. package/circom/query/query.circom +58 -0
  76. package/circom/query/test.js +20 -0
  77. package/circom/query/verifier.sol +177 -0
  78. package/circom/rollup/compile.sh +10 -0
  79. package/circom/rollup/gen.js +36 -0
  80. package/circom/rollup/generateInput.js +11 -0
  81. package/circom/rollup/index.circom +4 -0
  82. package/circom/rollup/rollup.circom +43 -0
  83. package/circom/rollup/test.js +35 -0
  84. package/circom/rollup/verifier.sol +240 -0
  85. package/circom/scripts/ceremony.js +39 -0
  86. package/circom/scripts/ceremony.sh +6 -0
  87. package/circom/scripts/compile.js +113 -0
  88. package/circom/scripts/compile.sh +16 -0
  89. package/circom/utils/uint.circom +512 -0
  90. package/circom/utils/utils.circom +628 -0
  91. package/demos/arweave/jsconfig.json +7 -0
  92. package/demos/arweave/lib/ZKArweave.json +617 -0
  93. package/demos/arweave/lib/encoder.js +375 -0
  94. package/demos/arweave/next.config.js +6 -0
  95. package/demos/arweave/package.json +26 -0
  96. package/demos/arweave/pages/_app.js +9 -0
  97. package/demos/arweave/pages/_document.js +19 -0
  98. package/demos/arweave/pages/api/arweave.js +31 -0
  99. package/demos/arweave/pages/api/hello.js +5 -0
  100. package/demos/arweave/pages/index.js +869 -0
  101. package/demos/arweave/public/circuit.wasm +0 -0
  102. package/demos/arweave/public/circuit_final.zkey +0 -0
  103. package/demos/arweave/public/verification_key.json +149 -0
  104. package/demos/arweave/vercel.json +7 -0
  105. package/demos/arweave/yarn.lock +2510 -0
  106. package/demos/simple/jsconfig.json +7 -0
  107. package/demos/simple/lib/encoder.js +375 -0
  108. package/demos/simple/next.config.js +6 -0
  109. package/demos/simple/package.json +24 -0
  110. package/demos/simple/pages/_app.js +9 -0
  111. package/demos/simple/pages/_document.js +13 -0
  112. package/demos/simple/pages/api/hello.js +5 -0
  113. package/demos/simple/pages/index.js +342 -0
  114. package/demos/simple/public/circuit.wasm +0 -0
  115. package/demos/simple/public/circuit_final.zkey +0 -0
  116. package/demos/simple/public/verification_key.json +149 -0
  117. package/demos/simple/yarn.lock +2519 -0
  118. package/docs/README.md +17 -0
  119. package/docs/simple-zkjson.md +210 -0
  120. package/docs/solidity-contracts.md +216 -0
  121. package/docs/zk-circuits.md +125 -0
  122. package/docs/zkdb-rollup.md +218 -0
  123. package/docs/zkjson-sdk.md +254 -0
  124. package/docs/zkjson-v1_5.md +365 -0
  125. package/package.json +16 -7
  126. package/sdk/contracts/NORollup.sol +13 -0
  127. package/sdk/package.json +15 -0
  128. package/sdk/yarn.lock +881 -0
  129. package/solidity/README.md +13 -0
  130. package/solidity/arguments.js +4 -0
  131. package/solidity/contracts/NORollup.sol +13 -0
  132. package/solidity/contracts/OPRollup.sol +14 -0
  133. package/solidity/contracts/ZKIPFS.sol +95 -0
  134. package/solidity/contracts/ZKJson.sol +21 -0
  135. package/solidity/contracts/ZKQuery.sol +286 -0
  136. package/solidity/contracts/ZKRollup.sol +35 -0
  137. package/solidity/contracts/apps/NORU.sol +66 -0
  138. package/solidity/contracts/apps/SimpleJSON.sol +64 -0
  139. package/solidity/contracts/apps/SimpleOPRU.sol +67 -0
  140. package/solidity/contracts/apps/SimpleRU.sol +67 -0
  141. package/solidity/contracts/apps/Token.sol +12 -0
  142. package/solidity/contracts/apps/ZKArweave.sol +89 -0
  143. package/solidity/contracts/apps/ZKBridge.sol +74 -0
  144. package/solidity/contracts/apps/ZKNFT.sol +63 -0
  145. package/solidity/contracts/verifiers/verifier_db.sol +275 -0
  146. package/solidity/contracts/verifiers/verifier_ipfs.sol +464 -0
  147. package/solidity/contracts/verifiers/verifier_json.sol +261 -0
  148. package/solidity/contracts/verifiers/verifier_rollup.sol +240 -0
  149. package/solidity/package.json +27 -0
  150. package/solidity/scripts/deploy.js +33 -0
  151. package/solidity/test/NORU.js +66 -0
  152. package/solidity/test/ZKArweave.js +97 -0
  153. package/solidity/test/arweave.js +55 -0
  154. package/solidity/test/bridge.js +71 -0
  155. package/solidity/test/simple.js +76 -0
  156. package/solidity/test/simpleOPRU.js +98 -0
  157. package/solidity/test/simpleRU.js +94 -0
  158. package/solidity/test/zknft.js +98 -0
  159. package/solidity/yarn.lock +4152 -0
  160. package/test/test.js +304 -0
  161. /package/{circomlibjs.js → sdk/circomlibjs.js} +0 -0
  162. /package/{collection.js → sdk/collection.js} +0 -0
  163. /package/{contracts → sdk/contracts}/OPRollup.sol +0 -0
  164. /package/{contracts → sdk/contracts}/ZKIPFS.sol +0 -0
  165. /package/{contracts → sdk/contracts}/ZKJson.sol +0 -0
  166. /package/{contracts → sdk/contracts}/ZKQuery.sol +0 -0
  167. /package/{contracts → sdk/contracts}/ZKRollup.sol +0 -0
  168. /package/{contracts → sdk/contracts}/apps/SimpleJSON.sol +0 -0
  169. /package/{contracts → sdk/contracts}/apps/SimpleOPRU.sol +0 -0
  170. /package/{contracts → sdk/contracts}/apps/SimpleRU.sol +0 -0
  171. /package/{contracts → sdk/contracts}/apps/Token.sol +0 -0
  172. /package/{contracts → sdk/contracts}/apps/ZKArweave.sol +0 -0
  173. /package/{contracts → sdk/contracts}/apps/ZKBridge.sol +0 -0
  174. /package/{contracts → sdk/contracts}/apps/ZKNFT.sol +0 -0
  175. /package/{contracts → sdk/contracts}/verifiers/verifier_db.sol +0 -0
  176. /package/{contracts → sdk/contracts}/verifiers/verifier_ipfs.sol +0 -0
  177. /package/{contracts → sdk/contracts}/verifiers/verifier_json.sol +0 -0
  178. /package/{contracts → sdk/contracts}/verifiers/verifier_rollup.sol +0 -0
  179. /package/{db.js → sdk/db.js} +0 -0
  180. /package/{doc.js → sdk/doc.js} +0 -0
  181. /package/{encoder-v1_5.js → sdk/encoder-v1_5.js} +0 -0
  182. /package/{encoder.js → sdk/encoder.js} +0 -0
  183. /package/{index.js → sdk/index.js} +0 -0
  184. /package/{json.js → sdk/json.js} +0 -0
  185. /package/{nft.js → sdk/nft.js} +0 -0
  186. /package/{parse.js → sdk/parse.js} +0 -0
  187. /package/{uint.js → sdk/uint.js} +0 -0
@@ -0,0 +1,261 @@
1
+ // SPDX-License-Identifier: GPL-3.0
2
+ /*
3
+ Copyright 2021 0KIMS association.
4
+
5
+ This file is generated with [snarkJS](https://github.com/iden3/snarkjs).
6
+
7
+ snarkJS is a free software: you can redistribute it and/or modify it
8
+ under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ snarkJS is distributed in the hope that it will be useful, but WITHOUT
13
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15
+ License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with snarkJS. If not, see <https://www.gnu.org/licenses/>.
19
+ */
20
+
21
+ pragma solidity >=0.7.0 <0.9.0;
22
+
23
+ contract Groth16Verifier {
24
+ // Scalar field size
25
+ uint256 constant r = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
26
+ // Base field size
27
+ uint256 constant q = 21888242871839275222246405745257275088696311157297823662689037894645226208583;
28
+
29
+ // Verification Key data
30
+ uint256 constant alphax = 7332885377758315278340183047560982420908393795468599595091895974752420296340;
31
+ uint256 constant alphay = 332255058049377868589021735422241784808251989994698755461004804814851540428;
32
+ uint256 constant betax1 = 14918511796604743115529252945397806548811923425844505517068409231790256866971;
33
+ uint256 constant betax2 = 211413574403138532859071680094500506786935898681671422463746292741380691281;
34
+ uint256 constant betay1 = 19126853899579995366417647673795374157635727056721981778430611935842415927913;
35
+ uint256 constant betay2 = 19131403844100444556608656382423150552404085133882015610549223179149801306375;
36
+ uint256 constant gammax1 = 11559732032986387107991004021392285783925812861821192530917403151452391805634;
37
+ uint256 constant gammax2 = 10857046999023057135944570762232829481370756359578518086990519993285655852781;
38
+ uint256 constant gammay1 = 4082367875863433681332203403145435568316851327593401208105741076214120093531;
39
+ uint256 constant gammay2 = 8495653923123431417604973247489272438418190587263600148770280649306958101930;
40
+ uint256 constant deltax1 = 16108517980506854297849182541741553709725147068726502437460795221662934054392;
41
+ uint256 constant deltax2 = 11108122055952200981463380103442015838004112520282166325679324656261172289310;
42
+ uint256 constant deltay1 = 15540443534206155738973728487806979316634787078945919829097599147377062022852;
43
+ uint256 constant deltay2 = 21379352474752452421616166568647842540503269819420348102486102247380909072561;
44
+
45
+
46
+ uint256 constant IC0x = 21491549690759898325084849607299564336640876765821749498156862035601257576731;
47
+ uint256 constant IC0y = 7673274862583779134920456438013707521756656044641568042313054191508669514090;
48
+
49
+ uint256 constant IC1x = 7384807594330870281878199565618965338344331100873316262082027153266713199801;
50
+ uint256 constant IC1y = 14876621143313435278104193218580147792502814126320367012799180884583971278043;
51
+
52
+ uint256 constant IC2x = 14168855774320618160297871496225220542802525303313492506646049444075434034461;
53
+ uint256 constant IC2y = 2468759921621309671933672856806282408346496190229767650695758108046431009056;
54
+
55
+ uint256 constant IC3x = 20882499572322978549523449110104123650836957036545445021640442961988931511616;
56
+ uint256 constant IC3y = 10781231220582947841663615195913878935048287628839154817279937306701845963832;
57
+
58
+ uint256 constant IC4x = 3551014538515980043254241443826671153636028870428071676154749646867482617102;
59
+ uint256 constant IC4y = 17513115597425155133040003702455782665905020659681301812064653011904364586605;
60
+
61
+ uint256 constant IC5x = 105515585129844888605937953967649955568230431552746130229062574355263145521;
62
+ uint256 constant IC5y = 20200666388807201898426694143171918805989526661219556885905461961107161411873;
63
+
64
+ uint256 constant IC6x = 19504246290594149902008126941831109015032250944240332802409169333280249886793;
65
+ uint256 constant IC6y = 17699531383222577195964406519381055857401242060823677129203944848736284577334;
66
+
67
+ uint256 constant IC7x = 15254965952105123078324026560946378979667618649209045648866104810507209861613;
68
+ uint256 constant IC7y = 3641619426903900212193517444566552500256221100745411003347851827295876272315;
69
+
70
+ uint256 constant IC8x = 4499605970446611025648671992837865142426045383246510513270735661446224104646;
71
+ uint256 constant IC8y = 15341853963424215265359126787955887881741741004410294373221073774379489499288;
72
+
73
+ uint256 constant IC9x = 4636178543162541151831226653997316232974453000168920950316536975489566766643;
74
+ uint256 constant IC9y = 2799228255066264685511548900627321262829537276926174168686910780679641714598;
75
+
76
+ uint256 constant IC10x = 6388673479423994256307474279305289225670011140384557756459873981364992797681;
77
+ uint256 constant IC10y = 15445971588389648358240399113305305960608235393782465515171348639813010141589;
78
+
79
+ uint256 constant IC11x = 16999109717455015622767449319493463705406770611876428205363721384440112529191;
80
+ uint256 constant IC11y = 8675643256310098492425698438900503035238176419524618195032951410590093388339;
81
+
82
+ uint256 constant IC12x = 16871502461507515213546155066931373929841527789003952441940247163262482018578;
83
+ uint256 constant IC12y = 4970662515578058992947951260883675496659331271578004380224271812057151496904;
84
+
85
+ uint256 constant IC13x = 13968526389162956068739649724104930691708514396451450078611693259360926530004;
86
+ uint256 constant IC13y = 8822824035572686629738946181419338699884848605068510614565951757702861630826;
87
+
88
+ uint256 constant IC14x = 13433257895962314784382997146377098286327147717667015994113571363174981683976;
89
+ uint256 constant IC14y = 16316358056856673776145141235445376046620537375366520262647177307024013423430;
90
+
91
+
92
+ // Memory data
93
+ uint16 constant pVk = 0;
94
+ uint16 constant pPairing = 128;
95
+
96
+ uint16 constant pLastMem = 896;
97
+
98
+ function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[14] calldata _pubSignals) public view returns (bool) {
99
+ assembly {
100
+ function checkField(v) {
101
+ if iszero(lt(v, q)) {
102
+ mstore(0, 0)
103
+ return(0, 0x20)
104
+ }
105
+ }
106
+
107
+ // G1 function to multiply a G1 value(x,y) to value in an address
108
+ function g1_mulAccC(pR, x, y, s) {
109
+ let success
110
+ let mIn := mload(0x40)
111
+ mstore(mIn, x)
112
+ mstore(add(mIn, 32), y)
113
+ mstore(add(mIn, 64), s)
114
+
115
+ success := staticcall(sub(gas(), 2000), 7, mIn, 96, mIn, 64)
116
+
117
+ if iszero(success) {
118
+ mstore(0, 0)
119
+ return(0, 0x20)
120
+ }
121
+
122
+ mstore(add(mIn, 64), mload(pR))
123
+ mstore(add(mIn, 96), mload(add(pR, 32)))
124
+
125
+ success := staticcall(sub(gas(), 2000), 6, mIn, 128, pR, 64)
126
+
127
+ if iszero(success) {
128
+ mstore(0, 0)
129
+ return(0, 0x20)
130
+ }
131
+ }
132
+
133
+ function checkPairing(pA, pB, pC, pubSignals, pMem) -> isOk {
134
+ let _pPairing := add(pMem, pPairing)
135
+ let _pVk := add(pMem, pVk)
136
+
137
+ mstore(_pVk, IC0x)
138
+ mstore(add(_pVk, 32), IC0y)
139
+
140
+ // Compute the linear combination vk_x
141
+
142
+ g1_mulAccC(_pVk, IC1x, IC1y, calldataload(add(pubSignals, 0)))
143
+
144
+ g1_mulAccC(_pVk, IC2x, IC2y, calldataload(add(pubSignals, 32)))
145
+
146
+ g1_mulAccC(_pVk, IC3x, IC3y, calldataload(add(pubSignals, 64)))
147
+
148
+ g1_mulAccC(_pVk, IC4x, IC4y, calldataload(add(pubSignals, 96)))
149
+
150
+ g1_mulAccC(_pVk, IC5x, IC5y, calldataload(add(pubSignals, 128)))
151
+
152
+ g1_mulAccC(_pVk, IC6x, IC6y, calldataload(add(pubSignals, 160)))
153
+
154
+ g1_mulAccC(_pVk, IC7x, IC7y, calldataload(add(pubSignals, 192)))
155
+
156
+ g1_mulAccC(_pVk, IC8x, IC8y, calldataload(add(pubSignals, 224)))
157
+
158
+ g1_mulAccC(_pVk, IC9x, IC9y, calldataload(add(pubSignals, 256)))
159
+
160
+ g1_mulAccC(_pVk, IC10x, IC10y, calldataload(add(pubSignals, 288)))
161
+
162
+ g1_mulAccC(_pVk, IC11x, IC11y, calldataload(add(pubSignals, 320)))
163
+
164
+ g1_mulAccC(_pVk, IC12x, IC12y, calldataload(add(pubSignals, 352)))
165
+
166
+ g1_mulAccC(_pVk, IC13x, IC13y, calldataload(add(pubSignals, 384)))
167
+
168
+ g1_mulAccC(_pVk, IC14x, IC14y, calldataload(add(pubSignals, 416)))
169
+
170
+
171
+ // -A
172
+ mstore(_pPairing, calldataload(pA))
173
+ mstore(add(_pPairing, 32), mod(sub(q, calldataload(add(pA, 32))), q))
174
+
175
+ // B
176
+ mstore(add(_pPairing, 64), calldataload(pB))
177
+ mstore(add(_pPairing, 96), calldataload(add(pB, 32)))
178
+ mstore(add(_pPairing, 128), calldataload(add(pB, 64)))
179
+ mstore(add(_pPairing, 160), calldataload(add(pB, 96)))
180
+
181
+ // alpha1
182
+ mstore(add(_pPairing, 192), alphax)
183
+ mstore(add(_pPairing, 224), alphay)
184
+
185
+ // beta2
186
+ mstore(add(_pPairing, 256), betax1)
187
+ mstore(add(_pPairing, 288), betax2)
188
+ mstore(add(_pPairing, 320), betay1)
189
+ mstore(add(_pPairing, 352), betay2)
190
+
191
+ // vk_x
192
+ mstore(add(_pPairing, 384), mload(add(pMem, pVk)))
193
+ mstore(add(_pPairing, 416), mload(add(pMem, add(pVk, 32))))
194
+
195
+
196
+ // gamma2
197
+ mstore(add(_pPairing, 448), gammax1)
198
+ mstore(add(_pPairing, 480), gammax2)
199
+ mstore(add(_pPairing, 512), gammay1)
200
+ mstore(add(_pPairing, 544), gammay2)
201
+
202
+ // C
203
+ mstore(add(_pPairing, 576), calldataload(pC))
204
+ mstore(add(_pPairing, 608), calldataload(add(pC, 32)))
205
+
206
+ // delta2
207
+ mstore(add(_pPairing, 640), deltax1)
208
+ mstore(add(_pPairing, 672), deltax2)
209
+ mstore(add(_pPairing, 704), deltay1)
210
+ mstore(add(_pPairing, 736), deltay2)
211
+
212
+
213
+ let success := staticcall(sub(gas(), 2000), 8, _pPairing, 768, _pPairing, 0x20)
214
+
215
+ isOk := and(success, mload(_pPairing))
216
+ }
217
+
218
+ let pMem := mload(0x40)
219
+ mstore(0x40, add(pMem, pLastMem))
220
+
221
+ // Validate that all evaluations ∈ F
222
+
223
+ checkField(calldataload(add(_pubSignals, 0)))
224
+
225
+ checkField(calldataload(add(_pubSignals, 32)))
226
+
227
+ checkField(calldataload(add(_pubSignals, 64)))
228
+
229
+ checkField(calldataload(add(_pubSignals, 96)))
230
+
231
+ checkField(calldataload(add(_pubSignals, 128)))
232
+
233
+ checkField(calldataload(add(_pubSignals, 160)))
234
+
235
+ checkField(calldataload(add(_pubSignals, 192)))
236
+
237
+ checkField(calldataload(add(_pubSignals, 224)))
238
+
239
+ checkField(calldataload(add(_pubSignals, 256)))
240
+
241
+ checkField(calldataload(add(_pubSignals, 288)))
242
+
243
+ checkField(calldataload(add(_pubSignals, 320)))
244
+
245
+ checkField(calldataload(add(_pubSignals, 352)))
246
+
247
+ checkField(calldataload(add(_pubSignals, 384)))
248
+
249
+ checkField(calldataload(add(_pubSignals, 416)))
250
+
251
+ checkField(calldataload(add(_pubSignals, 448)))
252
+
253
+
254
+ // Validate all evaluations
255
+ let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem)
256
+
257
+ mstore(0, isValid)
258
+ return(0, 0x20)
259
+ }
260
+ }
261
+ }
@@ -0,0 +1,17 @@
1
+ pragma circom 2.0.0;
2
+
3
+ // This circuit returns the sum of the inputs.
4
+ // n must be greater than 0.
5
+ template CalculateTotal(n) {
6
+ signal input nums[n];
7
+ signal output sum;
8
+
9
+ signal sums[n];
10
+ sums[0] <== nums[0];
11
+
12
+ for (var i=1; i < n; i++) {
13
+ sums[i] <== sums[i - 1] + nums[i];
14
+ }
15
+
16
+ sum <== sums[n - 1];
17
+ }
@@ -0,0 +1,10 @@
1
+ #!/bin/bash
2
+ circom index.circom --r1cs --wasm --sym --c \
3
+ && cd index_js \
4
+ && node generate_witness.js index.wasm ../input.json witness.wtns \
5
+ && cd .. \
6
+ && snarkjs groth16 setup index.r1cs ../pot12_final.ptau index_0000.zkey \
7
+ && snarkjs zkey contribute index_0000.zkey index_0001.zkey --name="zkJSON" -v \
8
+ && snarkjs zkey export verificationkey index_0001.zkey verification_key.json \
9
+ && snarkjs groth16 prove index_0001.zkey index_js/witness.wtns proof.json public.json \
10
+ && snarkjs groth16 verify verification_key.json public.json proof.json;
@@ -0,0 +1,18 @@
1
+ const { str, push, arr, toArray } = require("../../sdk/uint")
2
+ const { pad, path, val } = require("../../sdk/encoder")
3
+ const { parse } = require("../../sdk/parse")
4
+ const gen = async ({ size_val = 8, size_path = 4, size_json = 256 }) => {
5
+ const json = { hello: "world" }
6
+ const _str = new TextEncoder().encode(JSON.stringify(json))
7
+
8
+ let encoded = arr(256)
9
+ for (let v of Array.from(_str)) encoded = push(encoded, 256, 76, v)
10
+ const enc = parse(encoded, 256)
11
+ const _path = pad(path("hello"), size_path)
12
+ const _val = pad(path("world"), size_val)
13
+ return {
14
+ inputs: { encoded: str(encoded), path: _path, val: _val },
15
+ }
16
+ }
17
+
18
+ module.exports = gen
@@ -0,0 +1,10 @@
1
+ const { writeFileSync } = require("fs")
2
+ const { resolve } = require("path")
3
+ const gen = require("./gen")
4
+
5
+ const main = async () => {
6
+ const { inputs } = await gen({})
7
+ writeFileSync(resolve(__dirname, "input.json"), JSON.stringify(inputs))
8
+ }
9
+
10
+ main()
@@ -0,0 +1,4 @@
1
+ pragma circom 2.1.5;
2
+ include "./ipfs.circom";
3
+
4
+ component main {public [path, val]} = IPFS(256, 4, 8, 10);
@@ -0,0 +1,62 @@
1
+ pragma circom 2.1.5;
2
+ include "../utils/uint.circom";
3
+ include "./parse.circom";
4
+ include "./sha256.circom";
5
+ include "../json/json.circom";
6
+
7
+ function packBits(bits) {
8
+ var packed[32];
9
+ for (var i = 0; i < 32; i++) {
10
+ for (var i2 = 0; i2 < 8; i2++) {
11
+ packed[i] += bits[i * 8 + i2] * (1 << (8 - 1 - i2));
12
+ }
13
+ }
14
+ return packed;
15
+ }
16
+ template IPFS (size_json, size_path, size_val, nBlocks) {
17
+ signal input encoded[size_json];
18
+ signal input path[size_path];
19
+ signal input val[size_val];
20
+ signal output exist;
21
+ signal output out[32];
22
+ var binary[458];
23
+ var _json[size_json];
24
+ var _path[size_json];
25
+ var _val[size_json];
26
+ var _temp[size_json];
27
+ _json = parse(encoded, size_json, _path, _val, _json, _temp);
28
+ component _json2 = JSON(256, size_path, size_val);
29
+ _json2.json <-- _json;
30
+ _json2.path <== path;
31
+ _json2.val <== val;
32
+ exist <== _json2.exist;
33
+
34
+ var c[9] = [0, size_json, 0, 0, 0, 0, 0, 0, 0];
35
+ var i = 0;
36
+ while(c[5] == 0){
37
+ c = next(encoded, c);
38
+ for(var j = 0; j < 8; j++){
39
+ binary[i] = ((c[0] >> (7 - j)) & 1);
40
+ i++;
41
+ }
42
+ }
43
+ var paddedIn[nBlocks][512];
44
+ var tBlock = ((i + 64)\512)+1;
45
+ var k;
46
+ for (k=0; k<i; k++) {
47
+ paddedIn[k \ 512][k % 512] = binary[k];
48
+ }
49
+ paddedIn[i \ 512][i % 512] = 1;
50
+
51
+ for (k=i+1; k<tBlock*512-64; k++) {
52
+ paddedIn[k \ 512][k % 512] = 0;
53
+ }
54
+ for (k = 0; k< 64; k++) {
55
+ paddedIn[(tBlock * 512 - k - 1) \ 512][(tBlock * 512 - k - 1) % 512] = (i >> k)&1;
56
+ }
57
+ component sha = Sha256_unsafe(nBlocks);
58
+ sha.tBlock <-- tBlock;
59
+ sha.in <-- paddedIn;
60
+ var packed[32] = packBits(sha.out);
61
+ out <== packed;
62
+ }
@@ -0,0 +1,289 @@
1
+ pragma circom 2.1.5;
2
+ include "../utils/uint.circom";
3
+
4
+ function eql (a, b, blen, size) {
5
+ var alen = length(a, size);
6
+ if (alen != blen) return 0;
7
+ var c[9] = [0, size, 0, 0, 0, 0, 0, 0, 0];
8
+ for (var i = 0; i < blen; i++) {
9
+ c = next(a, c);
10
+ if (c[0] != b[i]) return 0;
11
+ }
12
+ return 1;
13
+ }
14
+
15
+ function constVal (_v, type, size, val) {
16
+ var _true_[4] = [116, 114, 117, 101];
17
+
18
+ val = push(val, size, 76, type);
19
+ if (type == 1) {
20
+ if (eql(_v, _true_, 4, size) == 1) {
21
+ val = push(val, size, 76, 1);
22
+ } else {
23
+ val = push(val, size, 76, 0);
24
+ }
25
+ } else if (type == 3) {
26
+ val = push(val, size, 76, length(_v, size));
27
+ var c[9] = [0, size, 0, 0, 0, 0, 0, 0, 0];
28
+ while (c[5] == 0) {
29
+ c = next(_v, c);
30
+ val = push(val, size, 76, c[0]);
31
+ }
32
+ } else if (type == 2) {
33
+ if (get(_v, size, 0) == 45) {
34
+ val = push(val, size, 76, 0);
35
+ } else {
36
+ val = push(val, size, 76, 1);
37
+ }
38
+ var after = 0;
39
+ var right = 0;
40
+ var digits = 0;
41
+ var c[9] = [0, size, 0, 0, 0, 0, 0, 0, 0];
42
+ while (c[5] == 0) {
43
+ c = next(_v, c);
44
+ if (c[0] == 46) {
45
+ after = 1;
46
+ } else if (c[0] != 45) {
47
+ if (after == 1) right += 1;
48
+ digits = digits * 10 + (c[0] - 48);
49
+ }
50
+ }
51
+ val = push(val, size, 76, right);
52
+ val = push(val, size, 76, digits);
53
+ }
54
+ return val;
55
+ }
56
+
57
+ function constPath (p, size, pth2) {
58
+ var len = get(p, size, 0);
59
+ pth2 = push(pth2, size, 76, len);
60
+ for (var i = 0; i < len; i++) {
61
+ var len2 = get(p, size, i + 1);
62
+ var _sum = sum(p, size, 76, 1, 1 + i);
63
+ var first = get(p, size, 1 + len + _sum);
64
+ if (first == 0) {
65
+ pth2 = push(pth2, size, 76, 0);
66
+ } else {
67
+ pth2 = push(pth2, size, 76, len2);
68
+ }
69
+ for (var i2 = 0; i2 < len2; i2++) {
70
+ var v = get(p, size, 1 + len + _sum + i2);
71
+ pth2 = push(pth2, size, 76, v);
72
+ }
73
+ }
74
+ return pth2;
75
+ }
76
+
77
+ function isNumber (val, size, digit) {
78
+ var len = length(val, size);
79
+ var c[9] = [0, size, 0, 0, 0, 0, 0, 0, 0];
80
+ while (c[5] == 0) {
81
+ c = next(val, c);
82
+ if (c[0] == 47 || c[0] < 45 || c[0] > 57) return 0;
83
+ }
84
+
85
+ return 1;
86
+ }
87
+
88
+
89
+ function empty(_arr, size) {
90
+ for(var i = 0; i < size; i++){
91
+ _arr[i] = 0;
92
+ }
93
+ return _arr;
94
+ }
95
+
96
+ function parse (str, size, path, val, json, temp) {
97
+ var _null_[4] = [110, 117, 108, 108];
98
+ var _true_[4] = [116, 114, 117, 101];
99
+ var _false_[5] = [102, 97, 108, 115, 101];
100
+ var inVal = 0;
101
+ var isNum = 0;
102
+ var esc = 0;
103
+ var nextKey = 0;
104
+ var arr = 0;
105
+ var obj = 0;
106
+ var ao[5];
107
+ var ind[5];
108
+ var err = 0;
109
+ var c[9] = [0, size, 0, 0, 0, 0, 0, 0, 0];
110
+ var bare = 1;
111
+ while (c[5] == 0) {
112
+ c = next(str, c);
113
+ var s = c[0];
114
+ if (inVal == 1) {
115
+ if (s == 92) {
116
+ esc = 1;
117
+ } else if (s == 34) {
118
+ if (esc == 1) {
119
+ val = push(val, size, 76, s);
120
+ } else {
121
+ inVal = 0;
122
+ if (nextKey == 1 && last(ao, 5) == 1) {
123
+ path = pushArray(path, size, 76, val, size, temp);
124
+ } else {
125
+ if (last(ao, 5) == 2) {
126
+ var _ind = last(ind, 5);
127
+ var __ind[5];
128
+ __ind = push(__ind, 5, 76, 0);
129
+ __ind = push(__ind, 5, 76, _ind);
130
+ path = pushArray(path, size, 76, __ind, 5, temp);
131
+ ind = pop(ind, 5);
132
+ ind = push(ind, 5, 76, _ind + 1);
133
+ }
134
+ json = concat(
135
+ json,
136
+ concat(constPath(path, size, temp), constVal(val, 3, size, temp), size, 76),
137
+ size,
138
+ 76
139
+ );
140
+ if(bare == 0) path = popArray(path, size, 76, temp);
141
+ }
142
+
143
+ val = empty(val, size);
144
+ nextKey = 0;
145
+ }
146
+ esc = 0;
147
+ } else {
148
+ val = push(val, size, 76, s);
149
+ esc = 0;
150
+ }
151
+ } else if (isNum == 1) {
152
+ if (s == 44 || s == 32 || s == 125 || s == 93) {
153
+ if (last(ao, 5) == 2) {
154
+ var _ind = last(ind, 5);
155
+ var __ind[5];
156
+ __ind = push(__ind, 5, 76, 0);
157
+ __ind = push(__ind, 5, 76, _ind);
158
+ path = pushArray(path, size, 76, __ind, 5, temp);
159
+ ind = pop(ind, 5);
160
+ ind = push(ind, 5, 76, _ind + 1);
161
+ }
162
+ if (
163
+ eql(val, _true_, 4, size) == 0 &&
164
+ eql(val, _false_, 5, size) == 0 &&
165
+ eql(val, _null_, 4, size) == 0 &&
166
+ isNumber(val, size, 76) == 0
167
+ ) {
168
+ err = 1;
169
+ }
170
+ var type = 2;
171
+ if (eql(val, _null_, 4, size) == 1) {
172
+ type = 0;
173
+ } else if (
174
+ eql(val, _true_, 4, size) == 1 ||
175
+ eql(val, _false_, 5, size) == 1
176
+ ) {
177
+ type = 1;
178
+ }
179
+ json = concat(
180
+ json,
181
+ concat(constPath(path, size, temp), constVal(val, type, size, temp), size, 76),
182
+ size,
183
+ 76
184
+ );
185
+ path = popArray(path, size, 76, temp);
186
+ if (s == 93) {
187
+ if (last(ao, 5) != 2) err = 1;
188
+ ao = pop(ao, 5);
189
+ if(bare == 0) path = popArray(path, size, 76, temp);
190
+ arr--;
191
+ ind = pop(ind, 5);
192
+ }
193
+ if (s == 125) {
194
+ if (last(ao, 5) != 1) err = 1;
195
+ ao = pop(ao, 5);
196
+ obj--;
197
+ }
198
+ isNum = 0;
199
+ val = empty(val, size);
200
+ if (s == 44) nextKey = 1;
201
+ } else {
202
+ val = push(val, size, 76, s);
203
+ }
204
+ } else if (s == 34) {
205
+ inVal = 1;
206
+ } else if (
207
+ s != 123 &&
208
+ s != 58 &&
209
+ s != 32 &&
210
+ s != 44 &&
211
+ s != 91 &&
212
+ s != 93 &&
213
+ s != 125
214
+ ) {
215
+ isNum = 1;
216
+ val = push(val, size, 76, s);
217
+ } else {
218
+ if (s != 32) {
219
+ if (s == 123 || s == 44){
220
+ bare = 0;
221
+ nextKey = 1;
222
+ }
223
+ if (s == 123) {
224
+ if (last(ao, 5) == 2) {
225
+ var _ind = last(ind, 5);
226
+ var __ind[5];
227
+ __ind = push(__ind, 5, 76, 0);
228
+ __ind = push(__ind, 5, 76, _ind);
229
+ path = pushArray(path, size, 76, __ind, 5, temp);
230
+ ind = pop(ind, 5);
231
+ ind = push(ind, 5, 76, _ind + 1);
232
+ }
233
+ ao = push(ao, 5, 76, 1);
234
+ obj++;
235
+ }
236
+ if (s == 125) {
237
+ if (last(ao, 5) != 1) err = 1;
238
+ ao = pop(ao, 5);
239
+ obj--;
240
+ }
241
+ if (s == 91) {
242
+ if (last(ao, 5) == 2) {
243
+ var _ind = last(ind, 5);
244
+ var __ind[5];
245
+ __ind = push(__ind, 5, 76, 0);
246
+ __ind = push(__ind, 5, 76, _ind);
247
+ path = pushArray(path, size, 76, __ind, 5, temp);
248
+ ind = pop(ind, 5);
249
+ ind = push(ind, 5, 76, _ind + 1);
250
+ }
251
+ ind = push(ind, 5, 76, 0);
252
+ ao = push(ao, 5, 76, 2);
253
+ arr++;
254
+ }
255
+ if (s == 93) {
256
+ if (last(ao, 5) != 2) err = 1;
257
+ ao = pop(ao, 5);
258
+ ind = pop(ind, 5);
259
+ path = popArray(path, size, 76, temp);
260
+ arr--;
261
+ }
262
+ }
263
+ }
264
+ }
265
+ if (length(val, size) != 0) {
266
+ var type = 4;
267
+ if (eql(val, _null_, 4, size) == 1) {
268
+ type = 0;
269
+ isNum = 0;
270
+ } else if (eql(val, _true_, 4, size) == 1 || eql(val, _false_, 5, size)) {
271
+ type = 1;
272
+ isNum = 0;
273
+ } else if (isNumber(val, size, 76) == 1) {
274
+ type = 2;
275
+ isNum = 0;
276
+ }
277
+ json = concat(
278
+ json,
279
+ concat(constPath(path, size, temp), constVal(val, type, size, temp), size, 76),
280
+ size,
281
+ 76
282
+ );
283
+ }
284
+ if (length(ao, 5) > 0) err = 1;
285
+ if (length(ind, 5) > 0) err = 1;
286
+ if (inVal) err = 1;
287
+ if (isNum) err = 1;
288
+ return json;
289
+ }