Skip to content

Commit 426cf48

Browse files
committed
Do not set secp256k1 error callback
Error callback in secp256k1 should not ever return. The default one prints a message to stderr and does abort() This is a really exceptional situation with no safe recovery, so there's no sense in handling it in python. Better just use the default handler.
1 parent 302f4f3 commit 426cf48

File tree

1 file changed

+0
-9
lines changed

1 file changed

+0
-9
lines changed

bitcointx/core/secp256k1.py

-9
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ class Secp256k1LastErrorContextVar(bitcointx.util.ContextVarsCompat):
6666
_ctypes_functype = getattr(ctypes, 'WINFUNCTYPE', getattr(ctypes, 'CFUNCTYPE'))
6767

6868

69-
@_ctypes_functype(ctypes.c_void_p, ctypes.c_char_p, ctypes.c_void_p)
70-
def _secp256k1_error_callback_fn(error_str, _data): # type: ignore
71-
_secp256k1_error_storage.last_error = {'code': -1, 'type': 'internal_error', 'message': str(error_str)}
72-
73-
7469
@_ctypes_functype(ctypes.c_void_p, ctypes.c_char_p, ctypes.c_void_p)
7570
def _secp256k1_illegal_callback_fn(error_str, _data): # type: ignore
7671
_secp256k1_error_storage.last_error = {'code': -2, 'type': 'illegal_argument', 'message': str(error_str)}
@@ -129,9 +124,6 @@ def _add_function_definitions(_secp256k1: ctypes.CDLL) -> None:
129124
_secp256k1.secp256k1_context_set_illegal_callback.restype = None
130125
_secp256k1.secp256k1_context_set_illegal_callback.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
131126

132-
_secp256k1.secp256k1_context_set_error_callback.restype = None
133-
_secp256k1.secp256k1_context_set_error_callback.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
134-
135127
_secp256k1.secp256k1_ecdsa_sign.restype = ctypes.c_int
136128
_secp256k1.secp256k1_ecdsa_sign.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_void_p, ctypes.c_void_p]
137129

@@ -198,7 +190,6 @@ def secp256k1_create_and_init_context(_secp256k1: ctypes.CDLL, flags: int
198190
if ctx is None:
199191
raise RuntimeError('secp256k1_context_create() returned None')
200192

201-
_secp256k1.secp256k1_context_set_error_callback(ctx, _secp256k1_error_callback_fn, 0)
202193
_secp256k1.secp256k1_context_set_illegal_callback(ctx, _secp256k1_illegal_callback_fn, 0)
203194

204195
seed = os.urandom(32)

0 commit comments

Comments
 (0)