This project demonstrates a basic ZK-based MerkleTree use case. It comes with a circuit and smart contract, a test for that contract, and a script that test that contract.
Try running some of the following tasks:
The merkle tree circuit is circuits/merkle_tree/merkle_tree.circom
, and here's some related scripts:
cd circuits
// compile circom
circom ./merkle_tree/merkle_tree.circom --sym --wasm --r1cs -o ./build
// gen zkey
snarkjs plonk setup build/merkle_tree.r1cs build/pot16_final.ptau build/merkle_tree.zkey
// gen verifier sol
snarkjs zkey export solidityverifier build/merkle_tree.zkey ../contracts/Verifier.sol
The smart contract includes Verifier.sol
which generated by snarkjs, and ZKMerkleTree.sol
to do the full prove process.
A test script(test/test.ts
) to verify that certain addreess is in the set of addresses
Each leave node is hash(secret, address), and we use '123' as secret.
// install npm package
npm install
// compile the contract
npx hardhat compile
// test verifys
npx hardhat test