Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
Revert "wip"
Browse files Browse the repository at this point in the history
This reverts commit 0533bf8.
reverting wip

t Please enter the commit message for your changes. Lines starting
  • Loading branch information
topanisto committed Aug 8, 2024
1 parent f280c07 commit d4b67d7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 147 deletions.
21 changes: 1 addition & 20 deletions uni-stark/src/proof.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alloc::vec::Vec;

use p3_commit::{Pcs, PolynomialSpace, Val};
use p3_commit::Pcs;
use serde::{Deserialize, Serialize};

use crate::StarkGenericConfig;
Expand Down Expand Up @@ -52,22 +52,3 @@ pub struct StarkProvingKey<SC: StarkGenericConfig> {
pub struct StarkVerifyingKey<SC: StarkGenericConfig> {
pub preprocessed_commit: Com<SC>,
}

pub struct CommittedData<SC: StarkGenericConfig + PolynomialSpace> {
pub(crate) trace_commits: Vec<Com<SC>>,
pub(crate) traces: Vec<PcsProverData<SC>>,
pub(crate) public_values: Vec<Vec<Val<SC>>>, // should also include challenge values
}

impl<SC: StarkGenericConfig + PolynomialSpace> CommittedData<SC> {
pub(crate) fn update_stage(
&mut self,
trace_commit: Com<SC>,
trace: PcsProverData<SC>,
publics: Vec<Val<SC>>,
) {
self.trace_commits.push(trace_commit);
self.traces.push(trace);
self.public_values.push(publics);
}
}
149 changes: 22 additions & 127 deletions uni-stark/src/prover.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use alloc::collections::BTreeMap;
use alloc::vec;
use alloc::vec::Vec;
use core::iter;
Expand All @@ -16,8 +15,8 @@ use tracing::{info_span, instrument};

use crate::symbolic_builder::{get_log_quotient_degree, SymbolicAirBuilder};
use crate::{
Commitments, CommittedData, Domain, OpenedValues, PackedChallenge, PackedVal, Proof,
ProverConstraintFolder, StarkGenericConfig, StarkProvingKey, Val,
Commitments, Domain, OpenedValues, PackedChallenge, PackedVal, Proof, ProverConstraintFolder,
StarkGenericConfig, StarkProvingKey, Val,
};

#[instrument(skip_all)]
Expand All @@ -30,24 +29,14 @@ pub fn prove<
config: &SC,
air: &A,
challenger: &mut SC::Challenger,
challenges: Vec<Vec<u64>>,
main_trace: RowMajorMatrix<Val<SC>>,
multi_stage_trace: Vec<RowMajorMatrix<Val<SC>>>,
trace: RowMajorMatrix<Val<SC>>,
public_values: &Vec<Val<SC>>,
) -> Proof<SC>
where
SC: StarkGenericConfig,
A: Air<SymbolicAirBuilder<Val<SC>>> + for<'a> Air<ProverConstraintFolder<'a, SC>>,
{
prove_with_key(
config,
None,
air,
challenger,
challenges,
main_trace,
public_values,
)
prove_with_key(config, None, air, challenger, trace, public_values)
}

#[instrument(skip_all)]
Expand All @@ -61,131 +50,43 @@ pub fn prove_with_key<
proving_key: Option<&StarkProvingKey<SC>>,
air: &A,
challenger: &mut SC::Challenger,
challenges: Vec<Vec<u64>>,
main_trace: RowMajorMatrix<Val<SC>>,
next_stage_callback: Option<SC>,
trace: RowMajorMatrix<Val<SC>>,
public_values: &Vec<Val<SC>>,
) -> Proof<SC>
where
SC: StarkGenericConfig,
A: Air<SymbolicAirBuilder<Val<SC>>> + for<'a> Air<ProverConstraintFolder<'a, SC>>,
{
let degree = main_trace.height(); // all traces have the same height
#[cfg(debug_assertions)]
crate::check_constraints::check_constraints(
air,
&air.preprocessed_trace()
.unwrap_or(RowMajorMatrix::new(vec![], 0)),
&trace,
public_values,
);

let degree = trace.height();
let log_degree = log2_strict_usize(degree);

let log_quotient_degree = get_log_quotient_degree::<Val<SC>, A>(air, public_values.len());
let quotient_degree = 1 << log_quotient_degree;

let pcs = config.pcs();
let trace_domain = pcs.natural_domain_for_degree(degree);

// Observe the instance
let (trace_commit, trace_data) =
info_span!("commit to trace data").in_scope(|| pcs.commit(vec![(trace_domain, trace)]));

// Observe the instance.
challenger.observe(Val::<SC>::from_canonical_usize(log_degree));
// TODO: Might be best practice to include other instance data here; see verifier comment.

if let Some(proving_key) = proving_key {
challenger.observe(proving_key.preprocessed_commit.clone())
};

// commitments to main trace
let committed_data = run_stage(
challenger,
pcs,
trace_domain,
main_trace,
public_values,
None,
);

challenges
.iter()
.enumerate()
.map(|(stage, stage_challenges)| {
let challenge_values = stage_challenges
.iter()
.map(|id| {
let challenge = challenger.sample();
(*id, challenge)
})
.collect::<BTreeMap<u64, SC::Challenge>>();

// calculating next stage trace
let next_stage_trace = next_stage_callback
.as_ref()
.get_trace(stage, challenge_values); // callback to generate trace
committed_data = run_stage(
challenger,
pcs,
trace_domain,
main_trace,
&challenge_values,
committed_data,
);
});

finish(pcs, proving_key, challenger, air, committed_data)
}

