From b0a275281ee5bfd789b832027fe6d5532273eb74 Mon Sep 17 00:00:00 2001 From: Byron Hambly Date: Tue, 8 Sep 2026 19:00:00 +0200 Subject: [PATCH 1/3] sigcache: harden proof cache keys with length-prefixed hashing Switch range-proof and surjection-proof cache hashers from raw CSHA256 concatenation to CHashWriter (SER_GETHASH). This serializes each field with a length prefix, so distinct argument tuples with byte-identical raw concatenations no longer collide to the same cache key. A cache entry is a positive verification result; a collision would let an attacker bypass verification. The fix affects two caches: - ComputeEntryRangeProof: proof, commitment, asset_commitment, scriptPubKey - ComputeEntrySurjectionProof: add vTags to key (was missing entirely) Both caches retain the per-process 64-byte salted midstate (nonce || PADDING_RANGE_PROOF / PADDING_SURJECTION_PROOF) for domain separation between the two proof types. Expose thin test-only hooks (TestComputeEntryRangeProof / TestComputeEntrySurjectionProof) so unit tests can reach the anonymous-namespace cache internals. (cherry picked from commit 94000967f6dc05b1afd435e79b1bbc597e29f816) --- src/script/sigcache.cpp | 79 +++++++++++++++++++++++++++++++++-------- src/script/sigcache.h | 41 ++++++++++++++------- 2 files changed, 92 insertions(+), 28 deletions(-) diff --git a/src/script/sigcache.cpp b/src/script/sigcache.cpp index 30a34f4b23..66aa6d969a 100644 --- a/src/script/sigcache.cpp +++ b/src/script/sigcache.cpp @@ -6,6 +6,7 @@ #include