Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LIMITATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
39 changes: 38 additions & 1 deletion tests/test_witness_receipt_nenrin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down