Download logic/rules/provenance.pl from Snapkitty/rowm-polymorphic-notebook: direct link, hf CLI and curl.
- Browser
- Download file 2.62 kB
-
https://huggingface.co/Snapkitty/rowm-polymorphic-notebook/resolve/main/logic/rules/provenance.pl
- Command line
-
hf download hf://Snapkitty/rowm-polymorphic-notebook/logic/rules/provenance.pl
-
curl -L -o provenance.pl https://huggingface.co/Snapkitty/rowm-polymorphic-notebook/resolve/main/logic/rules/provenance.pl
2.62 kB
| % Rules: Provenance and Receipt Chain Validation | |
| % Ensures complete traceability of all operations | |
| :- module(provenance, [ | |
| receipt_chain_valid/1, | |
| receipt_chain_head/1, | |
| trace_receipt_lineage/2, | |
| receipt_sequence_valid/1, | |
| lineage_complete/1 | |
| ]). | |
| :- use_module(receipts). | |
| :- use_module(agents). | |
| % receipt_chain_valid(IsValid) | |
| % The entire receipt chain is valid if: | |
| % - All receipts are cryptographically valid | |
| % - The chain is unbroken (each receipt links to its predecessor) | |
| % - Sequence numbers are monotonic | |
| % - All agents are authorized | |
| receipt_chain_valid(true) :- | |
| receipt_chain_head(HeadID), | |
| receipt_issued(HeadID, _SeqNum, _Agent, _Cap, _Instr, _Action, _InHash, _OutHash, _TS), | |
| receipt_sequence_valid(HeadID), | |
| lineage_complete(HeadID). | |
| receipt_chain_valid(false). | |
| % receipt_sequence_valid(ReceiptID) | |
| % Verify monotonic sequence numbers starting from this receipt and walking backwards | |
| receipt_sequence_valid(ReceiptID) :- | |
| receipt_issued(ReceiptID, SeqNum, _, _, _, _, _, _, _), | |
| (SeqNum = 0 -> true ; trace_receipt_lineage(ReceiptID, PrevID), receipt_issued(PrevID, PrevSeq, _, _, _, _, _, _, _), PrevSeq < SeqNum), | |
| (previous_receipt(ReceiptID, _) -> receipt_sequence_valid(previous_receipt_id(ReceiptID)) ; true). | |
| % Simplified: For Prolog query, just verify head is valid | |
| receipt_sequence_valid(ReceiptID) :- | |
| receipt_issued(ReceiptID, _SeqNum, Agent, CapID, _Instr, _Action, _InHash, _OutHash, _TS), | |
| agent_active(Agent, true), | |
| capability_valid(CapID, true). | |
| % trace_receipt_lineage(ReceiptID, PreviousReceiptID) | |
| % Walk backwards through receipt chain to establish provenance | |
| trace_receipt_lineage(ReceiptID, PrevID) :- | |
| previous_receipt(ReceiptID, PrevID). | |
| trace_receipt_lineage(ReceiptID, AncestorID) :- | |
| previous_receipt(ReceiptID, PrevID), | |
| trace_receipt_lineage(PrevID, AncestorID). | |
| % lineage_complete(ReceiptID) | |
| % Verify that the receipt chain is complete: either at sequence 0 or has valid predecessor | |
| lineage_complete(ReceiptID) :- | |
| receipt_issued(ReceiptID, 0, _, _, _, _, _, _, _). | |
| lineage_complete(ReceiptID) :- | |
| receipt_issued(ReceiptID, SeqNum, _, _, _, _, _, _, _), | |
| SeqNum > 0, | |
| previous_receipt(ReceiptID, PrevID), | |
| receipt_valid(PrevID, true), | |
| lineage_complete(PrevID). | |
| % Agent authorization carries through the chain | |
| receipt_agent_authorized(ReceiptID) :- | |
| receipt_issued(ReceiptID, _Seq, Agent, CapID, _Instr, _Action, _InHash, _OutHash, _TS), | |
| agent_active(Agent, true), | |
| capability_valid(CapID, true). | |