opML 与 TEE-ML — 三种 ML 验证方案对比
opML 乐观 ML 验证、TEE 推理(Phala/Marlin/Intel SGX)、与 zkML 对比
日期: 2026-12-26 方向: ZK工程 / 电路开发 阶段: Phase 4 - ZK电路开发实战 (Day 223-243) 标签: #zkML #opML #TEE #ORA #Phala #ML-verification
今日目标
| 类型 | 内容 |
|---|---|
| 学习 | opML 乐观 ML 验证、TEE 推理(Phala/Marlin/Intel SGX)、与 zkML 对比 |
| 实操 | 对比三种 ML 验证方案在不同 use case 的优劣 |
| 产出 | mlverify_compare.md(决策矩阵 + 真实项目案例) |
背景
zkML(Day 238)代价高(10 sec - 30 min prove)。生产场景需要更便宜的方案:
- opML:默认信任 prover,质疑期内 ZK 证明(fraud proof 风格)
- TEE-ML:在 Intel SGX / TDX / ARM TrustZone 等 enclave 内推理,硬件 attestation
三种方案是 web3 ML 验证的「不可能三角」的三个角:
- zkML: 数学最强,最贵
- opML: 经济最优,需要挑战期
- TEE-ML: 性能最好,依赖硬件信任
三种方案的工作原理
1. zkML 复习
Prover:
inference(model, input) → output
+ ZK proof "I correctly ran model on input"
→ publish (output, proof)
Verifier:
verify(proof, model_commit, input, output)
→ accept or reject
Cost: prove ~10s-30min, verify ~50ms
Trust: cryptographic
2. opML(Optimistic ML)
Prover:
inference(model, input) → output
→ publish (output) WITHOUT proof
→ 7-day challenge window
Watcher:
re-runs inference (off-chain or on-chain)
if mismatch: file challenge with ZK proof of correct execution
→ fraud proof verified on-chain
→ if fraud confirmed: penalty + revert
Cost: prove only on dispute, very cheap normal path
Trust: 1-of-N honest watcher assumption
3. TEE-ML(Hardware Trusted Execution)
Prover (running inside TEE):
inference(model, input) → output
TEE produces:
- attestation: signature from chip's attestation key
- quote: proves enclave is running specific code
Verifier:
verify attestation chain (Intel/AMD root → quote)
→ trust output
Cost: ~native ML speed, attestation is cheap
Trust: hardware vendor (Intel, AMD, ARM)
对比表 / Comparison Matrix
| 维度 | zkML | opML | TEE-ML |
|---|---|---|---|
| prove cost (normal path) | 极高 | 几乎零 | ~native ML |
| prove cost (worst case) | 极高 | 一次 fraud proof | 几乎零 |
| verify cost | ~50ms / ~500k gas | ~50ms (rare) + cheap watcher | attestation verify ~10ms |
| delay 到 finality | 立即 | 7 天 challenge | 立即 |
| trust model | crypto only | crypto + 1 honest watcher | hardware vendor |
| 支持模型规模 | 小(< 100M params) | 大(GPT-4 级别 OK) | 大(GPT-4 级别 OK) |
| 隐私(输入) | ✓(电路内) | ✗(fraud proof 时暴露) | ✓(enclave 内) |
| 隐私(模型) | ~(commitment OK) | ✗ | ✓ |
| 硬件需求 | 普通 GPU/CPU | 普通 | TEE-capable(SGX2/TDX/SEV) |
| 生态/工具 | EZKL, Giza | ORA, Optimum | Phala, Marlin |
各派代表项目
zkML 派
- EZKL — Halo2 + ONNX
- Giza — Cairo + PyTorch
- Modulus Labs — Rocky agent
- DDKang zkml — 学术原型
opML 派
- ORA Protocol — opML 主推者,链上 AI Oracle
- 合约:mainnet
0x4Eb...(具体见 ora.io) - 已支持:Llama-2, Mistral, BERT 等
- challenge period: 7 天
- 合约:mainnet
- Optimum — opML stack
- Inference Labs — opML for game logic
TEE-ML 派
- Phala Network — Polkadot 上的 TEE 平台
- SGX2 + AMD SEV 双支持
- 已部署:链上 LLM 推理服务
- Marlin Protocol — 高性能 TEE oracle
- Oasis Sapphire — 智能合约级 TEE
- Bagel/RingoML — TEE-LLM 试点
选型决策树
你要做什么 ML 验证?
├── 模型小(< 100M params)+ 立即结果
│ └── zkML(EZKL)
│
├── 模型大 + 可接受 challenge 期 + 公开输入
│ └── opML(ORA)
│
├── 输入/模型必须保密 + 大模型 + 立即结果
│ └── TEE-ML(Phala / Marlin)
│
└── Mission-critical (e.g., medical, judicial)
└── 多方案叠加:TEE + opML + 关键步骤 zkML
opML 详细:ORA Protocol 案例
ORA 是 opML 主推者,工作流程:
1. dApp 调用 ORA contract: requestML(modelId, inputData)
2. ORA emits Event 触发 off-chain prover
3. Prover 跑 inference → submit (output, modelHash, inputHash) on-chain
4. 7-day challenge window opens
5. Watchers re-run inference; if mismatch:
a. Watcher submits challenge with ZK fraud proof
b. ZK proof: "given (model, input), correct output is X, not Y"
c. ORA contract verifies, slashes prover, refunds
6. After 7 days no challenge: output finalized, dApp receives result
关键创新:fraud proof 是 ZK 而非 single-step interactive bisection。让 challenge 一次性,不需要多轮 round trip。
真实数据:
- Llama-2 7B inference: ~10 sec on prover GPU
- ZK fraud proof (if needed): ~30 min
- Cost in normal path: ~$0.01 per inference call
- Cost with full ZK: ~$10 per call (1000× difference)
TEE-ML 详细:Phala Network 案例
Phala 提供链上 AI inference 服务,运行在 TEE workers:
1. 用户提交加密 input 到 Phala chain
2. Phala worker (SGX/SEV enclave) 接收:
- 解密 input(仅在 enclave 内)
- 跑 inference
- encrypt output
- 生成 attestation
3. 链上合约验证 attestation chain
4. 用户收到加密 output (用自己的 pubkey 加密)
优点: native speed (no quantization overhead), preserves input privacy 缺点: trust Intel/AMD root key + various TEE side-channel attacks (Foreshadow, Plundervolt, SGAxe)
真实漏洞:
- 2018 Foreshadow / L1 Terminal Fault — affected SGXv1
- 2022 ÆPIC Leak — SGX cache leakage
- 2023 Downfall — affected Intel chips
→ 业界共识:TEE 不是 cryptographic 强度,但 cost-effective 在多数场景。
三方案融合 / Hybrid
实际生产中常用 hybrid:
Hybrid 1: TEE + opML
- TEE 跑 inference(快 + 隐私)
- opML 在 challenge 时用 ZK 验证 trace
- 默认信 TEE attestation;如有疑问 ZK fraud proof
Hybrid 2: zkML + LLM
- 大 LLM 用 TEE / opML
- 关键决策步骤(如 risk score)用 zkML 强化
Hybrid 3: TEE + ZK final wrap
- TEE 内部跑模型
- TEE attestation + 一个简单 ZK proof 整合上链
经济与去中心化分析
| 方案 | 平均 cost | dispute cost | 去中心化 |
|---|---|---|---|
| zkML | $1-100 / inference | - | 完全(任何人 verify) |
| opML | $0.01-0.1 | $10 (rare) | 1-of-N watcher |
| TEE | $0.001-0.01 | - | 中(依赖硬件 vendor) |
opML 通常 100-1000× 比 zkML 便宜,且支持任意大模型。
真实数据 / Real Performance
zkML (EZKL, MNIST CNN)
- inference time (off-chain): 50 ms
- prove time: 10 sec
- proof size: 10 KB
- verify gas: 700k
opML (ORA, Llama-2 7B)
- inference time: 5 sec on H100
- "happy path" cost: $0.005
- fraud proof cost (if challenge): $5-50
- finality: 7 days
TEE-ML (Phala, Llama-2 7B)
- inference time: 10 sec on TEE-capable CPU (no GPU TEE in production yet)
- attestation size: ~1 KB
- attestation verify gas: ~50k
- trust: Intel SGX2 root of trust
关键速查
zkML: cryptographic, slow, small models
opML: economic, delayed finality, big models
TEE-ML: hardware trust, fast, hardware vendor risk
合适的场景:
zkML → 链上 oracle, 信用评分, 短决策
opML → LLM 推理, 链上 AI agent, treasury 决策
TEE → 隐私推理, 高频 inference, 现实世界 IoT
面试题
-
Q: 三种 ML 验证方案的核心 trade-off? A: zkML:数学最强,但 cost 极高、模型大小受限。opML:cost 最低(normal path),代价是 7 天 challenge 期 + 1-of-N honest watcher 假设。TEE-ML:性能最好,但依赖硬件 vendor 信任,且历史上多个 SGX 漏洞证明 TEE 不是 cryptographic 强度。
-
Q: ORA 的 opML 与 Optimistic Rollup 的 fraud proof 有什么区别? A: 类似——都是「先 commit,再 challenge」。区别:(a) opML challenge 用 single-step ZK fraud proof,不像 OR 的 interactive bisection;(b) 验证对象是 ML inference 而非 EVM execution。本质都是「乐观 + ZK 兜底」范式。
-
Q: 为什么大型 LLM(GPT-4)用 zkML 不可行,但 opML 可行? A: zkML 需要把整个 inference trace 转电路(10^15 约束量级),不可行。opML 只在 dispute 时才证明(极少发生),且可以分段证明(只证明 disputed step)。所以 LLM 选 opML 或 TEE。
-
Q: 你给一个 web3 信用评分应用选 ML 验证方案,会选哪个? A: 看模型大小:(a) 小型 logistic regression / 决策树 — zkML 最优(快 verify、立即 finality);(b) 中等 ResNet/transformer — opML(cost 友好);(c) 大 LLM — TEE 或 opML。考虑因素:是否需要保密用户输入(隐私强度依次:zkML > TEE > opML)。
明日预告
Day 240 — ZK Bridge / Light Client Proofs。zkBridge、Succinct、Polyhedra:让跨链不再需要 multisig,全用 ZK 证明对方链状态。