@proto-kit/common 0.1.1-develop.211 → 0.1.1-develop.2137

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 (258) hide show
  1. package/dist/cache/CacheManifest.d.ts +11 -0
  2. package/dist/cache/CacheManifest.d.ts.map +1 -0
  3. package/dist/cache/CacheManifest.js +56 -0
  4. package/dist/cache/CacheManifest.js.map +1 -0
  5. package/dist/cache/ProxyCache.d.ts +13 -0
  6. package/dist/cache/ProxyCache.d.ts.map +1 -0
  7. package/dist/cache/ProxyCache.js +24 -0
  8. package/dist/cache/ProxyCache.js.map +1 -0
  9. package/dist/cache/RemoteCache.d.ts +8 -0
  10. package/dist/cache/RemoteCache.d.ts.map +1 -0
  11. package/dist/cache/RemoteCache.js +2 -0
  12. package/dist/cache/RemoteCache.js.map +1 -0
  13. package/dist/cache/RemoteCacheCompiler.d.ts +16 -0
  14. package/dist/cache/RemoteCacheCompiler.d.ts.map +1 -0
  15. package/dist/cache/RemoteCacheCompiler.js +104 -0
  16. package/dist/cache/RemoteCacheCompiler.js.map +1 -0
  17. package/dist/compiling/AtomicCompileHelper.d.ts +15 -0
  18. package/dist/compiling/AtomicCompileHelper.d.ts.map +1 -0
  19. package/dist/compiling/AtomicCompileHelper.js +61 -0
  20. package/dist/compiling/AtomicCompileHelper.js.map +1 -0
  21. package/dist/compiling/CompilableModule.d.ts +6 -0
  22. package/dist/compiling/CompilableModule.d.ts.map +1 -0
  23. package/dist/compiling/CompilableModule.js +2 -0
  24. package/dist/compiling/CompilableModule.js.map +1 -0
  25. package/dist/compiling/CompileRegistry.d.ts +25 -0
  26. package/dist/compiling/CompileRegistry.d.ts.map +1 -0
  27. package/dist/compiling/CompileRegistry.js +62 -0
  28. package/dist/compiling/CompileRegistry.js.map +1 -0
  29. package/dist/compiling/services/ChildVerificationKeyService.d.ts +10 -0
  30. package/dist/compiling/services/ChildVerificationKeyService.d.ts.map +1 -0
  31. package/dist/compiling/services/ChildVerificationKeyService.js +27 -0
  32. package/dist/compiling/services/ChildVerificationKeyService.js.map +1 -0
  33. package/dist/config/ChildContainerCreatable.d.ts +5 -0
  34. package/dist/config/ChildContainerCreatable.d.ts.map +1 -0
  35. package/dist/config/ChildContainerCreatable.js +2 -0
  36. package/dist/config/ChildContainerCreatable.js.map +1 -0
  37. package/dist/config/ChildContainerProvider.d.ts +5 -0
  38. package/dist/config/ChildContainerProvider.d.ts.map +1 -0
  39. package/dist/config/ChildContainerProvider.js +2 -0
  40. package/dist/config/ChildContainerProvider.js.map +1 -0
  41. package/dist/config/ConfigurableModule.d.ts +6 -2
  42. package/dist/config/ConfigurableModule.d.ts.map +1 -1
  43. package/dist/config/ConfigurableModule.js +5 -0
  44. package/dist/config/ConfigurableModule.js.map +1 -0
  45. package/dist/config/ModuleContainer.d.ts +70 -23
  46. package/dist/config/ModuleContainer.d.ts.map +1 -1
  47. package/dist/config/ModuleContainer.js +164 -31
  48. package/dist/config/ModuleContainer.js.map +1 -0
  49. package/dist/config/Startable.d.ts +4 -0
  50. package/dist/config/Startable.d.ts.map +1 -0
  51. package/dist/config/Startable.js +2 -0
  52. package/dist/config/Startable.js.map +1 -0
  53. package/dist/config/injectAlias.d.ts +18 -0
  54. package/dist/config/injectAlias.d.ts.map +1 -0
  55. package/dist/config/injectAlias.js +47 -0
  56. package/dist/config/injectAlias.js.map +1 -0
  57. package/dist/dependencyFactory/DependencyFactory.d.ts +14 -9
  58. package/dist/dependencyFactory/DependencyFactory.d.ts.map +1 -1
  59. package/dist/dependencyFactory/DependencyFactory.js +2 -96
  60. package/dist/dependencyFactory/DependencyFactory.js.map +1 -0
  61. package/dist/dependencyFactory/injectOptional.d.ts +16 -0
  62. package/dist/dependencyFactory/injectOptional.d.ts.map +1 -0
  63. package/dist/dependencyFactory/injectOptional.js +40 -0
  64. package/dist/dependencyFactory/injectOptional.js.map +1 -0
  65. package/dist/dummyVerificationKey.d.ts +3 -0
  66. package/dist/dummyVerificationKey.d.ts.map +1 -0
  67. package/dist/dummyVerificationKey.js +8 -0
  68. package/dist/dummyVerificationKey.js.map +1 -0
  69. package/dist/events/EventEmitter.d.ts +19 -0
  70. package/dist/events/EventEmitter.d.ts.map +1 -0
  71. package/dist/events/EventEmitter.js +35 -0
  72. package/dist/events/EventEmitter.js.map +1 -0
  73. package/dist/events/EventEmitterProxy.d.ts +18 -0
  74. package/dist/events/EventEmitterProxy.d.ts.map +1 -0
  75. package/dist/events/EventEmitterProxy.js +35 -0
  76. package/dist/events/EventEmitterProxy.js.map +1 -0
  77. package/dist/events/EventEmittingComponent.d.ts +9 -0
  78. package/dist/events/EventEmittingComponent.d.ts.map +1 -0
  79. package/dist/events/EventEmittingComponent.js +2 -0
  80. package/dist/events/EventEmittingComponent.js.map +1 -0
  81. package/dist/events/ReplayingSingleUseEventEmitter.d.ts +17 -0
  82. package/dist/events/ReplayingSingleUseEventEmitter.d.ts.map +1 -0
  83. package/dist/events/ReplayingSingleUseEventEmitter.js +34 -0
  84. package/dist/events/ReplayingSingleUseEventEmitter.js.map +1 -0
  85. package/dist/index.d.ts +27 -1
  86. package/dist/index.d.ts.map +1 -1
  87. package/dist/index.js +28 -2
  88. package/dist/index.js.map +1 -0
  89. package/dist/log.d.ts +37 -0
  90. package/dist/log.d.ts.map +1 -0
  91. package/dist/log.js +117 -0
  92. package/dist/log.js.map +1 -0
  93. package/dist/trees/InMemoryLinkedLeafStore.d.ts +21 -0
  94. package/dist/trees/InMemoryLinkedLeafStore.d.ts.map +1 -0
  95. package/dist/trees/InMemoryLinkedLeafStore.js +26 -0
  96. package/dist/trees/InMemoryLinkedLeafStore.js.map +1 -0
  97. package/dist/trees/InMemoryLinkedMerkleLeafStore.d.ts +7 -0
  98. package/dist/trees/InMemoryLinkedMerkleLeafStore.d.ts.map +1 -0
  99. package/dist/trees/InMemoryLinkedMerkleLeafStore.js +6 -0
  100. package/dist/trees/InMemoryLinkedMerkleLeafStore.js.map +1 -0
  101. package/dist/trees/InMemoryMerkleTreeStorage.d.ts +11 -0
  102. package/dist/trees/InMemoryMerkleTreeStorage.d.ts.map +1 -0
  103. package/dist/trees/InMemoryMerkleTreeStorage.js +13 -0
  104. package/dist/trees/InMemoryMerkleTreeStorage.js.map +1 -0
  105. package/dist/trees/LinkedMerkleTree.d.ts +345 -0
  106. package/dist/trees/LinkedMerkleTree.d.ts.map +1 -0
  107. package/dist/trees/LinkedMerkleTree.js +337 -0
  108. package/dist/trees/LinkedMerkleTree.js.map +1 -0
  109. package/dist/trees/LinkedMerkleTreeStore.d.ts +24 -0
  110. package/dist/trees/LinkedMerkleTreeStore.d.ts.map +1 -0
  111. package/dist/trees/LinkedMerkleTreeStore.js +2 -0
  112. package/dist/trees/LinkedMerkleTreeStore.js.map +1 -0
  113. package/dist/trees/MerkleTreeStore.d.ts +5 -0
  114. package/dist/trees/MerkleTreeStore.d.ts.map +1 -0
  115. package/dist/trees/MerkleTreeStore.js +2 -0
  116. package/dist/trees/MerkleTreeStore.js.map +1 -0
  117. package/dist/trees/MockAsyncMerkleStore.d.ts +9 -0
  118. package/dist/trees/MockAsyncMerkleStore.d.ts.map +1 -0
  119. package/dist/trees/MockAsyncMerkleStore.js +20 -0
  120. package/dist/trees/MockAsyncMerkleStore.js.map +1 -0
  121. package/dist/trees/RollupMerkleTree.d.ts +147 -0
  122. package/dist/trees/RollupMerkleTree.d.ts.map +1 -0
  123. package/dist/trees/RollupMerkleTree.js +218 -0
  124. package/dist/trees/RollupMerkleTree.js.map +1 -0
  125. package/dist/trees/VirtualMerkleTreeStore.d.ts +13 -0
  126. package/dist/trees/VirtualMerkleTreeStore.d.ts.map +1 -0
  127. package/dist/trees/VirtualMerkleTreeStore.js +18 -0
  128. package/dist/trees/VirtualMerkleTreeStore.js.map +1 -0
  129. package/dist/trees/lmt/AbstractLinkedMerkleTree.d.ts +288 -0
  130. package/dist/trees/lmt/AbstractLinkedMerkleTree.d.ts.map +1 -0
  131. package/dist/trees/lmt/AbstractLinkedMerkleTree.js +22 -0
  132. package/dist/trees/lmt/AbstractLinkedMerkleTree.js.map +1 -0
  133. package/dist/trees/lmt/InMemoryLinkedLeafStore.d.ts +21 -0
  134. package/dist/trees/lmt/InMemoryLinkedLeafStore.d.ts.map +1 -0
  135. package/dist/trees/lmt/InMemoryLinkedLeafStore.js +26 -0
  136. package/dist/trees/lmt/InMemoryLinkedLeafStore.js.map +1 -0
  137. package/dist/trees/lmt/InMemoryLinkedMerkleLeafStore.d.ts +7 -0
  138. package/dist/trees/lmt/InMemoryLinkedMerkleLeafStore.d.ts.map +1 -0
  139. package/dist/trees/lmt/InMemoryLinkedMerkleLeafStore.js +6 -0
  140. package/dist/trees/lmt/InMemoryLinkedMerkleLeafStore.js.map +1 -0
  141. package/dist/trees/lmt/LinkedLeafStore.d.ts +16 -0
  142. package/dist/trees/lmt/LinkedLeafStore.d.ts.map +1 -0
  143. package/dist/trees/lmt/LinkedLeafStore.js +2 -0
  144. package/dist/trees/lmt/LinkedLeafStore.js.map +1 -0
  145. package/dist/trees/lmt/LinkedLinkedStore.d.ts +16 -0
  146. package/dist/trees/lmt/LinkedLinkedStore.d.ts.map +1 -0
  147. package/dist/trees/lmt/LinkedLinkedStore.js +2 -0
  148. package/dist/trees/lmt/LinkedLinkedStore.js.map +1 -0
  149. package/dist/trees/lmt/LinkedMerkleTree.d.ts +11 -0
  150. package/dist/trees/lmt/LinkedMerkleTree.d.ts.map +1 -0
  151. package/dist/trees/lmt/LinkedMerkleTree.js +241 -0
  152. package/dist/trees/lmt/LinkedMerkleTree.js.map +1 -0
  153. package/dist/trees/lmt/LinkedMerkleTreeCircuitOps.d.ts +113 -0
  154. package/dist/trees/lmt/LinkedMerkleTreeCircuitOps.d.ts.map +1 -0
  155. package/dist/trees/lmt/LinkedMerkleTreeCircuitOps.js +113 -0
  156. package/dist/trees/lmt/LinkedMerkleTreeCircuitOps.js.map +1 -0
  157. package/dist/trees/lmt/LinkedMerkleTreeDatabase.d.ts +7 -0
  158. package/dist/trees/lmt/LinkedMerkleTreeDatabase.d.ts.map +1 -0
  159. package/dist/trees/lmt/LinkedMerkleTreeDatabase.js +2 -0
  160. package/dist/trees/lmt/LinkedMerkleTreeDatabase.js.map +1 -0
  161. package/dist/trees/lmt/LinkedMerkleTreeStore.d.ts +16 -0
  162. package/dist/trees/lmt/LinkedMerkleTreeStore.d.ts.map +1 -0
  163. package/dist/trees/lmt/LinkedMerkleTreeStore.js +2 -0
  164. package/dist/trees/lmt/LinkedMerkleTreeStore.js.map +1 -0
  165. package/dist/trees/lmt/LinkedMerkleTreeTypes.d.ts +74 -0
  166. package/dist/trees/lmt/LinkedMerkleTreeTypes.d.ts.map +1 -0
  167. package/dist/trees/lmt/LinkedMerkleTreeTypes.js +50 -0
  168. package/dist/trees/lmt/LinkedMerkleTreeTypes.js.map +1 -0
  169. package/dist/trees/sparse/InMemoryMerkleTreeStorage.d.ts +11 -0
  170. package/dist/trees/sparse/InMemoryMerkleTreeStorage.d.ts.map +1 -0
  171. package/dist/trees/sparse/InMemoryMerkleTreeStorage.js +13 -0
  172. package/dist/trees/sparse/InMemoryMerkleTreeStorage.js.map +1 -0
  173. package/dist/trees/sparse/MerkleTreeStore.d.ts +5 -0
  174. package/dist/trees/sparse/MerkleTreeStore.d.ts.map +1 -0
  175. package/dist/trees/sparse/MerkleTreeStore.js +2 -0
  176. package/dist/trees/sparse/MerkleTreeStore.js.map +1 -0
  177. package/dist/trees/sparse/MockAsyncMerkleStore.d.ts +9 -0
  178. package/dist/trees/sparse/MockAsyncMerkleStore.d.ts.map +1 -0
  179. package/dist/trees/sparse/MockAsyncMerkleStore.js +20 -0
  180. package/dist/trees/sparse/MockAsyncMerkleStore.js.map +1 -0
  181. package/dist/trees/sparse/RollupMerkleTree.d.ts +158 -0
  182. package/dist/trees/sparse/RollupMerkleTree.d.ts.map +1 -0
  183. package/dist/trees/sparse/RollupMerkleTree.js +330 -0
  184. package/dist/trees/sparse/RollupMerkleTree.js.map +1 -0
  185. package/dist/types.d.ts +62 -0
  186. package/dist/types.d.ts.map +1 -1
  187. package/dist/types.js +14 -1
  188. package/dist/types.js.map +1 -0
  189. package/dist/union/union.d.ts +177 -0
  190. package/dist/union/union.d.ts.map +1 -0
  191. package/dist/union/union.js +35 -0
  192. package/dist/union/union.js.map +1 -0
  193. package/dist/utils.d.ts +57 -2
  194. package/dist/utils.d.ts.map +1 -1
  195. package/dist/utils.js +153 -4
  196. package/dist/utils.js.map +1 -0
  197. package/dist/zkProgrammable/ProvableMethodExecutionContext.d.ts +4 -3
  198. package/dist/zkProgrammable/ProvableMethodExecutionContext.d.ts.map +1 -1
  199. package/dist/zkProgrammable/ProvableMethodExecutionContext.js +2 -3
  200. package/dist/zkProgrammable/ProvableMethodExecutionContext.js.map +1 -0
  201. package/dist/zkProgrammable/ZkProgrammable.d.ts +32 -11
  202. package/dist/zkProgrammable/ZkProgrammable.d.ts.map +1 -1
  203. package/dist/zkProgrammable/ZkProgrammable.js +36 -17
  204. package/dist/zkProgrammable/ZkProgrammable.js.map +1 -0
  205. package/dist/zkProgrammable/provableMethod.d.ts +7 -4
  206. package/dist/zkProgrammable/provableMethod.d.ts.map +1 -1
  207. package/dist/zkProgrammable/provableMethod.js +30 -14
  208. package/dist/zkProgrammable/provableMethod.js.map +1 -0
  209. package/jest.config.cjs +12 -1
  210. package/package.json +9 -7
  211. package/src/cache/CacheManifest.ts +57 -0
  212. package/src/cache/ProxyCache.ts +30 -0
  213. package/src/cache/RemoteCache.ts +9 -0
  214. package/src/cache/RemoteCacheCompiler.ts +131 -0
  215. package/src/compiling/AtomicCompileHelper.ts +71 -0
  216. package/src/compiling/CompilableModule.ts +6 -0
  217. package/src/compiling/CompileRegistry.ts +64 -0
  218. package/src/compiling/services/ChildVerificationKeyService.ts +26 -0
  219. package/src/config/ChildContainerCreatable.ts +5 -0
  220. package/src/config/ChildContainerProvider.ts +5 -0
  221. package/src/config/ConfigurableModule.ts +15 -2
  222. package/src/config/ModuleContainer.ts +286 -58
  223. package/src/config/Startable.ts +3 -0
  224. package/src/config/injectAlias.ts +70 -0
  225. package/src/dependencyFactory/DependencyFactory.ts +34 -109
  226. package/src/dummyVerificationKey.ts +10 -0
  227. package/src/events/EventEmitter.ts +61 -0
  228. package/src/events/EventEmitterProxy.ts +81 -0
  229. package/src/events/EventEmittingComponent.ts +11 -0
  230. package/src/events/ReplayingSingleUseEventEmitter.ts +42 -0
  231. package/src/index.ts +27 -2
  232. package/src/log.ts +145 -0
  233. package/src/trees/lmt/AbstractLinkedMerkleTree.ts +102 -0
  234. package/src/trees/lmt/InMemoryLinkedLeafStore.ts +42 -0
  235. package/src/trees/lmt/LinkedLeafStore.ts +13 -0
  236. package/src/trees/lmt/LinkedMerkleTree.ts +335 -0
  237. package/src/trees/lmt/LinkedMerkleTreeCircuitOps.ts +188 -0
  238. package/src/trees/lmt/LinkedMerkleTreeTypes.ts +53 -0
  239. package/src/trees/sparse/InMemoryMerkleTreeStorage.ts +17 -0
  240. package/src/trees/sparse/MerkleTreeStore.ts +5 -0
  241. package/src/trees/sparse/MockAsyncMerkleStore.ts +30 -0
  242. package/src/trees/sparse/RollupMerkleTree.ts +512 -0
  243. package/src/types.ts +53 -2
  244. package/src/utils.ts +281 -5
  245. package/src/zkProgrammable/ProvableMethodExecutionContext.ts +6 -6
  246. package/src/zkProgrammable/ZkProgrammable.ts +90 -35
  247. package/src/zkProgrammable/provableMethod.ts +50 -23
  248. package/test/config/ContainerEvents.test.ts +65 -0
  249. package/test/config/ModuleContainer.test.ts +146 -15
  250. package/test/config/injectAlias.test.ts +28 -0
  251. package/test/trees/LinkedMerkleTree.test.ts +124 -0
  252. package/test/trees/LinkedMerkleTreeCircuitOps.test.ts +147 -0
  253. package/test/trees/MerkleTree.test.ts +251 -0
  254. package/test/tsconfig.json +5 -2
  255. package/test/zkProgrammable/ZkProgrammable.test.ts +145 -119
  256. package/tsconfig.json +1 -1
  257. package/LICENSE.md +0 -201
  258. package/tsconfig.test.json +0 -9
