1 minor finding · 5 suggestions
Earlier concerns neither republished nor resolved: 3 suggestions. See the Run archive for their assessments.
Findings
[minor] · ECC construction repeatedly resets global SHA256 dispatch
ECC construction resets global SHA256 dispatch twice and would race with concurrent hashing, although no current caller producing that overlap was found.
Location: src/ecc_context.cpp:32 (head).
Details and suggested fix
ECC_Start() calls SHA256AutoDetect() for both the signing and verification contexts. Autodetection resets the global dispatch pointers, including temporarily clearing the multiway pointers, before selecting implementations and running SelfTest(). Hashing reads those pointers without synchronization; concurrent SHA256D64() can have a pointer cleared between its check and call. Construction also replaces any implementation selected earlier. Move default autodetection to coordinated one-time process initialization before hashing workers start, retaining initialization for standalone bench, unit and fuzz entry points. Have ECC_Start() only install SHA256Transform, which already has a portable fallback.
Optional improvements
[suggestion] · DER-lax fuzzing repeats unused ECC initialization per input
Every successfully parsed fuzz input now builds two contexts that neither fuzzed operation uses, repeating SHA autodetection and callback validation.
Location: src/test/fuzz/secp256k1_ecdsa_signature_parse_der_lax.cpp:29 (head).
Details and suggested fix
The parser runs before this target creates its ECC owner, so it uses the static-context fallback. The only subsequent operation, SigHasLowR(), explicitly serializes with secp256k1_context_static. This branch already created one unused context before the PR; it now creates two, each rerunning autodetection and an external-callback smoke test over 14 message lengths at 64 offsets. Remove the per-input MakeContextECC() and its include without changing the parser or low-R coverage. If managed-context routing is intended, create a static owner in a .init callback instead. The throughput effect has not been measured.
[suggestion] · The separate verification context saves no blinding work
Verification does not use the signing context's randomized generator state, so a second context adds setup work without avoiding blinded computation.
Location: src/ecc_context.cpp:48 (head).
Details and suggested fix
The rationale in commit 256376b does not match the verification implementations: Schnorr verification uses hash_ctx and secp256k1_ecmult, ECDSA verification delegates to secp256k1_ecdsa_sig_verify, and the routed parsing, serialization and public-tweak calls do not use ecmult_gen_ctx. The second ECC_Start() nevertheless repeats context creation, autodetection and callback validation on every construction. Share a const view of the signing context for public operations. A split could support future signing-context re-randomization without locking verification, but no production code re-randomizes today. If retaining the split for that reason, document it and clone the configured context before randomizing the signing context; cloning copies hash_ctx without repeating callback validation.
[suggestion] · Verification's new ECC lifetime requirement is undocumented
Public-key verification now depends on ECC lifetime ordering that the header does not document, although no current violating caller was found.
Location: src/ecc_context.cpp:22 (head).
Details and suggested fix
Verification previously used secp256k1_context_static; it now reads the unsynchronized g_ecc_context and can use m_verify_ctx, which ~ECC_Context() frees. Creating or destroying the singleton concurrently with verification would race on the global, and destruction could invalidate a context already returned to a verifier. The static fallback does not synchronize those transitions. Node and fixture teardown currently destroy chainman and join script-check workers before destroying ECC. Document in ecc_context.h that construction and destruction must not overlap signing or verification operations, normally by creating the owner before workers start and destroying it after they join.
[suggestion] · Signing-context routing lacks regression coverage
The new tests would still pass if signing used the unrandomized verification context, because valid signatures do not identify which context signed them.
Location: src/test/ecc_context_tests.cpp:53 (head).
Details and suggested fix
verify_context_sha256 signs before installing its counter and measures only subsequent verification; context_lifecycle checks getter identity and successful signing. Both allocated contexts have built generator state, so the verification context can sign successfully without the signing context's randomized blinding. The current signing calls are correctly routed. Add separate counter assertions for CKey::Sign and KeyPair::SignSchnorr by installing CountingSHA256Transform on SignContext(), then resetting after callback installation and key setup and requiring a positive count for each operation. Use a non-grinding ECDSA case so a correctly routed retry cannot mask a misrouted first attempt. RFC6979 and BIP340 nonce generation both hash through the supplied context.
[suggestion] · The new signing benchmark includes unused span.h
The benchmark directly includes span.h but uses none of its utility declarations.
Location: src/bench/ecc_sign_verify.cpp:10 (head).
Details and suggested fix
The file does not use UCharCast, MakeByteSpan, SpanPopBack or another utility from span.h. The UCharCast inside CKey::Set is resolved where that template is defined in key.h, not by this later include. Remove #include <span.h>.
Earlier concerns
Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.
- [suggestion]: Clarify whether kernel verification should use the optimized context
- [suggestion]: Require a 32-byte seed for the signing context (earlier report)
- [suggestion]: Callback-routing test misses factory registration (earlier report)