Project Name: spesmilo+electrum
Language: Python
Statement Type: Branch

Source Code:
def load_library():
    # note: for a mapping between bitcoin-core/secp256k1 git tags and .so.V libtool version numbers,
    #       see https://github.com/bitcoin-core/secp256k1/pull/1055#issuecomment-1227505189
    tested_libversions = [2, 1, 0, ]  # try latest version first
    libnames = []
    if sys.platform == 'darwin':
        for v in tested_libversions:
            libnames.append(f"libsecp256k1.{v}.dylib")
    elif sys.platform in ('windows', 'win32'):
        for v in tested_libversions:
            libnames.append(f"libsecp256k1-{v}.dll")
    elif 'ANDROID_DATA' in os.environ:
        libnames = ['libsecp256k1.so', ]  # don't care about version number. we built w/e is available.
    else:  # desktop Linux and similar
        for v in tested_libversions:
            libnames.append(f"libsecp256k1.so.{v}")
        # maybe we could fall back to trying "any" version? maybe guarded with an env var?
        #libnames.append(f"libsecp256k1.so")
    library_paths = []
    for libname in libnames:  # try local files in repo dir first
        library_paths.append(os.path.join(os.path.dirname(__file__), libname))
    for libname in libnames:
        library_paths.append(libname)

    exceptions = []
    secp256k1 = None
    for libpath in library_paths:
        try:
            secp256k1 = ctypes.cdll.LoadLibrary(libpath)
        except BaseException as e:
            exceptions.append(e)
        else:
            break
    if not secp256k1:
        _logger.error(f'libsecp256k1 library failed to load. exceptions: {repr(exceptions)}')
        return None

    try:
        secp256k1.secp256k1_context_create.argtypes = [c_uint]
        secp256k1.secp256k1_context_create.restype = c_void_p

        secp256k1.secp256k1_context_randomize.argtypes = [c_void_p, c_char_p]
        secp256k1.secp256k1_context_randomize.restype = c_int

        secp256k1.secp256k1_ec_pubkey_create.argtypes = [c_void_p, c_void_p, c_char_p]
        secp256k1.secp256k1_ec_pubkey_create.restype = c_int

        secp256k1.secp256k1_ecdsa_sign.argtypes = [c_void_p, c_char_p, c_char_p, c_char_p, c_void_p, c_void_p]
        secp256k1.secp256k1_ecdsa_sign.restype = c_int

        secp256k1.secp256k1_ecdsa_verify.argtypes = [c_void_p, c_char_p, c_char_p, c_char_p]
        secp256k1.secp256k1_ecdsa_verify.restype = c_int

        secp256k1.secp256k1_ec_pubkey_parse.argtypes = [c_void_p, c_char_p, c_char_p, c_size_t]
        secp256k1.secp256k1_ec_pubkey_parse.restype = c_int

        secp256k1.secp256k1_ec_pubkey_serialize.argtypes = [c_void_p, c_char_p, c_void_p, c_char_p, c_uint]
        secp256k1.secp256k1_ec_pubkey_serialize.restype = c_int

        secp256k1.secp256k1_ecdsa_signature_parse_compact.argtypes = [c_void_p, c_char_p, c_char_p]
        secp256k1.secp256k1_ecdsa_signature_parse_compact.restype = c_int

        secp256k1.secp256k1_ecdsa_signature_normalize.argtypes = [c_void_p, c_char_p, c_char_p]
        secp256k1.secp256k1_ecdsa_signature_normalize.restype = c_int

        secp256k1.secp256k1_ecdsa_signature_serialize_compact.argtypes = [c_void_p, c_char_p, c_char_p]
        secp256k1.secp256k1_ecdsa_signature_serialize_compact.restype = c_int

        secp256k1.secp256k1_ecdsa_signature_parse_der.argtypes = [c_void_p, c_char_p, c_char_p, c_size_t]
        secp256k1.secp256k1_ecdsa_signature_parse_der.restype = c_int

        secp256k1.secp256k1_ecdsa_signature_serialize_der.argtypes = [c_void_p, c_char_p, c_void_p, c_char_p]
        secp256k1.secp256k1_ecdsa_signature_serialize_der.restype = c_int

        secp256k1.secp256k1_ec_pubkey_tweak_mul.argtypes = [c_void_p, c_char_p, c_char_p]
        secp256k1.secp256k1_ec_pubkey_tweak_mul.restype = c_int

        secp256k1.secp256k1_ec_pubkey_combine.argtypes = [c_void_p, c_char_p, c_void_p, c_size_t]
        secp256k1.secp256k1_ec_pubkey_combine.restype = c_int

        # --enable-module-recovery
        try:
            secp256k1.secp256k1_ecdsa_recover.argtypes = [c_void_p, c_char_p, c_char_p, c_char_p]
            secp256k1.secp256k1_ecdsa_recover.restype = c_int

            secp256k1.secp256k1_ecdsa_recoverable_signature_parse_compact.argtypes = [c_void_p, c_char_p, c_char_p, c_int]
            secp256k1.secp256k1_ecdsa_recoverable_signature_parse_compact.restype = c_int
        except (OSError, AttributeError):
            raise LibModuleMissing('libsecp256k1 library found but it was built '
                                   'without required module (--enable-module-recovery)')

        secp256k1.ctx = secp256k1.secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY)
        ret = secp256k1.secp256k1_context_randomize(secp256k1.ctx, os.urandom(32))
        if not ret:
            _logger.error('secp256k1_context_randomize failed')
            return None

        return secp256k1
    except (OSError, AttributeError) as e:
        _logger.error(f'libsecp256k1 library was found and loaded but there was an error when using it: {repr(e)}')
        return None

load_library()

Selected Statement: if not secp256k1:

Function Input:

Variable Values Before Statement:
secp256k1: None

Value After Statement Execution: No

Variable States During Runtime (line, value):
tested_libversions: 4
[2, 1, 0]
libnames: 5
16
libsecp256k1.so.2
16
libsecp256k1.so.2, libsecp256k1.so.1
16
libsecp256k1.so.2, libsecp256k1.so.1, libsecp256k1.so.0
v: 15
2
15
1
15
0
library_paths: 19
21
/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.2
21
/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.2
/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.1
21
/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.2
/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.1
/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.0
23
/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.2
/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.1
/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.0
libsecp256k1.so.2
23
/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.2
/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.1
/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.0
libsecp256k1.so.2
libsecp256k1.so.1
23
/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.2
/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.1
/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.0
libsecp256k1.so.2
libsecp256k1.so.1
libsecp256k1.so.0
libname: 20
'libsecp256k1.so.2'
20
'libsecp256k1.so.1'
20
'libsecp256k1.so.0'
22
'libsecp256k1.so.2'
22
'libsecp256k1.so.1'
22
'libsecp256k1.so.0'
exceptions: 25
31
[OSError('/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.2: cannot open shared object file: No such file or directory')]
31
[OSError('/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.2: cannot open shared object file: No such file or directory'), OSError('/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.1: cannot open shared object file: No such file or directory')]
31
[OSError('/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.2: cannot open shared object file: No such file or directory'), OSError('/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.1: cannot open shared object file: No such file or directory'), OSError('/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.0: cannot open shared object file: No such file or directory')]
31
[OSError('/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.2: cannot open shared object file: No such file or directory'), OSError('/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.1: cannot open shared object file: No such file or directory'), OSError('/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.0: cannot open shared object file: No such file or directory'), OSError('libsecp256k1.so.2: cannot open shared object file: No such file or directory')]
31
[OSError('/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.2: cannot open shared object file: No such file or directory'), OSError('/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.1: cannot open shared object file: No such file or directory'), OSError('/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.0: cannot open shared object file: No such file or directory'), OSError('libsecp256k1.so.2: cannot open shared object file: No such file or directory'), OSError('libsecp256k1.so.1: cannot open shared object file: No such file or directory')]
31
[OSError('/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.2: cannot open shared object file: No such file or directory'), OSError('/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.1: cannot open shared object file: No such file or directory'), OSError('/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.0: cannot open shared object file: No such file or directory'), OSError('libsecp256k1.so.2: cannot open shared object file: No such file or directory'), OSError('libsecp256k1.so.1: cannot open shared object file: No such file or directory'), OSError('libsecp256k1.so.0: cannot open shared object file: No such file or directory')]
secp256k1: 26
None
libpath: 27
'/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.2'
27
'/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.1'
27
'/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.0'
27
'libsecp256k1.so.2'
27
'libsecp256k1.so.1'
27
'libsecp256k1.so.0'
e: 30
OSError('/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.2: cannot open shared object file: No such file or directory')
30
OSError('/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.1: cannot open shared object file: No such file or directory')
30
OSError('/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/spesmilo+electrum/spesmilo+electrum/electrum/libsecp256k1.so.0: cannot open shared object file: No such file or directory')
30
OSError('libsecp256k1.so.2: cannot open shared object file: No such file or directory')
30
OSError('libsecp256k1.so.1: cannot open shared object file: No such file or directory')
30
OSError('libsecp256k1.so.0: cannot open shared object file: No such file or directory')