Audit
audit
Immutable, compliance-ready experimental audit trails.
This module provides the AuditTrail class, which logs structural, state-transition, and analytical events
during an experiment's lifecycle, ensuring reproducibility, governance, and traceability.
| CLASS | DESCRIPTION |
|---|---|
AuditTrail |
Maintains an immutable, compliance-ready audit trail of experiment phase transition events. |
AuditTrail
Maintains an immutable, compliance-ready audit trail of experiment phase transition events.
In enterprise, financial, and clinical environments, maintaining a rigorous record of an experiment's history is critical for governance, auditing, and scientific reproducibility. An audit trail acts as a tamper-evident, chronological log tracking every key lifecycle change, modification to allocation parameters, and analytical peeking event.
Cryptographic Verification and State-Chaining
To satisfy strict regulatory compliance frameworks, the audit log entries are structured as a linear hash chain:
- Each log entry is represented as a state block \(B_k = (t_k, a_k, d_k, h_{k-1})\) where:
- \(t_k\): Coordinated Universal Time (ISO 8601 UTC timestamp).
- \(a_k\): The action or state transition executed (e.g., "ALLOCATION_SHIFT").
- \(d_k\): Detailed parameter changes (e.g., altering treatment allocation from \(10\\%\) to \(50\\%\)).
- \(h_{k-1}\): The SHA-256 cryptographic hash of the preceding block \(B_{k-1}\).
- The hash of the current block \(h_k\) is computed as:
$$
h_k = H(t_k \parallel a_k \parallel d_k \parallel h_{k-1})
$$
where \(\\parallel\) denotes string concatenation, and \(H\) is the SHA-256 secure hash function.
- Because of this chaining, any retroactive modification of historical logs immediately breaks the hash chain,
making the log highly secure and tamper-evident.
| ATTRIBUTE | DESCRIPTION |
|---|---|
experiment_id |
The unique identifier of the experiment under audit.
TYPE:
|
logs |
List of chronological, cryptographically linked log events.
TYPE:
|
| PARAMETER | DESCRIPTION |
|---|---|
experiment_id
|
The unique ID of the target experiment.
TYPE:
|
db_path
|
Optional SQLite database path for tamper-proof persistence.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
log_event |
Appends a new event with an active timestamp to the audit trail log. |
verify_integrity |
Verifies the complete cryptographic chain of the audit trail ledger. |
get_logs |
Returns the full list of chronological logs in the audit ledger. |
Source code in src\xpyrment\report\audit.py
log_event
Appends a new event with an active timestamp to the audit trail log.
Calculates timestamps in strict UTC, hashes the event details with the prior block's hash, and appends the entry to the ledger. Optionally attaches RSA/ECDSA digital signatures.
| PARAMETER | DESCRIPTION |
|---|---|
action
|
The action category (e.g.,
TYPE:
|
details
|
Detailed text or JSON payload describing the parameters or user that initiated the change.
TYPE:
|
signature
|
Cryptographic signature of the event hash.
TYPE:
|
public_key
|
Public key string to verify the signature.
TYPE:
|
Source code in src\xpyrment\report\audit.py
verify_integrity
Verifies the complete cryptographic chain of the audit trail ledger.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the hash chain is fully intact and unmodified, False otherwise.
TYPE:
|
Source code in src\xpyrment\report\audit.py
get_logs
Returns the full list of chronological logs in the audit ledger.
| RETURNS | DESCRIPTION |
|---|---|
List[Dict[str, str]]
|
List[Dict[str, str]]: A list of dictionary objects representing the serialized ledger blocks. |