Skip to content

Conversation

rubydusa
Copy link

I wrote a solidity verifier template for Groth16 that uses the new BLS12-381 precompiles as defined in EIP-2537

feats:

  • different format for verification key json export using -bls12381-solidity flag in zkey export verificationkey
  • export solidity calldata for new verifier

I implemented this in a way so it could be easy to extend bls12381 solidity verifiers for other zk proof types.

Manual test instructions:

fib.circom:

pragma circom 2.1.4;

template Fib(N) {
	signal input a1;
	signal input a2;

	signal output out;

	if (N == 1) {
		out <== a1; 
	}
	else if (N == 2) {
		out <== a2;
	}
	else {
		var b1 = a1;
		var b2 = a1 + a2;
		var i = N - 2;

		var inter = 0;

		while (i > 0) {
			inter = b2;
			b2 = b2 + b1;
			b1 = inter;
			
			i--;
		}

		out <== b2;
	}

}

component main = Fib(5);

input.json:

{
    "a1": 1,
    "a2": 1
}

run:

# compile
circom fib.circom --r1cs --wasm --prime bls12381

# powers of tau
snarkjs powersoftau new bls12381 10 pot_0000.ptau
snarkjs powersoftau contribute pot_0000.ptau pot_0001.ptau --name="Ram" --entropy="entropy"
snarkjs powersoftau beacon pot_0001.ptau pot_beacon.ptau 0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f 10
snarkjs powersoftau prepare phase2 pot_beacon.ptau pot_final.ptau

# genrerate solidity verifier
snarkjs groth16 setup fib.r1cs pot_final.ptau fib.zkey
snarkjs zkey export verificationkey -bls12381-solidity fib.zkey verification_key.json
snarkjs zkey export solidityverifier fib.zkey verifier.sol

# generate proof calldata
node fib_js/generate_witness.js fib_js/fib.wasm input.json witness.wtns
snarkjs groth16 prove fib.zkey witness.wtns proof.json public.json
snarkjs zkey export soliditycalldata public.json proof.json 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant