diff --git a/src/testers/witnessTester.ts b/src/testers/witnessTester.ts index a105cfc..5e47f49 100644 --- a/src/testers/witnessTester.ts +++ b/src/testers/witnessTester.ts @@ -222,7 +222,8 @@ export class WitnessTester signalDotCount === dotCount(s)); + const symbolNames = Object.keys(this.symbols!).filter(s => + s.startsWith(`main.${signal}`) && signalDotCount === dotCount(s)); // get the symbol values from symbol names, ignoring `main.` prefix // the matched symbols must exactly equal the signal diff --git a/tests/circuits/multiout.circom b/tests/circuits/multiout.circom new file mode 100644 index 0000000..8911b5c --- /dev/null +++ b/tests/circuits/multiout.circom @@ -0,0 +1,24 @@ +pragma circom 2.0.0; + +template Multiout(N) { + signal input a[N]; + signal input b[N]; + var newSize = N + N - 1; + signal output cOut[N]; + signal output aOut[newSize]; + signal output bOut[newSize]; + + var a1[newSize]; + var b1[newSize]; + var c1[N]; + for(var i = 0; i { + let circomkit: Circomkit; let circuit: WitnessTester<['in'], ['out']>; const { circuit: {name, config, size, exact}, @@ -11,7 +12,7 @@ describe('witness tester', () => { } = prepareMultiplier(4); beforeAll(async () => { - const circomkit = new Circomkit({ + circomkit = new Circomkit({ verbose: false, logLevel: 'silent', circuits: './tests/circuits.json', @@ -46,6 +47,40 @@ describe('witness tester', () => { expect(output.out).toEqual(BigInt(signals.output.out)); }); + it('should compute correctly with multiple output signals', async () => { + const N = 167; + const newSize = N + N - 1; + const a = 2; + const b = 3; + const aOut = Array(newSize).fill(0).map((_, i) => BigInt(i < N ? a * i : 0)); + const bOut = Array(newSize).fill(0).map((_, i) => BigInt(i < N ? b * i : 0)); + const cOut = Array(N).fill(BigInt(a * b)); + + const circuit2 = await circomkit.WitnessTester('multiout', { + file: 'multiout', + template: 'Multiout', + params: [N], + }); + + const input = { + a: Array(N).fill(a), + b: Array(N).fill(b), + }; + const output = await circuit2.compute(input, ['aOut', 'bOut', 'cOut']); + + expect(output).toHaveProperty('aOut'); + expect(output).toHaveProperty('bOut'); + expect(output).toHaveProperty('cOut'); + expect(output.aOut).toHaveLength(newSize); + expect(output.bOut).toHaveLength(newSize); + expect(output.cOut).toHaveLength(N); + expect(output.aOut).toEqual(aOut); + expect(output.bOut).toEqual(bOut); + expect(output.cOut).toEqual(cOut); + + await circuit2.expectPass(input, output); + }); + it('should read witness correctly', async () => { const witness = await circuit.calculateWitness(signals.input); const symbol = 'main.out';