Count the stake votes for a leader.
(leader-stake-votes leader voters commtt) → yes-stake
The
Note that the active committee may have changed between the even and odd round, if it changed between the two rounds exactly at the lookback distance. This possible change of committee is unproblematic for the purpose of the correctness of the protocol, as we ensure by way of formal proofs.
We go through the voters, and check whether the leader address is among the refernced previous certificates or not, counting its stake as part of the resulting vote stake.
Function:
(defun leader-stake-votes (leader voters commtt) (declare (xargs :guard (and (addressp leader) (certificate-setp voters) (committeep commtt)))) (declare (xargs :guard (subset (certificate-set->author-set voters) (committee-members commtt)))) (let ((__function__ 'leader-stake-votes)) (declare (ignorable __function__)) (b* (((when (or (not (mbt (certificate-setp voters))) (emptyp voters))) 0) (voter (head voters)) (voter-stake (committee-member-stake (certificate->author voter) commtt)) (yes-stake (leader-stake-votes leader (tail voters) commtt))) (if (in (address-fix leader) (certificate->previous voter)) (+ voter-stake yes-stake) yes-stake))))
Theorem:
(defthm natp-of-leader-stake-votes (b* ((yes-stake (leader-stake-votes leader voters commtt))) (natp yes-stake)) :rule-classes :rewrite)
Theorem:
(defthm leader-stake-votes-of-address-fix-leader (equal (leader-stake-votes (address-fix leader) voters commtt) (leader-stake-votes leader voters commtt)))
Theorem:
(defthm leader-stake-votes-address-equiv-congruence-on-leader (implies (address-equiv leader leader-equiv) (equal (leader-stake-votes leader voters commtt) (leader-stake-votes leader-equiv voters commtt))) :rule-classes :congruence)
Theorem:
(defthm leader-stake-votes-of-certificate-set-fix-voters (equal (leader-stake-votes leader (certificate-set-fix voters) commtt) (leader-stake-votes leader voters commtt)))
Theorem:
(defthm leader-stake-votes-certificate-set-equiv-congruence-on-voters (implies (certificate-set-equiv voters voters-equiv) (equal (leader-stake-votes leader voters commtt) (leader-stake-votes leader voters-equiv commtt))) :rule-classes :congruence)
Theorem:
(defthm leader-stake-votes-of-committee-fix-commtt (equal (leader-stake-votes leader voters (committee-fix commtt)) (leader-stake-votes leader voters commtt)))
Theorem:
(defthm leader-stake-votes-committee-equiv-congruence-on-commtt (implies (committee-equiv commtt commtt-equiv) (equal (leader-stake-votes leader voters commtt) (leader-stake-votes leader voters commtt-equiv))) :rule-classes :congruence)