Skip to content

[master] sigcache: harden range proof cache keys and add -norangeproofcache option - #1604

Open
delta1 wants to merge 3 commits into
ElementsProject:masterfrom
delta1:fix/master-sigcache
Open

[master] sigcache: harden range proof cache keys and add -norangeproofcache option#1604
delta1 wants to merge 3 commits into
ElementsProject:masterfrom
delta1:fix/master-sigcache

Conversation

@delta1

@delta1 delta1 commented Sep 14, 2026

Copy link
Copy Markdown
Member

target is master branch, cherry-picked commits from #1600

Switch the range-proof and surjection-proof cache hashers from raw
CSHA256 concatenation to CHashWriter . This length-prefixes
every field, so distinct argument tuples with byte-identical raw
concatenations no longer collide to the same cache key.

Both caches retain per-process salted midstates with distinct domain
separators ('r' / 's').

Also adds a -norangeproofcache startup option to
disable the range proof cache without recompiling.

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 9400096)
Test the field-boundary, script-sensitivity, domain-separation,
determinism, and vTags-sensitivity properties of the range-proof and
surjection-proof cache entry computation.

(cherry picked from commit 1513d63)
Add -norangeproofcache startup option. InitRangeproofCache()
early-returns (allocating nothing) when the flag is set. VerifyRangeProof
reads the flag on each call and bypasses both the Get and Set paths,
so cache behaviour is fully skipped without restarting.

(cherry picked from commit 19d7042)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant