diff --git a/compiler/noirc_evaluator/src/errors.rs b/compiler/noirc_evaluator/src/errors.rs index c4f56d032f9..bcd6865b721 100644 --- a/compiler/noirc_evaluator/src/errors.rs +++ b/compiler/noirc_evaluator/src/errors.rs @@ -88,6 +88,7 @@ impl From for FileDiagnostic { InternalBug::IndependentSubgraph { call_stack } => { ("There is no path from the output of this brillig call to either return values or inputs of the circuit, which creates an independent subgraph. This is quite likely a soundness vulnerability".to_string(),call_stack) } + InternalBug::AssertFailed { call_stack } => ("As a result, the compiled circuit is ensured to fail. Other assertions may also fail during execution".to_string(), call_stack) }; let call_stack = vecmap(call_stack, |location| location); let file_id = call_stack.last().map(|location| location.file).unwrap_or_default(); @@ -111,6 +112,8 @@ pub enum InternalWarning { pub enum InternalBug { #[error("Input to brillig function is in a separate subgraph to output")] IndependentSubgraph { call_stack: CallStack }, + #[error("Assertion is always false")] + AssertFailed { call_stack: CallStack }, } #[derive(Debug, PartialEq, Eq, Clone, Error)] diff --git a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs index a0be1ee19cf..d12d49784ec 100644 --- a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs +++ b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs @@ -2,7 +2,7 @@ use super::big_int::BigIntContext; use super::generated_acir::{BrilligStdlibFunc, GeneratedAcir, PLACEHOLDER_BRILLIG_INDEX}; use crate::brillig::brillig_gen::brillig_directive; use crate::brillig::brillig_ir::artifact::GeneratedBrillig; -use crate::errors::{InternalError, RuntimeError, SsaReport}; +use crate::errors::{InternalBug, InternalError, RuntimeError, SsaReport}; use crate::ssa::acir_gen::{AcirDynamicArray, AcirValue}; use crate::ssa::ir::dfg::CallStack; use crate::ssa::ir::types::Type as SsaType; @@ -126,6 +126,8 @@ pub(crate) struct AcirContext { big_int_ctx: BigIntContext, expression_width: ExpressionWidth, + + pub(crate) warnings: Vec, } impl AcirContext { @@ -518,6 +520,12 @@ impl AcirContext { self.mark_variables_equivalent(lhs, rhs)?; return Ok(()); } + if diff_expr.is_const() { + // Constraint is always false + self.warnings.push(SsaReport::Bug(InternalBug::AssertFailed { + call_stack: self.get_call_stack(), + })); + } self.acir_ir.assert_is_zero(diff_expr); if let Some(payload) = assert_message { diff --git a/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs b/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs index 0360b15d950..15b44fde65d 100644 --- a/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs +++ b/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs @@ -453,6 +453,7 @@ impl<'a> Context<'a> { } warnings.extend(return_warnings); + warnings.extend(self.acir_context.warnings.clone()); // Add the warnings from the alter Ssa passes Ok(self.acir_context.finish(input_witness, return_witnesses, warnings))