Skip to content

Commit

Permalink
chore: add warning when using verify_proof (#3429)
Browse files Browse the repository at this point in the history
guipublic authored Nov 6, 2023

Verified

This commit was signed with the committer’s verified signature.
lucacome Luca Comellini
1 parent ff96ba4 commit 874b2bf
Showing 2 changed files with 35 additions and 14 deletions.
22 changes: 14 additions & 8 deletions compiler/noirc_evaluator/src/errors.rs
Original file line number Diff line number Diff line change
@@ -63,16 +63,20 @@ impl From<SsaReport> 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<SsaReport> 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)]
27 changes: 21 additions & 6 deletions compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
@@ -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<ValueId, InstructionId>,
) -> Result<(), RuntimeError> {
) -> Result<Vec<SsaReport>, 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(

0 comments on commit 874b2bf

Please sign in to comment.