pub fn verify_winning_post<Tree: 'static + MerkleTreeTrait>(
    post_config: &PoStConfig,
    randomness: &ChallengeSeed,
    replicas: &[(SectorId, PublicReplicaInfo)],
    prover_id: ProverId,
    proof: &[u8],
) -> Result<bool> {
    info!("verify_winning_post:start");

    ensure!(
        post_config.typ == PoStType::Winning,
        "invalid post config type"
    );
    ensure!(
        post_config.sector_count == replicas.len(),
        "invalid amount of replicas provided"
    );

    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: false,
    };
    let pub_params: compound_proof::PublicParams<fallback::FallbackPoSt<Tree>> =
        fallback::FallbackPoStCompound::setup(&setup_params)?;

    let mut pub_sectors = Vec::with_capacity(param_sector_count);
    for _ in 0..param_sector_count {
        for (sector_id, replica) in replicas.iter() {
            let comm_r = replica.safe_comm_r().with_context(|| {
                format!("verify_winning_post: safe_comm_r failed: {:?}", sector_id)
            })?;
            pub_sectors.push(fallback::PublicSector {
                id: *sector_id,
                comm_r,
            });
        }
    }

    let pub_inputs = fallback::PublicInputs {
        randomness: randomness_safe,
        prover_id: prover_id_safe,
        sectors: &pub_sectors,
        k: None,
    };

    let is_valid = {
        let verifying_key = get_post_verifying_key::<Tree>(&post_config)?;

        let single_proof = MultiProof::new_from_reader(None, &proof[..], &verifying_key)?;
        if single_proof.len() != 1 {
            return Ok(false);
        }

        fallback::FallbackPoStCompound::verify(
            &pub_params,
            &pub_inputs,
            &single_proof,
            &fallback::ChallengeRequirements {
                minimum_challenge_count: post_config.challenge_count * post_config.sector_count,
            },
        )?
    };

    if !is_valid {
        return Ok(false);
    }

    info!("verify_winning_post:finish");

    Ok(true)
}
/// Verifies a winning proof-of-spacetime.
///
/// The provided `replicas` must be the same ones as passed to `generate_winning_post`, and be based on
/// the indices generated by `generate_winning_post_sector_challenge`. It is the responsibility of the
/// caller to ensure this.
Verifies a winning proof-of-spacetime.
Verifies a winning proof - of - spacetime .
pub fn verify_winning_post<Tree: 'static + MerkleTreeTrait>(
    post_config: &PoStConfig,
    randomness: &ChallengeSeed,
    replicas: &[(SectorId, PublicReplicaInfo)],
    prover_id: ProverId,
    proof: &[u8],
) -> Result<bool> {
    info!("verify_winning_post:start");
    ensure!(
        post_config.typ == PoStType::Winning,
        "invalid post config type"
    );
    ensure!(
        post_config.sector_count == replicas.len(),
        "invalid amount of replicas provided"
    );
    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: false,
    };
    let pub_params: compound_proof::PublicParams<fallback::FallbackPoSt<Tree>> =
        fallback::FallbackPoStCompound::setup(&setup_params)?;
    let mut pub_sectors = Vec::with_capacity(param_sector_count);
    for _ in 0..param_sector_count {
        for (sector_id, replica) in replicas.iter() {
            let comm_r = replica.safe_comm_r().with_context(|| {
                format!("verify_winning_post: safe_comm_r failed: {:?}", sector_id)
            })?;
            pub_sectors.push(fallback::PublicSector {
                id: *sector_id,
                comm_r,
            });
        }
    }
    let pub_inputs = fallback::PublicInputs {
        randomness: randomness_safe,
        prover_id: prover_id_safe,
        sectors: &pub_sectors,
        k: None,
    };
    let is_valid = {
        let verifying_key = get_post_verifying_key::<Tree>(&post_config)?;
        let single_proof = MultiProof::new_from_reader(None, &proof[..], &verifying_key)?;
        if single_proof.len() != 1 {
            return Ok(false);
        }
        fallback::FallbackPoStCompound::verify(
            &pub_params,
            &pub_inputs,
            &single_proof,
            &fallback::ChallengeRequirements {
                minimum_challenge_count: post_config.challenge_count * post_config.sector_count,
            },
        )?
    };
    if !is_valid {
        return Ok(false);
    }
    info!("verify_winning_post:finish");
    Ok(true)
}
pub fn verify_winning_post < Tree : ' static + MerkleTreeTrait > ( post_config : & PoStConfig , randomness : & ChallengeSeed , replicas : & [ ( SectorId , PublicReplicaInfo ) ] , prover_id : ProverId , proof : & [ u8 ] , ) -> Result < bool > { info ! ( " " ) ; ensure ! ( post_config typ PoStType Winning " " ) ; ensure ! ( post_config sector_count replicas len ( ) " " ) ; 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 : false , } ; let pub_params : compound_proof :: PublicParams < fallback :: FallbackPoSt < Tree > > = fallback :: FallbackPoStCompound :: setup ( & setup_params ) ? ; let mut pub_sectors = Vec :: with_capacity ( param_sector_count ) ; for _ in 0 .. param_sector_count { for ( sector_id , replica ) in replicas . iter ( ) { let comm_r = replica . safe_comm_r ( ) . with_context ( | | { format ! ( " " sector_id ) } ) ? ; pub_sectors . push ( fallback :: PublicSector { id : * sector_id , comm_r , } ) ; } } let pub_inputs = fallback :: PublicInputs { randomness : randomness_safe , prover_id : prover_id_safe , sectors : & pub_sectors , k : None , } ; let is_valid = { let verifying_key = get_post_verifying_key :: < Tree > ( & post_config ) ? ; let single_proof = MultiProof :: new_from_reader ( None , & proof [ .. ] , & verifying_key ) ? ; if single_proof . len ( ) != 1 { return Ok ( false ) ; } fallback :: FallbackPoStCompound :: verify ( & pub_params , & pub_inputs , & single_proof , & fallback :: ChallengeRequirements { minimum_challenge_count : post_config . challenge_count * post_config . sector_count , } , ) ? } ; if ! is_valid { return Ok ( false ) ; } info ! ( " " ) ; Ok ( true ) }
Verifies a winning proof-of-spacetime.
Verifies a winning proof - of - spacetime .
post_config
&PoStConfig
randomness
&ChallengeSeed
replicas
&[(SectorId, PublicReplicaInfo)]
prover_id
ProverId
proof
&[u8]
post_config
&PoStConfig
randomness
&ChallengeSeed
replicas
&[(SectorId, PublicReplicaInfo)]
prover_id
ProverId
proof
&[u8]