The dynamically created signing context for libsecp256k1 calls is only needed for functions that involve generator point multiplication with a secret key, i.e. different variants of public key creation and signing. The API docs hint to those by stating “(not secp256k1_context_static)” for the context parameter. In our case that applies to the following calls:
secp256k1_ec_pubkey_create
secp256k1_keypair_create
secp256k1_ellswift_create
secp256k1_ecdsa_sign
secp256k1_ecdsa_sign_recoverable
secp256k1_schnorrsig_sign32
ec_seckey_export_der
(not a direct secp256k1 function, but callssecp256k1_ec_pubkey_create
inside)
For all the other secp256k1 calls we can simply use the static context. This is done for consistency to other calls that already use secp256k1_context_static
, and also to reduce dependencies on the global signing context variable. Looked closer at this in the course of reviewing #29675, where some functions used the signing context that didn’t need to, avoiding a move to another module (see #29675 (review)).