Skip to content

Commit

Permalink
minor verifier refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
irakliyk committed Sep 23, 2020
1 parent 63bd9ec commit 21f9a34
Show file tree
Hide file tree
Showing 8 changed files with 281 additions and 295 deletions.
6 changes: 5 additions & 1 deletion common/src/stark/evaluator/mod.rs
Expand Up @@ -93,7 +93,7 @@ impl<T: TransitionEvaluator, A: AssertionEvaluator> ConstraintEvaluator<T, A> {

pub fn constraint_divisors(&self) -> Vec<ConstraintDivisor> {
// TODO: build and save constraint divisors at construction time?
let x_at_last_step = self.get_x_at(self.trace_length() - 1);
let x_at_last_step = self.get_x_at_last_step();
vec![
ConstraintDivisor::from_transition(self.trace_length(), x_at_last_step),
ConstraintDivisor::from_assertion(1),
Expand Down Expand Up @@ -127,6 +127,10 @@ impl<T: TransitionEvaluator, A: AssertionEvaluator> ConstraintEvaluator<T, A> {
self.trace_info.blowup()
}

pub fn get_x_at_last_step(&self) -> u128 {
self.get_x_at(self.trace_length() - 1)
}

// HELPER METHODS
// --------------------------------------------------------------------------------------------

Expand Down
110 changes: 1 addition & 109 deletions common/src/stark/proof.rs
@@ -1,5 +1,4 @@
use super::{ProofOptions, TraceInfo};
use crate::utils::{as_bytes, uninit_vector};
use super::ProofOptions;
use crypto::BatchMerkleProof;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -46,113 +45,6 @@ pub struct DeepValues {
// STARK PROOF IMPLEMENTATION
// ================================================================================================
impl StarkProof {
// CONSTRUCTOR
// -------------------------------------------------------------------------------------------
// TODO: would be good to re-factor proof structure so information could be written into it
// gradually. Also, maybe it makes sense to move drawing of randomness logic here.
#[allow(clippy::too_many_arguments)]
pub fn new(
trace_root: [u8; 32],
trace_proof: BatchMerkleProof,
trace_states: Vec<Vec<u128>>,
constraint_root: [u8; 32],
constraint_proof: BatchMerkleProof,
max_constraint_degree: usize,
deep_values: DeepValues,
fri_proof: FriProof,
pow_nonce: u64,
options: ProofOptions,
) -> StarkProof {
StarkProof {
trace_root,
lde_domain_depth: trace_proof.depth,
trace_nodes: trace_proof.nodes,
trace_states,
constraint_root,
constraint_proof,
max_constraint_degree: max_constraint_degree as u8,
deep_values,
fri_proof,
pow_nonce,
options,
}
}

// TRACE
// -------------------------------------------------------------------------------------------

pub fn trace_root(&self) -> &[u8; 32] {
&self.trace_root
}

pub fn trace_proof(&self) -> BatchMerkleProof {
let hash = self.options.hash_fn();
let mut hashed_states = uninit_vector::<[u8; 32]>(self.trace_states.len());
#[allow(clippy::needless_range_loop)]
for i in 0..self.trace_states.len() {
hash(as_bytes(&self.trace_states[i]), &mut hashed_states[i]);
}

BatchMerkleProof {
nodes: self.trace_nodes.clone(),
values: hashed_states,
depth: self.lde_domain_depth,
}
}

pub fn trace_states(&self) -> &[Vec<u128>] {
&self.trace_states
}

pub fn trace_info(&self) -> TraceInfo {
let lde_domain_size = usize::pow(2, self.lde_domain_depth as u32);
let blowup = self.options.blowup_factor();
let length = lde_domain_size / blowup;
let width = self.trace_states[0].len();

TraceInfo::new(width, length, blowup)
}

// CONSTRAINTS
// -------------------------------------------------------------------------------------------

pub fn constraint_root(&self) -> &[u8; 32] {
&self.constraint_root
}

pub fn constraint_proof(&self) -> BatchMerkleProof {
self.constraint_proof.clone()
}

pub fn max_constraint_degree(&self) -> usize {
self.max_constraint_degree as usize
}

// DEEP VALUES
// -------------------------------------------------------------------------------------------
pub fn get_state_at_z1(&self) -> &[u128] {
&self.deep_values.trace_at_z1
}

pub fn get_state_at_z2(&self) -> &[u128] {
&self.deep_values.trace_at_z2
}

// OTHER PROPERTIES
// -------------------------------------------------------------------------------------------

pub fn fri_proof(&self) -> &FriProof {
&self.fri_proof
}

pub fn pow_nonce(&self) -> u64 {
self.pow_nonce
}

pub fn options(&self) -> &ProofOptions {
&self.options
}

// SECURITY LEVEL
// -------------------------------------------------------------------------------------------
pub fn security_level(&self, optimistic: bool) -> u32 {
Expand Down
2 changes: 1 addition & 1 deletion examples/src/fibonacci/mod.rs
Expand Up @@ -70,7 +70,7 @@ impl Example for FibExample {

fn verify(&self, proof: StarkProof, assertions: Vec<Assertion>) -> Result<bool, String> {
// TODO: clean up
let verifier = Verifier::<FibEvaluator, IoAssertionEvaluator>::new(proof.options().clone());
let verifier = Verifier::<FibEvaluator, IoAssertionEvaluator>::new(proof.options.clone());
verifier.verify(proof, assertions)
}
}
Expand Down
8 changes: 4 additions & 4 deletions prover/src/monolith/mod.rs
Expand Up @@ -41,9 +41,9 @@ pub struct Prover<T: TransitionEvaluator, A: AssertionEvaluator> {
}

impl<T: TransitionEvaluator, A: AssertionEvaluator> Prover<T, A> {
// Creates a new prover for the specified `options`. Generic parameters T and A
// define specifics of the computation for this prover.
// TODO: set a default value for A?
/// Creates a new prover for the specified `options`. Generic parameters T and A
/// define specifics of the computation for this prover.
/// TODO: set a default value for A?
pub fn new(options: ProofOptions) -> Prover<T, A> {
Prover {
options,
Expand All @@ -53,7 +53,7 @@ impl<T: TransitionEvaluator, A: AssertionEvaluator> Prover<T, A> {
}

/// Generates a STARK proof attesting that the `trace` satisfies the `assertions` and that
// it is valid in the context of the computation described by this prover.
/// it is valid in the context of the computation described by this prover.
pub fn prove(&self, trace: Vec<Vec<u128>>, assertions: Vec<Assertion>) -> StarkProof {
let trace = TraceTable::new(trace);
validate_assertions(&trace, &assertions);
Expand Down
85 changes: 0 additions & 85 deletions verifier/src/composition.rs

This file was deleted.

30 changes: 0 additions & 30 deletions verifier/src/constraints.rs

This file was deleted.

0 comments on commit 21f9a34

Please sign in to comment.