iden3 / circom_tester

Provides tools for testing circom circuits.
56 stars 28 forks source link

Add useful function getOutput #22

Open Vieloooo opened 1 year ago

Vieloooo commented 1 year ago

Fix issue mentioned in https://github.com/iden3/circom_tester/issues/9#issuecomment-1233530665

Add a useful function getOutput which extract single output c and one-dimensional output vec[10] from witness. For circom like:

template Multiplier2() {
    signal input a;
    signal input b;
    signal output c;
    signal output vec[10];
    c <== a*b;
    for (var i = 0; i < 10; i++) {
        vec[i] <== a*b;
    }
}
    const w = await circuit.calculateWitness({ a: 3, b:6 });
    const o = await circuit.getOutput(w, [ "c", "vec[10]" ]);
    console.log(o);

Outputs:

{
  'main.c': '18',
  'main.vec[0]': '18',
  'main.vec[1]': '18',
  'main.vec[2]': '18',
  'main.vec[3]': '18',
  'main.vec[4]': '18',
  'main.vec[5]': '18',
  'main.vec[6]': '18',
  'main.vec[7]': '18',
  'main.vec[8]': '18',
  'main.vec[9]': '18'
}