Skip to content

Commit

Permalink
feat(plonky2): introduced Plonky2VerifyError
Browse files Browse the repository at this point in the history
  • Loading branch information
nickysn committed Jun 7, 2024
1 parent 41902a8 commit 03e0b33
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions compiler/noirc_evaluator/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ impl From<Plonky2GenError> for RuntimeError {
}
}

#[derive(Debug, PartialEq, Eq, Clone, Error)]
pub enum Plonky2VerifyError {
#[error("PLONKY2 backend verification error: {}", .message)]
VerificationFailed { message: String },
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum SsaReport {
Warning(InternalWarning),
Expand Down
10 changes: 5 additions & 5 deletions compiler/noirc_evaluator/src/ssa/plonky2_gen/circuit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::config::{P2CircuitData, P2Field, P2ProofWithPublicInputs};
use super::noir_to_plonky2_field;
use crate::errors::Plonky2GenError;
use crate::errors::{Plonky2GenError, Plonky2VerifyError};
use acvm::acir::native_types::WitnessMap;
use acvm::FieldElement;
use noirc_abi::{input_parser::InputValue, InputMap};
Expand Down Expand Up @@ -114,24 +114,24 @@ impl Plonky2Circuit {
&self,
proof: &[u8],
public_inputs: WitnessMap<FieldElement>,
) -> Result<bool, Plonky2GenError> {
) -> Result<bool, Plonky2VerifyError> {
let deserialized_proof: P2ProofWithPublicInputs = match serde_json::from_slice(proof) {
Ok(deserialized_proof) => deserialized_proof,
Err(error) => {
let error_message = format!("Unexpected deserialization error: {:?}", error);
return Err(Plonky2GenError::ICE { message: error_message });
return Err(Plonky2VerifyError::VerificationFailed { message: error_message });
}
};
if !Self::verify_public_inputs_in_proof(public_inputs, &deserialized_proof) {
return Err(Plonky2GenError::ICE {
return Err(Plonky2VerifyError::VerificationFailed {
message: "Public inputs don't match proof".to_string(),
});
}
match self.data.verify(deserialized_proof) {
Ok(_) => Ok(true),
Err(error) => {
let error_message = format!("Unexpected proof verification failure: {:?}", error);
Err(Plonky2GenError::ICE { message: error_message })
Err(Plonky2VerifyError::VerificationFailed { message: error_message })
}
}
}
Expand Down

0 comments on commit 03e0b33

Please sign in to comment.