Skip to content

feat: Added Verifiable Agents - #766

Merged
AmitoVrito merged 2 commits into
SynapseKit:mainfrom
Abhay-Mmmm:feat/verify-agents
Jul 14, 2026
Merged

AmitoVrito merged 2 commits into
SynapseKit:mainfrom
Abhay-Mmmm:feat/verify-agents

Conversation

@Abhay-Mmmm

Copy link
Copy Markdown
Collaborator

Summary

Adds a cryptographically verifiable audit and provenance system to SynapseKit: hash-chained execution traces, batch Merkle signing (Ed25519 by default, pluggable KMS/BYOK), portable signed bundles, an independent verifier with a three-valued MATCH/DRIFT/UNVERIFIABLE verdict, replay, PII redaction, OTel export, and a VerifiableAgent wrapper — plus a full CLI (synapsekit audit verify|replay) and examples.

Closes #738

Type of change

  • Bug fix
  • New feature
  • Documentation update
  • Refactor / internal improvement
  • Dependency / tooling update

Changes

  • New synapsekit.audit package: types.py (AuditRecord, EventKind taxonomy, Verdict, VerificationResult), serializer.py (deterministic canonical JSON hashing), trace.py (AuditTracer — hash-chained, two-level payload_hash→hash commitment, actor, redaction metadata), merkle.py (RFC 6962 recursive-split tree with domain-separated hashing — avoids the CVE-2012-2459 duplicate-leaf class of bug), signer.py (SigningPolicy strategy: Ed25519 default, BYOK, AWS/Azure/GCP KMS interfaces, encrypted key export), bundle.py (export_audit_bundle/export_selective_bundle, signed manifest metadata, deterministic zip output), verifier.py (standalone verify() — only needs stdlib + cryptography, supports trusted_keys pinning for real non-repudiation), replay.py, redact.py (PIIRedactor, redacts before hashing), sink.py (File/S3/Kafka/OTel sinks, sync + async awrite), otel.py, metrics.py (wired into signing/export/verify/redact), wrapper.py (VerifiableAgent proxy + instrument_attrs for capturing an agent's internal sub-component calls, @audited decorator).
  • New CLI: synapsekit audit verify bundle.zip [--trusted-key KEY_ID:BASE64] and synapsekit audit replay bundle.zip, registered in cli/main.py.
  • New examples: examples/verifiable_agent.py, examples/audit_verify.py.
  • cryptography>=42 promoted to a core dependency (Ed25519 is the default signing algorithm and must work out of the box).
  • Top-level synapsekit/__init__.py exports the curated public API (AuditTracer, EventKind, Verdict, SigningPolicy, VerifiableAgent, verify_audit_bundle, etc.), aliased where names would otherwise collide with existing exports.

Testing

  • All existing tests pass (uv run pytest tests/ -q)
  • New tests added for new behaviour
  • No API keys or secrets in the code

186 new tests in tests/audit/ (with the observe extra installed for the Prometheus-gated metrics tests), covering: positive verification, all required tamper scenarios (removed/reordered/modified records, bad hash/payload_hash/merkle root/manifest/schema/parent_id/public key), key rotation, selective disclosure, replay (tool/retrieval/policy-hash matching, LLM-determinism-optional), redaction ordering and metadata, async sinks, instrument_attrs, CLI exit codes, and Verdict categorization (DRIFT vs UNVERIFIABLE). Full repo suite: 4475/4479 passing (4 pre-existing failures unrelated to this change — missing optional bs4/onnxruntime deps and an external-binary test).

Notes for reviewer

  • Trust anchor: verify() without trusted_keys only proves internal self-consistency (nothing edited after export) — it does not authenticate the signer, since public keys are otherwise read from the bundle's own manifest. Pass trusted_keys={key_id: public_key_bytes} for real non-repudiation. VerificationResult.trust_anchor ("none"/"pinned") makes this explicit, and the CLI prints a warning when pinning isn't used.
  • Schema version bumped to 1.2 as part of this PR (Merkle construction changed from naive last-leaf duplication to RFC 6962, and the record schema gained event_id/actor/payload_hash/reserved redaction fields) — bundles produced by earlier schema versions are not compatible with this verifier.
  • AuditRecord.payload is deep-frozen (MappingProxyType/tuples) to prevent post-hash mutation; AuditRecord.to_dict() unfreezes it back to plain JSON types for serialization.
  • Compliance enforcement (HIPAA/GDPR/EU AI Act redaction enforcement, ZK proof exports) is intentionally out of scope for this PR — the schema reserves redaction_policy_hash/redaction_status fields now specifically so those can be added later without another breaking bundle-format change.

@AmitoVrito
AmitoVrito merged commit 6593108 into SynapseKit:main Jul 14, 2026
2 of 4 checks passed
@AmitoVrito

Copy link
Copy Markdown
Collaborator

Thanks Abhay, this audit system is really well designed, the RFC 6962 Merkle tree and fail-closed signature checks especially.

Merged via #772 with five fixes on top:

  1. CreditCardDetector matched any 13 to 16 digit run with no structural check, which over-redacted ordinary numeric IDs and under-verified real cards. Added a Luhn checksum gate.
  2. AuditRecord.from_dict never deep froze the payload, so bundle-reconstructed records were mutable while records built via AuditTracer.record were not. Fixed to freeze consistently in both paths.
  3. verify_chain had no run_id awareness, so an unfiltered multi-run record list could validate a forged cross-run chain link. Now raises if records span more than one run_id.
  4. Canonical JSON hashing had no Unicode normalization, so combining and precomposed forms of the same string hashed differently, weakening the hash-commits-to-logical-value guarantee. Added NFC normalization before hashing.
  5. Only internal Merkle nodes were domain separated per RFC 6962, leaves were not. Added the leaf domain prefix so both match the spec.

Regression tests added for all five, full suite green (4535 passed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v2.0: Verifiable Agents — cryptographically signed audit trails of every LLM call and tool invocation

2 participants