Review report

core: PR #36188

1 minor finding · 1 suggestion

Earlier concerns neither republished nor resolved: 3 suggestions. See the Run archive for their assessments.

Findings

Link

[minor] · ECC context creation races with SHA256 dispatch updates

Each ECC context build resets and reselects the global SHA256 dispatch pointers twice, creating a data race if another thread hashes at the same time; no current caller that does this was identified.

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

Details and suggested fix

ECC_Start() calls SHA256AutoDetect(), and the ECC_Context constructor calls ECC_Start() twice, once for signing and once for verification. SHA256AutoDetect() resets the global dispatch pointers, reselects implementations, and runs a self-test. Meanwhile, CSHA256::Write, SHA256D64, and the new SHA256Transform callback read those pointers without synchronization. Building an ECC context while another thread hashes is therefore a data race. Before this change, ECC context creation did not update SHA256 dispatch; kernel::Context instead runs detection once under std::call_once. Current callers create ECC contexts during startup or single-threaded tool or test setup, so no production occurrence was identified and production impact is unconfirmed. Detection is still needed for fuzz targets and unit tests that build a context without a kernel::Context. Move detection into a once-per-process helper shared by kernel::Context and ECC_Context, and have ECC_Start() only install SHA256Transform.


Optional improvements

Link

[suggestion] · DER-lax fuzz target creates an unused ECC context for each parsed input

Neither fuzzed operation uses the context, and its setup became more expensive, reducing fuzzing throughput.

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

Details and suggested fix

The context is created only after ecdsa_signature_parse_der_lax() runs, so parsing uses the secp256k1_context_static fallback. The only later call, SigHasLowR(), serializes with secp256k1_context_static as well. The per-input context therefore has no effect on the operations fuzzed here. Before this change, the target built one randomized context per parsed input. MakeContextECC() now builds signing and verification contexts, and each ECC_Start() reruns SHA256AutoDetect() with its self-test; installing the compression callback also runs libsecp's self-test. Remove the per-input MakeContextECC() call and the now-unused common/ecc_init.h include. Parsing and low-R checks are unaffected.


Coverage details

Earlier concerns

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