@proto-kit/protocol 0.1.1-develop.165 → 0.1.1-develop.1665

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 (441) hide show
  1. package/dist/Constants.js +1 -0
  2. package/dist/Constants.js.map +1 -0
  3. package/dist/hashing/mina-prefixes.d.ts +10 -0
  4. package/dist/hashing/mina-prefixes.d.ts.map +1 -0
  5. package/dist/hashing/mina-prefixes.js +10 -0
  6. package/dist/hashing/mina-prefixes.js.map +1 -0
  7. package/dist/hashing/protokit-prefixes.d.ts +10 -0
  8. package/dist/hashing/protokit-prefixes.d.ts.map +1 -0
  9. package/dist/hashing/protokit-prefixes.js +24 -0
  10. package/dist/hashing/protokit-prefixes.js.map +1 -0
  11. package/dist/hooks/AccountStateHook.d.ts +52 -0
  12. package/dist/hooks/AccountStateHook.d.ts.map +1 -0
  13. package/dist/hooks/AccountStateHook.js +52 -0
  14. package/dist/hooks/AccountStateHook.js.map +1 -0
  15. package/dist/hooks/BlockHeightHook.d.ts +7 -0
  16. package/dist/hooks/BlockHeightHook.d.ts.map +1 -0
  17. package/dist/hooks/BlockHeightHook.js +16 -0
  18. package/dist/hooks/BlockHeightHook.js.map +1 -0
  19. package/dist/hooks/LastStateRootBlockHook.d.ts +7 -0
  20. package/dist/hooks/LastStateRootBlockHook.d.ts.map +1 -0
  21. package/dist/hooks/LastStateRootBlockHook.js +16 -0
  22. package/dist/hooks/LastStateRootBlockHook.js.map +1 -0
  23. package/dist/hooks/NoopBlockHook.d.ts +8 -0
  24. package/dist/hooks/NoopBlockHook.d.ts.map +1 -0
  25. package/dist/hooks/NoopBlockHook.js +10 -0
  26. package/dist/hooks/NoopBlockHook.js.map +1 -0
  27. package/dist/hooks/NoopSettlementHook.d.ts +6 -0
  28. package/dist/hooks/NoopSettlementHook.d.ts.map +1 -0
  29. package/dist/{prover/statetransition/StateTransitionWitnessProvider.js → hooks/NoopSettlementHook.js} +8 -7
  30. package/dist/hooks/NoopSettlementHook.js.map +1 -0
  31. package/dist/hooks/NoopTransactionHook.d.ts +6 -0
  32. package/dist/hooks/NoopTransactionHook.d.ts.map +1 -0
  33. package/dist/hooks/NoopTransactionHook.js +11 -0
  34. package/dist/hooks/NoopTransactionHook.js.map +1 -0
  35. package/dist/index.d.ts +51 -9
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +52 -9
  38. package/dist/index.js.map +1 -0
  39. package/dist/model/AppliedStateTransitionBatch.d.ts +114 -0
  40. package/dist/model/AppliedStateTransitionBatch.d.ts.map +1 -0
  41. package/dist/model/AppliedStateTransitionBatch.js +16 -0
  42. package/dist/model/AppliedStateTransitionBatch.js.map +1 -0
  43. package/dist/model/MethodPublicOutput.d.ts +83 -29
  44. package/dist/model/MethodPublicOutput.d.ts.map +1 -1
  45. package/dist/model/MethodPublicOutput.js +4 -1
  46. package/dist/model/MethodPublicOutput.js.map +1 -0
  47. package/dist/model/Option.d.ts +70 -42
  48. package/dist/model/Option.d.ts.map +1 -1
  49. package/dist/model/Option.js +62 -47
  50. package/dist/model/Option.js.map +1 -0
  51. package/dist/model/Path.d.ts +4 -3
  52. package/dist/model/Path.d.ts.map +1 -1
  53. package/dist/model/Path.js +6 -5
  54. package/dist/model/Path.js.map +1 -0
  55. package/dist/model/RuntimeLike.d.ts +11 -0
  56. package/dist/model/RuntimeLike.d.ts.map +1 -0
  57. package/dist/model/RuntimeLike.js +2 -0
  58. package/dist/model/RuntimeLike.js.map +1 -0
  59. package/dist/model/StateTransition.d.ts +67 -16
  60. package/dist/model/StateTransition.d.ts.map +1 -1
  61. package/dist/model/StateTransition.js +18 -2
  62. package/dist/model/StateTransition.js.map +1 -0
  63. package/dist/model/StateTransitionProvableBatch.d.ts +389 -16
  64. package/dist/model/StateTransitionProvableBatch.d.ts.map +1 -1
  65. package/dist/model/StateTransitionProvableBatch.js +88 -11
  66. package/dist/model/StateTransitionProvableBatch.js.map +1 -0
  67. package/dist/model/network/NetworkState.d.ts +105 -9
  68. package/dist/model/network/NetworkState.d.ts.map +1 -1
  69. package/dist/model/network/NetworkState.js +20 -2
  70. package/dist/model/network/NetworkState.js.map +1 -0
  71. package/dist/model/transaction/RuntimeTransaction.d.ts +96 -28
  72. package/dist/model/transaction/RuntimeTransaction.d.ts.map +1 -1
  73. package/dist/model/transaction/RuntimeTransaction.js +75 -11
  74. package/dist/model/transaction/RuntimeTransaction.js.map +1 -0
  75. package/dist/model/transaction/SignedTransaction.d.ts +107 -0
  76. package/dist/model/transaction/SignedTransaction.d.ts.map +1 -0
  77. package/dist/model/transaction/SignedTransaction.js +34 -0
  78. package/dist/model/transaction/SignedTransaction.js.map +1 -0
  79. package/dist/model/transaction/ValueOption.d.ts +173 -0
  80. package/dist/model/transaction/ValueOption.d.ts.map +1 -0
  81. package/dist/model/transaction/ValueOption.js +25 -0
  82. package/dist/model/transaction/ValueOption.js.map +1 -0
  83. package/dist/protocol/Protocol.d.ts +27 -25
  84. package/dist/protocol/Protocol.d.ts.map +1 -1
  85. package/dist/protocol/Protocol.js +98 -28
  86. package/dist/protocol/Protocol.js.map +1 -0
  87. package/dist/protocol/ProtocolEnvironment.d.ts +9 -0
  88. package/dist/protocol/ProtocolEnvironment.d.ts.map +1 -0
  89. package/dist/protocol/ProtocolEnvironment.js +2 -0
  90. package/dist/protocol/ProtocolEnvironment.js.map +1 -0
  91. package/dist/protocol/ProtocolModule.d.ts +7 -7
  92. package/dist/protocol/ProtocolModule.d.ts.map +1 -1
  93. package/dist/protocol/ProtocolModule.js +10 -7
  94. package/dist/protocol/ProtocolModule.js.map +1 -0
  95. package/dist/protocol/ProvableBlockHook.d.ts +19 -0
  96. package/dist/protocol/ProvableBlockHook.d.ts.map +1 -0
  97. package/dist/protocol/ProvableBlockHook.js +21 -0
  98. package/dist/protocol/ProvableBlockHook.js.map +1 -0
  99. package/dist/protocol/ProvableTransactionHook.d.ts +34 -0
  100. package/dist/protocol/ProvableTransactionHook.d.ts.map +1 -0
  101. package/dist/protocol/ProvableTransactionHook.js +13 -0
  102. package/dist/protocol/ProvableTransactionHook.js.map +1 -0
  103. package/dist/protocol/TransitioningProtocolModule.d.ts +10 -0
  104. package/dist/protocol/TransitioningProtocolModule.d.ts.map +1 -0
  105. package/dist/protocol/TransitioningProtocolModule.js +9 -0
  106. package/dist/protocol/TransitioningProtocolModule.js.map +1 -0
  107. package/dist/prover/accumulators/AppliedBatchHashList.d.ts +18 -0
  108. package/dist/prover/accumulators/AppliedBatchHashList.d.ts.map +1 -0
  109. package/dist/prover/accumulators/AppliedBatchHashList.js +25 -0
  110. package/dist/prover/accumulators/AppliedBatchHashList.js.map +1 -0
  111. package/dist/prover/accumulators/StateTransitionReductionList.d.ts +12 -0
  112. package/dist/prover/accumulators/StateTransitionReductionList.d.ts.map +1 -0
  113. package/dist/prover/accumulators/StateTransitionReductionList.js +64 -0
  114. package/dist/prover/accumulators/StateTransitionReductionList.js.map +1 -0
  115. package/dist/prover/accumulators/TransactionHashList.d.ts +6 -0
  116. package/dist/prover/accumulators/TransactionHashList.d.ts.map +1 -0
  117. package/dist/prover/accumulators/TransactionHashList.js +8 -0
  118. package/dist/prover/accumulators/TransactionHashList.js.map +1 -0
  119. package/dist/prover/accumulators/WitnessedRootHashList.d.ts +137 -0
  120. package/dist/prover/accumulators/WitnessedRootHashList.d.ts.map +1 -0
  121. package/dist/prover/accumulators/WitnessedRootHashList.js +50 -0
  122. package/dist/prover/accumulators/WitnessedRootHashList.js.map +1 -0
  123. package/dist/prover/block/BlockProvable.d.ts +869 -65
  124. package/dist/prover/block/BlockProvable.d.ts.map +1 -1
  125. package/dist/prover/block/BlockProvable.js +86 -6
  126. package/dist/prover/block/BlockProvable.js.map +1 -0
  127. package/dist/prover/block/BlockProver.d.ts +82 -34
  128. package/dist/prover/block/BlockProver.d.ts.map +1 -1
  129. package/dist/prover/block/BlockProver.js +505 -86
  130. package/dist/prover/block/BlockProver.js.map +1 -0
  131. package/dist/prover/block/accummulators/BlockHashMerkleTree.d.ts +106 -0
  132. package/dist/prover/block/accummulators/BlockHashMerkleTree.d.ts.map +1 -0
  133. package/dist/prover/block/accummulators/BlockHashMerkleTree.js +25 -0
  134. package/dist/prover/block/accummulators/BlockHashMerkleTree.js.map +1 -0
  135. package/dist/prover/block/accummulators/RuntimeVerificationKeyTree.d.ts +139 -0
  136. package/dist/prover/block/accummulators/RuntimeVerificationKeyTree.d.ts.map +1 -0
  137. package/dist/prover/block/accummulators/RuntimeVerificationKeyTree.js +21 -0
  138. package/dist/prover/block/accummulators/RuntimeVerificationKeyTree.js.map +1 -0
  139. package/dist/prover/block/services/RuntimeVerificationKeyRootService.d.ts +7 -0
  140. package/dist/prover/block/services/RuntimeVerificationKeyRootService.d.ts.map +1 -0
  141. package/dist/prover/{statetransition/StateTransitionWitnessProviderReference.js → block/services/RuntimeVerificationKeyRootService.js} +11 -8
  142. package/dist/prover/block/services/RuntimeVerificationKeyRootService.js.map +1 -0
  143. package/dist/prover/statetransition/StateTransitionProvable.d.ts +137 -48
  144. package/dist/prover/statetransition/StateTransitionProvable.d.ts.map +1 -1
  145. package/dist/prover/statetransition/StateTransitionProvable.js +10 -5
  146. package/dist/prover/statetransition/StateTransitionProvable.js.map +1 -0
  147. package/dist/prover/statetransition/StateTransitionProver.d.ts +30 -17
  148. package/dist/prover/statetransition/StateTransitionProver.d.ts.map +1 -1
  149. package/dist/prover/statetransition/StateTransitionProver.js +169 -74
  150. package/dist/prover/statetransition/StateTransitionProver.js.map +1 -0
  151. package/dist/settlement/ContractModule.d.ts +16 -0
  152. package/dist/settlement/ContractModule.d.ts.map +1 -0
  153. package/dist/settlement/ContractModule.js +12 -0
  154. package/dist/settlement/ContractModule.js.map +1 -0
  155. package/dist/settlement/SettlementContractModule.d.ts +51 -0
  156. package/dist/settlement/SettlementContractModule.d.ts.map +1 -0
  157. package/dist/settlement/SettlementContractModule.js +80 -0
  158. package/dist/settlement/SettlementContractModule.js.map +1 -0
  159. package/dist/settlement/contracts/BridgeContract.d.ts +116 -0
  160. package/dist/settlement/contracts/BridgeContract.d.ts.map +1 -0
  161. package/dist/settlement/contracts/BridgeContract.js +259 -0
  162. package/dist/settlement/contracts/BridgeContract.js.map +1 -0
  163. package/dist/settlement/contracts/BridgeContractProtocolModule.d.ts +16 -0
  164. package/dist/settlement/contracts/BridgeContractProtocolModule.d.ts.map +1 -0
  165. package/dist/settlement/contracts/BridgeContractProtocolModule.js +41 -0
  166. package/dist/settlement/contracts/BridgeContractProtocolModule.js.map +1 -0
  167. package/dist/settlement/contracts/DispatchContractProtocolModule.d.ts +21 -0
  168. package/dist/settlement/contracts/DispatchContractProtocolModule.d.ts.map +1 -0
  169. package/dist/settlement/contracts/DispatchContractProtocolModule.js +57 -0
  170. package/dist/settlement/contracts/DispatchContractProtocolModule.js.map +1 -0
  171. package/dist/settlement/contracts/DispatchSmartContract.d.ts +44 -0
  172. package/dist/settlement/contracts/DispatchSmartContract.d.ts.map +1 -0
  173. package/dist/settlement/contracts/DispatchSmartContract.js +229 -0
  174. package/dist/settlement/contracts/DispatchSmartContract.js.map +1 -0
  175. package/dist/settlement/contracts/SettlementContractProtocolModule.d.ts +21 -0
  176. package/dist/settlement/contracts/SettlementContractProtocolModule.d.ts.map +1 -0
  177. package/dist/settlement/contracts/SettlementContractProtocolModule.js +84 -0
  178. package/dist/settlement/contracts/SettlementContractProtocolModule.js.map +1 -0
  179. package/dist/settlement/contracts/SettlementSmartContract.d.ts +123 -0
  180. package/dist/settlement/contracts/SettlementSmartContract.d.ts.map +1 -0
  181. package/dist/settlement/contracts/SettlementSmartContract.js +310 -0
  182. package/dist/settlement/contracts/SettlementSmartContract.js.map +1 -0
  183. package/dist/settlement/contracts/TokenBridgeTree.d.ts +228 -0
  184. package/dist/settlement/contracts/TokenBridgeTree.d.ts.map +1 -0
  185. package/dist/settlement/contracts/TokenBridgeTree.js +60 -0
  186. package/dist/settlement/contracts/TokenBridgeTree.js.map +1 -0
  187. package/dist/settlement/contracts/authorizations/ContractAuthorization.d.ts +10 -0
  188. package/dist/settlement/contracts/authorizations/ContractAuthorization.d.ts.map +1 -0
  189. package/dist/settlement/contracts/authorizations/ContractAuthorization.js +2 -0
  190. package/dist/settlement/contracts/authorizations/ContractAuthorization.js.map +1 -0
  191. package/dist/settlement/contracts/authorizations/TokenBridgeDeploymentAuth.d.ts +85 -0
  192. package/dist/settlement/contracts/authorizations/TokenBridgeDeploymentAuth.d.ts.map +1 -0
  193. package/dist/settlement/contracts/authorizations/TokenBridgeDeploymentAuth.js +11 -0
  194. package/dist/settlement/contracts/authorizations/TokenBridgeDeploymentAuth.js.map +1 -0
  195. package/dist/settlement/contracts/authorizations/UpdateMessagesHashAuth.d.ts +79 -0
  196. package/dist/settlement/contracts/authorizations/UpdateMessagesHashAuth.d.ts.map +1 -0
  197. package/dist/settlement/contracts/authorizations/UpdateMessagesHashAuth.js +11 -0
  198. package/dist/settlement/contracts/authorizations/UpdateMessagesHashAuth.js.map +1 -0
  199. package/dist/settlement/messages/Deposit.d.ts +77 -0
  200. package/dist/settlement/messages/Deposit.d.ts.map +1 -0
  201. package/dist/settlement/messages/Deposit.js +8 -0
  202. package/dist/settlement/messages/Deposit.js.map +1 -0
  203. package/dist/settlement/messages/OutgoingMessage.d.ts +67 -0
  204. package/dist/settlement/messages/OutgoingMessage.d.ts.map +1 -0
  205. package/dist/settlement/messages/OutgoingMessage.js +7 -0
  206. package/dist/settlement/messages/OutgoingMessage.js.map +1 -0
  207. package/dist/settlement/messages/OutgoingMessageArgument.d.ts +462 -0
  208. package/dist/settlement/messages/OutgoingMessageArgument.d.ts.map +1 -0
  209. package/dist/settlement/messages/OutgoingMessageArgument.js +40 -0
  210. package/dist/settlement/messages/OutgoingMessageArgument.js.map +1 -0
  211. package/dist/settlement/modularity/OutgoingMessageProcessor.d.ts +25 -0
  212. package/dist/settlement/modularity/OutgoingMessageProcessor.d.ts.map +1 -0
  213. package/dist/settlement/modularity/OutgoingMessageProcessor.js +30 -0
  214. package/dist/settlement/modularity/OutgoingMessageProcessor.js.map +1 -0
  215. package/dist/settlement/modularity/ProvableSettlementHook.d.ts +26 -0
  216. package/dist/settlement/modularity/ProvableSettlementHook.d.ts.map +1 -0
  217. package/dist/settlement/modularity/ProvableSettlementHook.js +4 -0
  218. package/dist/settlement/modularity/ProvableSettlementHook.js.map +1 -0
  219. package/dist/settlement/modularity/types.d.ts +8 -0
  220. package/dist/settlement/modularity/types.d.ts.map +1 -0
  221. package/dist/settlement/modularity/types.js +2 -0
  222. package/dist/settlement/modularity/types.js.map +1 -0
  223. package/dist/settlement/modules/NetworkStateSettlementModule.d.ts +11 -0
  224. package/dist/settlement/modules/NetworkStateSettlementModule.d.ts.map +1 -0
  225. package/dist/settlement/modules/NetworkStateSettlementModule.js +15 -0
  226. package/dist/settlement/modules/NetworkStateSettlementModule.js.map +1 -0
  227. package/dist/state/State.d.ts +68 -0
  228. package/dist/state/State.d.ts.map +1 -0
  229. package/dist/state/State.js +131 -0
  230. package/dist/state/State.js.map +1 -0
  231. package/dist/state/StateMap.d.ts +37 -0
  232. package/dist/state/StateMap.d.ts.map +1 -0
  233. package/dist/state/StateMap.js +56 -0
  234. package/dist/state/StateMap.js.map +1 -0
  235. package/dist/state/StateService.d.ts +6 -0
  236. package/dist/state/StateService.d.ts.map +1 -0
  237. package/dist/state/StateService.js +2 -0
  238. package/dist/state/StateService.js.map +1 -0
  239. package/dist/state/StateServiceProvider.d.ts +8 -0
  240. package/dist/state/StateServiceProvider.d.ts.map +1 -0
  241. package/dist/state/StateServiceProvider.js +37 -0
  242. package/dist/state/StateServiceProvider.js.map +1 -0
  243. package/dist/state/assert/assert.d.ts +12 -0
  244. package/dist/state/assert/assert.d.ts.map +1 -0
  245. package/dist/state/assert/assert.js +33 -0
  246. package/dist/state/assert/assert.js.map +1 -0
  247. package/dist/state/context/RuntimeMethodExecutionContext.d.ts +193 -0
  248. package/dist/state/context/RuntimeMethodExecutionContext.d.ts.map +1 -0
  249. package/dist/state/context/RuntimeMethodExecutionContext.js +138 -0
  250. package/dist/state/context/RuntimeMethodExecutionContext.js.map +1 -0
  251. package/dist/state/context/TransitionMethodExecutionContext.d.ts +23 -0
  252. package/dist/state/context/TransitionMethodExecutionContext.d.ts.map +1 -0
  253. package/dist/state/context/TransitionMethodExecutionContext.js +6 -0
  254. package/dist/state/context/TransitionMethodExecutionContext.js.map +1 -0
  255. package/dist/state/protocol/ProtocolState.d.ts +13 -0
  256. package/dist/state/protocol/ProtocolState.d.ts.map +1 -0
  257. package/dist/state/protocol/ProtocolState.js +58 -0
  258. package/dist/state/protocol/ProtocolState.js.map +1 -0
  259. package/dist/utils/FieldOptions.d.ts +62 -0
  260. package/dist/utils/FieldOptions.d.ts.map +1 -0
  261. package/dist/utils/FieldOptions.js +13 -0
  262. package/dist/utils/FieldOptions.js.map +1 -0
  263. package/dist/utils/MinaPrefixedProvableHashList.d.ts +19 -0
  264. package/dist/utils/MinaPrefixedProvableHashList.d.ts.map +1 -0
  265. package/dist/utils/MinaPrefixedProvableHashList.js +46 -0
  266. package/dist/utils/MinaPrefixedProvableHashList.js.map +1 -0
  267. package/dist/utils/PrefixedProvableHashList.d.ts +2 -2
  268. package/dist/utils/PrefixedProvableHashList.d.ts.map +1 -1
  269. package/dist/utils/PrefixedProvableHashList.js +2 -1
  270. package/dist/utils/PrefixedProvableHashList.js.map +1 -0
  271. package/dist/utils/ProvableHashList.d.ts +23 -4
  272. package/dist/utils/ProvableHashList.d.ts.map +1 -1
  273. package/dist/utils/ProvableHashList.js +38 -2
  274. package/dist/utils/ProvableHashList.js.map +1 -0
  275. package/dist/utils/ProvableReductionHashList.d.ts +18 -0
  276. package/dist/utils/ProvableReductionHashList.d.ts.map +1 -0
  277. package/dist/utils/ProvableReductionHashList.js +54 -0
  278. package/dist/utils/ProvableReductionHashList.js.map +1 -0
  279. package/dist/utils/utils.d.ts +20 -0
  280. package/dist/utils/utils.d.ts.map +1 -0
  281. package/dist/utils/utils.js +51 -0
  282. package/dist/utils/utils.js.map +1 -0
  283. package/jest.config.cjs +12 -1
  284. package/package.json +11 -9
  285. package/src/hashing/mina-prefixes.ts +10 -0
  286. package/src/hashing/protokit-prefixes.ts +37 -0
  287. package/src/hooks/AccountStateHook.ts +57 -0
  288. package/src/hooks/BlockHeightHook.ts +17 -0
  289. package/src/hooks/LastStateRootBlockHook.ts +25 -0
  290. package/src/hooks/NoopBlockHook.ts +24 -0
  291. package/src/hooks/NoopSettlementHook.ts +20 -0
  292. package/src/hooks/NoopTransactionHook.ts +13 -0
  293. package/src/index.ts +51 -9
  294. package/src/model/AppliedStateTransitionBatch.ts +16 -0
  295. package/src/model/MethodPublicOutput.ts +3 -1
  296. package/src/model/Option.ts +99 -60
  297. package/src/model/Path.ts +9 -5
  298. package/src/model/RuntimeLike.ts +12 -0
  299. package/src/model/StateTransition.ts +25 -3
  300. package/src/model/StateTransitionProvableBatch.ts +117 -14
  301. package/src/model/Transaction.ts +3 -1
  302. package/src/model/network/NetworkState.ts +21 -3
  303. package/src/model/transaction/RuntimeTransaction.ts +90 -15
  304. package/src/model/transaction/SignedTransaction.ts +47 -0
  305. package/src/model/transaction/ValueOption.ts +28 -0
  306. package/src/protocol/Protocol.ts +166 -74
  307. package/src/protocol/ProtocolEnvironment.ts +10 -0
  308. package/src/protocol/ProtocolModule.ts +16 -16
  309. package/src/protocol/ProvableBlockHook.ts +68 -0
  310. package/src/protocol/ProvableTransactionHook.ts +77 -0
  311. package/src/protocol/TransitioningProtocolModule.ts +12 -0
  312. package/src/prover/accumulators/AppliedBatchHashList.ts +32 -0
  313. package/src/prover/accumulators/StateTransitionReductionList.ts +92 -0
  314. package/src/prover/accumulators/TransactionHashList.ts +9 -0
  315. package/src/prover/accumulators/WitnessedRootHashList.ts +61 -0
  316. package/src/prover/block/BlockProvable.ts +188 -15
  317. package/src/prover/block/BlockProver.ts +979 -143
  318. package/src/prover/block/accummulators/BlockHashMerkleTree.ts +24 -0
  319. package/src/prover/block/accummulators/RuntimeVerificationKeyTree.ts +24 -0
  320. package/src/prover/block/services/RuntimeVerificationKeyRootService.ts +20 -0
  321. package/src/prover/statetransition/StateTransitionProvable.ts +26 -19
  322. package/src/prover/statetransition/StateTransitionProver.ts +338 -130
  323. package/src/settlement/ContractModule.ts +31 -0
  324. package/src/settlement/SettlementContractModule.ts +145 -0
  325. package/src/settlement/contracts/BridgeContract.ts +366 -0
  326. package/src/settlement/contracts/BridgeContractProtocolModule.ts +48 -0
  327. package/src/settlement/contracts/DispatchContractProtocolModule.ts +75 -0
  328. package/src/settlement/contracts/DispatchSmartContract.ts +325 -0
  329. package/src/settlement/contracts/SettlementContractProtocolModule.ts +113 -0
  330. package/src/settlement/contracts/SettlementSmartContract.ts +502 -0
  331. package/src/settlement/contracts/TokenBridgeTree.ts +73 -0
  332. package/src/settlement/contracts/authorizations/ContractAuthorization.ts +11 -0
  333. package/src/settlement/contracts/authorizations/TokenBridgeDeploymentAuth.ts +16 -0
  334. package/src/settlement/contracts/authorizations/UpdateMessagesHashAuth.ts +16 -0
  335. package/src/settlement/messages/Deposit.ts +7 -0
  336. package/src/settlement/messages/OutgoingMessage.ts +17 -0
  337. package/src/settlement/messages/OutgoingMessageArgument.ts +53 -0
  338. package/src/settlement/modularity/OutgoingMessageProcessor.ts +65 -0
  339. package/src/settlement/modularity/ProvableSettlementHook.ts +36 -0
  340. package/src/settlement/modularity/types.ts +22 -0
  341. package/src/settlement/modules/NetworkStateSettlementModule.ts +42 -0
  342. package/src/state/State.ts +177 -0
  343. package/src/state/StateMap.ts +73 -0
  344. package/src/state/StateService.ts +6 -0
  345. package/src/state/StateServiceProvider.ts +37 -0
  346. package/src/state/assert/assert.ts +38 -0
  347. package/src/state/context/RuntimeMethodExecutionContext.ts +181 -0
  348. package/src/state/context/TransitionMethodExecutionContext.ts +26 -0
  349. package/src/state/protocol/ProtocolState.ts +98 -0
  350. package/src/utils/FieldOptions.ts +13 -0
  351. package/src/utils/MinaPrefixedProvableHashList.ts +66 -0
  352. package/src/utils/PrefixedProvableHashList.ts +2 -2
  353. package/src/utils/ProvableHashList.ts +78 -3
  354. package/src/utils/ProvableReductionHashList.ts +77 -0
  355. package/src/utils/utils.ts +44 -55
  356. package/test/BlockProver.test.ts +161 -74
  357. package/test/Protocol.test.ts +20 -10
  358. package/test/State.test.ts +45 -0
  359. package/test/StateTransition.test.ts +57 -65
  360. package/test/TestingProtocol.ts +56 -0
  361. package/test/compiling/types.ts +28 -0
  362. package/test/model/Option.test.ts +72 -0
  363. package/test/model/StateTransitionProvableBatch.test.ts +137 -0
  364. package/test/modularity/types.ts +35 -0
  365. package/test/prover/block/BlockProver.test.ts +18 -0
  366. package/test/prover/statetransition/StateTransitionProver.test.ts +261 -0
  367. package/test/state/assert/assert.test.ts +56 -0
  368. package/test/tsconfig.json +7 -0
  369. package/test/utils/ProvableHashList.test.ts +44 -0
  370. package/test/utils/ProvableReductionHashList.test.ts +117 -0
  371. package/test/utils.test.ts +27 -0
  372. package/dist/config/ConfigurableModule.d.ts +0 -18
  373. package/dist/config/ConfigurableModule.d.ts.map +0 -1
  374. package/dist/config/ConfigurableModule.js +0 -20
  375. package/dist/config/ConfigurationAggregator.d.ts +0 -10
  376. package/dist/config/ConfigurationAggregator.d.ts.map +0 -1
  377. package/dist/config/ConfigurationAggregator.js +0 -35
  378. package/dist/config/ConfigurationReceiver.d.ts +0 -25
  379. package/dist/config/ConfigurationReceiver.d.ts.map +0 -1
  380. package/dist/config/ConfigurationReceiver.js +0 -36
  381. package/dist/config/ModuleContainer.d.ts +0 -44
  382. package/dist/config/ModuleContainer.d.ts.map +0 -1
  383. package/dist/config/ModuleContainer.js +0 -89
  384. package/dist/config/types.d.ts +0 -2
  385. package/dist/config/types.d.ts.map +0 -1
  386. package/dist/config/types.js +0 -1
  387. package/dist/model/MethodPublicInput.d.ts +0 -51
  388. package/dist/model/MethodPublicInput.d.ts.map +0 -1
  389. package/dist/model/MethodPublicInput.js +0 -11
  390. package/dist/model/transaction/ProtocolTransaction.d.ts +0 -70
  391. package/dist/model/transaction/ProtocolTransaction.d.ts.map +0 -1
  392. package/dist/model/transaction/ProtocolTransaction.js +0 -18
  393. package/dist/prover/block/BlockScopedModule.d.ts +0 -3
  394. package/dist/prover/block/BlockScopedModule.d.ts.map +0 -1
  395. package/dist/prover/block/BlockScopedModule.js +0 -6
  396. package/dist/prover/statetransition/StateTransitionWitnessProvider.d.ts +0 -16
  397. package/dist/prover/statetransition/StateTransitionWitnessProvider.d.ts.map +0 -1
  398. package/dist/prover/statetransition/StateTransitionWitnessProviderReference.d.ts +0 -7
  399. package/dist/prover/statetransition/StateTransitionWitnessProviderReference.d.ts.map +0 -1
  400. package/dist/src/model/Option.d.ts +0 -158
  401. package/dist/src/model/Option.d.ts.map +0 -1
  402. package/dist/src/model/Option.js +0 -53
  403. package/dist/src/model/Path.d.ts +0 -35
  404. package/dist/src/model/Path.d.ts.map +0 -1
  405. package/dist/src/model/Path.js +0 -51
  406. package/dist/src/model/StateTransition.d.ts +0 -201
  407. package/dist/src/model/StateTransition.d.ts.map +0 -1
  408. package/dist/src/model/StateTransition.js +0 -43
  409. package/dist/src/utils/PrefixedHashList.d.ts +0 -15
  410. package/dist/src/utils/PrefixedHashList.d.ts.map +0 -1
  411. package/dist/src/utils/PrefixedHashList.js +0 -28
  412. package/dist/src/utils/ProvableHashList.d.ts +0 -30
  413. package/dist/src/utils/ProvableHashList.d.ts.map +0 -1
  414. package/dist/src/utils/ProvableHashList.js +0 -43
  415. package/dist/utils/PrefixedHashList.d.ts +0 -14
  416. package/dist/utils/PrefixedHashList.d.ts.map +0 -1
  417. package/dist/utils/PrefixedHashList.js +0 -12
  418. package/dist/utils/Utils.d.ts +0 -17
  419. package/dist/utils/Utils.d.ts.map +0 -1
  420. package/dist/utils/Utils.js +0 -64
  421. package/dist/utils/merkletree/InMemoryMerkleTreeStorage.d.ts +0 -25
  422. package/dist/utils/merkletree/InMemoryMerkleTreeStorage.d.ts.map +0 -1
  423. package/dist/utils/merkletree/InMemoryMerkleTreeStorage.js +0 -77
  424. package/dist/utils/merkletree/MemoryMerkleTreeStorage.d.ts +0 -26
  425. package/dist/utils/merkletree/MemoryMerkleTreeStorage.d.ts.map +0 -1
  426. package/dist/utils/merkletree/MemoryMerkleTreeStorage.js +0 -79
  427. package/dist/utils/merkletree/MerkleTreeStore.d.ts +0 -11
  428. package/dist/utils/merkletree/MerkleTreeStore.d.ts.map +0 -1
  429. package/dist/utils/merkletree/MerkleTreeStore.js +0 -1
  430. package/dist/utils/merkletree/RollupMerkleTree.d.ts +0 -130
  431. package/dist/utils/merkletree/RollupMerkleTree.d.ts.map +0 -1
  432. package/dist/utils/merkletree/RollupMerkleTree.js +0 -244
  433. package/src/model/Option.test.ts +0 -21
  434. package/src/model/transaction/ProtocolTransaction.ts +0 -25
  435. package/src/prover/statetransition/StateTransitionWitnessProvider.ts +0 -24
  436. package/src/prover/statetransition/StateTransitionWitnessProviderReference.ts +0 -17
  437. package/src/utils/merkletree/InMemoryMerkleTreeStorage.ts +0 -106
  438. package/src/utils/merkletree/MerkleTreeStore.ts +0 -15
  439. package/src/utils/merkletree/RollupMerkleTree.ts +0 -250
  440. package/src/utils/merkletree/VirtualMerkleTreeStore.ts +0 -21
  441. package/tsconfig.test.json +0 -9
