Email me

Rust advisories / secp256k1

Unsound MediumRUSTSEC-2022-0070 · secp256k1

RUSTSEC-2022-0070: Unsound API in `secp256k1` allows use-after-free and invalid deallocation from safe code

Short answersecp256k1 has an API that can cause undefined behaviour from safe code: Unsound API in `secp256k1` allows use-after-free and invalid deallocation from safe code. Fixed in 0.22.2, 0.23.5, 0.24.2.

Cratesecp256k1
TypeUnsound (memory-corruption)
Affected versionsFrom 0.14.0 before 0.22.2; from 0.23.0 before 0.23.5; from 0.24.0 before 0.24.2.
Fixed in0.22.2, 0.23.5, 0.24.2
SeverityMedium (GitHub rating)
Published2022-11-30
Last changed2023-11-08
Also known asGHSA-969w-q74q-9j8v
Affected functionssecp256k1::Secp256k1::preallocated_gen_new

What to do

  1. See which version you have: cargo tree -i secp256k1 (it also shows which of your dependencies pulls it in).
  2. Update within your version requirement: cargo update -p secp256k1. If the fix is a newer major or minor than your requirement allows, raise it in Cargo.toml (for example secp256k1 = "0.24.2") or update the dependency that pulls it in.
  3. Check again with cargo audit, or paste your Cargo.lock into our Cargo.toml checker.

Details from the advisory

Because of incorrect bounds on method Secp256k1::preallocated_gen_new it was possible to cause use-after-free from safe consumer code. It was also possible to "free" memory not allocated by the appropriate allocator.

The method takes a place for storing the context as a mutable reference and returns context containing that reference. Because the code internally uses unsafe and the bounds were incorrect it was possible to create a context that outlived the passed reference (e.g. 'static). Because the context can alternatively carry heap-allocated pointer freed on drop it was possible to "deallocate" a pointer that wasn't returned from appropriate allocator. The code decides whether to free the memory based on type parameter but because of missing bound it was possible to construct the context with invalid parameter.

You are unaffected if you either

  • don't call Secp256k1::preallocated_gen_new
  • manually checked that your usage of the method is sound
  • upgraded to the patched version of secp256k1 (recommended)

The patched version uses correct bounds which means it is API-breaking. This effectively means adopting the policy of Rust lang itself allowing API-breaking changes to fix soundness bugs. Note however that valid straightforward usage of the code will continue to compile. Only unsound code or code that propagates the bound in custom generics will fail to compile. If the code is sound fixing the bounds should be sufficient to make the code compile.

See the GitHub issue for example "exploit" code and further discussion.

References

From the RustSec Advisory Database (CC0-1.0) via the OSV export, downloaded Oct 24, 2026. Severity score computed from the published CVSS vector.

Up next

Same cratesecp256k1: security historyEvery advisory for this crate, and whether it is safe to use today.Read it next →

Did this answer your question?

Get the receipts by email.

What my AI agents tried this week, with the real numbers: what worked, what flopped, what made money. One email when there is something worth reading.

No spam, never sold. Every email has a one-click unsubscribe.

Popular in the shop

All 124 tools →

Browse: Bundles and kitsHome, family and schoolMoney and businessAI toolsSports and fitnessMaking and hobbiesFood and drinkIndie dev and launchTrading and quant

Free: Landing page teardown iPhone app cost calculator LLM API cost calculator Paid online: $49 Launch Check App builds Articles FAQ