@proto-kit/protocol 0.1.1-develop.261 → 0.1.1-develop.263

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.
@@ -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;IAqDX;;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"}
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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AAiC;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 +1 @@
1
- {"version":3,"file":"InMemoryMerkleTreeStorage.d.ts","sourceRoot":"","sources":["../../../src/utils/merkletree/InMemoryMerkleTreeStorage.ts"],"names":[],"mappings":"AAIA,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,C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I;CAGhE;AAED,qBAAa,qBAAsB,SAAQ,yBAAyB;IAO/C,OAAO,CAAC,QAAQ,CAAC,MAAM;IAN1C,OAAO,CAAC,UAAU,CAIX;gBAE6B,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;IAKX,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAwCxC,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;CAqB9C"}
@@ -43,18 +43,24 @@ export class CachedMerkleTreeStore extends InMemoryMerkleTreeStorage {
43
43
  const key = index;
44
44
  const isLeft = index % 2n === 0n;
45
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 ?? "-"}`);
46
+ // Only preload node if it is not already preloaded.
47
+ // We also don't want to overwrite because changes will get lost (tracing)
48
+ if (this.getNode(key, level) === undefined) {
49
+ // eslint-disable-next-line no-await-in-loop
50
+ const value = await this.parent.getNode(key, level);
51
+ if (level === 0) {
52
+ log.debug(`Preloaded ${key} @ ${level} -> ${value ?? "-"}`);
53
+ }
54
+ if (value !== undefined) {
55
+ this.setNode(key, level, value);
56
+ }
52
57
  }
53
- if (value !== undefined) {
54
- this.setNode(key, level, value);
55
- }
56
- if (sibling !== undefined) {
57
- this.setNode(siblingKey, level, sibling);
58
+ if (this.getNode(siblingKey, level) === undefined) {
59
+ // eslint-disable-next-line no-await-in-loop
60
+ const sibling = await this.parent.getNode(siblingKey, level);
61
+ if (sibling !== undefined) {
62
+ this.setNode(siblingKey, level, sibling);
63
+ }
58
64
  }
59
65
  index /= 2n;
60
66
  }
@@ -120,6 +120,7 @@ declare class RollupMerkleTree {
120
120
  export declare namespace MerkleTreeUtils {
121
121
  function normalizeKey(key: Field): Field;
122
122
  function checkMembership(witness: RollupMerkleWitness, root: Field, key: Field, value: Field): Bool;
123
+ function checkMembershipGetRoots(witness: RollupMerkleWitness, root: Field, key: Field, value: Field): [Bool, Field, Field];
123
124
  function computeRoot(witness: RollupMerkleWitness, value: Field): Field;
124
125
  }
125
126
  /**
@@ -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;AAInE,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;CAiB/B;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,G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E,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"}
@@ -221,6 +221,13 @@ export var MerkleTreeUtils;
221
221
  return root.equals(root2);
222
222
  }
223
223
  MerkleTreeUtils.checkMembership = checkMembership;
224
+ function checkMembershipGetRoots(witness, root, key, value) {
225
+ const root2 = witness.calculateRoot(value);
226
+ const key2 = witness.calculateIndex();
227
+ key.assertEquals(key2, "Keys of MerkleWitness does not match");
228
+ return [root.equals(root2), root, root2];
229
+ }
230
+ MerkleTreeUtils.checkMembershipGetRoots = checkMembershipGetRoots;
224
231
  function computeRoot(witness, value) {
225
232
  return witness.calculateRoot(value);
226
233
  }
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.261+8731dfa",
6
+ "version": "0.1.1-develop.263+f167699",
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": "8731dfa8f5df502eadf6266a7216617737985146"
34
+ "gitHead": "f167699bddb5831155c4aa9587b4da032c30db0d"
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(
@@ -65,18 +65,25 @@ export class CachedMerkleTreeStore extends InMemoryMerkleTreeStorage {
65
65
  const isLeft = index % 2n === 0n;
66
66
  const siblingKey = isLeft ? index + 1n : index - 1n;
67
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 ?? "-"}`);
68
+ // Only preload node if it is not already preloaded.
69
+ // We also don't want to overwrite because changes will get lost (tracing)
70
+ if (this.getNode(key, level) === undefined) {
71
+ // eslint-disable-next-line no-await-in-loop
72
+ const value = await this.parent.getNode(key, level);
73
+ if (level === 0) {
74
+ log.debug(`Preloaded ${key} @ ${level} -> ${value ?? "-"}`);
75
+ }
76
+ if (value !== undefined) {
77
+ this.setNode(key, level, value);
78
+ }
74
79
  }
75
- if (value !== undefined) {
76
- this.setNode(key, level, value);
77
- }
78
- if (sibling !== undefined) {
79
- this.setNode(siblingKey, level, sibling);
80
+
81
+ if (this.getNode(siblingKey, level) === undefined) {
82
+ // eslint-disable-next-line no-await-in-loop
83
+ const sibling = await this.parent.getNode(siblingKey, level);
84
+ if (sibling !== undefined) {
85
+ this.setNode(siblingKey, level, sibling);
86
+ }
80
87
  }
81
88
  index /= 2n;
82
89
  }
@@ -234,6 +234,18 @@ export namespace MerkleTreeUtils {
234
234
  return root.equals(root2);
235
235
  }
236
236
 
237
+ export function checkMembershipGetRoots(
238
+ witness: RollupMerkleWitness,
239
+ root: Field,
240
+ key: Field,
241
+ value: Field
242
+ ): [Bool, Field, Field] {
243
+ const root2 = witness.calculateRoot(value);
244
+ const key2 = witness.calculateIndex();
245
+ key.assertEquals(key2, "Keys of MerkleWitness does not match");
246
+ return [root.equals(root2), root, root2];
247
+ }
248
+
237
249
  export function computeRoot(
238
250
  witness: RollupMerkleWitness,
239
251
  value: Field