The Trusted Execution Environment (TEE) module provides a software simulation of hardware-backed enclave primitives. It is explicitly not a real SGX, SEV, or TrustZone enclave — it emulates the same attestation, sealing, measurement, and watchdog contracts in pure Python so that governance scenarios can be tested without specialised hardware. In a production deployment these classes would be replaced by — or wrapped inside — a real hardware TEE runtime.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/xcoder-es/governance-layer/llms.txt
Use this file to discover all available pages before exploring further.
Enumerations
WatchdogState
Represents the current health state of a WatchdogTimer.
| Member | Description |
|---|---|
NORMAL | Heartbeats are arriving within the configured timeout. |
HEARTBEAT_MISSED | At least one heartbeat has been missed; timer is degraded. |
DEADLOCKED | Governance paralysis detected by the DeadlockBreaker. |
COLD_BOOT | Enclave has been reset via cold-boot recovery. |
Data Classes
AttestationReport
Returned by SimulatedEnclave.attest(). Captures the enclave measurement and a hash of its sealed-data store at the moment of attestation.
SHA-256 hex digest representing the simulated measurement of the enclave’s code and initial data. Generated fresh from
secrets.token_bytes at enclave construction or after a cold boot.Always
False in the current simulation. In a real TEE this flag would indicate a debug-mode enclave whose secrets should not be trusted.SHA-256 hex digest of the current
_sealed_storage dict at attestation time. Changes every time new data is sealed.Attestation validity flag. Can be set to
False by external verifiers to mark a revoked report.WatchdogEvent
A single timestamped entry in a WatchdogTimer’s event log.
Short event identifier, e.g.
"heartbeat_missed" or "heartbeat_restored".Unix timestamp (
time.time()) recorded at the moment the event was logged.Human-readable description, e.g.
"Last heartbeat 0.12s ago".BatchProposal
Describes a batch of action indices submitted to BatchVerifier for Merkle-tree validation.
Ordered list of action indices that make up the batch macro-trajectory.
Caller-supplied risk estimate for the whole batch. Validated against
BatchVerifier.risk_threshold.Caller-supplied diversity score. Overridden by
BatchVerifier, which recomputes diversity from action_indices internally.Arbitrary key-value metadata attached by the optimizer (e.g. episode ID, strategy name).
Classes
SimulatedEnclave
The central TEE abstraction. Maintains an isolated sealed-storage dictionary and a simulated measurement register. Once attest() is called the enclave is considered attested and remote verifiers can check the returned AttestationReport.
Constructor
Optional genesis manifest to associate with this enclave at creation time. If omitted the enclave starts in an un-initialised state and must be primed with
cold_boot() before it is used in a governed run.attest() -> AttestationReport
Marks the enclave as attested and returns a snapshot attestation report. The sealed_data_hash in the report reflects the sealed-storage state at the moment of the call. Subsequent seal() calls do not invalidate the report; the caller must re-attest to get an up-to-date hash.
Attestation report with
enclave_hash, is_debug=False, sealed_data_hash, and valid=True.seal(key, value)
Writes value into the simulated sealed-storage under key. In a real TEE this would encrypt the value with a hardware-bound key that only this exact enclave measurement can unseal.
Storage key.
Arbitrary Python value to store. Must be serialisable if
sealed_data_hash comparisons matter.unseal(key) -> Optional[Any]
Retrieves a previously sealed value.
Storage key to look up.
The sealed value, or
None if key was not found.verify_measurement(expected_hash) -> bool
Compares expected_hash against the internal measurement register. Returns True only on an exact SHA-256 hex-string match. Used by external verifiers to confirm they are talking to the expected enclave version.
SHA-256 hex digest to compare against the current measurement.
True if the hashes match exactly; False otherwise.cold_boot(genesis)
Resets the enclave to a clean state: all sealed data is erased, a new measurement hash is generated, and the attestation flag is cleared. The provided genesis manifest becomes the new root of trust.
The genesis manifest that primes the fresh enclave state.
Property: is_attested
True after the first successful attest() call; reset to False after cold_boot().WatchdogTimer
A heartbeat-based liveness monitor. The governed compute loop must call heartbeat() at least once every heartbeat_timeout_ms milliseconds. If the heartbeat is missed the state transitions to HEARTBEAT_MISSED and an event is logged.
Constructor
Maximum allowed interval between consecutive
heartbeat() calls, in milliseconds. Internally stored as seconds.heartbeat()
Resets the internal timestamp to time.time(). If the watchdog was previously in HEARTBEAT_MISSED state it returns to NORMAL and logs a "heartbeat_restored" event.
check() -> WatchdogState
Evaluates current liveness. If the elapsed time since the last heartbeat exceeds heartbeat_timeout the state transitions to HEARTBEAT_MISSED and a "heartbeat_missed" event is appended. Returns the current state without modifying it if the state is already COLD_BOOT.
The current watchdog state after the liveness check.
Property: state
The current state without performing a fresh liveness check.
get_events() -> List[WatchdogEvent]
A copy of all logged
WatchdogEvent objects in chronological order.DeadlockBreaker
Detects governance paralysis by counting consecutive deliberation cycles that produce no decision. When the stall count reaches threshold_cycles the breaker signals that a cold-boot should be triggered.
Constructor
Number of consecutive decision-free cycles before the breaker fires.
record_cycle(decision_produced)
Records the outcome of one governance cycle.
Pass
True if the cycle produced a governance decision; False if the deliberation stalled with no output. A True value resets the internal stall counter to zero.check() -> bool
Returns True exactly once — on the cycle that first crosses the threshold — then False forever until reset() is called. This edge-trigger semantics means the caller only needs to handle the cold-boot trigger once per stall episode.
True if a cold boot should be triggered; False otherwise.reset()
Clears the stall counter and the triggered flag, allowing the breaker to arm again for the next episode.
Property: is_deadlocked
True if stalled_cycles >= threshold. Does not set the triggered flag.Property: stalled_cycles
Number of consecutive cycles that have produced no decision since the last reset or decision.
Property: total_cold_boots
Cumulative number of cold-boot triggers since this
DeadlockBreaker instance was created.BatchVerifier
Validates a BatchProposal against risk and diversity thresholds, and constructs a Merkle root over the action-index sequence. The optimizer submits a batch root hash; the TEE validates the macro-trajectory; individual actions are then executed with Merkle proofs.
Constructor
Maximum allowed
aggregate_risk for a batch to pass validation.Minimum required diversity score. Diversity is computed as
unique_actions / total_actions.validate_batch(proposal) -> Tuple[bool, str]
Validates the proposal and computes a Merkle root if it passes.
The batch proposal to validate.
A
(valid, message) tuple. On success message contains the first 16 hex characters of the Merkle root. On failure message explains which check failed.verify_proof(action_index, proof, root) -> bool
Verifies a Merkle inclusion proof for a single action.
The action whose membership is being verified.
Ordered list of sibling hashes from leaf to root.
The trusted Merkle root hash returned by a previous
validate_batch() call.True if the reconstructed root matches root.Constant-Time Helpers
Thegovernance.tee.constant_time module provides flat-branch and fixed-iteration primitives that execute in the same number of CPU cycles regardless of input data, protecting the governance hot-path from cache-timing side-channel attacks.
cmov(condition, a, b) -> T
Branchless conditional move. Returns a if condition is True, b otherwise, without using a Python if.
Selector.
Value returned when
condition is True.Value returned when
condition is False.constant_time_compare(a, b) -> bool
Compares two byte strings in constant time using XOR accumulation. Returns False immediately (non-constant) only if the lengths differ; equal-length inputs are always fully iterated.
First byte string.
Second byte string.
fixed_iteration_map(items, fn, max_size, sentinel) -> List[Any]
Applies fn to exactly max_size items. If len(items) < max_size, the remaining slots are filled with sentinel before fn is applied, ensuring the loop body executes a constant number of times.
Input list.
Mapping function.
Fixed iteration count.
Padding value for slots beyond
len(items).oblivious_access(data, index, default) -> T
Reads data[index] by iterating over the full list and selecting via cmov, so the memory access pattern does not reveal index to a side-channel observer.
Source list.
Index to read obliviously.
Value returned if
data is empty.