@@ -1,201 +1,750 @@
1
- /* eslint-disable max-lines */
2
- import { Experimental, Field, type Proof, Provable, SelfProof } from "snarkyjs";
3
- import { inject, injectable } from "tsyringe";
4
1
  import {
2
+ Bool,
3
+ Field,
4
+ Proof,
5
+ Provable,
6
+ SelfProof,
7
+ VerificationKey,
8
+ ZkProgram,
9
+ } from "o1js";
10
+ import { container, inject, injectable, injectAll } from "tsyringe";
11
+ import {
12
+ AreProofsEnabled,
13
+ CompilableModule,
14
+ CompileArtifact,
15
+ CompileRegistry,
16
+ log,
17
+ MAX_FIELD,
5
18
  PlainZkProgram,
6
19
  provableMethod,
7
20
  WithZkProgrammable,
8
21
  ZkProgrammable,
9
22
  } from "@proto-kit/common";
10
23
 
11
- import { DefaultProvableHashList } from "../../utils/ProvableHashList";
12
24
  import { MethodPublicOutput } from "../../model/MethodPublicOutput";
13
25
  import { ProtocolModule } from "../../protocol/ProtocolModule";
14
26
  import {
15
27
  StateTransitionProof,
28
+ StateTransitionProvable,
16
29
  StateTransitionProverPublicInput,
17
30
  StateTransitionProverPublicOutput,
18
31
  } from "../statetransition/StateTransitionProvable";
