From 874b2bf223d8fbd924371c995a882aa0aaf42195 Mon Sep 17 00:00:00 2001 From: guipublic <47281315+guipublic@users.noreply.github.com> Date: Mon, 6 Nov 2023 15:43:01 +0100 Subject: [PATCH] chore: add warning when using verify_proof (#3429) --- compiler/noirc_evaluator/src/errors.rs | 22 +++++++++------ .../noirc_evaluator/src/ssa/acir_gen/mod.rs | 27 ++++++++++++++----- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/compiler/noirc_evaluator/src/errors.rs b/compiler/noirc_evaluator/src/errors.rs index 2429ca9e194..42672d4d0ad 100644 --- a/compiler/noirc_evaluator/src/errors.rs +++ b/compiler/noirc_evaluator/src/errors.rs @@ -63,16 +63,20 @@ impl From for FileDiagnostic { fn from(error: SsaReport) -> FileDiagnostic { match error { SsaReport::Warning(warning) => { - let InternalWarning::ReturnConstant { ref call_stack } = warning; - let call_stack = vecmap(call_stack, |location| *location); - let file_id = call_stack.last().map(|location| location.file).unwrap_or_default(); let message = warning.to_string(); + let (secondary_message, call_stack) = match warning { + InternalWarning::ReturnConstant { call_stack } => { + ("constant value".to_string(), call_stack) + }, + InternalWarning::VerifyProof { call_stack } => { + ("verify_proof(...) aggregates data for the verifier, the actual verification will be done when the full proof is verified using nargo verify. nargo prove may generate an invalid proof if bad data is used as input to verify_proof".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(); let location = call_stack.last().expect("Expected RuntimeError to have a location"); - let diagnostic = Diagnostic::simple_warning( - message, - "constant value".to_string(), - location.span, - ); + let diagnostic = + Diagnostic::simple_warning(message, secondary_message, location.span); diagnostic.in_file(file_id).with_call_stack(call_stack) } } @@ -83,6 +87,8 @@ impl From for FileDiagnostic { pub enum InternalWarning { #[error("Returning a constant value is not allowed")] ReturnConstant { call_stack: CallStack }, + #[error("Calling std::verify_proof(...) does not verify a proof")] + VerifyProof { call_stack: CallStack }, } #[derive(Debug, PartialEq, Eq, Clone, Error)] diff --git a/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs b/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs index 7307689768f..a849ae59e50 100644 --- a/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs +++ b/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs @@ -26,6 +26,7 @@ use crate::brillig::{brillig_gen::brillig_fn::FunctionContext as BrilligFunction use crate::errors::{InternalError, InternalWarning, RuntimeError, SsaReport}; pub(crate) use acir_ir::generated_acir::GeneratedAcir; +use acvm::acir::BlackBoxFunc; use acvm::{ acir::{circuit::opcodes::BlockId, native_types::Expression}, FieldElement, @@ -213,13 +214,18 @@ impl Context { let dfg = &main_func.dfg; let entry_block = &dfg[main_func.entry_block()]; let input_witness = self.convert_ssa_block_params(entry_block.parameters(), dfg)?; - + let mut warnings = Vec::new(); for instruction_id in entry_block.instructions() { - self.convert_ssa_instruction(*instruction_id, dfg, ssa, &brillig, last_array_uses)?; + warnings.extend(self.convert_ssa_instruction( + *instruction_id, + dfg, + ssa, + &brillig, + last_array_uses, + )?); } - let warnings = self.convert_ssa_return(entry_block.unwrap_terminator(), dfg)?; - + warnings.extend(self.convert_ssa_return(entry_block.unwrap_terminator(), dfg)?); Ok(self.acir_context.finish(vec![input_witness], warnings)) } @@ -377,9 +383,10 @@ impl Context { ssa: &Ssa, brillig: &Brillig, last_array_uses: &HashMap, - ) -> Result<(), RuntimeError> { + ) -> Result, RuntimeError> { let instruction = &dfg[instruction_id]; self.acir_context.set_call_stack(dfg.get_call_stack(instruction_id)); + let mut warnings = Vec::new(); match instruction { Instruction::Binary(binary) => { let result_acir_var = self.convert_ssa_binary(binary, dfg)?; @@ -482,6 +489,14 @@ impl Context { } } Value::Intrinsic(intrinsic) => { + if matches!( + intrinsic, + Intrinsic::BlackBox(BlackBoxFunc::RecursiveAggregation) + ) { + warnings.push(SsaReport::Warning(InternalWarning::VerifyProof { + call_stack: self.acir_context.get_call_stack(), + })); + } let outputs = self .convert_ssa_intrinsic_call(*intrinsic, arguments, dfg, result_ids)?; @@ -558,7 +573,7 @@ impl Context { } } self.acir_context.set_call_stack(CallStack::new()); - Ok(()) + Ok(warnings) } fn gen_brillig_for(