Observed since 20 Oct, 22:40 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
## Structuring datasets into Merkle Sum Trees
This is a Typescript (backend-friendly) library used to create Merkle Sum Trees where each node entry is username -> balance. The root of this tree contains the aggregated sum of all the node entries, thereby, representing the total assets/liabilities of a firm.
But coming to the point.
A merkle sum tree is a binary Merkle Tree with the following properties:
h(username, balance). The sum is equal to the balance itself, at the node level.h(left_child.hash, left_child.sum, right_child.hash, right_child.sum). The sum is therefore equal to the sum of the sum of it's children.merkleSumTree() is a Typescript implementation of a Merkle Sum Tree and it provides all the functions to construct the above mentioned modified Merkle Tree by just ingesting data from a csv file, picking up only the username -> balance.This diagram is a representation of a similar Merkle Sum Tree
$ npm i @0xagnish/zk-data-prep
import { MerkleSumTree } from '0xagnish/zk-data-prep';
const pathToCsv = 'test/entryPatterns/entry-16-valid.csv';
const tree = new MerkleSumTree(pathToCsv);
//constructs a tree using the given entries in the csv dataset
The entries contain the username parsed as BigInt. This transformation is needed in order to make the entries hashing friendly and later on operate with zkSNARKs.
const entries = tree.entries
// [
// Entry {
// _usernameToBigInt: 7440338505707899769n,
// _balance: 7534n,
// _username: 'gAdsIaKy'
// },
// Entry {
// _usernameToBigInt: 6008493982388733799n,
// _balance: 2060n,
// _username: 'SbuqOZGg'
// },
// ...
// ]
const root = tree.root
// {
// hash: 5256203632563331423195629050622063453704745190370457907459595269961493651429n,
// sum: 84359n
// }
Returns the index of an entry in the tree. If the entry does not exist in the tree, it returns -1.
const index = tree.indexOf("gAdsIaKy", BigInt(7534)) // 0
Creates a proof of membership for an entry identified by its index. The MerkleProof contains the path from the leaf to the root.
const proof = tree.createProof(0)
Verifies a proof and returns true or false. It verifies that a leaf is included in the tree and that the sum computed from the leaf to the root is equal to the total sum of the tree.
tree.verifyProof(proof)
To construct a Merkle Sum Tree with 262144 (2**18 leaves) it takes:
| Time taken | OS/Kernel | RAM |
|---|---|---|
| 108s | Ubuntu 22 LTS | 8 GB |
| 154s | Macbook Air M1 | 8 GB |
Download counts and popularity will appear here as the collector receives them.
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 22:40 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:07833825201c86af59c41ae2e295ff8109b5d26b44bfb18e7371da56fae96cbd