Add nonce specification (#64)

* Add nonce specification

* tweak nonce definition
This commit is contained in:
Giacomo Pasini 2024-02-06 16:37:49 +01:00 committed by GitHub
parent c1e12d6ce8
commit 8a82517fdd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 0 deletions

View File

@ -187,6 +187,9 @@ class LedgerState:
""" """
block: Id = None block: Id = None
# This nonce is used to derive the seed for the slot leader lottery
# It's updated at every block by hashing the previous nonce with the nullifier
# Note that this does not prevent nonce grinding at the last slot before the nonce snapshot
nonce: Id = None nonce: Id = None
total_stake: int = None total_stake: int = None
commitments: set[Id] = field(default_factory=set) # set of commitments commitments: set[Id] = field(default_factory=set) # set of commitments
@ -209,6 +212,13 @@ class LedgerState:
def apply(self, block: BlockHeader): def apply(self, block: BlockHeader):
assert block.parent == self.block assert block.parent == self.block
h = blake2b(digest_size=32)
h.update("epoch-nonce".encode(encoding="utf-8"))
h.update(self.nonce)
h.update(block.leader_proof.nullifier)
self.nonce = h.digest()
self.block = block.id() self.block = block.id()
self.nullifiers.add(block.leader_proof.nullifier) self.nullifiers.add(block.leader_proof.nullifier)