@proto-kit/protocol 0.1.1-develop.261 → 0.1.1-develop.267
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/prover/statetransition/StateTransitionProver.d.ts.map +1 -1
- package/dist/prover/statetransition/StateTransitionProver.js +5 -0
- package/dist/state/StateServiceProvider.d.ts +4 -4
- package/dist/state/StateServiceProvider.d.ts.map +1 -1
- package/dist/state/StateServiceProvider.js +19 -11
- package/dist/state/assert/assert.d.ts.map +1 -1
- package/dist/state/assert/assert.js +3 -1
- package/dist/state/context/RuntimeMethodExecutionContext.d.ts +1 -0
- package/dist/state/context/RuntimeMethodExecutionContext.d.ts.map +1 -1
- package/dist/state/context/RuntimeMethodExecutionContext.js +1 -0
- package/dist/utils/merkletree/InMemoryMerkleTreeStorage.d.ts +1 -15
- package/dist/utils/merkletree/InMemoryMerkleTreeStorage.d.ts.map +1 -1
- package/dist/utils/merkletree/InMemoryMerkleTreeStorage.js +0 -65
- package/dist/utils/merkletree/MerkleTreeStore.d.ts +2 -2
- package/dist/utils/merkletree/MerkleTreeStore.d.ts.map +1 -1
- package/dist/utils/merkletree/RollupMerkleTree.d.ts +2 -0
- package/dist/utils/merkletree/RollupMerkleTree.d.ts.map +1 -1
- package/dist/utils/merkletree/RollupMerkleTree.js +13 -0
- package/package.json +2 -2
- package/src/prover/statetransition/StateTransitionProver.ts +6 -0
- package/src/state/StateServiceProvider.ts +21 -12
- package/src/state/assert/assert.ts +3 -1
- package/src/state/context/RuntimeMethodExecutionContext.ts +1 -0
- package/src/utils/merkletree/InMemoryMerkleTreeStorage.ts +1 -90
- package/src/utils/merkletree/MerkleTreeStore.ts +2 -2
- package/src/utils/merkletree/RollupMerkleTree.ts +21 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StateTransitionProver.d.ts","sourceRoot":"","sources":["../../../src/prover/statetransition/StateTransitionProver.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,KAAK,EAAuB,MAAM,UAAU,CAAC;AAE1E,OAAO,EACL,gBAAgB,EAEhB,cAAc,EAEd,cAAc,EACf,MAAM,mBAAmB,CAAC;AAM3B,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;
|
|
1
|
+
{"version":3,"file":"StateTransitionProver.d.ts","sourceRoot":"","sources":["../../../src/prover/statetransition/StateTransitionProver.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,KAAK,EAAuB,MAAM,UAAU,CAAC;AAE1E,OAAO,EACL,gBAAgB,EAEhB,cAAc,EAEd,cAAc,EACf,MAAM,mBAAmB,CAAC;AAM3B,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;IA2DX;;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"}
|
|
@@ -109,6 +109,11 @@ export class StateTransitionProverProgrammable extends ZkProgrammable {
|
|
|
109
109
|
applyTransition(state, transition, type, index = 0) {
|
|
110
110
|
const treeWitness = Provable.witness(RollupMerkleWitness, () => this.witnessProvider.getWitness(transition.path));
|
|
111
111
|
const membershipValid = MerkleTreeUtils.checkMembership(treeWitness, state.stateRoot, transition.path, transition.from.value);
|
|
112
|
+
// if (!membershipValid.toBoolean()) {
|
|
113
|
+
// console.log(
|
|
114
|
+
// `Merklewitness error ${root1.toString()} ${root2.toString()}`
|
|
115
|
+
// );
|
|
116
|
+
// }
|
|
112
117
|
membershipValid
|
|
113
118
|
.or(transition.from.isSome.not())
|
|
114
119
|
.assertTrue(errors.merkleWitnessNotCorrect(index, type.isNormal().toBoolean() ? "normal" : "protocol"));
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { StateService } from "./StateService";
|
|
2
2
|
export declare class StateServiceProvider {
|
|
3
|
-
private
|
|
4
|
-
private readonly
|
|
5
|
-
constructor(
|
|
3
|
+
private readonly baseStateService?;
|
|
4
|
+
private readonly stateServiceStack;
|
|
5
|
+
constructor(baseStateService?: StateService | undefined);
|
|
6
6
|
get stateService(): StateService;
|
|
7
7
|
setCurrentStateService(service: StateService): void;
|
|
8
|
-
|
|
8
|
+
popCurrentStateService(): void;
|
|
9
9
|
}
|
|
10
10
|
//# sourceMappingURL=StateServiceProvider.d.ts.map
|
|
@@ -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;
|
|
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;IAIL,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC;IAH5D,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAsB;gBAGb,gBAAgB,CAAC,0BAAc;IAO1E,IAAW,YAAY,IAAI,YAAY,CAQtC;IAEM,sBAAsB,CAAC,OAAO,EAAE,YAAY;IAI5C,sBAAsB;CAO9B"}
|
|
@@ -11,27 +11,35 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
11
11
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
12
|
};
|
|
13
13
|
import { inject, injectable } from "tsyringe";
|
|
14
|
+
import { log } from "@proto-kit/common";
|
|
14
15
|
const errors = {
|
|
15
|
-
stateServiceNotSet: () => new Error(
|
|
16
|
-
protocol function by creating them with an AppChain or by setting the
|
|
17
|
-
stateService manually.`),
|
|
16
|
+
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."),
|
|
18
17
|
};
|
|
19
18
|
let StateServiceProvider = class StateServiceProvider {
|
|
20
|
-
constructor(
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
19
|
+
constructor(baseStateService) {
|
|
20
|
+
this.baseStateService = baseStateService;
|
|
21
|
+
this.stateServiceStack = [];
|
|
22
|
+
if (baseStateService !== undefined) {
|
|
23
|
+
this.stateServiceStack.push(baseStateService);
|
|
24
|
+
}
|
|
23
25
|
}
|
|
24
26
|
get stateService() {
|
|
25
|
-
if (this.
|
|
27
|
+
if (this.stateServiceStack.length === 0) {
|
|
26
28
|
throw errors.stateServiceNotSet();
|
|
27
29
|
}
|
|
28
|
-
|
|
30
|
+
// Assertion here is ok, because we check that the array is not empty above
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
32
|
+
return this.stateServiceStack.at(-1);
|
|
29
33
|
}
|
|
30
34
|
setCurrentStateService(service) {
|
|
31
|
-
this.
|
|
35
|
+
this.stateServiceStack.push(service);
|
|
32
36
|
}
|
|
33
|
-
|
|
34
|
-
this.
|
|
37
|
+
popCurrentStateService() {
|
|
38
|
+
if (this.stateServiceStack.length === 1) {
|
|
39
|
+
log.trace("Trying to pop last available (root) stateservice");
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
this.stateServiceStack.pop();
|
|
35
43
|
}
|
|
36
44
|
};
|
|
37
45
|
StateServiceProvider = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../../src/state/assert/assert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAMhC;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../../src/state/assert/assert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAMhC;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,MAAM,QAavD"}
|
|
@@ -15,7 +15,9 @@ export function assert(condition, message) {
|
|
|
15
15
|
const previousStatus = executionContext.current().result.status;
|
|
16
16
|
const status = condition.and(previousStatus);
|
|
17
17
|
if (!condition.toBoolean()) {
|
|
18
|
-
|
|
18
|
+
if (!executionContext.current().isSimulated) {
|
|
19
|
+
log.debug("Assertion failed: ", message);
|
|
20
|
+
}
|
|
19
21
|
executionContext.setStatusMessage(message);
|
|
20
22
|
}
|
|
21
23
|
executionContext.setStatus(status);
|
|
@@ -55,6 +55,7 @@ export declare class RuntimeMethodExecutionContext extends ProvableMethodExecuti
|
|
|
55
55
|
isFinished: boolean;
|
|
56
56
|
result: RuntimeProvableMethodExecutionResult;
|
|
57
57
|
input: RuntimeMethodExecutionData | undefined;
|
|
58
|
+
isSimulated: boolean;
|
|
58
59
|
};
|
|
59
60
|
}
|
|
60
61
|
//# sourceMappingURL=RuntimeMethodExecutionContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RuntimeMethodExecutionContext.d.ts","sourceRoot":"","sources":["../../../src/state/context/RuntimeMethodExecutionContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAE,8BAA8B,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AAClG,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAShE,qBAAa,oCAAqC,SAAQ,6BAA6B;IAE9E,gBAAgB,EAAE,eAAe,CAAC,GAAG,CAAC,EAAE,CAAM;IAE9C,MAAM,EAAE,IAAI,CAAc;IAE1B,aAAa,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,0BAA0B;IACzC,WAAW,EAAE,kBAAkB,CAAC;IAChC,YAAY,EAAE,YAAY,CAAC;CAC5B;AAED;;;;GAIG;AACH,qBACa,6BAA8B,SAAQ,8BAA8B;IACxE,OAAO,EAAE,MAAM,EAAE,CAAM;IAEvB,KAAK,EAAE,0BAA0B,GAAG,SAAS,CAAC;IAGrD,OAAO,CAAC,SAAS,CAAyC;IAE1C,MAAM,uCAA8C;IAEpE,OAAO,CAAC,WAAW,CAAkB;IAErC,OAAO,CAAC,iBAAiB;IAQzB;;;OAGG;IACI,kBAAkB,CAAC,KAAK,EAAE,eAAe,EAAE,eAAe,CAAC,KAAK,CAAC;IAKxE;;OAEG;IACI,gBAAgB,CAAC,OAAO,CAAC,EAAE,MAAM;IAQxC;;OAEG;IACI,SAAS,CAAC,MAAM,EAAE,IAAI;IAQ7B;;OAEG;IACI,KAAK,CAAC,KAAK,EAAE,0BAA0B;IAIvC,YAAY,CAAC,SAAS,EAAE,OAAO;IAItC;;OAEG;IACI,KAAK;IAIL,WAAW;IASlB;;;OAGG;IACI,OAAO
|
|
1
|
+
{"version":3,"file":"RuntimeMethodExecutionContext.d.ts","sourceRoot":"","sources":["../../../src/state/context/RuntimeMethodExecutionContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAE,8BAA8B,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AAClG,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAShE,qBAAa,oCAAqC,SAAQ,6BAA6B;IAE9E,gBAAgB,EAAE,eAAe,CAAC,GAAG,CAAC,EAAE,CAAM;IAE9C,MAAM,EAAE,IAAI,CAAc;IAE1B,aAAa,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,0BAA0B;IACzC,WAAW,EAAE,kBAAkB,CAAC;IAChC,YAAY,EAAE,YAAY,CAAC;CAC5B;AAED;;;;GAIG;AACH,qBACa,6BAA8B,SAAQ,8BAA8B;IACxE,OAAO,EAAE,MAAM,EAAE,CAAM;IAEvB,KAAK,EAAE,0BAA0B,GAAG,SAAS,CAAC;IAGrD,OAAO,CAAC,SAAS,CAAyC;IAE1C,MAAM,uCAA8C;IAEpE,OAAO,CAAC,WAAW,CAAkB;IAErC,OAAO,CAAC,iBAAiB;IAQzB;;;OAGG;IACI,kBAAkB,CAAC,KAAK,EAAE,eAAe,EAAE,eAAe,CAAC,KAAK,CAAC;IAKxE;;OAEG;IACI,gBAAgB,CAAC,OAAO,CAAC,EAAE,MAAM;IAQxC;;OAEG;IACI,SAAS,CAAC,MAAM,EAAE,IAAI;IAQ7B;;OAEG;IACI,KAAK,CAAC,KAAK,EAAE,0BAA0B;IAIvC,YAAY,CAAC,SAAS,EAAE,OAAO;IAItC;;OAEG;IACI,KAAK;IAIL,WAAW;IASlB;;;OAGG;IACI,OAAO;;;;;;CAQf"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MerkleTreeStore } from "./MerkleTreeStore";
|
|
2
2
|
export declare class InMemoryMerkleTreeStorage implements MerkleTreeStore {
|
|
3
3
|
protected readonly nodes: {
|
|
4
4
|
[key: number]: {
|
|
@@ -8,18 +8,4 @@ export declare class InMemoryMerkleTreeStorage implements MerkleTreeStore {
|
|
|
8
8
|
getNode(key: bigint, level: number): bigint | undefined;
|
|
9
9
|
setNode(key: bigint, level: number, value: bigint): void;
|
|
10
10
|
}
|
|
11
|
-
export declare class CachedMerkleTreeStore extends InMemoryMerkleTreeStorage {
|
|
12
|
-
private readonly parent;
|
|
13
|
-
private writeCache;
|
|
14
|
-
constructor(parent: AsyncMerkleTreeStore);
|
|
15
|
-
setNode(key: bigint, level: number, value: bigint): void;
|
|
16
|
-
getWrittenNodes(): {
|
|
17
|
-
[key: number]: {
|
|
18
|
-
[key: string]: bigint;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
resetWrittenNodes(): void;
|
|
22
|
-
preloadKey(index: bigint): Promise<void>;
|
|
23
|
-
mergeIntoParent(): Promise<void>;
|
|
24
|
-
}
|
|
25
11
|
//# sourceMappingURL=InMemoryMerkleTreeStorage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InMemoryMerkleTreeStorage.d.ts","sourceRoot":"","sources":["../../../src/utils/merkletree/InMemoryMerkleTreeStorage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"InMemoryMerkleTreeStorage.d.ts","sourceRoot":"","sources":["../../../src/utils/merkletree/InMemoryMerkleTreeStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,qBAAa,yBAA0B,YAAW,eAAe;IAC/D,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE;QACxB,CAAC,GAAG,EAAE,MAAM,GAAG;YACb,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;SACvB,CAAC;KACH,CAAM;IAEA,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAIvD,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;CAGhE"}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
|
-
import { log } from "@proto-kit/common";
|
|
3
|
-
import { RollupMerkleTree } from "./RollupMerkleTree.js";
|
|
4
1
|
export class InMemoryMerkleTreeStorage {
|
|
5
2
|
constructor() {
|
|
6
3
|
this.nodes = {};
|
|
@@ -13,65 +10,3 @@ export class InMemoryMerkleTreeStorage {
|
|
|
13
10
|
((_a = this.nodes)[level] ?? (_a[level] = {}))[key.toString()] = value;
|
|
14
11
|
}
|
|
15
12
|
}
|
|
16
|
-
export class CachedMerkleTreeStore extends InMemoryMerkleTreeStorage {
|
|
17
|
-
constructor(parent) {
|
|
18
|
-
super();
|
|
19
|
-
this.parent = parent;
|
|
20
|
-
this.writeCache = {};
|
|
21
|
-
}
|
|
22
|
-
setNode(key, level, value) {
|
|
23
|
-
var _a;
|
|
24
|
-
super.setNode(key, level, value);
|
|
25
|
-
((_a = this.writeCache)[level] ?? (_a[level] = {}))[key.toString()] = value;
|
|
26
|
-
}
|
|
27
|
-
getWrittenNodes() {
|
|
28
|
-
return this.writeCache;
|
|
29
|
-
}
|
|
30
|
-
resetWrittenNodes() {
|
|
31
|
-
this.writeCache = {};
|
|
32
|
-
}
|
|
33
|
-
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
34
|
-
async preloadKey(index) {
|
|
35
|
-
// Algo from RollupMerkleTree.getWitness()
|
|
36
|
-
const { leafCount, height } = RollupMerkleTree;
|
|
37
|
-
if (index >= leafCount) {
|
|
38
|
-
index %= leafCount;
|
|
39
|
-
}
|
|
40
|
-
// eslint-disable-next-line no-warning-comments,max-len
|
|
41
|
-
// TODO Not practical at the moment. Improve pattern when implementing DB storage
|
|
42
|
-
for (let level = 0; level < height; level++) {
|
|
43
|
-
const key = index;
|
|
44
|
-
const isLeft = index % 2n === 0n;
|
|
45
|
-
const siblingKey = isLeft ? index + 1n : index - 1n;
|
|
46
|
-
// eslint-disable-next-line no-await-in-loop
|
|
47
|
-
const value = await this.parent.getNode(key, level);
|
|
48
|
-
// eslint-disable-next-line no-await-in-loop
|
|
49
|
-
const sibling = await this.parent.getNode(siblingKey, level);
|
|
50
|
-
if (level === 0) {
|
|
51
|
-
log.debug(`Preloaded ${key} @ ${level} -> ${value ?? "-"}`);
|
|
52
|
-
}
|
|
53
|
-
if (value !== undefined) {
|
|
54
|
-
this.setNode(key, level, value);
|
|
55
|
-
}
|
|
56
|
-
if (sibling !== undefined) {
|
|
57
|
-
this.setNode(siblingKey, level, sibling);
|
|
58
|
-
}
|
|
59
|
-
index /= 2n;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
async mergeIntoParent() {
|
|
63
|
-
// In case no state got set we can skip this step
|
|
64
|
-
if (Object.keys(this.writeCache).length === 0) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
this.parent.openTransaction();
|
|
68
|
-
const { height } = RollupMerkleTree;
|
|
69
|
-
const nodes = this.getWrittenNodes();
|
|
70
|
-
const promises = Array.from({ length: height }).flatMap((ignored, level) => Object.entries(nodes[level]).map(async (entry) => {
|
|
71
|
-
await this.parent.setNode(BigInt(entry[0]), level, entry[1]);
|
|
72
|
-
}));
|
|
73
|
-
await Promise.all(promises);
|
|
74
|
-
this.parent.commit();
|
|
75
|
-
this.resetWrittenNodes();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export interface AsyncMerkleTreeStore {
|
|
2
2
|
openTransaction: () => void;
|
|
3
3
|
commit: () => void;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
setNodeAsync: (key: bigint, level: number, value: bigint) => Promise<void>;
|
|
5
|
+
getNodeAsync: (key: bigint, level: number) => Promise<bigint | undefined>;
|
|
6
6
|
}
|
|
7
7
|
export interface MerkleTreeStore {
|
|
8
8
|
setNode: (key: bigint, level: number, value: bigint) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MerkleTreeStore.d.ts","sourceRoot":"","sources":["../../../src/utils/merkletree/MerkleTreeStore.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,eAAe,EAAE,MAAM,IAAI,CAAC;IAE5B,MAAM,EAAE,MAAM,IAAI,CAAC;IAEnB,
|
|
1
|
+
{"version":3,"file":"MerkleTreeStore.d.ts","sourceRoot":"","sources":["../../../src/utils/merkletree/MerkleTreeStore.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,eAAe,EAAE,MAAM,IAAI,CAAC;IAE5B,MAAM,EAAE,MAAM,IAAI,CAAC;IAEnB,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE3E,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;CAC3E;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAE7D,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;CAC7D"}
|
|
@@ -54,6 +54,7 @@ declare class RollupMerkleWitness extends RollupMerkleWitness_base {
|
|
|
54
54
|
* @returns Index of the leaf.
|
|
55
55
|
*/
|
|
56
56
|
calculateIndex(): Field;
|
|
57
|
+
toShortenedEntries(): string[];
|
|
57
58
|
}
|
|
58
59
|
/**
|
|
59
60
|
* A [Merkle Tree](https://en.wikipedia.org/wiki/Merkle_tree) is a binary tree in
|
|
@@ -120,6 +121,7 @@ declare class RollupMerkleTree {
|
|
|
120
121
|
export declare namespace MerkleTreeUtils {
|
|
121
122
|
function normalizeKey(key: Field): Field;
|
|
122
123
|
function checkMembership(witness: RollupMerkleWitness, root: Field, key: Field, value: Field): Bool;
|
|
124
|
+
function checkMembershipGetRoots(witness: RollupMerkleWitness, root: Field, key: Field, value: Field): [Bool, Field, Field];
|
|
123
125
|
function computeRoot(witness: RollupMerkleWitness, value: Field): Field;
|
|
124
126
|
}
|
|
125
127
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RollupMerkleTree.d.ts","sourceRoot":"","sources":["../../../src/utils/merkletree/RollupMerkleTree.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,KAAK,EAA8B,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"RollupMerkleTree.d.ts","sourceRoot":"","sources":["../../../src/utils/merkletree/RollupMerkleTree.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,KAAK,EAA8B,MAAM,UAAU,CAAC;AAKnE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAIpD,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,CAAC;AAIjD,OAAO,EAAE,SAAS,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAErB;;;GAGG;AACH,cAAM,mBAAoB,SAAQ,wBAGhC;IACA,OAAc,MAAM,SAAO;IAEpB,MAAM,IAAI,MAAM;IAIvB;;;;OAIG;IACI,aAAa,CAAC,IAAI,EAAE,KAAK,GAAG,KAAK;IAaxC;;;OAGG;IACI,cAAc,IAAI,KAAK;IAkBvB,kBAAkB;CAO1B;AAED;;;;;;;;;;;;;GAaG;AACH,cAAM,gBAAgB;IACpB,OAAc,MAAM,SAAO;IAE3B,WAAkB,SAAS,IAAI,MAAM,CAEpC;IAED,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAW;IAElC,SAAgB,KAAK,EAAE,eAAe,CAAC;gBAEpB,KAAK,EAAE,eAAe;IAYzC;;;;;OAKG;IAEI,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK;IAInD;;;OAGG;IAEI,OAAO,IAAI,KAAK;IAMvB,OAAO,CAAC,OAAO;IAIf;;;OAGG;IAEH;;;;OAIG;IAEI,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK;IAgBzC;;;;;;OAMG;IACI,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,mBAAmB;IAqBrD;;;OAGG;IAEI,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE;IAM3B;;;OAGG;IACH,IAAW,SAAS,IAAI,MAAM,CAE7B;CACF;AAGD,yBAAiB,eAAe,CAAC;IAC/B,SAAgB,YAAY,CAAC,GAAG,EAAE,KAAK,GAAG,KAAK,CAS9C;IAED,SAAgB,eAAe,CAC7B,OAAO,EAAE,mBAAmB,EAC5B,IAAI,EAAE,KAAK,EACX,GAAG,EAAE,KAAK,EACV,KAAK,EAAE,KAAK,GACX,IAAI,CAKN;IAED,SAAgB,uBAAuB,CACrC,OAAO,EAAE,mBAAmB,EAC5B,IAAI,EAAE,KAAK,EACX,GAAG,EAAE,KAAK,EACV,KAAK,EAAE,KAAK,GACX,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAKtB;IAED,SAAgB,WAAW,CACzB,OAAO,EAAE,mBAAmB,EAC5B,KAAK,EAAE,KAAK,GACX,KAAK,CAEP;CACF;AAED;;;GAGG;AACH,iBAAS,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAK9D"}
|
|
@@ -12,6 +12,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
12
12
|
/* eslint-disable no-inline-comments */
|
|
13
13
|
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
14
14
|
import { Bool, Field, Poseidon, Provable, Struct } from "snarkyjs";
|
|
15
|
+
import { range } from "@proto-kit/common";
|
|
15
16
|
import { notInCircuit } from "../utils";
|
|
16
17
|
// external API
|
|
17
18
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
@@ -60,6 +61,11 @@ class RollupMerkleWitness extends Struct({
|
|
|
60
61
|
}
|
|
61
62
|
return index;
|
|
62
63
|
}
|
|
64
|
+
toShortenedEntries() {
|
|
65
|
+
return range(0, 5)
|
|
66
|
+
.concat(range(251, 255))
|
|
67
|
+
.map((index) => [this.path[index].toString(), this.isLeft[index].toString()].toString());
|
|
68
|
+
}
|
|
63
69
|
}
|
|
64
70
|
RollupMerkleWitness.height = 256;
|
|
65
71
|
/**
|
|
@@ -221,6 +227,13 @@ export var MerkleTreeUtils;
|
|
|
221
227
|
return root.equals(root2);
|
|
222
228
|
}
|
|
223
229
|
MerkleTreeUtils.checkMembership = checkMembership;
|
|
230
|
+
function checkMembershipGetRoots(witness, root, key, value) {
|
|
231
|
+
const root2 = witness.calculateRoot(value);
|
|
232
|
+
const key2 = witness.calculateIndex();
|
|
233
|
+
key.assertEquals(key2, "Keys of MerkleWitness does not match");
|
|
234
|
+
return [root.equals(root2), root, root2];
|
|
235
|
+
}
|
|
236
|
+
MerkleTreeUtils.checkMembershipGetRoots = checkMembershipGetRoots;
|
|
224
237
|
function computeRoot(witness, value) {
|
|
225
238
|
return witness.calculateRoot(value);
|
|
226
239
|
}
|
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.267+b252853",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc -p tsconfig.json",
|
|
9
9
|
"dev": "tsc -p tsconfig.json --watch",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"@jest/globals": "^29.5.0",
|
|
32
32
|
"@types/lodash": "^4.14.194"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "b2528538c73747d000cc3ea99ee26ee415d8248d"
|
|
35
35
|
}
|
|
@@ -203,6 +203,12 @@ export class StateTransitionProverProgrammable extends ZkProgrammable<
|
|
|
203
203
|
transition.from.value
|
|
204
204
|
);
|
|
205
205
|
|
|
206
|
+
// if (!membershipValid.toBoolean()) {
|
|
207
|
+
// console.log(
|
|
208
|
+
// `Merklewitness error ${root1.toString()} ${root2.toString()}`
|
|
209
|
+
// );
|
|
210
|
+
// }
|
|
211
|
+
|
|
206
212
|
membershipValid
|
|
207
213
|
.or(transition.from.isSome.not())
|
|
208
214
|
.assertTrue(
|
|
@@ -1,37 +1,46 @@
|
|
|
1
1
|
import { inject, injectable } from "tsyringe";
|
|
2
2
|
|
|
3
3
|
import { StateService } from "./StateService";
|
|
4
|
+
import { log } from "@proto-kit/common";
|
|
4
5
|
|
|
5
6
|
const errors = {
|
|
6
7
|
stateServiceNotSet: () =>
|
|
7
8
|
new Error(
|
|
8
|
-
|
|
9
|
-
protocol function by creating them with an AppChain or by setting the
|
|
10
|
-
stateService manually.`
|
|
9
|
+
"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."
|
|
11
10
|
),
|
|
12
11
|
};
|
|
13
12
|
|
|
14
13
|
@injectable()
|
|
15
14
|
export class StateServiceProvider {
|
|
16
|
-
private readonly
|
|
17
|
-
this.currentStateService;
|
|
15
|
+
private readonly stateServiceStack: StateService[] = [];
|
|
18
16
|
|
|
19
17
|
public constructor(
|
|
20
|
-
@inject("StateService") private
|
|
21
|
-
) {
|
|
18
|
+
@inject("StateService") private readonly baseStateService?: StateService
|
|
19
|
+
) {
|
|
20
|
+
if (baseStateService !== undefined) {
|
|
21
|
+
this.stateServiceStack.push(baseStateService);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
22
24
|
|
|
23
25
|
public get stateService(): StateService {
|
|
24
|
-
if (this.
|
|
26
|
+
if (this.stateServiceStack.length === 0) {
|
|
25
27
|
throw errors.stateServiceNotSet();
|
|
26
28
|
}
|
|
27
|
-
|
|
29
|
+
|
|
30
|
+
// Assertion here is ok, because we check that the array is not empty above
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
32
|
+
return this.stateServiceStack.at(-1)!;
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
public setCurrentStateService(service: StateService) {
|
|
31
|
-
this.
|
|
36
|
+
this.stateServiceStack.push(service);
|
|
32
37
|
}
|
|
33
38
|
|
|
34
|
-
public
|
|
35
|
-
this.
|
|
39
|
+
public popCurrentStateService() {
|
|
40
|
+
if (this.stateServiceStack.length === 1) {
|
|
41
|
+
log.trace("Trying to pop last available (root) stateservice");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
this.stateServiceStack.pop();
|
|
36
45
|
}
|
|
37
46
|
}
|
|
@@ -19,7 +19,9 @@ export function assert(condition: Bool, message?: string) {
|
|
|
19
19
|
const status = condition.and(previousStatus);
|
|
20
20
|
|
|
21
21
|
if (!condition.toBoolean()) {
|
|
22
|
-
|
|
22
|
+
if (!executionContext.current().isSimulated) {
|
|
23
|
+
log.debug("Assertion failed: ", message);
|
|
24
|
+
}
|
|
23
25
|
executionContext.setStatusMessage(message);
|
|
24
26
|
}
|
|
25
27
|
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { log } from "@proto-kit/common";
|
|
3
|
-
|
|
4
|
-
import { RollupMerkleTree } from "./RollupMerkleTree.js";
|
|
5
|
-
import { AsyncMerkleTreeStore, MerkleTreeStore } from "./MerkleTreeStore";
|
|
1
|
+
import { MerkleTreeStore } from "./MerkleTreeStore";
|
|
6
2
|
|
|
7
3
|
export class InMemoryMerkleTreeStorage implements MerkleTreeStore {
|
|
8
4
|
protected readonly nodes: {
|
|
@@ -19,88 +15,3 @@ export class InMemoryMerkleTreeStorage implements MerkleTreeStore {
|
|
|
19
15
|
(this.nodes[level] ??= {})[key.toString()] = value;
|
|
20
16
|
}
|
|
21
17
|
}
|
|
22
|
-
|
|
23
|
-
export class CachedMerkleTreeStore extends InMemoryMerkleTreeStorage {
|
|
24
|
-
private writeCache: {
|
|
25
|
-
[key: number]: {
|
|
26
|
-
[key: string]: bigint;
|
|
27
|
-
};
|
|
28
|
-
} = {};
|
|
29
|
-
|
|
30
|
-
public constructor(private readonly parent: AsyncMerkleTreeStore) {
|
|
31
|
-
super();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public setNode(key: bigint, level: number, value: bigint) {
|
|
35
|
-
super.setNode(key, level, value);
|
|
36
|
-
(this.writeCache[level] ??= {})[key.toString()] = value;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public getWrittenNodes(): {
|
|
40
|
-
[key: number]: {
|
|
41
|
-
[key: string]: bigint;
|
|
42
|
-
};
|
|
43
|
-
} {
|
|
44
|
-
return this.writeCache;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
public resetWrittenNodes() {
|
|
48
|
-
this.writeCache = {};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
52
|
-
public async preloadKey(index: bigint): Promise<void> {
|
|
53
|
-
// Algo from RollupMerkleTree.getWitness()
|
|
54
|
-
const { leafCount, height } = RollupMerkleTree;
|
|
55
|
-
|
|
56
|
-
if (index >= leafCount) {
|
|
57
|
-
index %= leafCount;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// eslint-disable-next-line no-warning-comments,max-len
|
|
61
|
-
// TODO Not practical at the moment. Improve pattern when implementing DB storage
|
|
62
|
-
for (let level = 0; level < height; level++) {
|
|
63
|
-
const key = index;
|
|
64
|
-
|
|
65
|
-
const isLeft = index % 2n === 0n;
|
|
66
|
-
const siblingKey = isLeft ? index + 1n : index - 1n;
|
|
67
|
-
|
|
68
|
-
// eslint-disable-next-line no-await-in-loop
|
|
69
|
-
const value = await this.parent.getNode(key, level);
|
|
70
|
-
// eslint-disable-next-line no-await-in-loop
|
|
71
|
-
const sibling = await this.parent.getNode(siblingKey, level);
|
|
72
|
-
if (level === 0) {
|
|
73
|
-
log.debug(`Preloaded ${key} @ ${level} -> ${value ?? "-"}`);
|
|
74
|
-
}
|
|
75
|
-
if (value !== undefined) {
|
|
76
|
-
this.setNode(key, level, value);
|
|
77
|
-
}
|
|
78
|
-
if (sibling !== undefined) {
|
|
79
|
-
this.setNode(siblingKey, level, sibling);
|
|
80
|
-
}
|
|
81
|
-
index /= 2n;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
public async mergeIntoParent(): Promise<void> {
|
|
86
|
-
// In case no state got set we can skip this step
|
|
87
|
-
if (Object.keys(this.writeCache).length === 0) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
this.parent.openTransaction();
|
|
92
|
-
const { height } = RollupMerkleTree;
|
|
93
|
-
const nodes = this.getWrittenNodes();
|
|
94
|
-
|
|
95
|
-
const promises = Array.from({ length: height }).flatMap((ignored, level) =>
|
|
96
|
-
Object.entries(nodes[level]).map(async (entry) => {
|
|
97
|
-
await this.parent.setNode(BigInt(entry[0]), level, entry[1]);
|
|
98
|
-
})
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
await Promise.all(promises);
|
|
102
|
-
|
|
103
|
-
this.parent.commit();
|
|
104
|
-
this.resetWrittenNodes();
|
|
105
|
-
}
|
|
106
|
-
}
|
|
@@ -3,9 +3,9 @@ export interface AsyncMerkleTreeStore {
|
|
|
3
3
|
|
|
4
4
|
commit: () => void;
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
setNodeAsync: (key: bigint, level: number, value: bigint) => Promise<void>;
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
getNodeAsync: (key: bigint, level: number) => Promise<bigint | undefined>;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export interface MerkleTreeStore {
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
/* eslint-disable no-inline-comments */
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
5
5
|
import { Bool, Field, Poseidon, Provable, Struct } from "snarkyjs";
|
|
6
|
+
import { range } from "@proto-kit/common";
|
|
6
7
|
|
|
7
8
|
import { notInCircuit } from "../utils";
|
|
8
9
|
|
|
@@ -69,6 +70,14 @@ class RollupMerkleWitness extends Struct({
|
|
|
69
70
|
|
|
70
71
|
return index;
|
|
71
72
|
}
|
|
73
|
+
|
|
74
|
+
public toShortenedEntries() {
|
|
75
|
+
return range(0, 5)
|
|
76
|
+
.concat(range(251, 255))
|
|
77
|
+
.map((index) =>
|
|
78
|
+
[this.path[index].toString(), this.isLeft[index].toString()].toString()
|
|
79
|
+
);
|
|
80
|
+
}
|
|
72
81
|
}
|
|
73
82
|
|
|
74
83
|
/**
|
|
@@ -234,6 +243,18 @@ export namespace MerkleTreeUtils {
|
|
|
234
243
|
return root.equals(root2);
|
|
235
244
|
}
|
|
236
245
|
|
|
246
|
+
export function checkMembershipGetRoots(
|
|
247
|
+
witness: RollupMerkleWitness,
|
|
248
|
+
root: Field,
|
|
249
|
+
key: Field,
|
|
250
|
+
value: Field
|
|
251
|
+
): [Bool, Field, Field] {
|
|
252
|
+
const root2 = witness.calculateRoot(value);
|
|
253
|
+
const key2 = witness.calculateIndex();
|
|
254
|
+
key.assertEquals(key2, "Keys of MerkleWitness does not match");
|
|
255
|
+
return [root.equals(root2), root, root2];
|
|
256
|
+
}
|
|
257
|
+
|
|
237
258
|
export function computeRoot(
|
|
238
259
|
witness: RollupMerkleWitness,
|
|
239
260
|
value: Field
|