@lfdecentralizedtrust/zeto-contracts 0.2.2 → 0.5.1

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 (164) hide show
  1. package/README.md +76 -162
  2. package/config/eip170.ts +30 -0
  3. package/contracts/factory.sol +30 -34
  4. package/contracts/factory_upgradeable.sol +11 -7
  5. package/contracts/lib/common/util.sol +40 -0
  6. package/contracts/lib/interfaces/ILockableCapability.sol +318 -0
  7. package/contracts/lib/interfaces/{izeto.sol → IZeto.sol} +13 -1
  8. package/contracts/lib/interfaces/{izeto_initializable.sol → IZetoInitializable.sol} +14 -12
  9. package/contracts/lib/interfaces/{izeto_kyc.sol → IZetoKyc.sol} +3 -3
  10. package/contracts/lib/interfaces/IZetoLockHooks.sol +42 -0
  11. package/contracts/lib/interfaces/IZetoLockableCapability.sol +237 -0
  12. package/contracts/lib/interfaces/IZetoStorage.sol +106 -0
  13. package/contracts/lib/interfaces/{izeto_lockable.sol → IZetoVerifier.sol} +8 -21
  14. package/contracts/lib/registry.sol +74 -26
  15. package/contracts/lib/storage/base.sol +210 -0
  16. package/contracts/lib/storage/nullifier.sol +166 -0
  17. package/contracts/lib/zeto_common.sol +277 -28
  18. package/contracts/lib/zeto_fungible.sol +443 -33
  19. package/contracts/lib/zeto_fungible_base.sol +69 -0
  20. package/contracts/lib/zeto_fungible_burn.sol +83 -53
  21. package/contracts/lib/zeto_fungible_burn_nullifier.sol +115 -72
  22. package/contracts/lib/zeto_fungible_nullifier.sol +167 -0
  23. package/contracts/lib/zeto_lockable.sol +219 -0
  24. package/contracts/lib/zeto_lockable_lib.sol +460 -0
  25. package/contracts/lib/zeto_lockable_storage.sol +43 -0
  26. package/contracts/lib/zeto_non_fungible.sol +228 -0
  27. package/contracts/lib/zeto_non_fungible_base.sol +61 -0
  28. package/contracts/lib/zeto_non_fungible_nullifier.sol +61 -0
  29. package/contracts/test/escrow1.sol +90 -34
  30. package/contracts/test/escrow2.sol +64 -29
  31. package/contracts/test/qurrency.sol +10 -2
  32. package/contracts/test/smt.sol +6 -1
  33. package/contracts/test/tendecimals.sol +14 -12
  34. package/contracts/verifiers/impl/anon.sol +189 -0
  35. package/contracts/verifiers/impl/anon_batch.sol +301 -0
  36. package/contracts/verifiers/impl/anon_enc.sol +266 -0
  37. package/contracts/verifiers/impl/anon_enc_batch.sol +602 -0
  38. package/contracts/verifiers/impl/anon_enc_nullifier.sol +287 -0
  39. package/contracts/verifiers/impl/anon_enc_nullifier_batch.sol +679 -0
  40. package/contracts/verifiers/impl/anon_enc_nullifier_kyc.sol +294 -0
  41. package/contracts/verifiers/impl/anon_enc_nullifier_kyc_batch.sol +686 -0
  42. package/contracts/verifiers/impl/anon_enc_nullifier_non_repudiation.sol +413 -0
  43. package/contracts/verifiers/impl/anon_enc_nullifier_non_repudiation_batch.sol +1141 -0
  44. package/contracts/verifiers/impl/anon_nullifier_kyc_transfer.sol +217 -0
  45. package/contracts/verifiers/impl/anon_nullifier_kyc_transferLocked.sol +196 -0
  46. package/contracts/verifiers/impl/anon_nullifier_kyc_transferLocked_batch.sol +308 -0
  47. package/contracts/verifiers/impl/anon_nullifier_kyc_transfer_batch.sol +385 -0
  48. package/contracts/verifiers/impl/anon_nullifier_qurrency_transfer.sol +497 -0
  49. package/contracts/verifiers/impl/anon_nullifier_qurrency_transfer_batch.sol +1001 -0
  50. package/contracts/verifiers/{verifier_anon_nullifier_transferLocked.sol → impl/anon_nullifier_transfer.sol} +12 -19
  51. package/contracts/verifiers/{verifier_anon_nullifier_transferLocked_batch.sol → impl/anon_nullifier_transfer_batch.sol} +44 -51
  52. package/contracts/verifiers/impl/burn.sol +182 -0
  53. package/contracts/verifiers/impl/burn_batch.sol +238 -0
  54. package/contracts/verifiers/impl/burn_nullifier.sol +203 -0
  55. package/contracts/verifiers/impl/burn_nullifier_batch.sol +315 -0
  56. package/contracts/verifiers/impl/deposit.sol +182 -0
  57. package/contracts/verifiers/impl/deposit_kyc.sol +189 -0
  58. package/contracts/verifiers/impl/nf_anon.sol +175 -0
  59. package/contracts/verifiers/{verifier_nf_anon_nullifier_transferLocked.sol → impl/nf_anon_nullifier_transfer.sol} +6 -13
  60. package/contracts/verifiers/impl/withdraw.sol +189 -0
  61. package/contracts/verifiers/impl/withdraw_batch.sol +245 -0
  62. package/contracts/verifiers/impl/withdraw_nullifier.sol +210 -0
  63. package/contracts/verifiers/impl/withdraw_nullifier_batch.sol +322 -0
  64. package/contracts/verifiers/verifier_anon.sol +31 -186
  65. package/contracts/verifiers/verifier_anon_batch.sol +31 -298
  66. package/contracts/verifiers/verifier_anon_enc.sol +31 -263
  67. package/contracts/verifiers/verifier_anon_enc_batch.sol +31 -599
  68. package/contracts/verifiers/verifier_anon_enc_nullifier.sol +31 -284
  69. package/contracts/verifiers/verifier_anon_enc_nullifier_batch.sol +33 -676
  70. package/contracts/verifiers/verifier_anon_enc_nullifier_kyc.sol +31 -291
  71. package/contracts/verifiers/verifier_anon_enc_nullifier_kyc_batch.sol +33 -683
  72. package/contracts/verifiers/verifier_anon_enc_nullifier_non_repudiation.sol +33 -410
  73. package/contracts/verifiers/verifier_anon_enc_nullifier_non_repudiation_batch.sol +33 -1138
  74. package/contracts/verifiers/verifier_anon_nullifier_kyc_transfer.sol +33 -214
  75. package/contracts/verifiers/verifier_anon_nullifier_kyc_transferLocked.sol +33 -221
  76. package/contracts/verifiers/verifier_anon_nullifier_kyc_transferLocked_batch.sol +33 -389
  77. package/contracts/verifiers/verifier_anon_nullifier_kyc_transfer_batch.sol +33 -382
  78. package/contracts/verifiers/verifier_anon_nullifier_qurrency_transfer.sol +33 -221
  79. package/contracts/verifiers/verifier_anon_nullifier_qurrency_transfer_batch.sol +33 -389
  80. package/contracts/verifiers/verifier_anon_nullifier_transfer.sol +33 -207
  81. package/contracts/verifiers/verifier_anon_nullifier_transfer_batch.sol +33 -375
  82. package/contracts/verifiers/verifier_burn.sol +31 -179
  83. package/contracts/verifiers/verifier_burn_batch.sol +31 -235
  84. package/contracts/verifiers/verifier_burn_nullifier.sol +31 -200
  85. package/contracts/verifiers/verifier_burn_nullifier_batch.sol +31 -312
  86. package/contracts/verifiers/verifier_deposit.sol +31 -179
  87. package/contracts/verifiers/verifier_deposit_kyc.sol +34 -0
  88. package/contracts/verifiers/verifier_nf_anon.sol +31 -172
  89. package/contracts/verifiers/verifier_nf_anon_nullifier_transfer.sol +33 -179
  90. package/contracts/verifiers/verifier_withdraw.sol +31 -186
  91. package/contracts/verifiers/verifier_withdraw_batch.sol +31 -242
  92. package/contracts/verifiers/verifier_withdraw_nullifier.sol +31 -207
  93. package/contracts/verifiers/verifier_withdraw_nullifier_batch.sol +33 -319
  94. package/contracts/zeto_anon.sol +77 -231
  95. package/contracts/zeto_anon_burnable.sol +56 -12
  96. package/contracts/zeto_anon_enc.sol +93 -190
  97. package/contracts/zeto_anon_enc_nullifier.sol +249 -195
  98. package/contracts/zeto_anon_enc_nullifier_kyc.sol +51 -232
  99. package/contracts/zeto_anon_enc_nullifier_non_repudiation.sol +231 -238
  100. package/contracts/zeto_anon_nullifier.sol +164 -298
  101. package/contracts/zeto_anon_nullifier_burnable.sol +68 -18
  102. package/contracts/zeto_anon_nullifier_kyc.sol +40 -345
  103. package/contracts/zeto_anon_nullifier_qurrency.sol +217 -361
  104. package/contracts/zeto_nf_anon.sol +55 -130
  105. package/contracts/zeto_nf_anon_nullifier.sol +90 -152
  106. package/hardhat.config.ts +18 -3
  107. package/ignition/modules/lib/deps.ts +13 -0
  108. package/ignition/modules/test/tendecimals.ts +7 -1
  109. package/ignition/modules/zeto_anon.ts +3 -0
  110. package/ignition/modules/zeto_anon_burnable.ts +11 -7
  111. package/ignition/modules/zeto_anon_enc.ts +3 -0
  112. package/ignition/modules/zeto_anon_enc_nullifier.ts +34 -0
  113. package/ignition/modules/zeto_anon_enc_nullifier_kyc.ts +5 -2
  114. package/ignition/modules/zeto_anon_enc_nullifier_non_repudiation.ts +3 -0
  115. package/ignition/modules/zeto_anon_nullifier.ts +31 -4
  116. package/ignition/modules/zeto_anon_nullifier_burnable.ts +53 -16
  117. package/ignition/modules/zeto_anon_nullifier_kyc.ts +30 -12
  118. package/ignition/modules/zeto_anon_nullifier_qurrency.ts +3 -0
  119. package/ignition/modules/zeto_nf_anon.ts +3 -1
  120. package/ignition/modules/zeto_nf_anon_nullifier.ts +17 -12
  121. package/package.json +7 -3
  122. package/scripts/deploy_cloneable.ts +19 -10
  123. package/scripts/deploy_upgradeable.ts +9 -5
  124. package/scripts/lib/zeto_libraries.ts +47 -0
  125. package/scripts/tokens/Zeto_Anon.ts +6 -3
  126. package/scripts/tokens/Zeto_AnonBurnable.ts +4 -1
  127. package/scripts/tokens/Zeto_AnonEnc.ts +15 -3
  128. package/scripts/tokens/Zeto_AnonEncNullifier.ts +11 -8
  129. package/scripts/tokens/Zeto_AnonEncNullifierKyc.ts +7 -6
  130. package/scripts/tokens/Zeto_AnonEncNullifierNonRepudiation.ts +7 -6
  131. package/scripts/tokens/Zeto_AnonNullifier.ts +7 -6
  132. package/scripts/tokens/Zeto_AnonNullifierBurnable.ts +7 -6
  133. package/scripts/tokens/Zeto_AnonNullifierKyc.ts +7 -6
  134. package/scripts/tokens/Zeto_AnonNullifierQurrency.ts +7 -8
  135. package/scripts/tokens/Zeto_NfAnon.ts +5 -3
  136. package/scripts/tokens/Zeto_NfAnonNullifier.ts +7 -7
  137. package/test/factory.ts +55 -73
  138. package/test/lib/anon_nullifier_helpers.ts +89 -0
  139. package/test/lib/anon_zeto_helpers.ts +76 -0
  140. package/test/lib/deploy.ts +5 -2
  141. package/test/lib/eip170.ts +23 -0
  142. package/test/lib/utils.ts +74 -35
  143. package/test/test/escrow1.ts +185 -58
  144. package/test/test/escrow2.ts +200 -107
  145. package/test/test/qurrency.ts +13 -33
  146. package/test/usdc-shielding.ts +39 -27
  147. package/test/utils.ts +144 -21
  148. package/test/zeto_anon.ts +956 -465
  149. package/test/zeto_anon_enc.ts +881 -143
  150. package/test/zeto_anon_enc_nullifier.ts +850 -39
  151. package/test/zeto_anon_enc_nullifier_kyc.ts +123 -182
  152. package/test/zeto_anon_enc_nullifier_non_repudiation.ts +80 -47
  153. package/test/zeto_anon_nullifier.ts +1212 -954
  154. package/test/zeto_anon_nullifier_kyc.ts +677 -656
  155. package/test/zeto_anon_nullifier_qurrency.ts +455 -307
  156. package/test/zeto_nf_anon.ts +737 -138
  157. package/test/zeto_nf_anon_nullifier.ts +876 -247
  158. package/contracts/lib/zeto_base.sol +0 -293
  159. package/contracts/lib/zeto_fungible_withdraw.sol +0 -132
  160. package/contracts/lib/zeto_fungible_withdraw_nullifier.sol +0 -144
  161. package/contracts/lib/zeto_nullifier.sol +0 -340
  162. package/contracts/zkDvP.sol_ +0 -273
  163. package/test/zkDvP.ts_ +0 -455
  164. /package/contracts/lib/{common.sol → common/common.sol} +0 -0
