Specify mock-leader-proof in message spec

This commit is contained in:
David Rusu 2024-02-02 01:16:14 +04:00
parent 9345af0614
commit 9f6b9eb242
3 changed files with 27 additions and 21 deletions

View File

@ -15,3 +15,9 @@ To test a specific module
```bash ```bash
python -m unittest -v cryptarchia.test_leader python -m unittest -v cryptarchia.test_leader
``` ```
Or all test modules in a directory
```bash
python -m unittest -v cryptarchia/test_*
```

View File

@ -87,13 +87,6 @@ class MockLeaderProof:
# TODO: verification not implemented # TODO: verification not implemented
return True return True
def _block_id_update(self, hasher):
# TODO: this is used to contribute to the block id, to ensure the id is dependent
# on the leader proof, but the details here are not specified yet, we're waiting on
# CL specification before we nail this down
hasher.update(self.commitment)
hasher.update(self.nullifier)
@dataclass @dataclass
class BlockHeader: class BlockHeader:
@ -109,24 +102,30 @@ class BlockHeader:
# #
# The following code is to be considered as a reference implementation, mostly to be used for testing. # The following code is to be considered as a reference implementation, mostly to be used for testing.
def id(self) -> Id: def id(self) -> Id:
# version byte
h = blake2b(digest_size=32) h = blake2b(digest_size=32)
# version byte
h.update(b"\x01") h.update(b"\x01")
# header type
h.update(b"\x00")
# content size # content size
h.update(int.to_bytes(self.content_size, length=4, byteorder="big")) h.update(int.to_bytes(self.content_size, length=4, byteorder="big"))
# content id # content id
assert len(self.content_id) == 32 assert len(self.content_id) == 32
h.update(self.content_id) h.update(self.content_id)
# slot # slot
h.update(int.to_bytes(self.slot.absolute_slot, length=8, byteorder="big")) h.update(int.to_bytes(self.slot.absolute_slot, length=8, byteorder="big"))
# parent # parent
assert len(self.parent) == 32 assert len(self.parent) == 32
h.update(self.parent) h.update(self.parent)
# TODO: Leader proof component of block id is mocked here until CL is understood # leader proof
self.leader_proof._block_id_update(h) assert len(self.leader_proof.commitment) == 32
h.update(self.leader_proof.commitment)
assert len(self.leader_proof.nullifier) == 32
h.update(self.leader_proof.nullifier)
return h.digest() return h.digest()

View File

@ -2,15 +2,14 @@
; ------------ BLOCK ---------------------- ; ------------ BLOCK ----------------------
BLOCK = HEADER CONTENT BLOCK = HEADER CONTENT
; ------------ HEADER --------------------- ; ------------ HEADER ---------------------
VERSION = %x01 VERSION = %x01
HEADER = VERSION HEADER-UNSIGNED LEADER-PROOF HEADER = VERSION HEADER-FIELDS MOCK-LEADER-PROOF
HEADER-UNSIGNED = %x00 HEADER-COMMON HEADER-FIELDS = CONTENT-SIZE CONTENT-ID BLOCK-DATE PARENT-ID
HEADER-COMMON = CONTENT-SIZE CONTENT-ID BLOCK-DATE PARENT-ID CONTENT-SIZE = U32
CONTENT-SIZE = U32 BLOCK-DATE = BLOCK-SLOT
BLOCK-DATE = BLOCK-SLOT BLOCK-SLOT = U64
BLOCK-SLOT = U64 PARENT-ID = HEADER-ID
PARENT-ID = HEADER-ID MOCK-LEADER-PROOF = COMMITMENT NULLIFIER
LEADER-PROOF = <NOT SPECIFIED YET>
; ------------ CONTENT -------------------- ; ------------ CONTENT --------------------
CONTENT = *OCTET CONTENT = *OCTET
@ -20,3 +19,5 @@ U32 = 4OCTET ; unsigned integer 32 bit (BE)
U64 = 8OCTET ; unsigned integer 32 bit (BE) U64 = 8OCTET ; unsigned integer 32 bit (BE)
HEADER-ID = 32OCTET HEADER-ID = 32OCTET
CONTENT-ID = 32OCTET CONTENT-ID = 32OCTET
COMMITMENT = 32OCTET
NULLIFIER = 32OCTET