import binary-merkle-root.circom instead of copying it

This commit is contained in:
0xturboblitz
2024-05-11 14:47:22 +09:00
parent 18a1a10575
commit cda2b7552d
8 changed files with 13 additions and 69 deletions

View File

@@ -4,7 +4,7 @@ include "circomlib/circuits/poseidon.circom";
include "@zk-email/circuits/helpers/extract.circom";
include "./utils/isOlderThan.circom";
include "./utils/isValid.circom";
include "./utils/binary-merkle-root.circom";
include "binary-merkle-root.circom";
template Disclose(nLevels) {
signal input secret;

View File

@@ -5,7 +5,7 @@ include "@zk-email/circuits/helpers/extract.circom";
include "./passport_verifier_sha256WithRSAEncryption_65537.circom";
include "./utils/chunk_data.circom";
include "./utils/compute_pubkey_leaf.circom";
include "./utils/binary-merkle-root.circom";
include "binary-merkle-root.circom";
template Register_sha256WithRSAEncryption_65537(n, k, max_datahashes_bytes, nLevels, signatureAlgorithm) {
signal input secret;

View File

@@ -1,43 +0,0 @@
pragma circom 2.1.5;
include "circomlib/circuits/poseidon.circom";
include "circomlib/circuits/mux1.circom";
include "circomlib/circuits/comparators.circom";
// This circuit is designed to calculate the root of a binary Merkle
// tree given a leaf, its depth, and the necessary sibling
// information (aka proof of membership).
// A circuit is designed without the capability to iterate through
// a dynamic array. To address this, a parameter with the static maximum
// tree depth is defined (i.e. 'MAX_DEPTH'). And additionally, the circuit
// receives a dynamic depth as an input, which is utilized in calculating the
// true root of the Merkle tree. The actual depth of the Merkle tree
// may be equal to or less than the static maximum depth.
template BinaryMerkleRoot(MAX_DEPTH) {
signal input leaf, depth, indices[MAX_DEPTH], siblings[MAX_DEPTH];
signal output out;
signal nodes[MAX_DEPTH + 1];
nodes[0] <== leaf;
signal roots[MAX_DEPTH];
var root = 0;
for (var i = 0; i < MAX_DEPTH; i++) {
var isDepth = IsEqual()([depth, i]);
roots[i] <== isDepth * nodes[i];
root += roots[i];
var c[2][2] = [ [nodes[i], siblings[i]], [siblings[i], nodes[i]] ];
var childNodes[2] = MultiMux1(2)(c, indices[i]);
nodes[i + 1] <== Poseidon(2)(childNodes);
}
var isDepth = IsEqual()([depth, MAX_DEPTH]);
out <== root + isDepth * nodes[MAX_DEPTH];
}

View File

@@ -13,6 +13,7 @@
"@zk-email/circuits": "^3.2.2",
"@zk-email/helpers": "^3.1.3",
"@zk-email/zk-regex-circom": "^1.2.1",
"@zk-kit/binary-merkle-root.circom": "^1.0.0-beta",
"@zk-kit/circuits": "^1.0.0-beta",
"@zk-kit/imt": "https://gitpkg.now.sh/0xturboblitz/zk-kit/packages/imt?6d417675",
"chai-as-promised": "^7.1.1",
@@ -34,4 +35,4 @@
"ts-mocha": "^10.0.0",
"ts-node": "^10.9.2"
}
}
}

View File

@@ -23,7 +23,7 @@ fi
cd ..
echo "compiling circuit"
circom circuits/disclose.circom -l node_modules --r1cs --O1 --wasm -c --output build
circom circuits/disclose.circom -l node_modules -l ./node_modules/@zk-kit/binary-merkle-root.circom/src -l ./node_modules/circomlib/circuits --r1cs --O1 --wasm -c --output build
echo "building zkey"
yarn snarkjs groth16 setup build/disclose.r1cs build/powersOfTau28_hez_final_20.ptau build/disclose.zkey

View File

@@ -1,21 +0,0 @@
mkdir -p build
cd build
if [ ! -f powersOfTau28_hez_final_20.ptau ]; then
echo "Download power of tau...."
wget https://hermez.s3-eu-west-1.amazonaws.com/powersOfTau28_hez_final_20.ptau
echo "Finished download!"
else
echo "Powers of tau file already downloaded... Skip download action!"
fi
cd ..
echo "compiling circuit"
circom circuits/merkle_tree/only_tree.circom --r1cs --sym --wasm --output build
echo "building zkey"
yarn snarkjs groth16 setup build/only_tree.r1cs build/powersOfTau28_hez_final_20.ptau build/only_tree.zkey
echo "building vkey"
echo "test random" | yarn snarkjs zkey contribute build/only_tree.zkey build/only_tree_final.zkey
yarn snarkjs zkey export verificationkey build/only_tree_final.zkey build/only_tree_verification_key.json

View File

@@ -23,7 +23,7 @@ fi
cd ..
echo "compiling circuit"
circom circuits/register_sha256WithRSAEncryption_65537.circom -l node_modules --r1cs --O1 --wasm -c --output build
circom circuits/register_sha256WithRSAEncryption_65537.circom -l node_modules -l ./node_modules/@zk-kit/binary-merkle-root.circom/src -l ./node_modules/circomlib/circuits --r1cs --O1 --wasm -c --output build
echo "building zkey"
yarn snarkjs groth16 setup build/register_sha256WithRSAEncryption_65537.r1cs build/powersOfTau28_hez_final_20.ptau build/register_sha256WithRSAEncryption_65537.zkey

View File

@@ -516,6 +516,13 @@
commander "^11.0.0"
snarkjs "^0.7.0"
"@zk-kit/binary-merkle-root.circom@^1.0.0-beta":
version "1.0.0-beta"
resolved "https://registry.yarnpkg.com/@zk-kit/binary-merkle-root.circom/-/binary-merkle-root.circom-1.0.0-beta.tgz#1124840ff3d0af8c28ad4d9ee5004d41f6768978"
integrity sha512-yj8bPpYWNjmk3DLIv9zyIyZ0WxTWKuYs1BxEDOCNKBmk6Gw4FtTcAsppXAF4gkqkvU29hhG/naaOuz0SGQSCFg==
dependencies:
circomlib "^2.0.5"
"@zk-kit/circuits@^1.0.0-beta":
version "1.0.0-beta"
resolved "https://registry.yarnpkg.com/@zk-kit/circuits/-/circuits-1.0.0-beta.tgz#4f41315839855762dac11b2ba2ce5e58fd8ad1e9"