Skip to content

Commit

Permalink
Add validations for circuit outputs. (#5894)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyalesokhin-starkware authored Jun 26, 2024
1 parent 3272fb1 commit cdf8434
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion crates/cairo-lang-sierra-to-casm/src/invocations/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions crates/cairo-lang-sierra-to-casm/src/invocations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion crates/cairo-lang-sierra/src/extensions/modules/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,10 @@ impl NamedLibfunc for GetOutputLibFunc {
context: &dyn SignatureSpecializationContext,
args: &[GenericArg],
) -> Result<LibfuncSignature, SpecializationError> {
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)])?;
Expand Down

0 comments on commit cdf8434

Please sign in to comment.