@@ -16,6 +16,7 @@
16
16
 
17
17
  import { ethers, ignition } from "hardhat";
18
18
  import zetoModule from "../../ignition/modules/zeto_anon";
19
+ import { withZetoLockableLib } from "../lib/zeto_libraries";
19
20
 
20
21
  export async function deployDependencies() {
21
22
  const [deployer] = await ethers.getSigners();
@@ -26,9 +27,11 @@ export async function deployDependencies() {
26
27
  verifier,
27
28
  batchVerifier,
28
29
  batchWithdrawVerifier,
30
+ zetoLockableLib,
29
31
  } = await ignition.deploy(zetoModule);
30
32
  return {
31
33
  deployer,
34
+ libraries: withZetoLockableLib(zetoLockableLib),
32
35
  args: [
33
36
  "Zeto Anon",
34
37
  "ZA",
@@ -39,11 +42,11 @@ export async function deployDependencies() {
39
42
  withdrawVerifier: withdrawVerifier.target,
40
43
  batchVerifier: batchVerifier.target,
41
44
  batchWithdrawVerifier: batchWithdrawVerifier.target,
42
- lockVerifier: "0x0000000000000000000000000000000000000000",
43
- batchLockVerifier: "0x0000000000000000000000000000000000000000",
45
+ lockVerifier: verifier.target, // for this token, the lock verifier is the same as the regular verifier
46
+ batchLockVerifier: batchVerifier.target,
44
47
  burnVerifier: "0x0000000000000000000000000000000000000000",
45
48
  batchBurnVerifier: "0x0000000000000000000000000000000000000000",
46
- }
49
+ },
47
50
  ],
48
51
  };
49
52
  }
@@ -16,6 +16,7 @@
16
16
 
17
17
  import { ethers, ignition } from "hardhat";
18
18
  import zetoModule from "../../ignition/modules/zeto_anon_burnable";
19
+ import { withZetoLockableLib } from "../lib/zeto_libraries";
19
20
 
20
21
  export async function deployDependencies() {
21
22
  const [deployer] = await ethers.getSigners();
@@ -28,9 +29,11 @@ export async function deployDependencies() {
28
29
  batchVerifier,
29
30
  batchWithdrawVerifier,
30
31
  batchBurnVerifier,
32
+ zetoLockableLib,
31
33
  } = await ignition.deploy(zetoModule);
32
34
  return {
33
35
  deployer,
36
+ libraries: withZetoLockableLib(zetoLockableLib),
34
37
  args: [
35
38
  "Zeto Anon Burnable",
36
39
  "ZAB",
@@ -45,7 +48,7 @@ export async function deployDependencies() {
45
48
  batchBurnVerifier: batchBurnVerifier.target,
46
49
  lockVerifier: "0x0000000000000000000000000000000000000000",
47
50
  batchLockVerifier: "0x0000000000000000000000000000000000000000",
48
- }
51
+ },
49
52
  ],
50
53
  };
51
54
  }
@@ -16,6 +16,7 @@
16
16
 
17
17
  import { ethers, ignition } from "hardhat";
18
18
  import zetoModule from "../../ignition/modules/zeto_anon_enc";
19
+ import { withZetoLockableLib } from "../lib/zeto_libraries";
19
20
 
