@proto-kit/protocol 0.1.1-develop.160 → 0.1.1-develop.162
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/block/BlockProver.js +3 -3
- package/dist/utils/merkletree/InMemoryMerkleTreeStorage.d.ts.map +1 -1
- package/dist/utils/merkletree/InMemoryMerkleTreeStorage.js +8 -3
- package/package.json +3 -3
- package/src/prover/block/BlockProver.ts +3 -3
- package/src/utils/merkletree/InMemoryMerkleTreeStorage.ts +9 -2
- package/test/StateTransition.test.ts +3 -3
|
@@ -82,10 +82,10 @@ let BlockProver = class BlockProver extends ProtocolModule {
|
|
|
82
82
|
stateRoot: publicInput.stateRoot,
|
|
83
83
|
networkStateHash: publicInput.networkStateHash,
|
|
84
84
|
};
|
|
85
|
-
this.applyTransaction(state, stateProof, appProof, executionData);
|
|
85
|
+
const stateTo = this.applyTransaction(state, stateProof, appProof, executionData);
|
|
86
86
|
return new BlockProverPublicOutput({
|
|
87
|
-
stateRoot:
|
|
88
|
-
transactionsHash:
|
|
87
|
+
stateRoot: stateTo.stateRoot,
|
|
88
|
+
transactionsHash: stateTo.transactionsHash,
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
91
|
merge(publicInput, proof1, proof2) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InMemoryMerkleTreeStorage.d.ts","sourceRoot":"","sources":["../../../src/utils/merkletree/InMemoryMerkleTreeStorage.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAE1E,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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B,MAAM,EAAE,oBAAoB;IAIzD,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAKjD,eAAe,IAAI;QACxB,CAAC,GAAG,EAAE,MAAM,GAAG;YACb,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;SACvB,CAAC;KACH;IAIM,iBAAiB;IAIX,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiCxC,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;CAqB9C"}
|
|
@@ -32,7 +32,6 @@ export class CachedMerkleTreeStore extends InMemoryMerkleTreeStorage {
|
|
|
32
32
|
this.writeCache = {};
|
|
33
33
|
}
|
|
34
34
|
async preloadKey(index) {
|
|
35
|
-
var _a;
|
|
36
35
|
log.debug(`Preloading MT ${index}`);
|
|
37
36
|
// Algo from RollupMerkleTree.getWitness()
|
|
38
37
|
const { leafCount, height } = RollupMerkleTree;
|
|
@@ -43,13 +42,19 @@ export class CachedMerkleTreeStore extends InMemoryMerkleTreeStorage {
|
|
|
43
42
|
// TODO Not practical at the moment. Improve pattern when implementing DB storage
|
|
44
43
|
for (let level = 0; level < height; level++) {
|
|
45
44
|
const key = index;
|
|
45
|
+
const isLeft = index % 2n === 0n;
|
|
46
|
+
const siblingKey = isLeft ? index + 1n : index - 1n;
|
|
46
47
|
// eslint-disable-next-line no-await-in-loop
|
|
47
48
|
const value = await this.parent.getNode(key, level);
|
|
49
|
+
const sibling = await this.parent.getNode(siblingKey, level);
|
|
48
50
|
if (level === 0) {
|
|
49
|
-
log.debug(`Preloaded ${key} -> ${value ?? "-"}`);
|
|
51
|
+
log.debug(`Preloaded ${key} @ ${level} -> ${value ?? "-"}`);
|
|
50
52
|
}
|
|
51
53
|
if (value !== undefined) {
|
|
52
|
-
|
|
54
|
+
this.setNode(key, level, value);
|
|
55
|
+
}
|
|
56
|
+
if (sibling !== undefined) {
|
|
57
|
+
this.setNode(siblingKey, level, sibling);
|
|
53
58
|
}
|
|
54
59
|
index /= 2n;
|
|
55
60
|
}
|
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.162+1fd6645",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc -p tsconfig.json",
|
|
9
9
|
"dev": "tsc -p tsconfig.json --watch",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@proto-kit/common": "0.1.1-develop.
|
|
20
|
+
"@proto-kit/common": "0.1.1-develop.162+1fd6645",
|
|
21
21
|
"lodash": "^4.17.21",
|
|
22
22
|
"loglevel": "^1.8.1",
|
|
23
23
|
"reflect-metadata": "^0.1.13",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"@jest/globals": "^29.5.0",
|
|
32
32
|
"@types/lodash": "^4.14.194"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "1fd6645b60e2b4c2db2ac35b53c1c5d0b66c5b91"
|
|
35
35
|
}
|
|
@@ -182,11 +182,11 @@ export class BlockProver
|
|
|
182
182
|
networkStateHash: publicInput.networkStateHash,
|
|
183
183
|
};
|
|
184
184
|
|
|
185
|
-
this.applyTransaction(state, stateProof, appProof, executionData);
|
|
185
|
+
const stateTo = this.applyTransaction(state, stateProof, appProof, executionData);
|
|
186
186
|
|
|
187
187
|
return new BlockProverPublicOutput({
|
|
188
|
-
stateRoot:
|
|
189
|
-
transactionsHash:
|
|
188
|
+
stateRoot: stateTo.stateRoot,
|
|
189
|
+
transactionsHash: stateTo.transactionsHash,
|
|
190
190
|
});
|
|
191
191
|
}
|
|
192
192
|
|
|
@@ -63,13 +63,20 @@ export class CachedMerkleTreeStore extends InMemoryMerkleTreeStorage {
|
|
|
63
63
|
for (let level = 0; level < height; level++) {
|
|
64
64
|
const key = index;
|
|
65
65
|
|
|
66
|
+
const isLeft = index % 2n === 0n;
|
|
67
|
+
const siblingKey = isLeft ? index + 1n : index - 1n;
|
|
68
|
+
|
|
66
69
|
// eslint-disable-next-line no-await-in-loop
|
|
67
70
|
const value = await this.parent.getNode(key, level);
|
|
71
|
+
const sibling = await this.parent.getNode(siblingKey, level);
|
|
68
72
|
if (level === 0) {
|
|
69
|
-
log.debug(`Preloaded ${key} -> ${value ?? "-"}`);
|
|
73
|
+
log.debug(`Preloaded ${key} @ ${level} -> ${value ?? "-"}`);
|
|
70
74
|
}
|
|
71
75
|
if (value !== undefined) {
|
|
72
|
-
|
|
76
|
+
this.setNode(key, level, value);
|
|
77
|
+
}
|
|
78
|
+
if(sibling !== undefined) {
|
|
79
|
+
this.setNode(siblingKey, level, sibling);
|
|
73
80
|
}
|
|
74
81
|
index /= 2n;
|
|
75
82
|
}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
Option,
|
|
7
7
|
ProvableStateTransition,
|
|
8
8
|
DefaultProvableHashList,
|
|
9
|
-
StateTransitionProvableBatch, CachedMerkleTreeStore
|
|
9
|
+
StateTransitionProvableBatch, CachedMerkleTreeStore, InMemoryMerkleTreeStorage
|
|
10
10
|
} from "../src/index";
|
|
11
11
|
import {
|
|
12
12
|
RollupMerkleTree,
|
|
@@ -108,7 +108,7 @@ describe("stateTransition", () => {
|
|
|
108
108
|
])("should pass without throwing", async (transitions) => {
|
|
109
109
|
expect.assertions(2);
|
|
110
110
|
|
|
111
|
-
const tree = new RollupMerkleTree(new
|
|
111
|
+
const tree = new RollupMerkleTree(new InMemoryMerkleTreeStorage());
|
|
112
112
|
|
|
113
113
|
// Is ignored because overwritten by first transition
|
|
114
114
|
tree.setLeaf(1n, Option.fromValue(Field(1), Field).treeValue);
|
|
@@ -168,7 +168,7 @@ describe("stateTransition", () => {
|
|
|
168
168
|
async (transitions, index) => {
|
|
169
169
|
expect.assertions(1);
|
|
170
170
|
|
|
171
|
-
const tree = new RollupMerkleTree(new
|
|
171
|
+
const tree = new RollupMerkleTree(new InMemoryMerkleTreeStorage());
|
|
172
172
|
|
|
173
173
|
// Is ignored because overwritten by first transition
|
|
174
174
|
tree.setLeaf(1n, Option.fromValue(Field(1), Field).treeValue);
|