AztecProtocol / aztec-packages

Apache License 2.0
173 stars 178 forks source link

bb.js fails proof verification in js #1526

Open critesjosh opened 1 year ago

critesjosh commented 1 year ago

I am able to generate proofs for the circuit in the browser, but verification fails.

Here is the circuit.

The circuit is compiled with nargo version

➜  next-hardhat git:(main) ✗ nargo --version
nargo 0.9.0 (git version hash: 3d1b2522c8d9a0acebff102f9f877c44178c5db5, is dirty: false)

Here is the error:

RuntimeError: null function or function signature mismatch
    at std::__2::shared_ptr<proof_system::plonk::proving_key> proof_system::plonk::initialize_proving_key<proof_system::UltraCircuitBuilder_<barretenberg::field<barretenberg::Bn254FrParams>>>(proof_system::UltraCircuitBuilder_<barretenberg::field<barretenberg::Bn254FrParams>> const&, barretenberg::srs::factories::CrsFactory<curve::BN254>*, unsigned long, unsigned long, proof_system::CircuitType) (02646f1a)
    at proof_system::plonk::UltraComposer::compute_proving_key(proof_system::UltraCircuitBuilder_<barretenberg::field<barretenberg::Bn254FrParams>>&) (02646f1a)
    at proof_system::plonk::UltraComposer::compute_verification_key(proof_system::UltraCircuitBuilder_<barretenberg::field<barretenberg::Bn254FrParams>>&) (02646f1a)
    at acir_proofs::AcirComposer::verify_proof(std::__2::vector<unsigned char, std::__2::allocator<unsigned char>> const&, bool) (02646f1a)
    at acir_verify_proof (02646f1a)
    at BarretenbergWasm.call (barretenberg_wasm.js:169:1)
    at callback (comlink.mjs:103:1)

To reproduce:

  1. Clone this repo
  2. cd into next-hardhat, install dependencies with yarn
  3. clone submodules, git submodule update --init --recursive
  4. start app with yarn dev
  5. open browser at localhost:3000 and click "calculate proof"
kobyhallx commented 1 year ago

@critesjosh are you able to demonstrate this with simple test failure or snippet?

critesjosh commented 1 year ago

There are steps to reproduce at the bottom of the issue description.

Savio-Sou commented 1 year ago

@critesjosh I guess what @kobyhallx meant is a minimally reproducible Noir program to ease the uncovering of the underlying bug.

Savio-Sou commented 1 year ago

And just to clarify, is this verification failing with bb.js's verify API in Next.js directly? (I.e. Not through a Solidity verifier?)

critesjosh commented 1 year ago

Correct, this is verification failure with bb.js, not via the Solidity verifier.

metavind commented 1 year ago

@critesjosh are you able to demonstrate this with simple test failure or snippet?

This implementation of Relu Circuit is giving an error. The circuit essentially maps each element of the array using the mapping f(x) = max(0, x). Since all field elements are non-negative, a compconstant is selected. All numbers below it are defined to be positive and the numbers above it are defined to be negative.