Skip to content

Commit

Permalink
added proof option wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbinth committed Oct 16, 2021
1 parent e3da9b2 commit 8e8dbf9
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 48 deletions.
7 changes: 5 additions & 2 deletions air/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@ use vm_core::{
OP_COUNTER_IDX, OP_SPONGE_RANGE,
};
use winter_air::{
Air, AirContext, Assertion, EvaluationFrame, ProofOptions, TraceInfo,
Air, AirContext, Assertion, EvaluationFrame, ProofOptions as WinterProofOptions, TraceInfo,
TransitionConstraintDegree,
};
use winter_utils::{group_slice_elements, ByteWriter, Serializable};

mod decoder;
mod options;
mod stack;
mod transition;
mod utils;

// EXPORTS
// ================================================================================================

pub use options::ProofOptions;
pub use transition::VmTransition;
pub use vm_core::{
utils::ToElements, BaseElement, FieldElement, StarkField, TraceState, MAX_OUTPUTS,
MIN_TRACE_LENGTH,
};
pub use winter_air::{FieldExtension, HashFunction};

// PROCESSOR AIR
// ================================================================================================
Expand All @@ -43,7 +46,7 @@ impl Air for ProcessorAir {
type BaseElement = BaseElement;
type PublicInputs = PublicInputs;

fn new(trace_info: TraceInfo, pub_inputs: PublicInputs, options: ProofOptions) -> Self {
fn new(trace_info: TraceInfo, pub_inputs: PublicInputs, options: WinterProofOptions) -> Self {
let meta = TraceMetadata::from_trace_info(&trace_info);

let mut tcd = decoder::get_transition_constraint_degrees(meta.ctx_depth, meta.loop_depth);
Expand Down
68 changes: 68 additions & 0 deletions air/src/options.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use core::ops::Deref;
use winter_air::{FieldExtension, HashFunction, ProofOptions as WinterProofOptions};

pub struct ProofOptions(WinterProofOptions);

impl ProofOptions {
pub fn new(
num_queries: usize,
blowup_factor: usize,
grinding_factor: u32,
hash_fn: HashFunction,
field_extension: FieldExtension,
fri_folding_factor: usize,
fri_max_remainder_size: usize,
) -> Self {
Self(WinterProofOptions::new(
num_queries,
blowup_factor,
grinding_factor,
hash_fn,
field_extension,
fri_folding_factor,
fri_max_remainder_size,
))
}

pub fn with_96_bit_security() -> Self {
Self(WinterProofOptions::new(
27,
8,
16,
HashFunction::Blake3_192,
FieldExtension::None,
8,
256,
))
}

pub fn with_128_bit_security() -> Self {
Self(WinterProofOptions::new(
36,
8,
21,
HashFunction::Blake3_256,
FieldExtension::Quadratic,
8,
256,
))
}

pub fn into_inner(self) -> WinterProofOptions {
self.0
}
}

impl Default for ProofOptions {
fn default() -> Self {
Self::with_96_bit_security()
}
}

impl Deref for ProofOptions {
type Target = WinterProofOptions;

fn deref(&self) -> &Self::Target {
&self.0
}
}
7 changes: 4 additions & 3 deletions distaff/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use air::{ProcessorAir, PublicInputs, TraceMetadata, TraceState, MAX_OUTPUTS, MIN_TRACE_LENGTH};
use core::convert::TryInto;
use core::{convert::TryInto, ops::Deref};
#[cfg(feature = "std")]
use log::debug;
use prover::{ExecutionTrace, ProverError, Serializable};
Expand All @@ -12,9 +12,10 @@ mod tests;
// EXPORTS
// ================================================================================================

pub use air::{FieldExtension, HashFunction, ProofOptions};
pub use assembly;
pub use processor::{BaseElement, FieldElement, Program, ProgramInputs, StarkField};
pub use prover::{FieldExtension, HashFunction, ProofOptions, StarkProof};
pub use prover::StarkProof;
pub use verifier::{verify, VerifierError};

// EXECUTOR
Expand Down Expand Up @@ -81,7 +82,7 @@ pub fn execute(
.map(|&v| v.as_int())
.collect::<Vec<_>>();
let pub_inputs = PublicInputs::new(program_hash, &inputs, &outputs);
let proof = prover::prove::<ProcessorAir>(trace, pub_inputs, options.clone())?;
let proof = prover::prove::<ProcessorAir>(trace, pub_inputs, options.deref().clone())?;

Ok((outputs, proof))
}
Expand Down
54 changes: 11 additions & 43 deletions examples/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use distaff::{FieldExtension, HashFunction, Program, ProgramInputs, ProofOptions};
use distaff::{Program, ProgramInputs, ProofOptions};
use structopt::StructOpt;

pub mod collatz;
Expand Down Expand Up @@ -30,50 +30,18 @@ pub struct ExampleOptions {
#[structopt(subcommand)]
pub example: ExampleType,

/// Hash function used in the protocol
#[structopt(short = "h", long = "hash_fn", default_value = "blake3_256")]
hash_fn: String,

/// Number of queries to include in a proof
#[structopt(short = "q", long = "queries", default_value = "28")]
num_queries: usize,

/// Blowup factor for low degree extension
#[structopt(short = "b", long = "blowup", default_value = "8")]
blowup_factor: usize,

/// Grinding factor for query seed
#[structopt(short = "g", long = "grinding", default_value = "16")]
grinding_factor: u32,

/// Whether to use field extension for composition polynomial
#[structopt(short = "e", long = "extension")]
field_extension: bool,
/// Security level for execution proofs generated by the VM
#[structopt(short = "s", long = "security", default_value = "96bits")]
security: String,
}

impl ExampleOptions {
pub fn get_proof_options(&self) -> ProofOptions {
let field_extension = if self.field_extension {
FieldExtension::Quadratic
} else {
FieldExtension::None
};
let hash_fn = match self.hash_fn.as_str() {
"blake3_192" => HashFunction::Blake3_192,
"blake3_256" => HashFunction::Blake3_256,
"sha3_256" => HashFunction::Sha3_256,
val => panic!("'{}' is not a valid hash function option", val),
};

ProofOptions::new(
self.num_queries,
self.blowup_factor,
self.grinding_factor,
hash_fn,
field_extension,
8,
256,
)
match self.security.as_str() {
"96bits" => ProofOptions::with_96_bit_security(),
"128bits" => ProofOptions::with_128_bit_security(),
other => panic!("{} is not a valid security level", other),
}
}
}

Expand Down Expand Up @@ -137,8 +105,8 @@ pub fn test_example(example: Example, fail: bool) {
32,
8,
0,
HashFunction::Blake3_256,
FieldExtension::None,
distaff::HashFunction::Blake3_256,
distaff::FieldExtension::None,
8,
256,
);
Expand Down

0 comments on commit 8e8dbf9

Please sign in to comment.