Skip to content

Audit trail with tamper evident#99

Merged
elizabetheonoja-art merged 3 commits into
Utility-Protocol:mainfrom
gloskull:Audit-Trail-with-Tamper-Evident
Jul 18, 2026
Merged

Audit trail with tamper evident#99
elizabetheonoja-art merged 3 commits into
Utility-Protocol:mainfrom
gloskull:Audit-Trail-with-Tamper-Evident

Conversation

@gloskull

Copy link
Copy Markdown
Contributor

Motivation
Provide a compact, on-chain tamper-evident audit trail so off-chain monitors can detect deletion, reordering, or mutation of critical lifecycle and billing events.
Cover high-value operations (meter registration, funding/top-up, and signed usage deductions) so settlement and monitoring systems can verify integrity end-to-end.
Description
Add a new AuditRecord contract type that stores sequence, previous_hash, record_hash, action, subject_id, actor, timestamp, and payload_hash for compact, privacy-preserving verification.
Add storage keys DataKey::AuditHead and DataKey::AuditRecord(u64) and implement helpers zero_hash, audit_payload_hash, calculate_audit_record_hash, and append_audit_record to maintain a chained hash head and persist per-sequence records.
Append audit records from critical paths by calling the append helper in register_meter, top_up, and deduct_units, and emit an AuditTrail event when records are appended.
Expose monitor-facing contract methods get_audit_head, get_audit_record, and verify_audit_chain to allow off-chain watchers to fetch and verify inclusive ranges of the chain, and add AUDIT_TRAIL_RUNBOOK.md with verification, alerting, and deployment guidance.
Testing
Ran cargo test --manifest-path contracts/utility_contracts/Cargo.toml audit --lib, which did not complete successfully because the workspace currently has pre-existing unrelated compile errors (e.g. duplicate MIGRATION_INSTRUCTION_BUDGET and outdated test/client signatures).
Ran cargo fmt --manifest-path contracts/utility_contracts/Cargo.toml --check, which failed because several repository files are not rustfmt-clean; no broad formatting changes were applied to avoid unrelated churn.
No new unit tests were added for the audit helpers in this change set; monitors can exercise the new public helpers via integration testing and canary deployments as described in the runbook.
Closes #92

@elizabetheonoja-art
elizabetheonoja-art merged commit ade9fc2 into Utility-Protocol:main Jul 18, 2026
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.

Audit Trail with Tamper-Evident Hash Chain Verification

2 participants