Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with signals length at the generated witness #12

Open
DenisPopov15 opened this issue Jan 13, 2025 · 2 comments
Open

Issue with signals length at the generated witness #12

DenisPopov15 opened this issue Jan 13, 2025 · 2 comments
Assignees

Comments

@DenisPopov15
Copy link

At the example circuit:

pragma circom 2.0.0;

include "circomlib/circuits/poseidon.circom";

/*
 * This is a simple commitment circuit that takes a nullifier and
 * a secret, returning their commitment.
 *
 * The commitment is the result of hashing the secret and the nullifier
 * together via the Poseidon hash function.
 */
template Commitment() {
    signal input nullifier;
    signal input secret;

    signal output commitment;
    signal output nullifierHash;

    component commitmentHash = Poseidon(2);
    commitmentHash.inputs[0] <== nullifier;
    commitmentHash.inputs[1] <== secret;

    commitment <== commitmentHash.out;

    component nullifierHasher = Poseidon(1);
    nullifierHasher.inputs[0] <== nullifier;

    nullifierHash <== nullifierHasher.out;
}

component main = Commitment();

I have an issue, that using build-circuit
Have as result graph with 456 signals

number of nodes 44503, signals 456
Removed 42278 unused nodes
Propagated 20 constants
Global value numbering applied
Found 0 constants
Removed 165 unused nodes
Converted to Montgomery form
number of nodes after optimize 2060, signals 456

and as result witness also have the same length, but zKey have length 935.
When trying to generate proof using snarkjs with zkey and such witness having an error:

Error: Invalid witness length. Circuit: 935, witness: 456

If generate a witness with generate_witness.js - its indeed creating another witness, which have 935 and everything works as expected.

Here is an input json example:

{
    "nullifier": "123",
    "secret": "456"
}

Could you please give a hint on what its could be

@olomix cc

@olomix
Copy link
Contributor

olomix commented Jan 17, 2025

I believe your circuit is completely fine. I think there might be an issue with the zkey generation. It was created using a different r1cs file. I checked your circuit using the test_circuits.sh script, and the test passed.

Please try everything once more. You can refer to the steps for generating the witness and proof from the test_circuits.sh script.

@DenisPopov15
Copy link
Author

@olomix Ok, FYI: it seems I solved the issue.
I did the same as you - put this circuit to the test circuits to be executed by test_circuits.sh

And I had the same issue as before. (935 and 456 different lengths)

About this test here - I found that the issue was that I had 2 circom compilers (2.1.9 which comes with zkit : https://github.com/dl-solarity/hardhat-zkit) and 2.2.1 which I manually compiled from latest code base repo
(and seems somehow to compile circuit at the test 2.1.9 was used, but circom alliance which calling from test_circuits.sh use 2.2.1), so I had the same issue with different signals length

So I put everywhere 2.1.9 and tests here start passing for me.

Also, I will leave it here in case somebody bumps into this with zkit like me - to make zkit artifacts compatible with this lib - you need to set at the zkit config: optimization: '02' at the zkit.compilationSettings

Was forced to dive deep into the code to understand that.

Thank you!
All my issues are resolved - please fill free to mark this issue as resolved, thnx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants