From 3a7d576d0ba7b0df866fcba4e7e53d6a5bc9a4db Mon Sep 17 00:00:00 2001 From: ibmp33 <51358300+ibmp33@users.noreply.github.com> Date: Mon, 11 Mar 2024 15:48:38 +0800 Subject: [PATCH] chore: modify script (#229) * chore: modify script * chore: modify script * chore: modify script * chore: cargo clippy * chore: cargo clippy * fix: remvoe dead code * fix: create folder --------- Co-authored-by: Ubuntu Co-authored-by: eigmax --- .gitignore | 2 + README.md | 6 +- plonky/src/plonk.rs | 4 +- starkjs/package.json | 2 +- starky/data/r1.starkStruct.bn128.json | 12 ++++ starky/src/polsarray.rs | 4 +- starky/src/stark_verify.rs | 4 +- starky/src/starkinfo.rs | 2 +- test/aggregation/custom-types.d.ts | 3 + test/aggregation/test/agg.test.ts | 16 ++--- test/aggregation/test/final.fflonk.test.ts | 10 +-- test/aggregation/test/final.test.ts | 4 +- test/aggregation/tsconfig.json | 3 +- test/recursive_proof_to_snark.sh | 23 +++++-- test/simple_bls.sh | 2 +- test/snark_verifier.sh | 9 +-- test/stark_aggregation.sh | 2 +- test/test_aggregation.sh | 4 +- test/test_aggregation_verifier.sh | 80 ---------------------- test/test_fibonacci_verifier.sh | 39 ----------- test/test_plonk_verifier.sh | 71 +++++++++++++++++++ test/test_poseidon_verifier.sh | 50 -------------- test/test_single.sh | 40 ----------- test/test_sm_verifier.sh | 39 ----------- 24 files changed, 142 insertions(+), 289 deletions(-) create mode 100644 starky/data/r1.starkStruct.bn128.json create mode 100644 test/aggregation/custom-types.d.ts delete mode 100755 test/test_aggregation_verifier.sh delete mode 100755 test/test_fibonacci_verifier.sh create mode 100755 test/test_plonk_verifier.sh delete mode 100644 test/test_poseidon_verifier.sh delete mode 100755 test/test_single.sh delete mode 100755 test/test_sm_verifier.sh diff --git a/.gitignore b/.gitignore index fdc117a0..d008991a 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ vk.bin proof.bin verifier.sol plonk4verifier.sol +plonkit.sol log_substitution.json ir_log node_modules @@ -29,6 +30,7 @@ keys/setup_*.key keys/setup_*.ptau **/circuits.*/ starkjs/circuits/ +starkjs/poseidon/ **/package-lock.json witness.wtns diff --git a/README.md b/README.md index 691d8336..2e64a8a7 100644 --- a/README.md +++ b/README.md @@ -29,11 +29,11 @@ zkit setup -p 13 -s setup_2^13.key ``` For power in range 20 to 26, you can download directly from [universal-setup hub](https://universal-setup.ams3.digitaloceanspaces.com). -* Single proof and zkML +* Single proof -> [test_single.sh](./test/test_single.sh) +> [test_plonk_verifier.sh](./test/test_plonk_verifier.sh) -> [test_single.sh mnist 15](./test/test_single.sh) +> [test_plonk_verifier.sh poseidon](./test/test_plonk_verifier.sh) * Snark aggregation proof diff --git a/plonky/src/plonk.rs b/plonky/src/plonk.rs index 95a22ae1..e483b6d7 100644 --- a/plonky/src/plonk.rs +++ b/plonky/src/plonk.rs @@ -96,7 +96,9 @@ pub fn analyse(circuit: CircomCircuit) -> Result { .expect("sythesize into traspilation must succeed"); result.num_nontrivial_constraints = transpiler.constraint_stats.len(); result.num_gates = transpiler.num_gates(); - result.constraint_stats = transpiler.constraint_stats.clone(); + result + .constraint_stats + .clone_from(&transpiler.constraint_stats); let hints = transpiler.into_hints(); result.num_hints = hints.len(); Ok(result) diff --git a/starkjs/package.json b/starkjs/package.json index 2990f5c4..386e6fab 100644 --- a/starkjs/package.json +++ b/starkjs/package.json @@ -4,7 +4,7 @@ "description": "", "main": "index.js", "scripts": { - "poseidon": "mkdir -p poseidon/build && mkdir -p poseidon/&& node poseidon/main_poseidon.js -w poseidon/build", + "poseidon": "mkdir -p poseidon/build && mkdir -p poseidon/&& node poseidon/main_poseidon.js -w poseidon/build --i 0 --pc poseidon/build/poseidon_test", "fib": "mkdir -p circuits && node fibonacci/fibonacci.js -w circuits --i 0 --pc /tmp/fib", "pe": "mkdir -p circuits && node permutation/permutation.js -w circuits", "simple_vm": "mkdir -p circuits && node simple_vm/simple_vm.js -w circuits", diff --git a/starky/data/r1.starkStruct.bn128.json b/starky/data/r1.starkStruct.bn128.json new file mode 100644 index 00000000..1f8524a6 --- /dev/null +++ b/starky/data/r1.starkStruct.bn128.json @@ -0,0 +1,12 @@ +{ + "nBits": 18, + "nBitsExt": 19, + "nQueries": 6, + "verificationHashType": "BN128", + "steps": [ + { "nBits": 19 }, + { "nBits": 13 }, + { "nBits": 8 }, + { "nBits": 4 } + ] +} diff --git a/starky/src/polsarray.rs b/starky/src/polsarray.rs index 5b823b45..1c948a4c 100644 --- a/starky/src/polsarray.rs +++ b/starky/src/polsarray.rs @@ -57,9 +57,9 @@ impl PolsArray { let mut ns: HashMap> = HashMap::new(); let mut arrayPols: Vec = vec![0usize; ref_.len.unwrap()]; if def.contains_key(&nameSpace) { - ns = def.get(&nameSpace).unwrap().clone(); + ns.clone_from(def.get(&nameSpace).unwrap()); if ns.contains_key(&namePols) { - arrayPols = ns.get(&namePols).unwrap().clone(); + arrayPols.clone_from(ns.get(&namePols).unwrap()); } } diff --git a/starky/src/stark_verify.rs b/starky/src/stark_verify.rs index 27ed1ddb..e412df53 100644 --- a/starky/src/stark_verify.rs +++ b/starky/src/stark_verify.rs @@ -32,8 +32,8 @@ pub fn stark_verify( ctx.N = 1 << stark_struct.nBits; ctx.nbits = stark_struct.nBits; ctx.nbits_ext = stark_struct.nBitsExt; - ctx.evals = proof.evals.clone(); - ctx.publics = proof.publics.clone(); + ctx.evals.clone_from(&proof.evals); + ctx.publics.clone_from(&proof.publics); for i in 0..proof.publics.len() { let b = ctx.publics[i] diff --git a/starky/src/starkinfo.rs b/starky/src/starkinfo.rs index afbbe033..de69c2f1 100644 --- a/starky/src/starkinfo.rs +++ b/starky/src/starkinfo.rs @@ -346,7 +346,7 @@ impl StarkInfo { log::trace!("map"); info.map(pil, stark_struct, &mut program)?; - info.publics = pil.publics.clone(); + info.publics.clone_from(&pil.publics); Ok((info, program)) } diff --git a/test/aggregation/custom-types.d.ts b/test/aggregation/custom-types.d.ts new file mode 100644 index 00000000..96284161 --- /dev/null +++ b/test/aggregation/custom-types.d.ts @@ -0,0 +1,3 @@ +declare module "ethereum-waffle/dist/esm/src/ContractJSON" { + export * from "ethereum-waffle/dist/esm/ContractJSON"; + } \ No newline at end of file diff --git a/test/aggregation/test/agg.test.ts b/test/aggregation/test/agg.test.ts index 74cd1fe4..afb9a777 100644 --- a/test/aggregation/test/agg.test.ts +++ b/test/aggregation/test/agg.test.ts @@ -1,7 +1,7 @@ -const { expect } = require("chai"); -const { ethers } = require("hardhat"); +import { expect } from "chai"; +import { ethers } from "hardhat"; -const proof = require("/tmp/aggregation/aggregation_proof.json"); +const proof_agg = require("/tmp/aggregation/aggregation_proof.json"); describe("Plonk verifier test", function() { it("Should return true when proof is correct", async function() { @@ -11,11 +11,11 @@ describe("Plonk verifier test", function() { await verifier.deployed(); expect(await verifier.verifyAggregatedProof( - proof[0], - proof[1], - proof[2], - proof[3], - proof[4], + proof_agg[0], + proof_agg[1], + proof_agg[2], + proof_agg[3], + proof_agg[4], )).to.equal(true); }); }); diff --git a/test/aggregation/test/final.fflonk.test.ts b/test/aggregation/test/final.fflonk.test.ts index ac6f7b86..ceb80ea0 100644 --- a/test/aggregation/test/final.fflonk.test.ts +++ b/test/aggregation/test/final.fflonk.test.ts @@ -1,8 +1,8 @@ -const { expect } = require("chai"); -const { ethers } = require("hardhat"); +import { expect } from "chai"; +import { ethers } from "hardhat"; -const proof = require("../fibonacci.final/proof.fflonk.json"); -const publics = require("../fibonacci.final/public.fflonk.json"); +const proof_fflonk = require("../fibonacci.final/proof.fflonk.json"); +const publics_fflonk = require("../fibonacci.final/public.fflonk.json"); // https://github.com/0xPolygonHermez/zkevm-contracts/blob/main/test/contracts/real-prover/real-prover-test-inputs.test.js#L5 function generateSolidityInputs( @@ -43,6 +43,6 @@ describe("Plonk verifier test", function() { const verifier = await verifierFactory.deploy(); await verifier.deployed(); - expect(await verifier.verifyProof(generateSolidityInputs(proof), publics)).to.be.equal(true); + expect(await verifier.verifyProof(generateSolidityInputs(proof_fflonk), publics_fflonk)).to.be.equal(true); }); }); diff --git a/test/aggregation/test/final.test.ts b/test/aggregation/test/final.test.ts index a28844a6..e1bc9569 100644 --- a/test/aggregation/test/final.test.ts +++ b/test/aggregation/test/final.test.ts @@ -1,5 +1,5 @@ -const { expect } = require("chai"); -const { ethers } = require("hardhat"); +import { expect } from "chai"; +import { ethers } from "hardhat"; let dir = "/tmp/aggregation_bn128_fibonacci/aggregation/fibonacci.final" const proof = require(dir + "/proof.json"); diff --git a/test/aggregation/tsconfig.json b/test/aggregation/tsconfig.json index 520cf4be..fe16deba 100644 --- a/test/aggregation/tsconfig.json +++ b/test/aggregation/tsconfig.json @@ -4,9 +4,8 @@ "module": "commonjs", "allowJs": true, "esModuleInterop": true, - "esModuleInterop": true, "outDir": "dist" }, - "include": ["./scripts", "./test", "typechain/**/*.ts", "typechain/**/*.d.ts", "typechain/**/*.js", "lib"], + "include": ["./scripts", "./test", "typechain/**/*.ts", "typechain/**/*.d.ts", "typechain/**/*.js", "lib", "custom-types.d.ts"], "files": ["./hardhat.config.ts"] } diff --git a/test/recursive_proof_to_snark.sh b/test/recursive_proof_to_snark.sh index 4576dc09..726569bd 100755 --- a/test/recursive_proof_to_snark.sh +++ b/test/recursive_proof_to_snark.sh @@ -8,7 +8,6 @@ RUNDIR="${CUR_DIR}/../starkjs" PILCACHE=$WORKSPACE/$TASK_NO/$CIRCUIT PILEXECJS=$4 GENERATE_PROOF_TYPE=$5 -WORKSPACE=$6 RUST_LOG=info # CIRCUIT="fibonacci" # PILEXECJS="fibonacci/fibonacci.js" @@ -92,8 +91,20 @@ mkdir -p $RUNDIR/circuits && node $RUNDIR/$PILEXECJS -w $RUNDIR/circuits -i $TAS --e $WORKSPACE/$RECURSIVE1_CIRCUIT.exec \ --m $WORKSPACE/$RECURSIVE1_CIRCUIT.cm -../target/release/eigen-zkit stark_prove -s ../starky/data/r1.starkStruct.json \ - -p $WORKSPACE/$RECURSIVE1_CIRCUIT.pil.json \ - --o $WORKSPACE/$RECURSIVE1_CIRCUIT.const \ - --m $WORKSPACE/$RECURSIVE1_CIRCUIT.cm -c $WORKSPACE/circuits/$TASK_NO/$RECURSIVE2_CIRCUIT.circom \ - --i $WORKSPACE/aggregation/$TASK_NO/$RECURSIVE1_CIRCUIT.zkin.json --norm_stage --agg_stage +mkdir -p $WORKSPACE/aggregation/$TASK_NO + +if [ "$GENERATE_PROOF_TYPE" = "stark" ]; then + echo "Generate stark proof" + ../target/release/eigen-zkit stark_prove -s ../starky/data/r1.starkStruct.json \ + -p $WORKSPACE/$RECURSIVE1_CIRCUIT.pil.json \ + --o $WORKSPACE/$RECURSIVE1_CIRCUIT.const \ + --m $WORKSPACE/$RECURSIVE1_CIRCUIT.cm -c $WORKSPACE/circuits/$TASK_NO/$RECURSIVE2_CIRCUIT.circom \ + --i $WORKSPACE/aggregation/$TASK_NO/$RECURSIVE1_CIRCUIT.zkin.json --norm_stage --agg_stage +else + echo "Generate snark proof" + ../target/release/eigen-zkit stark_prove -s ../starky/data/r1.starkStruct.bn128.json \ + -p $WORKSPACE/$RECURSIVE1_CIRCUIT.pil.json \ + --o $WORKSPACE/$RECURSIVE1_CIRCUIT.const \ + --m $WORKSPACE/$RECURSIVE1_CIRCUIT.cm -c $WORKSPACE/circuits/$TASK_NO/$RECURSIVE2_CIRCUIT.circom \ + --i $WORKSPACE/aggregation/$TASK_NO/input.json --norm_stage --agg_stage +fi \ No newline at end of file diff --git a/test/simple_bls.sh b/test/simple_bls.sh index 24d57b8a..ce9080d0 100755 --- a/test/simple_bls.sh +++ b/test/simple_bls.sh @@ -37,7 +37,7 @@ CUR_DIR=$(cd $(dirname $0);pwd) CIRCUIT_NAME=c12a.verifier WORK_DIR=${CUR_DIR}/aggregation2 mkdir -p $WORK_DIR/$CIRCUIT_NAME -cp ../starkjs/circuits/c12a.verifier.zkin.json $WORK_DIR/final_input.zkin.json +cp ../starkjs/circuits/c12a.verifier.zkin.json $WORK_DIR/fibonacci.final.zkin.json cp ../starkjs/circuits/c12a.verifier.circom $WORK_DIR/ bash -x ./snark_verifier.sh groth16 true BLS12381 $CIRCUIT_NAME $WORK_DIR diff --git a/test/snark_verifier.sh b/test/snark_verifier.sh index 1697a7f2..042a07de 100755 --- a/test/snark_verifier.sh +++ b/test/snark_verifier.sh @@ -39,6 +39,7 @@ fi if [ $snark_type = "groth16" ]; then if [ $first_run = "true" ]; then + echo "1. groth16 setup" $ZKIT groth16_setup -c $CURVE --r1cs $WORK_DIR/$CIRCUIT_NAME.r1cs -p $WORK_DIR/g16.zkey -v $WORK_DIR/verification_key.json fi @@ -46,14 +47,14 @@ if [ $snark_type = "groth16" ]; then $ZKIT groth16_prove -c $CURVE --r1cs $WORK_DIR/$CIRCUIT_NAME.r1cs -w $WORK_DIR/$CIRCUIT_NAME"_js"/$CIRCUIT_NAME.wasm -p $WORK_DIR/g16.zkey -i $SNARK_INPUT --public-input $WORK_DIR/public_input.json --proof $WORK_DIR/proof.json if [ $first_run = "true" ]; then - echo "4. verify groth16 proof" + echo "3. verify groth16 proof" $ZKIT groth16_verify -c $CURVE -v $WORK_DIR/verification_key.json --public-input $WORK_DIR/public_input.json --proof $WORK_DIR/proof.json if [ $CURVE = "BN128" ]; then - echo "5. generate verifier contract" + echo "4. generate verifier contract" $ZKIT generate_verifier -v $WORK_DIR/verification_key.json -p groth16 -s ${CUR_DIR}/single/contracts/groth16_verifier.sol - echo "6. test verifier contract" + echo "5. test verifier contract" cp $WORK_DIR/public_input.json ${CUR_DIR}/single/input/groth16_public_input.json cp $WORK_DIR/proof.json ${CUR_DIR}/single/input/groth16_proof.json cd single @@ -81,7 +82,7 @@ else echo "1. fflonk setup " if [ ! -f "$WORK_DIR/fflonk.zkey" ]; then - echo "1. generate groth16 zkey" + echo "1. generate fflonk zkey" # nohup snarkjs ffs $WORK_DIR/$CIRCUIT_NAME.r1cs $BIG_SRS $WORK_DIR/fflonk.zkey & $SNARKJS ffs $WORK_DIR/$CIRCUIT_NAME.r1cs $BIG_SRS $WORK_DIR/fflonk.zkey else diff --git a/test/stark_aggregation.sh b/test/stark_aggregation.sh index f1b116f5..fe969e28 100755 --- a/test/stark_aggregation.sh +++ b/test/stark_aggregation.sh @@ -66,7 +66,7 @@ cd ${CURRENT_DIR}/../starkjs && npm i && cd $CURRENT_DIR for (( i=0; i<$NUM_PROOF; i++ )) do - ./recursive_proof_to_snark.sh $i $WORKSPACE $CIRCUIT $PILEXECJS "stark" $WORKSPACE + ./recursive_proof_to_snark.sh $i $WORKSPACE $CIRCUIT $PILEXECJS "stark" done c12_end=$(date +%s) diff --git a/test/test_aggregation.sh b/test/test_aggregation.sh index 7542ebf3..02ad302e 100755 --- a/test/test_aggregation.sh +++ b/test/test_aggregation.sh @@ -33,7 +33,7 @@ if [ ! -f $BIG_SRS ]; then fi echo "1. compile circuit" -${ZKIT} compile -i ${CIRCUIT}.circom --O2=full -o $WORKSPACE +${ZKIT} compile -i single/circuit/circuit.circom --O2=full -o $WORKSPACE echo "2. export verification key" ${ZKIT} export_verification_key -s ${SRS} -c $WORKSPACE/${CIRCUIT}.r1cs --v $WORKSPACE/vk.bin @@ -76,4 +76,4 @@ echo "8. generate verifier" ${ZKIT} generate_aggregation_verifier -o $WORKSPACE/vk.bin --n $WORKSPACE/aggregation_vk.bin --num_inputs ${NUM_INPUTS} -s aggregation/contracts/verifier.sol echo "9. run verifier test" -cd $CUR_DIR/aggregation && npm run test +cd $CUR_DIR/aggregation && npm run test \ No newline at end of file diff --git a/test/test_aggregation_verifier.sh b/test/test_aggregation_verifier.sh deleted file mode 100755 index 6e1a06d6..00000000 --- a/test/test_aggregation_verifier.sh +++ /dev/null @@ -1,80 +0,0 @@ -#!/bin/bash -set -ex - -## build -cargo build --release - -BIG_POWER=26 -POWER=23 -NUM_PROOF=2 -NUM_INPUT=2 -CUR_DIR=$(cd $(dirname $0);pwd) -ZKIT="${CUR_DIR}/../target/release/eigen-zkit" -CIRCUIT="fibonacci" -PILEXECJS="fibonacci/fibonacci.js" - -# test poseidon -#CIRCUIT="poseidon" -#PILEXECJS="poseidon/main_poseidon.js" - -WORKSPACE=/tmp/aggregation_$CIRCUIT -rm -rf $WORKSPACE && mkdir -p $WORKSPACE - -cd ${CUR_DIR} && npm i -for (( i=0; i<$NUM_PROOF; i++ )) -do - nohup ./recursive_proof_to_snark.sh $i $WORKSPACE $CIRCUIT $PILEXECJS "snark" & -done -wait - - -SRS=${CUR_DIR}/../keys/setup_2^${POWER}.key -BIG_SRS=${CUR_DIR}/../keys/setup_2^${BIG_POWER}.key - -if [ ! -f $SRS ]; then -# curl https://universal-setup.ams3.digitaloceanspaces.com/setup_2^${POWER}.key -o $SRS - ${ZKIT} setup -p ${POWER} -s ${SRS} -fi - -if [ ! -f $BIG_SRS ]; then -# curl https://universal-setup.ams3.digitaloceanspaces.com/setup_2^${BIG_POWER}.key -o $BIG_SRS - ${ZKIT} setup -p ${BIG_POWER} -s ${BIG_SRS} -fi -RECURSIVE_CIRCUIT=$CIRCUIT.recursive1 -echo "1. compile circuit, use task 0 by default" -${ZKIT} compile -i ../starkjs/circuits/0/$RECURSIVE_CIRCUIT.circom -l "../starkjs/node_modules/pil-stark/circuits.bn128" -l "../starkjs/node_modules/circomlib/circuits" --O2=full -o $WORKSPACE - -echo "2. export verification key" -${ZKIT} export_verification_key -s ${SRS} -c $WORKSPACE/${RECURSIVE_CIRCUIT}.r1cs --v $WORKSPACE/vk.bin - -echo "3. generate each proof" -for (( i=0; i<$NUM_PROOF; i++ )) -do - input=$CUR_DIR/aggregation/$i/${RECURSIVE_CIRCUIT} && mkdir -p $input - ${ZKIT} calculate_witness -w ${WORKSPACE}/${RECURSIVE_CIRCUIT}_js/$RECURSIVE_CIRCUIT.wasm -i ${input}/input.json -o $input/witness.wtns - ${ZKIT} prove -c $WORKSPACE/${RECURSIVE_CIRCUIT}.r1cs -w $input/witness.wtns --b $input/proof.bin -s ${SRS} -t rescue -done - -echo "4. collect old proof list" -OLD_PROOF_LIST=$WORKSPACE/old_proof_list.txt -> $OLD_PROOF_LIST - -for (( i=0; i<$NUM_PROOF; i++ )) -do - input=${CUR_DIR}/aggregation/$i/${RECURSIVE_CIRCUIT} - echo $input/proof.bin >> $OLD_PROOF_LIST -done - -cat $OLD_PROOF_LIST - -echo "5. export aggregation vk" -${ZKIT} export_aggregation_verification_key --c $NUM_PROOF --i $NUM_INPUT -s ${BIG_SRS} --v $WORKSPACE/aggregation_vk.bin - -echo "6. generate aggregation proof" -${ZKIT} aggregation_prove -s ${BIG_SRS} --f $OLD_PROOF_LIST --v $WORKSPACE/vk.bin --n $WORKSPACE/aggregation_proof.bin --j $WORKSPACE/aggregation_proof.json - -echo "7. verify" -${ZKIT} aggregation_verify --p $WORKSPACE/aggregation_proof.bin --v $WORKSPACE/aggregation_vk.bin - -echo "8. generate verifier" -${ZKIT} generate_aggregation_verifier -o $WORKSPACE/vk.bin --n $WORKSPACE/aggregation_vk.bin --num_inputs $NUM_INPUT -s $WORKSPACE/verifier.sol diff --git a/test/test_fibonacci_verifier.sh b/test/test_fibonacci_verifier.sh deleted file mode 100755 index 21d9df32..00000000 --- a/test/test_fibonacci_verifier.sh +++ /dev/null @@ -1,39 +0,0 @@ -# EigenZKit -set -ex - -cargo build --release - -CIRCUIT=circuit -CUR_DIR=$(cd $(dirname $0);pwd) -POWER=24 -export RUST_BACKTRACE=1 -ZKIT="${CUR_DIR}/../target/release/eigen-zkit" -WORKSPACE=/tmp/${CIRCUIT} -rm -rf $WORKSPACE && mkdir -p $WORKSPACE - -SRS=${CUR_DIR}/../keys/setup_2^${POWER}.key -if [ ! -f $SRS ]; then - ${ZKIT} setup -p ${POWER} -s ${SRS} -fi - -cd $CUR_DIR - -echo "1. Compile the circuit" -# BN128 -${ZKIT} compile -i ../starkjs/circuits/$CIRCUIT.circom -l "../starkjs/node_modules/pil-stark/circuits.bn128" -l "../starkjs/node_modules/circomlib/circuits" --O2=full -o $WORKSPACE - -echo "2. Generate witness" -${ZKIT} calculate_witness -w ${WORKSPACE}/${CIRCUIT}_js/$CIRCUIT.wasm -i ../starkjs/circuits/${CIRCUIT}.zkin.json -o $WORKSPACE/witness.wtns - -echo "3. Export verification key" -${ZKIT} export_verification_key -s ${SRS} -c $WORKSPACE/$CIRCUIT.r1cs --v $WORKSPACE/vk.bin - -echo "4. prove" -${ZKIT} prove -c $WORKSPACE/$CIRCUIT.r1cs -w $WORKSPACE/witness.wtns -s ${SRS} --b $WORKSPACE/proof.bin - -echo "5. Verify the proof" -${ZKIT} verify -p $WORKSPACE/proof.bin -v $WORKSPACE/vk.bin - -echo "6. Generate verifier" -mkdir -p ${CIRCUIT}/contracts -${ZKIT} generate_verifier -v $WORKSPACE/vk.bin --s ${CIRCUIT}/contracts/verifier.sol diff --git a/test/test_plonk_verifier.sh b/test/test_plonk_verifier.sh new file mode 100755 index 00000000..426d7359 --- /dev/null +++ b/test/test_plonk_verifier.sh @@ -0,0 +1,71 @@ +# EigenZKit +set -ex + +cargo build --release + +CIRCUIT=${1:-circuit} +CUR_DIR=$(cd $(dirname $0); pwd) + +if [ "$CIRCUIT" = "circuit" ]; then + POWER=24 +elif [ "$CIRCUIT" = "poseidon" ]; then + POWER=25 +else + echo "Error: Unsupported CIRCUIT value '$CIRCUIT'" + exit 1 +fi + +export RUST_BACKTRACE=1 +ZKIT="${CUR_DIR}/../target/release/eigen-zkit" +WORKSPACE=/tmp/${CIRCUIT} +rm -rf $WORKSPACE && mkdir -p $WORKSPACE + +SRS=${CUR_DIR}/../keys/setup_2^${POWER}.key +if [ ! -f $SRS ]; then + ${ZKIT} setup -p ${POWER} -s ${SRS} +fi + +cd $CUR_DIR + +echo "1. Compile the circuit" +# BN128 +if [ "$CIRCUIT" = "circuit" ]; then + CIRCOM_FILE=single/circuit/$CIRCUIT.circom + INPUT_FILE=single/input/${CIRCUIT}.json +elif [ "$CIRCUIT" = "poseidon" ]; then + cd "../starkjs" + npm run poseidon + echo "========== 0. generate stark proof and then generate the stark verifier circom ============" + mkdir ./poseidon/circuits + ${ZKIT} stark_prove -s ../starky/data/starkStruct.json \ + -p ./poseidon/build/poseidon_test.pil.json \ + --o ./poseidon/build/poseidon_test.const \ + --m ./poseidon/build/poseidon_test.cm \ + -c ./poseidon/circuits/stark_verify.circom \ + --i ./poseidon/circuits/stark_proof.json \ + --norm_stage + cd $CUR_DIR + CIRCOM_FILE=../starkjs/poseidon/circuits/stark_verify.circom + INPUT_FILE=../starkjs/poseidon/circuits/stark_proof.json + CIRCUIT=stark_verify +fi +${ZKIT} compile -i ${CIRCOM_FILE} -l "../starkjs/node_modules/pil-stark/circuits.bn128" -l "../starkjs/node_modules/circomlib/circuits" --O2=full -o $WORKSPACE + +echo "2. Generate witness" +${ZKIT} calculate_witness -w ${WORKSPACE}/${CIRCUIT}_js/$CIRCUIT.wasm -i ${INPUT_FILE} -o $WORKSPACE/witness.wtns + +echo "3. Export verification key" +${ZKIT} export_verification_key -s ${SRS} -c $WORKSPACE/$CIRCUIT.r1cs --v $WORKSPACE/vk.bin + +echo "4. prove" +${ZKIT} prove -c $WORKSPACE/$CIRCUIT.r1cs -w $WORKSPACE/witness.wtns -s ${SRS} --b $WORKSPACE/proof.bin + +echo "5. Verify the proof" +${ZKIT} verify -p $WORKSPACE/proof.bin -v $WORKSPACE/vk.bin + +echo "6. Generate verifier" +mkdir -p ${WORKSPACE}/contracts +${ZKIT} generate_verifier -v $WORKSPACE/vk.bin -s single/contracts/verifier.sol + +echo "7. run verifier test" +cd $CUR_DIR/single && npm i && npx hardhat test --grep "Test Plonk verifier" diff --git a/test/test_poseidon_verifier.sh b/test/test_poseidon_verifier.sh deleted file mode 100644 index 50ee3d1f..00000000 --- a/test/test_poseidon_verifier.sh +++ /dev/null @@ -1,50 +0,0 @@ -# EigenZKit -set -ex - -cargo build --release - -CIRCOM_FILE=stark_verify -CUR_DIR=$(cd $(dirname $0);pwd) -POWER=24 -export RUST_BACKTRACE=1 -ZKIT="${CUR_DIR}/../target/release/eigen-zkit" -WORKSPACE=../starkjs/poseidon/circuits -#rm -rf $WORKSPACE && mkdir -p $WORKSPACE - -SRS=${CUR_DIR}/../keys/setup_2^${POWER}.key -if [ ! -f $SRS ]; then - ${ZKIT} setup -p ${POWER} -s ${SRS} -fi - -echo "npm run poseidon " -npm run poseidon - -echo "========== 0. generate stark proof and then generate the stark verifier circom ============" -${ZKIT} stark_prove -s ../starky/data/starkStruct.json.gl \ - -p ./poseidon/build/poseidon_test.pil.json \ - -o ./poseidon/build/poseidon_test.const \ - -m ./poseidon/build/poseidon_test.cm -c ./poseidon/circuits/stark_verify.circom -i ./poseidon/circuits/stark_proof.json - -# cd eigen-zkevm/test -cd $CUR_DIR - -echo "=========== 1. Compile the circuit ==================" -# BN128 -#${ZKIT} compile -i ../starkjs/poseidon/circuits/$CIRCOM_FILE.circom -l "../starkjs/node_modules/pil-stark/circuits.bn128" -l "../starkjs/node_modules/circomlib/circuits" --O2=full -o $WORKSPACE -${ZKIT} compile -i ../starkjs/poseidon/circuits/$CIRCOM_FILE.circom -l "../starkjs/node_modules/pil-stark/circuits.gl" -l "../starkjs/node_modules/circomlib/circuits" --O2=full -o $WORKSPACE - -echo "===========2. Generate witness ===========" -${ZKIT} calculate_witness -w ${WORKSPACE}/${CIRCOM_FILE}_js/$CIRCOM_FILE.wasm -i ${WORKSPACE}/stark_proof.json -o $WORKSPACE/witness.wtns - -echo "===========3. Export verification key ===========" -${ZKIT} export_verification_key -s ${SRS} -c $WORKSPACE/$CIRCOM_FILE.r1cs -v $WORKSPACE/vk.bin - -echo "===========4. prove ===========" -${ZKIT} prove -c $WORKSPACE/$CIRCOM_FILE.r1cs -w $WORKSPACE/witness.wtns -s ${SRS} -b $WORKSPACE/proof.bin - -echo "===========5. Verify the proof ===========" -${ZKIT} verify -p $WORKSPACE/proof.bin -v $WORKSPACE/vk.bin - -echo "===========6. Generate verifier ===========" -mkdir -p $WORKSPACE/contracts -${ZKIT} generate_verifier -v $WORKSPACE/vk.bin -s $WORKSPACE/contracts/stark_verifier.sol diff --git a/test/test_single.sh b/test/test_single.sh deleted file mode 100755 index 1eaa9de3..00000000 --- a/test/test_single.sh +++ /dev/null @@ -1,40 +0,0 @@ -# EigenZKit -set -ex - -cargo build --release - -CIRCUIT=${1-circuit} # use circuit or mnist as the first parameter -CUR_DIR=$(cd $(dirname $0);pwd) -POWER=${2-12} # 15 for zkMinist -ZKIT="${CUR_DIR}/../target/release/eigen-zkit" -WORKSPACE=/tmp/single -rm -rf $WORKSPACE && mkdir -p $WORKSPACE - -SRS=${CUR_DIR}/../keys/setup_2^${POWER}.key - -cd $CUR_DIR - -if [ ! -f $SRS ]; then - ${ZKIT} setup -p ${POWER} -s ${SRS} -fi - -echo "1. Compile the circuit" -${ZKIT} compile -i ${CUR_DIR}/single/circuit/${CIRCUIT}.circom --O2=full -o $WORKSPACE - -echo "2. Generate witness" -${ZKIT} calculate_witness -i ${CUR_DIR}/single/input/${CIRCUIT}.json -w ${WORKSPACE}/${CIRCUIT}_js/${CIRCUIT}.wasm -o $WORKSPACE/witness.wtns - -echo "3. Export verification key" -${ZKIT} export_verification_key -s ${SRS} -c $WORKSPACE/$CIRCUIT.r1cs --v $WORKSPACE/vk.bin - -echo "4. prove" -${ZKIT} prove -c $WORKSPACE/$CIRCUIT.r1cs -w $WORKSPACE/witness.wtns -s ${SRS} --b $WORKSPACE/proof.bin - -echo "5. Verify the proof" -${ZKIT} verify -p $WORKSPACE/proof.bin -v $WORKSPACE/vk.bin - -echo "6. Generate verifier" -${ZKIT} generate_verifier -v $WORKSPACE/vk.bin -s single/contracts/verifier.sol - -echo "7. run verifier test" -cd $CUR_DIR/single && npx hardhat test --grep "Test Plonk verifier" diff --git a/test/test_sm_verifier.sh b/test/test_sm_verifier.sh deleted file mode 100755 index da15919f..00000000 --- a/test/test_sm_verifier.sh +++ /dev/null @@ -1,39 +0,0 @@ -# EigenZKit -set -ex - -cargo build --release - -CIRCUIT=circuit -CUR_DIR=$(cd $(dirname $0);pwd) -POWER=26 -APP=SM -export RUST_BACKTRACE=1 -ZKIT="${CUR_DIR}/../target/release/eigen-zkit" -WORKSPACE=/tmp/${CIRCUIT} -rm -rf $WORKSPACE && mkdir -p $WORKSPACE - -SRS=${CUR_DIR}/../keys/setup_2^${POWER}.key -if [ ! -f $SRS ]; then - ${ZKIT} setup -p ${POWER} -s ${SRS} -fi - -cd $CUR_DIR - -echo "1. Compile the circuit" -${ZKIT} compile -i ../${APP}/circuits/$CIRCUIT.circom -l "../${APP}/node_modules/pil-stark/circuits.bn128" -l "../${APP}/node_modules/circomlib/circuits" --O2=full -o $WORKSPACE - -echo "2. Generate witness" -${ZKIT} -w ${WORKSPACE}/${CIRCUIT}_js/$CIRCUIT.wasm -i ../${APP}/circuits/${CIRCUIT}.zkin.json -o $WORKSPACE/witness.wtns - -echo "3. Export verification key" -${ZKIT} export_verification_key -s ${SRS} -c $WORKSPACE/$CIRCUIT.r1cs -v $WORKSPACE/vk.bin - -echo "4. prove" -${ZKIT} prove -c $WORKSPACE/$CIRCUIT.r1cs -w $WORKSPACE/witness.wtns -s ${SRS} -b $WORKSPACE/proof.bin - -echo "5. Verify the proof" -${ZKIT} verify -p $WORKSPACE/proof.bin -v $WORKSPACE/vk.bin - -echo "6. Generate verifier" -mkdir -p ${CIRCUIT}/contracts -${ZKIT} generate_verifier -v $WORKSPACE/vk.bin -s ${CIRCUIT}/contracts/verifier.sol