dcap-qvl
This crate implements the quote verification logic for DCAP (Data Center Attestation Primitives) in pure Rust. It supports both SGX (Software Guard Extensions) and TDX (Trust Domain Extensions) quotes.
Features
- Verify SGX and TDX quotes
- Get collateral from PCCS or Intel PCS
- Extract information from quotes
- Default PCCS: Phala Network (
https://pccs.phala.network) - recommended for better availability and lower rate limits
Usage
Add the following dependency to your Cargo.toml file to use this crate:
[]
= "0.1.0"
Crypto Backend Selection
This crate supports two crypto backends: ring (optimized, uses assembly) and rustcrypto (pure Rust).
Gas/Performance Comparison (NEAR Contract)
| Backend | Gas Consumption |
|---|---|
| ring | ~175 Tgas |
| rustcrypto | ~288 Tgas |
Ring saves ~113 Tgas (~39%) compared to rustcrypto.
Feature Flags
# Default: both backends enabled, ring takes priority
= "0.3.11"
# For WASM/NEAR (recommended for gas efficiency):
= { = "0.3.11", = false, = ["std", "ring"] }
# For pure Rust / no-assembly environments:
= { = "0.3.11", = false, = ["std", "rustcrypto"] }
Backend Selection Rules for verify()
The top-level verify() function selects backend based on enabled features:
ring enabled |
rustcrypto enabled |
verify() uses |
|---|---|---|
| ✓ | ✓ | ring |
| ✓ | ✗ | ring |
| ✗ | ✓ | rustcrypto |
| ✗ | ✗ | compile error |
⚠️ Important: Due to Cargo's additive feature model, if any crate in your dependency tree enables the ring feature, the top-level verify() will use ring. This can lead to unexpected behavior in complex projects.
Explicit Backend Selection (Recommended)
For predictable behavior, especially in complex projects, use explicit backend modules:
// Explicitly use ring backend
use verify;
// Explicitly use rustcrypto backend
use verify;
Example
use get_collateral;
// Use explicit backend for predictable behavior
use verify;
use PHALA_PCCS_URL;
async
Python Bindings
Python bindings are available for this crate, providing a Pythonic interface to the DCAP quote verification functionality.
Quick Start
# Build and test Python bindings
# Test across Python versions (3.8-3.13)
Usage
=
# Get collateral and verify in one step (defaults to Phala PCCS)
= await
See python-bindings/ for complete documentation, examples, and testing information.
License
This crate is licensed under the MIT license. See the LICENSE file for details.