Update secp256k1 subtree to latest master

bitcoin/bitcoin: PR #36890

3 suggestions

Optional improvements

Link

[suggestion] · The label_lookup contract omits the enforced tweak bound

An overflowing caller-supplied label tweak now invokes the default-aborting illegal callback without a documented range precondition; successful library-generated cache entries cannot trigger this.

Location: src/secp256k1/src/modules/silentpayments/main_impl.h:771 (head).

Details and suggested fix

secp256k1_silentpayments_recipient_scan_outputs now executes ARG_CHECK(!tweak_overflow) for a matching callback result instead of the previous zero-tweak fallback. The callback and scanning documentation specify only 32 bytes and pointer lifetime, while secp256k1.h promises that illegal-callback violations are explicit in the header. Document upstream that the returned tweak must encode a big-endian scalar strictly below the group order and that overflow invokes the illegal callback. Successful secp256k1_silentpayments_recipient_label_create output already satisfies this, including Core's CreateLabel path. Keep the rejection unchanged and avoid imposing a secret-key nonzero requirement: a zero combined tweak remains valid.


Link

[suggestion] · Full-check receive vectors still accept duplicate output records

The new uniqueness check skips full_check=1 vectors, leaving a pre-existing test gap where two copies of one expected output can pass while another expected output is missing.

Location: src/secp256k1/src/modules/silentpayments/tests_impl.h:989 (head).

Details and suggested fix

Each found_outputs[i] searches the expected entries from the beginning and can reuse the same matched index j. For the checked-in two-output, unlabeled, full-check vector, returning A's complete record twice would satisfy both matches, the tweak and signature checks, and the final count of two while omitting B. Move the pairwise secp256k1_xonly_pubkey_cmp loop outside the if (subtest->full_check) block upstream so both branches require distinct outputs, preserving the existing tweak, signature, and label assertions.


Link

[suggestion] · musig_ctx_sha256 fails when target selections repeat it

By source inspection, ./tests -t=musig -t=musig_ctx_sha256 would fail its second MuSig probe baseline; this invocation was not executed, and default single-pass runs are unaffected.

Location: src/secp256k1/src/modules/musig/tests_impl.h:656 (head).

Details and suggested fix

The target parser appends matching entries without deduplication, and the sequential runner calls both in the same process. DEFINE_SHA256_TRANSFORM_PROBE initializes each flag only once. The first musig_ctx_sha256 run sets all six during its overrides, but neither test entry nor exit clears them. Destroying the cloned context cannot reset file-static state. Reset the six flags at test entry upstream, preserving the baseline and override checks. Existing probe tests such as test_ecdh_ctx_sha256 already have this limitation, but the new test adds it to MuSig.


Coverage details

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

The volatile-mask pattern is intended to stop compilers from transforming secret-dependent arithmetic selection into branching, variable-time machine code.

In the pinned modular-inversion normalization routines, sign-derived masks conditionally add the modulus and negate limbs. Upstream #1998 explicitly preserves the volatile access for its anti-branching purpose while separating that access from subsequent arithmetic. This is a compiler-resistance measure, not merely a spelling change to suppress warnings.

Source 1

The non-volatile copy addresses a separate language-semantics constraint: repeated unsequenced volatile reads were unspecified in C89 and, according to the upstream explanation, undefined behavior under C11's side-effect rule.

The base evaluates the volatile cond_negate twice in expressions such as '(r0 ^ cond_negate) - cond_negate'. The head performs one volatile read into an ordinary local before those expressions. Upstream #1998 states that this separation retains the anti-branching purpose while avoiding unsequenced volatile accesses; Clang 24's warning prompted the change.

Source 1 · Source 2

A Jacobian result of secret-scalar multiplication can contain sensitive information beyond the final affine point, so conversion to affine coordinates does not eliminate the cleanup obligation. The affine helper centralizes multiplication, conversion, and clearing because forgetting the last step is easy and would not be detected by ordinary functional tests.

The head's ecmult_const_ge helper clears its local rj and replaces the previously open-coded sequences in ECDH and Silent Payments. The x-only path needs separate cleanup because it does not call the affine conversion helper: the head clears both rj and the secret-derived field intermediate i. Historical #1579 specifically identified Jacobian results from secret multiplications, including ECDH results and public-point/nonce computations, as cleanup targets. #1934 extends that reasoning to the previously overlooked x-only path.

