Closed ww6726 closed 1 year ago
This error message means that your input file in json format includes too many values for the input signal "a". I guess "a" is an array of signals defined with a size smaller than the number of values given in the input file. Let me know if this is not the case.
Hi @alrubio. That was not the case. But as I was running it again while monitoring the memory use. It seems like the memory ran out. I wonder if that was the case.
Can you send us the code and the input?
hi @alrubio.
Sure! Here are my codes
template mm() { var m = 128; var n = 128; var p = 128; signal input a[m][n]; signal input b[n][p]; signal output c[m][p]; component mm = matmul(m,n,p); mm.a <== a; mm.b <== b; c <== mm.c; } template matmul(m,n,p){ signal input a[m][n]; signal input b[n][p]; signal output c[m][p];
component matEleMulComponent[m][p];
component matEleSumComponent[m][p];
var idx = 0;
for(var i=0;i<m;i++){
for(var j=0;j<p;j++){
matEleMulComponent[i][j] = matEleMul(1,n);
matEleSumComponent[i][j] = matEleSum(1,n);
for(var k =0;k < n;k++){
matEleMulComponent[i][j].a[0][k] <== a[i][k];
matEleMulComponent[i][j].b[0][k] <== b[k][j];
}
for(var k = 0;k< n;k++){
matEleSumComponent[i][j].a[0][k] <== matEleMulComponent[i][j].out[0][k];
}
c[i][j] <== matEleSumComponent[i][j].out;
}
}
}
template matEleMul(m,n){ signal input a[m][n]; signal input b[m][n]; signal output out[m][n];
for(var i=0;i<m;i++){
for(var j=0;j<n;j++){
out[i][j] <== a[i][j] * b[i][j];
}
}
} template matEleSum(m,n){ signal input a[m][n]; signal output out; signal sum[mn];//signal defines constraints sum[0] <== a[0][0]; var idx = 0; for(var i =0;i<m;i++){ for(var j=0;j<n;j++){ if(idx>0){ sum[idx] <== a[i][j] + sum[idx-1]; } idx++; } } out <== sum[mn-1]; }
The input is too big in this case. Here is the code I use to generate the input:
const fs = require('fs');
const m = 128; const n = 128; const p = 128;
const matrixA = []; const matrixB = [];
// Create matrixA for (let i = 0; i < m; i++) { matrixA[i] = []; for (let j = 0; j < n; j++) { matrixA[i][j] = i * n + j + 1; } } // Create matrixB for (let i = 0; i < n; i++) { matrixB[i] = []; for (let j = 0; j < p; j++) { matrixB[i][j] = i + j + 1; } } const input = { a: matrixA, b: matrixB };
const inputJson = JSON.stringify(input);
fs.writeFile('input.json', inputJson, (err) => { if (err) { console.error('Error writing file:', err); } else { console.log('Input data written to file successfully!'); } });
There is no main in your program. Can you send me a github link to your code and the input.json file?
In any case, the limitation in the wasm code is related to the number of signals you have (10 millions would be already too much), but then it fails at the line the wasm in charged, which is not the exception is rising.
I'm quite sure there is something wrong with your input, in particular in the array signal "a".
You can check the witness_calculator.js generated file in the folder your_circuit_name_js/
The exception that raises comes from the line 149
throw new Error(Too many values for input signal ${k}\n
);
which happens when reading the input and checking that the size of the input array and the size of the signal array coincide.
You may also try with the C code, where there is no restriction on the number of signals and if the same exception rises it will confirm that the error is in the input.
Hi.
I am building a circuit for matrix multiplication. As I am scale up to 128x128 times 128x128, the program was killed with an error saying "(node:31079) UnhandledPromiseRejectionWarning: Error: Too many values for input signal a".
Can someone tell me what is the maximum number of constraints circom can support?