20
21
  export async function deployDependencies() {
21
22
  const [deployer] = await ethers.getSigners();
@@ -26,9 +27,11 @@ export async function deployDependencies() {
26
27
  verifier,
27
28
  batchVerifier,
28
29
  batchWithdrawVerifier,
30
+ zetoLockableLib,
29
31
  } = await ignition.deploy(zetoModule);
30
32
  return {
31
33
  deployer,
34
+ libraries: withZetoLockableLib(zetoLockableLib),
32
35
  args: [
33
36
  "Zeto Anon Enc",
34
37
  "ZAE",
@@ -39,11 +42,20 @@ export async function deployDependencies() {
39
42
  withdrawVerifier: withdrawVerifier.target,
40
43
  batchVerifier: batchVerifier.target,
41
44
  batchWithdrawVerifier: batchWithdrawVerifier.target,
42
- lockVerifier: "0x0000000000000000000000000000000000000000",
43
- batchLockVerifier: "0x0000000000000000000000000000000000000000",
45
+ // Same rationale as `Zeto_Anon`: the encryption-aware
46
+ // {Zeto_AnonEnc.constructPublicInputs} ignores `inputsLocked`
47
+ // and emits an identical public-input layout (ecdhPublicKey ++
48
+ // encryptedValues ++ inputs ++ outputs ++ encryptionNonce) for
49
+ // both the regular `transfer` flow and the locked-input flow
50
+ // driven by `spendLock`/`cancelLock`. We therefore wire the
51
+ // lockVerifier slots to the same Groth16 verifier as the
52
+ // unlocked path so {ZetoCommon.verifyProof} routes locked-input
53
+ // proofs to the encryption circuit's verifier.
54
+ lockVerifier: verifier.target,
55
+ batchLockVerifier: batchVerifier.target,
44
56
  burnVerifier: "0x0000000000000000000000000000000000000000",
45
57
  batchBurnVerifier: "0x0000000000000000000000000000000000000000",
46
- }
58
+ },
47
59
  ],
48
60
  };
49
61
  }
@@ -16,6 +16,7 @@
16
16
 
17
17
  import { ethers, ignition } from "hardhat";
18
18
  import zetoModule from "../../ignition/modules/zeto_anon_enc_nullifier";
19
+ import { withZetoLockableLib, smtLibraries } from "../lib/zeto_libraries";
19
20
 
20
21
  export async function deployDependencies() {
21
22
  const [deployer] = await ethers.getSigners();
@@ -24,11 +25,14 @@ export async function deployDependencies() {
24
25
  depositVerifier,
25
26
  withdrawVerifier,
26
27
  verifier,
28
+ lockVerifier,
27
29
  batchVerifier,
30
+ batchLockVerifier,
28
31
  batchWithdrawVerifier,
29
32
  smtLib,
30
33
  poseidon2,
31
34
  poseidon3,
35
+ zetoLockableLib,
32
36
  } = await ignition.deploy(zetoModule);
33
37
  return {
34
38
  deployer,
@@ -42,16 +46,15 @@ export async function deployDependencies() {
42
46
  withdrawVerifier: withdrawVerifier.target,
43
47
  batchVerifier: batchVerifier.target,
44
48
  batchWithdrawVerifier: batchWithdrawVerifier.target,
45
- lockVerifier: "0x0000000000000000000000000000000000000000",
46
- batchLockVerifier: "0x0000000000000000000000000000000000000000",
49
+ lockVerifier: lockVerifier.target,
50
+ batchLockVerifier: batchLockVerifier.target,
47
51
  burnVerifier: "0x0000000000000000000000000000000000000000",
48
52
  batchBurnVerifier: "0x0000000000000000000000000000000000000000",
49
- }
53
+ },
50
54
  ],
51
- libraries: {
52
- SmtLib: smtLib.target,
53
- PoseidonUnit2L: poseidon2.target,
54
- PoseidonUnit3L: poseidon3.target,
55
- },
55
+ libraries: withZetoLockableLib(
56
+ zetoLockableLib,
57
+ smtLibraries({ smtLib, poseidon2, poseidon3 }),
58
+ ),
56
59
  };
57
60
  }
@@ -16,6 +16,7 @@
16
16
 
17
17
  import { ethers, ignition } from "hardhat";
18
18
  import zetoModule from "../../ignition/modules/zeto_anon_enc_nullifier_kyc";
19
+ import { withZetoLockableLib, smtLibraries } from "../lib/zeto_libraries";
19
20
 
20
21
  export async function deployDependencies() {
21
22
  const [deployer] = await ethers.getSigners();
@@ -29,6 +30,7 @@ export async function deployDependencies() {
29
30
  smtLib,
30
31
  poseidon2,
31
32
  poseidon3,
33
+ zetoLockableLib,
32
34
  } = await ignition.deploy(zetoModule);
33
35
  return {
34
36
  deployer,
@@ -46,12 +48,11 @@ export async function deployDependencies() {
46
48
  batchLockVerifier: "0x0000000000000000000000000000000000000000",
47
49
  burnVerifier: "0x0000000000000000000000000000000000000000",
48
50
  batchBurnVerifier: "0x0000000000000000000000000000000000000000",
49
- }
51
+ },
50
52
  ],
51
- libraries: {
52
- SmtLib: smtLib.target,
53
- PoseidonUnit2L: poseidon2.target,
54
- PoseidonUnit3L: poseidon3.target,
55
- },
53
+ libraries: withZetoLockableLib(
54
+ zetoLockableLib,
55
+ smtLibraries({ smtLib, poseidon2, poseidon3 }),
56
+ ),
56
57
  };
57
58
  }
@@ -16,6 +16,7 @@
16
16
 
17
17
  import { ethers, ignition } from "hardhat";
18
18
  import zetoModule from "../../ignition/modules/zeto_anon_enc_nullifier_non_repudiation";
19
+ import { withZetoLockableLib, smtLibraries } from "../lib/zeto_libraries";
19
20
 
20
21
  export async function deployDependencies() {
21
22
  const [deployer] = await ethers.getSigners();
@@ -29,6 +30,7 @@ export async function deployDependencies() {
29
30
  smtLib,
30
31
  poseidon2,
31
32
  poseidon3,
33
+ zetoLockableLib,
32
34
  } = await ignition.deploy(zetoModule);
33
35
  return {
34
36
  deployer,
@@ -46,12 +48,11 @@ export async function deployDependencies() {
46
48
  batchLockVerifier: "0x0000000000000000000000000000000000000000",
47
49
  burnVerifier: "0x0000000000000000000000000000000000000000",
48
50
  batchBurnVerifier: "0x0000000000000000000000000000000000000000",
49
- }
51
+ },
50
52
  ],
51
- libraries: {
52
- SmtLib: smtLib.target,
53
- PoseidonUnit2L: poseidon2.target,
54
- PoseidonUnit3L: poseidon3.target,
55
- },
53
+ libraries: withZetoLockableLib(
54
+ zetoLockableLib,
55
+ smtLibraries({ smtLib, poseidon2, poseidon3 }),
56
+ ),
56
57
  };
57
58
  }
@@ -16,6 +16,7 @@
16
16
 
17
17
  import { ethers, ignition } from "hardhat";
18
18
  import zetoModule from "../../ignition/modules/zeto_anon_nullifier";
19
+ import { withZetoLockableLib, smtLibraries } from "../lib/zeto_libraries";
19
20
 
20
21
  export async function deployDependencies() {
21
22
  const [deployer] = await ethers.getSigners();
@@ -31,6 +32,7 @@ export async function deployDependencies() {
31
32
  smtLib,
32
33
  poseidon2,
33
34
  poseidon3,
35
+ zetoLockableLib,
34
36
  } = await ignition.deploy(zetoModule);
35
37
  return {
36
38
  deployer,
@@ -48,12 +50,11 @@ export async function deployDependencies() {
48
50
  batchLockVerifier: batchLockVerifier.target,
49
51
  burnVerifier: "0x0000000000000000000000000000000000000000",
50
52
  batchBurnVerifier: "0x0000000000000000000000000000000000000000",
51
- }
53
+ },
52
54
  ],
53
- libraries: {
54
- SmtLib: smtLib.target,
55
- PoseidonUnit2L: poseidon2.target,
56
- PoseidonUnit3L: poseidon3.target,
57
- },
55
+ libraries: withZetoLockableLib(
56
+ zetoLockableLib,
57
+ smtLibraries({ smtLib, poseidon2, poseidon3 }),
58
+ ),
58
59
  };
59
60
  }
@@ -16,6 +16,7 @@
16
16
 
17
17
  import { ethers, ignition } from "hardhat";
18
18
  import zetoModule from "../../ignition/modules/zeto_anon_nullifier_burnable";
19
+ import { withZetoLockableLib, smtLibraries } from "../lib/zeto_libraries";
19
20
 
20
21
  export async function deployDependencies() {
21
22
  const [deployer] = await ethers.getSigners();
@@ -33,6 +34,7 @@ export async function deployDependencies() {
33
34
  smtLib,
34
35
  poseidon2,
35
36
  poseidon3,
37
+ zetoLockableLib,
36
38
  } = await ignition.deploy(zetoModule);
37
39
  return {
38
40
  deployer,
@@ -50,12 +52,11 @@ export async function deployDependencies() {
50
52
  batchLockVerifier: batchLockVerifier.target,
51
53
  burnVerifier: burnVerifier.target,
52
54
  batchBurnVerifier: batchBurnVerifier.target,
53
- }
55
+ },
54
56
  ],
55
- libraries: {
56
- SmtLib: smtLib.target,
57
- PoseidonUnit2L: poseidon2.target,
58
- PoseidonUnit3L: poseidon3.target,
59
- },
57
+ libraries: withZetoLockableLib(
58
+ zetoLockableLib,
59
+ smtLibraries({ smtLib, poseidon2, poseidon3 }),
60
+ ),
60
61
  };
61
62
  }
@@ -16,6 +16,7 @@
16
16
 
17
17
  import { ethers, ignition } from "hardhat";
18
18
  import zetoModule from "../../ignition/modules/zeto_anon_nullifier_kyc";
19
+ import { withZetoLockableLib, smtLibraries } from "../lib/zeto_libraries";
19
20
 
20
21
  export async function deployDependencies() {
21
22
  const [deployer] = await ethers.getSigners();
@@ -31,6 +32,7 @@ export async function deployDependencies() {
31
32
  smtLib,
32
33
  poseidon2,
33
34
  poseidon3,
35
+ zetoLockableLib,
34
36
  } = await ignition.deploy(zetoModule);
35
37
  return {
36
38
  deployer,
@@ -48,12 +50,11 @@ export async function deployDependencies() {
48
50
  batchLockVerifier: batchLockVerifier.target,
49
51
  burnVerifier: "0x0000000000000000000000000000000000000000",
50
52
  batchBurnVerifier: "0x0000000000000000000000000000000000000000",
51
- }
53
+ },
52
54
  ],
53
- libraries: {
54
- SmtLib: smtLib.target,
55
- PoseidonUnit2L: poseidon2.target,
56
- PoseidonUnit3L: poseidon3.target,
57
- },
55
+ libraries: withZetoLockableLib(
56
+ zetoLockableLib,
57
+ smtLibraries({ smtLib, poseidon2, poseidon3 }),
58
+ ),
58
59
  };
59
60
  }
@@ -16,6 +16,7 @@
16
16
 
17
17
  import { ethers, ignition } from "hardhat";
18
18
  import zetoModule from "../../ignition/modules/zeto_anon_nullifier_qurrency";
19
+ import { withZetoLockableLib, smtLibraries } from "../lib/zeto_libraries";
19
20
 
