The TEE module provides hardware-enforced isolation between the governance layer and the optimization layer. In production, the Speaker state machine runs inside an SGX, SEV, or TrustZone enclave whose memory is encrypted and integrity-protected by the CPU — the optimization layer cannot read, write, or simulate the enclave’s private state. The classes in this module are a software simulation of those hardware guarantees: they provide the same API and behavioral semantics for development and testing, but do not provide actual hardware isolation.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.
SimulatedEnclave
The enclave provides three core capabilities: attestation (proving it is running authentic governance code), sealed storage (persisting secrets that survive reboots but cannot be read outside the enclave), and cold-boot recovery (resetting to a known genesis state).AttestationReport Fields
enclave_hash corresponds to MRENCLAVE — a measurement computed over the enclave’s code and initial data pages during loading. Remote verifiers compare this value against a known-good reference hash to confirm the enclave is running the authentic Speaker code and has not been tampered with.
WatchdogTimer
The watchdog timer detects compute starvation — situations where the host operating system is starving the enclave of CPU cycles, causing governance decisions to time out and default actions to be triggered. In hardware, the watchdog is a physically separate timer peripheral that the OS cannot suppress.WatchdogState Enum
HEARTBEAT_MISSED state would assert an unmaskable interrupt (NMI equivalent) that cannot be blocked by the OS. The interrupt handler suspends all optimization layer tensor execution pipelines, freezes all active governance state, and logs the watchdog event to write-only audit storage.
DeadlockBreaker
The deadlock breaker detects governance paralysis — situations where the parliament repeatedly fails to reach consensus over many cycles. Rather than a liveness problem (like the watchdog handles), this is a correctness problem: the parliament is technically running but perpetually deadlocking. Afterthreshold_cycles consecutive cycles without a governance decision, the breaker triggers a cold boot to the genesis baseline.
The deadlock breaker and the heartbeat watchdog are complementary — they detect different failure modes. The watchdog catches the OS starving the enclave of CPU cycles. The deadlock breaker catches the parliament painting itself into a corner through procedural deadlock. A system can fail either way, and both mechanisms are needed.
Deadlock Recovery Protocol
WhenDeadlockBreaker.check() returns True, the enclave executes the following cold-boot sequence inside the TEE:
- Freeze all governance state — no new actions, no state changes
- Reload the exact genesis manifest
Gfrom sealed storage - Discard all modified parameter envelopes — reset to genesis defaults
- Clear all meta-constraints
- Reload the active contract set from genesis defaults (constitutional contracts only)
- Log the recovery event to write-only audit storage with a full state snapshot
- Resume governance from the genesis baseline
Constant-Time Execution
Thegovernance.tee.constant_time module provides data-oblivious execution helpers that prevent cache-timing side-channel attacks. An optimization layer running on the same physical CPU can monitor L3 cache access latencies or performance counters to infer whether a vote passed or failed — effectively training a black-box model of the enclave’s decision boundaries without ever reading the enclave’s memory.
The mitigation: make every execution path take the same number of CPU cycles regardless of input data.
Batch Verification
Thegovernance.tee.batch module implements Merkle-tree batch verification to resolve the TEE throughput paradox: the optimization layer operates at GPU throughput (millions of actions per second), while individual TEE validation is CPU-bound. Batching N actions and submitting only the root hash amortizes the TEE overhead across all N actions.
Batch Verification Flow
N=1000, the TEE overhead per action drops from ~23 microseconds (individual validation) to ~0.023 microseconds — a three-order-of-magnitude throughput improvement.
Verifying Individual Actions Against a Signed Root
Real-World Hardware Context
In production, the components in this module map to real hardware primitives:| Simulation Class | Production Hardware |
|---|---|
SimulatedEnclave | Intel SGX enclave or AMD SEV virtual machine |
AttestationReport | SGX REPORT / QUOTE structure or SEV-SNP attestation report |
seal() / unseal() | SGX data sealing with sgx_seal_data() / sgx_unseal_data() |
cold_boot() | SGX enclave destruction + re-initialization from sealed genesis manifest |
WatchdogTimer | Hardware watchdog peripheral (Intel 8254 timer or on-die SoC watchdog) |
DeadlockBreaker | Deadlock counter running inside the TEE’s measured code region |
constant_time.* | Compiler-enforced constant-time patterns (volatile reads, cmov instructions) |
BatchVerifier | Merkle verification running inside the enclave’s protected execution context |
Intel SGX
Best fit for the Speaker enclave. 128 MB EPC limit is not a constraint — the Speaker is KB-scale. Strongest remote attestation via EPID/DCAP. Deployed since Skylake (2015).
AMD SEV
Preferred if the full parliament (all seven member value functions) needs hardware isolation. Full VM memory encryption eliminates EPC size constraints.
ARM TrustZone
Appropriate for edge deployments (robotics, autonomous vehicles). High maturity since ARMv6 (2001), but no standardized remote attestation.
Software Simulation
The classes in this module — suitable for development, testing, and CI. Provides correct API and protocol semantics. Does not provide hardware isolation.
API Reference
SimulatedEnclave constructor and methods
SimulatedEnclave constructor and methods
The genesis manifest to initialize from. If
None, the enclave starts without a genesis configuration and must receive one via cold_boot() before signing any governance outputs.Produces an attestation report containing the enclave’s measurement hash, debug status, and a hash of the current sealed storage. Sets
is_attested = True.Stores
value in the enclave’s encrypted sealed storage under key. Data persists across governance cycles but is cleared by cold_boot().Retrieves the value stored under
key, or None if the key does not exist or has been cleared.Compares the enclave’s internal measurement against
expected_hash. Used by remote verifiers to confirm they are communicating with the authentic Speaker implementation.Wipes all sealed storage, generates a fresh measurement, and reinitializes from the provided genesis manifest.
is_attested is reset to False — the enclave must re-attest before its outputs are trusted.True after attest() has been called and before cold_boot() is called.WatchdogTimer constructor and methods
WatchdogTimer constructor and methods
Milliseconds without a heartbeat before the state transitions to
HEARTBEAT_MISSED. The hardware default is set to 2× the worst-case governance cycle time (~23 µs), giving a 100 ms default a ~4,000× safety margin.Resets the last-heartbeat timestamp. Called by the Speaker at the end of each governance cycle to signal continued liveness. If the state was
HEARTBEAT_MISSED, calling heartbeat() restores it to NORMAL.Checks the elapsed time since the last heartbeat. If more than
heartbeat_timeout seconds have passed and the state was NORMAL, transitions to HEARTBEAT_MISSED and logs the event. Returns the current state.Returns the full event log, including
heartbeat_missed and heartbeat_restored events with timestamps and details.DeadlockBreaker constructor and methods
DeadlockBreaker constructor and methods
Number of consecutive governance cycles without a decision before
check() returns True and a cold boot should be triggered.Call once per governance cycle. If
decision_produced=True, resets the stalled-cycle counter to 0. If False, increments it.Returns
True if stalled_cycles >= threshold and a cold boot has not yet been triggered for this deadlock event. Returns False after a cold boot has been triggered (until reset() is called).Resets
stalled_cycles to 0 and clears the _cold_boot_triggered flag. Call after a cold boot has completed.True when stalled_cycles >= threshold, regardless of whether a cold boot has been triggered.The current count of consecutive governance cycles without a valid decision.
Total number of cold boots triggered by this instance since creation.