Bug Report
Cairo version: 6a3c423
Current behavior:
A core::circuit circuit whose CircuitInput<N> indices are not contiguous from 0 — either a gap (e.g. using CircuitInput<0> and CircuitInput<2>, skipping <1>) or a non-zero start (e.g. a lone CircuitInput<5>) — causes a compiler panic during Sierra type-specialization instead of producing a clean diagnostic:
thread 'main' panicked at crates/cairo-lang-sierra-generator/src/db.rs:370: Got failure while specializing type `Circuit<(...CircuitInput::<0>, ...CircuitInput::<2>...)>`: Could not specialize type
The Sierra Circuit type assumes its inputs form a contiguous 0..N set, and the non-contiguity is keyed on the input index set of the resulting Circuit<(<output>,)> type (what the output transitively depends on), not merely the syntactically-declared CircuitElements. So selecting a lone non-zero input as a circuit output (e.g. output (CircuitInput<1>,) while inputs <0>, <1> are declared) also crashes the compiler. Reusing the same index in multiple gates (e.g. circuit_add(a, a) with a = CircuitInput<0>) is fine — only the contiguity of the index set matters.
Expected behavior:
A clean compiler diagnostic stating that circuit input indices must form a contiguous 0..N range, rather than an internal compiler panic. A developer refactoring a circuit (deleting a now-unused middle input, or starting indices at 1) reasonably expects an error, not an ICE.
Steps to reproduce:
Compile/run a circuit whose CircuitInput<N> indices have a gap or do not start at 0:
CircuitInput<0> + CircuitInput<1> (contiguous) → compiles and runs (3+2 = 5 mod 7).
- Swap
CircuitInput<1> → CircuitInput<2> (gap at index 1) → ICE.
CircuitInput<5> + CircuitInput<6> (no 0..4) → same ICE.
circuit_add(a, b) with a=<0>, b=<1> but output (b,) = CircuitInput<1> alone → same ICE (output input set {1} is non-contiguous).
Verified with cairo-test --single-file at commit 6a3c423.
Related code:
let a = CircuitElement::<CircuitInput<0>> {};
let b = CircuitElement::<CircuitInput<2>> {}; // GAP at index 1 -> ICE "Could not specialize type Circuit<...>"
let s = circuit_add(a, b); // ... .eval(modulus) -> compiler panic at sierra-generator/db.rs:370
Other information:
- The panic site is the generic type-specialization failure at
crates/cairo-lang-sierra-generator/src/db.rs:362-371, where CoreType::specialize_by_id(...).unwrap_or_else(|err| panic!("Got failure while specializing type {long_id}: {err}")) is hit because the Circuit<...> long-id encodes non-contiguous CircuitInput indices that fail specialize_by_id.
- The circuit builder (
CircuitInput<N> / CircuitElement / circuit_add) lives in corelib/src/circuit.cairo; the Sierra Circuit type encodes its inputs by index and the specializer assumes a contiguous 0..N input set.
- The
core::circuit docs always show circuits using contiguous indices from 0 (CircuitInput<0>, <1>, <2>) without stating that contiguity is required or that violating it is a crash rather than a diagnostic.
- Suggested fix direction: emit a diagnostic when a circuit's transitive input index set is non-contiguous (has a gap or does not start at 0), instead of panicking in the Sierra generator.
Bug Report
Cairo version: 6a3c423
Current behavior:
A
core::circuitcircuit whoseCircuitInput<N>indices are not contiguous from 0 — either a gap (e.g. usingCircuitInput<0>andCircuitInput<2>, skipping<1>) or a non-zero start (e.g. a loneCircuitInput<5>) — causes a compiler panic during Sierra type-specialization instead of producing a clean diagnostic:The Sierra
Circuittype assumes its inputs form a contiguous0..Nset, and the non-contiguity is keyed on the input index set of the resultingCircuit<(<output>,)>type (what the output transitively depends on), not merely the syntactically-declaredCircuitElements. So selecting a lone non-zero input as a circuit output (e.g. output(CircuitInput<1>,)while inputs<0>, <1>are declared) also crashes the compiler. Reusing the same index in multiple gates (e.g.circuit_add(a, a)witha = CircuitInput<0>) is fine — only the contiguity of the index set matters.Expected behavior:
A clean compiler diagnostic stating that circuit input indices must form a contiguous
0..Nrange, rather than an internal compiler panic. A developer refactoring a circuit (deleting a now-unused middle input, or starting indices at 1) reasonably expects an error, not an ICE.Steps to reproduce:
Compile/run a circuit whose
CircuitInput<N>indices have a gap or do not start at 0:CircuitInput<0>+CircuitInput<1>(contiguous) → compiles and runs (3+2 = 5 mod 7).CircuitInput<1>→CircuitInput<2>(gap at index 1) → ICE.CircuitInput<5>+CircuitInput<6>(no0..4) → same ICE.circuit_add(a, b)witha=<0>, b=<1>but output(b,)=CircuitInput<1>alone → same ICE (output input set{1}is non-contiguous).Verified with
cairo-test --single-fileat commit 6a3c423.Related code:
Other information:
crates/cairo-lang-sierra-generator/src/db.rs:362-371, whereCoreType::specialize_by_id(...).unwrap_or_else(|err| panic!("Got failure while specializing type{long_id}: {err}"))is hit because theCircuit<...>long-id encodes non-contiguousCircuitInputindices that failspecialize_by_id.CircuitInput<N>/CircuitElement/circuit_add) lives incorelib/src/circuit.cairo; the SierraCircuittype encodes its inputs by index and the specializer assumes a contiguous0..Ninput set.core::circuitdocs always show circuits using contiguous indices from 0 (CircuitInput<0>,<1>,<2>) without stating that contiguity is required or that violating it is a crash rather than a diagnostic.