Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
branches:
- main
- staging
# `labeled` lets reviewers opt a PR into integration / GPU coverage by
# adding `run-integration` or `run-gpu` to the PR. Per-job `if:` checks
# the label set, so unrelated jobs still skip.
Expand Down Expand Up @@ -62,6 +63,56 @@ jobs:
- name: Pytest (test_paillier_encryption)
run: uv run pytest tests/x_vec/test_paillier_encryption.py

- name: Build and test native BFV CPU kernels
run: |
sudo apt-get update
sudo apt-get install -y libgmp-dev valgrind clang
make -C src/xtrace_sdk/x_vec/crypto/bfv_cpu_ext PYTHON="$PWD/.venv/bin/python"
uv run python -c 'from xtrace_sdk.x_vec.crypto.bfv_cpu_ext import _bfv_rns, _bfv_private; assert _bfv_rns.ABI_VERSION == 4; assert _bfv_private.ABI_VERSION == 1'
uv run pytest tests/x_vec/test_bfv_encryption.py tests/x_vec/test_bfv_evaluator.py tests/x_vec/test_bfv_rns.py tests/x_vec/test_bfv_native.py tests/x_vec/test_bfv_residue.py tests/x_vec/test_bfv_client.py tests/x_vec/test_bfv_security.py tests/x_vec/test_bfv_verified_client.py tests/x_vec/test_bfv_private.py tests/x_vec/test_bfv_guarded_client.py tests/x_vec/test_bfv_assurance.py

- name: BFV Nitro attestation and protocol regressions (offline)
run: uv run --extra bfv-nitro pytest tests/x_vec/test_bfv_nitro.py tests/x_vec/test_bfv_attested_client.py tests/x_vec/test_bfv_nitro_transport.py tests/x_vec/test_bfv_nitro_aws.py

- name: SEAL comparison (synthetic inputs only)
run: |
uv pip install --python .venv/bin/python -r experiments/bfv/requirements.txt
.venv/bin/python -m pytest experiments/bfv/test_packed_hamming.py tests/x_vec/test_bfv_client.py::test_optional_seal_reference

- name: Build documentation
run: uv run --extra bfv-nitro sphinx-build -W -b html docs /tmp/xtrace-docs

- name: BFV native arithmetic sanitizers
run: |
g++ -std=c++17 -O1 -g -fsanitize=address,undefined -fno-omit-frame-pointer -I src/xtrace_sdk/x_vec/crypto/bfv_cpu_ext tests/x_vec/native/test_bfv_rns.cpp -lgmpxx -lgmp -o /tmp/test_bfv_rns
/tmp/test_bfv_rns
g++ -std=c++17 -O1 -g -fsanitize=address,undefined -fno-omit-frame-pointer -I src/xtrace_sdk/x_vec/crypto/bfv_cpu_ext tests/x_vec/native/test_bfv_private.cpp -lgmpxx -lgmp -o /tmp/test_bfv_private
/tmp/test_bfv_private

- name: BFV private kernel secret-taint regression
run: |
bfv_gcc_install=$(dirname "$(g++ -print-libgcc-file-name)")
for bfv_cxx in g++ clang++; do
bfv_toolchain=()
if [ "$bfv_cxx" = clang++ ]; then
bfv_toolchain=("--gcc-install-dir=$bfv_gcc_install")
fi
"$bfv_cxx" "${bfv_toolchain[@]}" -std=c++17 -O3 -g -fPIC -fstack-protector-strong -D_FORTIFY_SOURCE=3 -DXTRACE_BFV_CTGRIND -I src/xtrace_sdk/x_vec/crypto/bfv_cpu_ext tests/x_vec/native/test_bfv_private.cpp -lgmpxx -lgmp -o /tmp/test_bfv_private_taint
valgrind --tool=memcheck --error-exitcode=1 --track-origins=yes /tmp/test_bfv_private_taint
if valgrind --tool=memcheck --error-exitcode=1 /tmp/test_bfv_private_taint --negative-control; then
exit 1
fi
done

- name: BFV Python binding sanitizers
run: |
bfv_py_include=$(.venv/bin/python -c 'import sysconfig; print(sysconfig.get_paths()["include"])')
g++ -std=c++17 -O1 -g -fsanitize=address,undefined -fno-omit-frame-pointer -fPIC -shared -I"$bfv_py_include" src/xtrace_sdk/x_vec/crypto/bfv_cpu_ext/bindings.cpp -lgmpxx -lgmp -o /tmp/bfv_sanitized.so
g++ -std=c++17 -O1 -g -fsanitize=address,undefined -fno-omit-frame-pointer -fPIC -shared -I"$bfv_py_include" src/xtrace_sdk/x_vec/crypto/bfv_cpu_ext/private_bindings.cpp -lgmpxx -lgmp -o /tmp/bfv_private_sanitized.so
bfv_asan_runtime=$(g++ -print-file-name=libasan.so)
bfv_cpp_runtime=$(g++ -print-file-name=libstdc++.so)
ASAN_OPTIONS=detect_leaks=0 PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 LD_PRELOAD="$bfv_asan_runtime:$bfv_cpp_runtime" .venv/bin/python tests/x_vec/native/run_binding_sanitizers.py /tmp/bfv_sanitized.so /tmp/bfv_private_sanitized.so

