secure-transac-contracts 1.0.0

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 (63) hide show
  1. package/build/contracts/AccessControl.json +4579 -0
  2. package/build/contracts/Context.json +356 -0
  3. package/build/contracts/CreditSystem.json +6037 -0
  4. package/build/contracts/ECDSA.json +4734 -0
  5. package/build/contracts/EIP712.json +3021 -0
  6. package/build/contracts/ERC165.json +352 -0
  7. package/build/contracts/ERC20.json +6816 -0
  8. package/build/contracts/ERC20Permit.json +2658 -0
  9. package/build/contracts/ERC721.json +12779 -0
  10. package/build/contracts/ERC721Utils.json +1058 -0
  11. package/build/contracts/Groth16Verifier.json +6298 -0
  12. package/build/contracts/Guardian.json +1116 -0
  13. package/build/contracts/IERC1155Errors.json +1687 -0
  14. package/build/contracts/IERC165.json +197 -0
  15. package/build/contracts/IERC20.json +1162 -0
  16. package/build/contracts/IERC20Errors.json +1662 -0
  17. package/build/contracts/IERC20Metadata.json +574 -0
  18. package/build/contracts/IERC20Permit.json +546 -0
  19. package/build/contracts/IERC5267.json +392 -0
  20. package/build/contracts/IERC721.json +1729 -0
  21. package/build/contracts/IERC721Errors.json +1694 -0
  22. package/build/contracts/IERC721Metadata.json +728 -0
  23. package/build/contracts/IERC721Receiver.json +296 -0
  24. package/build/contracts/IGuardian.json +215 -0
  25. package/build/contracts/ITrustRegistry.json +6767 -0
  26. package/build/contracts/IdentityVault.json +11584 -0
  27. package/build/contracts/Math.json +23115 -0
  28. package/build/contracts/MessageHashUtils.json +1668 -0
  29. package/build/contracts/Nonces.json +865 -0
  30. package/build/contracts/Ownable.json +1859 -0
  31. package/build/contracts/Panic.json +798 -0
  32. package/build/contracts/ReportingSystem.json +2787 -0
  33. package/build/contracts/SafeCast.json +21592 -0
  34. package/build/contracts/ScoringSystem.json +11245 -0
  35. package/build/contracts/SecureTransacSBT.json +18823 -0
  36. package/build/contracts/SecureTransacToken.json +19225 -0
  37. package/build/contracts/SecureVault.json +12890 -0
  38. package/build/contracts/ShortStrings.json +2852 -0
  39. package/build/contracts/SignedMath.json +1915 -0
  40. package/build/contracts/StorageSlot.json +1773 -0
  41. package/build/contracts/Strings.json +19001 -0
  42. package/build/contracts/TransactionLogger.json +5325 -0
  43. package/build/contracts/TrustDAO.json +23850 -0
  44. package/build/contracts/TrustRegistry.json +10948 -0
  45. package/build/contracts/VerificationRegistry.json +12811 -0
  46. package/build/contracts/ZKIdentityVerifier.json +13979 -0
  47. package/contracts/AccessControl.sol +34 -0
  48. package/contracts/CreditSystem.sol +48 -0
  49. package/contracts/Guardian.sol +33 -0
  50. package/contracts/IGuardian.sol +7 -0
  51. package/contracts/IdentityVault.sol +57 -0
  52. package/contracts/ReportingSystem.sol +14 -0
  53. package/contracts/ScoringSystem.sol +71 -0
  54. package/contracts/SecureTransacSBT.sol +72 -0
  55. package/contracts/SecureTransacToken.sol +20 -0
  56. package/contracts/SecureVault.sol +24 -0
  57. package/contracts/TransactionLogger.sol +12 -0
  58. package/contracts/TrustDAO.sol +158 -0
  59. package/contracts/TrustRegistry.sol +23 -0
  60. package/contracts/VerificationRegistry.sol +51 -0
  61. package/contracts/ZKIdentityVerifier.sol +38 -0
  62. package/contracts/ZKScoreVerifier.sol +175 -0
  63. package/package.json +32 -0
@@ -0,0 +1,175 @@
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 = 14632830399902886304199404318671907359765248140387609073440131662555804166596;
31
+ uint256 constant alphay = 1274055600882334744885589690016995899784990961580164915668784016916437087489;
32
+ uint256 constant betax1 = 5462291005412485052184432781735778656262572632531377043421324034501126612090;
33
+ uint256 constant betax2 = 14049718439394372710226074861629395251893924903072827309583266518186982466877;
34
+ uint256 constant betay1 = 6774567213246688234814017905922176954922820005613449554994203499031520104274;
35
+ uint256 constant betay2 = 10409450943583551857629587603529070735369070838912162950043701652160616296269;
36
+ uint256 constant gammax1 = 11559732032986387107991004021392285783925812861821192530917403151452391805634;
37
+ uint256 constant gammax2 = 10857046999023057135944570762232829481370756359578518086990519993285655852781;
38
+ uint256 constant gammay1 = 4082367875863433681332203403145435568316851327593401208105741076214120093531;
39
+ uint256 constant gammay2 = 8495653923123431417604973247489272438418190587263600148770280649306958101930;
40
+ uint256 constant deltax1 = 8902190764823417480167362269437807403007550957208210582556014071498950745100;
41
+ uint256 constant deltax2 = 17392927814280274128809405413462464933846479455614144160731542762506401056811;
42
+ uint256 constant deltay1 = 19750971702691361465026650158666149628389446047883118527861932543261742560474;
43
+ uint256 constant deltay2 = 11322084678453676013416237547752905035513460114497710370663950194895315197111;
44
+
45
+
46
+ uint256 constant IC0x = 17369393774834495845592729564895272134066802877109920494100547916128188425955;
47
+ uint256 constant IC0y = 19578224329101874886609464905325286051069167446532956151310890086704752793317;
48
+
49
+ uint256 constant IC1x = 14369734404272934763854163842219247647577069000213076472231873482928409613812;
50
+ uint256 constant IC1y = 142997981614115424567780043650670690918854474352127157489874052742402105637;
51
+
52
+ uint256 constant IC2x = 17827051454698757429131778274470966549911375167818384585615718762889832640068;
53
+ uint256 constant IC2y = 2102427399913946063300639589110840472656848920576583650639752822517776878250;
54
+
55
+
56
+ // Memory data
57
+ uint16 constant pVk = 0;
58
+ uint16 constant pPairing = 128;
59
+
60
+ uint16 constant pLastMem = 896;
61
+
62
+ function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[2] calldata _pubSignals) public view returns (bool) {
63
+ assembly {
64
+ function checkField(v) {
65
+ if iszero(lt(v, r)) {
66
+ mstore(0, 0)
67
+ return(0, 0x20)
68
+ }
69
+ }
70
+
71
+ // G1 function to multiply a G1 value(x,y) to value in an address
72
+ function g1_mulAccC(pR, x, y, s) {
73
+ let success
74
+ let mIn := mload(0x40)
75
+ mstore(mIn, x)
76
+ mstore(add(mIn, 32), y)
77
+ mstore(add(mIn, 64), s)
78
+
79
+ success := staticcall(sub(gas(), 2000), 7, mIn, 96, mIn, 64)
80
+
81
+ if iszero(success) {
82
+ mstore(0, 0)
83
+ return(0, 0x20)
84
+ }
85
+
86
+ mstore(add(mIn, 64), mload(pR))
87
+ mstore(add(mIn, 96), mload(add(pR, 32)))
88
+
89
+ success := staticcall(sub(gas(), 2000), 6, mIn, 128, pR, 64)
90
+
91
+ if iszero(success) {
92
+ mstore(0, 0)
93
+ return(0, 0x20)
94
+ }
95
+ }
96
+
97
+ function checkPairing(pA, pB, pC, pubSignals, pMem) -> isOk {
98
+ let _pPairing := add(pMem, pPairing)
99
+ let _pVk := add(pMem, pVk)
100
+
101
+ mstore(_pVk, IC0x)
102
+ mstore(add(_pVk, 32), IC0y)
103
+
104
+ // Compute the linear combination vk_x
105
+
106
+ g1_mulAccC(_pVk, IC1x, IC1y, calldataload(add(pubSignals, 0)))
107
+
108
+ g1_mulAccC(_pVk, IC2x, IC2y, calldataload(add(pubSignals, 32)))
109
+
110
+
111
+ // -A
112
+ mstore(_pPairing, calldataload(pA))
113
+ mstore(add(_pPairing, 32), mod(sub(q, calldataload(add(pA, 32))), q))
114
+
115
+ // B
116
+ mstore(add(_pPairing, 64), calldataload(pB))
117
+ mstore(add(_pPairing, 96), calldataload(add(pB, 32)))
118
+ mstore(add(_pPairing, 128), calldataload(add(pB, 64)))
119
+ mstore(add(_pPairing, 160), calldataload(add(pB, 96)))
120
+
121
+ // alpha1
122
+ mstore(add(_pPairing, 192), alphax)
123
+ mstore(add(_pPairing, 224), alphay)
124
+
125
+ // beta2
126
+ mstore(add(_pPairing, 256), betax1)
127
+ mstore(add(_pPairing, 288), betax2)
128
+ mstore(add(_pPairing, 320), betay1)
129
+ mstore(add(_pPairing, 352), betay2)
130
+
131
+ // vk_x
132
+ mstore(add(_pPairing, 384), mload(add(pMem, pVk)))
133
+ mstore(add(_pPairing, 416), mload(add(pMem, add(pVk, 32))))
134
+
135
+
136
+ // gamma2
137
+ mstore(add(_pPairing, 448), gammax1)
138
+ mstore(add(_pPairing, 480), gammax2)
139
+ mstore(add(_pPairing, 512), gammay1)
140
+ mstore(add(_pPairing, 544), gammay2)
141
+
142
+ // C
143
+ mstore(add(_pPairing, 576), calldataload(pC))
144
+ mstore(add(_pPairing, 608), calldataload(add(pC, 32)))
145
+
146
+ // delta2
147
+ mstore(add(_pPairing, 640), deltax1)
148
+ mstore(add(_pPairing, 672), deltax2)
149
+ mstore(add(_pPairing, 704), deltay1)
150
+ mstore(add(_pPairing, 736), deltay2)
151
+
152
+
153
+ let success := staticcall(sub(gas(), 2000), 8, _pPairing, 768, _pPairing, 0x20)
154
+
155
+ isOk := and(success, mload(_pPairing))
156
+ }
157
+
158
+ let pMem := mload(0x40)
159
+ mstore(0x40, add(pMem, pLastMem))
160
+
161
+ // Validate that all evaluations ∈ F
162
+
163
+ checkField(calldataload(add(_pubSignals, 0)))
164
+
165
+ checkField(calldataload(add(_pubSignals, 32)))
166
+
167
+
168
+ // Validate all evaluations
169
+ let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem)
170
+
171
+ mstore(0, isValid)
172
+ return(0, 0x20)
173
+ }
174
+ }
175
+ }
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "secure-transac-contracts",
3
+ "version": "1.0.0",
4
+ "description": "Secure Transaction Contracts",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "truffle test",
8
+ "dev:ganache": "ganache -p 7545 --chain.chainId 1337 --chain.networkId 1337 --db ./ganache_db --mnemonic \"test test test test test test test test test test test junk\"",
9
+ "dev:reset": "rm -Recurse -Force ./ganache_db ; truffle migrate --reset --network development",
10
+ "dev:deploy": "truffle migrate --network development",
11
+ "seed": "truffle exec scripts/seed.js --network development"
12
+ },
13
+ "keywords": [
14
+ "secure",
15
+ "transaction",
16
+ "contracts"
17
+ ],
18
+ "author": "AyushDocs",
19
+ "license": "ISC",
20
+ "dependencies": {
21
+ "@openzeppelin/contracts": "^5.4.0",
22
+ "@truffle/hdwallet-provider": "^2.1.15",
23
+ "dotenv": "^17.2.3"
24
+ },
25
+ "files": [
26
+ "contracts/**/*.sol",
27
+ "build/contracts/*.json"
28
+ ],
29
+ "devDependencies": {
30
+ "@openzeppelin/test-helpers": "^0.5.16"
31
+ }
32
+ }