Expand description
§bitrouter-attestation
Provider-agnostic, client-side confidential-inference verification. The
central abstraction is ConfidentialVerifier: given a model and a nonce
it proves (L1) the serving endpoint is genuine TEE hardware running the
legitimate, policy-pinned model, and given an exact request/response it
proves (L1.5) that exchange ran in that TEE unmodified.
The design mirrors private-ai-gateway’s UpstreamVerifier /
UpstreamVerifiedEvent normalization, but runs in the caller’s own trusted
process (bitrouter-cli’s local daemon) instead of inside an attested
re-signing gateway — so it needs no TEE of its own. See the refactor
spec (bitrouter-cloud/docs/bitrouter-attestation-plugin.md).
This crate is intentionally pure: no SDK, axum, or server dependency, so it
ships in the daemon, the bitrouter verify CLI, the cloud /v1/aci/verify
endpoint, and third-party clients alike.
Structs§
- AciDcap
Verifier Policy - The pinned acceptance policy. Constructed once at boot from operator config; every field is normalized so config and report compare equal regardless of hex casing or EC encoding framing.
- Attestation
Cache - A model → (verdict, expiry) cache. Cloneable handle over shared state.
- Attestation
Checks - The per-check breakdown of an attestation, mirroring private-ai-gateway’s
AciDcapVerifiercheck set (src/aci/verifier/dcap.rs). Every field is surfaced so a caller can see why a verdict is (un)verified, gateway-style. - Attestation
Info - The dstack
infoblock. Source of the policy-pinning fields (spec §1.5 Decision 8). These map to the ported DCAP policy’s pins (seecrate::near::dcap::model_identity). - Attestation
Report - Top-level report body:
{ gateway_attestation, model_attestations }. - Attestation
Verdict - L1 verdict: the model endpoint is genuine TEE hardware running the legitimate (policy-pinned) model. Yields the attested signing identity set that L1.5 binds a chat signature to.
- Chat
Signature - NEAR’s per-chat signature response (
GET {base}/v1/signature/{chat_id}). - Dcap
Quote Verifier - Production
QuoteVerifier: full DCAP verification against a PCCS. - Dstack
Event - One dstack measured-boot event. Each event with
imr == 3extends RTMR3 byRTMR3 = sha384(RTMR3 ‖ digest);eventnames it ("app-id","compose-hash", …) andevent_payloadis the measured value. - Exchange
Input - The exact bytes of one request/response exchange to verify (L1.5).
- Mock
Transport - In-memory transport that replays a canned report — the verifier’s offline test seam. Public so the plugin/daemon can reuse it in their own tests.
- Model
Attestation - One serving node’s attestation of a model.
- Model
Identity - The identity fields a
ModelAttestationpresents to the policy, extracted from itsinfoblock (Decision 8). - Near
Verifier - The NEAR
ConfidentialVerifier. Composes the report fetch, GPU NRAS check, DCAP quote verification, report_data/compose bindings, and the load-bearing policy pin into a singleAttestationVerdict, fail-closed at every step (spec §1.5 cond. 3) and TTL-cached. - Nras
Verdict - Outcome of checking an NRAS EAT. Every field must hold for
Self::passed. - Nvidia
EatKey - Resolves the NVIDIA NRAS EAT verification key. Wraps
jsonwebtokenso callers (the daemon, the CLI, third parties) don’t take a directjsonwebtokendependency. NVIDIA rotates its signing keys, so the right one is selected per request by the EAT’skid— useSelf::fetch_jwks(NVIDIA_NRAS_JWKS_URL) for that.Self::from_ec_pempins a single key. Pin/fetch in the trusted process — never through the untrusted cloud (§1.5). - Reqwest
Transport - Live
reqwesttransport pointed at a provider base URL (e.g. the cloud’s/v1/acipassthrough, orhttps://cloud-api.near.ai/v1). - TcbInfo
- The dstack
tcb_infosub-block. We model onlyapp_compose— the raw compose document whosesha256must equalcompose_hash(Task 3’s compose↔mr_config binding). The base registers (mrtd,rtmr0..2) reported here are self-declared cloud metadata and are not trusted: the verdict path asserts the quote’s decoded base registers against the policy’s pinned reference bundle (crate::AciDcapVerifierPolicy::accepts_base_measurements, issue #567), and bindsrtmr3via the event-log replay (crate::event_log_binds_info). - TdxMeasurements
- The measurement registers and report_data decoded from a TDX quote.
- Verified
Exchange - L1.5 result: a specific exchange provably ran in the attested TEE unmodified.
← gateway’s
UpstreamVerifiedEvent, normalized and client-side. - Verifier
Registry - Dispatches by provider so the daemon/cloud can hold one handle and serve
many confidential providers. ← gateway’s
RoutingUpstreamVerifier. NEAR is the only impl today; the registry exists so Tinfoil/Phala/AciGateway slot in without touching callers.
Enums§
- Integrity
Proof - Each provider’s native integrity proof — the portable artifact a third
party could re-check. Mirrors the gateway’s evidence/
ChannelBinding, but kept provider-native rather than normalized to one receipt shape. - Policy
Error - Verify
Error - Errors a
ConfidentialVerifiercan return. Note that a failed verification is not an error — it is a verdict withverified=false(fail-closed).VerifyErroris reserved for the verifier being unable to even reach a verdict it can trust (misconfiguration, malformed input).
Constants§
- DEFAULT_
CACHE_ TTL_ SECONDS - Default verdict cache TTL (spec §8).
- NRAS_
GPU_ URL - NVIDIA NRAS GPU attestation endpoint.
- NVIDIA_
NRAS_ JWKS_ URL - NVIDIA’s NRAS JWKS endpoint — the rotating set of EAT signing keys.
- PHALA_
PCCS_ URL - Default Phala PCCS endpoint for DCAP collateral, re-exported so callers can pin it in the daemon rather than fetch a URL through the untrusted cloud.
- SIGNING_
ALGO - The signing algorithm bitrouter requests and verifies (spec Decision 7): secp256k1 ECDSA with EIP-191 recovery, matching NEAR’s published vector.
- TRUST_
BOUNDARY - Honest trust-boundary label: we verify NEAR’s model quote directly, not
(as
nearai.pydoes) trust NEAR’s gateway.
Traits§
- Confidential
Verifier - Verifies confidential inference for one provider family, client-side.
- Quote
Verifier - Strategy for turning a raw TDX quote into measurements, abstracted so the
composing verifier can be unit-tested offline. The production
DcapQuoteVerifierperforms full DCAP verification (Intel signature + collateral); tests substitute a parse-only stub. - Report
Transport - Fetches confidential-inference evidence for a provider. Mockable so the verifier’s crypto runs offline in CI.
Functions§
- chat_
signing_ text - The exact text the TEE signs:
"{model}:{sha256(req)}:{sha256(resp)}". - check_
nras_ eat - Verify an NRAS response: EAT signature against
decoding_key, the overall result claim, and that the EAT nonce echoesnonce. Fails closed (returns a failed verdict) on a malformed body or a bad signature, never an error — the caller folds the verdict straight intocrate::AttestationChecks. - compose_
matches_ mr_ config - True iff
sha256(app_compose)(hex) equalsmr_config(case-insensitive), proving the running config is the measured one. - event_
log_ binds_ info - True iff the event log replays to the quote’s RTMR3 and records exactly
the
infofields the policy trusts. This is what anchorsapp_id,compose_hash,os_image_hash, andkey_provider_infoto the genuine TEE measurement. Any mismatch ⇒false(fail-closed). - model_
identity - Extract the policy-relevant identity from a model’s
infoblock:workload_id ← app_id,image_digests ← {os_image_hash, compose_hash},kms_root ← key_provider_info.id(spec §1.5 Decision 8). The compose container@sha256digests are additional image pins that can be folded in later without changing this shape. - parse_
tdx_ quote - Decode measurements from a raw TDX quote without network collateral. Offline and deterministic; does not prove Intel signed the quote.
- post_
nras - POST a model’s
nvidia_payloadto NRAS and return the raw response body. Online; the daemon calls this directly (not through the untrusted cloud). Errors are transport-level; claim/signature checking ischeck_nras_eat. - recover_
eip191_ address - Recover the 0x-prefixed Ethereum address that produced
signature_hexovermessageunder EIP-191.signature_hexis 65 bytes (r ‖ s ‖ v), hex, with or without a0xprefix. ReturnsNoneon any malformed input — the caller folds that into a fail-closed verdict. - replay_
rtmr - Replay the dstack event log into the register
imr:mr ← sha384(mr ‖ digest)for each matching event, starting from zero. ReturnsNoneif a digest is unparseable or the result isn’t 48 bytes. - report_
data_ binds - True iff
report_data(the 64 bytes from the verified TDX quote) bindssigning_addressin its first 32 bytes (20-byte address, zero-padded) and the 32-bytenoncein its last 32 bytes — the “standard” dstack mode. - sha256_
hex sha256(bytes)as lowercase hex — the request/response hashes in the text.- verify_
tdx_ quote - Full DCAP verification: fetch collateral from
pccs_url, verify Intel’s signature and TCB atnow_unix, and return the measurements from the verified report. Network-dependent.