# ── Integration tests (require XTrace API credentials) ──────────
# Triggers:
# - PRs: only when explicitly labeled `run-integration` (avoids quota
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,28 @@ All notable changes to this project will be documented in this file.

### Changed

- Native `BFVClient` server evaluation now defaults to cached GMP key switching: gadget products are accumulated and folded before unpacking, with fewer coefficient checks in Python. `server_backend="reference"` retains the original arithmetic. Parameters, ciphertexts and serialized keys remain compatible. A paired server benchmark checks identical ciphertext outputs and separates first-query from warm-query timings.
- **Device selection moved from the `DEVICE` environment variable to a `device=` constructor keyword** on `PaillierClient`, `PaillierLookupClient`, `ExecutionContext.create`, `ExecutionContext.load_from_disk`, and `ExecutionContext.load_from_remote`. The new default is `device="auto"`: clients probe for the GPU extension at construction time and fall back to CPU silently when no GPU is present. If a GPU is detected on the host (`/dev/nvidia0`, `nvidia-smi`, or `CUDA_VISIBLE_DEVICES`) but the extension fails to load, a warning is emitted instead of a silent CPU fallback so misconfigured GPU hosts don't quietly run on CPU. `device="gpu"` raises if the extension is unavailable; `device="cpu"` skips probing entirely.
- The `DEVICE` environment variable is no longer read. Existing callers must migrate to the `device=` kwarg.

### Added

- Optional AWS Nitro `BFVAttestedClient`/`BFVAttestedServer` sessions: signed owner requests, exact image measurement pins, fresh attestation, and enclave response receipts checked before private decryption. The enclave evaluates once; the BFV secret stays on the owner. Includes the `bfv-nitro` extra, bounded relay/service, local image build records and an opt-in real AWS test. This remains experimental and requires hardware validation and independent review before production use.
- Persistent BFV `server_backend="residue"` arithmetic with a product of 60-bit primes, fused NTTs and exact RNS tensor scaling. Existing GMP, reference and earlier native backends remain available for differential tests; selecting the product modulus requires fresh keys and a new index.
- BFV execution policies, bounded authenticated sessions, protected private exports, and an owner-controlled recomputing verifier. A separate native private decoder provides fixed-work terminal arithmetic with locked/wiped buffers; this is not an end-to-end constant-time guarantee.
- Complete C++ BFV server evaluation through `server_backend="native"`: direct packed ciphertext buffers, prepared masks, native result merging and compaction, lazy transforms, Barrett reduction and certified CRT conversion modulo q with exact fallback. Includes opt-in native phase profiling; existing BFV keys, wire formats and backends remain compatible. The current optional extensions require public ABI version 4 and private ABI version 1.

- Optional native BFV `server_backend="rns"`, with independently implemented C++ RNS/NTT polynomial arithmetic, cached transformed evaluation keys, exact GMP reconstruction, and a native Hamming tile circuit. Preserves native BFV keys, ciphertext outputs and wire format. Includes native-boundary tests, sanitizer oracles, optional SEAL benchmarks and correctly tagged binary wheels. The previous GMP and reference backends remain available.
- Native GMP BFV primitives in `crypto/encryption/bfv.py` and a `BFVClient` in `crypto/bfv_client.py`, with CRT batching, ciphertext multiplication/relinearization, public-key Hamming evaluation, packed distance responses, and terminal modulus compaction. Includes CPU benchmarks and tests against plaintext algebra and an optional SEAL oracle. This is an experimental local implementation; the existing Paillier clients and SEAL research example are preserved.
- Offline BFV packed Hamming experiment under `experiments/bfv`, with an isolated public-key server evaluator, correctness tests, a comparison against an exported Paillier Git revision, and a research report. The production Paillier path and dependencies are unchanged.
- `xtrace_sdk.x_vec.crypto.device.resolve_device` — shared device-resolution helper used by both Paillier clients and intended for future homomorphic clients with optional GPU backends.
- `test_cross_device_interop` — parametrised test covering CPU↔GPU portability for both `PaillierClient` and `PaillierLookupClient`. Verifies that contexts saved on one device load correctly on the other (hash equality), and that ciphertexts produced on either backend round-trip correctly through the other for both encryption and server-side homomorphic add.

### Security

- BFV regression tests demonstrate secret-key recovery from malicious ciphertexts and observable post-decryption accept/reject behavior, even with private result checks. The guarded and Nitro clients require approval before decryption. Attestation authenticates approved execution under the TEE's assumptions; raw BFV remains malleable and is not given a general chosen-ciphertext security claim.
- Nitro rejects malformed certificate versions and duplicate extensions through the bounded protocol error path. Staging PRs now run quality checks, SEAL reference tests and strict documentation builds; the native sanitizer harness also supports the CFFI dependency installed by the Nitro extra.

## [0.2.0] - 2026-04-18

### Added
Expand Down
Loading
Loading