From 3f681fc51f48fee867dee87bd3b3ca3306e27b56 Mon Sep 17 00:00:00 2001 From: David Rusu Date: Tue, 6 Feb 2024 20:19:30 +0400 Subject: [PATCH] update block id spec; typo --- cryptarchia/cryptarchia.py | 18 ++++++++++-------- cryptarchia/messages.abnf | 2 +- cryptarchia/test_ledger_state_update.py | 4 ++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/cryptarchia/cryptarchia.py b/cryptarchia/cryptarchia.py index 42cddd2..9e0b241 100644 --- a/cryptarchia/cryptarchia.py +++ b/cryptarchia/cryptarchia.py @@ -182,6 +182,8 @@ class BlockHeader: h.update(self.leader_proof.commitment) assert len(self.leader_proof.nullifier) == 32 h.update(self.leader_proof.nullifier) + assert len(self.leader_proof.evolved_commitment) == 32 + h.update(self.leader_proof.evolved_commitment) return h.digest() @@ -219,7 +221,7 @@ class LedgerState: # set of commitments commitments_spend: set[Id] = field(default_factory=set) - # set of commitments elligible to lead + # set of commitments eligible to lead commitments_lead: set[Id] = field(default_factory=set) # set of nullified coins @@ -235,10 +237,10 @@ class LedgerState: nullifiers=deepcopy(self.nullifiers), ) - def verify_elligible_to_spend(self, commitment: Id) -> bool: + def verify_eligible_to_spend(self, commitment: Id) -> bool: return commitment in self.commitments_spend - def verify_elligible_to_lead(self, commitment: Id) -> bool: + def verify_eligible_to_lead(self, commitment: Id) -> bool: return commitment in self.commitments_lead def verify_unspent(self, nullifier: Id) -> bool: @@ -263,15 +265,15 @@ class EpochState: # The nonce snapshot is taken 7k/f slots into the previous epoch nonce_snapshot: LedgerState - def verify_elligible_to_lead_due_to_age(self, commitment: Id) -> bool: - # A coin is elligible to lead if it was committed to before the the stake + def verify_eligible_to_lead_due_to_age(self, commitment: Id) -> bool: + # A coin is eligible to lead if it was committed to before the the stake # distribution snapshot was taken or it was produced by a leader proof since the snapshot was taken. # # This verification is checking that first condition. # # NOTE: `ledger_state.commitments_spend` is a super-set of `ledger_state.commitments_lead` - return self.stake_distribution_snapshot.verify_elligible_to_spend(commitment) + return self.stake_distribution_snapshot.verify_eligible_to_spend(commitment) def total_stake(self) -> int: """Returns the total stake that will be used to reletivize leadership proofs during this epoch""" @@ -308,8 +310,8 @@ class Follower: return ( proof.verify(slot) # verify slot leader proof and ( - ledger_state.verify_elligible_to_lead(proof.commitment) - or epoch_state.verify_elligible_to_lead_due_to_age(proof.commitment) + ledger_state.verify_eligible_to_lead(proof.commitment) + or epoch_state.verify_eligible_to_lead_due_to_age(proof.commitment) ) and ledger_state.verify_unspent(proof.nullifier) ) diff --git a/cryptarchia/messages.abnf b/cryptarchia/messages.abnf index fefd6a6..b749146 100644 --- a/cryptarchia/messages.abnf +++ b/cryptarchia/messages.abnf @@ -9,7 +9,7 @@ CONTENT-SIZE = U32 BLOCK-DATE = BLOCK-SLOT BLOCK-SLOT = U64 PARENT-ID = HEADER-ID -MOCK-LEADER-PROOF = COMMITMENT NULLIFIER +MOCK-LEADER-PROOF = COMMITMENT NULLIFIER COMMITMENT ; ------------ CONTENT -------------------- CONTENT = *OCTET diff --git a/cryptarchia/test_ledger_state_update.py b/cryptarchia/test_ledger_state_update.py index 752c73c..349db47 100644 --- a/cryptarchia/test_ledger_state_update.py +++ b/cryptarchia/test_ledger_state_update.py @@ -157,7 +157,7 @@ class TestLedgerStateUpdate(TestCase): assert follower.tip() == block_4 assert follower.tip().slot.epoch(follower.config).epoch == 2 - def test_evolved_coin_is_elligble_for_leadership(self): + def test_evolved_coin_is_eligible_for_leadership(self): coin = Coin(sk=0, value=100) genesis = mk_genesis_state([coin]) @@ -185,7 +185,7 @@ class TestLedgerStateUpdate(TestCase): assert follower.tip_id() == block_1.id() - # but the evolved coin is elligible + # but the evolved coin is eligible block_2_evolve = mk_block(slot=1, parent=block_1.id(), coin=coin.evolve()) follower.on_block(block_2_evolve)