@@ -0,0 +1,251 @@
1
+ import { beforeEach } from "@jest/globals";
2
+ import { Field } from "o1js";
3
+
4
+ import {
5
+ createMerkleTree,
6
+ InMemoryMerkleTreeStorage,
7
+ log,
8
+ RollupMerkleTree,
9
+ range,
10
+ } from "../../src";
11
+
12
+ describe("batch setLeaf", () => {
13
+ function generateBatch(
14
+ size: number,
15
+ height: number,
16
+ generator = () => Field.random().toBigInt()
17
+ ) {
18
+ const max = 2n ** BigInt(height - 1);
19
+ return range(0, size).map(() => ({
20
+ index: generator() % max,
21
+ leaf: Field.random(),
22
+ }));
23
+ }
24
+
25
+ function generateBatchAdjacent(size: number, height: number) {
26
+ let start = 0n;
27
+ return generateBatch(size, height, () => {
28
+ start += 1n;
29
+ return start - 1n;
30
+ });
31
+ }
32
+
33
+ function captureTime<R>(f: () => R): [number, R] {
34
+ const start = Date.now();
35
+ const ret = f();
36
+ return [Date.now() - start, ret];
37
+ }
38
+ const height = 10;
39
+ const maxIndex = 2n ** BigInt(height - 1) - 1n;
40
+
41
+ it.each([
42
+ [
43
+ { index: 1n, leaf: Field(5) },
44
+ { index: maxIndex, leaf: Field(7) },
45
+ ],
46
+ [
47
+ { index: maxIndex, leaf: Field(7) },
48
+ { index: maxIndex - 1n, leaf: Field(7) },
49
+ { index: 50n, leaf: Field(7) },
50
+ { index: 1n, leaf: Field(5) },
51
+ ],
52
+ generateBatch(5, height),
53
+ generateBatch(10, height),
54
+ generateBatch(50, height),
55
+ generateBatch(300, height),
56
+ ])("correctness", (...writes) => {
57
+ const Tree = createMerkleTree(height);
58
+ const tree1 = new Tree(new InMemoryMerkleTreeStorage());
59
+ const tree2 = new Tree(new InMemoryMerkleTreeStorage());
60
+
61
+ writes.forEach(({ index, leaf }) => {
62
+ tree1.setLeaf(index, leaf);
63
+ });
64
+
65
+ tree2.setLeaves(writes);
66
+
67
+ expect(tree1.getRoot().toString()).toStrictEqual(
68
+ tree2.getRoot().toString()
69
+ );
70
+ });
71
+
72
+ it.each([
73
+ // This tests the correct retrieval of previously-set siblings (vs. above
74
+ // where always fetch zero-siblings)
75
+ [[{ index: 1n, leaf: Field(5) }], [{ index: 4n, leaf: Field(1) }]],
76
+ [[{ index: 4n, leaf: Field(5) }], [{ index: 1n, leaf: Field(1) }]],
77
+ ])("correctness - batches", (...writes) => {
78
+ expect.assertions(writes.length);
79
+
80
+ const Tree = createMerkleTree(height);
81
+ const tree1 = new Tree(new InMemoryMerkleTreeStorage());
82
+ const tree2 = new Tree(new InMemoryMerkleTreeStorage());
83
+
84
+ writes.forEach((writes2) => {
85
+ writes2.forEach(({ index, leaf }) => {
86
+ tree1.setLeaf(index, leaf);
87
+ });
88
+
89
+ tree2.setLeaves(writes2);
90
+
91
+ expect(tree1.getRoot().toString()).toStrictEqual(
92
+ tree2.getRoot().toString()
93
+ );
94
+ });
95
+ });
96
+
97
+ it.each([
98
+ ["random", 10, generateBatch],
99
+ ["random", 100, generateBatch],
100
+ ["adjacent", 100, generateBatchAdjacent],
101
+ ["adjacent", 10, generateBatchAdjacent],
102
+ ])("test speedup: %s (%i leaves)", (label, batchSize, generateFunction) => {
103
+ const tree1 = new RollupMerkleTree(new InMemoryMerkleTreeStorage());
104
+ const tree2 = new RollupMerkleTree(new InMemoryMerkleTreeStorage());
105
+
106
+ const batch = generateFunction(batchSize, RollupMerkleTree.HEIGHT);
107
+
108
+ const slice = batch.slice();
109
+ const [time1] = captureTime(() => tree1.setLeaves(slice));
110
+ const [time2] = captureTime(() =>
111
+ batch.forEach(({ index, leaf }) => tree2.setLeaf(index, leaf))
112
+ );
113
+
114
+ console.log(`Speedup for batch size ${batchSize}, mode ${label}`);
115
+ console.log(time1);
116
+ console.log(time2);
117
+
118
+ expect(tree1.getRoot().toString()).toStrictEqual(
119
+ tree2.getRoot().toString()
120
+ );
121
+ });
122
+ });
123
+
124
+ describe.each([4, 16, 256])("cachedMerkleTree - %s", (height) => {
125
+ class MerkleTree extends createMerkleTree(height) {}
126
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
127
+ class MerkleTreeWitness extends MerkleTree.WITNESS {}
128
+
129
+ let store: InMemoryMerkleTreeStorage;
130
+ let tree: MerkleTree;
131
+
132
+ beforeEach(() => {
133
+ log.setLevel("INFO");
134
+
135
+ store = new InMemoryMerkleTreeStorage();
136
+ tree = new MerkleTree(store);
137
+ });
138
+
139
+ it("should have the same root when empty", () => {
140
+ expect.assertions(1);
141
+
142
+ expect(tree.getRoot().toBigInt()).toStrictEqual(MerkleTree.EMPTY_ROOT);
143
+ });
144
+
145
+ it("should have a different root when not empty", () => {
146
+ expect.assertions(1);
147
+
148
+ tree.setLeaf(1n, Field(1));
149
+
150
+ expect(tree.getRoot().toBigInt()).not.toStrictEqual(MerkleTree.EMPTY_ROOT);
151
+ });
152
+
153
+ it("should have the same root after adding and removing item", () => {
154
+ expect.assertions(1);
155
+
156
+ tree.setLeaf(1n, Field(1));
157
+
158
+ const root = tree.getRoot();
159
+
160
+ tree.setLeaf(5n, Field(5));
161
+ tree.setLeaf(5n, Field(0));
162
+
163
+ expect(tree.getRoot().toBigInt()).toStrictEqual(root.toBigInt());
164
+ });
165
+
166
+ it("should provide correct witnesses", () => {
167
+ expect.assertions(1);
168
+
169
+ tree.setLeaf(1n, Field(1));
170
+ tree.setLeaf(5n, Field(5));
171
+
172
+ const witness = tree.getWitness(5n);
173
+
174
+ expect(witness.calculateRoot(Field(5)).toBigInt()).toStrictEqual(
175
+ tree.getRoot().toBigInt()
176
+ );
177
+ });
178
+
179
+ it("should have invalid witnesses with wrong values", () => {
180
+ expect.assertions(1);
181
+
182
+ tree.setLeaf(1n, Field(1));
183
+ tree.setLeaf(5n, Field(5));
184
+
185
+ const witness = tree.getWitness(5n);
186
+
187
+ expect(witness.calculateRoot(Field(6)).toBigInt()).not.toStrictEqual(
188
+ tree.getRoot().toBigInt()
189
+ );
190
+ });
191
+
192
+ it("should have valid witnesses with changed value on the same leafs", () => {
193
+ expect.assertions(1);
194
+
195
+ tree.setLeaf(1n, Field(1));
196
+ tree.setLeaf(5n, Field(5));
197
+
198
+ const witness = tree.getWitness(5n);
199
+
200
+ tree.setLeaf(5n, Field(10));
201
+
202
+ expect(witness.calculateRoot(Field(10)).toBigInt()).toStrictEqual(
203
+ tree.getRoot().toBigInt()
204
+ );
205
+ });
206
+
207
+ it("should throw for invalid index", () => {
208
+ expect.assertions(2);
209
+
210
+ const index = 2n ** BigInt(height) + 1n;
211
+
212
+ expect(() => {
213
+ tree.setLeaf(index, Field(1));
214
+ }).toThrow("Index greater than maximum leaf number");
215
+
216
+ expect(() => {
217
+ tree.getNode(0, index);
218
+ }).toThrow("Index greater than maximum leaf number");
219
+ });
220
+
221
+ it("witness incrementing", () => {
222
+ tree.setLeaf(0n, Field(3256));
223
+ tree.setLeaf(1n, Field(3256));
224
+ tree.setLeaf(2n, Field(3256));
225
+
226
+ const witness = tree.getWitness(3n);
227
+
228
+ const [root, newWitness] = witness.calculateRootIncrement(
229
+ Field(3),
230
+ Field(1234)
231
+ );
232
+ tree.setLeaf(3n, Field(1234));
233
+
234
+ expect(tree.getRoot().toString()).toStrictEqual(root.toString());
235
+ expect(newWitness.calculateIndex().toString()).toStrictEqual("4");
236
+
237
+ const [root2, newWitness2] = newWitness.calculateRootIncrement(
238
+ Field(4),
239
+ Field(4321)
240
+ );
241
+ tree.setLeaf(4n, Field(4321));
242
+
243
+ expect(tree.getRoot().toString()).toStrictEqual(root2.toString());
244
+ expect(newWitness2.calculateIndex().toString()).toStrictEqual("5");
245
+
246
+ const root3 = newWitness2.calculateRoot(Field(555));
247
+ tree.setLeaf(5n, Field(555));
248
+
249
+ expect(tree.getRoot().toString()).toStrictEqual(root3.toString());
250
+ });
251
+ });
@@ -1,4 +1,7 @@
1
1
  {
2
- "extends": "./../tsconfig.json",
3
- "include": ["./**/*.ts", "./*.ts", "./../src/**/*.ts"]
2
+ "extends": "./../../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "experimentalDecorators": true
5
+ },
6
+ "include": ["./**/*.ts", "./*.ts"]
4
7
  }