Source 1 · Source 2 · Source 3

Hybrid-key parsing is a legacy public-API compatibility requirement, not a default encoding policy for new protocols. Explicit parser variants make accidental acceptance less likely.

The head preserves hybrid acceptance in secp256k1_ec_pubkey_parse through ge_parse_with_hybrid65, while separating compressed-only and ordinary uncompressed parsing. The historical proposal identifies the public parser as the likely sole API needing hybrid support and explains that the explicit split makes the unusual legacy behavior stand out. MuSig public nonces and Silent Payments labels use the compressed-only parser.

Source 1 · Source 2

An additive tweak is not a secret key: zero is a valid additive scalar, including when an output tweak and a label tweak cancel. A zero combined tweak does not make the resulting payment unspendable.

The base already preserves this case by replacing a failed secret-key tweak operation with a zero tweak, explicitly noting that the output remains spendable with the spend secret key alone. The head expresses the operation directly as scalar addition. Upstream #1929 motivates this as removing a type mismatch and the unnecessary secret-key nonzero invariant. This does not relax the separate BIP352 checks on hash-derived protocol values.

Source 1

An overflowing label-cache tweak is caller misuse because the library's label-creation API never produces such a value; silently reducing it would obscure a broken cache or other caller-side mistake.

The combined head checks scalar decoding for overflow and invokes ARG_CHECK after clearing sensitive temporaries. The historical discussion considered whether an assertion was worthwhile, then selected the illegal-argument contract because the cache is expected to contain library-generated values. This distinguishes malformed caller-maintained state from the valid zero result of adding two tweaks.

Source 1 · Source 2 · Source 3

Transactions with no eligible inputs or no Taproot outputs are ordinary non-Silent-Payments transactions, not illegal API arguments. Scanners and indexers should be able to pass them through without special filtering or risking the default aborting callback.

The head lets the existing infinity-sum check reject an empty eligible-input set and explicitly returns 0 for an empty output set, with n_found_outputs initialized to zero. Zero-length output arrays may be NULL. Upstream #1983 ties these choices to the documented return contract and to the fact that transactions are created by other parties. A maintainer expressly declined to classify the previous behavior as a vulnerability, so this history should not be recast as a present security finding.

Source 1 · Source 2

Ralph's inferences

The relevant optimization barrier is the volatile load, not the volatile qualification of every later arithmetic use. Copying its result into an ordinary local preserves that barrier while allowing repeated, sequenced-safe use of the loaded value.

In both normalization implementations, the head still writes the sign mask to a volatile object and reads it once before evaluating the limb expressions. This matches the existing divsteps convention of loading volatile conditions into ordinary masks. The intended effect is to prevent the optimizer from carrying the known restricted mask range through the volatile access and recognizing a conditional operation. Neither the C timing model nor the inspected record establishes an unconditional constant-time guarantee for every compiler and target.

Source 1

The affine helper is expected to support an identical input and output point, and its cleanup must affect only its private Jacobian temporary.

Pinned ECDH calls ecmult_const_ge with '&pt' as both input and output; the updated multiplication tests also exercise in-place calls. The helper consumes the input into a separate rj before writing the affine output and then clears only rj. For the x-only path, rj and i depend on secret q, whereas g and p are constructed from the base-point inputs rather than q. This explains the particular new cleanup targets without implying that every Jacobian object in the subsystem is secret.

Source 1 · Source 2

The compatibility-sensitive Bitcoin Core consumer is the general public-key path, especially CPubKey::Verify, rather than every caller that happens to invoke the public parser.

Pinned CPubKey::Verify parses the supplied key before ECDSA verification; IsFullyValid and Decompress also use the general parser. These are the paths where retaining legacy hybrid acceptance matters. By contrast, compressed-key protocols and BIP32's compressed-only derivation do not acquire a need for hybrid support merely by sharing that public entry point. The upstream split preserves the legacy boundary without extending it into new internal serialization formats.

Source 1 · Source 2