Skip to content

Commit

Permalink
feat: bls12381
Browse files Browse the repository at this point in the history
  • Loading branch information
eigmax committed Jul 15, 2023
1 parent f74a68e commit 7c024a9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ For power in range 20 to 26, you can download directly from [universal-setup hub
* Single proof
[test_single.sh](./test/test_single.sh)

* Aggregation proof
* Snark aggregation proof
[test_aggregation.sh](./test/test_aggregation.sh)

* Stark aggregation proof
[stark_aggregation.sh yes bn128](./test/stark_aggregation.sh)
[stark_aggregation.sh yes bls12-381](./test/stark_aggregation.sh)

* Stark proof and recursive stark prove
[starky](./starky)

Expand Down
2 changes: 1 addition & 1 deletion starky/src/stark_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ impl<'a, M: MerkleTree> StarkProof<M> {
}
cur_s = cur_s * shift_in;
}
log::debug!("qq2");
//log::debug!("qq2");
//crate::helper::pretty_print_array(&qq2);

fft(
Expand Down
33 changes: 21 additions & 12 deletions test/snark_verifier.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ export NODE_OPTIONS="--max-old-space-size=16384"
source ~/.bashrc

CUR_DIR=$(cd $(dirname $0);pwd)

snark_type=${1-groth16}
first_run=${2-false}
#bls12-381
CURVE=${3-bn128}
POWER=22
BIG_POWER=28
SRS=${CUR_DIR}/../keys/setup_2^${POWER}.ptau
SRS=${CUR_DIR}/../keys/setup_2^${POWER}.${CURVE}.ptau
#BIG_SRS=${CUR_DIR}/../keys/setup_2^${BIG_POWER}.ptau
BIG_SRS=/zkp/zkevm-proverjs/build/powersOfTau28_hez_final.ptau

Expand All @@ -28,9 +31,6 @@ fi

ZKIT="${CUR_DIR}/../target/release/eigen-zkit"

snark_type=${1-groth16}
first_run=${2-false}

if [ $first_run = "true" ]; then
echo "compile circom and generate wasm and r1cs"
$ZKIT compile -i $CUR_DIR/../starkjs/circuits/$CIRCUIT_NAME.circom -p bn128 -l "../starkjs/node_modules/pil-stark/circuits.bn128" -l "../starkjs/node_modules/circomlib/circuits" --O2=full -o $WORK_DIR
Expand All @@ -41,9 +41,12 @@ fi
if [ $snark_type = "groth16" ]; then
if [ ! -f $SRS ]; then
echo "downloading powersOfTau28_hez_final_${POWER}.ptau"
curl https://hermez.s3-eu-west-1.amazonaws.com/powersOfTau28_hez_final_${POWER}.ptau -o $SRS
#curl https://hermez.s3-eu-west-1.amazonaws.com/powersOfTau28_hez_final_${POWER}.ptau -o $SRS
$SNARKJS powersoftau new $CURVE ${POWER} /tmp/pot${POWER}_0000.ptau -v
$SNARKJS powersoftau contribute /tmp/pot${POWER}_0000.ptau /tmp/pot${POWER}_0001.ptau --name="First contribution" -v
$SNARKJS powersoftau prepare phase2 /tmp/pot${POWER}_0001.ptau $SRS -v
fi

echo ">>> groth16 scheme <<< "
if [ "$2" = "true" ]; then
echo "1. generate groth16 zkey"
Expand All @@ -62,14 +65,20 @@ if [ $snark_type = "groth16" ]; then
echo "4. verify groth16 proof"
$SNARKJS g16v $WORK_DIR/verification_key.json $WORK_DIR/public.json $WORK_DIR/proof.json

echo "5. generate verifier contract"
$SNARKJS zkesv $WORK_DIR/g16.zkey ${CUR_DIR}/aggregation/contracts/final_verifier.sol
if [ $CURVE = "bn128" ]; then
echo "5. generate verifier contract"
$SNARKJS zkesv $WORK_DIR/g16.zkey ${CUR_DIR}/aggregation/contracts/final_verifier.sol

echo "6. calculate verify gas cost"
cd aggregation && npx hardhat test test/final.test.ts
fi
echo "6. calculate verify gas cost"
cd aggregation && npx hardhat test test/final.test.ts
fi
fi

else
if [ $CURVE != "bn128" ]; then
echo "Not support bls12-381"
exit -1
fi
if [ ! -f $BIG_SRS ]; then
echo "downloading powersOfTau28_hez_final_${POWER}.ptau"
curl wget -P build https://hermez.s3-eu-west-1.amazonaws.com/powersOfTau28_hez_final.ptau -o $BIG_SRS
Expand Down
5 changes: 3 additions & 2 deletions test/stark_aggregation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ RUNDIR="${CUR_DIR}/../starkjs"
WORKSPACE=/tmp/aggregation_$CIRCUIT

first_run=${1-no}
CURVE=${2-bn128}
if [ $first_run = "yes" ]; then
rm -rf $WORKSPACE && mkdir -p $WORKSPACE
fi
Expand Down Expand Up @@ -137,9 +138,9 @@ final_end=$(date +%s)
snark_start=$(date +%s)

if [ $first_run = "yes" ]; then
$CUR_DIR/snark_verifier.sh groth16 true
$CUR_DIR/snark_verifier.sh groth16 true $CURVE
else
$CUR_DIR/snark_verifier.sh groth16 false
$CUR_DIR/snark_verifier.sh groth16 false $CURVE
fi

snark_end=$(date +%s)
Expand Down

0 comments on commit 7c024a9

Please sign in to comment.