pub fn check_proof(
    proof: &Proof,
    height: Height,
    authorities: &[Node],
    crypt_hash: impl Fn(&[u8]) -> Hash,
    check_sig: impl Fn(&Signature, &Hash) -> Option<Address>,
) -> bool {
    if proof.height == 0 {
        return true;
    }
    if height != proof.height + 1 {
        return false;
    }

    let vote_addresses: Vec<Address> = proof
        .precommit_votes
        .iter()
        .map(|(sender, _)| sender.clone())
        .collect();

    if get_votes_weight(authorities, &vote_addresses) * 3 <= get_total_weight(authorities) * 2 {
        return false;
    }

    proof.precommit_votes.iter().all(|(voter, sig)| {
        if authorities.iter().any(|node| node.address == *voter) {
            let vote = Vote {
                vote_type: VoteType::Precommit,
                height: proof.height,
                round: proof.round,
                block_hash: proof.block_hash.clone(),
                voter: voter.clone(),
            };
            let msg = rlp::encode(&vote);
            if let Some(address) = check_sig(sig, &crypt_hash(&msg)) {
                return address == *voter;
            }
        }
        false
    })
}
/// A public function for proof validation.
/// The input [`height`] is the height of block containing the proof.
/// The input [`authorities`] is the authority_list for the proof check.
/// The fn [`crypt_hash`], [`check_sig`] are user-defined.
A public function for proof validation.
The input [`height`] is the height of block containing the proof.
The input [`authorities`] is the authority_list for the proof check.
A public function for proof validation . The input [ ` height ` ] is the height of block containing the proof . The input [ ` authorities ` ] is the authority_list for the proof check .
pub fn check_proof(
    proof: &Proof,
    height: Height,
    authorities: &[Node],
    crypt_hash: impl Fn(&[u8]) -> Hash,
    check_sig: impl Fn(&Signature, &Hash) -> Option<Address>,
) -> bool {
    if proof.height == 0 {
        return true;
    }
    if height != proof.height + 1 {
        return false;
    }
    let vote_addresses: Vec<Address> = proof
        .precommit_votes
        .iter()
        .map(|(sender, _)| sender.clone())
        .collect();
    if get_votes_weight(authorities, &vote_addresses) * 3 <= get_total_weight(authorities) * 2 {
        return false;
    }
    proof.precommit_votes.iter().all(|(voter, sig)| {
        if authorities.iter().any(|node| node.address == *voter) {
            let vote = Vote {
                vote_type: VoteType::Precommit,
                height: proof.height,
                round: proof.round,
                block_hash: proof.block_hash.clone(),
                voter: voter.clone(),
            };
            let msg = rlp::encode(&vote);
            if let Some(address) = check_sig(sig, &crypt_hash(&msg)) {
                return address == *voter;
            }
        }
        false
    })
}
pub fn check_proof ( proof : & Proof , height : Height , authorities : & [ Node ] , crypt_hash : impl Fn ( & [ u8 ] ) -> Hash , check_sig : impl Fn ( & Signature , & Hash ) -> Option < Address > , ) -> bool { if proof . height == 0 { return true ; } if height != proof . height + 1 { return false ; } let vote_addresses : Vec < Address > = proof . precommit_votes . iter ( ) . map ( | ( sender , _ ) | sender . clone ( ) ) . collect ( ) ; if get_votes_weight ( authorities , & vote_addresses ) * 3 <= get_total_weight ( authorities ) * 2 { return false ; } proof . precommit_votes . iter ( ) . all ( | ( voter , sig ) | { if authorities . iter ( ) . any ( | node | node . address == * voter ) { let vote = Vote { vote_type : VoteType :: Precommit , height : proof . height , round : proof . round , block_hash : proof . block_hash . clone ( ) , voter : voter . clone ( ) , } ; let msg = rlp :: encode ( & vote ) ; if let Some ( address ) = check_sig ( sig , & crypt_hash ( & msg ) ) { return address == * voter ; } } false } ) }
A public function for proof validation.
A public function for proof validation .
proof
&Proof
height
Height
authorities
&[Node]
crypt_hash
impl Fn(&[u8]) -> Hash
check_sig
impl Fn(&Signature, &Hash) -> Option<Address>
proof
&Proof
height
Height
authorities
&[Node]
crypt_hash
impl Fn(&[u8]) -> Hash
check_sig
impl Fn(&Signature, &Hash) -> Option<Address>