@proto-kit/protocol 0.1.1-develop.1316 → 0.1.1-develop.1347

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 (145) hide show
  1. package/dist/hooks/AccountStateHook.d.ts +3 -3
  2. package/dist/hooks/AccountStateHook.d.ts.map +1 -1
  3. package/dist/hooks/AccountStateHook.js +6 -2
  4. package/dist/hooks/AccountStateHook.js.map +1 -1
  5. package/dist/hooks/LastStateRootBlockHook.d.ts +3 -4
  6. package/dist/hooks/LastStateRootBlockHook.d.ts.map +1 -1
  7. package/dist/hooks/LastStateRootBlockHook.js +4 -4
  8. package/dist/hooks/LastStateRootBlockHook.js.map +1 -1
  9. package/dist/hooks/NoopBlockHook.d.ts +3 -4
  10. package/dist/hooks/NoopBlockHook.d.ts.map +1 -1
  11. package/dist/hooks/NoopBlockHook.js +1 -1
  12. package/dist/hooks/NoopBlockHook.js.map +1 -1
  13. package/dist/hooks/NoopTransactionHook.d.ts +2 -2
  14. package/dist/hooks/NoopTransactionHook.d.ts.map +1 -1
  15. package/dist/hooks/NoopTransactionHook.js +4 -1
  16. package/dist/hooks/NoopTransactionHook.js.map +1 -1
  17. package/dist/index.d.ts +6 -1
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +6 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/model/AppliedStateTransitionBatch.d.ts +114 -0
  22. package/dist/model/AppliedStateTransitionBatch.d.ts.map +1 -0
  23. package/dist/model/AppliedStateTransitionBatch.js +16 -0
  24. package/dist/model/AppliedStateTransitionBatch.js.map +1 -0
  25. package/dist/model/StateTransition.d.ts +1 -0
  26. package/dist/model/StateTransition.d.ts.map +1 -1
  27. package/dist/model/StateTransition.js +5 -0
  28. package/dist/model/StateTransition.js.map +1 -1
  29. package/dist/model/StateTransitionProvableBatch.d.ts +249 -97
  30. package/dist/model/StateTransitionProvableBatch.d.ts.map +1 -1
  31. package/dist/model/StateTransitionProvableBatch.js +72 -65
  32. package/dist/model/StateTransitionProvableBatch.js.map +1 -1
  33. package/dist/model/transaction/RuntimeTransaction.d.ts +1 -0
  34. package/dist/model/transaction/RuntimeTransaction.d.ts.map +1 -1
  35. package/dist/model/transaction/RuntimeTransaction.js +3 -0
  36. package/dist/model/transaction/RuntimeTransaction.js.map +1 -1
  37. package/dist/protocol/ProvableBlockHook.d.ts +13 -3
  38. package/dist/protocol/ProvableBlockHook.d.ts.map +1 -1
  39. package/dist/protocol/ProvableBlockHook.js +16 -0
  40. package/dist/protocol/ProvableBlockHook.js.map +1 -1
  41. package/dist/protocol/ProvableTransactionHook.d.ts +29 -2
  42. package/dist/protocol/ProvableTransactionHook.d.ts.map +1 -1
  43. package/dist/protocol/ProvableTransactionHook.js +9 -0
  44. package/dist/protocol/ProvableTransactionHook.js.map +1 -1
  45. package/dist/prover/accumulators/AppliedBatchHashList.d.ts +18 -0
  46. package/dist/prover/accumulators/AppliedBatchHashList.d.ts.map +1 -0
  47. package/dist/prover/accumulators/AppliedBatchHashList.js +25 -0
  48. package/dist/prover/accumulators/AppliedBatchHashList.js.map +1 -0
  49. package/dist/{utils → prover/accumulators}/StateTransitionReductionList.d.ts +3 -2
  50. package/dist/prover/accumulators/StateTransitionReductionList.d.ts.map +1 -0
  51. package/dist/{utils → prover/accumulators}/StateTransitionReductionList.js +6 -3
  52. package/dist/prover/accumulators/StateTransitionReductionList.js.map +1 -0
  53. package/dist/prover/accumulators/TransactionHashList.d.ts +6 -0
  54. package/dist/prover/accumulators/TransactionHashList.d.ts.map +1 -0
  55. package/dist/prover/accumulators/TransactionHashList.js +8 -0
  56. package/dist/prover/accumulators/TransactionHashList.js.map +1 -0
  57. package/dist/prover/accumulators/WitnessedRootHashList.d.ts +137 -0
  58. package/dist/prover/accumulators/WitnessedRootHashList.d.ts.map +1 -0
  59. package/dist/prover/accumulators/WitnessedRootHashList.js +50 -0
  60. package/dist/prover/accumulators/WitnessedRootHashList.js.map +1 -0
  61. package/dist/prover/block/BlockProvable.d.ts +579 -35
  62. package/dist/prover/block/BlockProvable.d.ts.map +1 -1
  63. package/dist/prover/block/BlockProvable.js +55 -3
  64. package/dist/prover/block/BlockProvable.js.map +1 -1
  65. package/dist/prover/block/BlockProver.d.ts +52 -50
  66. package/dist/prover/block/BlockProver.d.ts.map +1 -1
  67. package/dist/prover/block/BlockProver.js +289 -209
  68. package/dist/prover/block/BlockProver.js.map +1 -1
  69. package/dist/prover/block/accummulators/BlockHashMerkleTree.d.ts +55 -13
  70. package/dist/prover/block/accummulators/BlockHashMerkleTree.d.ts.map +1 -1
  71. package/dist/prover/block/accummulators/BlockHashMerkleTree.js +11 -3
  72. package/dist/prover/block/accummulators/BlockHashMerkleTree.js.map +1 -1
  73. package/dist/prover/statetransition/StateTransitionProvable.d.ts +107 -106
  74. package/dist/prover/statetransition/StateTransitionProvable.d.ts.map +1 -1
  75. package/dist/prover/statetransition/StateTransitionProvable.js +8 -8
  76. package/dist/prover/statetransition/StateTransitionProvable.js.map +1 -1
  77. package/dist/prover/statetransition/StateTransitionProver.d.ts +14 -11
  78. package/dist/prover/statetransition/StateTransitionProver.d.ts.map +1 -1
  79. package/dist/prover/statetransition/StateTransitionProver.js +116 -62
  80. package/dist/prover/statetransition/StateTransitionProver.js.map +1 -1
  81. package/dist/settlement/contracts/DispatchContractProtocolModule.d.ts +1 -1
  82. package/dist/settlement/contracts/DispatchSmartContract.d.ts +1 -1
  83. package/dist/settlement/contracts/SettlementSmartContract.d.ts.map +1 -1
  84. package/dist/settlement/contracts/SettlementSmartContract.js +1 -0
  85. package/dist/settlement/contracts/SettlementSmartContract.js.map +1 -1
  86. package/dist/state/assert/assert.d.ts.map +1 -1
  87. package/dist/state/assert/assert.js +5 -3
  88. package/dist/state/assert/assert.js.map +1 -1
  89. package/dist/state/context/RuntimeMethodExecutionContext.d.ts +3 -3
  90. package/dist/state/context/RuntimeMethodExecutionContext.d.ts.map +1 -1
  91. package/dist/state/context/RuntimeMethodExecutionContext.js +7 -4
  92. package/dist/state/context/RuntimeMethodExecutionContext.js.map +1 -1
  93. package/dist/utils/FieldOptions.d.ts +62 -0
  94. package/dist/utils/FieldOptions.d.ts.map +1 -0
  95. package/dist/utils/FieldOptions.js +13 -0
  96. package/dist/utils/FieldOptions.js.map +1 -0
  97. package/dist/utils/ProvableHashList.d.ts +21 -2
  98. package/dist/utils/ProvableHashList.d.ts.map +1 -1
  99. package/dist/utils/ProvableHashList.js +37 -2
  100. package/dist/utils/ProvableHashList.js.map +1 -1
  101. package/dist/utils/ProvableReductionHashList.d.ts +7 -3
  102. package/dist/utils/ProvableReductionHashList.d.ts.map +1 -1
  103. package/dist/utils/ProvableReductionHashList.js +8 -5
  104. package/dist/utils/ProvableReductionHashList.js.map +1 -1
  105. package/dist/utils/utils.d.ts +10 -1
  106. package/dist/utils/utils.d.ts.map +1 -1
  107. package/dist/utils/utils.js +6 -0
  108. package/dist/utils/utils.js.map +1 -1
  109. package/package.json +2 -2
  110. package/src/hooks/AccountStateHook.ts +12 -3
  111. package/src/hooks/LastStateRootBlockHook.ts +7 -8
  112. package/src/hooks/NoopBlockHook.ts +7 -4
  113. package/src/hooks/NoopTransactionHook.ts +5 -2
  114. package/src/index.ts +6 -1
  115. package/src/model/AppliedStateTransitionBatch.ts +16 -0
  116. package/src/model/StateTransition.ts +6 -0
  117. package/src/model/StateTransitionProvableBatch.ts +94 -105
  118. package/src/model/transaction/RuntimeTransaction.ts +4 -0
  119. package/src/protocol/ProvableBlockHook.ts +51 -3
  120. package/src/protocol/ProvableTransactionHook.ts +67 -3
  121. package/src/prover/accumulators/AppliedBatchHashList.ts +32 -0
  122. package/src/{utils → prover/accumulators}/StateTransitionReductionList.ts +7 -4
  123. package/src/prover/accumulators/TransactionHashList.ts +9 -0
  124. package/src/prover/accumulators/WitnessedRootHashList.ts +61 -0
  125. package/src/prover/block/BlockProvable.ts +128 -9
  126. package/src/prover/block/BlockProver.ts +531 -383
  127. package/src/prover/block/accummulators/BlockHashMerkleTree.ts +11 -3
  128. package/src/prover/statetransition/StateTransitionProvable.ts +17 -11
  129. package/src/prover/statetransition/StateTransitionProver.ts +219 -144
  130. package/src/settlement/contracts/SettlementSmartContract.ts +4 -0
  131. package/src/state/assert/assert.ts +6 -3
  132. package/src/state/context/RuntimeMethodExecutionContext.ts +15 -7
  133. package/src/utils/FieldOptions.ts +13 -0
  134. package/src/utils/ProvableHashList.ts +77 -2
  135. package/src/utils/ProvableReductionHashList.ts +12 -3
  136. package/src/utils/utils.ts +18 -1
  137. package/test/BlockProver.test.ts +2 -0
  138. package/test/TestingProtocol.ts +5 -0
  139. package/test/model/StateTransitionProvableBatch.test.ts +137 -0
  140. package/test/prover/block/BlockProver.test.ts +18 -0
  141. package/test/prover/statetransition/StateTransitionProver.test.ts +240 -0
  142. package/test/utils/ProvableHashList.test.ts +44 -0
  143. package/test/utils/ProvableReductionHashList.test.ts +1 -1
  144. package/dist/utils/StateTransitionReductionList.d.ts.map +0 -1
  145. package/dist/utils/StateTransitionReductionList.js.map +0 -1
