Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

a16z/zkp-merkle-airdrop-lib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Notice: This repository has been deprecated in favor of the monorepo found at a16z/zkdrops

Zk Merkle Airdrop Library

Self-contained repo for interacting with the zkp-merkle-airdrop-contracts. A browser usage example of this library can be found in zkp-merkle-airdrop-fe-ex.

Usage

Create MerkleTree from file (ex file)

import { MerkleTree } from 'zkp-merkle-airdrop-lib';

let merkleTreeStorageString = ...; // Load the file from network or local into a string
let mt = MerkleTree.createFromStorageString(merkleTreeStorageString);

Create MerkleTree from leaves

import { MerkleTree } from 'zkp-merkle-airdrop-lib';

let treeHeight = 2**13;
// Create an array of BigNumbers to enter as leaves
let leaves: BigNumber[] = new Array(treeHeight).fill(0).map(_ => randomBigNumber());
let mt = MerkleTree.createFromLeaves(leaves)

Export MerkleTree storage string

import { MerkleTree } from 'zkp-merkle-airdrop-lib';

let mt: MerkleTree = ...;
let storageString = mt.getStorageString();
fs.WriteFileSync("./file/path/text.txt', storageString);

Generate proof

import { MerkleTree, pedersenhashConcat, generateProofCallData } from 'zk-merkle-airdrop-lib';

let KEY = "0x00d8d681994b73f635532cc3f0a7e3f02e10d55a6e107e1bd374b1c23bead940";
let SEC = "0x00b87f2a60e72cc5c6f334833c56aaed80aef550b76bd94837a86070c10dd061";
let airdropToAddress = "0x0"; // Reciever address -- caller of PrivateAirdrop.collectAirdrop()

// Optional: Compute commitment
let commitment: BigInt = pedersenhashConcat(BigInt(KEY), BigInt(SEC));

// Load tree into string
let merkleTreeStorageString: string = ...;
// Load dep files into buffers
let wasmBuffer: Buffer = ...;
let zkeyBuffer: Buffer = ...;

// Create MerkleTree
let mt = MerkleTree.createFromStorageString(merkleTreeStorageString);

// Optional: Check leaf exists
if (!mt.leafExists(commitment)) {
    alert("Commitment does not exist as leaf in tree!);
}

// Compute proof -- long running operation
let proof = await generateProofCallData(mt, BigInt(key), BigInt(secret), airdropToAddress, wasmBuffer, zkeyBuffer);

Notes

  • Recommended installation is as a submodule, then npm install --save file:zkp-merkle-airdrop-lib
  • witness_calculator is copied from those generated by the circom library with a BigInt adjustment to work in the browser.
  • The circom/snarkjs dependencies rely on server only libraries (fs, stream, path, crypto, os), which will not exist in a browser environment. If webpacking, these must be ignored.

Cmds

  • Install: npm i
  • Build: npm run build

Disclaimer

These smart contracts are being provided as is. No guarantee, representation or warranty is being made, express or implied, as to the safety or correctness of the user interface or the smart contracts. They have not been audited and as such there can be no assurance they will work as intended, and users may experience delays, failures, errors, omissions or loss of transmitted information. In addition, any airdrop using these smart contracts should be conducted in accordance with applicable law. Nothing in this repo should be construed as investment advice or legal advice for any particular facts or circumstances and is not meant to replace competent counsel. It is strongly advised for you to contact a reputable attorney in your jurisdiction for any questions or concerns with respect thereto. a16z is not liable for any use of the foregoing and users should proceed with caution and use at their own risk. See a16z.com/disclosure for more info.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •