@enclave-e3/contracts 0.1.11 → 0.1.13

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 (257) hide show
  1. package/artifacts/@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol/ProxyAdmin.json +3 -3
  2. package/artifacts/@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol/artifacts.d.ts +3 -3
  3. package/artifacts/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/ITransparentUpgradeableProxy.json +1 -1
  4. package/artifacts/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json +3 -3
  5. package/artifacts/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/artifacts.d.ts +4 -4
  6. package/artifacts/build-info/{solc-0_8_28-c77ac33099bb85c15f46d194dd2b735e036cb799.json → solc-0_8_28-e60a5d7c133605edcf61acdd5ba43ab44ee0928e.json} +27 -12
  7. package/artifacts/build-info/solc-0_8_28-e60a5d7c133605edcf61acdd5ba43ab44ee0928e.output.json +1 -0
  8. package/artifacts/contracts/E3RefundManager.sol/E3RefundManager.json +684 -0
  9. package/artifacts/contracts/E3RefundManager.sol/artifacts.d.ts +27 -0
  10. package/artifacts/contracts/Enclave.sol/Enclave.json +530 -182
  11. package/artifacts/contracts/Enclave.sol/artifacts.d.ts +4 -4
  12. package/artifacts/contracts/interfaces/IBondingRegistry.sol/IBondingRegistry.json +14 -1
  13. package/artifacts/contracts/interfaces/IBondingRegistry.sol/artifacts.d.ts +2 -2
  14. package/artifacts/contracts/interfaces/ICiphernodeRegistry.sol/ICiphernodeRegistry.json +55 -5
  15. package/artifacts/contracts/interfaces/ICiphernodeRegistry.sol/artifacts.d.ts +2 -2
  16. package/artifacts/contracts/interfaces/IComputeProvider.sol/IComputeProvider.json +1 -1
  17. package/artifacts/contracts/interfaces/IComputeProvider.sol/artifacts.d.ts +1 -1
  18. package/artifacts/contracts/interfaces/IDecryptionVerifier.sol/IDecryptionVerifier.json +1 -1
  19. package/artifacts/contracts/interfaces/IDecryptionVerifier.sol/artifacts.d.ts +1 -1
  20. package/artifacts/contracts/interfaces/IE3Program.sol/IE3Program.json +19 -24
  21. package/artifacts/contracts/interfaces/IE3Program.sol/artifacts.d.ts +2 -2
  22. package/artifacts/contracts/interfaces/IE3RefundManager.sol/IE3RefundManager.json +470 -0
  23. package/artifacts/contracts/interfaces/IE3RefundManager.sol/artifacts.d.ts +27 -0
  24. package/artifacts/contracts/interfaces/IEnclave.sol/IEnclave.json +383 -128
  25. package/artifacts/contracts/interfaces/IEnclave.sol/artifacts.d.ts +2 -2
  26. package/artifacts/contracts/interfaces/ISlashVerifier.sol/ISlashVerifier.json +1 -1
  27. package/artifacts/contracts/interfaces/ISlashVerifier.sol/artifacts.d.ts +1 -1
  28. package/artifacts/contracts/interfaces/ISlashingManager.sol/ISlashingManager.json +1 -1
  29. package/artifacts/contracts/interfaces/ISlashingManager.sol/artifacts.d.ts +1 -1
  30. package/artifacts/contracts/lib/ExitQueueLib.sol/ExitQueueLib.json +1 -1
  31. package/artifacts/contracts/lib/ExitQueueLib.sol/artifacts.d.ts +1 -1
  32. package/artifacts/contracts/registry/BondingRegistry.sol/BondingRegistry.json +16 -3
  33. package/artifacts/contracts/registry/BondingRegistry.sol/artifacts.d.ts +4 -4
  34. package/artifacts/contracts/registry/CiphernodeRegistryOwnable.sol/CiphernodeRegistryOwnable.json +91 -25
  35. package/artifacts/contracts/registry/CiphernodeRegistryOwnable.sol/artifacts.d.ts +6 -6
  36. package/artifacts/contracts/slashing/SlashingManager.sol/SlashingManager.json +3 -3
  37. package/artifacts/contracts/slashing/SlashingManager.sol/artifacts.d.ts +3 -3
  38. package/artifacts/contracts/test/MockCiphernodeRegistry.sol/MockCiphernodeRegistry.json +57 -7
  39. package/artifacts/contracts/test/MockCiphernodeRegistry.sol/MockCiphernodeRegistryEmptyKey.json +57 -7
  40. package/artifacts/contracts/test/MockCiphernodeRegistry.sol/artifacts.d.ts +8 -8
  41. package/artifacts/contracts/test/MockComputeProvider.sol/MockComputeProvider.json +3 -3
  42. package/artifacts/contracts/test/MockComputeProvider.sol/artifacts.d.ts +3 -3
  43. package/artifacts/contracts/test/MockDecryptionVerifier.sol/MockDecryptionVerifier.json +1 -1
  44. package/artifacts/contracts/test/MockDecryptionVerifier.sol/artifacts.d.ts +1 -1
  45. package/artifacts/contracts/test/MockE3Program.sol/MockE3Program.json +21 -26
  46. package/artifacts/contracts/test/MockE3Program.sol/artifacts.d.ts +4 -4
  47. package/artifacts/contracts/test/MockSlashingVerifier.sol/MockSlashingVerifier.json +1 -1
  48. package/artifacts/contracts/test/MockSlashingVerifier.sol/artifacts.d.ts +1 -1
  49. package/artifacts/contracts/test/MockStableToken.sol/MockUSDC.json +3 -3
  50. package/artifacts/contracts/test/MockStableToken.sol/artifacts.d.ts +3 -3
  51. package/artifacts/contracts/token/EnclaveTicketToken.sol/EnclaveTicketToken.json +14 -22
  52. package/artifacts/contracts/token/EnclaveTicketToken.sol/artifacts.d.ts +4 -4
  53. package/artifacts/contracts/token/EnclaveToken.sol/EnclaveToken.json +10 -10
  54. package/artifacts/contracts/token/EnclaveToken.sol/artifacts.d.ts +4 -4
  55. package/artifacts/contracts/verifier/DkgPkVerifier.sol/BaseZKHonkVerifier.json +89 -0
  56. package/artifacts/contracts/verifier/DkgPkVerifier.sol/CommitmentSchemeLib.json +13 -0
  57. package/artifacts/contracts/verifier/DkgPkVerifier.sol/DkgPkVerifier.json +186 -0
  58. package/artifacts/contracts/verifier/DkgPkVerifier.sol/FrLib.json +13 -0
  59. package/artifacts/contracts/verifier/DkgPkVerifier.sol/Honk.json +13 -0
  60. package/artifacts/contracts/verifier/DkgPkVerifier.sol/HonkVerificationKey.json +13 -0
  61. package/artifacts/contracts/verifier/DkgPkVerifier.sol/IVerifier.json +38 -0
  62. package/artifacts/contracts/verifier/DkgPkVerifier.sol/RelationsLib.json +13 -0
  63. package/artifacts/contracts/verifier/DkgPkVerifier.sol/ZKTranscriptLib.json +400 -0
  64. package/artifacts/contracts/verifier/DkgPkVerifier.sol/artifacts.d.ts +155 -0
  65. package/artifacts/poseidon-solidity/PoseidonT3.sol/PoseidonT3.json +1 -1
  66. package/artifacts/poseidon-solidity/PoseidonT3.sol/artifacts.d.ts +1 -1
  67. package/contracts/E3RefundManager.sol +365 -0
  68. package/contracts/Enclave.sol +426 -119
  69. package/contracts/interfaces/IBondingRegistry.sol +6 -0
  70. package/contracts/interfaces/ICiphernodeRegistry.sol +29 -7
  71. package/contracts/interfaces/IE3.sol +2 -6
  72. package/contracts/interfaces/IE3Program.sol +3 -7
  73. package/contracts/interfaces/IE3RefundManager.sol +150 -0
  74. package/contracts/interfaces/IEnclave.sol +186 -64
  75. package/contracts/registry/BondingRegistry.sol +9 -0
  76. package/contracts/registry/CiphernodeRegistryOwnable.sol +89 -42
  77. package/contracts/test/MockCiphernodeRegistry.sol +20 -6
  78. package/contracts/test/MockE3Program.sol +3 -8
  79. package/contracts/verifier/DkgPkVerifier.sol +3140 -0
  80. package/dist/hardhat.config.d.ts.map +1 -1
  81. package/dist/hardhat.config.js +4 -4
  82. package/dist/ignition/modules/dkgPkVerifier.d.ts +3 -0
  83. package/dist/ignition/modules/dkgPkVerifier.d.ts.map +1 -0
  84. package/dist/ignition/modules/dkgPkVerifier.js +10 -0
  85. package/dist/ignition/modules/e3RefundManager.d.ts +3 -0
  86. package/dist/ignition/modules/e3RefundManager.d.ts.map +1 -0
  87. package/dist/ignition/modules/e3RefundManager.js +23 -0
  88. package/dist/ignition/modules/enclave.d.ts.map +1 -1
  89. package/dist/ignition/modules/enclave.js +10 -0
  90. package/dist/scripts/deployAndSave/e3RefundManager.d.ts +20 -0
  91. package/dist/scripts/deployAndSave/e3RefundManager.d.ts.map +1 -0
  92. package/dist/scripts/deployAndSave/e3RefundManager.js +55 -0
  93. package/dist/scripts/deployAndSave/enclave.d.ts +13 -1
  94. package/dist/scripts/deployAndSave/enclave.d.ts.map +1 -1
  95. package/dist/scripts/deployAndSave/enclave.js +8 -1
  96. package/dist/scripts/deployAndSave/verifiers.d.ts +29 -0
  97. package/dist/scripts/deployAndSave/verifiers.d.ts.map +1 -0
  98. package/dist/scripts/deployAndSave/verifiers.js +109 -0
  99. package/dist/scripts/deployEnclave.d.ts.map +1 -1
  100. package/dist/scripts/deployEnclave.js +36 -0
  101. package/dist/scripts/deployVerifiers.d.ts +2 -0
  102. package/dist/scripts/deployVerifiers.d.ts.map +1 -0
  103. package/dist/scripts/deployVerifiers.js +33 -0
  104. package/dist/scripts/index.d.ts +1 -0
  105. package/dist/scripts/index.d.ts.map +1 -1
  106. package/dist/scripts/index.js +1 -0
  107. package/dist/tasks/enclave.d.ts +0 -2
  108. package/dist/tasks/enclave.d.ts.map +1 -1
  109. package/dist/tasks/enclave.js +8 -72
  110. package/dist/tasks/program.d.ts +2 -0
  111. package/dist/tasks/program.d.ts.map +1 -0
  112. package/dist/tasks/program.js +55 -0
  113. package/dist/test/E3Lifecycle/E3Integration.spec.d.ts +2 -0
  114. package/dist/test/E3Lifecycle/E3Integration.spec.d.ts.map +1 -0
  115. package/dist/test/E3Lifecycle/E3Integration.spec.js +757 -0
  116. package/dist/test/Enclave.spec.js +83 -406
  117. package/dist/test/Registry/CiphernodeRegistryOwnable.spec.js +133 -59
  118. package/dist/types/contracts/E3RefundManager.d.ts +379 -0
  119. package/dist/types/contracts/E3RefundManager.d.ts.map +1 -0
  120. package/dist/types/contracts/E3RefundManager.js +24 -0
  121. package/dist/types/contracts/Enclave.d.ts +325 -73
  122. package/dist/types/contracts/Enclave.d.ts.map +1 -1
  123. package/dist/types/contracts/Enclave.js +27 -3
  124. package/dist/types/contracts/index.d.ts +3 -0
  125. package/dist/types/contracts/index.d.ts.map +1 -1
  126. package/dist/types/contracts/interfaces/IBondingRegistry.d.ts +11 -1
  127. package/dist/types/contracts/interfaces/IBondingRegistry.d.ts.map +1 -1
  128. package/dist/types/contracts/interfaces/ICiphernodeRegistry.d.ts +35 -7
  129. package/dist/types/contracts/interfaces/ICiphernodeRegistry.d.ts.map +1 -1
  130. package/dist/types/contracts/interfaces/ICiphernodeRegistry.js +4 -0
  131. package/dist/types/contracts/interfaces/IE3Program.d.ts +16 -18
  132. package/dist/types/contracts/interfaces/IE3Program.d.ts.map +1 -1
  133. package/dist/types/contracts/interfaces/IE3RefundManager.d.ts +238 -0
  134. package/dist/types/contracts/interfaces/IE3RefundManager.d.ts.map +1 -0
  135. package/dist/types/contracts/interfaces/IE3RefundManager.js +16 -0
  136. package/dist/types/contracts/interfaces/IEnclave.d.ts +290 -62
  137. package/dist/types/contracts/interfaces/IEnclave.d.ts.map +1 -1
  138. package/dist/types/contracts/interfaces/IEnclave.js +27 -3
  139. package/dist/types/contracts/interfaces/index.d.ts +1 -0
  140. package/dist/types/contracts/interfaces/index.d.ts.map +1 -1
  141. package/dist/types/contracts/registry/BondingRegistry.d.ts +11 -1
  142. package/dist/types/contracts/registry/BondingRegistry.d.ts.map +1 -1
  143. package/dist/types/contracts/registry/CiphernodeRegistryOwnable.d.ts +35 -7
  144. package/dist/types/contracts/registry/CiphernodeRegistryOwnable.d.ts.map +1 -1
  145. package/dist/types/contracts/registry/CiphernodeRegistryOwnable.js +4 -0
  146. package/dist/types/contracts/test/MockCiphernodeRegistry.sol/MockCiphernodeRegistry.d.ts +35 -7
  147. package/dist/types/contracts/test/MockCiphernodeRegistry.sol/MockCiphernodeRegistry.d.ts.map +1 -1
  148. package/dist/types/contracts/test/MockCiphernodeRegistry.sol/MockCiphernodeRegistry.js +4 -0
  149. package/dist/types/contracts/test/MockCiphernodeRegistry.sol/MockCiphernodeRegistryEmptyKey.d.ts +35 -7
  150. package/dist/types/contracts/test/MockCiphernodeRegistry.sol/MockCiphernodeRegistryEmptyKey.d.ts.map +1 -1
  151. package/dist/types/contracts/test/MockCiphernodeRegistry.sol/MockCiphernodeRegistryEmptyKey.js +4 -0
  152. package/dist/types/contracts/test/MockE3Program.d.ts +16 -18
  153. package/dist/types/contracts/test/MockE3Program.d.ts.map +1 -1
  154. package/dist/types/contracts/verifier/DkgPkVerifier.sol/BaseZKHonkVerifier.d.ts +36 -0
  155. package/dist/types/contracts/verifier/DkgPkVerifier.sol/BaseZKHonkVerifier.d.ts.map +1 -0
  156. package/dist/types/contracts/verifier/DkgPkVerifier.sol/BaseZKHonkVerifier.js +1 -0
  157. package/dist/types/contracts/verifier/DkgPkVerifier.sol/DkgPkVerifier.d.ts +36 -0
  158. package/dist/types/contracts/verifier/DkgPkVerifier.sol/DkgPkVerifier.d.ts.map +1 -0
  159. package/dist/types/contracts/verifier/DkgPkVerifier.sol/DkgPkVerifier.js +1 -0
  160. package/dist/types/contracts/verifier/DkgPkVerifier.sol/IVerifier.d.ts +36 -0
  161. package/dist/types/contracts/verifier/DkgPkVerifier.sol/IVerifier.d.ts.map +1 -0
  162. package/dist/types/contracts/verifier/DkgPkVerifier.sol/IVerifier.js +1 -0
  163. package/dist/types/contracts/verifier/DkgPkVerifier.sol/ZKTranscriptLib.d.ts +138 -0
  164. package/dist/types/contracts/verifier/DkgPkVerifier.sol/ZKTranscriptLib.d.ts.map +1 -0
  165. package/dist/types/contracts/verifier/DkgPkVerifier.sol/ZKTranscriptLib.js +1 -0
  166. package/dist/types/contracts/verifier/DkgPkVerifier.sol/index.d.ts +5 -0
  167. package/dist/types/contracts/verifier/DkgPkVerifier.sol/index.d.ts.map +1 -0
  168. package/dist/types/contracts/verifier/DkgPkVerifier.sol/index.js +1 -0
  169. package/dist/types/contracts/verifier/index.d.ts +3 -0
  170. package/dist/types/contracts/verifier/index.d.ts.map +1 -0
  171. package/dist/types/contracts/verifier/index.js +1 -0
  172. package/dist/types/factories/@openzeppelin/contracts/proxy/transparent/ProxyAdmin__factory.d.ts +1 -1
  173. package/dist/types/factories/@openzeppelin/contracts/proxy/transparent/ProxyAdmin__factory.d.ts.map +1 -1
  174. package/dist/types/factories/@openzeppelin/contracts/proxy/transparent/ProxyAdmin__factory.js +1 -1
  175. package/dist/types/factories/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy__factory.d.ts +1 -1
  176. package/dist/types/factories/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy__factory.d.ts.map +1 -1
  177. package/dist/types/factories/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy__factory.js +1 -1
  178. package/dist/types/factories/contracts/E3RefundManager__factory.d.ts +540 -0
  179. package/dist/types/factories/contracts/E3RefundManager__factory.d.ts.map +1 -0
  180. package/dist/types/factories/contracts/E3RefundManager__factory.js +706 -0
  181. package/dist/types/factories/contracts/Enclave__factory.d.ts +412 -143
  182. package/dist/types/factories/contracts/Enclave__factory.d.ts.map +1 -1
  183. package/dist/types/factories/contracts/Enclave__factory.js +528 -180
  184. package/dist/types/factories/contracts/index.d.ts +2 -0
  185. package/dist/types/factories/contracts/index.d.ts.map +1 -1
  186. package/dist/types/factories/contracts/index.js +2 -0
  187. package/dist/types/factories/contracts/interfaces/IBondingRegistry__factory.d.ts +10 -0
  188. package/dist/types/factories/contracts/interfaces/IBondingRegistry__factory.d.ts.map +1 -1
  189. package/dist/types/factories/contracts/interfaces/IBondingRegistry__factory.js +13 -0
  190. package/dist/types/factories/contracts/interfaces/ICiphernodeRegistry__factory.d.ts +42 -4
  191. package/dist/types/factories/contracts/interfaces/ICiphernodeRegistry__factory.d.ts.map +1 -1
  192. package/dist/types/factories/contracts/interfaces/ICiphernodeRegistry__factory.js +54 -4
  193. package/dist/types/factories/contracts/interfaces/IE3Program__factory.d.ts +14 -18
  194. package/dist/types/factories/contracts/interfaces/IE3Program__factory.d.ts.map +1 -1
  195. package/dist/types/factories/contracts/interfaces/IE3Program__factory.js +18 -23
  196. package/dist/types/factories/contracts/interfaces/IE3RefundManager__factory.d.ts +358 -0
  197. package/dist/types/factories/contracts/interfaces/IE3RefundManager__factory.d.ts.map +1 -0
  198. package/dist/types/factories/contracts/interfaces/IE3RefundManager__factory.js +471 -0
  199. package/dist/types/factories/contracts/interfaces/IEnclave__factory.d.ts +303 -103
  200. package/dist/types/factories/contracts/interfaces/IEnclave__factory.d.ts.map +1 -1
  201. package/dist/types/factories/contracts/interfaces/IEnclave__factory.js +382 -127
  202. package/dist/types/factories/contracts/interfaces/index.d.ts +1 -0
  203. package/dist/types/factories/contracts/interfaces/index.d.ts.map +1 -1
  204. package/dist/types/factories/contracts/interfaces/index.js +1 -0
  205. package/dist/types/factories/contracts/registry/BondingRegistry__factory.d.ts +11 -1
  206. package/dist/types/factories/contracts/registry/BondingRegistry__factory.d.ts.map +1 -1
  207. package/dist/types/factories/contracts/registry/BondingRegistry__factory.js +14 -1
  208. package/dist/types/factories/contracts/registry/CiphernodeRegistryOwnable__factory.d.ts +62 -12
  209. package/dist/types/factories/contracts/registry/CiphernodeRegistryOwnable__factory.d.ts.map +1 -1
  210. package/dist/types/factories/contracts/registry/CiphernodeRegistryOwnable__factory.js +79 -13
  211. package/dist/types/factories/contracts/slashing/SlashingManager__factory.d.ts +1 -1
  212. package/dist/types/factories/contracts/slashing/SlashingManager__factory.d.ts.map +1 -1
  213. package/dist/types/factories/contracts/slashing/SlashingManager__factory.js +1 -1
  214. package/dist/types/factories/contracts/test/MockCiphernodeRegistry.sol/MockCiphernodeRegistryEmptyKey__factory.d.ts +43 -5
  215. package/dist/types/factories/contracts/test/MockCiphernodeRegistry.sol/MockCiphernodeRegistryEmptyKey__factory.d.ts.map +1 -1
  216. package/dist/types/factories/contracts/test/MockCiphernodeRegistry.sol/MockCiphernodeRegistryEmptyKey__factory.js +55 -5
  217. package/dist/types/factories/contracts/test/MockCiphernodeRegistry.sol/MockCiphernodeRegistry__factory.d.ts +43 -5
  218. package/dist/types/factories/contracts/test/MockCiphernodeRegistry.sol/MockCiphernodeRegistry__factory.d.ts.map +1 -1
  219. package/dist/types/factories/contracts/test/MockCiphernodeRegistry.sol/MockCiphernodeRegistry__factory.js +55 -5
  220. package/dist/types/factories/contracts/test/MockComputeProvider__factory.d.ts +1 -1
  221. package/dist/types/factories/contracts/test/MockComputeProvider__factory.d.ts.map +1 -1
  222. package/dist/types/factories/contracts/test/MockComputeProvider__factory.js +1 -1
  223. package/dist/types/factories/contracts/test/MockE3Program__factory.d.ts +15 -19
  224. package/dist/types/factories/contracts/test/MockE3Program__factory.d.ts.map +1 -1
  225. package/dist/types/factories/contracts/test/MockE3Program__factory.js +19 -24
  226. package/dist/types/factories/contracts/test/MockStableToken.sol/MockUSDC__factory.d.ts +1 -1
  227. package/dist/types/factories/contracts/test/MockStableToken.sol/MockUSDC__factory.d.ts.map +1 -1
  228. package/dist/types/factories/contracts/test/MockStableToken.sol/MockUSDC__factory.js +1 -1
  229. package/dist/types/factories/contracts/token/EnclaveTicketToken__factory.d.ts +1 -1
  230. package/dist/types/factories/contracts/token/EnclaveTicketToken__factory.d.ts.map +1 -1
  231. package/dist/types/factories/contracts/token/EnclaveTicketToken__factory.js +1 -1
  232. package/dist/types/factories/contracts/token/EnclaveToken__factory.d.ts +1 -1
  233. package/dist/types/factories/contracts/token/EnclaveToken__factory.d.ts.map +1 -1
  234. package/dist/types/factories/contracts/token/EnclaveToken__factory.js +1 -1
  235. package/dist/types/factories/contracts/verifier/DkgPkVerifier.sol/BaseZKHonkVerifier__factory.d.ts +66 -0
  236. package/dist/types/factories/contracts/verifier/DkgPkVerifier.sol/BaseZKHonkVerifier__factory.d.ts.map +1 -0
  237. package/dist/types/factories/contracts/verifier/DkgPkVerifier.sol/BaseZKHonkVerifier__factory.js +90 -0
  238. package/dist/types/factories/contracts/verifier/DkgPkVerifier.sol/DkgPkVerifier__factory.d.ts +87 -0
  239. package/dist/types/factories/contracts/verifier/DkgPkVerifier.sol/DkgPkVerifier__factory.d.ts.map +1 -0
  240. package/dist/types/factories/contracts/verifier/DkgPkVerifier.sol/DkgPkVerifier__factory.js +122 -0
  241. package/dist/types/factories/contracts/verifier/DkgPkVerifier.sol/IVerifier__factory.d.ts +26 -0
  242. package/dist/types/factories/contracts/verifier/DkgPkVerifier.sol/IVerifier__factory.d.ts.map +1 -0
  243. package/dist/types/factories/contracts/verifier/DkgPkVerifier.sol/IVerifier__factory.js +39 -0
  244. package/dist/types/factories/contracts/verifier/DkgPkVerifier.sol/ZKTranscriptLib__factory.d.ts +323 -0
  245. package/dist/types/factories/contracts/verifier/DkgPkVerifier.sol/ZKTranscriptLib__factory.d.ts.map +1 -0
  246. package/dist/types/factories/contracts/verifier/DkgPkVerifier.sol/ZKTranscriptLib__factory.js +422 -0
  247. package/dist/types/factories/contracts/verifier/DkgPkVerifier.sol/index.d.ts +5 -0
  248. package/dist/types/factories/contracts/verifier/DkgPkVerifier.sol/index.d.ts.map +1 -0
  249. package/dist/types/factories/contracts/verifier/DkgPkVerifier.sol/index.js +7 -0
  250. package/dist/types/factories/contracts/verifier/index.d.ts +2 -0
  251. package/dist/types/factories/contracts/verifier/index.d.ts.map +1 -0
  252. package/dist/types/factories/contracts/verifier/index.js +4 -0
  253. package/dist/types/index.d.ts +12 -0
  254. package/dist/types/index.d.ts.map +1 -1
  255. package/dist/types/index.js +6 -0
  256. package/package.json +17 -3
  257. package/artifacts/build-info/solc-0_8_28-c77ac33099bb85c15f46d194dd2b735e036cb799.output.json +0 -1
