namnc / circom-2-arithc

Circom interpreter to arithmetic circuit description
MIT License
42 stars 8 forks source link

Handle compound assignment operators #63

Open voltrevo opened 1 month ago

voltrevo commented 1 month ago

Eg when running this program:

template network() {
    signal input x;
    signal output y;

    var z = 3;
    z += x; // <----- compound assignment

    y <== z;
}

component main = network();

We get:

Error: RuntimeError(ItemNotDeclared("get_variable_value: DataAccess { name: \"random_3750075181\", access: [] }"))

Compound assignment doesn't need to be implemented for signals, that's handled as an error by circom, eg:

error[T2000]: Typing error found
    ┌─ "./src/assets/circuit.circom":173:5
    │
173 │     y += x;
    │     ^^^^^^ The operator does not match the types of the assigned elements.
 Assignments to signals do not allow the operator =, try using <== or <-- instead

Error: AnalysisError
namnc commented 1 month ago

Yeah I think right now you can do this with Variable but not Signal (in original Circom).

This is a circom extension that we should think carefully about (compound assignment is still a cool feature).