-
Notifications
You must be signed in to change notification settings - Fork 337
Open
Description
Problem
Using Circom version 2.2.2 generates C++ witness generation code that aborts with the following error:
Assertion `!(ctx->componentMemory[mySubcomponents[cmp_index_ref]].inputCounter)' failed.
The issue occurs when scalar inputs (alpha
and beta
) are wired to subcomponents before assigning array signals in a loop.
Environment
- Circom: 2.2.2
- Compiler: g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Minimal Example
Circuit (minimal_inputcounter_bug.circom
):
pragma circom 2.2.2;
template TwoColumnComponent() {
signal input alpha;
signal input beta;
signal input X[2][2];
signal output out;
out <== alpha + beta + X[0][0] + X[0][1] + X[1][0] + X[1][1];
}
template MinimalBug() {
signal input data[4][2];
signal output out;
component comp1 = TwoColumnComponent();
component comp2 = TwoColumnComponent();
// Assertion failure occurs due to this ordering of scalar signals
comp1.alpha <== 1;
comp1.beta <== 2;
comp2.alpha <== 3;
comp2.beta <== 4;
var cursor1 = 0;
var cursor2 = 0;
for (var i = 0; i < 4; i++) {
if (i < 2) {
comp1.X[cursor1][0] <== data[i][0];
comp1.X[cursor1][1] <== data[i][1];
cursor1++;
} else {
comp2.X[cursor2][0] <== data[i][0];
comp2.X[cursor2][1] <== data[i][1];
cursor2++;
}
}
out <== comp1.out + comp2.out;
}
component main = MinimalBug();
Input JSON (minimal_inputcounter_bug_input.json
):
{
"data": [[1,2],[3,4],[5,6],[7,8]]
}
Steps to Reproduce
- Compile the circuit:
circom minimal_inputcounter_bug.circom --r1cs --c --sym -o artifacts
- Build the witness generator:
cd artifacts/minimal_inputcounter_bug_cpp && make
- Run the witness generation (fails with assertion error):
./minimal_inputcounter_bug ../../minimal_inputcounter_bug_input.json witness.wtns
Expected Behavior
Witness generation should complete successfully, resulting in a valid witness.
Actual Behavior
Witness generation aborts with an assertion failure:
minimal_inputcounter_bug: minimal_inputcounter_bug.cpp:193: void MinimalBug_1_run(uint, Circom_CalcWit*): Assertion `!(ctx->componentMemory[mySubcomponents[cmp_index_ref]].inputCounter)' failed.
Aborted (core dumped)
Temporary Workaround
Moving scalar input assignments (alpha
and beta
) after array assignments avoids the issue.
Metadata
Metadata
Assignees
Labels
No labels