Skip to content

Commit

Permalink
It is optional to load all setups
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerTaule committed Nov 5, 2024
1 parent b625bda commit 747f64c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
33 changes: 22 additions & 11 deletions common/src/setup_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,32 @@ use crate::ProofType;

pub struct SetupsVadcop<F> {
pub sctx: Arc<SetupCtx<F>>,
pub sctx_compressor: Arc<SetupCtx<F>>,
pub sctx_recursive1: Arc<SetupCtx<F>>,
pub sctx_recursive2: Arc<SetupCtx<F>>,
pub sctx_final: Arc<SetupCtx<F>>,
pub sctx_compressor: Option<Arc<SetupCtx<F>>>,
pub sctx_recursive1: Option<Arc<SetupCtx<F>>>,
pub sctx_recursive2: Option<Arc<SetupCtx<F>>>,
pub sctx_final: Option<Arc<SetupCtx<F>>>,
}

impl<F> SetupsVadcop<F> {
pub fn new(global_info: &GlobalInfo) -> Self {
SetupsVadcop {
sctx: Arc::new(SetupCtx::new(global_info, &ProofType::Basic)),
sctx_compressor: Arc::new(SetupCtx::new(global_info, &ProofType::Compressor)),
sctx_recursive1: Arc::new(SetupCtx::new(global_info, &ProofType::Recursive1)),
sctx_recursive2: Arc::new(SetupCtx::new(global_info, &ProofType::Recursive2)),
sctx_final: Arc::new(SetupCtx::new(global_info, &ProofType::Final)),
pub fn new(global_info: &GlobalInfo, aggregation: bool) -> Self {
if aggregation {
SetupsVadcop {
sctx: Arc::new(SetupCtx::new(global_info, &ProofType::Basic)),
sctx_compressor: Some(Arc::new(SetupCtx::new(global_info, &ProofType::Compressor))),
sctx_recursive1: Some(Arc::new(SetupCtx::new(global_info, &ProofType::Recursive1))),
sctx_recursive2: Some(Arc::new(SetupCtx::new(global_info, &ProofType::Recursive2))),
sctx_final: Some(Arc::new(SetupCtx::new(global_info, &ProofType::Final))),
}
} else {
SetupsVadcop {
sctx: Arc::new(SetupCtx::new(global_info, &ProofType::Basic)),
sctx_compressor: None,
sctx_recursive1: None,
sctx_recursive2: None,
sctx_final: None,
}
}

}
}

Expand Down
23 changes: 14 additions & 9 deletions proofman/src/proofman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl<F: Field + 'static> ProofMan<F> {

let pctx = Arc::new(ProofCtx::create_ctx(witness_lib.pilout(), proving_key_path.clone()));

let setups = Arc::new(SetupsVadcop::new(&pctx.global_info));
let setups = Arc::new(SetupsVadcop::new(&pctx.global_info, options.aggregation));
let sctx: Arc<SetupCtx<F>> = setups.sctx.clone();

Self::initialize_witness(&mut witness_lib, pctx.clone(), ectx.clone(), sctx.clone());
Expand Down Expand Up @@ -166,7 +166,7 @@ impl<F: Field + 'static> ProofMan<F> {
let comp_proofs = generate_recursion_proof(
&pctx,
&ectx,
setups.sctx_compressor.clone(),
setups.sctx_compressor.as_ref().unwrap().clone(),
&proves_out,
&ProofType::Compressor,
output_dir_path.clone(),
Expand All @@ -179,7 +179,7 @@ impl<F: Field + 'static> ProofMan<F> {
let recursive1_proofs = generate_recursion_proof(
&pctx,
&ectx,
setups.sctx_recursive1.clone(),
setups.sctx_recursive1.as_ref().unwrap().clone(),
&comp_proofs,
&ProofType::Recursive1,
output_dir_path.clone(),
Expand All @@ -194,7 +194,7 @@ impl<F: Field + 'static> ProofMan<F> {
let recursive2_proofs = generate_recursion_proof(
&pctx,
&ectx,
sctx_recursive2,
sctx_recursive2.as_ref().unwrap().clone(),
&recursive1_proofs,
&ProofType::Recursive2,
output_dir_path.clone(),
Expand All @@ -209,7 +209,7 @@ impl<F: Field + 'static> ProofMan<F> {
let _final_proof = generate_recursion_proof(
&pctx,
&ectx,
setups.sctx_final.clone(),
setups.sctx_final.as_ref().unwrap().clone(),
&recursive2_proofs,
&ProofType::Final,
output_dir_path.clone(),
Expand Down Expand Up @@ -334,11 +334,16 @@ impl<F: Field + 'static> ProofMan<F> {
timer_start_debug!(INITIALIZE_CONST_POLS_COMPRESSOR);
let mut const_pols_calculated_compressor: HashMap<(usize, usize), bool> = HashMap::new();

let sctx_compressor = setups.sctx_compressor.as_ref().unwrap().clone();
let sctx_recursive1 = setups.sctx_recursive1.as_ref().unwrap().clone();
let sctx_recursive2 = setups.sctx_recursive2.as_ref().unwrap().clone();
let sctx_final = setups.sctx_final.as_ref().unwrap().clone();

for air_instance in
pctx.air_instance_repo.air_instances.read().unwrap().iter()
{
if pctx.global_info.get_air_has_compressor(air_instance.airgroup_id, air_instance.air_id) && !const_pols_calculated_compressor.contains_key(&(air_instance.airgroup_id, air_instance.air_id)) {
let setup = setups.sctx_compressor.get_setup(air_instance.airgroup_id, air_instance.air_id);
let setup = sctx_compressor.get_setup(air_instance.airgroup_id, air_instance.air_id);
setup.load_const_pols(&pctx.global_info, &ProofType::Compressor);
setup.load_const_pols_tree(&pctx.global_info, &ProofType::Compressor, false);
const_pols_calculated_compressor.insert((air_instance.airgroup_id, air_instance.air_id), true);
Expand All @@ -352,7 +357,7 @@ impl<F: Field + 'static> ProofMan<F> {
pctx.air_instance_repo.air_instances.read().unwrap().iter()
{
if !const_pols_calculated_recursive1.contains_key(&(air_instance.airgroup_id, air_instance.air_id)) {
let setup = setups.sctx_recursive1.get_setup(air_instance.airgroup_id, air_instance.air_id);
let setup = sctx_recursive1.get_setup(air_instance.airgroup_id, air_instance.air_id);
setup.load_const_pols(&pctx.global_info, &ProofType::Recursive1);
setup.load_const_pols_tree(&pctx.global_info, &ProofType::Recursive1, false);
const_pols_calculated_recursive1.insert((air_instance.airgroup_id, air_instance.air_id), true);
Expand All @@ -363,14 +368,14 @@ impl<F: Field + 'static> ProofMan<F> {
timer_start_debug!(INITIALIZE_CONST_POLS_RECURSIVE2);
let n_airgroups = pctx.global_info.air_groups.len();
for airgroup in 0..n_airgroups {
let setup = setups.sctx_recursive2.get_setup(airgroup, 0);
let setup = sctx_recursive2.get_setup(airgroup, 0);
setup.load_const_pols(&pctx.global_info, &ProofType::Recursive2);
setup.load_const_pols_tree(&pctx.global_info, &ProofType::Recursive2, false);
}
timer_stop_and_log_debug!(INITIALIZE_CONST_POLS_RECURSIVE2);

timer_start_debug!(INITIALIZE_CONST_POLS_FINAL);
let setup = setups.sctx_final.get_setup(0, 0);
let setup = sctx_final.get_setup(0, 0);
setup.load_const_pols(&pctx.global_info, &ProofType::Final);
setup.load_const_pols_tree(&pctx.global_info, &ProofType::Final, false);
timer_stop_and_log_debug!(INITIALIZE_CONST_POLS_FINAL);
Expand Down

0 comments on commit 747f64c

Please sign in to comment.