Zokrates / ZoKrates

A toolbox for zkSNARKs on Ethereum
https://zokrates.github.io
GNU Lesser General Public License v3.0
1.83k stars 361 forks source link

Generates wrong proof #1323

Open ray837 opened 1 year ago

ray837 commented 1 year ago

Description

Generates wrong proof for given zokrates code ,which generates false as ouput every time when verified.Below code is implemented in reactjs app. const runZokrates = async () => { const zokratesProvider = await initialize(); const code = def main(private field a) -> field { return true; }; const artifacts = await zokratesProvider.compile(code);

  const {witness,output} =  await zokratesProvider.computeWitness(artifacts,["2"]);

  console.log(witness); // Resulting witness which can be used to generate a proof
  console.log(output); // Computation output: "4"

  setWitness(witness);
  setOutput(output);

  const keypair = await zokratesProvider.setup(artifacts.program);
  setkeypair(keypair)

  const proof = await zokratesProvider.generateProof(artifacts.program,witness,keypair);
  setproof(proof)

//  console.log([proof.proof.a, proof.proof.b, proof.proof.c], proof.inputs);

  const { ethereum } = window;
  const provider = new ethers.providers.Web3Provider(ethereum);
  const signer = provider.getSigner();
  const contract = "0x2e48698055571a60cA9Fb9F052254d4e7A097092";

  const con = new ethers.Contract(contract,Verifier.abi,signer);
  console.log(con)
  const res = await con.verifyTx([proof.proof.a,proof.proof.b,proof.proof.c],proof.inputs);

  const isVerified = zokratesProvider.verify(keypair.vk, proof);
  //console.log(isVerified)
  console.log('Proof:', proof);
  console.log('Is Verified:', isVerified);
  console.log("Res"+res)

};

runZokrates();
dark64 commented 1 year ago

const code = def main(private field a) -> field { return true; };

This code is semantically invalid and should not compile?