@@ -1,22 +1,17 @@
1
- /* eslint-disable max-classes-per-file */
2
1
  import "reflect-metadata";
3
- // eslint-disable-next-line @typescript-eslint/no-shadow
4
2
  import { jest } from "@jest/globals";
5
3
  import { container } from "tsyringe";
6
- import { Experimental, Field, Struct, Proof } from "snarkyjs";
4
+ import { Field, Struct, Proof, ZkProgram } from "o1js";
7
5
 
8
6
  import {
9
- mockProof,
7
+ MOCK_PROOF,
10
8
  provableMethod,
11
- } from "../../src/zkProgrammable/provableMethod";
12
- import {
13
9
  AreProofsEnabled,
14
10
  CompileArtifact,
15
- mockVerificationKey,
16
- PlainZkProgram,
11
+ MOCK_VERIFICATION_KEY,
17
12
  ZkProgrammable,
18
- } from "../../src/zkProgrammable/ZkProgrammable";
19
- import { ProvableMethodExecutionContext } from "../../src/zkProgrammable/ProvableMethodExecutionContext";
13
+ ProvableMethodExecutionContext,
14
+ } from "../../src";
20
15
 
21
16
  const appChainMock: AreProofsEnabled = {
22
17
  areProofsEnabled: false,
@@ -36,31 +31,38 @@ class TestPublicOutput extends Struct({
36
31
 
37
32
  const failErrorMessage = "test failure";
38
33
 
34
+ type Balance = Field;
35
+
39
36
  class TestProgrammable extends ZkProgrammable<
40
37
  TestPublicInput,
41
38
  TestPublicOutput
42
39
  > {
43
- public appChain: AreProofsEnabled = appChainMock;
40
+ public areProofsEnabled: AreProofsEnabled = appChainMock;
44
41
 
45
42
  @provableMethod()
46
- public foo(publicInput: TestPublicInput, bar: Field) {
43
+ public async foo(publicInput: TestPublicInput, bar: Balance) {
47
44
  // expose the private input as public output again for testing purposes
48
- return new TestPublicOutput({
49
- bar,
50
- });
45
+ return {
46
+ publicOutput: new TestPublicOutput({
47
+ bar,
48
+ }),
49
+ };
51
50
  }
52
51
 
53
52
  @provableMethod()
54
- public fail(publicInput: TestPublicInput) {
53
+ public async fail(publicInput: TestPublicInput) {
55
54
  publicInput.foo.assertEquals(1, failErrorMessage);
56
55
 
57
- return new TestPublicOutput({
58
- bar: Field(0),
59
- });
56
+ return {
57
+ publicOutput: new TestPublicOutput({
58
+ bar: Field(0),
59
+ }),
60
+ };
60
61
  }
61
62
 
62
63
  public zkProgramFactory() {
63
- const program = Experimental.ZkProgram({
64
+ const program = ZkProgram({
65
+ name: "testprogram",
64
66
  publicInput: TestPublicInput,
65
67
  publicOutput: TestPublicOutput,
66
68
 
@@ -77,43 +79,46 @@ class TestProgrammable extends ZkProgrammable<
77
79
  },
78
80
  });
79
81
 
80
- const SelfProof = Experimental.ZkProgram.Proof(program);
82
+ const SelfProof = ZkProgram.Proof(program);
81
83
 
82
84
  const methods = {
83
85
  foo: program.foo.bind(program),
84
86
  fail: program.fail.bind(program),
85
87
  };
86
88
 
87
- return {
88
- compile: program.compile.bind(program),
89
- verify: program.verify.bind(program),
90
- Proof: SelfProof,
91
- methods,
92
- };
89
+ return [
90
+ {
91
+ name: program.name,
92
+ compile: program.compile.bind(program),
93
+ verify: program.verify.bind(program),
94
+ analyzeMethods: program.analyzeMethods.bind(program),
95
+ Proof: SelfProof,
96
+ methods,
97
+ },
98
+ ];
93
99
  }
94
100
  }
95
101
 
96
- class OtherTestProgrammable extends ZkProgrammable {
97
- public appChain: AreProofsEnabled = appChainMock;
102
+ class OtherTestProgrammable extends ZkProgrammable<undefined, void> {
103
+ public areProofsEnabled: AreProofsEnabled = appChainMock;
98
104
 
99
105
  public constructor(public testProgrammable: TestProgrammable) {
100
106
  super();
101
107
  }
102
108
 
109
+ proofType = this.testProgrammable.zkProgram[0].Proof;
110
+
103
111
  @provableMethod()
104
- public bar(
105
- testProgrammableProof: InstanceType<
106
- typeof this.testProgrammable.zkProgram.Proof
107
- >
108
- ) {
112
+ public async bar(testProgrammableProof: InstanceType<typeof this.proofType>) {
109
113
  testProgrammableProof.verify();
110
114
  }
111
115
 
112
- public zkProgramFactory(): PlainZkProgram {
113
- const program = Experimental.ZkProgram({
116
+ public zkProgramFactory() {
117
+ const program = ZkProgram({
118
+ name: "testprogram2",
114
119
  methods: {
115
120
  bar: {
116
- privateInputs: [this.testProgrammable.zkProgram.Proof],
121
+ privateInputs: [this.testProgrammable.zkProgram[0].Proof],
117
122
  method: this.bar.bind(this),
118
123
  },
119
124
  },
@@ -123,47 +128,68 @@ class OtherTestProgrammable extends ZkProgrammable {
123
128
  bar: program.bar.bind(program),
124
129
  };
125
130
 
126
- const SelfProof = Experimental.ZkProgram.Proof(program);
131
+ const SelfProof = ZkProgram.Proof(program);
127
132
 
128
- return {
129
- compile: program.compile.bind(program),
130
- verify: program.verify.bind(program),
131
- Proof: SelfProof,
132
- methods,
133
- };
133
+ return [
134
+ {
135
+ name: program.name,
136
+ compile: program.compile.bind(program),
137
+ verify: program.verify.bind(program),
138
+ analyzeMethods: program.analyzeMethods.bind(program),
139
+ Proof: SelfProof,
140
+ methods,
141
+ },
142
+ ];
134
143
  }
135
144
  }
136
145
 
146
+ const testWithProofs = false;
147
+
137
148
  describe("zkProgrammable", () => {
138
149
  let testProgrammable: TestProgrammable;
139
150
  let artifact: CompileArtifact;
140
151
  let zkProgramFactorySpy: ReturnType<typeof jest.spyOn>;
141
152
 
142
- describe.each([
153
+ const testCases: [
154
+ boolean,
155
+ {
156
+ verificationKey: CompileArtifact["verificationKey"];
157
+ shouldVerifyMockProofs: boolean;
158
+ },
159
+ ][] = [
143
160
  [
144
161
  false,
145
162
  {
146
- verificationKey: mockVerificationKey,
163
+ verificationKey: MOCK_VERIFICATION_KEY,
147
164
  shouldVerifyMockProofs: true,
148
165
  },
149
166
  ],
150
- [
151
- true,
152
- {
153
- verificationKey:
154
- "AAA32/LNoPxEfDF5UkwfEetd5jiVLDF/Ul3N+Q2wKNcqFZm7FRScVoJylKe73IAPgAcadZ/vFAeIuDuAPFx1FaoIIoGAq5LAKNNrkU8EnWUJgSmKm2rJ3uNkJifAf116Aja8pacHExKqq5WblExBpsV/ET9JavLBZSql4zYEIvj9KfYfAz2DV6a0/jRWJAiF2xBaK2UIyga33djCkw3Lk/UC3DjVrt2EysRhypmelSlnf+XKLECQMQSk8RH9/YlNvyBZpqiNt2Fl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with proofs enabled for the CI and other stuff,
170
+ // as it is quite expensive. But we should find a better pattern than this
171
+ if (testWithProofs) {
172
+ // TODO Migrate to new o1js compile artifact format
173
+ // testCases.push([
174
+ // true,
175
+ // {
176
+ // verificationKey:
177
+ // eslint-disable-next-line max-len
178
+ // "AAA32/LNoPxEfDF5UkwfEetd5jiVLDF/Ul3N+Q2wKNcqFZm7FRScVoJylKe73IAPgAcadZ/vFAeIuDuAPFx1FaoIIoGAq5LAKNNrkU8EnWUJgSmKm2rJ3uNkJifAf116Aja8pacHExKqq5WblExBpsV/ET9JavLBZSql4zYEIvj9KfYfAz2DV6a0/jRWJAiF2xBaK2UIyga33djCkw3Lk/UC3DjVrt2EysRhypmelSlnf+XKLECQMQSk8RH9/YlNvyBZpqiNt2FlUphQazs7tArBs1eMd8Zn5BE7gszpmPaIBOtcvVRRaoXc/9FRX89st9IEWtFf8MCMV5kDlKOGk7wCKMz8HjgfMG5ux/3FCHeQiJdfk1USn9oER3MsAsOUsziPykhVZkOHTXvVphx27cZwnf2iUIIEZgJ/GvKXv9ZRAPEQsf3bP6yoKoazBlJYJZVwJ4aidwzIHiqcMJmfUYoxL512IZf6WYCGHaisgzdOw7TSGo4LDc8IjqMT1fcqqziBQw5iZbeJ9JQwPFai1PkJQnD2Yh+XfclzWkCC9uJVEFUmidAVVw3DeMlCb77ylJUd9nVCi+MfElf+x2xqKyELAPU2Hf5+05yTxvFR6B+n1y1MEeOZsMpcWt11zHMC5aMGTiOLUZ6zJb9lAr5GuDaWTBTcRkzBp4sWaQ58MLNygBNfVgmLkp2N5ItRcyQPo138oegzHf1obQa8D6Id32K2DfDUXcvgcgo2Q6GSrTc55iNzoFEEnszUKAyi4usWdLQATzgC0CgbEaN54nF7JD1417PipM6skAf4fB31aqCEATAP+QVDRQTIrYkHJ4gykPi8QCTVk497d3wkJVioAtqWDiIoGlSITUmhBoj05xN6cndvsMrzaKQz420nYy/Nw1EIqL0yq71q2w/eRqnezVxOAjuoyAzo0ss9hT9C9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VmwRni+i1qIIBb38UpVA4Tt0wJzYGRsnZM5uev3IfIe1sRTvYsIAT/WeFRq43GLL5xelWjKnmEOr9yjzQj2uTelZU6PFknB3dlo5ybe2i6dpHoAU/vZvgdHKJ6ApSKnlCWEtbd4QG5Rc7vBt2Kj4/AxK1jp6/MLA/+p5dUlF+8682seKFHLAdKGxaE2d18jjnLdRZ5+YHcCE0TdnKateX+EToGKZkW9znPIweZGEgTKwXn3GUaBh+LX59g3KpRFPldlKt7KghKyMRpHE+NUpxXsvRi8Nil93U+BWB7hC1msGRoAK+fMsmH1e+ZCActSz0ZP074iKPZGLa/CZwkxCqUS7tPOqEOomk5PtUCjLaVxmu/m/Icw9sE18n1bhexuNgU6dVWRSs=",
179
+ //
180
+ // shouldVerifyMockProofs: false,
181
+ // },
182
+ // ]);
183
+ }
155
184
 
156
- shouldVerifyMockProofs: false,
157
- },
158
- ],
159
- ])(
185
+ describe.each(testCases)(
160
186
  "areProofsEnabled",
161
187
  (areProofsEnabled, { verificationKey, shouldVerifyMockProofs }) => {
162
188
  beforeAll(async () => {
163
189
  testProgrammable = new TestProgrammable();
164
- testProgrammable.appChain.setProofsEnabled(areProofsEnabled);
190
+ testProgrammable.areProofsEnabled.setProofsEnabled(areProofsEnabled);
165
191
  zkProgramFactorySpy = jest.spyOn(testProgrammable, "zkProgramFactory");
166
- artifact = await testProgrammable.zkProgram.compile();
192
+ artifact = await testProgrammable.zkProgram[0].compile();
167
193
  }, 500_000);
168
194
 
169
195
  describe("zkProgramFactory", () => {
@@ -190,8 +216,8 @@ describe("zkProgrammable", () => {
190
216
  it("if proofs are disabled, it should successfully verify mock proofs", async () => {
191
217
  expect.assertions(1);
192
218
 
193
- const proof = new testProgrammable.zkProgram.Proof({
194
- proof: mockProof,
219
+ const proof = new testProgrammable.zkProgram[0].Proof({
220
+ proof: MOCK_PROOF,
195
221
 
196
222
  publicInput: new TestPublicInput({
197
223
  foo: Field(0),
@@ -204,7 +230,7 @@ describe("zkProgrammable", () => {
204
230
  maxProofsVerified: 0,
205
231
  });
206
232
 
207
- const verified = await testProgrammable.zkProgram.verify(proof);
233
+ const verified = await testProgrammable.zkProgram[0].verify(proof);
208
234
 
209
235
  expect(verified).toBe(shouldVerifyMockProofs);
210
236
 
@@ -212,71 +238,71 @@ describe("zkProgrammable", () => {
212
238
  // const json = proof.toJSON();
213
239
  // expect(json).toBeDefined();
214
240
  });
215
- }
216
- );
217
-
218
- describe("provableMethod", () => {
219
- const executionContext = container.resolve<ProvableMethodExecutionContext>(
220
- ProvableMethodExecutionContext
221
- );
222
-
223
- let otherTestProgrammable: OtherTestProgrammable;
224
-
225
- const testPublicInput = new TestPublicInput({
226
- foo: Field(0),
227
- });
228
-
229
- describe("zkProgram interoperability", () => {
230
- beforeAll(async () => {
231
- otherTestProgrammable = new OtherTestProgrammable(testProgrammable);
232
- await otherTestProgrammable.zkProgram.compile();
233
- }, 500_000);
234
241
 
235
- it("should successfully pass proof of one zkProgram as input to another zkProgram", async () => {
236
- expect.assertions(3);
242
+ describe("provableMethod", () => {
243
+ const executionContext =
244
+ container.resolve<ProvableMethodExecutionContext>(
245
+ ProvableMethodExecutionContext
246
+ );
237
247
 
238
- // execute foo
239
- testProgrammable.foo(testPublicInput, Field(0));
248
+ let otherTestProgrammable: OtherTestProgrammable;
240
249
 
241
- // prove foo
242
- const testProof = await executionContext
243
- .current()
244
- .result.prove<Proof<TestPublicInput, TestPublicOutput>>();
245
- const testProofVerified = await testProgrammable.zkProgram.verify(
246
- testProof
247
- );
248
-
249
- // execute bar
250
- otherTestProgrammable.bar(testProof);
251
-
252
- // proof bar
253
- const otherTestProof = await executionContext
254
- .current()
255
- .result.prove<Proof<undefined, void>>();
256
- const otherTestProofVerified =
257
- await otherTestProgrammable.zkProgram.verify(otherTestProof);
258
-
259
- expect(testProof.publicOutput.bar.toString()).toBe(
260
- testPublicInput.foo.toString()
261
- );
250
+ const testPublicInput = new TestPublicInput({
251
+ foo: Field(0),
252
+ });
262
253
 
263
- expect(testProofVerified).toBe(true);
264
- expect(otherTestProofVerified).toBe(true);
265
- }, 500_000);
266
- });
254
+ describe("zkProgram interoperability", () => {
255
+ beforeAll(async () => {
256
+ otherTestProgrammable = new OtherTestProgrammable(testProgrammable);
257
+ await otherTestProgrammable.zkProgram[0].compile();
258
+ }, 500_000);
259
+
260
+ it("should successfully pass proof of one zkProgram as input to another zkProgram", async () => {
261
+ expect.assertions(3);
262
+
263
+ // execute foo
264
+ await testProgrammable.foo(testPublicInput, Field(0));
265
+
266
+ // prove foo
267
+ const testProof = await executionContext
268
+ .current()
269
+ .result.prove<Proof<TestPublicInput, TestPublicOutput>>();
270
+ const testProofVerified =
271
+ await testProgrammable.zkProgram[0].verify(testProof);
272
+
273
+ // execute bar
274
+ await otherTestProgrammable.bar(testProof);
275
+
276
+ // proof bar
277
+ const otherTestProof = await executionContext
278
+ .current()
279
+ .result.prove<Proof<undefined, undefined>>();
280
+ const otherTestProofVerified =
281
+ await otherTestProgrammable.zkProgram[0].verify(otherTestProof);
282
+
283
+ expect(testProof.publicOutput.bar.toString()).toBe(
284
+ testPublicInput.foo.toString()
285
+ );
286
+
287
+ expect(testProofVerified).toBe(true);
288
+ expect(otherTestProofVerified).toBe(true);
289
+ }, 500_000);
290
+ });
267
291
 
268
- describe("failed method execution", () => {
269
- it("if the method fails, it should fail to execute and prove", async () => {
270
- expect.assertions(2);
292
+ describe("failed method execution", () => {
293
+ it("if the method fails, it should fail to execute and prove", async () => {
294
+ expect.assertions(2);
271
295
 
272
- expect(() => {
273
- testProgrammable.fail(testPublicInput);
274
- }).toThrow(failErrorMessage);
296
+ await expect(
297
+ testProgrammable.fail(testPublicInput)
298
+ ).rejects.toThrow(failErrorMessage);
275
299
 
276
- await expect(async () => {
277
- await executionContext.current().result.prove();
278
- }).rejects.toThrow(failErrorMessage);
300
+ await expect(async () => {
301
+ await executionContext.current().result.prove();
302
+ }).rejects.toThrow(failErrorMessage);
303
+ });
304
+ });
279
305
  });
280
- });
281
- });
306
+ }
307
+ );
282
308
  });
package/tsconfig.json CHANGED
@@ -3,6 +3,6 @@
3
3
  "compilerOptions": {
4
4
  "outDir": "./dist"
5
5
  },
6
- "include": ["./src/index.ts"],
6
+ "include": ["./src/**/*.ts", "./src/*.ts"],
7
7
  "exclude": ["./dist/**/*.ts"]
8
8
  }