#[instrument(skip_all)]
#[allow(clippy::multiple_bound_locations)] // cfg not supported in where clauses?
pub fn run_stage<
SC,
#[cfg(debug_assertions)] A: for<'a> Air<crate::check_constraints::DebugConstraintBuilder<'a, Val<SC>>>,
#[cfg(not(debug_assertions))] A,
>(
challenger: &mut SC::Challenger,
pcs: &<SC as StarkGenericConfig>::Pcs,
trace_domain: <<SC as StarkGenericConfig>::Pcs as Pcs<
<SC as StarkGenericConfig>::Challenge,
<SC as StarkGenericConfig>::Challenger,
>>::Domain,
trace: RowMajorMatrix<Val<SC>>,
public_values: &Vec<Val<SC>>,
committed_data: Option<&mut CommittedData<SC>>,
) -> Option<&mut CommittedData<SC>>
where
SC: StarkGenericConfig + PolynomialSpace,
A: Air<SymbolicAirBuilder<Val<SC>>> + for<'a> Air<ProverConstraintFolder<'a, SC>>,
{
// we need sme kind of callback to

let (trace_commit, trace_data) =
info_span!("commit to trace data").in_scope(|| pcs.commit(vec![(trace_domain, trace)]));

challenger.observe(trace_commit.clone());
challenger.observe_slice(public_values);

committed_data
.unwrap_or(&mut CommittedData {
trace_commits: Vec::new(),
traces: Vec::new(),
public_values: Vec::new(),
})
.update_stage(trace_commit, trace_data, public_values);
// TODO: Might be best practice to include other instance data here; see verifier comment.

committed_data
}

#[instrument(skip_all)]
#[allow(clippy::multiple_bound_locations)]
pub fn finish<
SC,
#[cfg(debug_assertions)] A: for<'a> Air<crate::check_constraints::DebugConstraintBuilder<'a, Val<SC>>>,
#[cfg(not(debug_assertions))] A,
>(
pcs: &<SC as StarkGenericConfig>::Pcs,
proving_key: Option<&StarkProvingKey<SC>>,
challenger: &mut SC::Challenger,
air: &A,
commited_data: Option<&mut CommittedData<SC>>,
) -> Proof<SC>
where
SC: StarkGenericConfig,
A: Air<SymbolicAirBuilder<Val<SC>>> + for<'a> Air<ProverConstraintFolder<'a, SC>>,
{
// changes for challenges

let log_quotient_degree = get_log_quotient_degree::<Val<SC>, A>(air, public_values.len());
let quotient_degree = 1 << log_quotient_degree;

let alpha: SC::Challenge = challenger.sample_ext_element();

let quotient_domain =
Expand All @@ -197,17 +98,13 @@ where

let trace_on_quotient_domain = pcs.get_evaluations_on_domain(&trace_data, 0, quotient_domain);

// let permutation_on_quotient_domain =
// pcs.get_evaluations_on_domain(&permutation_trace, 0, quotient_domain);

let quotient_values = quotient_values(
air,
public_values,
trace_domain,
quotient_domain,
preprocessed_on_quotient_domain,
trace_on_quotient_domain,
multistage_on_quotient_domain,
alpha,
);
let quotient_flat = RowMajorMatrix::new_col(quotient_values).flatten_to_base();
Expand Down Expand Up @@ -285,7 +182,6 @@ where
}
}

// TODO: finish
#[instrument(name = "compute quotient polynomial", skip_all)]
fn quotient_values<SC, A, Mat>(
air: &A,
Expand All @@ -294,7 +190,6 @@ fn quotient_values<SC, A, Mat>(
quotient_domain: Domain<SC>,
preprocessed_on_quotient_domain: Option<Mat>,
trace_on_quotient_domain: Mat,
multistage_on_quotient_domain: Option<Vec<Mat>>,
alpha: SC::Challenge,
) -> Vec<SC::Challenge>
where
Expand Down

0 comments on commit d4b67d7

Please sign in to comment.