pyt-pos
v0.0.3
Published
A library to generate and verify pan-y-tomate Proof of Solvency
Downloads
5
Maintainers
Readme
pyt-pos
pyt-pos is a library to generate and verify pan-y-tomate Proof of Solvency.
The library contains the apis to generate a proof of solvency for each user and let them verify it.
npm install pyt-pos
import { Prover, UserVerifier } from 'pyt-pos';
import { MerkleSumTree } from 'pyt-merkle-sum-tree';
Prover
is a class that contains the core APIs to let CEXs generate Proof Of Solvency for each of its users.
The proof doesn't reveal any information such as the total balances of each user, the number of users and the total amount of liabilities of the exchange.
UserVerifier
is a class that contains the core APIs to let a user verify the proof that has been provided to them by the exchange.
MerkleSumTree
is a class that contains the core methods to create a Merkle Sum Tree from a csv file containing the username and balances of its users. More information about Merkle Sum Tree can be found at pyt-merkle-sum-tree.
APIs - Prover
# new Prover(tree: MerkleSumTree, assetsSum bigint, proverArtifacts SnarkProverArtifacts): Prover
import { Prover } from "pyt-pos"
import { MerkleSumTree } from "pyt-merkle-sum-tree"
const tree = new MerkleSumTree("test/entries/entry-65536-valid.csv")
const assetsSum = BigInt(4000000000)
const pathToWasm = './test/artifacts/valid/pyt-pos-16.wasm'
const pathToZkey = './test/artifacts/valid/pyt-pos-16_final.zkey'
const proverArtifacts = {
wasmFilePath: pathToWasm,
zkeyFilePath: pathToZkey
}
const prover = new Prover(tree, assetsSum, proverArtifacts)
Initializes a prover object. Takes as input an instance of the Merkle Sum Tree, the total assets owned by the exchange and the zkSNARK prover artifacts.
The available prover artifacts generated after a trusted-setup can be found in the pyt-circuits repository. For now, the trusted setup is only available for a merkle sum tree with 16 levels.
# generateProof(userIndex number): FullProof
Generates a proof of solvency for a specific user using a zkSNARK taking as input the index of the user in the Merkle Sum Tree.
const userIndex = 0
const proof = await prover.generateProofForUser(userIndex)
APIs - UserVerifier
# new UserVerifier(username: string, balance bigint, verificationKey JSON): UserVerifier
import { UserVerifier } from "pyt-pos"
const username = "OiMkdfHE"
const balance = BigInt(22404)
const verificationKey = require('./artifacts/valid/vkey.json');
const userVerifier = new UserVerifier(username, balance, verificationKey)
Initializes a user verifier object. Takes as input the username of the user, the balance of the user and the verification key.
The available verification key generated after a trusted-setup can be found in the pyt-circuits repository. For now, the verification key is only available for a merkle sum tree with 16 levels.
# verifyProof(proof: FullProof): boolean
Verifies the zk proof of solvency generated by the exchange for a specific user. Takes as input the proof
const bool = await userVerifier.verifyProof(proof)
The implementer should make sure that the public signals of the proof of solvency generated for a specific user match the expected values. These can be accessed from the proof object.
const rootHash = proof.rootHash // must match the root hash of the merkle sum tree published by the exchange
const assetsSum = proof.assetsSum // must match the total assets owned by the exchange as published by the exchange
Code Quality and Formatting
Run ESLint to analyze the code and catch bugs:
npm run lint
Run Prettier to check formatting rules and to fix them:
npm run format
Testing
npm run test