Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verification error when integrating with snarkjs #1330

Open
katamayodi opened this issue Jul 12, 2023 · 0 comments
Open

Verification error when integrating with snarkjs #1330

katamayodi opened this issue Jul 12, 2023 · 0 comments

Comments

@katamayodi
Copy link

katamayodi commented Jul 12, 2023

Description

I'm trying to integrate the compiled circuit from Zokrates into snarkjs. However, the snarkjs throws an error in the final verification phase. The source code of the Zokrates circuit is as follows:

def main(private field a) {
    assert(a == 1);
}

The source code is very simple. However, the snarkjs throws an error saying "Scalar size does not match" when doing the verification.

Environment

  • Zokrates Compiler version: 0.8.7
  • Snarkjs version: 0.7.0
  • Operating system: Ubuntu 22.04.2 LTS

Steps to Reproduce

Save the aforementioned source code as bug.zok. Save the following file as run.sh. Then run bash run.sh.

curve="bn128"
# The snarkjs would also throw an error if the curve "bls12-381" is used.
# curve="bls12-381"
tau_size=8

# Compile Zokrates code
# replace "-" with "_" in curve name
zokrates compile -i bug.zok --curve "${curve//-/_}"

# Perform setup with snarkjs
snarkjs powersoftau new "$curve" "$tau_size" pot"$tau_size"_0000.ptau -v
snarkjs powersoftau contribute pot"$tau_size"_0000.ptau pot"$tau_size"_0001.ptau --name="First contribution" -v -e="Some random text"
snarkjs powersoftau prepare phase2 pot"$tau_size"_0001.ptau pot"$tau_size"_final.ptau -v
snarkjs groth16 setup out.r1cs pot"$tau_size"_final.ptau 0000.zkey
snarkjs zkey contribute 0000.zkey 0001.zkey --name="1st Contributor Name" -v -e="Some other random text"
snarkjs zkey export verificationkey 0001.zkey verification_key.json

# Compute witness with Zokrates
zokrates compute-witness -a 1

# Generate proof with snarkjs
snarkjs groth16 prove 0001.zkey out.wtns proof.json public.json

# Verify proof with snarkjs
snarkjs groth16 verify verification_key.json public.json proof.json

In short, the above script does the following:

  1. Compile the Zokrates code.
  2. Perform the setup phase with snarkjs.
  3. Compute the witness with Zokrates.
  4. Generate the proof with snarkjs.
  5. Verify the proof with snarkjs.

The steps related to snarkjs are referred from the circom document as well as the snarkjs document.

The error occurs in the last step. The error message is as follows:

[ERROR] snarkJS: Error: Scalar size does not match
    at _multiExp (/usr/lib/node_modules/snarkjs/node_modules/ffjavascript/build/main.cjs:4975:19)
    at WasmCurve.multiExpAffine (/usr/lib/node_modules/snarkjs/node_modules/ffjavascript/build/main.cjs:5012:22)
    at groth16Verify$1 (/usr/lib/node_modules/snarkjs/build/cli.cjs:6171:31)
    at async Object.groth16Verify [as action] (/usr/lib/node_modules/snarkjs/build/cli.cjs:13017:21)
    at async clProcessor (/usr/lib/node_modules/snarkjs/build/cli.cjs:483:27)
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

No branches or pull requests

1 participant