iden3 / circom

zkSnark circuit compiler
GNU General Public License v3.0
1.34k stars 266 forks source link

EdDSAPoseidonVerifier verification failed. #300

Closed Subway2023 closed 1 month ago

Subway2023 commented 1 month ago

circuit.circom

include "../node_modules/circomlib/circuits/eddsaposeidon.circom";

template OwnershipProof() {
    // Signal definitions
    /** Private inputs */
    signal input note;
    signal input pub_key[2];
    signal input sig[3];
    component eddsa = EdDSAPoseidonVerifier();
    eddsa.enabled <== 0;
    eddsa.M <== note;
    eddsa.Ax <== pub_key[0];
    eddsa.Ay <== pub_key[1];
    eddsa.R8x <== sig[0];
    eddsa.R8y <== sig[1];
    eddsa.S <== sig[2];
}

component main = OwnershipProof();

input.json

{
    "note": "1234567890",
    "pub_key": [
        "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890",
        "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567891"
    ],
    "sig": [
        "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567892",
        "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567893",
        "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567894"
    ]
}

I followed the steps in Tutorial, but ultimately the verification failed.

snarkjs groth16 verify verification_key.json public.json proof.json

[ERROR] snarkJS: Error: Scalar size does not match
    at _multiExp (/root/.local/share/fnm/node-versions/v22.4.0/installation/lib/node_modules/snarkjs/node_modules/ffjavascript/build/main.cjs:4978:19)
    at WasmCurve.multiExpAffine (/root/.local/share/fnm/node-versions/v22.4.0/installation/lib/node_modules/snarkjs/node_modules/ffjavascript/build/main.cjs:5015:22)
    at groth16Verify$1 (/root/.local/share/fnm/node-versions/v22.4.0/installation/lib/node_modules/snarkjs/build/cli.cjs:6171:31)
    at async Object.groth16Verify [as action] (/root/.local/share/fnm/node-versions/v22.4.0/installation/lib/node_modules/snarkjs/build/cli.cjs:13017:21)
    at async clProcessor (/root/.local/share/fnm/node-versions/v22.4.0/installation/lib/node_modules/snarkjs/build/cli.cjs:483:27)
Arvolear commented 1 month ago

Hey, @Subway2023, you are getting this error because your circuit has no public signals. You can fix it by making the note signal public as this is the public data anyway.

Also, please check your inputs, as the values you provide are outside the curve's prime field.

demonsh commented 1 month ago

Hi @Subway2023 It was a bug in snarkjs. This PR fix the issue https://github.com/iden3/ffjavascript/pull/161 After next release of snarkjs the issue must be resolved.