1

Alice wants to prove a statement (let's say, she has a secret value x such that x * 2 = 10) to Bob without revealing x).

Alice generates a proof using the ZK-Snark protocol.

const { proof, publicSignals } = await snarkjs.groth16.fullProve(
          sampleInput,
          "circuits/quadratic.wasm",
          "circuits/quadratic.zkey"
);
// Construct the raw calldata to be sent to the verifier contract
const rawcalldata = await snarkjs.groth16.exportSolidityCallData(
          proof,
          publicSignals
);
let jsonCalldata = JSON.parse("[" + rawcalldata + "]");

The verifier contract exposes a public function, let's call it "verifyProof," which takes the calldata (proof) provided by the prover. How can one prevent others from calling the verifier contract with the same calldata as the prover?

it("proves the proof", async () => {
        assert.isTrue(
          await verifier.verifyProof(
            jsonCalldata[0],
            jsonCalldata[1],
            jsonCalldata[2],
            jsonCalldata[3]
          )
        );
});
1
  • Context and details about the circuits and the contract are missing in this question, but a general approach for preventing re-using the same proof is setting up a nullifier.
    – Brozorec
    Commented Jun 2 at 5:58

1 Answer 1

0

I think it will depend on the logic of the contract. Two snark proofs generated for the same inputs will look different because they have some randomness added to the proof.

If you want to avoid someone to frontrun your transaction the best option is to include another input into the proof, the address of the sender or a signature, it depends on the logic of the contract.

1
  • 1
    was thinking of nullifiers, but you're correct that it wouldn't help for frontrunning... Although not sure if the original question refers to frontrunning or double spending. Good idea about checking the sender address. Commented Jun 4 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.