20
21
  export async function deployDependencies() {
21
22
  const [deployer] = await ethers.getSigners();
@@ -33,6 +34,7 @@ export async function deployDependencies() {
33
34
  poseidon3,
34
35
  poseidon5,
35
36
  poseidon6,
37
+ zetoLockableLib,
36
38
  } = await ignition.deploy(zetoModule);
37
39
  return {
38
40
  deployer,
@@ -50,14 +52,11 @@ export async function deployDependencies() {
50
52
  batchLockVerifier: "0x0000000000000000000000000000000000000000", //batchLockVerifier.target,
51
53
  burnVerifier: "0x0000000000000000000000000000000000000000",
52
54
  batchBurnVerifier: "0x0000000000000000000000000000000000000000",
53
- }
55
+ },
54
56
  ],
55
- libraries: {
56
- SmtLib: smtLib.target,
57
- PoseidonUnit2L: poseidon2.target,
58
- PoseidonUnit3L: poseidon3.target,
59
- PoseidonUnit5L: poseidon5.target,
60
- PoseidonUnit6L: poseidon6.target,
61
- },
57
+ libraries: withZetoLockableLib(
58
+ zetoLockableLib,
59
+ smtLibraries({ smtLib, poseidon2, poseidon3, poseidon5, poseidon6 }),
60
+ ),
62
61
  };
63
62
  }
@@ -16,13 +16,15 @@
16
16
 
17
17
  import { ethers, ignition } from "hardhat";
18
18
  import zetoModule from "../../ignition/modules/zeto_nf_anon";
19
+ import { withZetoLockableLib } from "../lib/zeto_libraries";
19
20
 
20
21
  export async function deployDependencies() {
21
22
  const [deployer] = await ethers.getSigners();
22
23
 
23
- const { verifier } = await ignition.deploy(zetoModule);
24
+ const { verifier, zetoLockableLib } = await ignition.deploy(zetoModule);
24
25
  return {
25
26
  deployer,
27
+ libraries: withZetoLockableLib(zetoLockableLib),
26
28
  args: [
27
29
  "Zeto NF Anon",
28
30
  "ZNFA",
@@ -33,11 +35,11 @@ export async function deployDependencies() {
33
35
  withdrawVerifier: "0x0000000000000000000000000000000000000000",
34
36
  batchVerifier: "0x0000000000000000000000000000000000000000",
35
37
  batchWithdrawVerifier: "0x0000000000000000000000000000000000000000",
36
- lockVerifier: "0x0000000000000000000000000000000000000000",
38
+ lockVerifier: verifier.target, // for this token, the lock verifier is the same as the regular verifier
37
39
  batchLockVerifier: "0x0000000000000000000000000000000000000000",
38
40
  burnVerifier: "0x0000000000000000000000000000000000000000",
39
41
  batchBurnVerifier: "0x0000000000000000000000000000000000000000",
40
- }
42
+ },
41
43
  ],
42
44
  };
43
45
  }
@@ -16,11 +16,12 @@
16
16
 
17
17
  import { ethers, ignition } from "hardhat";
18
18
  import zetoModule from "../../ignition/modules/zeto_nf_anon_nullifier";
19
+ import { withZetoLockableLib, smtLibraries } from "../lib/zeto_libraries";
19
20
 
20
21
  export async function deployDependencies() {
21
22
  const [deployer] = await ethers.getSigners();
22
23
 
23
- const { verifier, lockVerifier, smtLib, poseidon2, poseidon3 } =
24
+ const { verifier, lockVerifier, smtLib, poseidon2, poseidon3, zetoLockableLib } =
24
25
  await ignition.deploy(zetoModule);
25
26
  return {
26
27
  deployer,
@@ -38,12 +39,11 @@ export async function deployDependencies() {
38
39
  batchLockVerifier: "0x0000000000000000000000000000000000000000",
39
40
  burnVerifier: "0x0000000000000000000000000000000000000000",
40
41
  batchBurnVerifier: "0x0000000000000000000000000000000000000000",
41
- }
42
+ },
42
43
  ],
43
- libraries: {
44
- SmtLib: smtLib.target,
45
- PoseidonUnit2L: poseidon2.target,
46
- PoseidonUnit3L: poseidon3.target,
47
- },
44
+ libraries: withZetoLockableLib(
45
+ zetoLockableLib,
46
+ smtLibraries({ smtLib, poseidon2, poseidon3 }),
47
+ ),
48
48
  };
49
49
  }
package/test/factory.ts CHANGED
@@ -17,6 +17,8 @@
17
17
  import { ethers, network } from "hardhat";
18
18
  import { Signer } from "ethers";
19
19
  import { expect } from "chai";
20
+ import { getLinkedContractFactory } from "../scripts/lib/common";
21
+ import { withZetoLockableLib } from "../scripts/lib/zeto_libraries";
20
22
 
21
23
  describe("(factory) Zeto based fungible token with anonymity without encryption or nullifier", function () {
22
24
  let deployer: Signer;
@@ -47,7 +49,7 @@ describe("(factory) Zeto based fungible token with anonymity without encryption
47
49
  batchLockVerifier: "0xae92d5aD7583AD66E49A0c67BAd18F6ba52dDDc1",
48
50
  burnVerifier: "0xae92d5aD7583AD66E49A0c67BAd18F6ba52dDDc1",
49
51
  batchBurnVerifier: "0xae92d5aD7583AD66E49A0c67BAd18F6ba52dDDc1",
50
- }
52
+ },
51
53
  };
52
54
  await expect(
53
55
  factory.connect(nonOwner).registerImplementation("test", implInfo as any),
@@ -73,7 +75,7 @@ describe("(factory) Zeto based fungible token with anonymity without encryption
73
75
  batchLockVerifier: "0x0000000000000000000000000000000000000000",
74
76
  burnVerifier: "0x0000000000000000000000000000000000000000",
75
77
  batchBurnVerifier: "0x0000000000000000000000000000000000000000",
76
- }
78
+ },
77
79
  };
78
80
  await expect(
79
81
  factory.connect(deployer).registerImplementation("test", implInfo as any),
@@ -99,7 +101,7 @@ describe("(factory) Zeto based fungible token with anonymity without encryption
99
101
  batchLockVerifier: "0x0000000000000000000000000000000000000000",
100
102
  burnVerifier: "0x0000000000000000000000000000000000000000",
101
103
  batchBurnVerifier: "0x0000000000000000000000000000000000000000",
102
- }
104
+ },
103
105
  };
104
106
  await expect(
105
107
  factory.connect(deployer).registerImplementation("test", implInfo as any),
@@ -125,7 +127,7 @@ describe("(factory) Zeto based fungible token with anonymity without encryption
125
127
  batchLockVerifier: "0x0000000000000000000000000000000000000000",
126
128
  burnVerifier: "0x0000000000000000000000000000000000000000",
127
129
  batchBurnVerifier: "0x0000000000000000000000000000000000000000",
128
- }
130
+ },
129
131
  };
130
132
  await expect(
131
133
  factory.connect(deployer).registerImplementation("test", implInfo as any),
@@ -151,7 +153,7 @@ describe("(factory) Zeto based fungible token with anonymity without encryption
151
153
  batchLockVerifier: "0x0000000000000000000000000000000000000000",
152
154
  burnVerifier: "0x0000000000000000000000000000000000000000",
153
155
  batchBurnVerifier: "0x0000000000000000000000000000000000000000",
154
- }
156
+ },
155
157
  };
156
158
  const tx1 = await factory
157
159
  .connect(deployer)
@@ -161,7 +163,12 @@ describe("(factory) Zeto based fungible token with anonymity without encryption
161
163
  await expect(
162
164
  factory
163
165
  .connect(deployer)
164
- .deployZetoFungibleToken("name", "symbol", "test", await deployer.getAddress()),
166
+ .deployZetoFungibleToken(
167
+ "name",
168
+ "symbol",
169
+ "test",
170
+ await deployer.getAddress(),
171
+ ),
165
172
  ).rejectedWith("Factory: depositVerifier address is required");
166
173
  });
167
174
  it("attempting to deploy a fungible token but with a registered implementation that misses required depositVerifier should fail", async function () {
@@ -183,7 +190,7 @@ describe("(factory) Zeto based fungible token with anonymity without encryption
183
190
  batchLockVerifier: "0x0000000000000000000000000000000000000000",
184
191
  burnVerifier: "0x0000000000000000000000000000000000000000",
185
192
  batchBurnVerifier: "0x0000000000000000000000000000000000000000",
186
- }
193
+ },
187
194
  };
188
195
  const tx1 = await factory
189
196
  .connect(deployer)
@@ -193,7 +200,12 @@ describe("(factory) Zeto based fungible token with anonymity without encryption
193
200
  await expect(
194
201
  factory
195
202
  .connect(deployer)
196
- .deployZetoFungibleToken("name", "symbol", "test", await deployer.getAddress()),
203
+ .deployZetoFungibleToken(
204
+ "name",
205
+ "symbol",
206
+ "test",
207
+ await deployer.getAddress(),
208
+ ),
197
209
  ).rejectedWith("Factory: depositVerifier address is required");
198
210
  });
199
211
 
@@ -216,7 +228,7 @@ describe("(factory) Zeto based fungible token with anonymity without encryption
216
228
  batchLockVerifier: "0x0000000000000000000000000000000000000000",
217
229
  burnVerifier: "0x0000000000000000000000000000000000000000",
218
230
  batchBurnVerifier: "0x0000000000000000000000000000000000000000",
219
- }
231
+ },
220
232
  };
221
233
  const tx1 = await factory
222
234
  .connect(deployer)
@@ -226,7 +238,12 @@ describe("(factory) Zeto based fungible token with anonymity without encryption
226
238
  await expect(
227
239
  factory
228
240
  .connect(deployer)
229
- .deployZetoFungibleToken("name", "symbol", "test", await deployer.getAddress()),
241
+ .deployZetoFungibleToken(
242
+ "name",
243
+ "symbol",
244
+ "test",
245
+ await deployer.getAddress(),
246
+ ),
230
247
  ).rejectedWith("Factory: withdrawVerifier address is required");
231
248
  });
232
249
 
@@ -249,7 +266,7 @@ describe("(factory) Zeto based fungible token with anonymity without encryption
249
266
  batchLockVerifier: "0x0000000000000000000000000000000000000000",
250
267
  burnVerifier: "0x0000000000000000000000000000000000000000",
251
268
  batchBurnVerifier: "0x0000000000000000000000000000000000000000",
252
- }
269
+ },
253
270
  };
254
271
  const tx1 = await factory
255
272
  .connect(deployer)
@@ -259,68 +276,15 @@ describe("(factory) Zeto based fungible token with anonymity without encryption
259
276
  await expect(
260
277
  factory
261
278
  .connect(deployer)
262
- .deployZetoFungibleToken("name", "symbol", "test", await deployer.getAddress()),
279
+ .deployZetoFungibleToken(
280
+ "name",
281
+ "symbol",
282
+ "test",
283
+ await deployer.getAddress(),
284
+ ),
263
285
  ).rejectedWith("Factory: batchWithdrawVerifier address is required");
264
286
  });
265
287
 