@@ -10,41 +10,43 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  var __param = (this && this.__param) || function (paramIndex, decorator) {
11
11
  return function (target, key) { decorator(target, key, paramIndex); }
12
12
  };
13
- import { Bool, Field, Poseidon, Provable, SelfProof, ZkProgram, } from "o1js";
13
+ import { Bool, Field, Provable, SelfProof, ZkProgram, } from "o1js";
14
14
  import { container, inject, injectable, injectAll } from "tsyringe";
15
- import { MAX_FIELD, provableMethod, ZkProgrammable, } from "@proto-kit/common";
16
- import { DefaultProvableHashList } from "../../utils/ProvableHashList";
15
+ import { log, MAX_FIELD, provableMethod, ZkProgrammable, } from "@proto-kit/common";
17
16
  import { ProtocolModule } from "../../protocol/ProtocolModule";
18
17
  import { RuntimeTransaction } from "../../model/transaction/RuntimeTransaction";
19
18
  import { ProvableStateTransition, } from "../../model/StateTransition";
20
- import { RuntimeMethodExecutionContext } from "../../state/context/RuntimeMethodExecutionContext";
19
+ import { toProvableHookBlockState, } from "../../protocol/ProvableTransactionHook";
20
+ import { RuntimeMethodExecutionContext, } from "../../state/context/RuntimeMethodExecutionContext";
21
+ import { toAfterTransactionHookArgument, toBeforeTransactionHookArgument, } from "../../protocol/ProvableBlockHook";
21
22
  import { NetworkState } from "../../model/network/NetworkState";
22
23
  import { SignedTransaction } from "../../model/transaction/SignedTransaction";
23
- import { MinaActions, MinaActionsHashList, } from "../../utils/MinaPrefixedProvableHashList";
24
- import { StateTransitionReductionList } from "../../utils/StateTransitionReductionList";
25
- import { BlockProverExecutionData, BlockProverPublicInput, BlockProverPublicOutput, DynamicRuntimeProof, } from "./BlockProvable";
24
+ import { MinaActions } from "../../utils/MinaPrefixedProvableHashList";
25
+ import { StateTransitionReductionList } from "../accumulators/StateTransitionReductionList";
26
+ import { assertEqualsIf } from "../../utils/utils";
27
+ import { WitnessedRootWitness } from "../accumulators/WitnessedRootHashList";
28
+ import { StateServiceProvider } from "../../state/StateServiceProvider";
29
+ import { AppliedStateTransitionBatch } from "../../model/AppliedStateTransitionBatch";
30
+ import { BlockProverPublicInput, BlockProverPublicOutput, DynamicRuntimeProof, BlockProverMultiTransactionExecutionData, BlockProverSingleTransactionExecutionData, BlockProverStateCommitments, } from "./BlockProvable";
26
31
  import { BlockHashMerkleTreeWitness, BlockHashTreeEntry, } from "./accummulators/BlockHashMerkleTree";
27
- import { MethodVKConfigData, RuntimeVerificationKeyAttestation, } from "./accummulators/RuntimeVerificationKeyTree";
32
+ import { MethodVKConfigData, } from "./accummulators/RuntimeVerificationKeyTree";
28
33
  import { RuntimeVerificationKeyRootService } from "./services/RuntimeVerificationKeyRootService";
29
34
  const errors = {
30
- stateProofNotStartingAtZero: () => "StateProof not starting ST-commitment at zero",
31
- stateTransitionsHashNotEqual: () => "StateTransition list commitments are not equal",
32
35
  propertyNotMatchingStep: (propertyName, step) => `${propertyName} not matching: ${step}`,
33
36
  propertyNotMatching: (propertyName) => `${propertyName} not matching`,
34
37
  stateRootNotMatching: (step) => errors.propertyNotMatchingStep("StateRoots", step),
35
38
  transactionsHashNotMatching: (step) => errors.propertyNotMatchingStep("Transactions hash", step),
36
39
  networkStateHashNotMatching: (step) => errors.propertyNotMatchingStep("Network state hash", step),
37
40
  invalidZkProgramTreeRoot: () => "Root hash of the provided zkProgram config witness is invalid",
38
- invalidZkProgramConfigMethodId: () => "Method id of the provided zkProgram config does not match the executed transaction method id",
39
41
  };
40
42
  export class BlockProverProgrammable extends ZkProgrammable {
41
- constructor(prover, stateTransitionProver, runtime, transactionHooks, blockHooks, verificationKeyService) {
43
+ constructor(prover, stateTransitionProver, transactionHooks, blockHooks, stateServiceProvider, verificationKeyService) {
42
44
  super();
43
45
  this.prover = prover;
44
46
  this.stateTransitionProver = stateTransitionProver;
45
- this.runtime = runtime;
46
47
  this.transactionHooks = transactionHooks;
47
48
  this.blockHooks = blockHooks;
49
+ this.stateServiceProvider = stateServiceProvider;
48
50
  this.verificationKeyService = verificationKeyService;
49
51
  this.name = "BlockProver";
50
52
  }
@@ -53,35 +55,43 @@ export class BlockProverProgrammable extends ZkProgrammable {
53
55
  }
54
56
  /**
55
57
  * Applies and checks the two proofs and applies the corresponding state
56
- * changes to the given state
58
+ * changes to the given state.
59
+ *
60
+ * The rough high level workflow of this function:
61
+ * 1. Execute beforeTransaction hooks, pushing the ST batch
62
+ * 2. Add Transaction to bundle, meaning appending it to all the respective commitments
63
+ * 3. Push the runtime ST batch
64
+ * 4. Execute afterTransaction hooks, pushing the ST batch
65
+ * 5. Some consistency checks and signature verification
57
66
  *
58
- * @param state The from-state of the BlockProver
59
- * @param stateTransitionProof
60
- * @param runtimeProof
67
+ * @param fromState The from-state of the BlockProver
68
+ * @param runtimeOutput
61
69
  * @param executionData
62
- * @param verificationKey
70
+ * @param networkState
63
71
  * @returns The new BlockProver-state to be used as public output
64
72
  */
65
- async applyTransaction(state, stateTransitionProof, runtimeProof, executionData, verificationKey) {
66
- const { transaction, networkState, signature } = executionData;
67
- const { isMessage } = runtimeProof.publicOutput;
68
- runtimeProof.verify(verificationKey);
69
- stateTransitionProof.verify();
70
- const stateTo = { ...state };
71
- // Checks for the stateTransitionProof and appProof matching
72
- stateTransitionProof.publicInput.stateTransitionsHash.assertEquals(Field(0), errors.stateProofNotStartingAtZero());
73
- stateTransitionProof.publicInput.protocolTransitionsHash.assertEquals(Field(0), errors.stateProofNotStartingAtZero());
74
- runtimeProof.publicOutput.stateTransitionsHash.assertEquals(stateTransitionProof.publicOutput.stateTransitionsHash, errors.stateTransitionsHashNotEqual());
75
- // Assert from state roots
76
- state.stateRoot.assertEquals(stateTransitionProof.publicInput.stateRoot, errors.propertyNotMatching("from state root"));
77
- state.stateRoot.assertEquals(stateTransitionProof.publicInput.protocolStateRoot, errors.propertyNotMatching("from protocol state root"));
78
- // Apply protocol state transitions
79
- await this.assertProtocolTransitions(stateTransitionProof, executionData, runtimeProof);
80
- // Apply state if status success
81
- stateTo.stateRoot = Provable.if(runtimeProof.publicOutput.status, stateTransitionProof.publicOutput.stateRoot, stateTransitionProof.publicOutput.protocolStateRoot);
73
+ async applyTransaction(fromState, runtimeOutput, executionData, networkState) {
74
+ const { transaction, signature } = executionData;
75
+ let state = { ...fromState };
76
+ const { isMessage } = runtimeOutput;
77
+ const beforeTxHookArguments = toBeforeTransactionHookArgument(executionData, networkState, state);
78
+ // Apply beforeTransaction hook state transitions
79
+ const beforeBatch = await this.executeTransactionHooks(async (module, args) => await module.beforeTransaction(args), beforeTxHookArguments);
80
+ state = this.addTransactionToBundle(state, runtimeOutput.isMessage, transaction);
81
+ state.pendingSTBatches.push(beforeBatch);
82
+ state.pendingSTBatches.push({
83
+ batchHash: runtimeOutput.stateTransitionsHash,
84
+ applied: runtimeOutput.status,
85
+ });
86
+ // Apply afterTransaction hook state transitions
87
+ const afterTxHookArguments = toAfterTransactionHookArgument(executionData, networkState, state, runtimeOutput);
88
+ // Switch to different state set for afterTx hooks
89
+ this.stateServiceProvider.popCurrentStateService();
90
+ const afterBatch = await this.executeTransactionHooks(async (module, args) => await module.afterTransaction(args), afterTxHookArguments);
91
+ state.pendingSTBatches.push(afterBatch);
82
92
  // Check transaction integrity against appProof
83
93
  const blockTransactionHash = transaction.hash();
84
- blockTransactionHash.assertEquals(runtimeProof.publicOutput.transactionHash, "Transactions provided in AppProof and BlockProof do not match");
94
+ blockTransactionHash.assertEquals(runtimeOutput.transactionHash, "Transactions provided in AppProof and BlockProof do not match");
85
95
  // Check transaction signature
86
96
  new SignedTransaction({
87
97
  transaction,
@@ -93,211 +103,254 @@ export class BlockProverProgrammable extends ZkProgrammable {
93
103
  // Validate layout of transaction witness
94
104
  transaction.assertTransactionType(isMessage);
95
105
  // Check network state integrity against appProof
96
- state.networkStateHash.assertEquals(runtimeProof.publicOutput.networkStateHash, "Network state does not match state used in AppProof");
97
- state.networkStateHash.assertEquals(networkState.hash(), "Network state provided to BlockProver does not match the publicInput");
98
- return stateTo;
106
+ state.networkState
107
+ .hash()
108
+ .assertEquals(runtimeOutput.networkStateHash, "Network state does not match state used in AppProof");
109
+ return state;
99
110
  }
100
111
  // eslint-disable-next-line max-len
101
112
  // TODO How does this interact with the RuntimeMethodExecutionContext when executing runtimemethods?
102
- async assertProtocolTransitions(stateTransitionProof, executionData, runtimeProof) {
103
- const executionContext = container.resolve(RuntimeMethodExecutionContext);
104
- executionContext.clear();
105
- // Setup context for potential calls to runtime methods.
106
- // This way they can use this.transaction etc. while still having provable
107
- // integrity between data
108
- executionContext.setup({
109
- // That is why we should probably hide it from the transaction context inputs
110
- transaction: executionData.transaction,
111
- networkState: executionData.networkState,
112
- });
113
- executionContext.beforeMethod("", "", []);
114
- for (const module of this.transactionHooks) {
115
- // eslint-disable-next-line no-await-in-loop
116
- await module.onTransaction(executionData);
117
- }
118
- executionContext.afterMethod();
119
- const { stateTransitions, status, statusMessage } = executionContext.current().result;
120
- status.assertTrue(statusMessage);
113
+ /**
114
+ * Constructs a AppliedBatch based on a list of STs and the flag whether to
115
+ * be applied or not. The AppliedBatch is a condensed commitment to a batch
116
+ * of STs.
117
+ */
118
+ constructBatch(stateTransitions, applied) {
121
119
  const transitions = stateTransitions.map((transition) => transition.toProvable());
122
- const hashList = new StateTransitionReductionList(ProvableStateTransition, stateTransitionProof.publicInput.protocolTransitionsHash);
120
+ const hashList = new StateTransitionReductionList(ProvableStateTransition);
123
121
  transitions.forEach((transition) => {
124
122
  hashList.push(transition);
125
123
  });
126
- stateTransitionProof.publicOutput.protocolTransitionsHash.assertEquals(hashList.commitment, "ProtocolTransitionsHash not matching the generated protocol transitions");
124
+ return new AppliedStateTransitionBatch({
125
+ batchHash: hashList.commitment,
126
+ applied,
127
+ });
127
128
  }
128
- async executeBlockHooks(state, inputNetworkState, type) {
129
+ async executeTransactionHooks(hook, hookArguments) {
130
+ const { batch } = await this.executeHooks(hookArguments, async () => {
131
+ for (const module of this.transactionHooks) {
132
+ // eslint-disable-next-line no-await-in-loop
133
+ await hook(module, hookArguments);
134
+ }
135
+ });
136
+ return batch;
137
+ }
138
+ async executeHooks(contextArguments, method) {
129
139
  const executionContext = container.resolve(RuntimeMethodExecutionContext);
130
140
  executionContext.clear();
141
+ // Setup context for potential calls to runtime methods.
142
+ // This way they can use this.transaction etc. while still having provable
143
+ // integrity between data
144
+ executionContext.setup(contextArguments);
131
145
  executionContext.beforeMethod("", "", []);
132
- const resultingNetworkState = await this.blockHooks.reduce(async (networkStatePromise, blockHook) => {
133
- const networkState = await networkStatePromise;
134
- // Setup context for potential calls to runtime methods.
135
- // With the special case that we set the new networkstate for every hook
136
- // We also have to put in a dummy transaction for network.transaction
137
- executionContext.setup({
138
- transaction: RuntimeTransaction.dummyTransaction(),
139
- networkState,
140
- });
141
- if (type === "beforeBlock") {
142
- return await blockHook.beforeBlock(networkState, state);
143
- }
144
- if (type === "afterBlock") {
145
- return await blockHook.afterBlock(networkState, state);
146
- }
147
- throw new Error("Unreachable");
148
- }, Promise.resolve(inputNetworkState));
146
+ const result = await method();
149
147
  executionContext.afterMethod();
150
148
  const { stateTransitions, status, statusMessage } = executionContext.current().result;
151
- status.assertTrue(`Block hook call failed: ${statusMessage ?? "-"}`);
149
+ status.assertTrue(`Transaction hook call failed: ${statusMessage ?? "-"}`);
152
150
  return {
153
- networkState: resultingNetworkState,
154
- stateTransitions,
151
+ batch: this.constructBatch(stateTransitions, Bool(true)),
152
+ result,
155
153
  };
156
154
  }
157
- addTransactionToBundle(state, isMessage, transaction) {
158
- const stateTo = {
159
- ...state,
155
+ async executeBlockHooks(hook, hookArguments, inputNetworkState) {
156
+ const transaction = RuntimeTransaction.dummyTransaction();
157
+ const startingInputs = {
158
+ transaction,
159
+ networkState: inputNetworkState,
160
160
  };
161
+ return await this.executeHooks(startingInputs, async () => {
162
+ const executionContext = container.resolve(RuntimeMethodExecutionContext);
163
+ return await this.blockHooks.reduce(async (networkStatePromise, blockHook) => {
164
+ const networkState = await networkStatePromise;
165
+ // Setup context for potential calls to runtime methods.
166
+ // With the special case that we set the new networkstate for every hook
167
+ // We also have to put in a dummy transaction for network.transaction
168
+ executionContext.setup({
169
+ transaction: RuntimeTransaction.dummyTransaction(),
170
+ networkState,
171
+ });
172
+ return await hook(blockHook, networkState, hookArguments);
173
+ }, Promise.resolve(inputNetworkState));
174
+ });
175
+ }
176
+ addTransactionToBundle(state, isMessage, transaction) {
161
177
  const transactionHash = transaction.hash();
162
178
  // Append tx to transaction list
163
- const transactionList = new DefaultProvableHashList(Field, state.transactionsHash);
164
- transactionList.pushIf(transactionHash, isMessage.not());
165
- stateTo.transactionsHash = transactionList.commitment;
179
+ state.transactionList.pushIf(transactionHash, isMessage.not());
166
180
  // Append tx to eternal transaction list
167
181
  // TODO Change that to the a sequence-state compatible transaction struct
168
- const eternalTransactionList = new DefaultProvableHashList(Field, state.eternalTransactionsHash);
169
- eternalTransactionList.pushIf(transactionHash, isMessage.not());
170
- stateTo.eternalTransactionsHash = eternalTransactionList.commitment;
182
+ state.eternalTransactionsList.pushIf(transactionHash, isMessage.not());
171
183
  // Append tx to incomingMessagesHash
172
184
  const actionHash = MinaActions.actionHash(transaction.hashData());
173
- const incomingMessagesList = new MinaActionsHashList(state.incomingMessagesHash);
174
- incomingMessagesList.pushIf(actionHash, isMessage);
175
- stateTo.incomingMessagesHash = incomingMessagesList.commitment;
176
- return stateTo;
185
+ state.incomingMessages.pushIf(actionHash, isMessage);
186
+ return state;
177
187
  }
178
- async proveTransaction(publicInput, stateProof, runtimeProof, executionData, verificationKeyWitness) {
179
- const state = {
180
- ...publicInput,
181
- };
182
- state.networkStateHash.assertEquals(executionData.networkState.hash(), "ExecutionData Networkstate doesn't equal public input hash");
183
- publicInput.blockNumber.assertEquals(MAX_FIELD, "blockNumber has to be MAX for transaction proofs");
188
+ verifyVerificationKeyAttestation(attestation, methodId) {
184
189
  // Verify the [methodId, vk] tuple against the baked-in vk tree root
185
- const { verificationKey, witness: verificationKeyTreeWitness } = verificationKeyWitness;
190
+ const { verificationKey, witness: verificationKeyTreeWitness } = attestation;
186
191
  const root = Field(this.verificationKeyService.getRoot());
187
192
  const calculatedRoot = verificationKeyTreeWitness.calculateRoot(new MethodVKConfigData({
188
- methodId: executionData.transaction.methodId,
193
+ methodId: methodId,
189
194
  vkHash: verificationKey.hash,
190
195
  }).hash());
191
196
  root.assertEquals(calculatedRoot, errors.invalidZkProgramTreeRoot());
192
- const bundleInclusionState = this.addTransactionToBundle(state, runtimeProof.publicOutput.isMessage, executionData.transaction);
193
- const stateTo = await this.applyTransaction(bundleInclusionState, stateProof, runtimeProof, executionData, verificationKey);
197
+ return verificationKey;
198
+ }
199
+ async proveTransactionInternal(fromState, runtimeProof, { transaction, networkState }) {
200
+ const verificationKey = this.verifyVerificationKeyAttestation(transaction.verificationKeyAttestation, transaction.transaction.methodId);
201
+ runtimeProof.verify(verificationKey);
202
+ return await this.applyTransaction(fromState, runtimeProof.publicOutput, transaction, networkState);
203
+ }
204
+ staticChecks(publicInput) {
205
+ publicInput.blockNumber.assertEquals(MAX_FIELD, "blockNumber has to be MAX for transaction proofs");
206
+ }
207
+ async proveTransaction(publicInput, runtimeProof, executionData) {
208
+ const state = BlockProverStateCommitments.toBlockProverState(publicInput, executionData.networkState);
209
+ this.staticChecks(publicInput);
210
+ const stateTo = await this.proveTransactionInternal(state, runtimeProof, executionData);
194
211
  return new BlockProverPublicOutput({
195
- ...stateTo,
196
- blockNumber: publicInput.blockNumber,
212
+ ...BlockProverStateCommitments.fromBlockProverState(stateTo),
197
213
  closed: Bool(false),
198
214
  });
199
215
  }
200
- assertSTProofInput(stateTransitionProof, stateRoot) {
201
- stateTransitionProof.publicInput.stateTransitionsHash.assertEquals(Field(0), errors.stateProofNotStartingAtZero());
202
- stateTransitionProof.publicInput.protocolTransitionsHash.assertEquals(Field(0), errors.stateProofNotStartingAtZero());
203
- // Assert from state roots
204
- stateRoot.assertEquals(stateTransitionProof.publicInput.stateRoot, errors.propertyNotMatching("from state root"));
216
+ async proveTransactions(publicInput, runtimeProof1, runtimeProof2, executionData) {
217
+ const state = BlockProverStateCommitments.toBlockProverState(publicInput, executionData.networkState);
218
+ this.staticChecks(publicInput);
219
+ const state1 = await this.proveTransactionInternal(state, runtimeProof1, {
220
+ transaction: executionData.transaction1,
221
+ networkState: executionData.networkState,
222
+ });
223
+ // Switch to next state record for 2nd tx beforeTx hook
224
+ // TODO Can be prevented by merging 1st afterTx + 2nd beforeTx
225
+ this.stateServiceProvider.popCurrentStateService();
226
+ const stateTo = await this.proveTransactionInternal(state1, runtimeProof2, {
227
+ transaction: executionData.transaction2,
228
+ networkState: executionData.networkState,
229
+ });
230
+ return new BlockProverPublicOutput({
231
+ ...BlockProverStateCommitments.fromBlockProverState(stateTo),
232
+ closed: Bool(false),
233
+ });
205
234
  }
206
- async proveBlock(publicInput, networkState, blockWitness,
207
- // stateTransitionProof: StateTransitionProof,
208
- transactionProof) {
209
- const state = {
210
- ...publicInput,
235
+ includeSTProof(stateTransitionProof, apply, stateRoot, pendingSTBatchesHash, witnessedRootsHash) {
236
+ assertEqualsIf(stateTransitionProof.publicInput.currentBatchStateHash, Field(0), apply, "State for STProof has to be empty at the start");
237
+ assertEqualsIf(stateTransitionProof.publicOutput.currentBatchStateHash, Field(0), apply, "State for STProof has to be empty at the end");
238
+ assertEqualsIf(stateTransitionProof.publicInput.batchesHash, Field(0), apply, "Batcheshash doesn't start at 0");
239
+ // Assert from state roots
240
+ assertEqualsIf(stateRoot, stateTransitionProof.publicInput.root, apply, errors.propertyNotMatching("from state root"));
241
+ // Assert the stBatchesHash executed is the same
242
+ assertEqualsIf(pendingSTBatchesHash, stateTransitionProof.publicOutput.batchesHash, apply, "Pending STBatches are not the same that have been executed by the ST proof");
243
+ // Assert root Accumulator
244
+ assertEqualsIf(Field(0), stateTransitionProof.publicInput.witnessedRootsHash, apply, errors.propertyNotMatching("from state root"));
245
+ // Assert the witnessedRootsHash created is the same
246
+ assertEqualsIf(witnessedRootsHash, stateTransitionProof.publicOutput.witnessedRootsHash, apply, "Root accumulator Commitment is not the same that have been executed by the ST proof");
247
+ // update root only if we didn't defer
248
+ const newRoot = Provable.if(apply, stateTransitionProof.publicOutput.root, stateRoot);
249
+ // Reset only if we didn't defer
250
+ const newBatchesHash = Provable.if(apply, Field(0), pendingSTBatchesHash);
251
+ const newWitnessedRootsHash = Provable.if(apply, Field(0), witnessedRootsHash);
252
+ return {
253
+ stateRoot: newRoot,
254
+ pendingSTBatchesHash: newBatchesHash,
255
+ witnessedRootsHash: newWitnessedRootsHash,
211
256
  };
257
+ }
258
+ async proveBlock(publicInput, networkState, blockWitness, stateTransitionProof, deferSTProof, afterBlockRootWitness, transactionProof) {
212
259
  // 1. Make assertions about the inputs
213
260
  publicInput.transactionsHash.assertEquals(Field(0), "Transactionshash has to start at 0");
214
- publicInput.networkStateHash.assertEquals(networkState.hash(), "Wrong NetworkState supplied");
215
- transactionProof.publicInput.transactionsHash.assertEquals(Field(0), "TransactionProof transactionshash has to start at 0");
261
+ // TransactionProof format checks
216
262
  transactionProof.publicInput.blockHashRoot.assertEquals(Field(0), "TransactionProof cannot carry the blockHashRoot - publicInput");
217
263
  transactionProof.publicOutput.blockHashRoot.assertEquals(Field(0), "TransactionProof cannot carry the blockHashRoot - publicOutput");
218
264
  transactionProof.publicInput.networkStateHash.assertEquals(transactionProof.publicOutput.networkStateHash, "TransactionProof cannot alter the network state");
219
- transactionProof.publicInput.eternalTransactionsHash.assertEquals(state.eternalTransactionsHash, "TransactionProof starting eternalTransactionHash not matching");
220
- transactionProof.publicInput.incomingMessagesHash.assertEquals(state.incomingMessagesHash, "TransactionProof starting incomingMessagesHash not matching");
221
- // TODO Reintroduce ST Proofs
222
- // Verify ST Proof only if STs have been emitted,
223
- // otherwise we can input a dummy proof
224
- // const stsEmitted = stateTransitionProof.publicOutput.stateTransitionsHash
225
- // .equals(0)
226
- // .and(stateTransitionProof.publicOutput.protocolTransitionsHash.equals(0))
227
- // .not();
228
- // Provable.log("VerifyIf 1", stsEmitted);
229
- // stateTransitionProof.verifyIf(Bool(false));
230
- // stateTransitionProof.verifyIf(stsEmitted);
265
+ const state = BlockProverStateCommitments.toBlockProverState(publicInput, networkState);
231
266
  // Verify Transaction proof if it has at least 1 tx - i.e. the
232
267
  // input and output doesn't match fully
233
268
  // We have to compare the whole input and output because we can make no
234
269
  // assumptions about the values, since it can be an arbitrary dummy-proof
235
270
  const txProofOutput = transactionProof.publicOutput;
236
271
  const isEmptyTransition = txProofOutput.equals(transactionProof.publicInput, txProofOutput.closed);
237
- Provable.log("VerifyIf 2", isEmptyTransition.not());
238
- transactionProof.verifyIf(isEmptyTransition.not());
272
+ const skipTransactionProofVerification = isEmptyTransition;
273
+ const verifyTransactionProof = isEmptyTransition.not();
274
+ log.provable.debug("VerifyIf TxProof", verifyTransactionProof);
275
+ transactionProof.verifyIf(verifyTransactionProof);
239
276
  // 2. Execute beforeBlock hooks
240
- const beforeBlockResult = await this.executeBlockHooks(state, networkState, "beforeBlock");
241
- // const beforeBlockHashList = new StateTransitionReductionList(
242
- // ProvableStateTransition
243
- // );
244
- // beforeBlockResult.stateTransitions.forEach((st) => {
245
- // beforeBlockHashList.push(st.toProvable());
246
- // });
247
- // We are reusing protocolSTs here as beforeBlock STs
248
- // TODO Not possible atm bcs we can't have a seperation between protocol/runtime state roots,
249
- // which we would for both before and after to be able to emit STs
250
- // stateTransitionProof.publicInput.protocolTransitionsHash.assertEquals(
251
- // beforeBlockHashList.commitment
252
- // );
253
- // state.stateRoot = stateTransitionProof.publicInput.protocolStateRoot;
254
- // TODO Only for now
255
- // beforeBlockHashList.commitment.assertEquals(
256
- // Field(0),
257
- // "beforeBlock() cannot emit state transitions yet"
258
- // );
277
+ const beforeBlockArgs = toProvableHookBlockState(state);
278
+ const beforeBlockResult = await this.executeBlockHooks(async (module, networkStateArg, args) => await module.beforeBlock(networkStateArg, args), beforeBlockArgs, networkState);
279
+ state.pendingSTBatches.push(beforeBlockResult.batch);
259
280
  // 4. Apply TX-type BlockProof
260
- transactionProof.publicInput.networkStateHash.assertEquals(beforeBlockResult.networkState.hash(), "TransactionProof networkstate hash not matching beforeBlock hook result");
261
- transactionProof.publicInput.stateRoot.assertEquals(state.stateRoot, "TransactionProof input state root not matching blockprover state root");
262
- state.stateRoot = transactionProof.publicOutput.stateRoot;
263
- state.transactionsHash = transactionProof.publicOutput.transactionsHash;
264
- state.eternalTransactionsHash =
265
- transactionProof.publicOutput.eternalTransactionsHash;
266
- state.incomingMessagesHash =
267
- transactionProof.publicOutput.incomingMessagesHash;
268
- // 5. Execute afterBlock hooks
269
- // this.assertSTProofInput(stateTransitionProof, state.stateRoot);
270
- const afterBlockResult = await this.executeBlockHooks(state, beforeBlockResult.networkState, "afterBlock");
271
- const afterBlockHashList = new StateTransitionReductionList(ProvableStateTransition);
272
- afterBlockResult.stateTransitions.forEach((st) => {
273
- afterBlockHashList.push(st.toProvable());
281
+ transactionProof.publicInput.networkStateHash
282
+ .equals(beforeBlockResult.result.hash())
283
+ .or(skipTransactionProofVerification)
284
+ .assertTrue("TransactionProof networkstate hash not matching beforeBlock hook result");
285
+ transactionProof.publicInput.stateRoot.assertEquals(transactionProof.publicOutput.stateRoot, "TransactionProofs can't change the state root");
286
+ // Check that the transaction proof's STs start after the beforeBlock hook
287
+ transactionProof.publicInput.pendingSTBatchesHash.assertEquals(state.pendingSTBatches.commitment, "Transaction proof doesn't start their STs after the beforeBlockHook");
288
+ // Fast-forward the stBatchHashList to after all transactions appended
289
+ state.pendingSTBatches.commitment =
290
+ transactionProof.publicOutput.pendingSTBatchesHash;
291
+ // Fast-forward block content commitments by the results of the aggregated transaction proof
292
+ // Implicitly, the 'from' values here are asserted against the publicInput, since the hashlists
293
+ // are created out of the public input
294
+ state.transactionList.fastForward({
295
+ from: transactionProof.publicInput.transactionsHash,
296
+ to: transactionProof.publicOutput.transactionsHash,
297
+ });
298
+ state.eternalTransactionsList.fastForward({
299
+ from: transactionProof.publicInput.eternalTransactionsHash,
300
+ to: transactionProof.publicOutput.eternalTransactionsHash,
274
301
  });
275
- state.networkStateHash = afterBlockResult.networkState.hash();
276
- // We are reusing runtime STs here as afterBlock STs
277
- // stateTransitionProof.publicInput.protocolTransitionsHash.assertEquals(
278
- // afterBlockHashList.commitment,
279
- // "STProof from-ST-hash not matching generated ST-hash from afterBlock hooks"
280
- // );
281
- // state.stateRoot = Provable.if(
282
- // stsEmitted,
283
- // stateTransitionProof.publicOutput.stateRoot,
284
- // state.stateRoot
285
- // );
286
- // 6. Close block
287
- // Calculate the new block index
302
+ state.incomingMessages.fastForward({
303
+ from: transactionProof.publicInput.incomingMessagesHash,
304
+ to: transactionProof.publicOutput.incomingMessagesHash,
305
+ });
306
+ // Witness root
307
+ const isEmpty = state.pendingSTBatches.commitment.equals(0);
308
+ isEmpty
309
+ .implies(state.stateRoot.equals(afterBlockRootWitness.witnessedRoot))
310
+ .assertTrue();
311
+ state.witnessedRoots.witnessRoot({
312
+ appliedBatchListState: state.pendingSTBatches.commitment,
313
+ root: afterBlockRootWitness.witnessedRoot,
314
+ }, afterBlockRootWitness.preimage, isEmpty.not());
315
+ // 5. Calculate the new block tree hash
288
316
  const blockIndex = blockWitness.calculateIndex();
289
317
  blockIndex.assertEquals(publicInput.blockNumber);
290
318
  blockWitness
291
319
  .calculateRoot(Field(0))
292
320
  .assertEquals(publicInput.blockHashRoot, "Supplied block hash witness not matching state root");
293
321
  state.blockHashRoot = blockWitness.calculateRoot(new BlockHashTreeEntry({
294
- // Mirroring UnprovenBlock.hash()
295
- blockHash: Poseidon.hash([blockIndex, state.transactionsHash]),
322
+ block: {
323
+ index: blockIndex,
324
+ transactionListHash: state.transactionList.commitment,
325
+ },
296
326
  closed: Bool(true),
297
327
  }).hash());
328
+ // 6. Execute afterBlock hooks
329
+ // Switch state service to afterBlock one
330
+ this.stateServiceProvider.popCurrentStateService();
331
+ const afterBlockHookArgs = toProvableHookBlockState(state);
332
+ const afterBlockResult = await this.executeBlockHooks(async (module, networkStateArg, args) => await module.afterBlock(networkStateArg, args), {
333
+ ...afterBlockHookArgs,
334
+ stateRoot: afterBlockRootWitness.witnessedRoot,
335
+ }, beforeBlockResult.result);
336
+ state.pendingSTBatches.push(afterBlockResult.batch);
337
+ state.networkState = afterBlockResult.result;
338
+ // 7. Close block
339
+ // Verify ST Proof only if STs have been emitted,
340
+ // and we don't defer the verification of the STs
341
+ // otherwise we can input a dummy proof
342
+ const batchesEmpty = state.pendingSTBatches.commitment.equals(Field(0));
343
+ const verifyStProof = deferSTProof.not().and(batchesEmpty.not());
344
+ log.provable.debug("Verify STProof", verifyStProof);
345
+ stateTransitionProof.verifyIf(verifyStProof);
346
+ // Apply STProof if not deferred
347
+ const stateProofResult = this.includeSTProof(stateTransitionProof, verifyStProof, state.stateRoot, state.pendingSTBatches.commitment, state.witnessedRoots.commitment);
348
+ state.stateRoot = stateProofResult.stateRoot;
349
+ state.pendingSTBatches.commitment = stateProofResult.pendingSTBatchesHash;
350
+ state.witnessedRoots.commitment = stateProofResult.witnessedRootsHash;
351
+ state.blockNumber = blockIndex.add(1);
298
352
  return new BlockProverPublicOutput({
299
- ...state,
300
- blockNumber: blockIndex.add(1),
353
+ ...BlockProverStateCommitments.fromBlockProverState(state),
301
354
  closed: Bool(true),
302
355
  });
303
356
  }
@@ -329,6 +382,12 @@ export class BlockProverProgrammable extends ZkProgrammable {
329
382
  // Check incomingMessagesHash
330
383
  publicInput.incomingMessagesHash.assertEquals(proof1.publicInput.incomingMessagesHash, errors.propertyNotMatchingStep("IncomingMessagesHash", "publicInput.from -> proof1.from"));
331
384
  proof1.publicOutput.incomingMessagesHash.assertEquals(proof2.publicInput.incomingMessagesHash, errors.propertyNotMatchingStep("IncomingMessagesHash", "proof1.to -> proof2.from"));
385
+ // Check pendingSTBatchesHash
386
+ publicInput.pendingSTBatchesHash.assertEquals(proof1.publicInput.pendingSTBatchesHash, errors.transactionsHashNotMatching("publicInput.from -> proof1.from"));
387
+ proof1.publicOutput.pendingSTBatchesHash.assertEquals(proof2.publicInput.pendingSTBatchesHash, errors.transactionsHashNotMatching("proof1.to -> proof2.from"));
388
+ // Check witnessedRootsHash
389
+ publicInput.witnessedRootsHash.assertEquals(proof1.publicInput.witnessedRootsHash, errors.transactionsHashNotMatching("publicInput.from -> proof1.from"));
390
+ proof1.publicOutput.witnessedRootsHash.assertEquals(proof2.publicInput.witnessedRootsHash, errors.transactionsHashNotMatching("proof1.to -> proof2.from"));
332
391
  // Assert closed indicator matches
333
392
  // (i.e. we can only merge TX-Type and Block-Type with each other)
334
393
  proof1.publicOutput.closed.assertEquals(proof2.publicOutput.closed, "Closed indicators not matching");
@@ -371,6 +430,8 @@ export class BlockProverProgrammable extends ZkProgrammable {
371
430
  incomingMessagesHash: proof2.publicOutput.incomingMessagesHash,
372
431
  closed: isValidClosedMerge,
373
432
  blockNumber: proof2.publicOutput.blockNumber,
433
+ pendingSTBatchesHash: proof2.publicOutput.pendingSTBatchesHash,
434
+ witnessedRootsHash: proof2.publicOutput.witnessedRootsHash,
374
435
  });
375
436
  }
376
437
  /**
@@ -382,6 +443,7 @@ export class BlockProverProgrammable extends ZkProgrammable {
382
443
  const { prover, stateTransitionProver } = this;
383
444
  const StateTransitionProofClass = stateTransitionProver.zkProgram[0].Proof;
384
445
  const proveTransaction = prover.proveTransaction.bind(prover);
446
+ const proveTransactions = prover.proveTransactions.bind(prover);
385
447
  const proveBlock = prover.proveBlock.bind(prover);
386
448
  const merge = prover.merge.bind(prover);
387
449
  const program = ZkProgram({
@@ -391,28 +453,34 @@ export class BlockProverProgrammable extends ZkProgrammable {
391
453
  methods: {
392
454
  proveTransaction: {
393
455
  privateInputs: [
394
- StateTransitionProofClass,
395
456
  DynamicRuntimeProof,
396
- BlockProverExecutionData,
397
- RuntimeVerificationKeyAttestation,
457
+ BlockProverSingleTransactionExecutionData,
458
+ ],
459
+ async method(publicInput, runtimeProof, executionData) {
460
+ return await proveTransaction(publicInput, runtimeProof, executionData);
461
+ },
462
+ },
463
+ proveTransactions: {
464
+ privateInputs: [
465
+ DynamicRuntimeProof,
466
+ DynamicRuntimeProof,
467
+ BlockProverMultiTransactionExecutionData,
398
468
  ],
399
- async method(publicInput, stateProof, appProof, executionData, verificationKeyAttestation) {
400
- return await proveTransaction(publicInput, stateProof, appProof, executionData, verificationKeyAttestation);
469
+ async method(publicInput, runtimeProof1, runtimeProof2, executionData) {
470
+ return await proveTransactions(publicInput, runtimeProof1, runtimeProof2, executionData);
401
471
  },
402
472
  },
403
473
  proveBlock: {
404
474
  privateInputs: [
405
475
  NetworkState,
406
476
  BlockHashMerkleTreeWitness,
407
- // StateTransitionProofClass,
477
+ StateTransitionProofClass,
478
+ Bool,
479
+ WitnessedRootWitness,
408
480
  (SelfProof),
409
481
  ],
410
- async method(publicInput, networkState, blockWitness,
411
- // stateTransitionProof: StateTransitionProof,
412
- transactionProof) {
413
- return await proveBlock(publicInput, networkState, blockWitness,
414
- // stateTransitionProof,
415
- transactionProof);
482
+ async method(publicInput, networkState, blockWitness, stateTransitionProof, deferSTs, afterBlockRootWitness, transactionProof) {
483
+ return await proveBlock(publicInput, networkState, blockWitness, stateTransitionProof, deferSTs, afterBlockRootWitness, transactionProof);
416
484
  },
417
485
  },
418
486
  merge: {
@@ -428,6 +496,7 @@ export class BlockProverProgrammable extends ZkProgrammable {
428
496
  });
429
497
  const methods = {
430
498
  proveTransaction: program.proveTransaction,
499
+ proveTransactions: program.proveTransactions,
431
500
  proveBlock: program.proveBlock,
432
501
  merge: program.merge,
433
502
  };
@@ -447,17 +516,27 @@ export class BlockProverProgrammable extends ZkProgrammable {
447
516
  __decorate([
448
517
  provableMethod(),
449
518
  __metadata("design:type", Function),
450
- __metadata("design:paramtypes", [BlockProverPublicInput, Object, DynamicRuntimeProof,
451
- BlockProverExecutionData,
452
- RuntimeVerificationKeyAttestation]),
519
+ __metadata("design:paramtypes", [BlockProverPublicInput,
520
+ DynamicRuntimeProof,
521
+ BlockProverSingleTransactionExecutionData]),
453
522
  __metadata("design:returntype", Promise)
454
523
  ], BlockProverProgrammable.prototype, "proveTransaction", null);
524
+ __decorate([
525
+ provableMethod(),
526
+ __metadata("design:type", Function),
527
+ __metadata("design:paramtypes", [BlockProverPublicInput,
528
+ DynamicRuntimeProof,
529
+ DynamicRuntimeProof,
530
+ BlockProverMultiTransactionExecutionData]),
531
+ __metadata("design:returntype", Promise)
532
+ ], BlockProverProgrammable.prototype, "proveTransactions", null);
455
533
  __decorate([
456
534
  provableMethod(),
457
535
  __metadata("design:type", Function),
458
536
  __metadata("design:paramtypes", [BlockProverPublicInput,
459
537
  NetworkState,
460
- BlockHashMerkleTreeWitness, Object]),
538
+ BlockHashMerkleTreeWitness, Object, Bool,
539
+ WitnessedRootWitness, Object]),
461
540
  __metadata("design:returntype", Promise)
462
541
  ], BlockProverProgrammable.prototype, "proveBlock", null);
463
542
  __decorate([
@@ -472,11 +551,11 @@ __decorate([
472
551
  * then be merged to be committed to the base-layer contract
473
552
  */
474
553
  export let BlockProver = class BlockProver extends ProtocolModule {
475
- constructor(stateTransitionProver, runtime, transactionHooks, blockHooks, verificationKeyService) {
554
+ constructor(stateTransitionProver, runtime, transactionHooks, blockHooks, stateServiceProvider, verificationKeyService) {
476
555
  super();
477
556
  this.stateTransitionProver = stateTransitionProver;
478
557
  this.runtime = runtime;
479
- this.zkProgrammable = new BlockProverProgrammable(this, stateTransitionProver.zkProgrammable, runtime.zkProgrammable, transactionHooks, blockHooks, verificationKeyService);
558
+ this.zkProgrammable = new BlockProverProgrammable(this, stateTransitionProver.zkProgrammable, transactionHooks, blockHooks, stateServiceProvider, verificationKeyService);
480
559
  }
481
560
  async compile(registry) {
482
561
  await registry.forceProverExists(async () => {
@@ -485,15 +564,14 @@ export let BlockProver = class BlockProver extends ProtocolModule {
485
564
  });
486
565
  return await this.zkProgrammable.compile(registry);
487
566
  }
488
- proveTransaction(publicInput, stateProof, appProof, executionData, verificationKeyAttestation) {
489
- return this.zkProgrammable.proveTransaction(publicInput, stateProof, appProof, executionData, verificationKeyAttestation);
567
+ proveTransaction(publicInput, runtimeProof, executionData) {
568
+ return this.zkProgrammable.proveTransaction(publicInput, runtimeProof, executionData);
569
+ }
570
+ proveTransactions(publicInput, runtimeProof1, runtimeProof2, executionData) {
571
+ return this.zkProgrammable.proveTransactions(publicInput, runtimeProof1, runtimeProof2, executionData);
490
572
  }
491
- proveBlock(publicInput, networkState, blockWitness,
492
- // stateTransitionProof: StateTransitionProof,
493
- transactionProof) {
494
- return this.zkProgrammable.proveBlock(publicInput, networkState, blockWitness,
495
- // stateTransitionProof,
496
- transactionProof);
573
+ proveBlock(publicInput, networkState, blockWitness, stateTransitionProof, deferSTs, afterBlockRootWitness, transactionProof) {
574
+ return this.zkProgrammable.proveBlock(publicInput, networkState, blockWitness, stateTransitionProof, deferSTs, afterBlockRootWitness, transactionProof);
497
575
  }
498
576
  merge(publicInput, proof1, proof2) {
499
577
  return this.zkProgrammable.merge(publicInput, proof1, proof2);
@@ -505,6 +583,8 @@ BlockProver = __decorate([
505
583
  __param(1, inject("Runtime")),
506
584
  __param(2, injectAll("ProvableTransactionHook")),
507
585
  __param(3, injectAll("ProvableBlockHook")),
508
- __metadata("design:paramtypes", [Object, Object, Array, Array, RuntimeVerificationKeyRootService])
586
+ __param(4, inject("StateServiceProvider")),
587
+ __metadata("design:paramtypes", [Object, Object, Array, Array, StateServiceProvider,
588
+ RuntimeVerificationKeyRootService])
509
589
  ], BlockProver);
510
590
  //# sourceMappingURL=BlockProver.js.map