security-gpu-attest
Zero-CGo, zero-entitlement demo that executes an inline Metal compute kernel,
attests real Apple Silicon GPU execution via x/engineattest,
signs the attestation receipt with an ephemeral hardware Secure Enclave P-256
key via x/enclave, verifies the ASN.1 signature with
Go's stdlib crypto/ecdsa, and proves a CPU-forged impostor is rejected.
What It Does
- Attested GPU compute (
metal + x/engineattest): compiles an inline
MSL affine_mix kernel and executes it through engineattest.Queue.GPU,
verifying a nonzero hardware GPU scheduling window (GPUEndTime > GPUStartTime > 0)
and hashing the GPU output buffer (SHA-256).
- Negative-control CPU impostor: runs a CPU loop computing the same
transform without dispatching to Metal and asserts
engineattest.Queue.GPU
rejects it with engineattest.ErrDidNotRun.
- Hardware Secure Enclave receipt signing (
x/enclave): generates an
ephemeral P-256 key (IsHardwareBacked() == true on Apple Silicon; cleaned
up via defer key.Close()), signs the canonical attestation receipt digest,
and cross-verifies the DER signature + tampered-digest rejection using stdlib
crypto/ecdsa.VerifyASN1.
Usage
CGO_ENABLED=0 go run ./examples/security/security-gpu-attest
Flags:
-n — float32 elements to process on GPU (default 1048576)
-require-hardware — fail closed if Secure Enclave is unavailable
Sample Output (Apple M4 Max)
=== GPU Execution Attestation (Apple M4 Max) ===
GPU dispatch: PASS (kernel=affine_mix, n=1048576, gpu=104µs)
Output SHA-256: c67fa3230fbc1154e29d05104ecf3df8522d3673cb29770b7232dbf7155258c2
CPU impostor: REJECTED (engineattest: no command buffer was created during the attested region: engine did not execute during the attested region)
=== Secure Enclave Receipt Signature ===
Probe available: true
Hardware-backed: true (ephemeral key cleaned up on exit)
Public key: 044a46bf178d4657a98e2bf99b48f2d8... (65B X9.63)
Receipt: device=Apple M4 Max;kernel=affine_mix;n=1048576;gpu_us=104;out_sha256=c67fa3230fbc1154;attested=gpu;ts=2026-11-28T01:58:10Z
ECDSA ASN.1 sig: 72 bytes
stdlib verify: PASS (crypto/ecdsa.VerifyASN1)
Tamper check: REJECTED=true