Skip to content

[FEAT] Tamper-Proof Merkle Hash-Chain Compliance & Immutable Audit Log Vault #405

Description

@jotel-dev

telegram link : t.me/nullifiersystem


1. Summary & Core Promise

Financial compliance requires cryptographically immutable event logging. This feature implements a Tamper-Proof Merkle Hash-Chain Audit Vault. Database mutations generate sequential SHA-256 hash chains (hash_n = SHA256(payload + hash_{n-1})). Every 1,000 events, a Merkle tree root is anchored on Stellar via contracts/zk-credential/src/lib.rs, generating verifiable audit inclusion proofs.


2. Background & Architectural Risks

  • Database Tampering: Direct DB access allows rogue admins to alter past trade records without detection.
  • Audit Verification: External regulators require cryptographic proof that log records were not altered retroactively.

3. Database Layer Specifications

Migration SQL (023_add_merkle_audit_vault.sql)

CREATE TABLE audit_hash_chain (
    sequence_id BIGSERIAL PRIMARY KEY,
    event_type VARCHAR(64) NOT NULL,
    payload_hash VARCHAR(64) NOT NULL,
    prev_hash VARCHAR(64) NOT NULL,
    curr_hash VARCHAR(64) NOT NULL,
    created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);

4. Backend Route & Service Layer Specifications

Route: GET /api/v1/audit/proof/:eventId

  1. Generates Merkle inclusion proof for any past audit event.
  2. Returns Stellar anchor transaction hash proving root registration.

5. Background Processors / Workers

Merkle Anchor Worker (apps/api/src/lib/workers/auditAnchorWorker.ts)

  • Aggregates 1,000 log entries into a Merkle tree and commits root on-chain.

6. Frontend / UI Component Specifications

Component: mobile/frontend/src/pages/AuditorPortal.tsx

  • Compliance officer dashboard for searching events, validating SHA-256 chain integrity, and downloading Merkle proof bundles.

7. Rigor & Test Plan

  1. Tamper Detection Test (verify-audit-chain.ts): Mutating a historical row breaks hash continuity.
  2. Merkle Inclusion Proof Test (hash-chain.test.ts).

8. Relevant Files Inventory (18 Files)

  • apps/api/src/lib/audit/hash-chain-engine.ts
  • apps/api/src/lib/audit/merkle-aggregator.ts
  • apps/api/src/lib/audit/proof-generator.ts
  • apps/api/src/lib/workers/auditAnchorWorker.ts
  • apps/api/src/db/migrations/023_add_merkle_audit_vault.sql
  • apps/api/src/routes/audit-vault.ts
  • scripts/verify-audit-chain.ts
  • apps/api/src/lib/store.ts
  • apps/api/src/lib/stellar.ts
  • apps/api/src/app.ts
  • contracts/zk-credential/src/lib.rs
  • mobile/frontend/src/pages/AuditorPortal.tsx
  • mobile/frontend/src/components/AuditProofViewer.tsx
  • packages/shared/src/types/audit.ts
  • packages/shared/src/index.ts
  • apps/api/src/lib/audit/__tests__/hash-chain.test.ts
  • apps/api/src/routes/__tests__/audit-vault.test.ts
  • tests/e2e/audit_tamper_detection.test.ts

9. Acceptance Criteria

  • Sequential SHA-256 hash chains computed for all database mutations.
  • CLI verification tool detects single-bit data modifications.

10. Contributor Notes

  • ⚠️ Immutability: NEVER allow sequence number gaps in audit_hash_chain.

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardThird CampaignCampaign: Third Campaignextreme

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions