iden3 / circom

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

How to use two independent outputs in one circuit? #114

Closed mlshv closed 2 years ago

mlshv commented 2 years ago

Hello circom people! I've tried to find a similar issue or a documentation for my case, but didn't succeed. Please help 🥲

I'm trying to create a simple circuit which has two inputs: secret (private) and wallet (public). In this circuit i calculate mimc hash for wallet + secret and secret. But when i try to verify it, i get the following error:

[ERROR] snarkJS: Error: Invalid witness length. Circuit: 276, witness: 549

But if i calculate only one hash with single output it works ok. What am i doing wrong?

This is my circuit:

pragma circom 2.0.7;

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

template Hash() {
  signal input preimage;
  signal output out;

  component mimc = MiMCSponge(1, 91, 1); // (nInputs, nRounds, nOutputs)
  mimc.k <== 1;
  mimc.ins[0] <== preimage;

  out <== mimc.outs[0];
}

template Main() {
    signal input secret;
    signal input wallet;
    signal output outs[2];

    component walletSecretHash = Hash();
    walletSecretHash.preimage <== secret + wallet;
    outs[0] <== walletSecretHash.out;

    component secretHash = Hash();
    secretHash.preimage <== secret;
    outs[1] <== secretHash.out;
}

component main {public [wallet]} = Main();
mlshv commented 2 years ago

I think i fixed the issue by using bigger ptau file