19
32
  import { RuntimeTransaction } from "../../model/transaction/RuntimeTransaction";
33
+ import {
34
+ ProvableStateTransition,
35
+ StateTransition,
36
+ } from "../../model/StateTransition";
37
+ import {
38
+ AfterTransactionHookArguments,
39
+ BeforeTransactionHookArguments,
40
+ ProvableTransactionHook,
41
+ toProvableHookBlockState,
42
+ } from "../../protocol/ProvableTransactionHook";
43
+ import {
44
+ RuntimeMethodExecutionContext,
45
+ RuntimeMethodExecutionData,
46
+ } from "../../state/context/RuntimeMethodExecutionContext";
47
+ import {
48
+ AfterBlockHookArguments,
49
+ BeforeBlockHookArguments,
50
+ ProvableBlockHook,
51
+ toAfterTransactionHookArgument,
52
+ toBeforeTransactionHookArgument,
53
+ } from "../../protocol/ProvableBlockHook";
54
+ import { NetworkState } from "../../model/network/NetworkState";
55
+ import { SignedTransaction } from "../../model/transaction/SignedTransaction";
56
+ import { MinaActions } from "../../utils/MinaPrefixedProvableHashList";
57
+ import { StateTransitionReductionList } from "../accumulators/StateTransitionReductionList";
58
+ import { assertEqualsIf } from "../../utils/utils";
59
+ import { WitnessedRootWitness } from "../accumulators/WitnessedRootHashList";
60
+ import { StateServiceProvider } from "../../state/StateServiceProvider";
61
+ import { AppliedStateTransitionBatch } from "../../model/AppliedStateTransitionBatch";
20
62
 
21
63
  import {
22
64
  BlockProvable,
23
- BlockProverExecutionData,
24
65
  BlockProverProof,
25
66
  BlockProverPublicInput,
26
67
  BlockProverPublicOutput,
68
+ DynamicRuntimeProof,
69
+ BlockProverMultiTransactionExecutionData,
70
+ BlockProverTransactionArguments,
71
+ BlockProverSingleTransactionExecutionData,
72
+ BlockProverState,
73
+ BlockProverStateCommitments,
27
74
  } from "./BlockProvable";
75
+ import {
76
+ BlockHashMerkleTreeWitness,
77
+ BlockHashTreeEntry,
78
+ } from "./accummulators/BlockHashMerkleTree";
79
+ import {
80
+ MethodVKConfigData,
81
+ MinimalVKTreeService,
82
+ RuntimeVerificationKeyAttestation,
83
+ } from "./accummulators/RuntimeVerificationKeyTree";
84
+ import { RuntimeVerificationKeyRootService } from "./services/RuntimeVerificationKeyRootService";
28
85
 
29
86
  const errors = {
30
- stateProofNotStartingAtZero: () =>
31
- "StateProof not starting ST-commitment at zero",
32
-
33
- stateTransitionsHashNotEqual: () =>
34
- "StateTransition list commitments are not equal",
87
+ propertyNotMatchingStep: (propertyName: string, step: string) =>
88
+ `${propertyName} not matching: ${step}`,
35
89
 
36
90
  propertyNotMatching: (propertyName: string) => `${propertyName} not matching`,
37
91
 
38
- stateRootNotMatching: (step: string) => `StateRoots not matching ${step}`,
92
+ stateRootNotMatching: (step: string) =>
93
+ errors.propertyNotMatchingStep("StateRoots", step),
39
94
 
40
95
  transactionsHashNotMatching: (step: string) =>
41
- `transactions hash not matching ${step}`,
42
- };
96
+ errors.propertyNotMatchingStep("Transactions hash", step),
43
97
 
44
- export interface BlockProverState {
45
- // The current state root of the block prover
46
- stateRoot: Field;
98
+ networkStateHashNotMatching: (step: string) =>
99
+ errors.propertyNotMatchingStep("Network state hash", step),
47
100
 
48
- /**
49
- * The current commitment of the transaction-list which
50
- * will at the end equal the bundle hash
51
- */
52
- transactionsHash: Field;
101
+ invalidZkProgramTreeRoot: () =>
102
+ "Root hash of the provided zkProgram config witness is invalid",
103
+ };
53
104
 
54
- /**
55
- * The network state which gives access to values such as blockHeight
56
- * This value is the same for the whole batch (L2 block)
57
- */
58
- networkStateHash: Field;
59
- }
105
+ type ApplyTransactionArguments = Omit<
106
+ BlockProverTransactionArguments,
107
+ "verificationKeyAttestation"
108
+ >;
60
109
 
