How automata-network/unifi-tdx-prover works
Project Type and Purpose
• This is a Rust‐based, microservice/open‐source tool (“Unifi TDX Prover”) designed to run inside an Intel TDX Trusted Execution Environment (TEE).
• Its primary responsibility is to generate and sign rollup validity proofs (PoE) for Unifi’s atomicWithdrawal by executing blocks, building proofs of block execution (PoB), and providing attestation reports and ephemeral key–signed proofs to an on‐chain ProverRegistry contract.
File Structure Analysis
• Top-level binaries:
• bin/multi-prover: the long-running Actix-Web Prover service
• bin/guest-input-to-proof-request: a CLI tool to convert raw GuestInput JSON → ProofRequest JSON
• crates/: modular libraries
• base/: core types and helpers (base64, Ethereum RPC, keypairs, thread management, on‐chain ProverRegistry interactions)
• executor/: block execution engine (chain state, memdb) and proof‐of‐block (PoB) logic
• prover/: orchestrates PoB → PoE signing and exposes an internal Prover API
• tee/: interfaces with TDX (mock or real attestation report generation, IMA, TDX builders, agent service)
• config/: JSON configs for different environments (holesky/testnet/mainnet vs. localhost_mock)
• testdata/: sample GuestInput and expected ProofRequest JSON files
Architecture Overview from README
• Sequence:
1. TDX Prover initializes, generates ephemeral key, calls ProverRegistry contract to register the instance (attestation report + userData)
2. On each new block, an external “ProofBuilder API” (multi-prover) calls requestProof(ProofInput)
3. The prover → executor executes block (PoB), signs PoE with ephemeral key inside TEE, returns ProofResponse
4. ProofBuilder then calls ProverRegistry.verifyProofs([...]) on-chain
Components
a. Front-end / Client Tools:
• CLI: guest-input-to-proof-request
• ProofBuilder API (could be an external service or UI that calls multi-prover)
b. Prover Service (multi-prover):
• Actix-Web HTTP Server listening on configurable port (20300)
• Prover API layer (crates/prover/src/api.rs)
• Executor module (crates/executor) for PoB
• TEE interface module (crates/tee) for attestation & signing PoE
• Base module (crates/base) for on-chain interactions & key management
c. External Systems:
• Ethereum JSON-RPC node (for sending register & verify transactions)
• ProverRegistry Solidity contract (on Unifi’s layer1)
• AttestationVerifier Solidity contract
d. Data Stores / Config:
• In-memory DB (memdb) for chain state in executor
• Local config files (config/*.json)
Relationships & Data Flow
• CLI → Prover Service (submit GuestInput JSON)
• Prover Service → Executor (PoB generation)
• Executor → Prover Service (PobResult)
• Prover Service → TEE module (attach attestation & sign PoE)
• Prover Service → Ethereum RPC (register instance, verify proofs)
• Ethereum RPC → On-chain contracts (ProverRegistry & AttestationVerifier) → events back to Prover Service
Architectural Patterns & Principles
• Modular crates correspond to bounded contexts (Separation of concerns)
• Single Long-Running Service (multi-prover) + Lightweight CLI
• TEE enclave abstraction (mock vs. real) behind a unified API (agent_service.rs)
• On-chain registration & verification as an external dependency
Technologies & Frameworks
• Rust + Cargo workspaces
• Actix-Web for HTTP server
• Intel TDX APIs (via crates/tee)
• Ethereum JSON-RPC (ethers-rs or custom base::eth module)
• JSON config & serde for serialization
• CLI via cargo run --bin
Final Recommendations
• Configuration injection (config/*.json) at service startup
• Ephemeral key lifecycle: generated on startup in TEE, used per-block, rotated via on-chain event