diff --git a/README.md b/README.md index 28f4791..783e2f5 100644 --- a/README.md +++ b/README.md @@ -15,3 +15,9 @@ To test a specific module ```bash python -m unittest -v cryptarchia.test_leader ``` + +Or all test modules in a directory + +```bash +python -m unittest -v cryptarchia/test_* +``` diff --git a/cryptarchia/cryptarchia.py b/cryptarchia/cryptarchia.py index 8ad59ca..64defba 100644 --- a/cryptarchia/cryptarchia.py +++ b/cryptarchia/cryptarchia.py @@ -87,13 +87,6 @@ class MockLeaderProof: # TODO: verification not implemented 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 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. def id(self) -> Id: - # version byte h = blake2b(digest_size=32) + + # version byte h.update(b"\x01") - # header type - h.update(b"\x00") + # content size h.update(int.to_bytes(self.content_size, length=4, byteorder="big")) + # content id assert len(self.content_id) == 32 h.update(self.content_id) + # slot h.update(int.to_bytes(self.slot.absolute_slot, length=8, byteorder="big")) + # parent assert len(self.parent) == 32 h.update(self.parent) - # TODO: Leader proof component of block id is mocked here until CL is understood - self.leader_proof._block_id_update(h) + # leader proof + 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() diff --git a/cryptarchia/messages.abnf b/cryptarchia/messages.abnf index ef3e7c5..fefd6a6 100644 --- a/cryptarchia/messages.abnf +++ b/cryptarchia/messages.abnf @@ -2,15 +2,14 @@ ; ------------ BLOCK ---------------------- BLOCK = HEADER CONTENT ; ------------ HEADER --------------------- -VERSION = %x01 -HEADER = VERSION HEADER-UNSIGNED LEADER-PROOF -HEADER-UNSIGNED = %x00 HEADER-COMMON -HEADER-COMMON = CONTENT-SIZE CONTENT-ID BLOCK-DATE PARENT-ID -CONTENT-SIZE = U32 -BLOCK-DATE = BLOCK-SLOT -BLOCK-SLOT = U64 -PARENT-ID = HEADER-ID -LEADER-PROOF = +VERSION = %x01 +HEADER = VERSION HEADER-FIELDS MOCK-LEADER-PROOF +HEADER-FIELDS = CONTENT-SIZE CONTENT-ID BLOCK-DATE PARENT-ID +CONTENT-SIZE = U32 +BLOCK-DATE = BLOCK-SLOT +BLOCK-SLOT = U64 +PARENT-ID = HEADER-ID +MOCK-LEADER-PROOF = COMMITMENT NULLIFIER ; ------------ CONTENT -------------------- CONTENT = *OCTET @@ -20,3 +19,5 @@ U32 = 4OCTET ; unsigned integer 32 bit (BE) U64 = 8OCTET ; unsigned integer 32 bit (BE) HEADER-ID = 32OCTET CONTENT-ID = 32OCTET +COMMITMENT = 32OCTET +NULLIFIER = 32OCTET