iden3 / snarkjs

zkSNARK implementation in JavaScript & WASM
GNU General Public License v3.0
1.75k stars 421 forks source link

How to solve the incompatibility problem in snark.js of the witness file generated by go-rapidsnark? #511

Open doubiliu opened 1 month ago

doubiliu commented 1 month ago

I used the CalculateBinWitness method of the go-rapidsnark library to generate a witness file, and now I need to check it in snarkjs. I use snarkjs wtns check circuit1.r1cs witness.wtns and the result shows snarkJS: WITNESS CHECKING FINISHED UNSUCCESSFULLY. How should I solve this problem @jbaylina

doubiliu commented 1 month ago

My generate code: `func TestCircom1CalculateWitness(t *testing.T) { wasmFilename := "testdata/test_files/circuit1.wasm" inputsFilename := "testdata/test_files/input.json"

wasmBytes, err := os.ReadFile(wasmFilename)
require.NoError(t, err)
inputBytes, _ := os.ReadFile(inputsFilename)
require.NoError(t, err)

var ops []witness.Option = []witness.Option{witness.WithWasmEngine(wasmer.NewCircom2WitnessCalculator)}
calc, err := witness.NewCalculator(wasmBytes, ops...)
require.NoError(t, err)

inputs, err := witness.ParseInputs(inputBytes)
require.NoError(t, err)
wtnsBytes, err := calc.CalculateBinWitness(inputs, true)
require.NoError(t, err)
require.NotEmpty(t, wtnsBytes)
_ = ioutil.WriteFile("testdata/test_files/witness.wtns", wtnsBytes, fs.FileMode(defaultFileMode))

}`