@proto-kit/protocol 0.1.1-develop.340 → 0.1.1-develop.456
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.
- package/dist/blockmodules/AccountStateModule.d.ts +1 -1
- package/dist/blockmodules/AccountStateModule.d.ts.map +1 -1
- package/dist/blockmodules/BlockHeightHook.d.ts +7 -0
- package/dist/blockmodules/BlockHeightHook.d.ts.map +1 -0
- package/dist/blockmodules/BlockHeightHook.js +16 -0
- package/dist/blockmodules/NoopBlockHook.d.ts +7 -0
- package/dist/blockmodules/NoopBlockHook.d.ts.map +1 -0
- package/dist/blockmodules/NoopBlockHook.js +9 -0
- package/dist/blockmodules/NoopTransactionHook.d.ts +1 -1
- package/dist/blockmodules/NoopTransactionHook.d.ts.map +1 -1
- package/dist/blockmodules/NoopTransactionHook.js +1 -2
- package/dist/hooks/AccountStateHook.d.ts +38 -0
- package/dist/hooks/AccountStateHook.d.ts.map +1 -0
- package/dist/hooks/AccountStateHook.js +36 -0
- package/dist/hooks/BlockHeightHook.d.ts +7 -0
- package/dist/hooks/BlockHeightHook.d.ts.map +1 -0
- package/dist/hooks/BlockHeightHook.js +14 -0
- package/dist/hooks/NoopBlockHook.d.ts +7 -0
- package/dist/hooks/NoopBlockHook.d.ts.map +1 -0
- package/dist/hooks/NoopBlockHook.js +9 -0
- package/dist/hooks/NoopTransactionHook.d.ts +6 -0
- package/dist/hooks/NoopTransactionHook.d.ts.map +1 -0
- package/dist/hooks/NoopTransactionHook.js +4 -0
- package/dist/hooks/TransactionFeeHook.d.ts +16 -0
- package/dist/hooks/TransactionFeeHook.d.ts.map +1 -0
- package/dist/hooks/TransactionFeeHook.js +39 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/model/Option.d.ts +29 -22
- package/dist/model/Option.d.ts.map +1 -1
- package/dist/model/Option.js +51 -45
- package/dist/model/StateTransition.d.ts +4 -2
- package/dist/model/StateTransition.d.ts.map +1 -1
- package/dist/model/StateTransition.js +2 -2
- package/dist/model/network/NetworkState.d.ts +1 -40
- package/dist/model/network/NetworkState.d.ts.map +1 -1
- package/dist/model/network/NetworkState.js +9 -10
- package/dist/protocol/Protocol.d.ts +4 -18
- package/dist/protocol/Protocol.d.ts.map +1 -1
- package/dist/protocol/Protocol.js +20 -9
- package/dist/protocol/ProtocolModule.d.ts +2 -2
- package/dist/protocol/ProtocolModule.d.ts.map +1 -1
- package/dist/protocol/ProtocolModule.js +1 -1
- package/dist/protocol/ProvableBlockHook.d.ts +16 -0
- package/dist/protocol/ProvableBlockHook.d.ts.map +1 -0
- package/dist/protocol/ProvableBlockHook.js +4 -0
- package/dist/protocol/ProvableTransactionHook.d.ts +2 -1
- package/dist/protocol/ProvableTransactionHook.d.ts.map +1 -1
- package/dist/protocol/TransitioningProtocolModule.d.ts +4 -0
- package/dist/protocol/TransitioningProtocolModule.d.ts.map +1 -1
- package/dist/protocol/TransitioningProtocolModule.js +4 -0
- package/dist/prover/block/BlockProvable.d.ts +21 -6
- package/dist/prover/block/BlockProvable.d.ts.map +1 -1
- package/dist/prover/block/BlockProvable.js +3 -1
- package/dist/prover/block/BlockProver.d.ts +9 -4
- package/dist/prover/block/BlockProver.d.ts.map +1 -1
- package/dist/prover/block/BlockProver.js +66 -16
- package/dist/prover/block/BlockTransactionPosition.d.ts +36 -0
- package/dist/prover/block/BlockTransactionPosition.d.ts.map +1 -0
- package/dist/prover/block/BlockTransactionPosition.js +25 -0
- package/dist/prover/statetransition/StateTransitionProver.d.ts +1 -1
- package/dist/prover/statetransition/StateTransitionProver.d.ts.map +1 -1
- package/dist/prover/statetransition/StateTransitionProver.js +4 -5
- package/dist/prover/statetransition/StateTransitionWitnessProvider.d.ts +3 -3
- package/dist/prover/statetransition/StateTransitionWitnessProvider.d.ts.map +1 -1
- package/dist/prover/statetransition/StateTransitionWitnessProvider.js +2 -2
- package/dist/state/State.d.ts +8 -1
- package/dist/state/State.d.ts.map +1 -1
- package/dist/state/State.js +11 -4
- package/dist/state/StateServiceProvider.d.ts +0 -2
- package/dist/state/StateServiceProvider.d.ts.map +1 -1
- package/dist/state/StateServiceProvider.js +5 -17
- package/package.json +3 -2
- package/src/blockmodules/AccountStateModule.ts +2 -2
- package/src/blockmodules/BlockHeightHook.ts +21 -0
- package/src/blockmodules/NoopBlockHook.ts +16 -0
- package/src/blockmodules/NoopTransactionHook.ts +3 -4
- package/src/index.ts +4 -4
- package/src/model/Option.ts +71 -56
- package/src/model/StateTransition.ts +2 -2
- package/src/model/network/NetworkState.ts +9 -9
- package/src/protocol/Protocol.ts +33 -32
- package/src/protocol/ProtocolModule.ts +3 -3
- package/src/protocol/ProvableBlockHook.ts +22 -0
- package/src/protocol/ProvableTransactionHook.ts +4 -1
- package/src/protocol/TransitioningProtocolModule.ts +4 -0
- package/src/prover/block/BlockProvable.ts +4 -2
- package/src/prover/block/BlockProver.ts +134 -21
- package/src/prover/block/BlockTransactionPosition.ts +34 -0
- package/src/prover/statetransition/StateTransitionProver.ts +6 -13
- package/src/prover/statetransition/StateTransitionWitnessProvider.ts +4 -5
- package/src/state/State.ts +11 -4
- package/src/state/StateServiceProvider.ts +2 -10
- package/test/Option.test.ts +64 -0
- package/test/StateTransition.test.ts +1 -1
- package/dist/utils/merkletree/InMemoryMerkleTreeStorage.d.ts +0 -11
- package/dist/utils/merkletree/InMemoryMerkleTreeStorage.d.ts.map +0 -1
- package/dist/utils/merkletree/InMemoryMerkleTreeStorage.js +0 -12
- package/dist/utils/merkletree/MerkleTreeStore.d.ts +0 -11
- package/dist/utils/merkletree/MerkleTreeStore.d.ts.map +0 -1
- package/dist/utils/merkletree/MerkleTreeStore.js +0 -1
- package/dist/utils/merkletree/RollupMerkleTree.d.ts +0 -132
- package/dist/utils/merkletree/RollupMerkleTree.d.ts.map +0 -1
- package/dist/utils/merkletree/RollupMerkleTree.js +0 -251
- package/src/utils/merkletree/InMemoryMerkleTreeStorage.ts +0 -17
- package/src/utils/merkletree/MerkleTreeStore.ts +0 -15
- package/src/utils/merkletree/RollupMerkleTree.ts +0 -275
- package/src/utils/merkletree/VirtualMerkleTreeStore.ts +0 -21
- package/test/utils/MerkleTree.test.ts +0 -82
|
@@ -11,7 +11,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
11
11
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
12
|
};
|
|
13
13
|
/* eslint-disable max-lines */
|
|
14
|
-
import { Experimental, Field, Provable, SelfProof } from "o1js";
|
|
14
|
+
import { Experimental, Field, Provable, SelfProof, } from "o1js";
|
|
15
15
|
import { container, inject, injectable, injectAll } from "tsyringe";
|
|
16
16
|
import { provableMethod, ZkProgrammable, } from "@proto-kit/common";
|
|
17
17
|
import { DefaultProvableHashList } from "../../utils/ProvableHashList";
|
|
@@ -20,6 +20,8 @@ import { RuntimeTransaction } from "../../model/transaction/RuntimeTransaction";
|
|
|
20
20
|
import { BlockProverExecutionData, BlockProverPublicInput, BlockProverPublicOutput, } from "./BlockProvable";
|
|
21
21
|
import { ProvableStateTransition } from "../../model/StateTransition";
|
|
22
22
|
import { RuntimeMethodExecutionContext } from "../../state/context/RuntimeMethodExecutionContext";
|
|
23
|
+
import { NetworkState } from "../../model/network/NetworkState";
|
|
24
|
+
import { BlockTransactionPosition } from "./BlockTransactionPosition";
|
|
23
25
|
const errors = {
|
|
24
26
|
stateProofNotStartingAtZero: () => "StateProof not starting ST-commitment at zero",
|
|
25
27
|
stateTransitionsHashNotEqual: () => "StateTransition list commitments are not equal",
|
|
@@ -30,12 +32,13 @@ const errors = {
|
|
|
30
32
|
export class BlockProverProgrammable extends ZkProgrammable {
|
|
31
33
|
constructor(
|
|
32
34
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
33
|
-
prover, stateTransitionProver, runtime,
|
|
35
|
+
prover, stateTransitionProver, runtime, transactionHooks, blockHooks) {
|
|
34
36
|
super();
|
|
35
37
|
this.prover = prover;
|
|
36
38
|
this.stateTransitionProver = stateTransitionProver;
|
|
37
39
|
this.runtime = runtime;
|
|
38
|
-
this.
|
|
40
|
+
this.transactionHooks = transactionHooks;
|
|
41
|
+
this.blockHooks = blockHooks;
|
|
39
42
|
}
|
|
40
43
|
get appChain() {
|
|
41
44
|
return this.prover.appChain;
|
|
@@ -75,11 +78,6 @@ export class BlockProverProgrammable extends ZkProgrammable {
|
|
|
75
78
|
// Check network state integrity against appProof
|
|
76
79
|
state.networkStateHash.assertEquals(appProof.publicOutput.networkStateHash, "Network state does not match state used in AppProof");
|
|
77
80
|
state.networkStateHash.assertEquals(networkState.hash(), "Network state provided to BlockProver does not match the publicInput");
|
|
78
|
-
// Append tx to transaction list
|
|
79
|
-
const transactionList = new DefaultProvableHashList(Field, state.transactionsHash);
|
|
80
|
-
const { transactionHash } = appProof.publicOutput;
|
|
81
|
-
transactionList.push(transactionHash);
|
|
82
|
-
stateTo.transactionsHash = transactionList.commitment;
|
|
83
81
|
return stateTo;
|
|
84
82
|
}
|
|
85
83
|
// eslint-disable-next-line no-warning-comments, max-len
|
|
@@ -95,7 +93,7 @@ export class BlockProverProgrammable extends ZkProgrammable {
|
|
|
95
93
|
networkState: executionData.networkState,
|
|
96
94
|
});
|
|
97
95
|
executionContext.beforeMethod("", "", []);
|
|
98
|
-
this.
|
|
96
|
+
this.transactionHooks.forEach((module) => {
|
|
99
97
|
module.onTransaction(executionData);
|
|
100
98
|
});
|
|
101
99
|
executionContext.afterMethod();
|
|
@@ -108,16 +106,68 @@ export class BlockProverProgrammable extends ZkProgrammable {
|
|
|
108
106
|
});
|
|
109
107
|
stateTransitionProof.publicOutput.protocolTransitionsHash.assertEquals(hashList.commitment, "ProtocolTransitionsHash not matching the generated protocol transitions");
|
|
110
108
|
}
|
|
109
|
+
getBeforeBlockNetworkState(state, networkState) {
|
|
110
|
+
return this.blockHooks.reduce((networkState, blockHook) => {
|
|
111
|
+
return blockHook.beforeBlock({
|
|
112
|
+
state,
|
|
113
|
+
networkState,
|
|
114
|
+
});
|
|
115
|
+
}, networkState);
|
|
116
|
+
}
|
|
117
|
+
getAfterBlockNetworkState(state, networkState) {
|
|
118
|
+
return this.blockHooks.reduce((networkState, blockHook) => {
|
|
119
|
+
return blockHook.afterBlock({
|
|
120
|
+
state,
|
|
121
|
+
networkState,
|
|
122
|
+
});
|
|
123
|
+
}, networkState);
|
|
124
|
+
}
|
|
125
|
+
addTransactionToBundle(state, stateTransitionProof, appProof, executionData) {
|
|
126
|
+
const { transactionPosition, networkState } = executionData;
|
|
127
|
+
const stateTo = {
|
|
128
|
+
...state,
|
|
129
|
+
};
|
|
130
|
+
// Execute beforeBlook hooks and apply if it is the first tx of the bundle
|
|
131
|
+
const beforeHookResult = this.getBeforeBlockNetworkState(state, networkState);
|
|
132
|
+
const bundleOpened = transactionPosition.equals(BlockTransactionPosition.fromPositionType("FIRST"));
|
|
133
|
+
const resultingNetworkState = new NetworkState(Provable.if(bundleOpened, NetworkState, beforeHookResult, networkState));
|
|
134
|
+
stateTo.networkStateHash = resultingNetworkState.hash();
|
|
135
|
+
// TODO Modify bundle merkle tree as per specs
|
|
136
|
+
// Append tx to transaction list
|
|
137
|
+
const transactionList = new DefaultProvableHashList(Field, state.transactionsHash);
|
|
138
|
+
const { transactionHash } = appProof.publicOutput;
|
|
139
|
+
transactionList.push(transactionHash);
|
|
140
|
+
stateTo.transactionsHash = transactionList.commitment;
|
|
141
|
+
return {
|
|
142
|
+
state: stateTo,
|
|
143
|
+
networkState: resultingNetworkState,
|
|
144
|
+
bundleOpened,
|
|
145
|
+
bundleClosed: transactionPosition.equals(BlockTransactionPosition.fromPositionType("LAST")),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
111
148
|
proveTransaction(publicInput, stateProof, appProof, executionData) {
|
|
112
149
|
const state = {
|
|
113
150
|
transactionsHash: publicInput.transactionsHash,
|
|
114
151
|
stateRoot: publicInput.stateRoot,
|
|
115
152
|
networkStateHash: publicInput.networkStateHash,
|
|
116
153
|
};
|
|
117
|
-
const
|
|
154
|
+
const bundleInclusionResult = this.addTransactionToBundle(state, stateProof, appProof, executionData);
|
|
155
|
+
const stateTo = this.applyTransaction(bundleInclusionResult.state, stateProof, appProof, {
|
|
156
|
+
transaction: executionData.transaction,
|
|
157
|
+
transactionPosition: executionData.transactionPosition,
|
|
158
|
+
networkState: bundleInclusionResult.networkState,
|
|
159
|
+
});
|
|
160
|
+
// Apply afterBlock hooks
|
|
161
|
+
const afterBlockNetworkState = this.getAfterBlockNetworkState(stateTo, bundleInclusionResult.networkState);
|
|
162
|
+
const bundleClosed = executionData.transactionPosition.equals(BlockTransactionPosition.fromPositionType("LAST"));
|
|
163
|
+
// We only need the hash here since this computed networkstate
|
|
164
|
+
// is only used as an input in the next bundle
|
|
165
|
+
const resultingNetworkStateHash = Provable.if(bundleClosed, afterBlockNetworkState.hash(), stateTo.networkStateHash);
|
|
118
166
|
return new BlockProverPublicOutput({
|
|
119
167
|
stateRoot: stateTo.stateRoot,
|
|
120
168
|
transactionsHash: stateTo.transactionsHash,
|
|
169
|
+
// eslint-disable-next-line putout/putout
|
|
170
|
+
networkStateHash: resultingNetworkStateHash,
|
|
121
171
|
});
|
|
122
172
|
}
|
|
123
173
|
merge(publicInput, proof1, proof2) {
|
|
@@ -131,10 +181,11 @@ export class BlockProverProgrammable extends ZkProgrammable {
|
|
|
131
181
|
proof1.publicOutput.transactionsHash.assertEquals(proof2.publicInput.transactionsHash, errors.transactionsHashNotMatching("proof1.to -> proof2.from"));
|
|
132
182
|
// Check networkhash
|
|
133
183
|
publicInput.networkStateHash.assertEquals(proof1.publicInput.networkStateHash, errors.transactionsHashNotMatching("publicInput.from -> proof1.from"));
|
|
134
|
-
|
|
184
|
+
proof1.publicOutput.networkStateHash.assertEquals(proof2.publicInput.networkStateHash, errors.transactionsHashNotMatching("proof1.to -> proof2.from"));
|
|
135
185
|
return new BlockProverPublicOutput({
|
|
136
186
|
stateRoot: proof2.publicOutput.stateRoot,
|
|
137
187
|
transactionsHash: proof2.publicOutput.transactionsHash,
|
|
188
|
+
networkStateHash: proof2.publicOutput.networkStateHash,
|
|
138
189
|
});
|
|
139
190
|
}
|
|
140
191
|
/**
|
|
@@ -204,13 +255,11 @@ __decorate([
|
|
|
204
255
|
* then be merged to be committed to the base-layer contract
|
|
205
256
|
*/
|
|
206
257
|
let BlockProver = class BlockProver extends ProtocolModule {
|
|
207
|
-
constructor(stateTransitionProver, runtime, transactionHooks) {
|
|
258
|
+
constructor(stateTransitionProver, runtime, transactionHooks, blockHooks) {
|
|
208
259
|
super();
|
|
209
260
|
this.stateTransitionProver = stateTransitionProver;
|
|
210
261
|
this.runtime = runtime;
|
|
211
|
-
this.zkProgrammable = new BlockProverProgrammable(this, stateTransitionProver.zkProgrammable, runtime.zkProgrammable, transactionHooks
|
|
212
|
-
// protocol.dependencyContainer.resolveAll("P rovableTransactionHook")
|
|
213
|
-
);
|
|
262
|
+
this.zkProgrammable = new BlockProverProgrammable(this, stateTransitionProver.zkProgrammable, runtime.zkProgrammable, transactionHooks, blockHooks);
|
|
214
263
|
}
|
|
215
264
|
merge(publicInput, proof1, proof2) {
|
|
216
265
|
return this.zkProgrammable.merge(publicInput, proof1, proof2);
|
|
@@ -224,6 +273,7 @@ BlockProver = __decorate([
|
|
|
224
273
|
__param(0, inject("StateTransitionProver")),
|
|
225
274
|
__param(1, inject("Runtime")),
|
|
226
275
|
__param(2, injectAll("ProvableTransactionHook")),
|
|
227
|
-
|
|
276
|
+
__param(3, injectAll("ProvableBlockHook")),
|
|
277
|
+
__metadata("design:paramtypes", [Object, Object, Array, Array])
|
|
228
278
|
], BlockProver);
|
|
229
279
|
export { BlockProver };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Bool } from "o1js";
|
|
2
|
+
export type BlockTransactionPositionType = "FIRST" | "LAST" | "MIDDLE";
|
|
3
|
+
declare const BlockTransactionPosition_base: (new (value: {
|
|
4
|
+
type: import("o1js/dist/node/lib/field").Field;
|
|
5
|
+
}) => {
|
|
6
|
+
type: import("o1js/dist/node/lib/field").Field;
|
|
7
|
+
}) & {
|
|
8
|
+
_isStruct: true;
|
|
9
|
+
} & import("o1js/dist/node/snarky").ProvablePure<{
|
|
10
|
+
type: import("o1js/dist/node/lib/field").Field;
|
|
11
|
+
}> & {
|
|
12
|
+
toInput: (x: {
|
|
13
|
+
type: import("o1js/dist/node/lib/field").Field;
|
|
14
|
+
}) => {
|
|
15
|
+
fields?: import("o1js/dist/node/lib/field").Field[] | undefined;
|
|
16
|
+
packed?: [import("o1js/dist/node/lib/field").Field, number][] | undefined;
|
|
17
|
+
};
|
|
18
|
+
toJSON: (x: {
|
|
19
|
+
type: import("o1js/dist/node/lib/field").Field;
|
|
20
|
+
}) => {
|
|
21
|
+
type: string;
|
|
22
|
+
};
|
|
23
|
+
fromJSON: (x: {
|
|
24
|
+
type: string;
|
|
25
|
+
}) => {
|
|
26
|
+
type: import("o1js/dist/node/lib/field").Field;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export declare class BlockTransactionPosition extends BlockTransactionPosition_base {
|
|
30
|
+
private static readonly fieldMapping;
|
|
31
|
+
static fromPositionType(type: BlockTransactionPositionType): BlockTransactionPosition;
|
|
32
|
+
static positionTypeFromIndex(index: number, bundleLength: number): BlockTransactionPositionType;
|
|
33
|
+
equals(type: BlockTransactionPosition): Bool;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=BlockTransactionPosition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BlockTransactionPosition.d.ts","sourceRoot":"","sources":["../../../src/prover/block/BlockTransactionPosition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAiB,MAAM,MAAM,CAAC;AAG3C,MAAM,MAAM,4BAA4B,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEvE,qBAAa,wBAAyB,SAAQ,6BAE5C;IACA,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAOlC;WAEY,gBAAgB,CAAC,IAAI,EAAE,4BAA4B;WAMnD,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;IAOhE,MAAM,CAAC,IAAI,EAAE,wBAAwB,GAAG,IAAI;CAGpD"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Field, Struct } from "o1js";
|
|
2
|
+
import { match } from "ts-pattern";
|
|
3
|
+
export class BlockTransactionPosition extends Struct({
|
|
4
|
+
type: Field,
|
|
5
|
+
}) {
|
|
6
|
+
static fromPositionType(type) {
|
|
7
|
+
return new BlockTransactionPosition({
|
|
8
|
+
type: Field(BlockTransactionPosition.fieldMapping[type]).toConstant(),
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
static positionTypeFromIndex(index, bundleLength) {
|
|
12
|
+
return match(index)
|
|
13
|
+
.with(0, () => "FIRST")
|
|
14
|
+
.with(bundleLength - 1, () => "LAST")
|
|
15
|
+
.otherwise(() => "MIDDLE");
|
|
16
|
+
}
|
|
17
|
+
equals(type) {
|
|
18
|
+
return this.type.equals(type.type);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
BlockTransactionPosition.fieldMapping = {
|
|
22
|
+
FIRST: 0,
|
|
23
|
+
MIDDLE: 1,
|
|
24
|
+
LAST: 2,
|
|
25
|
+
};
|
|
@@ -39,7 +39,7 @@ export declare class StateTransitionProverProgrammable extends ZkProgrammable<St
|
|
|
39
39
|
runBatch(publicInput: StateTransitionProverPublicInput, batch: StateTransitionProvableBatch): StateTransitionProverPublicOutput;
|
|
40
40
|
merge(publicInput: StateTransitionProverPublicInput, proof1: StateTransitionProof, proof2: StateTransitionProof): StateTransitionProverPublicOutput;
|
|
41
41
|
}
|
|
42
|
-
export declare class StateTransitionProver extends ProtocolModule
|
|
42
|
+
export declare class StateTransitionProver extends ProtocolModule implements StateTransitionProvable {
|
|
43
43
|
readonly witnessProviderReference: StateTransitionWitnessProviderReference;
|
|
44
44
|
readonly zkProgrammable: StateTransitionProverProgrammable;
|
|
45
45
|
constructor(witnessProviderReference: StateTransitionWitnessProviderReference);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StateTransitionProver.d.ts","sourceRoot":"","sources":["../../../src/prover/statetransition/StateTransitionProver.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,KAAK,EAAuB,MAAM,MAAM,CAAC;AAEtE,OAAO,EACL,gBAAgB,EAEhB,cAAc,
|
|
1
|
+
{"version":3,"file":"StateTransitionProver.d.ts","sourceRoot":"","sources":["../../../src/prover/statetransition/StateTransitionProver.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,KAAK,EAAuB,MAAM,MAAM,CAAC;AAEtE,OAAO,EACL,gBAAgB,EAEhB,cAAc,EAGd,cAAc,EACf,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAEL,gBAAgB,EACjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EACL,2BAA2B,EAC3B,4BAA4B,EAC7B,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAG/D,OAAO,EACL,uBAAuB,EACvB,gCAAgC,EAChC,oBAAoB,EACpB,iCAAiC,EAClC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,uCAAuC,EAAE,MAAM,2CAA2C,CAAC;AAepG,UAAU,mCAAmC;IAC3C,SAAS,EAAE,KAAK,CAAC;IACjB,iBAAiB,EAAE,KAAK,CAAC;IACzB,mBAAmB,EAAE,gBAAgB,CAAC,uBAAuB,CAAC,CAAC;IAC/D,sBAAsB,EAAE,gBAAgB,CAAC,uBAAuB,CAAC,CAAC;CACnE;AAOD;;;GAGG;AACH,qBAAa,iCAAkC,SAAQ,cAAc,CACnE,gCAAgC,EAChC,iCAAiC,CAClC;IAGG,OAAO,CAAC,QAAQ,CAAC,qBAAqB;aACtB,wBAAwB,EAAE,uCAAuC;gBADhE,qBAAqB,EAAE,qBAAqB,EAC7C,wBAAwB,EAAE,uCAAuC;IAKnF,IAAW,QAAQ,IAAI,gBAAgB,GAAG,SAAS,CAElD;IAEM,gBAAgB,IAAI,cAAc,CACvC,gCAAgC,EAChC,iCAAiC,CAClC;IAqDD,OAAO,KAAK,eAAe,GAM1B;IAED;;;OAGG;IACI,gBAAgB,CACrB,SAAS,EAAE,KAAK,EAChB,iBAAiB,EAAE,KAAK,EACxB,6BAA6B,EAAE,KAAK,EACpC,gCAAgC,EAAE,KAAK,EACvC,eAAe,EAAE,4BAA4B,GAC5C,mCAAmC;IA6BtC;;;OAGG;IACI,eAAe,CACpB,KAAK,EAAE,mCAAmC,EAC1C,UAAU,EAAE,uBAAuB,EACnC,IAAI,EAAE,2BAA2B,EACjC,KAAK,SAAI;IAiDX;;OAEG;IAEI,QAAQ,CACb,WAAW,EAAE,gCAAgC,EAC7C,KAAK,EAAE,4BAA4B,GAClC,iCAAiC;IAkB7B,KAAK,CACV,WAAW,EAAE,gCAAgC,EAC7C,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,oBAAoB,GAC3B,iCAAiC;CAqErC;AAED,qBACa,qBACX,SAAQ,cACR,YAAW,uBAAuB;aAMhB,wBAAwB,EAAE,uCAAuC;IAJnF,SAAgB,cAAc,EAAE,iCAAiC,CAAC;gBAIhD,wBAAwB,EAAE,uCAAuC;IAS5E,QAAQ,CACb,WAAW,EAAE,gCAAgC,EAC7C,KAAK,EAAE,4BAA4B,GAClC,iCAAiC;IAI7B,KAAK,CACV,WAAW,EAAE,gCAAgC,EAC7C,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,oBAAoB,GAC3B,iCAAiC;CAGrC"}
|
|
@@ -10,8 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
/* eslint-disable max-lines */
|
|
11
11
|
import { Experimental, Field, Provable, SelfProof } from "o1js";
|
|
12
12
|
import { injectable } from "tsyringe";
|
|
13
|
-
import { provableMethod, ZkProgrammable, } from "@proto-kit/common";
|
|
14
|
-
import { MerkleTreeUtils, RollupMerkleWitness, } from "../../utils/merkletree/RollupMerkleTree.js";
|
|
13
|
+
import { provableMethod, RollupMerkleTreeWitness, ZkProgrammable, } from "@proto-kit/common";
|
|
15
14
|
import { DefaultProvableHashList, } from "../../utils/ProvableHashList";
|
|
16
15
|
import { ProvableStateTransition } from "../../model/StateTransition";
|
|
17
16
|
import { StateTransitionProvableBatch, } from "../../model/StateTransitionProvableBatch";
|
|
@@ -107,12 +106,12 @@ export class StateTransitionProverProgrammable extends ZkProgrammable {
|
|
|
107
106
|
* and mutates it in place
|
|
108
107
|
*/
|
|
109
108
|
applyTransition(state, transition, type, index = 0) {
|
|
110
|
-
const
|
|
111
|
-
const membershipValid =
|
|
109
|
+
const witness = Provable.witness(RollupMerkleTreeWitness, () => this.witnessProvider.getWitness(transition.path));
|
|
110
|
+
const membershipValid = witness.checkMembership(state.stateRoot, transition.path, transition.from.value);
|
|
112
111
|
membershipValid
|
|
113
112
|
.or(transition.from.isSome.not())
|
|
114
113
|
.assertTrue(errors.merkleWitnessNotCorrect(index, type.isNormal().toBoolean() ? "normal" : "protocol"));
|
|
115
|
-
const newRoot =
|
|
114
|
+
const newRoot = witness.calculateRoot(transition.to.value);
|
|
116
115
|
state.stateRoot = Provable.if(transition.to.isSome, newRoot, state.stateRoot);
|
|
117
116
|
// Only update protocol state root if ST is also of type protocol
|
|
118
117
|
// Since protocol STs are all at the start of the batch, this works
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Field } from "o1js";
|
|
2
|
-
import {
|
|
2
|
+
import { RollupMerkleTreeWitness } from "@proto-kit/common";
|
|
3
3
|
/**
|
|
4
4
|
* Interface for providing merkle witnesses to the state-transition prover
|
|
5
5
|
*/
|
|
@@ -8,9 +8,9 @@ export interface StateTransitionWitnessProvider {
|
|
|
8
8
|
* Provides the merkle witness corresponding to the given key
|
|
9
9
|
* @param key Merkle-tree key
|
|
10
10
|
*/
|
|
11
|
-
getWitness: (key: Field) =>
|
|
11
|
+
getWitness: (key: Field) => RollupMerkleTreeWitness;
|
|
12
12
|
}
|
|
13
13
|
export declare class NoOpStateTransitionWitnessProvider implements StateTransitionWitnessProvider {
|
|
14
|
-
getWitness():
|
|
14
|
+
getWitness(): RollupMerkleTreeWitness;
|
|
15
15
|
}
|
|
16
16
|
//# sourceMappingURL=StateTransitionWitnessProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StateTransitionWitnessProvider.d.ts","sourceRoot":"","sources":["../../../src/prover/statetransition/StateTransitionWitnessProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"StateTransitionWitnessProvider.d.ts","sourceRoot":"","sources":["../../../src/prover/statetransition/StateTransitionWitnessProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C;;;OAGG;IACH,UAAU,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,uBAAuB,CAAC;CACrD;AAED,qBACa,kCACX,YAAW,8BAA8B;IAElC,UAAU,IAAI,uBAAuB;CAG7C"}
|
|
@@ -5,10 +5,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { injectable } from "tsyringe";
|
|
8
|
-
import {
|
|
8
|
+
import { RollupMerkleTreeWitness } from "@proto-kit/common";
|
|
9
9
|
let NoOpStateTransitionWitnessProvider = class NoOpStateTransitionWitnessProvider {
|
|
10
10
|
getWitness() {
|
|
11
|
-
return new
|
|
11
|
+
return new RollupMerkleTreeWitness({ path: [], isLeft: [] });
|
|
12
12
|
}
|
|
13
13
|
};
|
|
14
14
|
NoOpStateTransitionWitnessProvider = __decorate([
|
package/dist/state/State.d.ts
CHANGED
|
@@ -28,6 +28,13 @@ export declare class State<Value> extends State_base {
|
|
|
28
28
|
*/
|
|
29
29
|
static from<Value>(valueType: FlexibleProvablePure<Value>): State<Value>;
|
|
30
30
|
constructor(valueType: FlexibleProvablePure<Value>);
|
|
31
|
+
/**
|
|
32
|
+
* Returns the state that is currently the current state tree
|
|
33
|
+
* value: The value-fields, or if not state was found, dummy values
|
|
34
|
+
* isSome: Whether the values where found in the state or not
|
|
35
|
+
* (Basically, whether the value-fields are dummy values or actual values
|
|
36
|
+
* @private
|
|
37
|
+
*/
|
|
31
38
|
private getState;
|
|
32
39
|
/**
|
|
33
40
|
* Provides an in-circuit witness for the current state representation,
|
|
@@ -35,7 +42,7 @@ export declare class State<Value> extends State_base {
|
|
|
35
42
|
*
|
|
36
43
|
* @returns Optional value of the current state
|
|
37
44
|
*/
|
|
38
|
-
private
|
|
45
|
+
private witnessFromState;
|
|
39
46
|
/**
|
|
40
47
|
* Retrieves the current state and creates a state transition
|
|
41
48
|
* anchoring the use of the current state value in the circuit.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../src/state/State.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,KAAK,EAAY,KAAK,oBAAoB,EAAE,MAAM,MAAM,CAAC;AAIxE,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAGzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAG9D,qBAAa,QAAQ;IACZ,IAAI,CAAC,EAAE,KAAK,CAAC;IAEb,aAAa,IAAI,OAAO,CAAC,IAAI,IAAI;QAAE,IAAI,EAAE,IAAI,CAAA;KAAE;CAOvD;AAED,qBAAa,wBAAwB;IAC5B,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAE5C,qBAAqB,IAAI,OAAO,CAAC,IAAI,IAAI;QAC9C,oBAAoB,EAAE,oBAAoB,CAAC;KAC5C;CAOF;;AAED;;GAEG;AACH,qBAAa,KAAK,CAAC,KAAK,CAAE,SAAQ,UAAyC;IAW/C,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;IAVhE;;;;;OAKG;WACW,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;gBAItC,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;IAIhE,OAAO,CAAC,QAAQ;IAuChB;;;;;OAKG;IACH,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../src/state/State.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,KAAK,EAAY,KAAK,oBAAoB,EAAE,MAAM,MAAM,CAAC;AAIxE,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAGzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAG9D,qBAAa,QAAQ;IACZ,IAAI,CAAC,EAAE,KAAK,CAAC;IAEb,aAAa,IAAI,OAAO,CAAC,IAAI,IAAI;QAAE,IAAI,EAAE,IAAI,CAAA;KAAE;CAOvD;AAED,qBAAa,wBAAwB;IAC5B,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAE5C,qBAAqB,IAAI,OAAO,CAAC,IAAI,IAAI;QAC9C,oBAAoB,EAAE,oBAAoB,CAAC;KAC5C;CAOF;;AAED;;GAEG;AACH,qBAAa,KAAK,CAAC,KAAK,CAAE,SAAQ,UAAyC;IAW/C,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;IAVhE;;;;;OAKG;WACW,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;gBAItC,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC;IAIhE;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ;IAuChB;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAUxB;;;;;OAKG;IACI,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC;IAc3B;;;;;;;;;;OAUG;IACI,GAAG,CAAC,KAAK,EAAE,KAAK;CAiBxB"}
|
package/dist/state/State.js
CHANGED
|
@@ -36,6 +36,13 @@ export class State extends Mixin(WithPath, WithStateServiceProvider) {
|
|
|
36
36
|
super();
|
|
37
37
|
this.valueType = valueType;
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns the state that is currently the current state tree
|
|
41
|
+
* value: The value-fields, or if not state was found, dummy values
|
|
42
|
+
* isSome: Whether the values where found in the state or not
|
|
43
|
+
* (Basically, whether the value-fields are dummy values or actual values
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
39
46
|
getState() {
|
|
40
47
|
this.hasStateServiceOrFail();
|
|
41
48
|
this.hasPathOrFail();
|
|
@@ -70,7 +77,7 @@ export class State extends Mixin(WithPath, WithStateServiceProvider) {
|
|
|
70
77
|
*
|
|
71
78
|
* @returns Optional value of the current state
|
|
72
79
|
*/
|
|
73
|
-
|
|
80
|
+
witnessFromState() {
|
|
74
81
|
// get the value from storage, or return a dummy value instead
|
|
75
82
|
const value = Provable.witness(this.valueType, () => this.getState().value);
|
|
76
83
|
// check if the value exists in the storage or not
|
|
@@ -84,7 +91,7 @@ export class State extends Mixin(WithPath, WithStateServiceProvider) {
|
|
|
84
91
|
* @returns Option representation of the current state.
|
|
85
92
|
*/
|
|
86
93
|
get() {
|
|
87
|
-
const option = this.
|
|
94
|
+
const option = this.witnessFromState();
|
|
88
95
|
this.hasPathOrFail();
|
|
89
96
|
const stateTransition = StateTransition.from(this.path, option);
|
|
90
97
|
container
|
|
@@ -105,8 +112,8 @@ export class State extends Mixin(WithPath, WithStateServiceProvider) {
|
|
|
105
112
|
*/
|
|
106
113
|
set(value) {
|
|
107
114
|
// link the transition to the current state
|
|
108
|
-
const fromOption = this.
|
|
109
|
-
const toOption = Option.
|
|
115
|
+
const fromOption = this.witnessFromState();
|
|
116
|
+
const toOption = Option.fromValue(value, this.valueType);
|
|
110
117
|
this.hasPathOrFail();
|
|
111
118
|
const stateTransition = StateTransition.fromTo(this.path, fromOption, toOption);
|
|
112
119
|
container
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { StateService } from "./StateService";
|
|
2
2
|
export declare class StateServiceProvider {
|
|
3
|
-
private readonly baseStateService?;
|
|
4
3
|
private readonly stateServiceStack;
|
|
5
|
-
constructor(baseStateService?: StateService | undefined);
|
|
6
4
|
get stateService(): StateService;
|
|
7
5
|
setCurrentStateService(service: StateService): void;
|
|
8
6
|
popCurrentStateService(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StateServiceProvider.d.ts","sourceRoot":"","sources":["../../src/state/StateServiceProvider.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAU9C,qBACa,oBAAoB;
|
|
1
|
+
{"version":3,"file":"StateServiceProvider.d.ts","sourceRoot":"","sources":["../../src/state/StateServiceProvider.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAU9C,qBACa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAsB;IAExD,IAAW,YAAY,IAAI,YAAY,CAQtC;IAEM,sBAAsB,CAAC,OAAO,EAAE,YAAY;IAI5C,sBAAsB;CAO9B"}
|
|
@@ -4,24 +4,14 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
-
};
|
|
13
|
-
import { inject, injectable } from "tsyringe";
|
|
7
|
+
import { injectable } from "tsyringe";
|
|
14
8
|
import { log } from "@proto-kit/common";
|
|
15
9
|
const errors = {
|
|
16
10
|
stateServiceNotSet: () => new Error("StateService has not been set yet. Be sure to either call your runtime or protocol function by creating them with an AppChain or by setting the stateService manually."),
|
|
17
11
|
};
|
|
18
12
|
let StateServiceProvider = class StateServiceProvider {
|
|
19
|
-
constructor(
|
|
20
|
-
this.baseStateService = baseStateService;
|
|
13
|
+
constructor() {
|
|
21
14
|
this.stateServiceStack = [];
|
|
22
|
-
if (baseStateService !== undefined) {
|
|
23
|
-
this.stateServiceStack.push(baseStateService);
|
|
24
|
-
}
|
|
25
15
|
}
|
|
26
16
|
get stateService() {
|
|
27
17
|
if (this.stateServiceStack.length === 0) {
|
|
@@ -35,16 +25,14 @@ let StateServiceProvider = class StateServiceProvider {
|
|
|
35
25
|
this.stateServiceStack.push(service);
|
|
36
26
|
}
|
|
37
27
|
popCurrentStateService() {
|
|
38
|
-
if (this.stateServiceStack.length ===
|
|
39
|
-
log.trace("Trying to pop
|
|
28
|
+
if (this.stateServiceStack.length === 0) {
|
|
29
|
+
log.trace("Trying to pop from empty state-service stack");
|
|
40
30
|
return;
|
|
41
31
|
}
|
|
42
32
|
this.stateServiceStack.pop();
|
|
43
33
|
}
|
|
44
34
|
};
|
|
45
35
|
StateServiceProvider = __decorate([
|
|
46
|
-
injectable()
|
|
47
|
-
__param(0, inject("StateService")),
|
|
48
|
-
__metadata("design:paramtypes", [Object])
|
|
36
|
+
injectable()
|
|
49
37
|
], StateServiceProvider);
|
|
50
38
|
export { StateServiceProvider };
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
|
-
"version": "0.1.1-develop.
|
|
6
|
+
"version": "0.1.1-develop.456+bdb345d",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc -p tsconfig.json",
|
|
9
9
|
"dev": "tsc -p tsconfig.json --watch",
|
|
@@ -25,11 +25,12 @@
|
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"@proto-kit/common": "*",
|
|
27
27
|
"o1js": "0.13.1",
|
|
28
|
+
"ts-pattern": "^4.3.0",
|
|
28
29
|
"tsyringe": "^4.7.0"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@jest/globals": "^29.5.0",
|
|
32
33
|
"@types/lodash": "^4.14.194"
|
|
33
34
|
},
|
|
34
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "bdb345d9e6132387a870c8a4236d8fe295502ce4"
|
|
35
36
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PublicKey, Struct, UInt64 } from "o1js";
|
|
2
2
|
|
|
3
3
|
import { BlockProverExecutionData } from "../prover/block/BlockProvable";
|
|
4
4
|
import { StateMap } from "../state/StateMap";
|
|
@@ -10,7 +10,7 @@ export class AccountState extends Struct({
|
|
|
10
10
|
nonce: UInt64,
|
|
11
11
|
}) {}
|
|
12
12
|
|
|
13
|
-
export class AccountStateModule extends ProvableTransactionHook
|
|
13
|
+
export class AccountStateModule extends ProvableTransactionHook {
|
|
14
14
|
@protocolState() public accountState = StateMap.from<PublicKey, AccountState>(
|
|
15
15
|
PublicKey,
|
|
16
16
|
AccountState
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Provable } from "o1js";
|
|
2
|
+
import { NetworkState } from "../model/network/NetworkState";
|
|
3
|
+
import {
|
|
4
|
+
AfterBlockParameters,
|
|
5
|
+
BeforeBlockParameters,
|
|
6
|
+
ProvableBlockHook,
|
|
7
|
+
} from "../protocol/ProvableBlockHook";
|
|
8
|
+
|
|
9
|
+
export class BlockHeightHook extends ProvableBlockHook<Record<string, never>> {
|
|
10
|
+
public afterBlock({ networkState }: AfterBlockParameters): NetworkState {
|
|
11
|
+
return new NetworkState({
|
|
12
|
+
block: {
|
|
13
|
+
height: networkState.block.height.add(1),
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public beforeBlock(blockData: BeforeBlockParameters): NetworkState {
|
|
19
|
+
return blockData.networkState;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AfterBlockParameters,
|
|
3
|
+
BeforeBlockParameters,
|
|
4
|
+
ProvableBlockHook
|
|
5
|
+
} from "../protocol/ProvableBlockHook";
|
|
6
|
+
import { NetworkState } from "../model/network/NetworkState";
|
|
7
|
+
|
|
8
|
+
export class NoopBlockHook extends ProvableBlockHook<Record<string, never>>{
|
|
9
|
+
public afterBlock(blockData: AfterBlockParameters): NetworkState {
|
|
10
|
+
return blockData.networkState;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public beforeBlock(blockData: BeforeBlockParameters): NetworkState {
|
|
14
|
+
return blockData.networkState;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ProvableTransactionHook } from "../protocol/ProvableTransactionHook";
|
|
2
2
|
import { BlockProverExecutionData } from "../prover/block/BlockProvable";
|
|
3
3
|
|
|
4
|
-
export class NoopTransactionHook extends ProvableTransactionHook
|
|
5
|
-
public onTransaction(executionData: BlockProverExecutionData): void {
|
|
6
|
-
|
|
7
|
-
}
|
|
4
|
+
export class NoopTransactionHook extends ProvableTransactionHook {
|
|
5
|
+
public onTransaction(executionData: BlockProverExecutionData): void {}
|
|
6
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from "./blockmodules/AccountStateModule";
|
|
2
|
+
export * from "./blockmodules/BlockHeightHook";
|
|
2
3
|
export * from "./utils/ProvableHashList";
|
|
3
4
|
export * from "./model/StateTransition";
|
|
4
5
|
export * from "./model/StateTransitionProvableBatch";
|
|
@@ -11,18 +12,17 @@ export * from "./utils/PrefixedProvableHashList.js";
|
|
|
11
12
|
export * from "./utils/utils";
|
|
12
13
|
export * from "./prover/block/BlockProver";
|
|
13
14
|
export * from "./prover/block/BlockProvable";
|
|
15
|
+
export * from "./prover/block/BlockTransactionPosition";
|
|
14
16
|
export * from "./prover/statetransition/StateTransitionProver";
|
|
15
17
|
export * from "./prover/statetransition/StateTransitionProvable";
|
|
16
18
|
export * from "./prover/statetransition/StateTransitionWitnessProvider";
|
|
17
|
-
export * from "./utils/merkletree/MerkleTreeStore";
|
|
18
|
-
export * from "./utils/merkletree/InMemoryMerkleTreeStorage";
|
|
19
|
-
export * from "./utils/merkletree/RollupMerkleTree";
|
|
20
19
|
export * from "./model/MethodPublicOutput";
|
|
21
20
|
export * from "./prover/statetransition/StateTransitionWitnessProviderReference";
|
|
22
21
|
export * from "./protocol/Protocol";
|
|
23
22
|
export * from "./protocol/ProtocolModule";
|
|
24
|
-
export * from "./protocol/
|
|
23
|
+
export * from "./protocol/ProtocolEnvironment";
|
|
25
24
|
export * from "./protocol/ProvableTransactionHook";
|
|
25
|
+
export * from "./protocol/ProvableBlockHook";
|
|
26
26
|
export * from "./state/context/ProtocolMethodExecutionContext";
|
|
27
27
|
export * from "./state/context/TransitionMethodExecutionContext";
|
|
28
28
|
export * from "./state/context/RuntimeMethodExecutionContext";
|