Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
python3 --version
pip freeze --all
python3 -c "import electrum_ecc; print(f'{electrum_ecc.__version__=}'); print(electrum_ecc.ecc_fast.version_info())"
python3 -c "from electrum_ecc.ecc_fast import HAS_MUSIG; assert HAS_MUSIG"

- name: Run pytest
run: pytest tests --cov=electrum_ecc
Expand Down Expand Up @@ -82,3 +83,29 @@ jobs:
- name: import test from src/
working-directory: src
run: python3 -c "import electrum_ecc; print(f'{electrum_ecc.__version__=}'); print(electrum_ecc.ecc_fast.version_info())"

system-lib-without-musig:
name: "unittests: system libsecp256k1 without MuSig"
runs-on: ubuntu-24.04
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v6
with:
submodules: true

- uses: actions/setup-python@v6
with:
python-version: "3.13"

- name: Install system libsecp256k1 and package
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends libsecp256k1-1
pip install pytest
ELECTRUM_ECC_DONT_COMPILE=1 pip install .

- name: Verify fallback and run pytest
run: |
python3 -c "from electrum_ecc.ecc_fast import HAS_MUSIG; assert not HAS_MUSIG"
pytest tests
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def compile_secp(build_dir: str) -> None:
'--enable-module-recovery',
'--enable-module-extrakeys',
'--enable-module-schnorrsig',
'--enable-module-musig',
'--enable-experimental',
'--enable-module-ecdh',
'--enable-benchmark=no',
Expand Down
52 changes: 52 additions & 0 deletions src/electrum_ecc/ecc_fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class LibModuleMissing(Exception): pass

def load_library():
global HAS_SCHNORR
global HAS_MUSIG

HAS_MUSIG = False

libnames_local = []
libnames_anywhere = []
Expand Down Expand Up @@ -180,6 +183,54 @@ def load_library():
# raise LibModuleMissing('libsecp256k1 library found but it was built '
# 'without required module (--enable-module-extrakeys)')

# --enable-module-musig
try:
char_ptr = POINTER(c_char)
char_ptr_ptr = POINTER(char_ptr)
secp256k1.secp256k1_musig_pubnonce_parse.argtypes = [c_void_p, POINTER(c_char), POINTER(c_char)]
secp256k1.secp256k1_musig_pubnonce_parse.restype = c_int
secp256k1.secp256k1_musig_pubnonce_serialize.argtypes = [c_void_p, POINTER(c_char), POINTER(c_char)]
secp256k1.secp256k1_musig_pubnonce_serialize.restype = c_int
secp256k1.secp256k1_musig_aggnonce_parse.argtypes = [c_void_p, POINTER(c_char), POINTER(c_char)]
secp256k1.secp256k1_musig_aggnonce_parse.restype = c_int
secp256k1.secp256k1_musig_aggnonce_serialize.argtypes = [c_void_p, POINTER(c_char), POINTER(c_char)]
secp256k1.secp256k1_musig_aggnonce_serialize.restype = c_int
secp256k1.secp256k1_musig_partial_sig_parse.argtypes = [c_void_p, POINTER(c_char), POINTER(c_char)]
secp256k1.secp256k1_musig_partial_sig_parse.restype = c_int
secp256k1.secp256k1_musig_partial_sig_serialize.argtypes = [c_void_p, POINTER(c_char), POINTER(c_char)]
secp256k1.secp256k1_musig_partial_sig_serialize.restype = c_int

secp256k1.secp256k1_musig_pubkey_agg.argtypes = [c_void_p, char_ptr, char_ptr, char_ptr_ptr, c_size_t]
secp256k1.secp256k1_musig_pubkey_agg.restype = c_int
secp256k1.secp256k1_musig_pubkey_ec_tweak_add.argtypes = [c_void_p, POINTER(c_char), POINTER(c_char), POINTER(c_char)]
secp256k1.secp256k1_musig_pubkey_ec_tweak_add.restype = c_int
secp256k1.secp256k1_musig_pubkey_xonly_tweak_add.argtypes = [c_void_p, POINTER(c_char), POINTER(c_char), POINTER(c_char)]
secp256k1.secp256k1_musig_pubkey_xonly_tweak_add.restype = c_int

secp256k1.secp256k1_musig_nonce_gen.argtypes = [
c_void_p, POINTER(c_char), POINTER(c_char), POINTER(c_char),
POINTER(c_char), POINTER(c_char), POINTER(c_char),
POINTER(c_char), POINTER(c_char),
]
secp256k1.secp256k1_musig_nonce_gen.restype = c_int
secp256k1.secp256k1_musig_nonce_agg.argtypes = [c_void_p, char_ptr, char_ptr_ptr, c_size_t]
secp256k1.secp256k1_musig_nonce_agg.restype = c_int
secp256k1.secp256k1_musig_nonce_process.argtypes = [c_void_p, POINTER(c_char), POINTER(c_char), POINTER(c_char), POINTER(c_char)]
secp256k1.secp256k1_musig_nonce_process.restype = c_int
secp256k1.secp256k1_musig_partial_sign.argtypes = [c_void_p, POINTER(c_char), POINTER(c_char), POINTER(c_char), POINTER(c_char), POINTER(c_char)]
secp256k1.secp256k1_musig_partial_sign.restype = c_int
secp256k1.secp256k1_musig_partial_sig_verify.argtypes = [c_void_p, POINTER(c_char), POINTER(c_char), POINTER(c_char), POINTER(c_char), POINTER(c_char)]
secp256k1.secp256k1_musig_partial_sig_verify.restype = c_int
secp256k1.secp256k1_musig_partial_sig_agg.argtypes = [c_void_p, char_ptr, char_ptr, char_ptr_ptr, c_size_t]
secp256k1.secp256k1_musig_partial_sig_agg.restype = c_int
except (OSError, AttributeError):
_logger.warning(
'libsecp256k1 library found but it was built without desired module '
'(--enable-module-musig)'
)
else:
HAS_MUSIG = True

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:
Expand All @@ -194,6 +245,7 @@ def load_library():

_libsecp256k1 = None
HAS_SCHNORR = True
HAS_MUSIG = False
try:
_libsecp256k1 = load_library()
except BaseException as e:
Expand Down
Loading