@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.
- package/dist/cache/CacheManifest.d.ts +11 -0
- package/dist/cache/CacheManifest.d.ts.map +1 -0
- package/dist/cache/CacheManifest.js +56 -0
- package/dist/cache/CacheManifest.js.map +1 -0
- package/dist/cache/ProxyCache.d.ts +13 -0
- package/dist/cache/ProxyCache.d.ts.map +1 -0
- package/dist/cache/ProxyCache.js +24 -0
- package/dist/cache/ProxyCache.js.map +1 -0
- package/dist/cache/RemoteCache.d.ts +8 -0
- package/dist/cache/RemoteCache.d.ts.map +1 -0
- package/dist/cache/RemoteCache.js +2 -0
- package/dist/cache/RemoteCache.js.map +1 -0
- package/dist/cache/RemoteCacheCompiler.d.ts +16 -0
- package/dist/cache/RemoteCacheCompiler.d.ts.map +1 -0
- package/dist/cache/RemoteCacheCompiler.js +104 -0
- package/dist/cache/RemoteCacheCompiler.js.map +1 -0
- package/dist/compiling/AtomicCompileHelper.d.ts +15 -0
- package/dist/compiling/AtomicCompileHelper.d.ts.map +1 -0
- package/dist/compiling/AtomicCompileHelper.js +61 -0
- package/dist/compiling/AtomicCompileHelper.js.map +1 -0
- package/dist/compiling/CompilableModule.d.ts +6 -0
- package/dist/compiling/CompilableModule.d.ts.map +1 -0
- package/dist/compiling/CompilableModule.js +2 -0
- package/dist/compiling/CompilableModule.js.map +1 -0
- package/dist/compiling/CompileRegistry.d.ts +25 -0
- package/dist/compiling/CompileRegistry.d.ts.map +1 -0
- package/dist/compiling/CompileRegistry.js +62 -0
- package/dist/compiling/CompileRegistry.js.map +1 -0
- package/dist/compiling/services/ChildVerificationKeyService.d.ts +10 -0
- package/dist/compiling/services/ChildVerificationKeyService.d.ts.map +1 -0
- package/dist/compiling/services/ChildVerificationKeyService.js +27 -0
- package/dist/compiling/services/ChildVerificationKeyService.js.map +1 -0
- package/dist/config/ChildContainerCreatable.d.ts +5 -0
- package/dist/config/ChildContainerCreatable.d.ts.map +1 -0
- package/dist/config/ChildContainerCreatable.js +2 -0
- package/dist/config/ChildContainerCreatable.js.map +1 -0
- package/dist/config/ChildContainerProvider.d.ts +5 -0
- package/dist/config/ChildContainerProvider.d.ts.map +1 -0
- package/dist/config/ChildContainerProvider.js +2 -0
- package/dist/config/ChildContainerProvider.js.map +1 -0
- package/dist/config/ConfigurableModule.d.ts +6 -2
- package/dist/config/ConfigurableModule.d.ts.map +1 -1
- package/dist/config/ConfigurableModule.js +5 -0
- package/dist/config/ConfigurableModule.js.map +1 -0
- package/dist/config/ModuleContainer.d.ts +70 -23
- package/dist/config/ModuleContainer.d.ts.map +1 -1
- package/dist/config/ModuleContainer.js +164 -31
- package/dist/config/ModuleContainer.js.map +1 -0
- package/dist/config/Startable.d.ts +4 -0
- package/dist/config/Startable.d.ts.map +1 -0
- package/dist/config/Startable.js +2 -0
- package/dist/config/Startable.js.map +1 -0
- package/dist/config/injectAlias.d.ts +18 -0
- package/dist/config/injectAlias.d.ts.map +1 -0
- package/dist/config/injectAlias.js +47 -0
- package/dist/config/injectAlias.js.map +1 -0
- package/dist/dependencyFactory/DependencyFactory.d.ts +14 -9
- package/dist/dependencyFactory/DependencyFactory.d.ts.map +1 -1
- package/dist/dependencyFactory/DependencyFactory.js +2 -96
- package/dist/dependencyFactory/DependencyFactory.js.map +1 -0
- package/dist/dependencyFactory/injectOptional.d.ts +16 -0
- package/dist/dependencyFactory/injectOptional.d.ts.map +1 -0
- package/dist/dependencyFactory/injectOptional.js +40 -0
- package/dist/dependencyFactory/injectOptional.js.map +1 -0
- package/dist/dummyVerificationKey.d.ts +3 -0
- package/dist/dummyVerificationKey.d.ts.map +1 -0
- package/dist/dummyVerificationKey.js +8 -0
- package/dist/dummyVerificationKey.js.map +1 -0
- package/dist/events/EventEmitter.d.ts +19 -0
- package/dist/events/EventEmitter.d.ts.map +1 -0
- package/dist/events/EventEmitter.js +35 -0
- package/dist/events/EventEmitter.js.map +1 -0
- package/dist/events/EventEmitterProxy.d.ts +18 -0
- package/dist/events/EventEmitterProxy.d.ts.map +1 -0
- package/dist/events/EventEmitterProxy.js +35 -0
- package/dist/events/EventEmitterProxy.js.map +1 -0
- package/dist/events/EventEmittingComponent.d.ts +9 -0
- package/dist/events/EventEmittingComponent.d.ts.map +1 -0
- package/dist/events/EventEmittingComponent.js +2 -0
- package/dist/events/EventEmittingComponent.js.map +1 -0
- package/dist/events/ReplayingSingleUseEventEmitter.d.ts +17 -0
- package/dist/events/ReplayingSingleUseEventEmitter.d.ts.map +1 -0
- package/dist/events/ReplayingSingleUseEventEmitter.js +34 -0
- package/dist/events/ReplayingSingleUseEventEmitter.js.map +1 -0
- package/dist/index.d.ts +27 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -2
- package/dist/index.js.map +1 -0
- package/dist/log.d.ts +37 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +117 -0
- package/dist/log.js.map +1 -0
- package/dist/trees/InMemoryLinkedLeafStore.d.ts +21 -0
- package/dist/trees/InMemoryLinkedLeafStore.d.ts.map +1 -0
- package/dist/trees/InMemoryLinkedLeafStore.js +26 -0
- package/dist/trees/InMemoryLinkedLeafStore.js.map +1 -0
- package/dist/trees/InMemoryLinkedMerkleLeafStore.d.ts +7 -0
- package/dist/trees/InMemoryLinkedMerkleLeafStore.d.ts.map +1 -0
- package/dist/trees/InMemoryLinkedMerkleLeafStore.js +6 -0
- package/dist/trees/InMemoryLinkedMerkleLeafStore.js.map +1 -0
- package/dist/trees/InMemoryMerkleTreeStorage.d.ts +11 -0
- package/dist/trees/InMemoryMerkleTreeStorage.d.ts.map +1 -0
- package/dist/trees/InMemoryMerkleTreeStorage.js +13 -0
- package/dist/trees/InMemoryMerkleTreeStorage.js.map +1 -0
- package/dist/trees/LinkedMerkleTree.d.ts +345 -0
- package/dist/trees/LinkedMerkleTree.d.ts.map +1 -0
- package/dist/trees/LinkedMerkleTree.js +337 -0
- package/dist/trees/LinkedMerkleTree.js.map +1 -0
- package/dist/trees/LinkedMerkleTreeStore.d.ts +24 -0
- package/dist/trees/LinkedMerkleTreeStore.d.ts.map +1 -0
- package/dist/trees/LinkedMerkleTreeStore.js +2 -0
- package/dist/trees/LinkedMerkleTreeStore.js.map +1 -0
- package/dist/trees/MerkleTreeStore.d.ts +5 -0
- package/dist/trees/MerkleTreeStore.d.ts.map +1 -0
- package/dist/trees/MerkleTreeStore.js +2 -0
- package/dist/trees/MerkleTreeStore.js.map +1 -0
- package/dist/trees/MockAsyncMerkleStore.d.ts +9 -0
- package/dist/trees/MockAsyncMerkleStore.d.ts.map +1 -0
- package/dist/trees/MockAsyncMerkleStore.js +20 -0
- package/dist/trees/MockAsyncMerkleStore.js.map +1 -0
- package/dist/trees/RollupMerkleTree.d.ts +147 -0
- package/dist/trees/RollupMerkleTree.d.ts.map +1 -0
- package/dist/trees/RollupMerkleTree.js +218 -0
- package/dist/trees/RollupMerkleTree.js.map +1 -0
- package/dist/trees/VirtualMerkleTreeStore.d.ts +13 -0
- package/dist/trees/VirtualMerkleTreeStore.d.ts.map +1 -0
- package/dist/trees/VirtualMerkleTreeStore.js +18 -0
- package/dist/trees/VirtualMerkleTreeStore.js.map +1 -0
- package/dist/trees/lmt/AbstractLinkedMerkleTree.d.ts +288 -0
- package/dist/trees/lmt/AbstractLinkedMerkleTree.d.ts.map +1 -0
- package/dist/trees/lmt/AbstractLinkedMerkleTree.js +22 -0
- package/dist/trees/lmt/AbstractLinkedMerkleTree.js.map +1 -0
- package/dist/trees/lmt/InMemoryLinkedLeafStore.d.ts +21 -0
- package/dist/trees/lmt/InMemoryLinkedLeafStore.d.ts.map +1 -0
- package/dist/trees/lmt/InMemoryLinkedLeafStore.js +26 -0
- package/dist/trees/lmt/InMemoryLinkedLeafStore.js.map +1 -0
- package/dist/trees/lmt/InMemoryLinkedMerkleLeafStore.d.ts +7 -0
- package/dist/trees/lmt/InMemoryLinkedMerkleLeafStore.d.ts.map +1 -0
- package/dist/trees/lmt/InMemoryLinkedMerkleLeafStore.js +6 -0
- package/dist/trees/lmt/InMemoryLinkedMerkleLeafStore.js.map +1 -0
- package/dist/trees/lmt/LinkedLeafStore.d.ts +16 -0
- package/dist/trees/lmt/LinkedLeafStore.d.ts.map +1 -0
- package/dist/trees/lmt/LinkedLeafStore.js +2 -0
- package/dist/trees/lmt/LinkedLeafStore.js.map +1 -0
- package/dist/trees/lmt/LinkedLinkedStore.d.ts +16 -0
- package/dist/trees/lmt/LinkedLinkedStore.d.ts.map +1 -0
- package/dist/trees/lmt/LinkedLinkedStore.js +2 -0
- package/dist/trees/lmt/LinkedLinkedStore.js.map +1 -0
- package/dist/trees/lmt/LinkedMerkleTree.d.ts +11 -0
- package/dist/trees/lmt/LinkedMerkleTree.d.ts.map +1 -0
- package/dist/trees/lmt/LinkedMerkleTree.js +241 -0
- package/dist/trees/lmt/LinkedMerkleTree.js.map +1 -0
- package/dist/trees/lmt/LinkedMerkleTreeCircuitOps.d.ts +113 -0
- package/dist/trees/lmt/LinkedMerkleTreeCircuitOps.d.ts.map +1 -0
- package/dist/trees/lmt/LinkedMerkleTreeCircuitOps.js +113 -0
- package/dist/trees/lmt/LinkedMerkleTreeCircuitOps.js.map +1 -0
- package/dist/trees/lmt/LinkedMerkleTreeDatabase.d.ts +7 -0
- package/dist/trees/lmt/LinkedMerkleTreeDatabase.d.ts.map +1 -0
- package/dist/trees/lmt/LinkedMerkleTreeDatabase.js +2 -0
- package/dist/trees/lmt/LinkedMerkleTreeDatabase.js.map +1 -0
- package/dist/trees/lmt/LinkedMerkleTreeStore.d.ts +16 -0
- package/dist/trees/lmt/LinkedMerkleTreeStore.d.ts.map +1 -0
- package/dist/trees/lmt/LinkedMerkleTreeStore.js +2 -0
- package/dist/trees/lmt/LinkedMerkleTreeStore.js.map +1 -0
- package/dist/trees/lmt/LinkedMerkleTreeTypes.d.ts +74 -0
- package/dist/trees/lmt/LinkedMerkleTreeTypes.d.ts.map +1 -0
- package/dist/trees/lmt/LinkedMerkleTreeTypes.js +50 -0
- package/dist/trees/lmt/LinkedMerkleTreeTypes.js.map +1 -0
- package/dist/trees/sparse/InMemoryMerkleTreeStorage.d.ts +11 -0
- package/dist/trees/sparse/InMemoryMerkleTreeStorage.d.ts.map +1 -0
- package/dist/trees/sparse/InMemoryMerkleTreeStorage.js +13 -0
- package/dist/trees/sparse/InMemoryMerkleTreeStorage.js.map +1 -0
- package/dist/trees/sparse/MerkleTreeStore.d.ts +5 -0
- package/dist/trees/sparse/MerkleTreeStore.d.ts.map +1 -0
- package/dist/trees/sparse/MerkleTreeStore.js +2 -0
- package/dist/trees/sparse/MerkleTreeStore.js.map +1 -0
- package/dist/trees/sparse/MockAsyncMerkleStore.d.ts +9 -0
- package/dist/trees/sparse/MockAsyncMerkleStore.d.ts.map +1 -0
- package/dist/trees/sparse/MockAsyncMerkleStore.js +20 -0
- package/dist/trees/sparse/MockAsyncMerkleStore.js.map +1 -0
- package/dist/trees/sparse/RollupMerkleTree.d.ts +158 -0
- package/dist/trees/sparse/RollupMerkleTree.d.ts.map +1 -0
- package/dist/trees/sparse/RollupMerkleTree.js +330 -0
- package/dist/trees/sparse/RollupMerkleTree.js.map +1 -0
- package/dist/types.d.ts +62 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +14 -1
- package/dist/types.js.map +1 -0
- package/dist/union/union.d.ts +177 -0
- package/dist/union/union.d.ts.map +1 -0
- package/dist/union/union.js +35 -0
- package/dist/union/union.js.map +1 -0
- package/dist/utils.d.ts +57 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +153 -4
- package/dist/utils.js.map +1 -0
- package/dist/zkProgrammable/ProvableMethodExecutionContext.d.ts +4 -3
- package/dist/zkProgrammable/ProvableMethodExecutionContext.d.ts.map +1 -1
- package/dist/zkProgrammable/ProvableMethodExecutionContext.js +2 -3
- package/dist/zkProgrammable/ProvableMethodExecutionContext.js.map +1 -0
- package/dist/zkProgrammable/ZkProgrammable.d.ts +32 -11
- package/dist/zkProgrammable/ZkProgrammable.d.ts.map +1 -1
- package/dist/zkProgrammable/ZkProgrammable.js +36 -17
- package/dist/zkProgrammable/ZkProgrammable.js.map +1 -0
- package/dist/zkProgrammable/provableMethod.d.ts +7 -4
- package/dist/zkProgrammable/provableMethod.d.ts.map +1 -1
- package/dist/zkProgrammable/provableMethod.js +30 -14
- package/dist/zkProgrammable/provableMethod.js.map +1 -0
- package/jest.config.cjs +12 -1
- package/package.json +9 -7
- package/src/cache/CacheManifest.ts +57 -0
- package/src/cache/ProxyCache.ts +30 -0
- package/src/cache/RemoteCache.ts +9 -0
- package/src/cache/RemoteCacheCompiler.ts +131 -0
- package/src/compiling/AtomicCompileHelper.ts +71 -0
- package/src/compiling/CompilableModule.ts +6 -0
- package/src/compiling/CompileRegistry.ts +64 -0
- package/src/compiling/services/ChildVerificationKeyService.ts +26 -0
- package/src/config/ChildContainerCreatable.ts +5 -0
- package/src/config/ChildContainerProvider.ts +5 -0
- package/src/config/ConfigurableModule.ts +15 -2
- package/src/config/ModuleContainer.ts +286 -58
- package/src/config/Startable.ts +3 -0
- package/src/config/injectAlias.ts +70 -0
- package/src/dependencyFactory/DependencyFactory.ts +34 -109
- package/src/dummyVerificationKey.ts +10 -0
- package/src/events/EventEmitter.ts +61 -0
- package/src/events/EventEmitterProxy.ts +81 -0
- package/src/events/EventEmittingComponent.ts +11 -0
- package/src/events/ReplayingSingleUseEventEmitter.ts +42 -0
- package/src/index.ts +27 -2
- package/src/log.ts +145 -0
- package/src/trees/lmt/AbstractLinkedMerkleTree.ts +102 -0
- package/src/trees/lmt/InMemoryLinkedLeafStore.ts +42 -0
- package/src/trees/lmt/LinkedLeafStore.ts +13 -0
- package/src/trees/lmt/LinkedMerkleTree.ts +335 -0
- package/src/trees/lmt/LinkedMerkleTreeCircuitOps.ts +188 -0
- package/src/trees/lmt/LinkedMerkleTreeTypes.ts +53 -0
- package/src/trees/sparse/InMemoryMerkleTreeStorage.ts +17 -0
- package/src/trees/sparse/MerkleTreeStore.ts +5 -0
- package/src/trees/sparse/MockAsyncMerkleStore.ts +30 -0
- package/src/trees/sparse/RollupMerkleTree.ts +512 -0
- package/src/types.ts +53 -2
- package/src/utils.ts +281 -5
- package/src/zkProgrammable/ProvableMethodExecutionContext.ts +6 -6
- package/src/zkProgrammable/ZkProgrammable.ts +90 -35
- package/src/zkProgrammable/provableMethod.ts +50 -23
- package/test/config/ContainerEvents.test.ts +65 -0
- package/test/config/ModuleContainer.test.ts +146 -15
- package/test/config/injectAlias.test.ts +28 -0
- package/test/trees/LinkedMerkleTree.test.ts +124 -0
- package/test/trees/LinkedMerkleTreeCircuitOps.test.ts +147 -0
- package/test/trees/MerkleTree.test.ts +251 -0
- package/test/tsconfig.json +5 -2
- package/test/zkProgrammable/ZkProgrammable.test.ts +145 -119
- package/tsconfig.json +1 -1
- package/LICENSE.md +0 -201
- package/tsconfig.test.json +0 -9
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { Bool, Field, Poseidon, Provable, Struct } from "o1js";
|
|
2
|
+
import { range } from "../utils";
|
|
3
|
+
import { InMemoryMerkleTreeStorage } from "./InMemoryMerkleTreeStorage";
|
|
4
|
+
class StructTemplate extends Struct({
|
|
5
|
+
path: Provable.Array(Field, 0),
|
|
6
|
+
isLeft: Provable.Array(Bool, 0),
|
|
7
|
+
}) {
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A [Merkle Tree](https://en.wikipedia.org/wiki/Merkle_tree) is a binary tree in
|
|
11
|
+
* which every leaf is the cryptography hash of a piece of data,
|
|
12
|
+
* and every node is the hash of the concatenation of its two child nodes.
|
|
13
|
+
*
|
|
14
|
+
* A Merkle Tree allows developers to easily and securely verify
|
|
15
|
+
* the integrity of large amounts of data.
|
|
16
|
+
*
|
|
17
|
+
* Take a look at our [documentation](https://docs.minaprotocol.com/en/zkapps)
|
|
18
|
+
* on how to use Merkle Trees in combination with zkApps and
|
|
19
|
+
* zero knowledge programming!
|
|
20
|
+
*
|
|
21
|
+
* Levels are indexed from leaves (level 0) to root (level N - 1).
|
|
22
|
+
*
|
|
23
|
+
* This function takes a height as argument and returns a class
|
|
24
|
+
* that implements a merkletree with that specified height.
|
|
25
|
+
*
|
|
26
|
+
* It also holds the Witness class under tree.WITNESS
|
|
27
|
+
*/
|
|
28
|
+
export function createMerkleTree(height) {
|
|
29
|
+
var _a;
|
|
30
|
+
/**
|
|
31
|
+
* The {@link BaseMerkleWitness} class defines a circuit-compatible base class
|
|
32
|
+
* for [Merkle Witness'](https://computersciencewiki.org/index.php/Merkle_proof).
|
|
33
|
+
*/
|
|
34
|
+
class RollupMerkleWitness extends Struct({
|
|
35
|
+
path: Provable.Array(Field, height - 1),
|
|
36
|
+
isLeft: Provable.Array(Bool, height - 1),
|
|
37
|
+
}) {
|
|
38
|
+
height() {
|
|
39
|
+
return RollupMerkleWitness.height;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Calculates a root depending on the leaf value.
|
|
43
|
+
* @param leaf Value of the leaf node that belongs to this Witness.
|
|
44
|
+
* @returns The calculated root.
|
|
45
|
+
*/
|
|
46
|
+
calculateRoot(leaf) {
|
|
47
|
+
let hash = leaf;
|
|
48
|
+
const n = this.height();
|
|
49
|
+
for (let index = 1; index < n; ++index) {
|
|
50
|
+
const isLeft = this.isLeft[index - 1];
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
52
|
+
const [left, right] = maybeSwap(isLeft, hash, this.path[index - 1]);
|
|
53
|
+
hash = Poseidon.hash([left, right]);
|
|
54
|
+
}
|
|
55
|
+
return hash;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Calculates the index of the leaf node that belongs to this Witness.
|
|
59
|
+
* @returns Index of the leaf.
|
|
60
|
+
*/
|
|
61
|
+
calculateIndex() {
|
|
62
|
+
let powerOfTwo = Field(1);
|
|
63
|
+
let index = Field(0);
|
|
64
|
+
const n = this.height();
|
|
65
|
+
for (let i = 1; i < n; ++i) {
|
|
66
|
+
index = Provable.if(this.isLeft[i - 1], index, index.add(powerOfTwo));
|
|
67
|
+
powerOfTwo = powerOfTwo.mul(2);
|
|
68
|
+
}
|
|
69
|
+
return index;
|
|
70
|
+
}
|
|
71
|
+
checkMembership(root, key, value) {
|
|
72
|
+
const calculatedRoot = this.calculateRoot(value);
|
|
73
|
+
const calculatedKey = this.calculateIndex();
|
|
74
|
+
// We don't have to range-check the key, because if it would be greater
|
|
75
|
+
// than leafCount, it would not match the computedKey
|
|
76
|
+
key.assertEquals(calculatedKey, "Keys of MerkleWitness does not match");
|
|
77
|
+
return root.equals(calculatedRoot);
|
|
78
|
+
}
|
|
79
|
+
checkMembershipGetRoots(root, key, value) {
|
|
80
|
+
const calculatedRoot = this.calculateRoot(value);
|
|
81
|
+
const calculatedKey = this.calculateIndex();
|
|
82
|
+
key.assertEquals(calculatedKey, "Keys of MerkleWitness does not match");
|
|
83
|
+
return [root.equals(calculatedRoot), root, calculatedRoot];
|
|
84
|
+
}
|
|
85
|
+
toShortenedEntries() {
|
|
86
|
+
return range(0, 5)
|
|
87
|
+
.concat(range(this.height() - 4, this.height()))
|
|
88
|
+
.map((index) => [
|
|
89
|
+
this.path[index].toString(),
|
|
90
|
+
this.isLeft[index].toString(),
|
|
91
|
+
].toString());
|
|
92
|
+
}
|
|
93
|
+
static dummy() {
|
|
94
|
+
return new RollupMerkleWitness({
|
|
95
|
+
isLeft: Array(height - 1).fill(Bool(true)),
|
|
96
|
+
path: Array(height - 1).fill(Field(0)),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
RollupMerkleWitness.height = height;
|
|
101
|
+
return _a = class AbstractRollupMerkleTree {
|
|
102
|
+
static get leafCount() {
|
|
103
|
+
return 2n ** BigInt(AbstractRollupMerkleTree.HEIGHT - 1);
|
|
104
|
+
}
|
|
105
|
+
constructor(store) {
|
|
106
|
+
this.store = store;
|
|
107
|
+
this.zeroes = [0n];
|
|
108
|
+
for (let index = 1; index < AbstractRollupMerkleTree.HEIGHT; index += 1) {
|
|
109
|
+
const previousLevel = Field(this.zeroes[index - 1]);
|
|
110
|
+
this.zeroes.push(Poseidon.hash([previousLevel, previousLevel]).toBigInt());
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
assertIndexRange(index) {
|
|
114
|
+
if (index > this.leafCount) {
|
|
115
|
+
throw new Error("Index greater than maximum leaf number");
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Returns a node which lives at a given index and level.
|
|
120
|
+
* @param level Level of the node.
|
|
121
|
+
* @param index Index of the node.
|
|
122
|
+
* @returns The data of the node.
|
|
123
|
+
*/
|
|
124
|
+
getNode(level, index) {
|
|
125
|
+
this.assertIndexRange(index);
|
|
126
|
+
return Field(this.store.getNode(index, level) ?? this.zeroes[level]);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Returns the root of the [Merkle Tree](https://en.wikipedia.org/wiki/Merkle_tree).
|
|
130
|
+
* @returns The root of the Merkle Tree.
|
|
131
|
+
*/
|
|
132
|
+
getRoot() {
|
|
133
|
+
return this.getNode(AbstractRollupMerkleTree.HEIGHT - 1, 0n).toConstant();
|
|
134
|
+
}
|
|
135
|
+
// private in interface
|
|
136
|
+
setNode(level, index, value) {
|
|
137
|
+
this.store.setNode(index, level, value.toBigInt());
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Sets the value of a leaf node at a given index to a given value.
|
|
141
|
+
* @param index Position of the leaf node.
|
|
142
|
+
* @param leaf New value.
|
|
143
|
+
*/
|
|
144
|
+
setLeaf(index, leaf) {
|
|
145
|
+
this.assertIndexRange(index);
|
|
146
|
+
this.setNode(0, index, leaf);
|
|
147
|
+
let currentIndex = index;
|
|
148
|
+
for (let level = 1; level < AbstractRollupMerkleTree.HEIGHT; level += 1) {
|
|
149
|
+
currentIndex /= 2n;
|
|
150
|
+
const left = this.getNode(level - 1, currentIndex * 2n);
|
|
151
|
+
const right = this.getNode(level - 1, currentIndex * 2n + 1n);
|
|
152
|
+
this.setNode(level, currentIndex, Poseidon.hash([left, right]));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Returns the witness (also known as
|
|
157
|
+
* [Merkle Proof or Merkle Witness](https://computersciencewiki.org/index.php/Merkle_proof))
|
|
158
|
+
* for the leaf at the given index.
|
|
159
|
+
* @param index Position of the leaf node.
|
|
160
|
+
* @returns The witness that belongs to the leaf.
|
|
161
|
+
*/
|
|
162
|
+
getWitness(index) {
|
|
163
|
+
this.assertIndexRange(index);
|
|
164
|
+
const path = [];
|
|
165
|
+
const isLefts = [];
|
|
166
|
+
let currentIndex = index;
|
|
167
|
+
for (let level = 0; level < AbstractRollupMerkleTree.HEIGHT - 1; level += 1) {
|
|
168
|
+
const isLeft = currentIndex % 2n === 0n;
|
|
169
|
+
const sibling = this.getNode(level, isLeft ? currentIndex + 1n : currentIndex - 1n);
|
|
170
|
+
isLefts.push(Bool(isLeft));
|
|
171
|
+
path.push(sibling);
|
|
172
|
+
currentIndex /= 2n;
|
|
173
|
+
}
|
|
174
|
+
return new RollupMerkleWitness({
|
|
175
|
+
isLeft: isLefts,
|
|
176
|
+
path,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
// TODO: should this take an optional offset? should it fail if the array is too long?
|
|
180
|
+
/**
|
|
181
|
+
* Fills all leaves of the tree.
|
|
182
|
+
* @param leaves Values to fill the leaves with.
|
|
183
|
+
*/
|
|
184
|
+
fill(leaves) {
|
|
185
|
+
leaves.forEach((value, index) => {
|
|
186
|
+
this.setLeaf(BigInt(index), value);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Returns the amount of leaf nodes.
|
|
191
|
+
* @returns Amount of leaf nodes.
|
|
192
|
+
*/
|
|
193
|
+
get leafCount() {
|
|
194
|
+
return AbstractRollupMerkleTree.leafCount;
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
_a.HEIGHT = height,
|
|
198
|
+
_a.EMPTY_ROOT = new _a(new InMemoryMerkleTreeStorage())
|
|
199
|
+
.getRoot()
|
|
200
|
+
.toBigInt(),
|
|
201
|
+
_a.WITNESS = RollupMerkleWitness,
|
|
202
|
+
_a;
|
|
203
|
+
}
|
|
204
|
+
export class RollupMerkleTree extends createMerkleTree(256) {
|
|
205
|
+
}
|
|
206
|
+
export class RollupMerkleTreeWitness extends RollupMerkleTree.WITNESS {
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* More efficient version of `maybeSwapBad` which
|
|
210
|
+
* reuses an intermediate variable
|
|
211
|
+
*/
|
|
212
|
+
function maybeSwap(b, x, y) {
|
|
213
|
+
const m = b.toField().mul(x.sub(y)); // b*(x - y)
|
|
214
|
+
const x1 = y.add(m); // y + b*(x - y)
|
|
215
|
+
const y2 = x.sub(m); // x - b*(x - y) = x + b*(y - x)
|
|
216
|
+
return [x1, y2];
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=RollupMerkleTree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RollupMerkleTree.js","sourceRoot":"","sources":["../../src/trees/RollupMerkleTree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE/D,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAIjC,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAExE,MAAM,cAAe,SAAQ,MAAM,CAAC;IAClC,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;IAC9B,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;CAChC,CAAC;CAAG;AAqFL;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,gBAAgB,CAAC,MA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AO,gBAAiB,SAAQ,gBAAgB,CAAC,GAAG,CAAC;CAAG;AAC9D,MAAM,OAAO,uBAAwB,SAAQ,gBAAgB,CAAC,OAAO;CAAG;AAExE;;;GAGG;AACH,SAAS,SAAS,CAAC,CAAO,EAAE,CAAQ,EAAE,CAAQ;IAC5C,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY;IACjD,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,gBAAgB;IACrC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,gCAAgC;IACrD,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MerkleTreeStore } from "./MerkleTreeStore";
|
|
2
|
+
import { InMemoryMerkleTreeStorage } from "./InMemoryMerkleTreeStorage";
|
|
3
|
+
/**
|
|
4
|
+
* A MemoryMerkleTreeStore that, if falls back to a parent store if it
|
|
5
|
+
* has no data
|
|
6
|
+
*/
|
|
7
|
+
export declare class VirtualMerkleTreeStore extends InMemoryMerkleTreeStorage {
|
|
8
|
+
private readonly parent;
|
|
9
|
+
constructor(parent: MerkleTreeStore);
|
|
10
|
+
getNode(key: bigint, level: number): bigint | undefined;
|
|
11
|
+
setNode(key: bigint, level: number, value: bigint): void;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=VirtualMerkleTreeStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VirtualMerkleTreeStore.d.ts","sourceRoot":"","sources":["../../src/trees/VirtualMerkleTreeStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAExE;;;GAGG;AACH,qBAAa,sBAAuB,SAAQ,yBAAyB;IAChD,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,eAAe;IAIpD,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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { InMemoryMerkleTreeStorage } from "./InMemoryMerkleTreeStorage";
|
|
2
|
+
/**
|
|
3
|
+
* A MemoryMerkleTreeStore that, if falls back to a parent store if it
|
|
4
|
+
* has no data
|
|
5
|
+
*/
|
|
6
|
+
export class VirtualMerkleTreeStore extends InMemoryMerkleTreeStorage {
|
|
7
|
+
constructor(parent) {
|
|
8
|
+
super();
|
|
9
|
+
this.parent = parent;
|
|
10
|
+
}
|
|
11
|
+
getNode(key, level) {
|
|
12
|
+
return super.getNode(key, level) ?? this.parent.getNode(key, level);
|
|
13
|
+
}
|
|
14
|
+
setNode(key, level, value) {
|
|
15
|
+
super.setNode(key, level, value);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=VirtualMerkleTreeStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VirtualMerkleTreeStore.js","sourceRoot":"","sources":["../../src/trees/VirtualMerkleTreeStore.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAExE;;;GAGG;AACH,MAAM,OAAO,sBAAuB,SAAQ,yBAAyB;IACnE,YAAoC,MAAuB;QACzD,KAAK,EAAE,CAAC;QAD0B,WAAM,GAAN,MAAM,CAAiB;IAE3D,CAAC;IAEM,OAAO,CAAC,GAAW,EAAE,KAAa;QACvC,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACtE,CAAC;IAEM,OAAO,CAAC,GAAW,EAAE,KAAa,EAAE,KAAa;QACtD,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACnC,CAAC;CACF"}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { Bool, Field } from "o1js";
|
|
2
|
+
import { RollupMerkleTree } from "../sparse/RollupMerkleTree";
|
|
3
|
+
import { TypedClass } from "../../types";
|
|
4
|
+
import { MerkleTreeStore } from "../sparse/MerkleTreeStore";
|
|
5
|
+
import { LinkedLeafStore } from "./LinkedLeafStore";
|
|
6
|
+
import { LinkedLeafStruct } from "./LinkedMerkleTreeTypes";
|
|
7
|
+
declare const RollupMerkleTreeWitness_base: TypedClass<import("../sparse/RollupMerkleTree").AbstractMerkleWitness> & typeof import("../sparse/RollupMerkleTree").StructTemplate & {
|
|
8
|
+
dummy: () => import("../sparse/RollupMerkleTree").AbstractMerkleWitness;
|
|
9
|
+
};
|
|
10
|
+
declare class RollupMerkleTreeWitness extends RollupMerkleTreeWitness_base {
|
|
11
|
+
}
|
|
12
|
+
type LinkedMerkleWitnessValue = {
|
|
13
|
+
leaf: LinkedLeafStruct;
|
|
14
|
+
merkleWitness: RollupMerkleTreeWitness;
|
|
15
|
+
checkMembership(root: Field, path: Field, value: Field): Bool;
|
|
16
|
+
};
|
|
17
|
+
declare const LinkedMerkleWitnessTemplate_base: (new (value: {
|
|
18
|
+
leaf: LinkedLeafStruct;
|
|
19
|
+
merkleWitness: RollupMerkleTreeWitness;
|
|
20
|
+
}) => {
|
|
21
|
+
leaf: LinkedLeafStruct;
|
|
22
|
+
merkleWitness: RollupMerkleTreeWitness;
|
|
23
|
+
}) & {
|
|
24
|
+
_isStruct: true;
|
|
25
|
+
} & Omit<import("o1js/dist/node/lib/provable/types/provable-intf").Provable<{
|
|
26
|
+
leaf: LinkedLeafStruct;
|
|
27
|
+
merkleWitness: RollupMerkleTreeWitness;
|
|
28
|
+
}, {
|
|
29
|
+
leaf: {
|
|
30
|
+
value: bigint;
|
|
31
|
+
path: bigint;
|
|
32
|
+
nextPath: bigint;
|
|
33
|
+
};
|
|
34
|
+
merkleWitness: {
|
|
35
|
+
path: bigint[];
|
|
36
|
+
isLeft: boolean[];
|
|
37
|
+
};
|
|
38
|
+
}>, "fromFields"> & {
|
|
39
|
+
fromFields: (fields: import("o1js/dist/node/lib/provable/field").Field[]) => {
|
|
40
|
+
leaf: LinkedLeafStruct;
|
|
41
|
+
merkleWitness: RollupMerkleTreeWitness;
|
|
42
|
+
};
|
|
43
|
+
} & {
|
|
44
|
+
fromValue: (value: {
|
|
45
|
+
leaf: LinkedLeafStruct | {
|
|
46
|
+
value: string | number | bigint | import("o1js/dist/node/lib/provable/field").Field;
|
|
47
|
+
path: string | number | bigint | import("o1js/dist/node/lib/provable/field").Field;
|
|
48
|
+
nextPath: string | number | bigint | import("o1js/dist/node/lib/provable/field").Field;
|
|
49
|
+
};
|
|
50
|
+
merkleWitness: {
|
|
51
|
+
path: import("o1js/dist/node/lib/provable/field").Field[] | bigint[];
|
|
52
|
+
isLeft: import("o1js/dist/node/lib/provable/bool").Bool[] | boolean[];
|
|
53
|
+
} | RollupMerkleTreeWitness;
|
|
54
|
+
}) => {
|
|
55
|
+
leaf: LinkedLeafStruct;
|
|
56
|
+
merkleWitness: RollupMerkleTreeWitness;
|
|
57
|
+
};
|
|
58
|
+
toInput: (x: {
|
|
59
|
+
leaf: LinkedLeafStruct;
|
|
60
|
+
merkleWitness: RollupMerkleTreeWitness;
|
|
61
|
+
}) => {
|
|
62
|
+
fields?: import("o1js/dist/node/lib/provable/field").Field[] | undefined;
|
|
63
|
+
packed?: [import("o1js/dist/node/lib/provable/field").Field, number][] | undefined;
|
|
64
|
+
};
|
|
65
|
+
toJSON: (x: {
|
|
66
|
+
leaf: LinkedLeafStruct;
|
|
67
|
+
merkleWitness: RollupMerkleTreeWitness;
|
|
68
|
+
}) => {
|
|
69
|
+
leaf: {
|
|
70
|
+
value: string;
|
|
71
|
+
path: string;
|
|
72
|
+
nextPath: string;
|
|
73
|
+
};
|
|
74
|
+
merkleWitness: {
|
|
75
|
+
path: string[];
|
|
76
|
+
isLeft: boolean[];
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
fromJSON: (x: {
|
|
80
|
+
leaf: {
|
|
81
|
+
value: string;
|
|
82
|
+
path: string;
|
|
83
|
+
nextPath: string;
|
|
84
|
+
};
|
|
85
|
+
merkleWitness: {
|
|
86
|
+
path: string[];
|
|
87
|
+
isLeft: boolean[];
|
|
88
|
+
};
|
|
89
|
+
}) => {
|
|
90
|
+
leaf: LinkedLeafStruct;
|
|
91
|
+
merkleWitness: RollupMerkleTreeWitness;
|
|
92
|
+
};
|
|
93
|
+
empty: () => {
|
|
94
|
+
leaf: LinkedLeafStruct;
|
|
95
|
+
merkleWitness: RollupMerkleTreeWitness;
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
declare class LinkedMerkleWitnessTemplate extends LinkedMerkleWitnessTemplate_base {
|
|
99
|
+
checkMembership(root: Field, path: Field, value: Field): Bool;
|
|
100
|
+
}
|
|
101
|
+
type LinkedOperationWitnessValue = {
|
|
102
|
+
leafPrevious: LinkedMerkleWitnessValue;
|
|
103
|
+
leafCurrent: LinkedMerkleWitnessValue;
|
|
104
|
+
};
|
|
105
|
+
declare const LinkedOperationWitnessTemplate_base: (new (value: {
|
|
106
|
+
leafPrevious: LinkedMerkleWitnessTemplate;
|
|
107
|
+
leafCurrent: LinkedMerkleWitnessTemplate;
|
|
108
|
+
}) => {
|
|
109
|
+
leafPrevious: LinkedMerkleWitnessTemplate;
|
|
110
|
+
leafCurrent: LinkedMerkleWitnessTemplate;
|
|
111
|
+
}) & {
|
|
112
|
+
_isStruct: true;
|
|
113
|
+
} & Omit<import("o1js/dist/node/lib/provable/types/provable-intf").Provable<{
|
|
114
|
+
leafPrevious: LinkedMerkleWitnessTemplate;
|
|
115
|
+
leafCurrent: LinkedMerkleWitnessTemplate;
|
|
116
|
+
}, {
|
|
117
|
+
leafPrevious: {
|
|
118
|
+
leaf: {
|
|
119
|
+
value: bigint;
|
|
120
|
+
path: bigint;
|
|
121
|
+
nextPath: bigint;
|
|
122
|
+
};
|
|
123
|
+
merkleWitness: {
|
|
124
|
+
path: bigint[];
|
|
125
|
+
isLeft: boolean[];
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
leafCurrent: {
|
|
129
|
+
leaf: {
|
|
130
|
+
value: bigint;
|
|
131
|
+
path: bigint;
|
|
132
|
+
nextPath: bigint;
|
|
133
|
+
};
|
|
134
|
+
merkleWitness: {
|
|
135
|
+
path: bigint[];
|
|
136
|
+
isLeft: boolean[];
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
}>, "fromFields"> & {
|
|
140
|
+
fromFields: (fields: import("o1js/dist/node/lib/provable/field").Field[]) => {
|
|
141
|
+
leafPrevious: LinkedMerkleWitnessTemplate;
|
|
142
|
+
leafCurrent: LinkedMerkleWitnessTemplate;
|
|
143
|
+
};
|
|
144
|
+
} & {
|
|
145
|
+
fromValue: (value: {
|
|
146
|
+
leafPrevious: LinkedMerkleWitnessTemplate | {
|
|
147
|
+
leaf: LinkedLeafStruct | {
|
|
148
|
+
value: string | number | bigint | import("o1js/dist/node/lib/provable/field").Field;
|
|
149
|
+
path: string | number | bigint | import("o1js/dist/node/lib/provable/field").Field;
|
|
150
|
+
nextPath: string | number | bigint | import("o1js/dist/node/lib/provable/field").Field;
|
|
151
|
+
};
|
|
152
|
+
merkleWitness: {
|
|
153
|
+
path: import("o1js/dist/node/lib/provable/field").Field[] | bigint[];
|
|
154
|
+
isLeft: import("o1js/dist/node/lib/provable/bool").Bool[] | boolean[];
|
|
155
|
+
} | RollupMerkleTreeWitness;
|
|
156
|
+
};
|
|
157
|
+
leafCurrent: LinkedMerkleWitnessTemplate | {
|
|
158
|
+
leaf: LinkedLeafStruct | {
|
|
159
|
+
value: string | number | bigint | import("o1js/dist/node/lib/provable/field").Field;
|
|
160
|
+
path: string | number | bigint | import("o1js/dist/node/lib/provable/field").Field;
|
|
161
|
+
nextPath: string | number | bigint | import("o1js/dist/node/lib/provable/field").Field;
|
|
162
|
+
};
|
|
163
|
+
merkleWitness: {
|
|
164
|
+
path: import("o1js/dist/node/lib/provable/field").Field[] | bigint[];
|
|
165
|
+
isLeft: import("o1js/dist/node/lib/provable/bool").Bool[] | boolean[];
|
|
166
|
+
} | RollupMerkleTreeWitness;
|
|
167
|
+
};
|
|
168
|
+
}) => {
|
|
169
|
+
leafPrevious: LinkedMerkleWitnessTemplate;
|
|
170
|
+
leafCurrent: LinkedMerkleWitnessTemplate;
|
|
171
|
+
};
|
|
172
|
+
toInput: (x: {
|
|
173
|
+
leafPrevious: LinkedMerkleWitnessTemplate;
|
|
174
|
+
leafCurrent: LinkedMerkleWitnessTemplate;
|
|
175
|
+
}) => {
|
|
176
|
+
fields?: import("o1js/dist/node/lib/provable/field").Field[] | undefined;
|
|
177
|
+
packed?: [import("o1js/dist/node/lib/provable/field").Field, number][] | undefined;
|
|
178
|
+
};
|
|
179
|
+
toJSON: (x: {
|
|
180
|
+
leafPrevious: LinkedMerkleWitnessTemplate;
|
|
181
|
+
leafCurrent: LinkedMerkleWitnessTemplate;
|
|
182
|
+
}) => {
|
|
183
|
+
leafPrevious: {
|
|
184
|
+
leaf: {
|
|
185
|
+
value: string;
|
|
186
|
+
path: string;
|
|
187
|
+
nextPath: string;
|
|
188
|
+
};
|
|
189
|
+
merkleWitness: {
|
|
190
|
+
path: string[];
|
|
191
|
+
isLeft: boolean[];
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
leafCurrent: {
|
|
195
|
+
leaf: {
|
|
196
|
+
value: string;
|
|
197
|
+
path: string;
|
|
198
|
+
nextPath: string;
|
|
199
|
+
};
|
|
200
|
+
merkleWitness: {
|
|
201
|
+
path: string[];
|
|
202
|
+
isLeft: boolean[];
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
fromJSON: (x: {
|
|
207
|
+
leafPrevious: {
|
|
208
|
+
leaf: {
|
|
209
|
+
value: string;
|
|
210
|
+
path: string;
|
|
211
|
+
nextPath: string;
|
|
212
|
+
};
|
|
213
|
+
merkleWitness: {
|
|
214
|
+
path: string[];
|
|
215
|
+
isLeft: boolean[];
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
leafCurrent: {
|
|
219
|
+
leaf: {
|
|
220
|
+
value: string;
|
|
221
|
+
path: string;
|
|
222
|
+
nextPath: string;
|
|
223
|
+
};
|
|
224
|
+
merkleWitness: {
|
|
225
|
+
path: string[];
|
|
226
|
+
isLeft: boolean[];
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
}) => {
|
|
230
|
+
leafPrevious: LinkedMerkleWitnessTemplate;
|
|
231
|
+
leafCurrent: LinkedMerkleWitnessTemplate;
|
|
232
|
+
};
|
|
233
|
+
empty: () => {
|
|
234
|
+
leafPrevious: LinkedMerkleWitnessTemplate;
|
|
235
|
+
leafCurrent: LinkedMerkleWitnessTemplate;
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
declare class LinkedOperationWitnessTemplate extends LinkedOperationWitnessTemplate_base {
|
|
239
|
+
}
|
|
240
|
+
export interface AbstractLinkedMerkleTree {
|
|
241
|
+
leafStore: LinkedLeafStore;
|
|
242
|
+
tree: RollupMerkleTree;
|
|
243
|
+
/**
|
|
244
|
+
* Returns the root of the [Merkle Tree](https://en.wikipedia.org/wiki/Merkle_tree).
|
|
245
|
+
* @returns The root of the Merkle Tree.
|
|
246
|
+
*/
|
|
247
|
+
getRoot(): Field;
|
|
248
|
+
/**
|
|
249
|
+
* Sets the value of a leaf node at a given index to a given value.
|
|
250
|
+
* @param path of the leaf node.
|
|
251
|
+
* @param value New value.
|
|
252
|
+
*/
|
|
253
|
+
setLeaf(path: bigint, value?: bigint): LinkedOperationWitnessValue;
|
|
254
|
+
setLeaves(batch: {
|
|
255
|
+
path: bigint;
|
|
256
|
+
value: bigint;
|
|
257
|
+
}[]): void;
|
|
258
|
+
/**
|
|
259
|
+
* Returns a leaf which lives at a given path.
|
|
260
|
+
* Errors otherwise.
|
|
261
|
+
* @param path Index of the node.
|
|
262
|
+
* @returns The data of the leaf.
|
|
263
|
+
*/
|
|
264
|
+
getLeaf(path: bigint): LinkedLeafStruct | undefined;
|
|
265
|
+
/**
|
|
266
|
+
* Returns the witness (also known as
|
|
267
|
+
* [Merkle Proof or Merkle Witness](https://computersciencewiki.org/index.php/Merkle_proof))
|
|
268
|
+
* for the leaf at the given path.
|
|
269
|
+
* @param path Position of the leaf node.
|
|
270
|
+
* @returns The witness that belongs to the leaf.
|
|
271
|
+
*/
|
|
272
|
+
getReadWitness(path: bigint): LinkedMerkleWitnessValue;
|
|
273
|
+
}
|
|
274
|
+
export interface AbstractLinkedMerkleTreeClass {
|
|
275
|
+
new (store: MerkleTreeStore, leafStore: LinkedLeafStore): AbstractLinkedMerkleTree;
|
|
276
|
+
WITNESS: typeof LinkedOperationWitnessTemplate & {
|
|
277
|
+
fromReadWitness(readWitness: LinkedMerkleWitnessTemplate): LinkedOperationWitnessTemplate;
|
|
278
|
+
};
|
|
279
|
+
READ_WITNESS: typeof LinkedMerkleWitnessTemplate & TypedClass<{
|
|
280
|
+
checkMembership(root: Field, path: Field, value: Field): Bool;
|
|
281
|
+
}>;
|
|
282
|
+
HEIGHT: number;
|
|
283
|
+
EMPTY_ROOT: Field;
|
|
284
|
+
dummyWitness(): LinkedOperationWitnessValue;
|
|
285
|
+
dummyReadWitness(): LinkedMerkleWitnessValue;
|
|
286
|
+
}
|
|
287
|
+
export {};
|
|
288
|
+
//# sourceMappingURL=AbstractLinkedMerkleTree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbstractLinkedMer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AAE,eAAe,CAAC;IAE3B,IAAI,EAAE,gBAAgB,CAAC;IAEvB;;;OAGG;IACH,OAAO,IAAI,KAAK,CAAC;IAEjB;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,2BAA2B,CAAC;IAEnE,SAAS,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,GAAG,IAAI,CAAC;IAE1D;;;;;OAKG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAAC;IAEpD;;;;;;OAMG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,wBAAwB,CAAC;CACxD;AAED,MAAM,WAAW,6BAA6B;IAC5C,KACE,KAAK,EAAE,eAAe,EACtB,SAAS,EAAE,eAAe,GACzB,wBAAwB,CAAC;IAE5B,OAAO,EAAE,OAAO,8BAA8B,GAAG;QAC/C,eAAe,CACb,WAAW,EAAE,2BAA2B,GACvC,8BAA8B,CAAC;KACnC,CAAC;IAEF,YAAY,EAAE,OAAO,2BAA2B,GAC9C,UAAU,CAAC;QACT,eAAe,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;KAC/D,CAAC,CAAC;IAEL,MAAM,EAAE,MAAM,CAAC;IAEf,UAAU,EAAE,KAAK,CAAC;IAElB,YAAY,IAAI,2BAA2B,CAAC;IAE5C,gBAAgB,IAAI,wBAAwB,CAAC;CAC9C"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Bool, Struct } from "o1js";
|
|
2
|
+
import { createMerkleTree } from "../sparse/RollupMerkleTree";
|
|
3
|
+
import { LinkedLeafStruct } from "./LinkedMerkleTreeTypes";
|
|
4
|
+
class RollupMerkleTreeWitness extends createMerkleTree(40).WITNESS {
|
|
5
|
+
}
|
|
6
|
+
// We use the RollupMerkleTreeWitness here, although we will actually implement
|
|
7
|
+
// the RollupMerkleTreeWitnessV2 defined below when instantiating the class.
|
|
8
|
+
class LinkedMerkleWitnessTemplate extends Struct({
|
|
9
|
+
leaf: LinkedLeafStruct,
|
|
10
|
+
merkleWitness: RollupMerkleTreeWitness,
|
|
11
|
+
}) {
|
|
12
|
+
checkMembership(root, path, value) {
|
|
13
|
+
// Mock implementation for typing
|
|
14
|
+
return Bool(true);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
class LinkedOperationWitnessTemplate extends Struct({
|
|
18
|
+
leafPrevious: LinkedMerkleWitnessTemplate,
|
|
19
|
+
leafCurrent: LinkedMerkleWitnessTemplate,
|
|
20
|
+
}) {
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=AbstractLinkedMerkleTree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbstractLinkedMerkleTree.js","sourceRoot":"","sources":["../../../src/trees/lmt/AbstractLinkedMerkleTree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAS,MAAM,EAAE,MAAM,MAAM,CAAC;AAE3C,OAAO,EAAE,gBAAgB,EAAoB,MAAM,4BAA4B,CAAC;AAKhF,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,MAAM,uBAAwB,SAAQ,gBAAgB,CAAC,EAAE,CAAC,CAAC,OAAO;CAAG;AAQrE,+EAA+E;AAC/E,4EAA4E;AAC5E,MAAM,2BAA4B,SAAQ,MAAM,CAAC;IAC/C,IAAI,EAAE,gBAAgB;IACtB,aAAa,EAAE,uBAAuB;CACvC,CAAC;IACO,eAAe,CAAC,IAAW,EAAE,IAAW,EAAE,KAAY;QAC3D,iCAAiC;QACjC,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;CACF;AAOD,MAAM,8BAA+B,SAAQ,MAAM,CAAC;IAClD,YAAY,EAAE,2BAA2B;IACzC,WAAW,EAAE,2BAA2B;CACzC,CAAC;CAAG"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { LinkedLeafStore, LinkedLeaf } from "./LinkedLeafStore";
|
|
2
|
+
export declare class InMemoryLinkedLeafStore implements LinkedLeafStore {
|
|
3
|
+
leaves: {
|
|
4
|
+
[key: string]: {
|
|
5
|
+
leaf: LinkedLeaf;
|
|
6
|
+
index: bigint;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
maximumIndex?: bigint;
|
|
10
|
+
getLeaf(path: bigint): {
|
|
11
|
+
leaf: LinkedLeaf;
|
|
12
|
+
index: bigint;
|
|
13
|
+
} | undefined;
|
|
14
|
+
setLeaf(index: bigint, value: LinkedLeaf): void;
|
|
15
|
+
getMaximumIndex(): bigint | undefined;
|
|
16
|
+
getPreviousLeaf(path: bigint): {
|
|
17
|
+
leaf: LinkedLeaf;
|
|
18
|
+
index: bigint;
|
|
19
|
+
} | undefined;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=InMemoryLinkedLeafStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InMemoryLinkedLeafStore.d.ts","sourceRoot":"","sources":["../../../src/trees/lmt/InMemoryLinkedLeafStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEhE,qBAAa,uBAAwB,YAAW,eAAe;IACtD,MAAM,EAAE;QACb,CAAC,GAAG,EAAE,MAAM,GAAG;YAAE,IAAI,EAAE,UAAU,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC;KACpD,CAAM;IAEA,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,OAAO,CACZ,IAAI,EAAE,MAAM,GACX;QAAE,IAAI,EAAE,UAAU,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS;IAI3C,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI;IAa/C,eAAe,IAAI,MAAM,GAAG,SAAS;IAKrC,eAAe,CACpB,IAAI,EAAE,MAAM,GACX;QAAE,IAAI,EAAE,UAAU,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS;CAMnD"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export class InMemoryLinkedLeafStore {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.leaves = {};
|
|
4
|
+
}
|
|
5
|
+
getLeaf(path) {
|
|
6
|
+
return this.leaves[path.toString()];
|
|
7
|
+
}
|
|
8
|
+
setLeaf(index, value) {
|
|
9
|
+
const leaf = this.getLeaf(value.path);
|
|
10
|
+
if (leaf !== undefined && leaf?.index !== index) {
|
|
11
|
+
throw new Error("Cannot change index of existing leaf");
|
|
12
|
+
}
|
|
13
|
+
this.leaves[value.path.toString()] = { leaf: value, index: index };
|
|
14
|
+
if (index > (this.maximumIndex ?? -1)) {
|
|
15
|
+
this.maximumIndex = index;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
getMaximumIndex() {
|
|
19
|
+
return this.maximumIndex;
|
|
20
|
+
}
|
|
21
|
+
// This gets the leaf with the closest path.
|
|
22
|
+
getPreviousLeaf(path) {
|
|
23
|
+
return Object.values(this.leaves).find((storedLeaf) => storedLeaf.leaf.nextPath > path && storedLeaf.leaf.path < path);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=InMemoryLinkedLeafStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InMemoryLinkedLeafStore.js","sourceRoot":"","sources":["../../../src/trees/lmt/InMemoryLinkedLeafStore.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,uBAAuB;IAApC;QACS,WAAM,GAET,EAAE,CAAC;IAoCT,CAAC;IAhCQ,OAAO,CACZ,IAAY;QAEZ,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;IACtC,CAAC;IAEM,OAAO,CAAC,KAAa,EAAE,KAAiB;QAC7C,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAEtC,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,EAAE,KAAK,KAAK,KAAK,EAAE;YAC/C,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;SACzD;QAED,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;QACnE,IAAI,KAAK,GAAG,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,CAAC,CAAC,EAAE;YACrC,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;SAC3B;IACH,CAAC;IAEM,eAAe;QACpB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,4CAA4C;IACrC,eAAe,CACpB,IAAY;QAEZ,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CACpC,CAAC,UAAU,EAAE,EAAE,CACb,UAAU,CAAC,IAAI,CAAC,QAAQ,GAAG,IAAI,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CACjE,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { InMemoryLinkedLeafStore } from "./InMemoryLinkedLeafStore";
|
|
2
|
+
import { InMemoryMerkleTreeStorage } from "../sparse/InMemoryMerkleTreeStorage";
|
|
3
|
+
declare const InMemoryLinkedMerkleLeafStore_base: import("ts-mixer/dist/types/types").Class<any[], InMemoryLinkedLeafStore & InMemoryMerkleTreeStorage, typeof InMemoryLinkedLeafStore & typeof InMemoryMerkleTreeStorage>;
|
|
4
|
+
export declare class InMemoryLinkedMerkleLeafStore extends InMemoryLinkedMerkleLeafStore_base {
|
|
5
|
+
}
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=InMemoryLinkedMerkleLeafStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InMemoryLinkedMerkleLeafStore.d.ts","sourceRoot":"","sources":["../../../src/trees/lmt/InMemoryLinkedMerkleLeafStore.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAC;;AAEhF,qBAAa,6BAA8B,SAAQ,kCAGlD;CAAG"}
|