3 suggestions
Optional improvements
[suggestion] · ECDSA cache-key separation still relies on a fatal precondition
An explicit ECDSA public-key length would let a future malformed direct call fail verification instead of depending on an always-fatal validity assertion.
Location: src/script/sigcache.cpp:58 (head).
Details and suggested fix
For the same sighash and cache, an invalid CPubKey contributes zero public-key bytes. Without the assertion, a signature containing valid_pubkey || valid_signature would therefore reproduce the preimage of that valid tuple. The new Assert(pubkey.IsValid()) prevents this by aborting, including in production builds. No current caller producing this input was found: the script checker rejects invalid encodings before invoking the hook. Prefer prefixing the ECDSA public-key bytes with a single length byte derived from pubkey.size() and removing the fatal ECDSA assertion. This separates malformed tuples from valid entries and lets CPubKey::Verify return false on a miss. Entries are freshly salted and memory-only, so changing this layout has no persisted compatibility consumer, although it adds a byte to the preimage and departs from the byte-preserving refactor. This alternative applies only to ECDSA: Schnorr keys already have a fixed width, and the underlying Schnorr verifier's existing 64-byte assertion would remain.
[suggestion] · The new fuzz comparisons never query a populated cache
Each fuzz input gets a fresh cache and at most one verification call, so the new equality assertions do not check whether stored results are reused correctly.
Location: src/test/fuzz/script_sigcache.cpp:54 (head).
Details and suggested fix
The cache is local to FUZZ_TARGET, and each branch calls its caching verifier only once. Get precedes Set, so even a valid signature with store=true is inserted only after the lookup and is never queried before the cache is destroyed. On a miss, the caching checker invokes the same CPubKey::Verify or XOnlyPubKey::VerifySchnorr used by the assertion's other operand. This checks miss-result propagation but would not detect an incomplete cache key returning a stored result for different inputs. Seed the cache by deriving a valid key from fuzz input, signing a fuzz-chosen sighash, and verifying with store=true. Then query the original tuple and fuzz-selected mutations of its sighash, public key, or signature against the uncached verifier. The second DoTest pass and BIP341 unit checks already exercise populated caches; this suggestion concerns what the new fuzz oracle covers.
[suggestion] · Direct-call documentation omits the asserted input requirements
The override points direct callers to base-hook comments that omit the valid-encoding and 64-byte signature requirements enforced by the new assertions.
Location: src/script/sigcache.h:77 (head).
Details and suggested fix
The referenced base-hook comments describe a cache goal and an obligation for overriders, but neither states the concrete conditions a direct caller must satisfy. Document that the ECDSA hook requires vchPubKey.IsValid() and a signature with its sighash-type byte removed, which may leave an empty signature. Clarify that this key check is syntactic: it accepts hybrid 0x06/0x07 encodings and does not check curve validity. Document that the Schnorr hook requires exactly 64 signature bytes after removing any optional 65th sighash-type byte. State the same size explicitly on ComputeEntrySchnorr, whose comment currently only says to omit the sighash byte, and keep the cache-specific rationale in sigcache.h. Current callers already satisfy these requirements; spelling them out makes the new fatal preconditions usable without tracing the interpreter implementation.