Review report

core: PR #36188

1 minor finding · 4 suggestions

Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive for their assessments.

Findings

Link

[minor] · ECC setup rewrites process-wide SHA256 dispatch

Every ECC_Context construction reselects unsynchronized global SHA256 pointers twice, creating a latent data race if hashing overlaps construction.

Location: src/ecc_context.cpp:32 (head).

Details and suggested fix

ECC_Start() calls SHA256AutoDetect() for both contexts. Detection resets Transform and TransformD64 and nulls the multiway pointers, while CSHA256::Write, SHA256D64 and SHA256Transform read them without synchronization. Overlapping hashing therefore races with construction; SHA256D64 can also pass its non-null check before detection clears the pointer. The old ECC setup did not touch SHA dispatch, and these new calls bypass kernel::Context's once-guard. No current caller was identified that constructs an ECC context while another thread hashes, so production impact is unconfirmed. Centralize default detection behind a shared once-flag used by initialization callers, including kernel::Context and MakeContextECC(), and complete it before concurrent hashing begins. Let ECC_Start() only install SHA256Transform, while retaining acceleration for standalone callers without a kernel context.


Optional improvements

Link

[suggestion] · DER-lax fuzzing repeats unused ECC initialization

Each successfully parsed fuzz input now creates two unused contexts and repeats SHA256 detection and external-callback self-tests, spending fuzzing time on fixed setup.

Location: src/test/fuzz/secp256k1_ecdsa_signature_parse_der_lax.cpp:29 (head).

Details and suggested fix

The parser runs before the local ECC owner exists, so it takes the secp256k1_context_static fallback. The only later operation, SigHasLowR(), also uses the static context directly. Before this PR the branch built one randomized context; it now builds two, each rerunning SHA256AutoDetect() and libsecp256k1's external-compression smoke test over 14 message lengths at 64 offsets. None of that setup serves either fuzzed operation. Remove the per-input MakeContextECC() owner and the common/ecc_init.h include. The parser and low-R operations will still run unchanged.


Link

[suggestion] · Signing-context construction accepts an empty blinding seed

The public constructor accepts an empty seed even though it creates signing state, leaving the randomization requirement unenforced at the owner boundary.

Location: src/ecc_context.cpp:47 (head).

Details and suggested fix

ECC_Start() permits an empty span and then skips secp256k1_context_randomize(), which is intentional for verification setup. The constructor also forwards the caller's span unchanged to signing setup, so constructing an owner with an empty seed would publish signing state without fresh randomized blinding and without failing the size assertion. The only current caller found, MakeContextECC(), always supplies 32 random bytes, so this is hardening rather than a current initialization failure. Add assert(rng_seed32.size() == 32) in the constructor to preserve the old signing-context randomization requirement while keeping the empty-seed path private to verification setup.


Link

[suggestion] · Separate verification context adds setup without avoiding blinding

The routed verification operations never use the blinded generator state, so sharing the initialized signing context would preserve accelerated hashing without a second context's setup.

Location: src/ecc_context.cpp:48 (head).

Details and suggested fix

The blinding rationale in commit 4bd3fcef does not apply to these calls: ECDSA verification uses secp256k1_ecdsa_sig_verify, and Schnorr verification uses ctx->hash_ctx plus secp256k1_ecmult, not ecmult_gen_ctx. Parsing, serialization and public tweaks do not use the blinded generator state either. Randomization already happens before publishing the owner, and libsecp256k1 permits concurrent const-context calls. Prefer sharing the signing context as const for verification, with a single owner and destruction, to avoid the second allocation, autodetection and callback self-test. If the split is intended to permit future signing-context re-randomization, document that rationale in ecc_context.h instead: re-randomization requires exclusive access, but no current code does it after construction.


Link

[suggestion] · Callback-routing test misses factory registration

verify_context_sha256 replaces the callback before observing it, so omitting the factory's SHA256Transform registration would not fail the new tests.

Location: src/test/ecc_context_tests.cpp:55 (head).

Details and suggested fix

This test proves that VerifySchnorr() uses the managed verification context, not that ECC_Start() installed Core's compression function. Without the production setter call, both contexts would retain libsecp256k1's built-in compression and produce identical signatures and verification results. The lifecycle assertions would also remain satisfied, leaving loss of the PR's acceleration undetected. To cover registration, allow a counting compression wrapper to pass through the construction path, reset its counter after setup, and observe subsequent operations without reinstalling the callback. That requires a construction-time test seam, so weigh its interface cost against relying on the benchmarks.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.