diff --git a/crates/cairo-lang-sierra-to-casm/src/invocations/circuit.rs b/crates/cairo-lang-sierra-to-casm/src/invocations/circuit.rs index 6ef56504d01..59f40d98304 100644 --- a/crates/cairo-lang-sierra-to-casm/src/invocations/circuit.rs +++ b/crates/cairo-lang-sierra-to-casm/src/invocations/circuit.rs @@ -479,7 +479,12 @@ fn build_get_output( let CircuitInfo { values, .. } = builder.program_info.circuits_info.circuits.get(circuit_ty).unwrap(); - let output_offset = values.get(output_ty).unwrap(); + let Some(output_offset) = values.get(output_ty) else { + return Err(InvocationError::InvalidCircuitOutput { + output_ty: output_ty.clone(), + circuit_ty: circuit_ty.clone(), + }); + }; add_input_variables! {casm_builder, deref values_ptr; diff --git a/crates/cairo-lang-sierra-to-casm/src/invocations/mod.rs b/crates/cairo-lang-sierra-to-casm/src/invocations/mod.rs index 4aadfc973e8..cad7559c85c 100644 --- a/crates/cairo-lang-sierra-to-casm/src/invocations/mod.rs +++ b/crates/cairo-lang-sierra-to-casm/src/invocations/mod.rs @@ -89,6 +89,8 @@ pub enum InvocationError { // TODO(lior): Remove this error once not used. #[error("This libfunc does not support pre-cost metadata yet.")] PreCostMetadataNotSupported, + #[error("{output_ty} is not a contained in the circuit {circuit_ty}.")] + InvalidCircuitOutput { output_ty: ConcreteTypeId, circuit_ty: ConcreteTypeId }, } /// Describes a simple change in the ap tracking itself. diff --git a/crates/cairo-lang-sierra/src/extensions/modules/circuit.rs b/crates/cairo-lang-sierra/src/extensions/modules/circuit.rs index f716bd99511..f782835db31 100644 --- a/crates/cairo-lang-sierra/src/extensions/modules/circuit.rs +++ b/crates/cairo-lang-sierra/src/extensions/modules/circuit.rs @@ -793,7 +793,10 @@ impl NamedLibfunc for GetOutputLibFunc { context: &dyn SignatureSpecializationContext, args: &[GenericArg], ) -> Result { - let (circ_ty, _output_ty) = args_as_two_types(args)?; + let (circ_ty, output_ty) = args_as_two_types(args)?; + if !CIRCUIT_COMPONENTS.contains(&context.get_type_info(output_ty)?.long_id.generic_id) { + return Err(SpecializationError::UnsupportedGenericArg); + } let outputs_ty = context.get_concrete_type(CircuitOutputs::id(), &[GenericArg::Type(circ_ty)])?;