-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Implement comprehensive error handling in verify.cairo #23
Conversation
Key changes: - Added Result-based error handling - Implemented detailed error checks for curve points and field elements - Added granular error messages for debugging - Updated all functions to use proper error propagation - Improved error reporting for verification failures
use plonk_verifier::pairing::tate_bkls::{tate_pairing, tate_miller_loop}; | ||
use plonk_verifier::pairing::optimal_ate::{single_ate_pairing, ate_miller_loop}; | ||
use plonk_verifier::plonk::transcript::{TranscriptTrait, Keccak256Transcript}; | ||
use plonk_verifier::errors::{PlonkError, Result}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you link this file into the PR
|
||
result | ||
Result::Ok(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we are returning True here? Let's fix with proper result that we want
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also reduce all Result::Ok() into just Ok()
if !Self::is_on_curve(proof.A) { | ||
return Result::Err(PlonkError::InvalidCurvePoint('Point A is not on curve')); | ||
} | ||
if !Self::is_on_curve(proof.B) { | ||
return Result::Err(PlonkError::InvalidCurvePoint('Point B is not on curve')); | ||
} | ||
if !Self::is_on_curve(proof.C) { | ||
return Result::Err(PlonkError::InvalidCurvePoint('Point C is not on curve')); | ||
} | ||
if !Self::is_on_curve(proof.Z) { | ||
return Result::Err(PlonkError::InvalidCurvePoint('Point Z is not on curve')); | ||
} | ||
if !Self::is_on_curve(proof.T1) { | ||
return Result::Err(PlonkError::InvalidCurvePoint('Point T1 is not on curve')); | ||
} | ||
if !Self::is_on_curve(proof.T2) { | ||
return Result::Err(PlonkError::InvalidCurvePoint('Point T2 is not on curve')); | ||
} | ||
if !Self::is_on_curve(proof.T3) { | ||
return Result::Err(PlonkError::InvalidCurvePoint('Point T3 is not on curve')); | ||
} | ||
if !Self::is_on_curve(proof.Wxi) { | ||
return Result::Err(PlonkError::InvalidCurvePoint('Point Wxi is not on curve')); | ||
} | ||
if !Self::is_on_curve(proof.Wxiw) { | ||
return Result::Err(PlonkError::InvalidCurvePoint('Point Wxiw is not on curve')); | ||
} | ||
|
||
// Validate field elements | ||
if !Self::is_in_field(proof.eval_a) { | ||
return Result::Err(PlonkError::InvalidFieldElement('eval_a not in field')); | ||
} | ||
if !Self::is_in_field(proof.eval_b) { | ||
return Result::Err(PlonkError::InvalidFieldElement('eval_b not in field')); | ||
} | ||
if !Self::is_in_field(proof.eval_c) { | ||
return Result::Err(PlonkError::InvalidFieldElement('eval_c not in field')); | ||
} | ||
if !Self::is_in_field(proof.eval_s1) { | ||
return Result::Err(PlonkError::InvalidFieldElement('eval_s1 not in field')); | ||
} | ||
if !Self::is_in_field(proof.eval_s2) { | ||
return Result::Err(PlonkError::InvalidFieldElement('eval_s2 not in field')); | ||
} | ||
if !Self::is_in_field(proof.eval_zw) { | ||
return Result::Err(PlonkError::InvalidFieldElement('eval_zw not in field')); | ||
} | ||
|
||
// Validate public inputs | ||
if !Self::check_public_inputs_length(verification_key.nPublic, publicSignals.len().into()) { | ||
return Result::Err(PlonkError::InvalidPublicInput('Public inputs length mismatch')); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make this cleaner by creating a helper function to wrap each call (probably place this in the error file you have made) and have it so that this helper function outputs as a Result type. This way we can just call this helper function and error handle it with "?" all in one line.
if !Self::is_on_curve(proof.A) { | ||
return Result::Err(PlonkError::InvalidCurvePoint('Point A is not on curve')); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make the code more visible by importing the Result::Errr and PlonkError::InvalidCurvePoint directly. This way we can just have a simple Err(InvalidCurvePoint(' '));
|
||
result | ||
Result::Ok(true) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clean same thing as before in the code below.
|
||
result | ||
Ok(()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return Ok(result)
Error Handling Implementation for Cairo PLONK Verifier
Overview
This PR implements comprehensive error handling for the PLONK verifier in Cairo, transforming the codebase to use Result types and providing detailed error information for debugging and validation.
Key Changes
Error Handling System
Code Improvements
?
operatorError Types
Testing