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

Can't run fullProve function #107

Closed
vuvoth opened this issue Oct 25, 2021 · 7 comments · Fixed by iden3/circom_runtime#14 or #121
Closed

Can't run fullProve function #107

vuvoth opened this issue Oct 25, 2021 · 7 comments · Fixed by iden3/circom_runtime#14 or #121

Comments

@vuvoth
Copy link

vuvoth commented Oct 25, 2021

I try running the [email protected] fullProve function on node and browser but it returns the error. I tried to run only prove and it work well, not returning any error.

More info about env:

  • Hardware : Macbook M1
  • node v14.18.1
  • snarkjs 0.4.10
  • circom 2.0
    Error:
snarkjs.min.js:1 Uncaught (in promise) LinkError: WebAssembly.instantiate(): Import #0 module="runtime" function="exceptionHandler" error: function import requires a callable
    at lg (snarkjs.min.js:1)
    at async Gg (snarkjs.min.js:1)
    at async Object.fullProve (snarkjs.min.js:1)
    at async HTMLButtonElement.calculateProof ((index):36)

Thank you for your help!

@vuvoth
Copy link
Author

vuvoth commented Oct 28, 2021

I switch to Circom old version(0.5.46) implemented in javascript and it works well. Thanks.

@vuvoth vuvoth closed this as completed Oct 28, 2021
@connorbode
Copy link

I've just encountered this issue using circom compiler 2.0.1. This issue should perhaps not be closed.

I've had no trouble using the generate_witness.js file created by the circom compiler + snarkjs plonk prove. That leads me to believe the generated wasm is ok.

However when using snarkjs plonk fullprove the same WebAssembly exception mentioned in the issue description occurs.

@vuvoth vuvoth reopened this Nov 22, 2021
@connorbode
Copy link

connorbode commented Nov 22, 2021

I've found a reasonable workaround based on the generate_witness.js file.

For Circuit.circom, the file Circuit_js/witness_calculator.js can be used in JS as follows:

const snarkjs = require('snarkjs')
const fs = require('fs')

const wc = require('/path/to/Circuit_js/witness_calculator.js')
const wasm = '/path/to/Circuit_js/Circuit.wasm'
const zkey = '/path/to/Circuit_final.zkey'
const INPUTS_FILE = '/tmp/inputs'
const WITNESS_FILE = '/tmp/witness'

const generateWitness = async (inputs) => {
  const buffer = fs.readFileSync(wasm);
  const witnessCalculator = await wc(buffer)
  const buff = await witnessCalculator.calculateWTNSBin(inputs, 0);
  fs.writeFileSync(WITNESS_FILE, buff)
}

const main = async () => {
  const inputSignals = { enabled: 1, in: [1, 1] } // replace with your signals
  await generateWitness(inputSignals)
  const { proof, publicSignals } = await snarkjs.plonk.prove(zkey, WITNESS_FILE);
}

@michal-wrzosek
Copy link

thnaks @connorbode
I will also look for some client-side workaround as well. I'm curious what is the core problem here. It would be cool to make snarkjs compatible with new circom.

@connorbode
Copy link

connorbode commented Nov 26, 2021

@michal-wrzosek if you used any of that code, please check the updated generateWitness function. I pulled the code from witness_calculator.js and made quick edits. I didn't realize but the code (1) wrote JSON serialized inputs to disk (2) read the inputs back immediately after (whoops). This may have caused some issues with different data types.

@sragss
Copy link
Contributor

sragss commented Jan 5, 2022

This is definitely happening during the witness creation in snarkjs/src/wtns_calculate.js.

A cleaner workaround that I found (that does not require writing to file) is that you can call snarkjs.plonk.prove(zkey_file, witness_buffer) rather than passing the witness file name.

My best guess is that the generated WASM is not compatible with this version of the circom runtime resulting in more function definitions being required here: https://github.com/iden3/circom_runtime/blob/master/js/witness_calculator.js#L52-L88

@sragss
Copy link
Contributor

sragss commented Jan 5, 2022

This is the version that witness_calculator.js uses, which is generated by the circom cmd tool. Whereas this is the version that snarkjs.plonk.fullProve and snarkjs.wtns.wtns_calculate use.

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