iden3 / snarkjs

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

Exported PLONK verifier contract is different on Mac, compared to Linux #145

Open danicuki opened 2 years ago

danicuki commented 2 years ago

This is my circuit:

pragma circom 2.0.4;

// [assignment] Modify the circuit below to perform a multiplication of three signals

template Multiplier3 () {  

   // Declaration of signals.  
   signal input a;  
   signal input b;
   signal temp1;
   signal input c;
   signal output d;

   // Constraints.  
   temp1 <== a*b;
   d <== temp1*c;
}

component main = Multiplier3();

When I compile and export the PLONK solidity file on Mac, I got these lines different from the Linux version:

When I try to run a test on the Mac version, it fails, while the test on linux passes. Test code:

describe("Multiplier3 with PLONK", function () {
  let Verifier;
  let verifier;

  beforeEach(async function () {
    Verifier = await ethers.getContractFactory("PlonkVerifier");
    verifier = await Verifier.deploy();
    await verifier.deployed();
  });

  it("Should return true for correct proof", async function () {
    const { proof, publicSignals } = await plonk.fullProve(
      { a: "1", b: "2", c: "3" },
      "contracts/circuits/Multiplier3_plonk/Multiplier3_js/Multiplier3.wasm",
      "contracts/circuits/Multiplier3_plonk/circuit_final.zkey"
    );

    console.log("1x2x3 =", publicSignals[0]);

    const editedPublicSignals = unstringifyBigInts(publicSignals);
    const editedProof = unstringifyBigInts(proof);

    const calldata = await plonk.exportSolidityCallData(
      editedProof,
      editedPublicSignals
    );
    const p = calldata.split(",")[0];
    const pub_sig = JSON.parse(calldata.split(",")[1]);
    expect(await verifier.verifyProof(p, pub_sig)).to.be.true;
  });

  it("Should return false for invalid proof", async function () {
    expect(await verifier.verifyProof("0x01", [1, 2, 3])).to.be.false;
  });
});

Both envs using: node v16.15.0 circom compiler 2.0.4 snarkjs@0.4.16

alxkzmn commented 2 years ago

I experienced the same issue but after updating snarkjs to 0.4.22 the issue disappeared.