@@ -8,6 +8,7 @@ pragma solidity >=0.8.27;
8
8
  import { IEnclave, E3, IE3Program } from "./interfaces/IEnclave.sol";
9
9
  import { ICiphernodeRegistry } from "./interfaces/ICiphernodeRegistry.sol";
10
10
  import { IBondingRegistry } from "./interfaces/IBondingRegistry.sol";
11
+ import { IE3RefundManager } from "./interfaces/IE3RefundManager.sol";
11
12
  import { IDecryptionVerifier } from "./interfaces/IDecryptionVerifier.sol";
12
13
  import {
13
14
  OwnableUpgradeable
@@ -39,6 +40,10 @@ contract Enclave is IEnclave, OwnableUpgradeable {
39
40
  /// @dev Handles staking and reward distribution for ciphernodes.
40
41
  IBondingRegistry public bondingRegistry;
41
42
 
43
+ /// @notice E3 Refund Manager contract for handling failed E3 refunds.
44
+ /// @dev Manages refund calculation and claiming for failed E3s.
45
+ IE3RefundManager public e3RefundManager;
46
+
42
47
  /// @notice Address of the ERC20 token used for E3 fees.
43
48
  /// @dev All E3 request fees must be paid in this token.
44
49
  IERC20 public feeToken;
@@ -72,6 +77,21 @@ contract Enclave is IEnclave, OwnableUpgradeable {
72
77
  /// @dev Stores the amount paid for an E3, distributed to committee upon completion.
73
78
  mapping(uint256 e3Id => uint256 e3Payment) public e3Payments;
74
79
 
80
+ /// @notice Maps E3 ID to its current stage
81
+ mapping(uint256 e3Id => E3Stage) internal _e3Stages;
82
+
83
+ /// @notice Maps E3 ID to its deadlines
84
+ mapping(uint256 e3Id => E3Deadlines) internal _e3Deadlines;
85
+
86
+ /// @notice Maps E3 ID to failure reason (if failed)
87
+ mapping(uint256 e3Id => FailureReason) internal _e3FailureReasons;
88
+
89
+ /// @notice Maps E3 ID to requester address
90
+ mapping(uint256 e3Id => address) internal _e3Requesters;
91
+
92
+ /// @notice Global timeout configuration
93
+ E3TimeoutConfig internal _timeoutConfig;
94
+
75
95
  ////////////////////////////////////////////////////////////
76
96
  // //
77
97
  // Errors //
@@ -85,20 +105,6 @@ contract Enclave is IEnclave, OwnableUpgradeable {
85
105
  /// @param e3Program The E3 program address that is not allowed.
86
106
  error E3ProgramNotAllowed(IE3Program e3Program);
87
107
 
88
- /// @notice Thrown when attempting to activate an E3 that is already activated.
89
- /// @param e3Id The ID of the E3 that is already activated.
90
- error E3AlreadyActivated(uint256 e3Id);
91
-
92
- /// @notice Thrown when the E3 start window or computation period has expired.
93
- error E3Expired();
94
-
95
- /// @notice Thrown when attempting operations on an E3 that has not been activated yet.
96
- /// @param e3Id The ID of the E3 that is not activated.
97
- error E3NotActivated(uint256 e3Id);
98
-
99
- /// @notice Thrown when attempting to activate an E3 before its start window begins.
100
- error E3NotReady();
101
-
102
108
  /// @notice Thrown when attempting to access an E3 that does not exist.
103
109
  /// @param e3Id The ID of the non-existent E3.
104
110
  error E3DoesNotExist(uint256 e3Id);
@@ -115,16 +121,6 @@ contract Enclave is IEnclave, OwnableUpgradeable {
115
121
  /// @param encryptionSchemeId The ID of the invalid encryption scheme.
116
122
  error InvalidEncryptionScheme(bytes32 encryptionSchemeId);
117
123
 
118
- /// @notice Thrown when attempting to publish input after the computation deadline has passed.
119
- /// @param e3Id The ID of the E3.
120
- /// @param expiration The expiration timestamp that has passed.
121
- error InputDeadlinePassed(uint256 e3Id, uint256 expiration);
122
-
123
- /// @notice Thrown when attempting to publish output before the input deadline has passed.
124
- /// @param e3Id The ID of the E3.
125
- /// @param expiration The expiration timestamp that has not yet passed.
126
- error InputDeadlineNotPassed(uint256 e3Id, uint256 expiration);
127
-
128
124
  /// @notice Thrown when attempting to set an invalid ciphernode registry address.
129
125
  /// @param ciphernodeRegistry The invalid ciphernode registry address.
130
126
  error InvalidCiphernodeRegistry(ICiphernodeRegistry ciphernodeRegistry);
@@ -137,12 +133,6 @@ contract Enclave is IEnclave, OwnableUpgradeable {
137
133
  /// @param output The invalid output data.
138
134
  error InvalidOutput(bytes output);
139
135
 
140
- /// @notice Thrown when input data is invalid.
141
- error InvalidInput();
142
-
143
- /// @notice Thrown when the start window parameters are invalid.
144
- error InvalidStartWindow();
145
-
146
136
  /// @notice Thrown when the threshold parameters are invalid (e.g., M > N or M = 0).
147
137
  /// @param threshold The invalid threshold array [M, N].
148
138
  error InvalidThreshold(uint32[2] threshold);
@@ -171,12 +161,56 @@ contract Enclave is IEnclave, OwnableUpgradeable {
171
161
  /// @param feeToken The invalid fee token address.
172
162
  error InvalidFeeToken(IERC20 feeToken);
173
163
 
164
+ /// @notice E3 is not in expected stage
165
+ error InvalidStage(uint256 e3Id, E3Stage expected, E3Stage actual);
166
+
167
+ /// @notice E3 has already been marked as failed
168
+ error E3AlreadyFailed(uint256 e3Id);
169
+
170
+ /// @notice E3 has already completed
171
+ error E3AlreadyComplete(uint256 e3Id);
172
+
173
+ /// @notice Failure condition not yet met
174
+ error FailureConditionNotMet(uint256 e3Id);
175
+
176
+ /// @notice The Input deadline is invalid
177
+ error InvalidInputDeadline(uint256 deadline);
178
+
179
+ /// @notice The input deadline start is in the past
180
+ error InvalidInputDeadlineStart(uint256 start);
181
+ /// @notice The input deadline end is before the start
182
+ error InvalidInputDeadlineEnd(uint256 end);
183
+
184
+ /// @notice The duties are completed, and ciphernodes are not required to act anymore for this E3
185
+ /// @param e3Id The ID of the E3
186
+ /// @param expiration The expiration timestamp of the E3
187
+ error CommitteeDutiesCompleted(uint256 e3Id, uint256 expiration);
188
+
189
+ /// @notice The input deadline has not yet been reached
190
+ /// @param e3Id The ID of the E3
191
+ /// @param inputDeadline The input deadline timestamp of the E3
192
+ error InputDeadlineNotReached(uint256 e3Id, uint256 inputDeadline);
193
+
174
194
  ////////////////////////////////////////////////////////////
175
195
  // //
176
- // Initialization //
196
+ // Modifiers //
177
197
  // //
178
198
  ////////////////////////////////////////////////////////////
179
199
 
200
+ /// @notice Restricts function to CiphernodeRegistry contract only
201
+ modifier onlyCiphernodeRegistry() {
202
+ require(
203
+ msg.sender == address(ciphernodeRegistry),
204
+ "Only CiphernodeRegistry"
205
+ );
206
+ _;
207
+ }
208
+
209
+ ////////////////////////////////////////////////////////////
210
+ // //
211
+ // Initialization //
212
+ ////////////////////////////////////////////////////////////
213
+
180
214
  /// @notice Constructor that disables initializers.
181
215
  /// @dev Prevents the implementation contract from being initialized. Initialization is performed
182
216
  /// via the initialize() function when deployed behind a proxy.
@@ -189,22 +223,28 @@ contract Enclave is IEnclave, OwnableUpgradeable {
189
223
  /// @param _owner The owner address of this contract.
190
224
  /// @param _ciphernodeRegistry The address of the Ciphernode Registry contract.
191
225
  /// @param _bondingRegistry The address of the Bonding Registry contract.
226
+ /// @param _e3RefundManager The address of the E3 Refund Manager contract.
192
227
  /// @param _feeToken The address of the ERC20 token used for E3 fees.
193
228
  /// @param _maxDuration The maximum duration of a computation in seconds.
229
+ /// @param config Initial timeout configuration for E3 lifecycle stages.
194
230
  /// @param _e3ProgramsParams Array of ABI encoded E3 encryption scheme parameters sets (e.g., for BFV).
195
231
  function initialize(
196
232
  address _owner,
197
233
  ICiphernodeRegistry _ciphernodeRegistry,
198
234
  IBondingRegistry _bondingRegistry,
235
+ IE3RefundManager _e3RefundManager,
199
236
  IERC20 _feeToken,
200
237
  uint256 _maxDuration,
238
+ E3TimeoutConfig calldata config,
201
239
  bytes[] memory _e3ProgramsParams
202
240
  ) public initializer {
203
241
  __Ownable_init(msg.sender);
204
242
  setMaxDuration(_maxDuration);
205
243
  setCiphernodeRegistry(_ciphernodeRegistry);
206
244
  setBondingRegistry(_bondingRegistry);
245
+ setE3RefundManager(_e3RefundManager);
207
246
  setFeeToken(_feeToken);
247
+ _setTimeoutConfig(config);
208
248
  setE3ProgramsParams(_e3ProgramsParams);
209
249
  if (_owner != owner()) transferOwnership(_owner);
210
250
  }
@@ -219,28 +259,42 @@ contract Enclave is IEnclave, OwnableUpgradeable {
219
259
  function request(
220
260
  E3RequestParams calldata requestParams
221
261
  ) external returns (uint256 e3Id, E3 memory e3) {
222
- uint256 e3Fee = getE3Quote(requestParams);
262
+ // check whether the threshold config is valid
223
263
  require(
224
264
  requestParams.threshold[1] >= requestParams.threshold[0] &&
225
265
  requestParams.threshold[0] > 0,
226
266
  InvalidThreshold(requestParams.threshold)
227
267
  );
268
+
269
+ // input start date should be in the future
228
270
  require(
229
- // TODO: do we need a minimum start window to allow time for committee selection?
230
- requestParams.startWindow[1] >= requestParams.startWindow[0] &&
231
- requestParams.startWindow[1] >= block.timestamp,
232
- InvalidStartWindow()
271
+ requestParams.inputWindow[0] >= block.timestamp,
272
+ // &&
273
+ // requestParams.inputWindow[0] >= block.timestamp +
274
+ // _timeoutConfig.dkgWindow,
275
+ InvalidInputDeadlineStart(requestParams.inputWindow[0])
233
276
  );
277
+ // the end of the input window should be after the start
234
278
  require(
235
- requestParams.duration > 0 && requestParams.duration <= maxDuration,
236
- InvalidDuration(requestParams.duration)
279
+ requestParams.inputWindow[1] >= requestParams.inputWindow[0],
280
+ InvalidInputDeadlineEnd(requestParams.inputWindow[1])
237
281
  );
282
+
283
+ // The total duration cannot be > maxDuration
284
+ uint256 totalDuration = requestParams.inputWindow[1] -
285
+ block.timestamp +
286
+ _timeoutConfig.computeWindow +
287
+ _timeoutConfig.decryptionWindow;
288
+ // TODO do we actually need a max duration?
289
+ require(totalDuration < maxDuration, InvalidDuration(totalDuration));
290
+
238
291
  require(
239
292
  e3Programs[requestParams.e3Program],
240
293
  E3ProgramNotAllowed(requestParams.e3Program)
241
294
  );
242
295
 
243
- // TODO: should IDs be incremental or produced deterministically?
296
+ uint256 e3Fee = getE3Quote(requestParams);
297
+
244
298
  e3Id = nexte3Id;
245
299
  nexte3Id++;
246
300
  uint256 seed = uint256(keccak256(abi.encode(block.prevrandao, e3Id)));
@@ -248,9 +302,7 @@ contract Enclave is IEnclave, OwnableUpgradeable {
248
302
  e3.seed = seed;
249
303
  e3.threshold = requestParams.threshold;
250
304
  e3.requestBlock = block.number;
251
- e3.startWindow = requestParams.startWindow;
252
- e3.duration = requestParams.duration;
253
- e3.expiration = 0;
305
+ e3.inputWindow = requestParams.inputWindow;
254
306
  e3.e3Program = requestParams.e3Program;
255
307
  e3.e3ProgramParams = requestParams.e3ProgramParams;
256
308
  e3.customParams = requestParams.customParams;
@@ -293,47 +345,17 @@ contract Enclave is IEnclave, OwnableUpgradeable {
293
345
  CommitteeSelectionFailed()
294
346
  );
295
347
 
296
- emit E3Requested(e3Id, e3, requestParams.e3Program);
297
- }
298
-
299
- /// @inheritdoc IEnclave
300
- function activate(uint256 e3Id) external returns (bool success) {
301
- E3 memory e3 = getE3(e3Id);
302
-
303
- require(e3.expiration == 0, E3AlreadyActivated(e3Id));
304
- require(e3.startWindow[0] <= block.timestamp, E3NotReady());
305
- // TODO: handle what happens to the payment if the start window has passed.
306
- require(e3.startWindow[1] >= block.timestamp, E3Expired());
307
-
308
- bytes32 publicKeyHash = ciphernodeRegistry.committeePublicKey(e3Id);
309
-
310
- uint256 expiresAt = block.timestamp + e3.duration;
311
- e3s[e3Id].expiration = expiresAt;
312
- e3s[e3Id].committeePublicKey = publicKeyHash;
313
-
314
- emit E3Activated(e3Id, expiresAt, publicKeyHash);
315
-
316
- return true;
317
- }
318
-
319
- /// @inheritdoc IEnclave
320
- function publishInput(
321
- uint256 e3Id,
322
- bytes calldata data
323
- ) external returns (bool success) {
324
- E3 memory e3 = getE3(e3Id);
325
-
326
- // Note: if we make 0 a no expiration, this has to be refactored
327
- require(e3.expiration > 0, E3NotActivated(e3Id));
328
- // TODO: should we have an input window, including both a start and end timestamp?
329
- require(
330
- e3.expiration > block.timestamp,
331
- InputDeadlinePassed(e3Id, e3.expiration)
332
- );
348
+ // Initialize E3 lifecycle
349
+ _e3Stages[e3Id] = E3Stage.Requested;
350
+ _e3Requesters[e3Id] = msg.sender;
333
351
 
334
- e3.e3Program.validateInput(e3Id, msg.sender, data);
352
+ // the compute deadline is end of input window + compute window
353
+ _e3Deadlines[e3Id].computeDeadline =
354
+ e3.inputWindow[1] +
355
+ _timeoutConfig.computeWindow;
335
356
 
336
- success = true;
357
+ emit E3Requested(e3Id, e3, requestParams.e3Program);
358
+ emit E3StageChanged(e3Id, E3Stage.None, E3Stage.Requested);
337
359
  }
338
360
 
339
361
  /// @inheritdoc IEnclave
@@ -344,14 +366,21 @@ contract Enclave is IEnclave, OwnableUpgradeable {
344
366
  ) external returns (bool success) {
345
367
  E3 memory e3 = getE3(e3Id);
346
368
 
347
- // Note: if we make 0 a no expiration, this has to be refactored
348
- require(e3.expiration > 0, E3NotActivated(e3Id));
369
+ E3Deadlines memory deadlines = _e3Deadlines[e3Id];
370
+
371
+ // You cannot post outputs after the compute deadline
372
+ require(
373
+ deadlines.computeDeadline >= block.timestamp,
374
+ CommitteeDutiesCompleted(e3Id, deadlines.computeDeadline)
375
+ );
376
+
377
+ // The program need to have stopped accepting inputs
349
378
  require(
350
- e3.expiration <= block.timestamp,
351
- InputDeadlineNotPassed(e3Id, e3.expiration)
379
+ block.timestamp >= e3.inputWindow[1],
380
+ InputDeadlineNotReached(e3Id, e3.inputWindow[1])
352
381
  );
353
- // TODO: should the output verifier be able to change its mind?
354
- //i.e. should we be able to call this multiple times?
382
+
383
+ // For now we only accept one output
355
384
  require(
356
385
  e3.ciphertextOutput == bytes32(0),
357
386
  CiphertextOutputAlreadyPublished(e3Id)
@@ -363,7 +392,18 @@ contract Enclave is IEnclave, OwnableUpgradeable {
363
392
  (success) = e3.e3Program.verify(e3Id, ciphertextOutputHash, proof);
364
393
  require(success, InvalidOutput(ciphertextOutput));
365
394
 
395
+ // Update lifecycle stage
396
+ _e3Stages[e3Id] = E3Stage.CiphertextReady;
397
+ _e3Deadlines[e3Id].decryptionDeadline =
398
+ block.timestamp +
399
+ _timeoutConfig.decryptionWindow;
400
+
366
401
  emit CiphertextOutputPublished(e3Id, ciphertextOutput);
402
+ emit E3StageChanged(
403
+ e3Id,
404
+ E3Stage.KeyPublished,
405
+ E3Stage.CiphertextReady
406
+ );
367
407
  }
368
408
 
369
409
  /// @inheritdoc IEnclave
@@ -374,15 +414,20 @@ contract Enclave is IEnclave, OwnableUpgradeable {
374
414
  ) external returns (bool success) {
375
415
  E3 memory e3 = getE3(e3Id);
376
416
 
377
- // Note: if we make 0 a no expiration, this has to be refactored
378
- require(e3.expiration > 0, E3NotActivated(e3Id));
417
+ // Check we are in the right stage
418
+ // no need to check if there's a ciphertext as we would not
419
+ // be in this stage otherwise
420
+ E3Stage current = _e3Stages[e3Id];
379
421
  require(
380
- e3.ciphertextOutput != bytes32(0),
381
- CiphertextOutputNotPublished(e3Id)
422
+ current == E3Stage.CiphertextReady,
423
+ InvalidStage(e3Id, E3Stage.CiphertextReady, current)
382
424
  );
425
+
426
+ // you cannot post a decryption after the decryption deadline
427
+ E3Deadlines memory deadlines = _e3Deadlines[e3Id];
383
428
  require(
384
- e3.plaintextOutput.length == 0,
385
- PlaintextOutputAlreadyPublished(e3Id)
429
+ deadlines.decryptionDeadline >= block.timestamp,
430
+ CommitteeDutiesCompleted(e3Id, deadlines.decryptionDeadline)
386
431
  );
387
432
 
388
433
  e3s[e3Id].plaintextOutput = plaintextOutput;
@@ -394,9 +439,13 @@ contract Enclave is IEnclave, OwnableUpgradeable {
394
439
  );
395
440
  require(success, InvalidOutput(plaintextOutput));
396
441
 
442
+ // Update lifecycle stage to Complete
443
+ _e3Stages[e3Id] = E3Stage.Complete;
444
+
397
445
  _distributeRewards(e3Id);
398
446
 
399
447
  emit PlaintextOutputPublished(e3Id, plaintextOutput);
448
+ emit E3StageChanged(e3Id, E3Stage.CiphertextReady, E3Stage.Complete);
400
449
  }
401
450
 
402
451
  ////////////////////////////////////////////////////////////
@@ -436,6 +485,34 @@ contract Enclave is IEnclave, OwnableUpgradeable {
436
485
  emit RewardsDistributed(e3Id, committeeNodes, amounts);
437
486
  }
438
487
 
488
+ /// @notice Retrieves the honest committee nodes for a given E3.
489
+ /// @dev Determines honest nodes based on failure reason and committee publication status.
490
+ /// @param e3Id The ID of the E3.
491
+ /// @return honestNodes An array of addresses of honest committee nodes.
492
+ function _getHonestNodes(
493
+ uint256 e3Id
494
+ ) private view returns (address[] memory) {
495
+ FailureReason reason = _e3FailureReasons[e3Id];
496
+
497
+ // Early failures have no committee
498
+ if (
499
+ reason == FailureReason.CommitteeFormationTimeout ||
500
+ reason == FailureReason.InsufficientCommitteeMembers
501
+ ) {
502
+ return new address[](0);
503
+ }
504
+
505
+ // Try to get published committee nodes
506
+ try ciphernodeRegistry.getCommitteeNodes(e3Id) returns (
507
+ address[] memory nodes
508
+ ) {
509
+ // TODO: Implement fault attribution to filter honest from faulting nodes
510
+ return nodes; // Assume all are honest for now
511
+ } catch {
512
+ return new address[](0); // Committee not published (DKG failed)
513
+ }
514
+ }
515
+
439
516
  ////////////////////////////////////////////////////////////
440
517
  // //
441
518
  // Set Functions //
@@ -443,75 +520,61 @@ contract Enclave is IEnclave, OwnableUpgradeable {
443
520
  ////////////////////////////////////////////////////////////
444
521
 
445
522
  /// @inheritdoc IEnclave
446
- function setMaxDuration(
447
- uint256 _maxDuration
448
- ) public onlyOwner returns (bool success) {
523
+ function setMaxDuration(uint256 _maxDuration) public onlyOwner {
449
524
  maxDuration = _maxDuration;
450
- success = true;
451
525
  emit MaxDurationSet(_maxDuration);
452
526
  }
453
527
 
454
528
  /// @inheritdoc IEnclave
455
529
  function setCiphernodeRegistry(
456
530
  ICiphernodeRegistry _ciphernodeRegistry
457
- ) public onlyOwner returns (bool success) {
531
+ ) public onlyOwner {
458
532
  require(
459
533
  address(_ciphernodeRegistry) != address(0) &&
460
534
  _ciphernodeRegistry != ciphernodeRegistry,
461
535
  InvalidCiphernodeRegistry(_ciphernodeRegistry)
462
536
  );
463
537
  ciphernodeRegistry = _ciphernodeRegistry;
464
- success = true;
465
538
  emit CiphernodeRegistrySet(address(_ciphernodeRegistry));
466
539
  }
467
540
 
468
541
  /// @inheritdoc IEnclave
469
542
  function setBondingRegistry(
470
543
  IBondingRegistry _bondingRegistry
471
- ) public onlyOwner returns (bool success) {
544
+ ) public onlyOwner {
472
545
  require(
473
546
  address(_bondingRegistry) != address(0) &&
474
547
  _bondingRegistry != bondingRegistry,
475
548
  InvalidBondingRegistry(_bondingRegistry)
476
549
  );
477
550
  bondingRegistry = _bondingRegistry;
478
- success = true;
479
551
  emit BondingRegistrySet(address(_bondingRegistry));
480
552
  }
481
553
 
482
554
  /// @inheritdoc IEnclave
483
- function setFeeToken(
484
- IERC20 _feeToken
485
- ) public onlyOwner returns (bool success) {
555
+ function setFeeToken(IERC20 _feeToken) public onlyOwner {
486
556
  require(
487
557
  address(_feeToken) != address(0) && _feeToken != feeToken,
488
558
  InvalidFeeToken(_feeToken)
489
559
  );
490
560
  feeToken = _feeToken;
491
- success = true;
492
561
  emit FeeTokenSet(address(_feeToken));
493
562
  }
494
563
 
495
564
  /// @inheritdoc IEnclave
496
- function enableE3Program(
497
- IE3Program e3Program
498
- ) public onlyOwner returns (bool success) {
565
+ function enableE3Program(IE3Program e3Program) public onlyOwner {
499
566
  require(
500
567
  !e3Programs[e3Program],
501
568
  ModuleAlreadyEnabled(address(e3Program))
502
569
  );
503
570
  e3Programs[e3Program] = true;
504
- success = true;
505
571
  emit E3ProgramEnabled(e3Program);
506
572
  }
507
573
 
508
574
  /// @inheritdoc IEnclave
509
- function disableE3Program(
510
- IE3Program e3Program
511
- ) public onlyOwner returns (bool success) {
575
+ function disableE3Program(IE3Program e3Program) public onlyOwner {
512
576
  require(e3Programs[e3Program], ModuleNotEnabled(address(e3Program)));
513
577
  delete e3Programs[e3Program];
514
- success = true;
515
578
  emit E3ProgramDisabled(e3Program);
516
579
  }
517
580
 
@@ -519,21 +582,20 @@ contract Enclave is IEnclave, OwnableUpgradeable {
519
582
  function setDecryptionVerifier(
520
583
  bytes32 encryptionSchemeId,
521
584
  IDecryptionVerifier decryptionVerifier
522
- ) public onlyOwner returns (bool success) {
585
+ ) public onlyOwner {
523
586
  require(
524
587
  decryptionVerifier != IDecryptionVerifier(address(0)) &&
525
588
  decryptionVerifiers[encryptionSchemeId] != decryptionVerifier,
526
589
  InvalidEncryptionScheme(encryptionSchemeId)
527
590
  );
528
591
  decryptionVerifiers[encryptionSchemeId] = decryptionVerifier;
529
- success = true;
530
592
  emit EncryptionSchemeEnabled(encryptionSchemeId);
531
593
  }
532
594
 
533
595
  /// @inheritdoc IEnclave
534
596
  function disableEncryptionScheme(
535
597
  bytes32 encryptionSchemeId
536
- ) public onlyOwner returns (bool success) {
598
+ ) public onlyOwner {
537
599
  require(
538
600
  decryptionVerifiers[encryptionSchemeId] !=
539
601
  IDecryptionVerifier(address(0)),
@@ -542,14 +604,13 @@ contract Enclave is IEnclave, OwnableUpgradeable {
542
604
  decryptionVerifiers[encryptionSchemeId] = IDecryptionVerifier(
543
605
  address(0)
544
606
  );
545
- success = true;
546
607
  emit EncryptionSchemeDisabled(encryptionSchemeId);
547
608
  }
548
609
 
549
610
  /// @inheritdoc IEnclave
550
611
  function setE3ProgramsParams(
551
612
  bytes[] memory _e3ProgramsParams
552
- ) public onlyOwner returns (bool success) {
613
+ ) public onlyOwner {
553
614
  uint256 length = _e3ProgramsParams.length;
554
615
  for (uint256 i; i < length; ) {
555
616
  e3ProgramsParams[_e3ProgramsParams[i]] = true;
@@ -557,10 +618,256 @@ contract Enclave is IEnclave, OwnableUpgradeable {
557
618
  ++i;
558
619
  }
559
620
  }
560
- success = true;
561
621
  emit AllowedE3ProgramsParamsSet(_e3ProgramsParams);
562
622
  }
563
623
 
624
+ /// @notice Sets the E3 Refund Manager contract address
625
+ /// @param _e3RefundManager The new E3 Refund Manager contract address
626
+ function setE3RefundManager(
627
+ IE3RefundManager _e3RefundManager
628
+ ) public onlyOwner {
629
+ require(
630
+ address(_e3RefundManager) != address(0),
631
+ "Invalid E3RefundManager address"
632
+ );
633
+ e3RefundManager = _e3RefundManager;
634
+ emit E3RefundManagerSet(address(_e3RefundManager));
635
+ }
636
+
637
+ /// @notice Process a failed E3 and calculate refunds
638
+ /// @dev Can be called by anyone once E3 is in failed state
639
+ /// @param e3Id The ID of the failed E3
640
+ function processE3Failure(uint256 e3Id) external {
641
+ E3Stage stage = _e3Stages[e3Id];
642
+ require(stage == E3Stage.Failed, "E3 not failed");
643
+
644
+ uint256 payment = e3Payments[e3Id];
645
+ require(payment > 0, "No payment to refund");
646
+ e3Payments[e3Id] = 0; // Prevent double processing
647
+
648
+ address[] memory honestNodes = _getHonestNodes(e3Id);
649
+
650
+ feeToken.safeTransfer(address(e3RefundManager), payment);
651
+ e3RefundManager.calculateRefund(e3Id, payment, honestNodes);
652
+
653
+ emit E3FailureProcessed(e3Id, payment, honestNodes.length);
654
+ }
655
+
656
+ /// @inheritdoc IEnclave
657
+ function onCommitteeFinalized(
658
+ uint256 e3Id
659
+ ) external onlyCiphernodeRegistry {
660
+ // Update E3 lifecycle stage - committee finalized, DKG starting
661
+ E3Stage current = _e3Stages[e3Id];
662
+ if (current != E3Stage.Requested) {
663
+ revert InvalidStage(e3Id, E3Stage.Requested, current);
664
+ }
665
+ _e3Stages[e3Id] = E3Stage.CommitteeFinalized;
666
+ _e3Deadlines[e3Id].dkgDeadline =
667
+ block.timestamp +
668
+ _timeoutConfig.dkgWindow;
669
+
670
+ emit CommitteeFinalized(e3Id);
671
+ emit E3StageChanged(
672
+ e3Id,
673
+ E3Stage.Requested,
674
+ E3Stage.CommitteeFinalized
675
+ );
676
+ }
677
+
678
+ /// @inheritdoc IEnclave
679
+ function onCommitteePublished(
680
+ uint256 e3Id,
681
+ bytes32 committeePublicKeyHash
682
+ ) external onlyCiphernodeRegistry {
683
+ // DKG complete, key published
684
+ E3Stage current = _e3Stages[e3Id];
685
+ if (current != E3Stage.CommitteeFinalized) {
686
+ revert InvalidStage(e3Id, E3Stage.CommitteeFinalized, current);
687
+ }
688
+ _e3Stages[e3Id] = E3Stage.KeyPublished;
689
+
690
+ e3s[e3Id].committeePublicKey = committeePublicKeyHash;
691
+
692
+ emit CommitteeFormed(e3Id);
693
+ emit E3StageChanged(
694
+ e3Id,
695
+ E3Stage.CommitteeFinalized,
696
+ E3Stage.KeyPublished
697
+ );
698
+ }
699
+
700
+ /// @inheritdoc IEnclave
701
+ function onE3Failed(
702
+ uint256 e3Id,
703
+ uint8 reason
704
+ ) external onlyCiphernodeRegistry {
705
+ require(reason > 0 && reason <= 12, "Invalid failure reason");
706
+ // Mark E3 as failed with the given reason
707
+ _markE3FailedWithReason(e3Id, FailureReason(reason));
708
+ }
709
+
710
+ ////////////////////////////////////////////////////////////
711
+ // //
712
+ // Lifecycle Functions //
713
+ // //
714
+ ////////////////////////////////////////////////////////////
715
+
716
+ /// @notice Anyone can mark an E3 as failed if timeout passed
717
+ /// @param e3Id The E3 ID
718
+ /// @return reason The failure reason
719
+ function markE3Failed(
720
+ uint256 e3Id
721
+ ) external returns (FailureReason reason) {
722
+ E3Stage current = _e3Stages[e3Id];
723
+
724
+ if (current == E3Stage.None)
725
+ revert InvalidStage(e3Id, E3Stage.Requested, current);
726
+ if (current == E3Stage.Complete) revert E3AlreadyComplete(e3Id);
727
+ if (current == E3Stage.Failed) revert E3AlreadyFailed(e3Id);
728
+
729
+ bool canFail;
730
+ (canFail, reason) = _checkFailureCondition(e3Id, current);
731
+ if (!canFail) revert FailureConditionNotMet(e3Id);
732
+
733
+ _e3Stages[e3Id] = E3Stage.Failed;
734
+ _e3FailureReasons[e3Id] = reason;
735
+
736
+ emit E3StageChanged(e3Id, current, E3Stage.Failed);
737
+ emit E3Failed(e3Id, current, reason);
738
+ }
739
+
740
+ /// @notice Internal function to mark E3 as failed with specific reason
741
+ /// @param e3Id The E3 ID
742
+ /// @param reason The failure reason
743
+ function _markE3FailedWithReason(
744
+ uint256 e3Id,
745
+ FailureReason reason
746
+ ) internal {
747
+ E3Stage current = _e3Stages[e3Id];
748
+
749
+ if (current == E3Stage.None)
750
+ revert InvalidStage(e3Id, E3Stage.Requested, current);
751
+ if (current == E3Stage.Complete) revert E3AlreadyComplete(e3Id);
752
+ if (current == E3Stage.Failed) revert E3AlreadyFailed(e3Id);
753
+
754
+ _e3Stages[e3Id] = E3Stage.Failed;
755
+ _e3FailureReasons[e3Id] = reason;
756
+
757
+ emit E3StageChanged(e3Id, current, E3Stage.Failed);
758
+ emit E3Failed(e3Id, current, reason);
759
+ }
760
+
761
+ /// @notice Check if E3 can be marked as failed
762
+ /// @param e3Id The E3 ID
763
+ /// @return canFail Whether failure condition is met
764
+ /// @return reason The failure reason if applicable
765
+ function checkFailureCondition(
766
+ uint256 e3Id
767
+ ) external view returns (bool canFail, FailureReason reason) {
768
+ E3Stage current = _e3Stages[e3Id];
769
+ return _checkFailureCondition(e3Id, current);
770
+ }
771
+
772
+ /// @notice Internal function to check failure conditions
773
+ function _checkFailureCondition(
774
+ uint256 e3Id,
775
+ E3Stage stage
776
+ ) internal view returns (bool canFail, FailureReason reason) {
777
+ E3Deadlines memory d = _e3Deadlines[e3Id];
778
+
779
+ uint256 committeeDeadline = ciphernodeRegistry.getCommitteeDeadline(
780
+ e3Id
781
+ );
782
+
783
+ if (stage == E3Stage.Requested && block.timestamp > committeeDeadline) {
784
+ return (true, FailureReason.CommitteeFormationTimeout);
785
+ }
786
+ if (
787
+ stage == E3Stage.CommitteeFinalized &&
788
+ block.timestamp > d.dkgDeadline
789
+ ) {
790
+ return (true, FailureReason.DKGTimeout);
791
+ }
792
+ if (
793
+ stage == E3Stage.KeyPublished && block.timestamp > d.computeDeadline
794
+ ) {
795
+ return (true, FailureReason.ComputeTimeout);
796
+ }
797
+ if (
798
+ stage == E3Stage.CiphertextReady &&
799
+ block.timestamp > d.decryptionDeadline
800
+ ) {
801
+ return (true, FailureReason.DecryptionTimeout);
802
+ }
803
+
804
+ return (false, FailureReason.None);
805
+ }
806
+
807
+ /// @notice Get current stage of an E3
808
+ /// @param e3Id The E3 ID
809
+ /// @return stage The current stage
810
+ function getE3Stage(uint256 e3Id) external view returns (E3Stage stage) {
811
+ return _e3Stages[e3Id];
812
+ }
813
+
814
+ /// @notice Get failure reason for an E3
815
+ /// @param e3Id The E3 ID
816
+ /// @return reason The failure reason
817
+ function getFailureReason(
818
+ uint256 e3Id
819
+ ) external view returns (FailureReason reason) {
820
+ return _e3FailureReasons[e3Id];
821
+ }
822
+
823
+ /// @notice Get requester address for an E3
824
+ /// @param e3Id The E3 ID
825
+ /// @return requester The requester address
826
+ function getRequester(
827
+ uint256 e3Id
828
+ ) external view returns (address requester) {
829
+ return _e3Requesters[e3Id];
830
+ }
831
+
832
+ /// @notice Get deadlines for an E3
833
+ /// @param e3Id The E3 ID
834
+ /// @return deadlines The E3 deadlines
835
+ function getDeadlines(
836
+ uint256 e3Id
837
+ ) external view returns (E3Deadlines memory deadlines) {
838
+ return _e3Deadlines[e3Id];
839
+ }
840
+
841
+ /// @notice Get timeout configuration
842
+ /// @return config The current timeout config
843
+ function getTimeoutConfig()
844
+ external
845
+ view
846
+ returns (E3TimeoutConfig memory config)
847
+ {
848
+ return _timeoutConfig;
849
+ }
850
+
851
+ /// @notice Set timeout configuration
852
+ /// @param config The new timeout config
853
+ function setTimeoutConfig(
854
+ E3TimeoutConfig calldata config
855
+ ) external onlyOwner {
856
+ _setTimeoutConfig(config);
857
+ }
858
+
859
+ /// @notice Internal function to set timeout config
860
+ function _setTimeoutConfig(E3TimeoutConfig calldata config) internal {
861
+ require(config.dkgWindow > 0, "Invalid DKG window");
862
+ require(config.computeWindow > 0, "Invalid compute window");
863
+ require(config.decryptionWindow > 0, "Invalid decryption window");
864
+ require(config.gracePeriod > 0, "Invalid grace period");
865
+
866
+ _timeoutConfig = config;
867
+
868
+ emit TimeoutConfigUpdated(config);
869
+ }
870
+
564
871
  ////////////////////////////////////////////////////////////
565
872
  // //
566
873
  // Get Functions //