pub fn generate_winning_post<Tree: 'static + MerkleTreeTrait>(
    post_config: &PoStConfig,
    randomness: &ChallengeSeed,
    replicas: &[(SectorId, PrivateReplicaInfo<Tree>)],
    prover_id: ProverId,
) -> Result<SnarkProof> {
    info!("generate_winning_post:start");
    ensure!(
        post_config.typ == PoStType::Winning,
        "invalid post config type"
    );

    ensure!(
        replicas.len() == post_config.sector_count,
        "invalid amount of replicas"
    );

    let randomness_safe: <Tree::Hasher as Hasher>::Domain =
        as_safe_commitment(randomness, "randomness")?;
    let prover_id_safe: <Tree::Hasher as Hasher>::Domain =
        as_safe_commitment(&prover_id, "prover_id")?;

    let vanilla_params = winning_post_setup_params(&post_config)?;
    let param_sector_count = vanilla_params.sector_count;

    let setup_params = compound_proof::SetupParams {
        vanilla_params,
        partitions: None,
        priority: post_config.priority,
    };
    let pub_params: compound_proof::PublicParams<fallback::FallbackPoSt<Tree>> =
        fallback::FallbackPoStCompound::setup(&setup_params)?;
    let groth_params = get_post_params::<Tree>(&post_config)?;

    let trees = replicas
        .iter()
        .map(|(sector_id, replica)| {
            replica
                .merkle_tree(post_config.sector_size)
                .with_context(|| {
                    format!("generate_winning_post: merkle_tree failed: {:?}", sector_id)
                })
        })
        .collect::<Result<Vec<_>>>()?;

    let mut pub_sectors = Vec::with_capacity(param_sector_count);
    let mut priv_sectors = Vec::with_capacity(param_sector_count);

    for _ in 0..param_sector_count {
        for ((sector_id, replica), tree) in replicas.iter().zip(trees.iter()) {
            let comm_r = replica.safe_comm_r().with_context(|| {
                format!("generate_winning_post: safe_comm_r failed: {:?}", sector_id)
            })?;
            let comm_c = replica.safe_comm_c();
            let comm_r_last = replica.safe_comm_r_last();

            pub_sectors.push(fallback::PublicSector::<<Tree::Hasher as Hasher>::Domain> {
                id: *sector_id,
                comm_r,
            });
            priv_sectors.push(fallback::PrivateSector {
                tree,
                comm_c,
                comm_r_last,
            });
        }
    }

    let pub_inputs = fallback::PublicInputs::<<Tree::Hasher as Hasher>::Domain> {
        randomness: randomness_safe,
        prover_id: prover_id_safe,
        sectors: &pub_sectors,
        k: None,
    };

    let priv_inputs = fallback::PrivateInputs::<Tree> {
        sectors: &priv_sectors,
    };

    let proof = fallback::FallbackPoStCompound::<Tree>::prove(
        &pub_params,
        &pub_inputs,
        &priv_inputs,
        &groth_params,
    )?;
    let proof = proof.to_vec()?;

    info!("generate_winning_post:finish");

    Ok(proof)
}
/// Generates a Winning proof-of-spacetime.
Generates a Winning proof-of-spacetime.
Generates a Winning proof - of - spacetime .
pub fn generate_winning_post<Tree: 'static + MerkleTreeTrait>(
    post_config: &PoStConfig,
    randomness: &ChallengeSeed,
    replicas: &[(SectorId, PrivateReplicaInfo<Tree>)],
    prover_id: ProverId,
) -> Result<SnarkProof> {
    info!("generate_winning_post:start");
    ensure!(
        post_config.typ == PoStType::Winning,
        "invalid post config type"
    );
    ensure!(
        replicas.len() == post_config.sector_count,
        "invalid amount of replicas"
    );
    let randomness_safe: <Tree::Hasher as Hasher>::Domain =
        as_safe_commitment(randomness, "randomness")?;
    let prover_id_safe: <Tree::Hasher as Hasher>::Domain =
        as_safe_commitment(&prover_id, "prover_id")?;
    let vanilla_params = winning_post_setup_params(&post_config)?;
    let param_sector_count = vanilla_params.sector_count;
    let setup_params = compound_proof::SetupParams {
        vanilla_params,
        partitions: None,
        priority: post_config.priority,
    };
    let pub_params: compound_proof::PublicParams<fallback::FallbackPoSt<Tree>> =
        fallback::FallbackPoStCompound::setup(&setup_params)?;
    let groth_params = get_post_params::<Tree>(&post_config)?;
    let trees = replicas
        .iter()
        .map(|(sector_id, replica)| {
            replica
                .merkle_tree(post_config.sector_size)
                .with_context(|| {
                    format!("generate_winning_post: merkle_tree failed: {:?}", sector_id)
                })
        })
        .collect::<Result<Vec<_>>>()?;
    let mut pub_sectors = Vec::with_capacity(param_sector_count);
    let mut priv_sectors = Vec::with_capacity(param_sector_count);
    for _ in 0..param_sector_count {
        for ((sector_id, replica), tree) in replicas.iter().zip(trees.iter()) {
            let comm_r = replica.safe_comm_r().with_context(|| {
                format!("generate_winning_post: safe_comm_r failed: {:?}", sector_id)
            })?;
            let comm_c = replica.safe_comm_c();
            let comm_r_last = replica.safe_comm_r_last();
            pub_sectors.push(fallback::PublicSector::<<Tree::Hasher as Hasher>::Domain> {
                id: *sector_id,
                comm_r,
            });
            priv_sectors.push(fallback::PrivateSector {
                tree,
                comm_c,
                comm_r_last,
            });
        }
    }
    let pub_inputs = fallback::PublicInputs::<<Tree::Hasher as Hasher>::Domain> {
        randomness: randomness_safe,
        prover_id: prover_id_safe,
        sectors: &pub_sectors,
        k: None,
    };
    let priv_inputs = fallback::PrivateInputs::<Tree> {
        sectors: &priv_sectors,
    };
    let proof = fallback::FallbackPoStCompound::<Tree>::prove(
        &pub_params,
        &pub_inputs,
        &priv_inputs,
        &groth_params,
    )?;
    let proof = proof.to_vec()?;
    info!("generate_winning_post:finish");
    Ok(proof)
}
pub fn generate_winning_post < Tree : ' static + MerkleTreeTrait > ( post_config : & PoStConfig , randomness : & ChallengeSeed , replicas : & [ ( SectorId , PrivateReplicaInfo < Tree > ) ] , prover_id : ProverId , ) -> Result < SnarkProof > { info ! ( " " ) ; ensure ! ( post_config typ PoStType Winning " " ) ; ensure ! ( replicas len ( ) post_config sector_count " " ) ; let randomness_safe : < Tree :: Hasher as Hasher > :: Domain = as_safe_commitment ( randomness , " " ) ? ; let prover_id_safe : < Tree :: Hasher as Hasher > :: Domain = as_safe_commitment ( & prover_id , " " ) ? ; let vanilla_params = winning_post_setup_params ( & post_config ) ? ; let param_sector_count = vanilla_params . sector_count ; let setup_params = compound_proof :: SetupParams { vanilla_params , partitions : None , priority : post_config . priority , } ; let pub_params : compound_proof :: PublicParams < fallback :: FallbackPoSt < Tree > > = fallback :: FallbackPoStCompound :: setup ( & setup_params ) ? ; let groth_params = get_post_params :: < Tree > ( & post_config ) ? ; let trees = replicas . iter ( ) . map ( | ( sector_id , replica ) | { replica . merkle_tree ( post_config . sector_size ) . with_context ( | | { format ! ( " " sector_id ) } ) } ) . collect :: < Result < Vec < _ > > > ( ) ? ; let mut pub_sectors = Vec :: with_capacity ( param_sector_count ) ; let mut priv_sectors = Vec :: with_capacity ( param_sector_count ) ; for _ in 0 .. param_sector_count { for ( ( sector_id , replica ) , tree ) in replicas . iter ( ) . zip ( trees . iter ( ) ) { let comm_r = replica . safe_comm_r ( ) . with_context ( | | { format ! ( " " sector_id ) } ) ? ; let comm_c = replica . safe_comm_c ( ) ; let comm_r_last = replica . safe_comm_r_last ( ) ; pub_sectors . push ( fallback :: PublicSector :: < < Tree :: Hasher as Hasher > :: Domain > { id : * sector_id , comm_r , } ) ; priv_sectors . push ( fallback :: PrivateSector { tree , comm_c , comm_r_last , } ) ; } } let pub_inputs = fallback :: PublicInputs :: < < Tree :: Hasher as Hasher > :: Domain > { randomness : randomness_safe , prover_id : prover_id_safe , sectors : & pub_sectors , k : None , } ; let priv_inputs = fallback :: PrivateInputs :: < Tree > { sectors : & priv_sectors , } ; let proof = fallback :: FallbackPoStCompound :: < Tree > :: prove ( & pub_params , & pub_inputs , & priv_inputs , & groth_params , ) ? ; let proof = proof . to_vec ( ) ? ; info ! ( " " ) ; Ok ( proof ) }
Generates a Winning proof-of-spacetime.
Generates a Winning proof - of - spacetime .
post_config
&PoStConfig
randomness
&ChallengeSeed
replicas
&[(SectorId, PrivateReplicaInfo<Tree>)]
prover_id
ProverId
post_config
&PoStConfig
randomness
&ChallengeSeed
replicas
&[(SectorId, PrivateReplicaInfo<Tree>)]
prover_id
ProverId