Skip to content

Commit d0c8275

Browse files
luisleo526claude
andcommitted
outputs: message_hash64 uses the standard FNV-1a 64 offset basis
output_message_hash() seeded FNV-1a 64 with 1469598103934665603, the standard offset basis 14695981039346656037 with its last digit dropped, while pineforge.h and docs/outputs.md promise FNV-1a 64 and tell users to re-hash the bytes they recorded. message_hash64 is new in 1.5.0, so the standard basis costs nothing before the release. The test helper fnv1a64() repeated the same truncated seed, so the recorder test compared the bug with itself and could never catch it. The recorder test now also pins the published FNV-1a 64 test vectors ("" -> 0xcbf29ce484222325, "a" -> 0xaf63dc4c8601ec8c), and docs/outputs.md states the basis, the prime and the "a" vector. The internal state-hash folds that share the old constant are not public hashes and stay as they are. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 3c126b4 commit d0c8275

4 files changed

Lines changed: 10 additions & 4 deletions

File tree

‎docs/outputs.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ constant means is not the engine's business; the module's manifest
4242
message (0 without a message). A C reader receives the message as
4343
NUL-terminated text, so a message holding a NUL byte reads to its first NUL
4444
while its hash covers all of it: re-hash the bytes you recorded, not the
45-
text you read back.
45+
text you read back. The hash is standard FNV-1a 64 (offset basis
46+
`0xcbf29ce484222325`, prime `0x100000001b3`): the message `a` hashes to
47+
`0xaf63dc4c8601ec8c`.
4648
- **Run constants.** One double per index per run, for a value fixed for the
4749
whole run, such as a level read from an input. NaN until written; the
4850
run's first write stores it and a later write must be equal (bit for bit,

‎src/engine_report.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,9 @@ void note_switch_refusal(BacktestEngine& engine, const char* text, const char* r
348348
note_run_failure(engine, text, RunFailureCode::outputs_rejected, {{"reason", reason}});
349349
}
350350

351-
// FNV-1a 64 of the bytes, as stream_state_hash folds them.
351+
// FNV-1a 64 of the bytes, with the standard offset basis and prime.
352352
uint64_t output_message_hash(const std::string& text) {
353-
uint64_t hash = 1469598103934665603ULL;
353+
uint64_t hash = 14695981039346656037ULL;
354354
for (const unsigned char c : text) {
355355
hash ^= c;
356356
hash *= 1099511628211ULL;

‎tests/outputs_test_support.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ inline bool same_events(const std::vector<EventRecord>& a, const std::vector<Eve
280280

281281
// FNV-1a 64 of a message's bytes, the recorder's message_hash64.
282282
inline std::uint64_t fnv1a64(const std::string& text) {
283-
std::uint64_t hash = 1469598103934665603ULL;
283+
std::uint64_t hash = 14695981039346656037ULL;
284284
for (unsigned char c : text) {
285285
hash ^= c;
286286
hash *= 1099511628211ULL;

‎tests/test_outputs_recorder.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ void hand_values() {
210210
CHECK(messages[0].message == "first" && messages[0].ordinal_in_bar == 0);
211211
CHECK(messages[1].message == "second" && messages[1].ordinal_in_bar == 1);
212212
CHECK(messages[1].message_hash64 == fnv1a64(std::string("second\0bytes", 12)));
213+
// The published FNV-1a 64 test vectors, so the helper cannot drift
214+
// together with the recorder.
215+
CHECK(fnv1a64("") == 0xcbf29ce484222325ULL);
216+
CHECK(fnv1a64("a") == 0xaf63dc4c8601ec8cULL);
213217
CHECK(messages[1].sequence == messages[0].sequence + 1);
214218
}
215219
CHECK(r.constants.size() == 2);

0 commit comments

Comments
 (0)