From 529e361411fa47e060cbcc9ace47778b8fef8ec0 Mon Sep 17 00:00:00 2001 From: Srinivasa Consultants <78673153+dinakarjs@users.noreply.github.com> Date: Tue, 1 Dec 2026 10:19:10 +0530 Subject: [PATCH] test(witness): bind captured tree head and verification reports Signed-off-by: Srinivasa Consultants <78673153+dinakarjs@users.noreply.github.com> --- LIMITATIONS.md | 2 +- tests/test_witness_receipt_nenrin.py | 39 +++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/LIMITATIONS.md b/LIMITATIONS.md index 127363d..9e20148 100644 --- a/LIMITATIONS.md +++ b/LIMITATIONS.md @@ -73,7 +73,7 @@ all, rather than issuing a second one under the new code. That is the correct be witness that reissued a different receipt for a checkpoint it had already witnessed would be a witness whose receipts are not final. The consequence for this registry is that a receipt carrying `iat` or a signed grade requires a checkpoint the witness has not seen, which means the -log has to advance first. Checkpoint 1 will read `witness_time_established: false` and +log has to advance first. The September 7 Action State receipt for checkpoint 1 will read `witness_time_established: false` and `grade_cryptographically_bound: false` for as long as it exists, and no deployment on either side changes that. Confirmed with the witness operator on September 12, 2026, after their deploy, and recorded here because both sides had assumed otherwise in their own runbooks. diff --git a/tests/test_witness_receipt_nenrin.py b/tests/test_witness_receipt_nenrin.py index 0973b00..b346b71 100644 --- a/tests/test_witness_receipt_nenrin.py +++ b/tests/test_witness_receipt_nenrin.py @@ -132,7 +132,7 @@ def test_altered_checkpoint_rejected(self): cp['root'] = '00' * 32 self.assertFalse(check(2, cp=cp)['verified']) - def test_reported_grade_must_match_the_signed_one(self): + def test_mismatched_reported_grade_is_not_cryptographically_bound(self): response = copy.deepcopy(load_json(PACKET / 'witness-response-2.json')) response['grade'] = 'countersigned-observed' result = check(2, response=response) @@ -212,6 +212,43 @@ def test_swapped_or_altered_correction_proof_rejected(self): # the record altered by one byte self.assertNotEqual(anchor_problems(record_143.replace(b'972264', b'972850'), proof_143, *expect_143), []) + def test_saved_reports_match_fresh_verification(self): + for i in (1, 2): + with self.subTest(checkpoint=i): + self.assertEqual(load_json(PACKET / f'verification-{i}.json'), check(i)) + + def test_tree_head_signature_and_ordered_receipts(self): + from cryptography.exceptions import InvalidSignature + from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey + + head, = [json.loads(line) for line in + (PACKET / 'witness-tree-heads.ndjson').read_text().splitlines()] + body = {k: v for k, v in head.items() if k != 'signature'} + encoded = json.dumps(body, sort_keys=True, separators=(',', ':')).encode() + key = Ed25519PublicKey.from_public_bytes(bytes.fromhex(WITNESS_KEY)) + signature = bytes.fromhex(head['signature']) + key.verify(signature, encoded) + with self.assertRaises(InvalidSignature): + key.verify(bytes([signature[0] ^ 1]) + signature[1:], encoded) + altered = dict(body, tree_size=3) + with self.assertRaises(InvalidSignature): + key.verify(signature, json.dumps(altered, sort_keys=True, + separators=(',', ':')).encode()) + self.assertEqual(head['witness_key'], WITNESS_KEY) + responses = [load_json(PACKET / f'witness-response-{i}.json') for i in (1, 2)] + leaves = [hashlib.sha256(b'\x00' + bytes.fromhex(r['entry_hash'])).digest() + for r in responses] + root = hashlib.sha256(b'\x01' + leaves[0] + leaves[1]).hexdigest() + self.assertEqual(head['root'], root) + self.assertEqual(head['tree_size'], responses[1]['tree_size']) + self.assertEqual([r['leaf_index'] for r in responses], [0, 1]) + self.assertNotEqual(head['root'], + hashlib.sha256(b'\x01' + leaves[1] + leaves[0]).hexdigest()) + for i, response in enumerate(responses, 1): + result = check(i) + self.assertTrue(result['verified'], result) + self.assertEqual(result['entry_hash'], response['entry_hash']) + def test_sha256sums_match_the_packet(self): lines = (PACKET / 'SHA256SUMS').read_text(encoding='utf-8').splitlines() listed = dict(reversed(line.split(' ', 1)) for line in lines)