266
- // it("attempting to deploy a fungible token but with a registered implementation that misses required lockVerifier should fail", async function () {
267
- // // we want to test the effectiveness of the factory contract
268
- // // to create clones of the Zeto implementation contract
269
- // const Factory = await ethers.getContractFactory("ZetoTokenFactory");
270
- // const factory = await Factory.deploy();
271
- // await factory.waitForDeployment();
272
-
273
- // const implInfo = {
274
- // implementation: "0xae92d5aD7583AD66E49A0c67BAd18F6ba52dDDc1",
275
- // verifier: "0xae92d5aD7583AD66E49A0c67BAd18F6ba52dDDc1",
276
- // batchVerifier: "0xae92d5aD7583AD66E49A0c67BAd18F6ba52dDDc1",
277
- // depositVerifier: "0xae92d5aD7583AD66E49A0c67BAd18F6ba52dDDc1",
278
- // withdrawVerifier: "0xae92d5aD7583AD66E49A0c67BAd18F6ba52dDDc1",
279
- // batchWithdrawVerifier: "0xae92d5aD7583AD66E49A0c67BAd18F6ba52dDDc1",
280
- // lockVerifier: "0x0000000000000000000000000000000000000000",
281
- // batchLockVerifier: "0x0000000000000000000000000000000000000000",
282
- // };
283
- // const tx1 = await factory
284
- // .connect(deployer)
285
- // .registerImplementation("test", implInfo as any);
286
- // await tx1.wait();
287
-
288
- // await expect(
289
- // factory
290
- // .connect(deployer)
291
- // .deployZetoFungibleToken("test", await deployer.getAddress()),
292
- // ).rejectedWith("Factory: lockVerifier address is required");
293
- // });
294
-
295
- // it("attempting to deploy a fungible token but with a registered implementation that misses required batchLockVerifier should fail", async function () {
296
- // // we want to test the effectiveness of the factory contract
297
- // // to create clones of the Zeto implementation contract
298
- // const Factory = await ethers.getContractFactory("ZetoTokenFactory");
299
- // const factory = await Factory.deploy();
300
- // await factory.waitForDeployment();
301
-
302
- // const implInfo = {
303
- // implementation: "0xae92d5aD7583AD66E49A0c67BAd18F6ba52dDDc1",
304
- // verifier: "0xae92d5aD7583AD66E49A0c67BAd18F6ba52dDDc1",
305
- // batchVerifier: "0xae92d5aD7583AD66E49A0c67BAd18F6ba52dDDc1",
306
- // depositVerifier: "0xae92d5aD7583AD66E49A0c67BAd18F6ba52dDDc1",
307
- // withdrawVerifier: "0xae92d5aD7583AD66E49A0c67BAd18F6ba52dDDc1",
308
- // batchWithdrawVerifier: "0xae92d5aD7583AD66E49A0c67BAd18F6ba52dDDc1",
309
- // lockVerifier: "0xae92d5aD7583AD66E49A0c67BAd18F6ba52dDDc1",
310
- // batchLockVerifier: "0x0000000000000000000000000000000000000000",
311
- // };
312
- // const tx1 = await factory
313
- // .connect(deployer)
314
- // .registerImplementation("test", implInfo as any);
315
- // await tx1.wait();
316
-
317
- // await expect(
318
- // factory
319
- // .connect(deployer)
320
- // .deployZetoFungibleToken("test", await deployer.getAddress()),
321
- // ).rejectedWith("Factory: batchLockVerifier address is required");
322
- // });
323
-
324
288
  it("attempting to deploy a fungible token with a properly registered implementation should succeed", async function () {
325
289
  // we want to test the effectiveness of the factory contract
326
290
  // to create clones of the Zeto implementation contract
@@ -328,8 +292,21 @@ describe("(factory) Zeto based fungible token with anonymity without encryption
328
292
  const factory = await Factory.deploy();
329
293
  await factory.waitForDeployment();
330
294
 
295
+ // deploy a real Zeto token so that the "implementation" contract can
296
+ // pass the code length check in the ERC1967Proxy contract
297
+ const ZetoLockableLib = await ethers.getContractFactory("ZetoLockableLib");
298
+ const zetoLockableLib = await ZetoLockableLib.deploy();
299
+ await zetoLockableLib.waitForDeployment();
300
+
301
+ const Zeto = await getLinkedContractFactory(
302
+ "Zeto_Anon",
303
+ withZetoLockableLib(zetoLockableLib),
304
+ );
305
+ const zeto = await Zeto.deploy();
306
+ await zeto.waitForDeployment();
307
+
331
308
  const implInfo = {
332
- implementation: "0xae92d5aD7583AD66E49A0c67BAd18F6ba52dDDc1",
309
+ implementation: zeto.target,
333
310
  verifiers: {
334
311
  verifier: "0xae92d5aD7583AD66E49A0c67BAd18F6ba52dDDc1",
335
312
  batchVerifier: "0xae92d5aD7583AD66E49A0c67BAd18F6ba52dDDc1",
@@ -340,7 +317,7 @@ describe("(factory) Zeto based fungible token with anonymity without encryption
340
317
  batchLockVerifier: "0xae92d5aD7583AD66E49A0c67BAd18F6ba52dDDc1",
341
318
  burnVerifier: "0xae92d5aD7583AD66E49A0c67BAd18F6ba52dDDc1",
342
319
  batchBurnVerifier: "0xae92d5aD7583AD66E49A0c67BAd18F6ba52dDDc1",
343
- }
320
+ },
344
321
  };
345
322
  const tx1 = await factory
346
323
  .connect(deployer)
@@ -350,7 +327,12 @@ describe("(factory) Zeto based fungible token with anonymity without encryption
350
327
  await expect(
351
328
  factory
352
329
  .connect(deployer)
353
- .deployZetoFungibleToken("name", "symbol", "test", await deployer.getAddress()),
330
+ .deployZetoFungibleToken(
331
+ "name",
332
+ "symbol",
333
+ "test",
334
+ await deployer.getAddress(),
335
+ ),
354
336
  ).fulfilled;
355
337
  });
356
338
  });