Skip to content

Commit

Permalink
chore: modify script (#229)
Browse files Browse the repository at this point in the history
* 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 <devadmin@zkevm-prover-uat-vm1.qf0bt0i4yvdutbhtrpicnmptkg.ix.internal.cloudapp.net>
Co-authored-by: eigmax <stephen@ieigen.com>
  • Loading branch information
3 people authored Mar 11, 2024
1 parent 810ed8a commit 3a7d576
Show file tree
Hide file tree
Showing 24 changed files with 142 additions and 289 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ vk.bin
proof.bin
verifier.sol
plonk4verifier.sol
plonkit.sol
log_substitution.json
ir_log
node_modules
Expand All @@ -29,6 +30,7 @@ keys/setup_*.key
keys/setup_*.ptau
**/circuits.*/
starkjs/circuits/
starkjs/poseidon/
**/package-lock.json
witness.wtns

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion plonky/src/plonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ pub fn analyse<E: Engine>(circuit: CircomCircuit<E>) -> Result<AnalyseResult> {
.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)
Expand Down
2 changes: 1 addition & 1 deletion starkjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions starky/data/r1.starkStruct.bn128.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"nBits": 18,
"nBitsExt": 19,
"nQueries": 6,
"verificationHashType": "BN128",
"steps": [
{ "nBits": 19 },
{ "nBits": 13 },
{ "nBits": 8 },
{ "nBits": 4 }
]
}
4 changes: 2 additions & 2 deletions starky/src/polsarray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ impl PolsArray {
let mut ns: HashMap<String, Vec<usize>> = HashMap::new();
let mut arrayPols: Vec<usize> = 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());
}
}

Expand Down
4 changes: 2 additions & 2 deletions starky/src/stark_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ pub fn stark_verify<M: MerkleTree, T: Transcript>(
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]
Expand Down
2 changes: 1 addition & 1 deletion starky/src/starkinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
3 changes: 3 additions & 0 deletions test/aggregation/custom-types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module "ethereum-waffle/dist/esm/src/ContractJSON" {
export * from "ethereum-waffle/dist/esm/ContractJSON";
}
16 changes: 8 additions & 8 deletions test/aggregation/test/agg.test.ts
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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);
});
});
10 changes: 5 additions & 5 deletions test/aggregation/test/final.fflonk.test.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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);
});
});
4 changes: 2 additions & 2 deletions test/aggregation/test/final.test.ts
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
3 changes: 1 addition & 2 deletions test/aggregation/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
23 changes: 17 additions & 6 deletions test/recursive_proof_to_snark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/simple_bls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 5 additions & 4 deletions test/snark_verifier.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,22 @@ 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

echo "2. groth16 fullprove"
$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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/stark_aggregation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/test_aggregation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
80 changes: 0 additions & 80 deletions test/test_aggregation_verifier.sh

This file was deleted.

39 changes: 0 additions & 39 deletions test/test_fibonacci_verifier.sh

This file was deleted.

Loading

0 comments on commit 3a7d576

Please sign in to comment.