From 5ae772fdd8cb03314ca527cfa2fbe3933e74ca65 Mon Sep 17 00:00:00 2001 From: ecgang Date: Sat, 25 Jul 2026 15:47:19 -0700 Subject: [PATCH] Courier vectors: pin the pre-image in the signature test too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The signature test signed whatever pre-image it was handed and verified it, which is self-consistent by construction — it would have passed over a wrong canonicalization. Mutating an input (timestamp +1ms) proved it: the comparison test failed and this one did not. It now pins the pre-image before signing, so both tests fail on any change to field layout, timestamp encoding or payload length. Co-Authored-By: Claude Opus 5 (1M context) --- .../Tests/BitFoundationTests/CourierVectorTests.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/localPackages/BitFoundation/Tests/BitFoundationTests/CourierVectorTests.swift b/localPackages/BitFoundation/Tests/BitFoundationTests/CourierVectorTests.swift index 113ea1ee..63991f69 100644 --- a/localPackages/BitFoundation/Tests/BitFoundationTests/CourierVectorTests.swift +++ b/localPackages/BitFoundation/Tests/BitFoundationTests/CourierVectorTests.swift @@ -157,6 +157,13 @@ struct CourierVectorTests { let packet = try Self.envelopePacket() let preimage = try #require(packet.toBinaryDataForSigning()) + // Pin what is being signed. Without this the test is self-consistent by + // construction — it would sign whatever it was handed, verify it, and + // pass over a wrong canonicalization. Proven by mutating an input and + // watching this line, not the verification below, be the one that fails. + #expect(preimage.hexEncodedString() + == Self.preimageBodyHex + String(repeating: "98", count: 152)) + let key = try Curve25519.Signing.PrivateKey(rawRepresentation: Self.signingSeed) #expect(key.publicKey.rawRepresentation.hexEncodedString() == "2152f8d19b791d24453242e15f2eab6cb7cffa7b6a5ed30097960e069881db12")