fix stack overflow error caused by SynthesisError

This commit is contained in:
collin 2020-08-16 23:13:10 -07:00
parent a704eddb51
commit 55d6dc5cc6
11 changed files with 21 additions and 19 deletions

View File

@ -51,13 +51,19 @@ impl ExpressionError {
pub fn cannot_enforce(operation: String, error: SynthesisError, span: Span) -> Self { pub fn cannot_enforce(operation: String, error: SynthesisError, span: Span) -> Self {
let message = format!( let message = format!(
"the gadget operation `{}` failed due to synthesis error `{}`", "the gadget operation `{}` failed due to synthesis error `{:?}`",
operation, error, operation, error,
); );
Self::new_from_span(message, span) Self::new_from_span(message, span)
} }
pub fn cannot_evaluate(operation: String, span: Span) -> Self {
let message = format!("Mismatched types found for operation `{}`", operation);
Self::new_from_span(message, span)
}
pub fn conditional_boolean(actual: String, span: Span) -> Self { pub fn conditional_boolean(actual: String, span: Span) -> Self {
let message = format!("if, else conditional must resolve to a boolean, found `{}`", actual); let message = format!("if, else conditional must resolve to a boolean, found `{}`", actual);

View File

@ -28,7 +28,7 @@ impl AddressError {
pub fn cannot_enforce(operation: String, error: SynthesisError, span: Span) -> Self { pub fn cannot_enforce(operation: String, error: SynthesisError, span: Span) -> Self {
let message = format!( let message = format!(
"the address operation `{}` failed due to the synthesis error `{}`", "the address operation `{:?}` failed due to the synthesis error `{}`",
operation, error, operation, error,
); );

View File

@ -22,7 +22,7 @@ impl BooleanError {
pub fn cannot_enforce(operation: String, error: SynthesisError, span: Span) -> Self { pub fn cannot_enforce(operation: String, error: SynthesisError, span: Span) -> Self {
let message = format!( let message = format!(
"the boolean operation `{}` failed due to the synthesis error `{}`", "the boolean operation `{}` failed due to the synthesis error `{:?}`",
operation, error, operation, error,
); );

View File

@ -21,14 +21,14 @@ impl FieldError {
} }
pub fn negate_operation(error: SynthesisError, span: Span) -> Self { pub fn negate_operation(error: SynthesisError, span: Span) -> Self {
let message = format!("field negation failed due to synthesis error `{}`", error,); let message = format!("field negation failed due to synthesis error `{:?}`", error,);
Self::new_from_span(message, span) Self::new_from_span(message, span)
} }
pub fn binary_operation(operation: String, error: SynthesisError, span: Span) -> Self { pub fn binary_operation(operation: String, error: SynthesisError, span: Span) -> Self {
let message = format!( let message = format!(
"the field binary operation `{}` failed due to synthesis error `{}`", "the field binary operation `{}` failed due to synthesis error `{:?}`",
operation, error, operation, error,
); );
@ -54,7 +54,7 @@ impl FieldError {
} }
pub fn synthesis_error(error: SynthesisError, span: Span) -> Self { pub fn synthesis_error(error: SynthesisError, span: Span) -> Self {
let message = format!("compilation failed due to field synthesis error `{}`", error); let message = format!("compilation failed due to field synthesis error `{:?}`", error);
Self::new_from_span(message, span) Self::new_from_span(message, span)
} }

View File

@ -21,14 +21,14 @@ impl GroupError {
} }
pub fn negate_operation(error: SynthesisError, span: Span) -> Self { pub fn negate_operation(error: SynthesisError, span: Span) -> Self {
let message = format!("group negation failed due to the synthesis error `{}`", error,); let message = format!("group negation failed due to the synthesis error `{:?}`", error,);
Self::new_from_span(message, span) Self::new_from_span(message, span)
} }
pub fn binary_operation(operation: String, error: SynthesisError, span: Span) -> Self { pub fn binary_operation(operation: String, error: SynthesisError, span: Span) -> Self {
let message = format!( let message = format!(
"the group binary operation `{}` failed due to the synthesis error `{}`", "the group binary operation `{}` failed due to the synthesis error `{:?}`",
operation, error, operation, error,
); );
@ -48,7 +48,7 @@ impl GroupError {
} }
pub fn synthesis_error(error: SynthesisError, span: Span) -> Self { pub fn synthesis_error(error: SynthesisError, span: Span) -> Self {
let message = format!("compilation failed due to group synthesis error `{}`", error); let message = format!("compilation failed due to group synthesis error `{:?}`", error);
Self::new_from_span(message, span) Self::new_from_span(message, span)
} }

View File

@ -23,7 +23,7 @@ impl IntegerError {
pub fn cannot_enforce(operation: String, error: SynthesisError, span: Span) -> Self { pub fn cannot_enforce(operation: String, error: SynthesisError, span: Span) -> Self {
let message = format!( let message = format!(
"the integer operation `{}` failed due to the synthesis error `{}`", "the integer operation `{}` failed due to the synthesis error `{:?}`",
operation, error, operation, error,
); );

View File

@ -47,7 +47,7 @@ pub fn evaluate_eq<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<
} }
}; };
let boolean = constraint_result.map_err(|e| ExpressionError::cannot_enforce(format!("evaluate equal"), e, span))?; let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(format!("=="), span))?;
Ok(ConstrainedValue::Boolean(boolean)) Ok(ConstrainedValue::Boolean(boolean))
} }

View File

@ -36,8 +36,7 @@ pub fn evaluate_ge<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<
} }
}; };
let boolean = constraint_result let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(format!(">="), span))?;
.map_err(|e| ExpressionError::cannot_enforce(format!("evaluate greater than or equal"), e, span))?;
Ok(ConstrainedValue::Boolean(boolean)) Ok(ConstrainedValue::Boolean(boolean))
} }

View File

@ -36,8 +36,7 @@ pub fn evaluate_gt<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<
} }
}; };
let boolean = let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(format!(">"), span))?;
constraint_result.map_err(|e| ExpressionError::cannot_enforce(format!("evaluate greater than"), e, span))?;
Ok(ConstrainedValue::Boolean(boolean)) Ok(ConstrainedValue::Boolean(boolean))
} }

View File

@ -36,8 +36,7 @@ pub fn evaluate_le<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<
} }
}; };
let boolean = constraint_result let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(format!("<="), span))?;
.map_err(|e| ExpressionError::cannot_enforce(format!("evaluate less than or equal"), e, span))?;
Ok(ConstrainedValue::Boolean(boolean)) Ok(ConstrainedValue::Boolean(boolean))
} }

View File

@ -36,8 +36,7 @@ pub fn evaluate_lt<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<
} }
}; };
let boolean = let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(format!("<"), span))?;
constraint_result.map_err(|e| ExpressionError::cannot_enforce(format!("evaluate less than"), e, span))?;
Ok(ConstrainedValue::Boolean(boolean)) Ok(ConstrainedValue::Boolean(boolean))
} }