From 599e9e8efe1bf014b9e04e4de72e5bf378db8356 Mon Sep 17 00:00:00 2001 From: Trent Nelson Date: Sat, 3 Oct 2026 23:58:04 -0700 Subject: [PATCH] Avoid copying packed scientific evidence before encoding Pass the canonical host buffer directly to SHA-256 and Base64. Retain the exact receipt format while avoiding a full-size byte copy. Signed-off-by: Trent Nelson --- src/cuphoton/xscan/device_pipeline.py | 8 +-- tests/xscan/test_device_pipeline.py | 77 +++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 4 deletions(-) diff --git a/src/cuphoton/xscan/device_pipeline.py b/src/cuphoton/xscan/device_pipeline.py index f2b7b829..0187ce43 100644 --- a/src/cuphoton/xscan/device_pipeline.py +++ b/src/cuphoton/xscan/device_pipeline.py @@ -2361,16 +2361,16 @@ def _scientific_evidence_receipt( if int(host_values.size) != expected_count: raise RuntimeError("terminal scientific evidence size changed") canonical = np.ascontiguousarray(host_values, dtype=np.dtype(" None: assert result.returncode == 0 +@pytest.mark.parametrize("strided", [False, True]) +def test_scientific_evidence_receipt_preserves_packed_bytes( + strided: bool, +) -> None: + import cuphoton.xscan.device_pipeline as pipeline + + expected = _scientific_evidence_payload() + raw = bytearray(base64.b64decode(expected["packed_base64"])) + # Encoding must retain signed zeros, infinities and distinct NaN payloads. + bits = ( + 0x0000000000000000, + 0x8000000000000000, + 0x7FF0000000000000, + 0xFFF0000000000000, + 0x7FF8000000000001, + 0xFFF8000000000002, + ) + raw[: 8 * len(bits)] = b"".join( + value.to_bytes(8, "little") for value in bits + ) + expected_bytes = bytes(raw) + values = np.frombuffer(expected_bytes, dtype=" None: payload = _scientific_evidence_payload()