zkjson 0.6.1 → 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/{contracts → sdk/contracts}/NORollup.sol +0 -2
  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,67 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.7.0 <0.9.0;
4
+
5
+ import "../ZKRollup.sol";
6
+
7
+ interface VerifierDB {
8
+ function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[16] calldata _pubSignals) view external returns (bool);
9
+ }
10
+
11
+ contract SimpleRU is ZKRollup {
12
+ uint constant SIZE_PATH = 4;
13
+ uint constant SIZE_VAL = 8;
14
+ address public verifierDB;
15
+
16
+ constructor (address _verifierRU, address _verifierDB, address _committer){
17
+ verifierRU = _verifierRU;
18
+ verifierDB = _verifierDB;
19
+ committer = _committer;
20
+ }
21
+
22
+ function validateQuery(uint[] memory path, uint[] memory zkp) private view returns(uint[] memory){
23
+ verify(zkp, VerifierDB.verifyProof.selector, verifierDB);
24
+ return _validateQueryRU(path, zkp, SIZE_PATH, SIZE_VAL);
25
+ }
26
+
27
+ function qInt (uint[] memory path, uint[] memory zkp) public view returns (int) {
28
+ uint[] memory value = validateQuery(path, zkp);
29
+ return _qInt(value);
30
+ }
31
+
32
+ function qFloat (uint[] memory path, uint[] memory zkp) public view returns (uint[3] memory) {
33
+ uint[] memory value = validateQuery(path, zkp);
34
+ return _qFloat(value);
35
+ }
36
+
37
+ function qRaw (uint[] memory path, uint[] memory zkp) public view returns (uint[] memory) {
38
+ uint[] memory value = validateQuery(path, zkp);
39
+ return _qRaw(value);
40
+ }
41
+
42
+ function qString (uint[] memory path, uint[] memory zkp) public view returns (string memory) {
43
+ uint[] memory value = validateQuery(path, zkp);
44
+ return _qString(value);
45
+ }
46
+
47
+ function qBool (uint[] memory path, uint[] memory zkp) public view returns (bool) {
48
+ uint[] memory value = validateQuery(path, zkp);
49
+ return _qBool(value);
50
+ }
51
+
52
+ function qNull (uint[] memory path, uint[] memory zkp) public view returns (bool) {
53
+ uint[] memory value = validateQuery(path, zkp);
54
+ return _qNull(value);
55
+ }
56
+
57
+ function qCond (uint[] memory path, uint[] memory cond, uint[] memory zkp) public view returns (bool) {
58
+ uint[] memory value = validateQuery(path, zkp);
59
+ return _qCond(value, cond);
60
+ }
61
+
62
+ function qCustom (uint[] memory path, uint[] memory path2, uint[] memory zkp) public view returns (int) {
63
+ uint[] memory value = validateQuery(path, zkp);
64
+ return getInt(path2, value);
65
+ }
66
+
67
+ }
@@ -0,0 +1,12 @@
1
+ // contracts/GLDToken.sol
2
+ // SPDX-License-Identifier: MIT
3
+ pragma solidity ^0.8.0;
4
+
5
+ import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
6
+
7
+ contract Token is ERC20 {
8
+ constructor() ERC20("Token", "TOKEN") {}
9
+ function mint(address to, uint amount) public {
10
+ _mint(to, amount);
11
+ }
12
+ }
@@ -0,0 +1,89 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.7.0 <0.9.0;
4
+
5
+ import "../ZKJson.sol";
6
+
7
+ interface VerifierJSON {
8
+ function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[14] calldata _pubSignals) view external returns (bool);
9
+
10
+ }
11
+
12
+ contract ZKArweave is ZKJson {
13
+ address public verifier;
14
+ address public validator;
15
+ uint constant SIZE_PATH = 4;
16
+ uint constant SIZE_VAL = 8;
17
+
18
+ constructor (address _verifier, address _validator){
19
+ verifier = _verifier;
20
+ validator = _validator;
21
+ }
22
+
23
+ function validateQuery(string memory txid, uint[] memory path, uint[] memory zkp, bytes memory sig) public view returns(uint[] memory){
24
+ verify(zkp, VerifierJSON.verifyProof.selector, verifier);
25
+ verifyMessage(txid, zkp[9], sig);
26
+ return _validateQueryJSON(path, zkp, SIZE_PATH, SIZE_VAL);
27
+ }
28
+
29
+ function qInt (string memory txid, uint[] memory path, uint[] memory zkp, bytes memory sig) public view returns (int) {
30
+ uint[] memory value = validateQuery(txid, path, zkp, sig);
31
+ return _qInt(value);
32
+ }
33
+
34
+ function qFloat (string memory txid, uint[] memory path, uint[] memory zkp, bytes memory sig) public view returns (uint[3] memory) {
35
+ uint[] memory value = validateQuery(txid, path, zkp, sig);
36
+ return _qFloat(value);
37
+ }
38
+
39
+ function qRaw (string memory txid, uint[] memory path, uint[] memory zkp, bytes memory sig) public view returns (uint[] memory) {
40
+ uint[] memory value = validateQuery(txid, path, zkp, sig);
41
+ return _qRaw(value);
42
+ }
43
+
44
+ function qString (string memory txid, uint[] memory path, uint[] memory zkp, bytes memory sig) public view returns (string memory) {
45
+ uint[] memory value = validateQuery(txid, path, zkp, sig);
46
+ return _qString(value);
47
+ }
48
+
49
+ function qBool (string memory txid, uint[] memory path, uint[] memory zkp, bytes memory sig) public view returns (bool) {
50
+ uint[] memory value = validateQuery(txid, path, zkp, sig);
51
+ return _qBool(value);
52
+ }
53
+
54
+ function qNull (string memory txid, uint[] memory path, uint[] memory zkp, bytes memory sig) public view returns (bool) {
55
+ uint[] memory value = validateQuery(txid, path, zkp, sig);
56
+ return _qNull(value);
57
+ }
58
+
59
+ function getMessageHash(string memory txid, uint hash) public pure returns (bytes32) {
60
+ return keccak256(abi.encodePacked(txid, hash));
61
+ }
62
+
63
+ function getEthSignedMessageHash( bytes32 _messageHash ) private pure returns (bytes32) {
64
+ return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", _messageHash));
65
+ }
66
+
67
+ function verifyMessage(string memory txid, uint _message, bytes memory signature) public view returns (bool) {
68
+ bytes32 messageHash = getMessageHash(txid, _message);
69
+ bytes32 ethSignedMessageHash = getEthSignedMessageHash(messageHash);
70
+ return recoverSigner(ethSignedMessageHash, signature) == validator;
71
+ }
72
+
73
+ function recoverSigner(
74
+ bytes32 _ethSignedMessageHash,
75
+ bytes memory _signature
76
+ ) private pure returns (address) {
77
+ (bytes32 r, bytes32 s, uint8 v) = splitSignature(_signature);
78
+ return ecrecover(_ethSignedMessageHash, v, r, s);
79
+ }
80
+
81
+ function splitSignature(bytes memory sig) private pure returns (bytes32 r, bytes32 s, uint8 v) {
82
+ require(sig.length == 65, "invalid signature length");
83
+ assembly {
84
+ r := mload(add(sig, 32))
85
+ s := mload(add(sig, 64))
86
+ v := byte(0, mload(add(sig, 96)))
87
+ }
88
+ }
89
+ }
@@ -0,0 +1,74 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.7.0 <0.9.0;
4
+
5
+ interface IZKDB {
6
+
7
+ function qInt (uint[] memory path, uint[] memory zkp) external view returns (int);
8
+
9
+ function qString ( uint[] memory path, uint[] memory zkp) external view returns (string memory);
10
+
11
+ }
12
+
13
+ interface IERC20 {
14
+ function mint (address, uint) external;
15
+ }
16
+
17
+ contract ZKBridge {
18
+ address public zkdb;
19
+ address public token;
20
+ mapping(uint => bool) public done;
21
+ constructor (address _zkdb, address _token){
22
+ zkdb = _zkdb;
23
+ token = _token;
24
+ }
25
+
26
+ function hexCharToByte(uint8 c) public pure returns (uint8) {
27
+ if (bytes1(c) >= bytes1('0') && bytes1(c) <= bytes1('9')) {
28
+ return c - uint8(bytes1('0'));
29
+ }
30
+ if (bytes1(c) >= bytes1('a') && bytes1(c) <= bytes1('f')) {
31
+ return 10 + c - uint8(bytes1('a'));
32
+ }
33
+ if (bytes1(c) >= bytes1('A') && bytes1(c) <= bytes1('F')) {
34
+ return 10 + c - uint8(bytes1('A'));
35
+ }
36
+ revert("Invalid hex character");
37
+ }
38
+
39
+ function toAddr(string memory s) public pure returns (address) {
40
+ bytes memory ss = bytes(s);
41
+ require(ss.length == 42, "Invalid length");
42
+
43
+ uint256 r = 0;
44
+ for (uint256 i = 2; i < 42; i++) {
45
+ r = r * 16 + hexCharToByte(uint8(ss[i]));
46
+ }
47
+
48
+ return address(uint160(r));
49
+ }
50
+
51
+ function char(bytes1 b) internal pure returns (bytes1 c) {
52
+ if (uint8(b) < 10) return bytes1(uint8(b) + 0x30);
53
+ else return bytes1(uint8(b) + 0x57);
54
+ }
55
+
56
+ function bridge(uint col, uint doc, uint[] memory zkp, uint[] memory zkp2) public returns (address){
57
+ require(done[doc] == false, "already minted");
58
+ done[doc] = true;
59
+ uint[] memory path = new uint[](3);
60
+ path[0] = col;
61
+ path[1] = doc;
62
+ path[2] = 1111231163111;
63
+ uint[] memory path2 = new uint[](3);
64
+ path2[0] = col;
65
+ path2[1] = doc;
66
+ path2[2] = 1111629731093111311731103116;
67
+ string memory str = IZKDB(zkdb).qString(path, zkp);
68
+ address addr = toAddr(str);
69
+ int balance = IZKDB(zkdb).qInt(path2, zkp2);
70
+ IERC20(token).mint(addr, uint(balance));
71
+ return addr;
72
+ }
73
+
74
+ }
@@ -0,0 +1,63 @@
1
+ /// SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.20;
3
+
4
+ import "../ZKIPFS.sol";
5
+
6
+ import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
7
+
8
+ import {ERC721URIStorage} from "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
9
+
10
+ contract ZKNFT is ERC721URIStorage, ZKIPFS {
11
+ uint256 private _nextTokenId;
12
+ constructor(address _verifierIPFS) ERC721("ZKNFT", "ZKNFT") {
13
+ verifierIPFS = _verifierIPFS;
14
+ }
15
+
16
+ function mint(address to, string memory tokenURI)
17
+ public
18
+ returns (uint256)
19
+ {
20
+ uint256 tokenId = _nextTokenId++;
21
+ _mint(to, tokenId);
22
+ _setTokenURI(tokenId, tokenURI);
23
+
24
+ return tokenId;
25
+ }
26
+
27
+ function _verify (uint tokenId, uint[] memory path, uint[] memory zkp) private view returns (uint[] memory) {
28
+ return validateQuery(tokenURI(tokenId), path, zkp);
29
+ }
30
+
31
+ function qString (uint tokenId, uint[] memory path, uint[] memory zkp) public view returns (string memory) {
32
+ return _qString(_verify(tokenId, path, zkp));
33
+ }
34
+
35
+ function qInt (uint tokenId, uint[] memory path, uint[] memory zkp) public view returns (int) {
36
+ return _qInt(_verify(tokenId, path, zkp));
37
+ }
38
+
39
+ function qFloat (uint tokenId, uint[] memory path, uint[] memory zkp) public view returns (uint[3] memory) {
40
+ return _qFloat(_verify(tokenId, path, zkp));
41
+ }
42
+
43
+ function qBool (uint tokenId, uint[] memory path, uint[] memory zkp) public view returns (bool) {
44
+ return _qBool(_verify(tokenId, path, zkp));
45
+ }
46
+
47
+ function qNull (uint tokenId, uint[] memory path, uint[] memory zkp) public view returns (bool) {
48
+ return _qNull(_verify(tokenId, path, zkp));
49
+ }
50
+
51
+ function qRaw (uint tokenId, uint[] memory path, uint[] memory zkp) internal view returns (uint[] memory) {
52
+ return _qRaw(_verify(tokenId, path, zkp));
53
+ }
54
+
55
+ function qCustom (uint tokenId, uint[] memory path, uint[] memory path2, uint[] memory zkp) public view returns (int) {
56
+ return getInt(path2, qRaw(tokenId, path, zkp));
57
+ }
58
+
59
+ function qCond (uint tokenId, uint[] memory path, uint[] memory cond, uint[] memory zkp) public view returns (bool) {
60
+ return _qCond(_verify(tokenId, path, zkp), cond);
61
+ }
62
+
63
+ }
@@ -0,0 +1,275 @@
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 Groth16VerifierDB {
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 = 15666102625973721621314372231502757622972672186869992706298330320625360022168;
31
+ uint256 constant alphay = 7860317584437807811785184551736117381909584923230858144057222694769024311858;
32
+ uint256 constant betax1 = 5694626294852239414951192660282103704402907520663058613604080680299155414738;
33
+ uint256 constant betax2 = 5842324628399168549713701697348354919163878880337475549755337604460908215719;
34
+ uint256 constant betay1 = 15299555850342023627325133664905760186157697378199428660903779519265533045460;
35
+ uint256 constant betay2 = 19369932919467500712513911930210382196103616502274926080161996489344136260171;
36
+ uint256 constant gammax1 = 11559732032986387107991004021392285783925812861821192530917403151452391805634;
37
+ uint256 constant gammax2 = 10857046999023057135944570762232829481370756359578518086990519993285655852781;
38
+ uint256 constant gammay1 = 4082367875863433681332203403145435568316851327593401208105741076214120093531;
39
+ uint256 constant gammay2 = 8495653923123431417604973247489272438418190587263600148770280649306958101930;
40
+ uint256 constant deltax1 = 566319682436850529692773273170461279524268577891150635825387390239831567882;
41
+ uint256 constant deltax2 = 18860268461005016027048821926573675096822806032916343944940397566918262972873;
42
+ uint256 constant deltay1 = 18469561290186198192930600182225641948070680663786775400869545881576215584097;
43
+ uint256 constant deltay2 = 16843711002267486950099400107694084564320643561117060725912074365097520873528;
44
+
45
+
46
+ uint256 constant IC0x = 15211415922364842912753184178425045511192002084183450091972766587897729031131;
47
+ uint256 constant IC0y = 15971336196196622349517605395705397293225200783943199092270415284510546939053;
48
+
49
+ uint256 constant IC1x = 3464979308878298246776645144833226341117035087307090727251356729925690049544;
50
+ uint256 constant IC1y = 2701132742000937878189241109199334668029723964378951774716229117963684334785;
51
+
52
+ uint256 constant IC2x = 17746992021893097019070205838284045039565036550366113750079443947456708932914;
53
+ uint256 constant IC2y = 20205302109688801012538493936661638426411524231619729625407218303411393971055;
54
+
55
+ uint256 constant IC3x = 12245350253809957962446325719420284548409481797652910572382809447209300296011;
56
+ uint256 constant IC3y = 2181944750218360909814361656088418665618898112511704294612292313825818583174;
57
+
58
+ uint256 constant IC4x = 14272371780610106622173486440520433262823996106221430333841111091741849894946;
59
+ uint256 constant IC4y = 2651668025058914772481681251893270544825897012494799335931264036971472027402;
60
+
61
+ uint256 constant IC5x = 15368773499402856795009961960791288514014805980406357981082924459251021982345;
62
+ uint256 constant IC5y = 19702123112400711796073644885827586177870326559870904640843668152019488063904;
63
+
64
+ uint256 constant IC6x = 10677187776951951873630238944736414260225581042281553648384370976204183115940;
65
+ uint256 constant IC6y = 1992236736977150082653976323411946326010253872212815347510072691523085595255;
66
+
67
+ uint256 constant IC7x = 21415137280411204335091094503224446366978234376524115265045654108152006539895;
68
+ uint256 constant IC7y = 18542175761555436023959545358821820821282980394602494205800055757297012906764;
69
+
70
+ uint256 constant IC8x = 6283856560272202991953013809355758204828896535304136319974685636684888856128;
71
+ uint256 constant IC8y = 14499901693513608835779722317486164346309825524575154749627267356894076467615;
72
+
73
+ uint256 constant IC9x = 19685518566119573827093988474850506880006629001058664371716514877455244663914;
74
+ uint256 constant IC9y = 8481292601887397637049972433197231800580995340144247273832382075808559008848;
75
+
76
+ uint256 constant IC10x = 223137936376193785345096638287096394886709464533117482694619505935732331537;
77
+ uint256 constant IC10y = 4193175916548019617597370686901033731734454606724750484807673453694700951952;
78
+
79
+ uint256 constant IC11x = 16453801468826605202509345195157388810770747557053039494013978418267763931861;
80
+ uint256 constant IC11y = 9875951739441984097810674555101191788888352673039488118805457327521421929503;
81
+
82
+ uint256 constant IC12x = 21492667345885781313718619285662713900245557314551393448696666210356792295028;
83
+ uint256 constant IC12y = 13513771098803659055046650647390462300798249154666189755091027612809331818956;
84
+
85
+ uint256 constant IC13x = 4220313889112567763732397801925007682896952364521933389131895252279385675080;
86
+ uint256 constant IC13y = 4489372840961844505718038698916106673528658906928588565989450268053621743612;
87
+
88
+ uint256 constant IC14x = 14271407211698650570939162738932653937074499981772815895780302661786173648938;
89
+ uint256 constant IC14y = 19455923871335066470920134858740491433267919882177953263240475980057134848859;
90
+
91
+ uint256 constant IC15x = 16133332441580541207424712869162600438872610254859964823012819022285880626496;
92
+ uint256 constant IC15y = 205394163904875832569231417271795177705566674339331369995643748855708511527;
93
+
94
+ uint256 constant IC16x = 20041249883696113203488105074051660077326597780992987346896682994784878002567;
95
+ uint256 constant IC16y = 17581544103776691653953052153212138864315675260675640899993173889329216891748;
96
+
97
+
98
+ // Memory data
99
+ uint16 constant pVk = 0;
100
+ uint16 constant pPairing = 128;
101
+
102
+ uint16 constant pLastMem = 896;
103
+
104
+ function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[16] calldata _pubSignals) public view returns (bool) {
105
+ assembly {
106
+ function checkField(v) {
107
+ if iszero(lt(v, q)) {
108
+ mstore(0, 0)
109
+ return(0, 0x20)
110
+ }
111
+ }
112
+
113
+ // G1 function to multiply a G1 value(x,y) to value in an address
114
+ function g1_mulAccC(pR, x, y, s) {
115
+ let success
116
+ let mIn := mload(0x40)
117
+ mstore(mIn, x)
118
+ mstore(add(mIn, 32), y)
119
+ mstore(add(mIn, 64), s)
120
+
121
+ success := staticcall(sub(gas(), 2000), 7, mIn, 96, mIn, 64)
122
+
123
+ if iszero(success) {
124
+ mstore(0, 0)
125
+ return(0, 0x20)
126
+ }
127
+
128
+ mstore(add(mIn, 64), mload(pR))
129
+ mstore(add(mIn, 96), mload(add(pR, 32)))
130
+
131
+ success := staticcall(sub(gas(), 2000), 6, mIn, 128, pR, 64)
132
+
133
+ if iszero(success) {
134
+ mstore(0, 0)
135
+ return(0, 0x20)
136
+ }
137
+ }
138
+
139
+ function checkPairing(pA, pB, pC, pubSignals, pMem) -> isOk {
140
+ let _pPairing := add(pMem, pPairing)
141
+ let _pVk := add(pMem, pVk)
142
+
143
+ mstore(_pVk, IC0x)
144
+ mstore(add(_pVk, 32), IC0y)
145
+
146
+ // Compute the linear combination vk_x
147
+
148
+ g1_mulAccC(_pVk, IC1x, IC1y, calldataload(add(pubSignals, 0)))
149
+
150
+ g1_mulAccC(_pVk, IC2x, IC2y, calldataload(add(pubSignals, 32)))
151
+
152
+ g1_mulAccC(_pVk, IC3x, IC3y, calldataload(add(pubSignals, 64)))
153
+
154
+ g1_mulAccC(_pVk, IC4x, IC4y, calldataload(add(pubSignals, 96)))
155
+
156
+ g1_mulAccC(_pVk, IC5x, IC5y, calldataload(add(pubSignals, 128)))
157
+
158
+ g1_mulAccC(_pVk, IC6x, IC6y, calldataload(add(pubSignals, 160)))
159
+
160
+ g1_mulAccC(_pVk, IC7x, IC7y, calldataload(add(pubSignals, 192)))
161
+
162
+ g1_mulAccC(_pVk, IC8x, IC8y, calldataload(add(pubSignals, 224)))
163
+
164
+ g1_mulAccC(_pVk, IC9x, IC9y, calldataload(add(pubSignals, 256)))
165
+
166
+ g1_mulAccC(_pVk, IC10x, IC10y, calldataload(add(pubSignals, 288)))
167
+
168
+ g1_mulAccC(_pVk, IC11x, IC11y, calldataload(add(pubSignals, 320)))
169
+
170
+ g1_mulAccC(_pVk, IC12x, IC12y, calldataload(add(pubSignals, 352)))
171
+
172
+ g1_mulAccC(_pVk, IC13x, IC13y, calldataload(add(pubSignals, 384)))
173
+
174
+ g1_mulAccC(_pVk, IC14x, IC14y, calldataload(add(pubSignals, 416)))
175
+
176
+ g1_mulAccC(_pVk, IC15x, IC15y, calldataload(add(pubSignals, 448)))
177
+
178
+ g1_mulAccC(_pVk, IC16x, IC16y, calldataload(add(pubSignals, 480)))
179
+
180
+
181
+ // -A
182
+ mstore(_pPairing, calldataload(pA))
183
+ mstore(add(_pPairing, 32), mod(sub(q, calldataload(add(pA, 32))), q))
184
+
185
+ // B
186
+ mstore(add(_pPairing, 64), calldataload(pB))
187
+ mstore(add(_pPairing, 96), calldataload(add(pB, 32)))
188
+ mstore(add(_pPairing, 128), calldataload(add(pB, 64)))
189
+ mstore(add(_pPairing, 160), calldataload(add(pB, 96)))
190
+
191
+ // alpha1
192
+ mstore(add(_pPairing, 192), alphax)
193
+ mstore(add(_pPairing, 224), alphay)
194
+
195
+ // beta2
196
+ mstore(add(_pPairing, 256), betax1)
197
+ mstore(add(_pPairing, 288), betax2)
198
+ mstore(add(_pPairing, 320), betay1)
199
+ mstore(add(_pPairing, 352), betay2)
200
+
201
+ // vk_x
202
+ mstore(add(_pPairing, 384), mload(add(pMem, pVk)))
203
+ mstore(add(_pPairing, 416), mload(add(pMem, add(pVk, 32))))
204
+
205
+
206
+ // gamma2
207
+ mstore(add(_pPairing, 448), gammax1)
208
+ mstore(add(_pPairing, 480), gammax2)
209
+ mstore(add(_pPairing, 512), gammay1)
210
+ mstore(add(_pPairing, 544), gammay2)
211
+
212
+ // C
213
+ mstore(add(_pPairing, 576), calldataload(pC))
214
+ mstore(add(_pPairing, 608), calldataload(add(pC, 32)))
215
+
216
+ // delta2
217
+ mstore(add(_pPairing, 640), deltax1)
218
+ mstore(add(_pPairing, 672), deltax2)
219
+ mstore(add(_pPairing, 704), deltay1)
220
+ mstore(add(_pPairing, 736), deltay2)
221
+
222
+
223
+ let success := staticcall(sub(gas(), 2000), 8, _pPairing, 768, _pPairing, 0x20)
224
+
225
+ isOk := and(success, mload(_pPairing))
226
+ }
227
+
228
+ let pMem := mload(0x40)
229
+ mstore(0x40, add(pMem, pLastMem))
230
+
231
+ // Validate that all evaluations ∈ F
232
+
233
+ checkField(calldataload(add(_pubSignals, 0)))
234
+
235
+ checkField(calldataload(add(_pubSignals, 32)))
236
+
237
+ checkField(calldataload(add(_pubSignals, 64)))
238
+
239
+ checkField(calldataload(add(_pubSignals, 96)))
240
+
241
+ checkField(calldataload(add(_pubSignals, 128)))
242
+
243
+ checkField(calldataload(add(_pubSignals, 160)))
244
+
245
+ checkField(calldataload(add(_pubSignals, 192)))
246
+
247
+ checkField(calldataload(add(_pubSignals, 224)))
248
+
249
+ checkField(calldataload(add(_pubSignals, 256)))
250
+
251
+ checkField(calldataload(add(_pubSignals, 288)))
252
+
253
+ checkField(calldataload(add(_pubSignals, 320)))
254
+
255
+ checkField(calldataload(add(_pubSignals, 352)))
256
+
257
+ checkField(calldataload(add(_pubSignals, 384)))
258
+
259
+ checkField(calldataload(add(_pubSignals, 416)))
260
+
261
+ checkField(calldataload(add(_pubSignals, 448)))
262
+
263
+ checkField(calldataload(add(_pubSignals, 480)))
264
+
265
+ checkField(calldataload(add(_pubSignals, 512)))
266
+
267
+
268
+ // Validate all evaluations
269
+ let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem)
270
+
271
+ mstore(0, isValid)
272
+ return(0, 0x20)
273
+ }
274
+ }
275
+ }