Skip to content

Commit

Permalink
fix: minor nits and refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
Al-Kindi-0 committed Oct 17, 2023
1 parent 6307022 commit 064daa8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 33 deletions.
18 changes: 13 additions & 5 deletions verifier/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,16 @@ pub enum VerifierError {
/// constraint evaluation queries do not represent a polynomial of the degree expected by the
/// verifier.
FriVerificationFailed(fri::VerifierError),
/// This error occurs when the parameters, that were used to generate the proof, do not provide
/// a conjectured security level greater than or equal to the conjectured security level
/// expected by the verifier.
InsufficientConjecturedSecurity(u32, u32),
/// This error occurs when the parameters, that were used to generate the proof, do not provide
/// a proven security level greater than or equal to the proven security level expected by
/// the verifier.
InsufficientProvenSecurity(u32, u32),
/// This error occurs when the parameters, that were used to generate the proof, do not match
/// any of the set of parameters expected by the verifier.
UnacceptableProofOptions,
}

Expand Down Expand Up @@ -77,13 +85,13 @@ impl fmt::Display for VerifierError {
Self::FriVerificationFailed(err) => {
write!(f, "verification of low-degree proof failed: {err}")
}
Self::InsufficientConjecturedSecurity(minimal_security,proofs_security)=> {
write!(f, "verification failed due to parameters not providing enough conjectured security: expected at least {minimal_security} bits of security but the proof provides only {proofs_security} bits of conjectured security")
Self::InsufficientConjecturedSecurity(minimal_security, proof_security)=> {
write!(f, "insufficient proof security level: expected at least {minimal_security} bits of conjectured security, but was {proof_security} bits")
}
Self::InsufficientProvenSecurity(minimal_security,proofs_security)=> {
write!(f, "verification failed due to parameters not providing enough proven security: expected at least {minimal_security} bits of security but the proof provides only {proofs_security} bits of proven security")
Self::InsufficientProvenSecurity(minimal_security, proof_security)=> {
write!(f, "insufficient proof security level: expected at least {minimal_security} bits of proven security, but was {proof_security} bits")
}
Self::UnacceptableProofOptions => {write!(f, "verification failed due to parameters not providing enough security: the proof was generated with a set of parameters not accepted by the verifier")}
Self::UnacceptableProofOptions => {write!(f, "invalid proof options: security parameters do not match the acceptable parameter set")}
}
}
}
67 changes: 39 additions & 28 deletions verifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ use math::{
};

pub use utils::{
ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable, SliceReader,
collections::Vec, ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable,
SliceReader,
};

pub use crypto;
use crypto::{ElementHasher, RandomCoin};
use crypto::{ElementHasher, Hasher, RandomCoin};

use fri::FriVerifier;

Expand Down Expand Up @@ -84,7 +85,7 @@ pub use errors::VerifierError;
pub fn verify<AIR, HashFn, RandCoin>(
proof: StarkProof,
pub_inputs: AIR::PublicInputs,
acceptable_options: &AcceptableOptions,
acceptable_options: &AcceptableOptions,
) -> Result<(), VerifierError>
where
AIR: Air,
Expand All @@ -93,31 +94,7 @@ where
{
// check that `proof` was generated with an acceptable set of parameters from the point of view
// of the verifier
match acceptable_options {
AcceptableOptions::MinConjecturedSecurity(minimal_security) => {
let proof_security = proof.security_level::<HashFn>(true);
if proof_security < *minimal_security {
return Err(VerifierError::InsufficientConjecturedSecurity(
*minimal_security,
proof_security,
));
}
}
AcceptableOptions::MinProvenSecurity(minimal_security) => {
let proof_security = proof.security_level::<HashFn>(false);
if proof_security < *minimal_security {
return Err(VerifierError::InsufficientProvenSecurity(
*minimal_security,
proof_security,
));
}
}
AcceptableOptions::OptionSet(options) => {
if !options.iter().any(|opt| opt == proof.options()) {
return Err(VerifierError::UnacceptableProofOptions);
}
}
}
let _ = acceptable_options.validate::<HashFn>(&proof);

// build a seed for the public coin; the initial seed is a hash of the proof context and the
// public inputs, but as the protocol progresses, the coin will be reseeded with the info
Expand Down Expand Up @@ -323,7 +300,41 @@ where
// Specifies either the minimal, conjectured or proven, security level or a set of
// `ProofOptions` that are acceptable by the verification procedure.
pub enum AcceptableOptions {
/// Minimal acceptable conjectured security level
MinConjecturedSecurity(u32),
/// Minimal acceptable proven security level
MinProvenSecurity(u32),
/// Set of acceptable proof parameters
OptionSet(Vec<ProofOptions>),
}

impl AcceptableOptions {
pub fn validate<H: Hasher>(&self, proof: &StarkProof) -> Result<(), VerifierError> {
match self {
AcceptableOptions::MinConjecturedSecurity(minimal_security) => {
let proof_security = proof.security_level::<H>(true);
if proof_security < *minimal_security {
return Err(VerifierError::InsufficientConjecturedSecurity(
*minimal_security,
proof_security,
));
}
}
AcceptableOptions::MinProvenSecurity(minimal_security) => {
let proof_security = proof.security_level::<H>(false);
if proof_security < *minimal_security {
return Err(VerifierError::InsufficientProvenSecurity(
*minimal_security,
proof_security,
));
}
}
AcceptableOptions::OptionSet(options) => {
if !options.iter().any(|opt| opt == proof.options()) {
return Err(VerifierError::UnacceptableProofOptions);
}
}
}
Ok(())
}
}

0 comments on commit 064daa8

Please sign in to comment.