examples/detect_false_inclusion_claim.py
| 1 | """Show that a false 'this document was in training' claim is rejected. |
| 2 | |
| 3 | Run: python examples/detect_false_inclusion_claim.py |
| 4 | """ |
| 5 | |
| 6 | from quantumshield import AgentIdentity |
| 7 | |
| 8 | from pqc_training_data import ( |
| 9 | CommitmentBuilder, |
| 10 | CommitmentSigner, |
| 11 | CommitmentVerifier, |
| 12 | DataRecord, |
| 13 | ) |
| 14 | |
| 15 | |
| 16 | def main() -> None: |
| 17 | identity = AgentIdentity.create("honest-model-creator") |
| 18 | signer = CommitmentSigner(identity) |
| 19 | |
| 20 | # Legit training corpus (10 records) |
| 21 | corpus = [ |
| 22 | DataRecord(content=f"legit-{i}".encode(), metadata={"id": i}) |
| 23 | for i in range(10) |
| 24 | ] |
| 25 | builder = CommitmentBuilder("honest-corpus", "1.0.0") |
| 26 | builder.add_records(corpus) |
| 27 | commitment = signer.sign(builder.build()) |
| 28 | |
| 29 | # A claimant says "this document was in your training set": |
| 30 | forged = DataRecord( |
| 31 | content=b"this-never-existed-in-training", metadata={"id": 999} |
| 32 | ) |
| 33 | |
| 34 | # They try to build a proof using one of the real records' slots - the leaf |
| 35 | # hashes won't match, so verify rejects. |
| 36 | pretend_proof = builder.tree.inclusion_proof(index=0) # proof for corpus[0] |
| 37 | |
| 38 | result = CommitmentVerifier.verify(forged, pretend_proof, commitment) |
| 39 | if result.fully_verified: |
| 40 | print("[FAIL] False claim was incorrectly accepted!") |
| 41 | else: |
| 42 | print("[OK] False inclusion claim was correctly rejected.") |
| 43 | print(f" reason: {result.error}") |
| 44 | |
| 45 | |
| 46 | if __name__ == "__main__": |
| 47 | main() |
| 48 | |