Passing a NULL context to secp256k1_ecdsa_verify results in a segmentation fault (see attached code). I have the feeling this behavior is unintended as the secp256k1 library appears to be systematic in testing for NULL pointers. However, I am not sure because 1. you need a context to call the call back function (so can't do it here), and 2. the library does silently accept NULL context when it does not matter (so maybe it has a deliberate policy of not testing for NULL context).

#include "secp256k1.h"
#include <assert.h>

int main(){

  // valid key
  const unsigned char *pubkey_bytes = "\x03"

  // valid signature
  const unsigned char *sig_bytes = 

  const unsigned char *hash_bytes = 

  int value;
  secp256k1_context *ctx;
  secp256k1_pubkey pub;
  secp256k1_ecdsa_signature sig;

  ctx = secp256k1_context_create

  // parsing public key
  value = secp256k1_ec_pubkey_parse(ctx, &pub, pubkey_bytes, 33);
  assert(value == 1);

  // parsing signature
  value = secp256k1_ecdsa_signature_parse_compact(ctx, &sig, sig_bytes);
  assert(value == 1);

  // verifying signature 
  value = secp256k1_ecdsa_verify(ctx, &sig, hash_bytes, &pub);
  assert(value == 1);

  // passing NULL context (SEGMENTATION FAULT)
  value = secp256k1_ecdsa_verify(NULL, &sig, hash_bytes, &pub);


  return 0;

  • I'm not sure what you're expecting to learn by posting here? Is it intended behavior? - only the developers can answer that. Is it desirable behavior? - matter of opinion. – Nate Eldredge May 3 '17 at 14:39
  • @NateEldredge yes is this intended? I think some people on this forum would know. I am reluctant to file an issue on the github repository if it isn't deemed an issue. – Sven Williamson May 3 '17 at 15:24
  • Sounds like a bug to me. – Pieter Wuille May 3 '17 at 15:35
  • @PieterWuille Thank you I'll report it then. – Sven Williamson May 3 '17 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.