61
- /**
62
- * BlockProver class, which aggregates a AppChainProof and
63
- * a StateTransitionProof into a single BlockProof, that can
64
- * then be merged to be committed to the base-layer contract
65
- */
66
- @injectable()
67
- export class BlockProver
68
- extends ProtocolModule<BlockProverPublicInput, BlockProverPublicOutput>
69
- implements BlockProvable
70
- {
110
+ export type BlockProof = Proof<BlockProverPublicInput, BlockProverPublicOutput>;
111
+
112
+ export class BlockProverProgrammable extends ZkProgrammable<
113
+ BlockProverPublicInput,
114
+ BlockProverPublicOutput
115
+ > {
71
116
  public constructor(
72
- @inject("StateTransitionProver")
73
- private readonly stateTransitionProver: ZkProgrammable<
117
+ private readonly prover: BlockProver,
118
+ public readonly stateTransitionProver: ZkProgrammable<
74
119
  StateTransitionProverPublicInput,
75
120
  StateTransitionProverPublicOutput
76
121
  >,
77
- @inject("Runtime")
78
- private readonly runtime: WithZkProgrammable<void, MethodPublicOutput>
122
+ private readonly transactionHooks: ProvableTransactionHook<unknown>[],
123
+ private readonly blockHooks: ProvableBlockHook<unknown>[],
124
+ private readonly stateServiceProvider: StateServiceProvider,
125
+ private readonly verificationKeyService: MinimalVKTreeService
79
126
  ) {
80
127
  super();
81
128
  }
82
129
 
130
+ name = "BlockProver";
131
+
132
+ public get areProofsEnabled(): AreProofsEnabled | undefined {
133
+ return this.prover.areProofsEnabled;
134
+ }
135
+
83
136
  /**
84
137
  * Applies and checks the two proofs and applies the corresponding state
85
- * changes to the given state
138
+ * changes to the given state.
139
+ *
140
+ * The rough high level workflow of this function:
141
+ * 1. Execute beforeTransaction hooks, pushing the ST batch
142
+ * 2. Add Transaction to bundle, meaning appending it to all the respective commitments
143
+ * 3. Push the runtime ST batch
144
+ * 4. Execute afterTransaction hooks, pushing the ST batch
145
+ * 5. Some consistency checks and signature verification
86
146
  *
87
- * @param state The from-state of the BlockProver
88
- * @param stateTransitionProof
89
- * @param appProof
147
+ * @param fromState The from-state of the BlockProver
148
+ * @param runtimeOutput
149
+ * @param executionData
150
+ * @param networkState
90
151
  * @returns The new BlockProver-state to be used as public output
91
152
  */
92
- public applyTransaction(
93
- state: BlockProverState,
94
- stateTransitionProof: Proof<
95
- StateTransitionProverPublicInput,
96
- StateTransitionProverPublicOutput
97
- >,
98
- appProof: Proof<void, MethodPublicOutput>,
99
- { transaction, networkState }: BlockProverExecutionData
100
- ): BlockProverState {
101
- appProof.verify();
102
- stateTransitionProof.verify();
153
+ public async applyTransaction(
154
+ fromState: BlockProverState,
155
+ runtimeOutput: MethodPublicOutput,
156
+ executionData: ApplyTransactionArguments,
157
+ networkState: NetworkState
158
+ ): Promise<BlockProverState> {
159
+ const { transaction, signature } = executionData;
103
160
 
104
- const stateTo = { ...state };
161
+ let state = { ...fromState };
105
162
 
106
- // eslint-disable-next-line no-warning-comments
107
- // TODO Check methodId?
163
+ const { isMessage } = runtimeOutput;
108
164
 
109
- // Checks for the stateTransitionProof and appProof matching
110
- stateTransitionProof.publicInput.stateTransitionsHash.assertEquals(
111
- Field(0),
112
- errors.stateProofNotStartingAtZero()
165
+ const beforeTxHookArguments = toBeforeTransactionHookArgument(
166
+ executionData,
167
+ networkState,
168
+ state
113
169
  );
114
170
 
115
- appProof.publicOutput.stateTransitionsHash.assertEquals(
116
- stateTransitionProof.publicOutput.stateTransitionsHash,
117
- errors.stateTransitionsHashNotEqual()
171
+ // Apply beforeTransaction hook state transitions
172
+ const beforeBatch = await this.executeTransactionHooks(
173
+ async (module, args) => await module.beforeTransaction(args),
174
+ beforeTxHookArguments
118
175
  );
119
176
 
120
- // Apply state if status success
121
- state.stateRoot.assertEquals(
122
- stateTransitionProof.publicInput.stateRoot,
123
- errors.propertyNotMatching("from state root")
177
+ state = this.addTransactionToBundle(
178
+ state,
179
+ runtimeOutput.isMessage,
180
+ transaction
124
181
  );
125
- stateTo.stateRoot = Provable.if(
126
- appProof.publicOutput.status,
127
- stateTransitionProof.publicOutput.stateRoot,
128
- stateTransitionProof.publicInput.stateRoot
182
+
183
+ state.pendingSTBatches.push(beforeBatch);
184
+
185
+ state.pendingSTBatches.push({
186
+ batchHash: runtimeOutput.stateTransitionsHash,
187
+ applied: runtimeOutput.status,
188
+ });
189
+
190
+ // Apply afterTransaction hook state transitions
191
+ const afterTxHookArguments = toAfterTransactionHookArgument(
192
+ executionData,
193
+ networkState,
194
+ state,
195
+ runtimeOutput
129
196
  );
130
197
 
131
- // Check transaction signature
132
- transaction
133
- .validateSignature()
134
- .assertTrue("Transaction signature not valid");
198
+ // Switch to different state set for afterTx hooks
199
+ this.stateServiceProvider.popCurrentStateService();
135
200
 
136
- // Check if the methodId is correct
137
- // to do
201
+ const afterBatch = await this.executeTransactionHooks(
202
+ async (module, args) => await module.afterTransaction(args),
203
+ afterTxHookArguments
204
+ );
205
+ state.pendingSTBatches.push(afterBatch);
138
206
 
139
207
  // Check transaction integrity against appProof
140
- const blockTransactionHash =
141
- RuntimeTransaction.fromProtocolTransaction(transaction).hash();
208
+ const blockTransactionHash = transaction.hash();
142
209
 
143
210
  blockTransactionHash.assertEquals(
144
- appProof.publicOutput.transactionHash,
211
+ runtimeOutput.transactionHash,
145
212
  "Transactions provided in AppProof and BlockProof do not match"
146
213
  );
147
214
 
215
+ // Check transaction signature
216
+ new SignedTransaction({
217
+ transaction,
218
+ signature,
219
+ })
220
+ .validateSignature()
221
+ .or(isMessage)
222
+ .assertTrue("Transaction signature not valid");
223
+
224
+ // Validate layout of transaction witness
225
+ transaction.assertTransactionType(isMessage);
226
+
148
227
  // Check network state integrity against appProof
149
- state.networkStateHash.assertEquals(
150
- appProof.publicOutput.networkStateHash,
151
- "Network state does not match state used in AppProof"
152
- );
153
- state.networkStateHash.assertEquals(
154
- networkState.hash(),
155
- "Network state provided to BlockProver does not match the publicInput"
228
+ state.networkState
229
+ .hash()
230
+ .assertEquals(
231
+ runtimeOutput.networkStateHash,
232
+ "Network state does not match state used in AppProof"
233
+ );
234
+
235
+ return state;
236
+ }
237
+
238
+ // eslint-disable-next-line max-len
239
+ // TODO How does this interact with the RuntimeMethodExecutionContext when executing runtimemethods?
240
+
241
+ /**
242
+ * Constructs a AppliedBatch based on a list of STs and the flag whether to
243
+ * be applied or not. The AppliedBatch is a condensed commitment to a batch
244
+ * of STs.
245
+ */
246
+ private constructBatch(
247
+ stateTransitions: StateTransition<any>[],
248
+ applied: Bool
249
+ ) {
250
+ const transitions = stateTransitions.map((transition) =>
251
+ transition.toProvable()
156
252
  );
157
253
 
254
+ const hashList = new StateTransitionReductionList(ProvableStateTransition);
255
+ transitions.forEach((transition) => {
256
+ hashList.push(transition);
257
+ });
258
+
259
+ return new AppliedStateTransitionBatch({
260
+ batchHash: hashList.commitment,
261
+ applied,
262
+ });
263
+ }
264
+
265
+ private async executeTransactionHooks<
266
+ T extends BeforeTransactionHookArguments | AfterTransactionHookArguments,
267
+ >(
268
+ hook: (module: ProvableTransactionHook<unknown>, args: T) => Promise<void>,
269
+ hookArguments: T
270
+ ) {
271
+ const { batch } = await this.executeHooks(hookArguments, async () => {
272
+ for (const module of this.transactionHooks) {
273
+ // eslint-disable-next-line no-await-in-loop
274
+ await hook(module, hookArguments);
275
+ }
276
+ });
277
+ return batch;
278
+ }
279
+
280
+ private async executeHooks<T>(
281
+ contextArguments: RuntimeMethodExecutionData,
282
+ method: () => Promise<T>
283
+ ) {
284
+ const executionContext = container.resolve(RuntimeMethodExecutionContext);
285
+ executionContext.clear();
286
+
287
+ // Setup context for potential calls to runtime methods.
288
+ // This way they can use this.transaction etc. while still having provable
289
+ // integrity between data
290
+ executionContext.setup(contextArguments);
291
+ executionContext.beforeMethod("", "", []);
292
+
293
+ const result = await method();
294
+
295
+ executionContext.afterMethod();
296
+
297
+ const { stateTransitions, status, statusMessage } =
298
+ executionContext.current().result;
299
+
300
+ status.assertTrue(`Transaction hook call failed: ${statusMessage ?? "-"}`);
301
+
302
+ return {
303
+ batch: this.constructBatch(stateTransitions, Bool(true)),
304
+ result,
305
+ };
306
+ }
307
+
308
+ public async executeBlockHooks<
309
+ T extends BeforeBlockHookArguments | AfterBlockHookArguments,
310
+ >(
311
+ hook: (
312
+ module: ProvableBlockHook<unknown>,
313
+ networkState: NetworkState,
314
+ args: T
315
+ ) => Promise<NetworkState>,
316
+ hookArguments: T,
317
+ inputNetworkState: NetworkState
318
+ ) {
319
+ const transaction = RuntimeTransaction.dummyTransaction();
320
+ const startingInputs = {
321
+ transaction,
322
+ networkState: inputNetworkState,
323
+ };
324
+
325
+ return await this.executeHooks(startingInputs, async () => {
326
+ const executionContext = container.resolve(RuntimeMethodExecutionContext);
327
+
328
+ return await this.blockHooks.reduce<Promise<NetworkState>>(
329
+ async (networkStatePromise, blockHook) => {
330
+ const networkState = await networkStatePromise;
331
+
332
+ // Setup context for potential calls to runtime methods.
333
+ // With the special case that we set the new networkstate for every hook
334
+ // We also have to put in a dummy transaction for network.transaction
335
+ executionContext.setup({
336
+ transaction: RuntimeTransaction.dummyTransaction(),
337
+ networkState,
338
+ });
339
+
340
+ return await hook(blockHook, networkState, hookArguments);
341
+ },
342
+ Promise.resolve(inputNetworkState)
343
+ );
344
+ });
345
+ }
346
+
347
+ public addTransactionToBundle<
348
+ T extends Pick<
349
+ BlockProverState,
350
+ "transactionList" | "eternalTransactionsList" | "incomingMessages"
351
+ >,
352
+ >(state: T, isMessage: Bool, transaction: RuntimeTransaction): T {
353
+ const transactionHash = transaction.hash();
354
+
158
355
  // Append tx to transaction list
159
- const transactionList = new DefaultProvableHashList(
160
- Field,
161
- state.transactionsHash
356
+ state.transactionList.pushIf(transactionHash, isMessage.not());
357
+
358
+ // Append tx to eternal transaction list
359
+ // TODO Change that to the a sequence-state compatible transaction struct
360
+ state.eternalTransactionsList.push(transactionHash);
361
+
362
+ // Append tx to incomingMessagesHash
363
+ const actionHash = MinaActions.actionHash(transaction.hashData());
364
+
365
+ state.incomingMessages.pushIf(actionHash, isMessage);
366
+
367
+ return state;
368
+ }
369
+
370
+ private verifyVerificationKeyAttestation(
371
+ attestation: RuntimeVerificationKeyAttestation,
372
+ methodId: Field
373
+ ): VerificationKey {
374
+ // Verify the [methodId, vk] tuple against the baked-in vk tree root
375
+ const { verificationKey, witness: verificationKeyTreeWitness } =
376
+ attestation;
377
+
378
+ const root = Field(this.verificationKeyService.getRoot());
379
+ const calculatedRoot = verificationKeyTreeWitness.calculateRoot(
380
+ new MethodVKConfigData({
381
+ methodId: methodId,
382
+ vkHash: verificationKey.hash,
383
+ }).hash()
384
+ );
385
+ root.assertEquals(calculatedRoot, errors.invalidZkProgramTreeRoot());
386
+
387
+ return verificationKey;
388
+ }
389
+
390
+ public async proveTransactionInternal(
391
+ fromState: BlockProverState,
392
+ runtimeProof: DynamicRuntimeProof,
393
+ { transaction, networkState }: BlockProverSingleTransactionExecutionData
394
+ ): Promise<BlockProverState> {
395
+ const verificationKey = this.verifyVerificationKeyAttestation(
396
+ transaction.verificationKeyAttestation,
397
+ transaction.transaction.methodId
162
398
  );
163
399
 
164
- const { transactionHash } = appProof.publicOutput;
165
- transactionList.push(transactionHash);
400
+ runtimeProof.verify(verificationKey);
166
401
 
167
- stateTo.transactionsHash = transactionList.commitment;
402
+ return await this.applyTransaction(
403
+ fromState,
404
+ runtimeProof.publicOutput,
405
+ transaction,
406
+ networkState
407
+ );
408
+ }
168
409
 
169
- return stateTo;
410
+ private staticChecks(publicInput: BlockProverPublicInput) {
411
+ publicInput.blockNumber.assertEquals(
412
+ MAX_FIELD,
413
+ "blockNumber has to be MAX for transaction proofs"
414
+ );
170
415
  }
171
416
 
172
417
  @provableMethod()
173
- public proveTransaction(
418
+ public async proveTransaction(
174
419
  publicInput: BlockProverPublicInput,
175
- stateProof: StateTransitionProof,
176
- appProof: Proof<void, MethodPublicOutput>,
177
- executionData: BlockProverExecutionData
178
- ): BlockProverPublicOutput {
179
- const state: BlockProverState = {
180
- transactionsHash: publicInput.transactionsHash,
181
- stateRoot: publicInput.stateRoot,
182
- networkStateHash: publicInput.networkStateHash,
420
+ runtimeProof: DynamicRuntimeProof,
421
+ executionData: BlockProverSingleTransactionExecutionData
422
+ ): Promise<BlockProverPublicOutput> {
423
+ const state = BlockProverStateCommitments.toBlockProverState(
424
+ publicInput,
425
+ executionData.networkState
426
+ );
427
+
428
+ this.staticChecks(publicInput);
429
+
430
+ const stateTo = await this.proveTransactionInternal(
431
+ state,
432
+ runtimeProof,
433
+ executionData
434
+ );
435
+
436
+ return new BlockProverPublicOutput({
437
+ ...BlockProverStateCommitments.fromBlockProverState(stateTo),
438
+ closed: Bool(false),
439
+ });
440
+ }
441
+
442
+ @provableMethod()
443
+ public async proveTransactions(
444
+ publicInput: BlockProverPublicInput,
445
+ runtimeProof1: DynamicRuntimeProof,
446
+ runtimeProof2: DynamicRuntimeProof,
447
+ executionData: BlockProverMultiTransactionExecutionData
448
+ ): Promise<BlockProverPublicOutput> {
449
+ const state = BlockProverStateCommitments.toBlockProverState(
450
+ publicInput,
451
+ executionData.networkState
452
+ );
453
+
454
+ this.staticChecks(publicInput);
455
+
456
+ const state1 = await this.proveTransactionInternal(state, runtimeProof1, {
457
+ transaction: executionData.transaction1,
458
+ networkState: executionData.networkState,
459
+ });
460
+
461
+ // Switch to next state record for 2nd tx beforeTx hook
462
+ // TODO Can be prevented by merging 1st afterTx + 2nd beforeTx
463
+ this.stateServiceProvider.popCurrentStateService();
464
+
465
+ const stateTo = await this.proveTransactionInternal(state1, runtimeProof2, {
466
+ transaction: executionData.transaction2,
467
+ networkState: executionData.networkState,
468
+ });
469
+
470
+ return new BlockProverPublicOutput({
471
+ ...BlockProverStateCommitments.fromBlockProverState(stateTo),
472
+ closed: Bool(false),
473
+ });
474
+ }
475
+
476
+ public includeSTProof(
477
+ stateTransitionProof: StateTransitionProof,
478
+ apply: Bool,
479
+ stateRoot: Field,
480
+ pendingSTBatchesHash: Field,
481
+ witnessedRootsHash: Field
482
+ ): {
483
+ stateRoot: Field;
484
+ pendingSTBatchesHash: Field;
485
+ witnessedRootsHash: Field;
486
+ } {
487
+ assertEqualsIf(
488
+ stateTransitionProof.publicInput.currentBatchStateHash,
489
+ Field(0),
490
+ apply,
491
+ "State for STProof has to be empty at the start"
492
+ );
493
+ assertEqualsIf(
494
+ stateTransitionProof.publicOutput.currentBatchStateHash,
495
+ Field(0),
496
+ apply,
497
+ "State for STProof has to be empty at the end"
498
+ );
499
+
500
+ assertEqualsIf(
501
+ stateTransitionProof.publicInput.batchesHash,
502
+ Field(0),
503
+ apply,
504
+ "Batcheshash doesn't start at 0"
505
+ );
506
+
507
+ // Assert from state root
508
+ assertEqualsIf(
509
+ stateRoot,
510
+ stateTransitionProof.publicInput.root,
511
+ apply,
512
+ errors.propertyNotMatching("from state root")
513
+ );
514
+
515
+ // Assert the stBatchesHash executed is the same
516
+ assertEqualsIf(
517
+ pendingSTBatchesHash,
518
+ stateTransitionProof.publicOutput.batchesHash,
519
+ apply,
520
+ "Pending STBatches are not the same that have been executed by the ST proof"
521
+ );
522
+
523
+ // Assert root Accumulator
524
+ assertEqualsIf(
525
+ Field(0),
526
+ stateTransitionProof.publicInput.witnessedRootsHash,
527
+ apply,
528
+ errors.propertyNotMatching("from state root")
529
+ );
530
+ // Assert the witnessedRootsHash created is the same
531
+ assertEqualsIf(
532
+ witnessedRootsHash,
533
+ stateTransitionProof.publicOutput.witnessedRootsHash,
534
+ apply,
535
+ "Root accumulator Commitment is not the same that have been executed by the ST proof"
536
+ );
537
+
538
+ // update root only if we didn't defer
539
+ const newRoot = Provable.if(
540
+ apply,
541
+ stateTransitionProof.publicOutput.root,
542
+ stateRoot
543
+ );
544
+ // Reset only if we didn't defer
545
+ const newBatchesHash = Provable.if(apply, Field(0), pendingSTBatchesHash);
546
+ const newWitnessedRootsHash = Provable.if(
547
+ apply,
548
+ Field(0),
549
+ witnessedRootsHash
550
+ );
551
+ return {
552
+ stateRoot: newRoot,
553
+ pendingSTBatchesHash: newBatchesHash,
554
+ witnessedRootsHash: newWitnessedRootsHash,
183
555
  };
556
+ }
184
557
 
185
- const stateTo = this.applyTransaction(state, stateProof, appProof, executionData);
558
+ @provableMethod()
559
+ public async proveBlock(
560
+ publicInput: BlockProverPublicInput,
561
+ networkState: NetworkState,
562
+ blockWitness: BlockHashMerkleTreeWitness,
563
+ stateTransitionProof: StateTransitionProof,
564
+ deferSTProof: Bool,
565
+ afterBlockRootWitness: WitnessedRootWitness,
566
+ transactionProof: BlockProverProof
567
+ ): Promise<BlockProverPublicOutput> {
568
+ // 1. Make assertions about the inputs
569
+ publicInput.transactionsHash.assertEquals(
570
+ Field(0),
571
+ "Transactionshash has to start at 0"
572
+ );
573
+
574
+ // TransactionProof format checks
575
+ transactionProof.publicInput.blockHashRoot.assertEquals(
576
+ Field(0),
577
+ "TransactionProof cannot carry the blockHashRoot - publicInput"
578
+ );
579
+ transactionProof.publicOutput.blockHashRoot.assertEquals(
580
+ Field(0),
581
+ "TransactionProof cannot carry the blockHashRoot - publicOutput"
582
+ );
583
+ transactionProof.publicInput.networkStateHash.assertEquals(
584
+ transactionProof.publicOutput.networkStateHash,
585
+ "TransactionProof cannot alter the network state"
586
+ );
587
+
588
+ const state = BlockProverStateCommitments.toBlockProverState(
589
+ publicInput,
590
+ networkState
591
+ );
592
+
593
+ // Verify Transaction proof if it has at least 1 tx - i.e. the
594
+ // input and output doesn't match fully
595
+ // We have to compare the whole input and output because we can make no
596
+ // assumptions about the values, since it can be an arbitrary dummy-proof
597
+ const txProofOutput = transactionProof.publicOutput;
598
+ const isEmptyTransition = txProofOutput.equals(
599
+ transactionProof.publicInput,
600
+ txProofOutput.closed
601
+ );
602
+ const skipTransactionProofVerification = isEmptyTransition;
603
+ const verifyTransactionProof = isEmptyTransition.not();
604
+ log.provable.debug("VerifyIf TxProof", verifyTransactionProof);
605
+ transactionProof.verifyIf(verifyTransactionProof);
606
+
607
+ // 2. Execute beforeBlock hooks
608
+ const beforeBlockArgs = toProvableHookBlockState(state);
609
+ const beforeBlockResult = await this.executeBlockHooks(
610
+ async (module, networkStateArg, args) =>
611
+ await module.beforeBlock(networkStateArg, args),
612
+ beforeBlockArgs,
613
+ networkState
614
+ );
615
+
616
+ state.pendingSTBatches.push(beforeBlockResult.batch);
617
+
618
+ // 4. Apply TX-type BlockProof
619
+ transactionProof.publicInput.networkStateHash
620
+ .equals(beforeBlockResult.result.hash())
621
+ .or(skipTransactionProofVerification)
622
+ .assertTrue(
623
+ "TransactionProof networkstate hash not matching beforeBlock hook result"
624
+ );
625
+ transactionProof.publicInput.stateRoot.assertEquals(
626
+ transactionProof.publicOutput.stateRoot,
627
+ "TransactionProofs can't change the state root"
628
+ );
629
+
630
+ // Check that the transaction proof's STs start after the beforeBlock hook
631
+ transactionProof.publicInput.pendingSTBatchesHash.assertEquals(
632
+ state.pendingSTBatches.commitment,
633
+ "Transaction proof doesn't start their STs after the beforeBlockHook"
634
+ );
635
+ // Fast-forward the stBatchHashList to after all transactions appended
636
+ state.pendingSTBatches.commitment =
637
+ transactionProof.publicOutput.pendingSTBatchesHash;
638
+
639
+ // Fast-forward block content commitments by the results of the aggregated transaction proof
640
+ // Implicitly, the 'from' values here are asserted against the publicInput, since the hashlists
641
+ // are created out of the public input
642
+ state.transactionList.fastForward({
643
+ from: transactionProof.publicInput.transactionsHash,
644
+ to: transactionProof.publicOutput.transactionsHash,
645
+ });
646
+ state.eternalTransactionsList.fastForward({
647
+ from: transactionProof.publicInput.eternalTransactionsHash,
648
+ to: transactionProof.publicOutput.eternalTransactionsHash,
649
+ });
650
+ state.incomingMessages.fastForward({
651
+ from: transactionProof.publicInput.incomingMessagesHash,
652
+ to: transactionProof.publicOutput.incomingMessagesHash,
653
+ });
654
+
655
+ // Witness root
656
+ const isEmpty = state.pendingSTBatches.commitment.equals(0);
657
+ isEmpty
658
+ .implies(state.stateRoot.equals(afterBlockRootWitness.witnessedRoot))
659
+ .assertTrue();
660
+
661
+ state.witnessedRoots.witnessRoot(
662
+ {
663
+ appliedBatchListState: state.pendingSTBatches.commitment,
664
+ root: afterBlockRootWitness.witnessedRoot,
665
+ },
666
+ afterBlockRootWitness.preimage,
667
+ isEmpty.not()
668
+ );
669
+
670
+ // 5. Calculate the new block tree hash
671
+ const blockIndex = blockWitness.calculateIndex();
672
+
673
+ blockIndex.assertEquals(publicInput.blockNumber);
674
+
675
+ blockWitness
676
+ .calculateRoot(Field(0))
677
+ .assertEquals(
678
+ publicInput.blockHashRoot,
679
+ "Supplied block hash witness not matching state root"
680
+ );
681
+
682
+ state.blockHashRoot = blockWitness.calculateRoot(
683
+ new BlockHashTreeEntry({
684
+ block: {
685
+ index: blockIndex,
686
+ transactionListHash: state.transactionList.commitment,
687
+ },
688
+ closed: Bool(true),
689
+ }).hash()
690
+ );
691
+
692
+ // 6. Execute afterBlock hooks
693
+
694
+ // Switch state service to afterBlock one
695
+ this.stateServiceProvider.popCurrentStateService();
696
+
697
+ const afterBlockHookArgs = toProvableHookBlockState(state);
698
+ const afterBlockResult = await this.executeBlockHooks(
699
+ async (module, networkStateArg, args) =>
700
+ await module.afterBlock(networkStateArg, args),
701
+ {
702
+ ...afterBlockHookArgs,
703
+ stateRoot: afterBlockRootWitness.witnessedRoot,
704
+ },
705
+ beforeBlockResult.result
706
+ );
707
+
708
+ state.pendingSTBatches.push(afterBlockResult.batch);
709
+
710
+ state.networkState = afterBlockResult.result;
711
+
712
+ // 7. Close block
713
+
714
+ // Verify ST Proof only if STs have been emitted,
715
+ // and we don't defer the verification of the STs
716
+ // otherwise we can input a dummy proof
717
+ const batchesEmpty = state.pendingSTBatches.commitment.equals(Field(0));
718
+ const verifyStProof = deferSTProof.not().and(batchesEmpty.not());
719
+ log.provable.debug("Verify STProof", verifyStProof);
720
+ stateTransitionProof.verifyIf(verifyStProof);
721
+
722
+ // Apply STProof if not deferred
723
+ const stateProofResult = this.includeSTProof(
724
+ stateTransitionProof,
725
+ verifyStProof,
726
+ state.stateRoot,
727
+ state.pendingSTBatches.commitment,
728
+ state.witnessedRoots.commitment
729
+ );
730
+ state.stateRoot = stateProofResult.stateRoot;
731
+ state.pendingSTBatches.commitment = stateProofResult.pendingSTBatchesHash;
732
+ state.witnessedRoots.commitment = stateProofResult.witnessedRootsHash;
733
+
734
+ state.blockNumber = blockIndex.add(1);
186
735
 
187
736
  return new BlockProverPublicOutput({
188
- stateRoot: stateTo.stateRoot,
189
- transactionsHash: stateTo.transactionsHash,
737
+ ...BlockProverStateCommitments.fromBlockProverState(state),
738
+ closed: Bool(true),
190
739
  });
191
740
  }
192
741
 
193
742
  @provableMethod()
194
- public merge(
743
+ public async merge(
195
744
  publicInput: BlockProverPublicInput,
196
745
  proof1: BlockProverProof,
197
746
  proof2: BlockProverProof
198
- ): BlockProverPublicOutput {
747
+ ): Promise<BlockProverPublicOutput> {
199
748
  proof1.verify();
200
749
  proof2.verify();
201
750
 
@@ -209,19 +758,144 @@ export class BlockProver
209
758
  errors.stateRootNotMatching("proof1.to -> proof2.from")
210
759
  );
211
760
 
212
- // Check transaction list
213
- publicInput.transactionsHash.assertEquals(
214
- proof1.publicInput.transactionsHash,
761
+ // Check transaction list hash.
762
+ // Only assert them if these are tx proofs, skip for closed proofs
763
+ publicInput.transactionsHash
764
+ .equals(proof1.publicInput.transactionsHash)
765
+ .or(proof1.publicOutput.closed)
766
+ .assertTrue(
767
+ errors.transactionsHashNotMatching("publicInput.from -> proof1.from")
768
+ );
769
+ proof1.publicOutput.transactionsHash
770
+ .equals(proof2.publicInput.transactionsHash)
771
+ .or(proof1.publicOutput.closed)
772
+ .assertTrue(
773
+ errors.transactionsHashNotMatching("proof1.to -> proof2.from")
774
+ );
775
+
776
+ // Check networkhash
777
+ publicInput.networkStateHash.assertEquals(
778
+ proof1.publicInput.networkStateHash,
779
+ errors.networkStateHashNotMatching("publicInput.from -> proof1.from")
780
+ );
781
+ proof1.publicOutput.networkStateHash.assertEquals(
782
+ proof2.publicInput.networkStateHash,
783
+ errors.networkStateHashNotMatching("proof1.to -> proof2.from")
784
+ );
785
+
786
+ // Check blockHashRoot
787
+ publicInput.blockHashRoot.assertEquals(
788
+ proof1.publicInput.blockHashRoot,
215
789
  errors.transactionsHashNotMatching("publicInput.from -> proof1.from")
216
790
  );
217
- proof1.publicOutput.transactionsHash.assertEquals(
218
- proof2.publicInput.transactionsHash,
791
+ proof1.publicOutput.blockHashRoot.assertEquals(
792
+ proof2.publicInput.blockHashRoot,
219
793
  errors.transactionsHashNotMatching("proof1.to -> proof2.from")
220
794
  );
221
795
 
796
+ // Check eternalTransactionsHash
797
+ publicInput.eternalTransactionsHash.assertEquals(
798
+ proof1.publicInput.eternalTransactionsHash,
799
+ errors.transactionsHashNotMatching("publicInput.from -> proof1.from")
800
+ );
801
+ proof1.publicOutput.eternalTransactionsHash.assertEquals(
802
+ proof2.publicInput.eternalTransactionsHash,
803
+ errors.transactionsHashNotMatching("proof1.to -> proof2.from")
804
+ );
805
+
806
+ // Check incomingMessagesHash
807
+ publicInput.incomingMessagesHash.assertEquals(
808
+ proof1.publicInput.incomingMessagesHash,
809
+ errors.propertyNotMatchingStep(
810
+ "IncomingMessagesHash",
811
+ "publicInput.from -> proof1.from"
812
+ )
813
+ );
814
+ proof1.publicOutput.incomingMessagesHash.assertEquals(
815
+ proof2.publicInput.incomingMessagesHash,
816
+ errors.propertyNotMatchingStep(
817
+ "IncomingMessagesHash",
818
+ "proof1.to -> proof2.from"
819
+ )
820
+ );
821
+
822
+ // Check pendingSTBatchesHash
823
+ publicInput.pendingSTBatchesHash.assertEquals(
824
+ proof1.publicInput.pendingSTBatchesHash,
825
+ errors.transactionsHashNotMatching("publicInput.from -> proof1.from")
826
+ );
827
+ proof1.publicOutput.pendingSTBatchesHash.assertEquals(
828
+ proof2.publicInput.pendingSTBatchesHash,
829
+ errors.transactionsHashNotMatching("proof1.to -> proof2.from")
830
+ );
831
+
832
+ // Check witnessedRootsHash
833
+ publicInput.witnessedRootsHash.assertEquals(
834
+ proof1.publicInput.witnessedRootsHash,
835
+ errors.transactionsHashNotMatching("publicInput.from -> proof1.from")
836
+ );
837
+ proof1.publicOutput.witnessedRootsHash.assertEquals(
838
+ proof2.publicInput.witnessedRootsHash,
839
+ errors.transactionsHashNotMatching("proof1.to -> proof2.from")
840
+ );
841
+
842
+ // Assert closed indicator matches
843
+ // (i.e. we can only merge TX-Type and Block-Type with each other)
844
+ proof1.publicOutput.closed.assertEquals(
845
+ proof2.publicOutput.closed,
846
+ "Closed indicators not matching"
847
+ );
848
+
849
+ // Either
850
+ // blockNumbers are unset and proofs are unclosed or
851
+ // both blocks are closed, then they have to increment or
852
+ // one block is closed, then height has to be the same
853
+
854
+ // Imperative algo would look like
855
+ // if(proof1.height == MAX && proof2.height == MAX){
856
+ // assert !proof1.closed && !proof2.closed;
857
+ // }else if(proof1.closed && proof2.closed){
858
+ // assert proof1.height + 1 == proof2.height
859
+ // // next one is omitted for now
860
+ // }else if(proof1.closed || proof2.closed{
861
+ // assert proof1.height == proof2.height
862
+ // }
863
+
864
+ const proof1Closed = proof1.publicOutput.closed;
865
+ const proof2Closed = proof2.publicOutput.closed;
866
+
867
+ const blockNumberProgressionValid = publicInput.blockNumber
868
+ .equals(proof1.publicInput.blockNumber)
869
+ .and(
870
+ proof1.publicOutput.blockNumber.equals(proof2.publicInput.blockNumber)
871
+ );
872
+
873
+ // For tx proofs, we check that the progression starts and end with MAX
874
+ // in addition to that both proofs are non-closed
875
+ const isValidTransactionMerge = publicInput.blockNumber
876
+ .equals(MAX_FIELD)
877
+ .and(blockNumberProgressionValid)
878
+ .and(proof1Closed.or(proof2Closed).not());
879
+
880
+ const isValidClosedMerge = proof1Closed
881
+ .and(proof2Closed)
882
+ .and(blockNumberProgressionValid);
883
+
884
+ isValidTransactionMerge
885
+ .or(isValidClosedMerge)
886
+ .assertTrue("Invalid BlockProof merge");
887
+
222
888
  return new BlockProverPublicOutput({
223
889
  stateRoot: proof2.publicOutput.stateRoot,
224
890
  transactionsHash: proof2.publicOutput.transactionsHash,
891
+ networkStateHash: proof2.publicOutput.networkStateHash,
892
+ blockHashRoot: proof2.publicOutput.blockHashRoot,
893
+ eternalTransactionsHash: proof2.publicOutput.eternalTransactionsHash,
894
+ incomingMessagesHash: proof2.publicOutput.incomingMessagesHash,
895
+ closed: isValidClosedMerge,
896
+ blockNumber: proof2.publicOutput.blockNumber,
897
+ pendingSTBatchesHash: proof2.publicOutput.pendingSTBatchesHash,
898
+ witnessedRootsHash: proof2.publicOutput.witnessedRootsHash,
225
899
  });
226
900
  }
227
901
 
@@ -233,53 +907,103 @@ export class BlockProver
233
907
  public zkProgramFactory(): PlainZkProgram<
234
908
  BlockProverPublicInput,
235
909
  BlockProverPublicOutput
236
- > {
237
- const StateTransitionProofClass =
238
- this.stateTransitionProver.zkProgram.Proof;
239
- const RuntimeProofClass = this.runtime.zkProgrammable.zkProgram.Proof;
240
-
241
- const proveTransaction = this.proveTransaction.bind(this);
242
- const merge = this.merge.bind(this);
910
+ >[] {
911
+ const { prover, stateTransitionProver } = this;
912
+ const StateTransitionProofClass = stateTransitionProver.zkProgram[0].Proof;
913
+ const proveTransaction = prover.proveTransaction.bind(prover);
914
+ const proveTransactions = prover.proveTransactions.bind(prover);
915
+ const proveBlock = prover.proveBlock.bind(prover);
916
+ const merge = prover.merge.bind(prover);
243
917
 
244
- const program = Experimental.ZkProgram({
918
+ const program = ZkProgram({
919
+ name: "BlockProver",
245
920
  publicInput: BlockProverPublicInput,
246
921
  publicOutput: BlockProverPublicOutput,
247
922
 
248
923
  methods: {
249
924
  proveTransaction: {
250
925
  privateInputs: [
251
- StateTransitionProofClass,
252
- RuntimeProofClass,
253
- BlockProverExecutionData,
926
+ DynamicRuntimeProof,
927
+ BlockProverSingleTransactionExecutionData,
928
+ ],
929
+
930
+ async method(
931
+ publicInput: BlockProverPublicInput,
932
+ runtimeProof: DynamicRuntimeProof,
933
+ executionData: BlockProverSingleTransactionExecutionData
934
+ ) {
935
+ return await proveTransaction(
936
+ publicInput,
937
+ runtimeProof,
938
+ executionData
939
+ );
940
+ },
941
+ },
942
+
943
+ proveTransactions: {
944
+ privateInputs: [
945
+ DynamicRuntimeProof,
946
+ DynamicRuntimeProof,
947
+ BlockProverMultiTransactionExecutionData,
254
948
  ],
255
949
 
256
- method(
950
+ async method(
257
951
  publicInput: BlockProverPublicInput,
258
- stateProof: StateTransitionProof,
259
- appProof: Proof<void, MethodPublicOutput>,
260
- executionData: BlockProverExecutionData
952
+ runtimeProof1: DynamicRuntimeProof,
953
+ runtimeProof2: DynamicRuntimeProof,
954
+ executionData: BlockProverMultiTransactionExecutionData
261
955
  ) {
262
- return proveTransaction(
956
+ return await proveTransactions(
263
957
  publicInput,
264
- stateProof,
265
- appProof,
958
+ runtimeProof1,
959
+ runtimeProof2,
266
960
  executionData
267
961
  );
268
962
  },
269
963
  },
270
964
 
965
+ proveBlock: {
966
+ privateInputs: [
967
+ NetworkState,
968
+ BlockHashMerkleTreeWitness,
969
+ StateTransitionProofClass,
970
+ Bool,
971
+ WitnessedRootWitness,
972
+ SelfProof<BlockProverPublicInput, BlockProverPublicOutput>,
973
+ ],
974
+ async method(
975
+ publicInput: BlockProverPublicInput,
976
+ networkState: NetworkState,
977
+ blockWitness: BlockHashMerkleTreeWitness,
978
+ stateTransitionProof: StateTransitionProof,
979
+ deferSTs: Bool,
980
+ afterBlockRootWitness: WitnessedRootWitness,
981
+ transactionProof: BlockProverProof
982
+ ) {
983
+ return await proveBlock(
984
+ publicInput,
985
+ networkState,
986
+ blockWitness,
987
+ stateTransitionProof,
988
+ deferSTs,
989
+ afterBlockRootWitness,
990
+ transactionProof
991
+ );
992
+ },
993
+ },
994
+
271
995
  merge: {
272
996
  privateInputs: [
273
997
  SelfProof<BlockProverPublicInput, BlockProverPublicOutput>,
274
998
  SelfProof<BlockProverPublicInput, BlockProverPublicOutput>,
275
999
  ],
276
1000
 
277
- method(
1001
+ async method(
278
1002
  publicInput: BlockProverPublicInput,
279
1003
  proof1: BlockProverProof,
280
1004
  proof2: BlockProverProof
281
1005
  ) {
282
- return merge(publicInput, proof1, proof2);
1006
+ return await merge(publicInput, proof1, proof2);
283
1007
  },
284
1008
  },
285
1009
  },
@@ -287,16 +1011,128 @@ export class BlockProver
287
1011
 
288
1012
  const methods = {
289
1013
  proveTransaction: program.proveTransaction,
1014
+ proveTransactions: program.proveTransactions,
1015
+ proveBlock: program.proveBlock,
290
1016
  merge: program.merge,
291
1017
  };
292
1018
 
293
- const SelfProofClass = Experimental.ZkProgram.Proof(program);
1019
+ const SelfProofClass = ZkProgram.Proof(program);
294
1020
 
295
- return {
296
- compile: program.compile.bind(program),
297
- verify: program.verify.bind(program),
298
- Proof: SelfProofClass,
299
- methods,
300
- };
1021
+ return [
1022
+ {
1023
+ name: program.name,
1024
+ compile: program.compile.bind(program),
1025
+ verify: program.verify.bind(program),
1026
+ analyzeMethods: program.analyzeMethods.bind(program),
1027
+ Proof: SelfProofClass,
1028
+ methods,
1029
+ },
1030
+ ];
1031
+ }
1032
+ }
1033
+
1034
+ /**
1035
+ * BlockProver class, which aggregates a AppChainProof and
1036
+ * a StateTransitionProof into a single BlockProof, that can
1037
+ * then be merged to be committed to the base-layer contract
1038
+ */
1039
+ @injectable()
1040
+ export class BlockProver
1041
+ extends ProtocolModule
1042
+ implements BlockProvable, CompilableModule
1043
+ {
1044
+ public zkProgrammable: BlockProverProgrammable;
1045
+
1046
+ public constructor(
1047
+ @inject("StateTransitionProver")
1048
+ public readonly stateTransitionProver: WithZkProgrammable<
1049
+ StateTransitionProverPublicInput,
1050
+ StateTransitionProverPublicOutput
1051
+ > &
1052
+ StateTransitionProvable,
1053
+ @inject("Runtime")
1054
+ public readonly runtime: WithZkProgrammable<undefined, MethodPublicOutput> &
1055
+ CompilableModule,
1056
+ @injectAll("ProvableTransactionHook")
1057
+ transactionHooks: ProvableTransactionHook<unknown>[],
1058
+ @injectAll("ProvableBlockHook")
1059
+ blockHooks: ProvableBlockHook<unknown>[],
1060
+ @inject("StateServiceProvider")
1061
+ stateServiceProvider: StateServiceProvider,
1062
+ verificationKeyService: RuntimeVerificationKeyRootService
1063
+ ) {
1064
+ super();
1065
+ this.zkProgrammable = new BlockProverProgrammable(
1066
+ this,
1067
+ stateTransitionProver.zkProgrammable,
1068
+ transactionHooks,
1069
+ blockHooks,
1070
+ stateServiceProvider,
1071
+ verificationKeyService
1072
+ );
1073
+ }
1074
+
1075
+ public async compile(
1076
+ registry: CompileRegistry
1077
+ ): Promise<Record<string, CompileArtifact> | undefined> {
1078
+ return await registry.forceProverExists(async () => {
1079
+ await this.stateTransitionProver.compile(registry);
1080
+ await this.runtime.compile(registry);
1081
+ return await this.zkProgrammable.compile(registry);
1082
+ });
1083
+ }
1084
+
1085
+ public proveTransaction(
1086
+ publicInput: BlockProverPublicInput,
1087
+ runtimeProof: DynamicRuntimeProof,
1088
+ executionData: BlockProverSingleTransactionExecutionData
1089
+ ): Promise<BlockProverPublicOutput> {
1090
+ return this.zkProgrammable.proveTransaction(
1091
+ publicInput,
1092
+ runtimeProof,
1093
+ executionData
1094
+ );
1095
+ }
1096
+
1097
+ public proveTransactions(
1098
+ publicInput: BlockProverPublicInput,
1099
+ runtimeProof1: DynamicRuntimeProof,
1100
+ runtimeProof2: DynamicRuntimeProof,
1101
+ executionData: BlockProverMultiTransactionExecutionData
1102
+ ): Promise<BlockProverPublicOutput> {
1103
+ return this.zkProgrammable.proveTransactions(
1104
+ publicInput,
1105
+ runtimeProof1,
1106
+ runtimeProof2,
1107
+ executionData
1108
+ );
1109
+ }
1110
+
1111
+ public proveBlock(
1112
+ publicInput: BlockProverPublicInput,
1113
+ networkState: NetworkState,
1114
+ blockWitness: BlockHashMerkleTreeWitness,
1115
+ stateTransitionProof: StateTransitionProof,
1116
+ deferSTs: Bool,
1117
+ afterBlockRootWitness: WitnessedRootWitness,
1118
+ transactionProof: BlockProverProof
1119
+ ): Promise<BlockProverPublicOutput> {
1120
+ return this.zkProgrammable.proveBlock(
1121
+ publicInput,
1122
+ networkState,
1123
+ blockWitness,
1124
+ stateTransitionProof,
1125
+ deferSTs,
1126
+ afterBlockRootWitness,
1127
+ transactionProof
1128
+ );
1129
+ }
1130
+
1131
+ public merge(
1132
+ publicInput: BlockProverPublicInput,
1133
+ proof1: BlockProverProof,
1134
+ proof2: BlockProverProof
1135
+ ): Promise<BlockProverPublicOutput> {
1136
+ return this.zkProgrammable.merge(publicInput, proof1, proof2);
301
1137
  }
302
1138
  }