mirror of
https://github.com/selfxyz/self.git
synced 2026-04-05 03:00:53 -04:00
adapt build scripts to multiple register circuits
This commit is contained in:
@@ -40,8 +40,8 @@ Proof of Passport currently supports the following sig/hash algorithms:
|
||||
|
||||
|
||||
- [x] sha256WithRSAEncryption
|
||||
- [ ] sha1WithRSAEncryption (under development)
|
||||
- [ ] rsassaPss
|
||||
- [x] sha1WithRSAEncryption
|
||||
- [ ] rsassaPss (under development)
|
||||
- [ ] ecdsa-with-SHA384
|
||||
- [ ] ecdsa-with-SHA1
|
||||
- [ ] ecdsa-with-SHA256
|
||||
@@ -57,12 +57,10 @@ Proof of Passport currently supports the following sig/hash algorithms:
|
||||
yarn install-circuits
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Build circuits (dev only)
|
||||
|
||||
```bash
|
||||
./scripts/build_circuit.sh
|
||||
./scripts/build_circuits.sh
|
||||
```
|
||||
|
||||
## Run tests
|
||||
@@ -70,8 +68,4 @@ yarn install-circuits
|
||||
```bash
|
||||
yarn test
|
||||
```
|
||||
This will run tests with sample data generated on the fly.
|
||||
|
||||
The
|
||||
|
||||
To run tests with your own passport data, extract your `passportData.json` using the app (available soon), place it in `inputs/`, then run `yarn test`
|
||||
This will run tests with sample data generated on the fly.
|
||||
36
circuits/scripts/build_circuits.sh
Executable file
36
circuits/scripts/build_circuits.sh
Executable file
@@ -0,0 +1,36 @@
|
||||
#!/bin/bash
|
||||
|
||||
source "scripts/download_ptau.sh"
|
||||
|
||||
build_circuit() {
|
||||
local CIRCUIT_NAME=$1
|
||||
local START_TIME=$(date +%s)
|
||||
|
||||
echo "compiling circuit: $CIRCUIT_NAME"
|
||||
circom circuits/${CIRCUIT_NAME}.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/${CIRCUIT_NAME}.r1cs build/powersOfTau28_hez_final_20.ptau build/${CIRCUIT_NAME}.zkey
|
||||
|
||||
echo "building vkey"
|
||||
yarn snarkjs zkey contribute build/${CIRCUIT_NAME}.zkey build/${CIRCUIT_NAME}_final.zkey -e="random text"
|
||||
yarn snarkjs zkey export verificationkey build/${CIRCUIT_NAME}_final.zkey build/${CIRCUIT_NAME}_vkey.json
|
||||
|
||||
yarn snarkjs zkey export solidityverifier build/${CIRCUIT_NAME}_final.zkey build/Verifier_${CIRCUIT_NAME}.sol
|
||||
sed -i '' "s/Groth16Verifier/Verifier_${CIRCUIT_NAME}/g" build/Verifier_${CIRCUIT_NAME}.sol
|
||||
cp build/Verifier_${CIRCUIT_NAME}.sol ../contracts/contracts/Verifier_${CIRCUIT_NAME}.sol
|
||||
echo "copied Verifier_${CIRCUIT_NAME}.sol to contracts"
|
||||
|
||||
echo "Build of $CIRCUIT_NAME completed in $(($(date +%s) - START_TIME)) seconds"
|
||||
echo "Size of ${CIRCUIT_NAME}.r1cs: $(wc -c <build/${CIRCUIT_NAME}.r1cs) bytes"
|
||||
echo "Size of ${CIRCUIT_NAME}.wasm: $(wc -c <build/${CIRCUIT_NAME}_js/${CIRCUIT_NAME}.wasm) bytes"
|
||||
echo "Size of ${CIRCUIT_NAME}_final.zkey: $(wc -c <build/${CIRCUIT_NAME}_final.zkey) bytes"
|
||||
}
|
||||
|
||||
declare -a CIRCUITS=("register_sha256WithRSAEncryption_65537" "register_sha1WithRSAEncryption_65537" "disclose")
|
||||
|
||||
TOTAL_START_TIME=$(date +%s)
|
||||
for CIRCUIT_NAME in "${CIRCUITS[@]}"; do
|
||||
build_circuit "$CIRCUIT_NAME"
|
||||
done
|
||||
echo "Total completed in $(($(date +%s) - TOTAL_START_TIME)) seconds"
|
||||
@@ -1,44 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Record the start time
|
||||
START_TIME=$(date +%s)
|
||||
|
||||
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/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
|
||||
|
||||
if command -v openssl &> /dev/null
|
||||
then
|
||||
RAND_STR=$(openssl rand -hex 64)
|
||||
else
|
||||
RAND_STR="random text"
|
||||
fi
|
||||
|
||||
echo "building vkey"
|
||||
echo $RAND_STR | yarn snarkjs zkey contribute build/disclose.zkey build/disclose_final.zkey
|
||||
yarn snarkjs zkey export verificationkey build/disclose_final.zkey build/disclose_vkey.json
|
||||
|
||||
yarn snarkjs zkey export solidityVerifier build/disclose_final.zkey build/Verifier_disclose.sol
|
||||
sed -i '' 's/Groth16Verifier/Verifier_disclose/g' build/Verifier_disclose.sol
|
||||
cp build/Verifier_disclose.sol ../contracts/contracts/Verifier_disclose.sol
|
||||
echo "copied Verifier_disclose.sol to contracts"
|
||||
|
||||
echo "Build completed in $(($(date +%s) - $START_TIME)) seconds"
|
||||
|
||||
echo "file sizes:"
|
||||
echo "Size of disclose.r1cs: $(wc -c <build/disclose.r1cs) bytes"
|
||||
echo "Size of disclose.wasm: $(wc -c <build/disclose_js/disclose.wasm) bytes"
|
||||
echo "Size of disclose_final.zkey: $(wc -c <build/disclose_final.zkey) bytes"
|
||||
@@ -1,44 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Record the start time
|
||||
START_TIME=$(date +%s)
|
||||
|
||||
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/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
|
||||
|
||||
if command -v openssl &> /dev/null
|
||||
then
|
||||
RAND_STR=$(openssl rand -hex 64)
|
||||
else
|
||||
RAND_STR="random text"
|
||||
fi
|
||||
|
||||
echo "building vkey"
|
||||
echo $RAND_STR | yarn snarkjs zkey contribute build/register_sha256WithRSAEncryption_65537.zkey build/register_sha256WithRSAEncryption_65537_final.zkey
|
||||
yarn snarkjs zkey export verificationkey build/register_sha256WithRSAEncryption_65537_final.zkey build/register_sha256WithRSAEncryption_65537_vkey.json
|
||||
|
||||
yarn snarkjs zkey export solidityverifier build/register_sha256WithRSAEncryption_65537_final.zkey build/Verifier_register_sha256WithRSAEncryption_65537.sol
|
||||
sed -i '' 's/Groth16Verifier/Verifier_register_sha256WithRSAEncryption_65537/g' build/Verifier_register_sha256WithRSAEncryption_65537.sol
|
||||
cp build/Verifier_register_sha256WithRSAEncryption_65537.sol ../contracts/contracts/Verifier_register_sha256WithRSAEncryption_65537.sol
|
||||
echo "copied Verifier_register_sha256WithRSAEncryption_65537.sol to contracts"
|
||||
|
||||
echo "Build completed in $(($(date +%s) - $START_TIME)) seconds"
|
||||
|
||||
echo "file sizes:"
|
||||
echo "Size of register_sha256WithRSAEncryption_65537.r1cs: $(wc -c <build/register_sha256WithRSAEncryption_65537.r1cs) bytes"
|
||||
echo "Size of register_sha256WithRSAEncryption_65537.wasm: $(wc -c <build/register_sha256WithRSAEncryption_65537_js/register_sha256WithRSAEncryption_65537.wasm) bytes"
|
||||
echo "Size of register_sha256WithRSAEncryption_65537_final.zkey: $(wc -c <build/register_sha256WithRSAEncryption_65537_final.zkey) bytes"
|
||||
12
circuits/scripts/download_ptau.sh
Normal file
12
circuits/scripts/download_ptau.sh
Normal file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
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 ..
|
||||
Reference in New Issue
Block a user