Skip to content

Array bound checking in component signals #60

@ed255

Description

@ed255

The following circuit makes circom crash instead of detecting an out of bounds array access attempt in f.out.

template foo() {
        signal input in[2];
        signal output out[2];
}

template test() {
        signal input a[2];
        signal b[2];

        component f = foo();
        for (var i=0; i<2; i++) { f.in[i] <== a[i]; }

        for (var i=0; i<4; i++) { b[i] <== f.out[i]; }
}

component main = test();

Tested on circom 0.5.11, error:

$ ./node_modules/.bin/circom test1.circom
TypeError: Cannot read property 'o' of undefined
    at joinSignals (/root/tmp/circom-test/node_modules/circom/src/construction_phase.js:424:27)
    at execAssignement (/root/tmp/circom-test/node_modules/circom/src/construction_phase.js:395:17)
    at execSignalAssignConstrain (/root/tmp/circom-test/node_modules/circom/src/construction_phase.js:942:15)
    at exec (/root/tmp/circom-test/node_modules/circom/src/construction_phase.js:111:20)
    at execBlock (/root/tmp/circom-test/node_modules/circom/src/construction_phase.js:535:9)
    at exec (/root/tmp/circom-test/node_modules/circom/src/construction_phase.js:192:16)
    at execLoop (/root/tmp/circom-test/node_modules/circom/src/construction_phase.js:746:9)
    at exec (/root/tmp/circom-test/node_modules/circom/src/construction_phase.js:196:16)
    at execBlock (/root/tmp/circom-test/node_modules/circom/src/construction_phase.js:535:9)
    at instantiateComponent (/root/tmp/circom-test/node_modules/circom/src/construction_phase.js:522:9)
Cannot read property 'o' of undefined

If the out of bounds error is from a signal inside the component, the proper error is reported:

template test() {
        signal input a[2];
        signal b[2];

        for (var i=0; i<4; i++) { b[i] <== a[i]; }
}

component main = test();

Tested on circom 0.5.11, result:

$ ./node_modules/.bin/circom test2.circom
undefined
ERROR at /root/tmp/circom-test/test2.circom:5,36-5,40   Out of Range
{
 "type": "VARIABLE",
 "name": "a",
 "selectors": [
  {
   "type": "VARIABLE",
   "name": "i",
   "selectors": [],
   "first_line": 5,
   "first_column": 38,
   "last_line": 5,
   "last_column": 39,
   "refId": 2
  }
 ],
 "first_line": 5,
 "first_column": 36,
 "last_line": 5,
 "last_column": 40,
 "refId": 0
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions