diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index f32fc3298..82c73e1d6 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -20,7 +20,7 @@ jobs: CIBW_BEFORE_ALL_LINUX: yum install -y swig || apk add swig CIBW_BEFORE_ALL_MACOS: brew install gnu-sed swig automake CIBW_BEFORE_ALL_WINDOWS: choco install swig --version=3.0.12 --no-progress --allow-downgrade -y - CIBW_BEFORE_BUILD_WINDOWS: .\tools\msvc\wheel_preamble.bat + CIBW_BEFORE_BUILD_WINDOWS: .\tools\msvc\swig.bat CIBW_REPAIR_WHEEL_COMMAND_LINUX: auditwheel repair --only-plat -w {dest_dir} {wheel} LIBWALLY_DIR: "." SWIG_PATH: "C:\\ProgramData\\chocolatey\\lib\\swig\\tools\\install\\swigwin-3.0.12" diff --git a/.gitignore b/.gitignore index 5580b38a0..77dc28fad 100644 --- a/.gitignore +++ b/.gitignore @@ -78,6 +78,7 @@ docs/source/psbt_members.rst docs/source/script.rst docs/source/symmetric.rst docs/source/transaction.rst +docs/source/transaction_members.rst docs/source/elements.rst docs/source/*_int.rst .idea/ diff --git a/README.md b/README.md index 5dd1fc418..fe89173ff 100644 --- a/README.md +++ b/README.md @@ -114,34 +114,39 @@ installed. ### Python -For non-development use, you can install wally with `pip` as follows: +For non-development use, you can install wally from PyPI with `pip` as follows: ``` pip install wallycore==0.9.2 ``` -For python development, you can build and install wally using: +For development, you can build and install wally using: ``` $ pip install . ``` -It is suggested you only install this way into a virtualenv while the library -is under heavy development. - If you wish to explicitly choose the python version to use, set the -`PYTHON_VERSION` environment variable (to e.g. `3`, `3.7` etc) before +`PYTHON_VERSION` environment variable (to e.g. `3.9`, `3.10` etc) before running `pip` or (when compiling manually) `./configure`. You can also install the binary [wally releases](https://github.com/ElementsProject/libwally-core/releases) -using the released wheel files without having to compile the library, e.g.: +using the released wheel files, for example if you don't wish to install from PyPI over the network: ``` pip install wallycore-.whl ``` -The script `tools/build_python_manylinux_wheels.sh` builds the Linux release files -and can be used as an example for your own python projects. +Each wally release includes a signed `requirements.txt` file. It is strongly +suggested that you verify and use this file when installing, with: + +``` +pip -r requirements.txt +``` + +Doing so ensures that the wheel you install is the version you expect and an +official build. This will detect, for example, if PyPI is hacked and a +malicious wallycore package uploaded. ### Android diff --git a/configure.ac b/configure.ac index 703f25d5d..dee72ef2b 100644 --- a/configure.ac +++ b/configure.ac @@ -12,6 +12,9 @@ AH_BOTTOM([#include "ccan_config.h" LDPATH_VAR=LD_LIBRARY_PATH case $host_os in +cygwin*|mingw*) + is_win="yes" + ;; *darwin*) is_osx="yes" LDPATH_VAR=DYLD_LIBRARY_PATH @@ -212,12 +215,6 @@ AC_RUN_IFELSE([AC_LANG_SOURCE([[int main(void){static int a[2];return *((int*)(( have_unaligned=1, have_unaligned=0, have_unaligned=0) AC_DEFINE_UNQUOTED([HAVE_UNALIGNED_ACCESS], [$have_unaligned], [Define if we have unaligned access]) -if test "x$is_osx" != "xyes"; then - # Assume we are using gcc (i.e. have this attribute) if cross-compiling - AC_COMPILE_IFELSE([AC_LANG_SOURCE([extern int foo(int) __attribute__((weak)); int main(void){return 0;}])], - [AC_DEFINE([HAVE_ATTRIBUTE_WEAK], 1, [Define if we have __attribute__((weak))])]) -fi - AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]],[[mmap(0,0,0,0,0,0)]])], [AC_DEFINE(HAVE_MMAP, 1, [Define if we have mmap])]) @@ -339,6 +336,9 @@ if test "x$swig_python" = "xyes"; then if test "x$pythonexists" != "xyes"; then AC_MSG_FAILURE([ERROR: No usable Python was found for swig-python]) fi + if test "x$elements_abi" = "xno"; then + AC_MSG_FAILURE([ERROR: Python wrapper can not be enabled when Elements ABI is disabled]) + fi SWIG_PYTHON AX_CHECK_COMPILE_FLAG([-DSWIG_PYTHON_BUILD=1], [AM_CFLAGS="$AM_CFLAGS -DSWIG_PYTHON_BUILD=1"]) fi @@ -349,6 +349,9 @@ AC_ARG_ENABLE(swig-java, AM_CONDITIONAL([USE_SWIG_JAVA], [test "x$swig_java" = "xyes"]) if test "x$swig_java" = "xyes"; then + if test "x$elements_abi" = "xno"; then + AC_MSG_FAILURE([ERROR: Java wrapper can not be enabled when Elements ABI is disabled]) + fi saved_JAVA_HOME=$JAVA_HOME if test x"$cross_compiling" = "xyes"; then # For cross compiling we assume the users host O/S Java install is not @@ -389,12 +392,19 @@ AC_SUBST([JAVAC_TARGET]) AC_SUBST([AM_CFLAGS]) +AM_CONDITIONAL([SHARED_BUILD_ENABLED], [test "x$enable_shared" = "xyes"]) if test "x$enable_static" = "xyes"; then CTEST_EXTRA_STATIC='$(libwallycore_la_LIBADD)' + dnl Windows static builds require SECP256K1_STATIC to be defined. + dnl As a result, you can't build both a static (.lib) and dynamic (.dll) + dnl library with a single 'configure; make' invocation. + if test "x$is_win" = "xyes" -a "x$enable_shared" = "xyes"; then + AC_MSG_ERROR([Windows builds cannot build shared and static builds at the same time]) + fi + AX_CHECK_COMPILE_FLAG([-DSECP256K1_STATIC=1], [AM_CFLAGS="$AM_CFLAGS -DSECP256K1_STATIC=1"]) fi AC_SUBST([CTEST_EXTRA_STATIC]) -AM_CONDITIONAL([SHARED_BUILD_ENABLED], [test "x$enable_shared" = "xyes"]) AC_CONFIG_FILES([ Makefile diff --git a/setup.py b/setup.py index 3f30e1ca2..c0249ea6a 100644 --- a/setup.py +++ b/setup.py @@ -40,29 +40,23 @@ # Run the autotools/make build up front to generate our sources, # then build using the standard Python ext module machinery. # (Windows requires source generation to be done separately). - import multiprocessing import subprocess abs_path = os.path.dirname(os.path.abspath(__file__)) + '/' - def call(args): - subprocess.check_call(args, cwd=abs_path, env=configure_env) + def call(args, cwd=abs_path): + subprocess.check_call(args, cwd=cwd, env=configure_env) call(['./tools/cleanup.sh']) call(['./tools/autogen.sh']) call(['./configure'] + CONFIGURE_ARGS) - call(['make', '-j{}'.format(multiprocessing.cpu_count())]) + call(['make', 'swig_python/swig_python_wrap.c'], abs_path + 'src/') define_macros=[ ('SWIG_PYTHON_BUILD', None), ('WALLY_CORE_BUILD', None), - ('HAVE_CONFIG_H', None), - ('SECP256K1_BUILD', None), - ('BUILD_ELEMENTS', None) + ('BUILD_ELEMENTS', None), ] -if is_windows: - define_macros.append(('USE_ECMULT_STATIC_PRECOMPUTATION', None)) - define_macros.append(('ECMULT_WINDOW_SIZE', 15)) include_dirs=[ './', @@ -70,11 +64,12 @@ def call(args): './src/ccan', './src/secp256k1/include', ] + if is_windows: - shutil.copyfile('./src/amalgamation/windows_config/libsecp256k1-config.h', 'src/secp256k1/src/libsecp256k1-config.h') include_dirs = ['./src/amalgamation/windows_config'] + include_dirs - -extra_compile_args = ['-flax-vector-conversions'] + extra_compile_args = [] +else: + extra_compile_args = ['-flax-vector-conversions'] wally_ext = Extension( '_wallycore', @@ -82,7 +77,7 @@ def call(args): include_dirs=include_dirs, extra_compile_args=extra_compile_args, sources=[ - 'src/swig_python/swig_wrap.c' if is_windows else 'src/swig_python/swig_python_wrap.c', + 'src/swig_python/swig_python_wrap.c', 'src/amalgamation/combined.c', 'src/amalgamation/combined_ccan.c', 'src/amalgamation/combined_ccan2.c', diff --git a/src/Makefile.am b/src/Makefile.am index a20e0c218..261c23c05 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,6 +24,7 @@ include_HEADERS += $(top_srcdir)/include/wally_psbt_members.h include_HEADERS += $(top_srcdir)/include/wally_script.h include_HEADERS += $(top_srcdir)/include/wally_symmetric.h include_HEADERS += $(top_srcdir)/include/wally_transaction.h +include_HEADERS += $(top_srcdir)/include/wally_transaction_members.h pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = wallycore.pc @@ -177,6 +178,7 @@ libwallycore_la_SOURCES = \ libwallycore_la_INCLUDES = \ include/wally.hpp \ include/wally_address.h \ + include/wally_anti_exfil.h \ include/wally_bip32.h \ include/wally_bip38.h \ include/wally_bip39.h \ @@ -188,9 +190,11 @@ libwallycore_la_INCLUDES = \ include/wally_elements.h \ include/wally_map.h \ include/wally_psbt.h \ + include/wally_psbt_members.h \ include/wally_script.h \ include/wally_symmetric.h \ - include/wally_transaction.h + include/wally_transaction.h \ + include/wally_transaction_members.h if SHARED_BUILD_ENABLED LT_VER_CURRENT = 0 # increment at every ABI change (whether breaking or non-breaking) diff --git a/src/amalgamation/combined.c b/src/amalgamation/combined.c index 216a6389e..c60d4dcca 100644 --- a/src/amalgamation/combined.c +++ b/src/amalgamation/combined.c @@ -1,4 +1,40 @@ -#define SECP256K1_BUILD 1 +/* + * secp2556k1-zkp configuration + */ +#define ENABLE_MODULE_ECDH 1 +#define ENABLE_MODULE_EXTRAKEYS 1 +#define ENABLE_MODULE_SCHNORRSIG 1 +#define ENABLE_MODULE_GENERATOR 1 +#define ENABLE_MODULE_ECDSA_S2C 1 +#ifdef BUILD_ELEMENTS +#define ENABLE_MODULE_RANGEPROOF 1 +#define ENABLE_MODULE_RECOVERY 1 +#define ENABLE_MODULE_SURJECTIONPROOF 1 +#define ENABLE_MODULE_WHITELIST 1 +#endif + +#if (defined(__clang__) || defined(__GNUC__)) && (defined(__x86_64__) || defined(__amd64__)) +#define USE_ASM_X86_64 1 +#endif + +#undef PACKAGE +#undef PACKAGE_BUGREPORT +#undef PACKAGE_NAME +#undef PACKAGE_STRING +#undef PACKAGE_TARNAME +#undef PACKAGE_URL +#undef PACKAGE_VERSION +#undef VERSION +#if defined(__clang__) +#pragma clang diagnostic ignored "-Wunused-function" +#elif defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wunused-function" +#endif +#include "src/secp256k1/src/secp256k1.c" +#include "src/secp256k1/src/precomputed_ecmult_gen.c" +#include "src/secp256k1/src/precomputed_ecmult.c" +#include "ccan/ccan/crypto/sha256/sha256.c" + #include "internal.c" #include "address.c" #include "aes.c" @@ -29,19 +65,6 @@ #include "transaction.c" #include "wif.c" #include "wordlist.c" -#undef PACKAGE -#undef PACKAGE_BUGREPORT -#undef PACKAGE_NAME -#undef PACKAGE_STRING -#undef PACKAGE_TARNAME -#undef PACKAGE_URL -#undef PACKAGE_VERSION -#undef VERSION -#undef SECP256K1_BUILD -#include "src/secp256k1/src/secp256k1.c" -#include "src/secp256k1/src/precomputed_ecmult_gen.c" -#include "src/secp256k1/src/precomputed_ecmult.c" -#include "ccan/ccan/crypto/sha256/sha256.c" void wally_silence_unused_warnings(void) { @@ -49,20 +72,4 @@ void wally_silence_unused_warnings(void) assert_bip32_assumptions(); assert_bip38_assumptions(); assert_tx_assumptions(); - secp256k1_fe_get_bounds(NULL, 0); - secp256k1_fe_inv_var(NULL, NULL); - secp256k1_ge_set_all_gej_var(NULL, NULL, 0); - secp256k1_gej_has_quad_y_var(NULL); - secp256k1_ge_is_valid_var(NULL); - secp256k1_ge_set_infinity(NULL); - secp256k1_ec_commit_verify(NULL, NULL, NULL, NULL, 0); - secp256k1_ecmult_multi_var(NULL, NULL, NULL, NULL, NULL, NULL, 0); - secp256k1_ecmult_strauss_batch_single(NULL, NULL, NULL, NULL, NULL, NULL, 0); - secp256k1_ecmult_pippenger_batch_single(NULL, NULL, NULL, NULL, NULL, NULL, 0); - secp256k1_pippenger_scratch_size(0, 0); - secp256k1_scalar_chacha20(NULL, NULL, NULL, 0); - secp256k1_sha256_initialize_tagged(NULL, NULL, 0); - tx_elements_input_issuance_proof_init(NULL, NULL, 0, NULL, 0); - tx_elements_output_proof_init(NULL, NULL, 0, NULL, 0); - witness_stack_from_bytes(NULL, NULL, NULL); } diff --git a/src/amalgamation/windows_config/config.h b/src/amalgamation/windows_config/config.h index 312345559..454a73eca 100644 --- a/src/amalgamation/windows_config/config.h +++ b/src/amalgamation/windows_config/config.h @@ -1,36 +1,19 @@ #ifndef LIBWALLYCORE_CONFIG_H #define LIBWALLYCORE_CONFIG_H + +/* config.h for Windows. Assumes a little-endian intel-ish target */ #include -#define HAVE_ATTRIBUTE_WEAK 1 -#define HAVE_BIG_ENDIAN 0 -#define HAVE_BSWAP_64 0 -#define HAVE_BYTESWAP_H 0 -#define HAVE_DLFCN_H 1 -#define HAVE_INTTYPES_H 1 -#define HAVE_LITTLE_ENDIAN 1 -#define HAVE_MEMORY_H 1 -#define HAVE_MMAP 1 -#define HAVE_PTHREAD 1 -#define HAVE_PTHREAD_PRIO_INHERIT 1 -#define HAVE_PYTHON "2.7" -#define HAVE_STDINT_H 1 -#define HAVE_STDLIB_H 1 -#define HAVE_STRINGS_H 1 -#define HAVE_STRING_H 1 -#define HAVE_SYS_STAT_H 1 -#define HAVE_SYS_TYPES_H 1 -#define HAVE_UNISTD_H 1 -#define STDC_HEADERS 1 -#define VERSION "0.6" -#if (!defined(_SSIZE_T_DECLARED)) && (!defined(_ssize_t)) && (!defined(ssize_t)) -#define ssize_t long long +#ifndef _WIN32 +#error windows_config/config.h is only intended for windows builds #endif -#define alignment_ok(p, n) ((size_t)(p) % (n) == 0) +#define HAVE_UNALIGNED_ACCESS 1 -void wally_clear(void *p, size_t len); +#if (!defined(_SSIZE_T_DECLARED)) && (!defined(_ssize_t)) && (!defined(ssize_t)) +#define ssize_t long long +#endif -#define CCAN_CLEAR_MEMORY(p, len) wally_clear(p, len) +#include "ccan_config.h" -#endif /*LIBWALLYCORE_CONFIG_H*/ +#endif /* LIBWALLYCORE_CONFIG_H */ diff --git a/src/amalgamation/windows_config/libsecp256k1-config.h b/src/amalgamation/windows_config/libsecp256k1-config.h deleted file mode 100644 index 890fb1cdc..000000000 --- a/src/amalgamation/windows_config/libsecp256k1-config.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef LIBSECP256K1_CONFIG_H -#define LIBSECP256K1_CONFIG_H - -#define ECMULT_GEN_PREC_BITS 4 -#define ENABLE_MODULE_ECDH 1 -#define ENABLE_MODULE_ECDSA_S2C 1 -#define ENABLE_MODULE_EXTRAKEYS 1 -#define ENABLE_MODULE_GENERATOR 1 -#define ENABLE_MODULE_RANGEPROOF 1 -#define ENABLE_MODULE_RECOVERY 1 -#define ENABLE_MODULE_SCHNORRSIG 1 -#define ENABLE_MODULE_SURJECTIONPROOF 1 -#define ENABLE_MODULE_WHITELIST 1 -#define HAVE_DLFCN_H 1 -#define HAVE_INTTYPES_H 1 -#define HAVE_LIBCRYPTO 1 -#define HAVE_MEMORY_H 1 -#define HAVE_STDINT_H 1 -#define HAVE_STDLIB_H 1 -#define HAVE_STRINGS_H 1 -#define HAVE_STRING_H 1 -#define HAVE_SYS_STAT_H 1 -#define HAVE_SYS_TYPES_H 1 -#define HAVE_UNISTD_H 1 -#define STDC_HEADERS 1 -#define USE_ASM_X86_64 1 -#define USE_FIELD_10X26 1 -#define USE_FIELD_INV_BUILTIN 1 -#define USE_NUM_NONE 1 -#define USE_SCALAR_8X32 1 -#define USE_SCALAR_INV_BUILTIN 1 - -#endif /*LIBSECP256K1_CONFIG_H*/ diff --git a/src/ecdh.c b/src/ecdh.c index 0130de427..4888efc7f 100644 --- a/src/ecdh.c +++ b/src/ecdh.c @@ -1,6 +1,5 @@ #include "internal.h" #include -#include #include int wally_ecdh(const unsigned char *pub_key, size_t pub_key_len, diff --git a/src/internal.c b/src/internal.c index 1a4e53d0d..b3ff4f06b 100644 --- a/src/internal.c +++ b/src/internal.c @@ -29,27 +29,27 @@ int wally_get_build_version(uint32_t *value) int pubkey_combine(secp256k1_pubkey *pubnonce, const secp256k1_pubkey *const *pubnonces, size_t n) { - return secp256k1_ec_pubkey_combine(secp256k1_context_no_precomp, pubnonce, pubnonces, n); + return secp256k1_ec_pubkey_combine(secp256k1_context_static, pubnonce, pubnonces, n); } int pubkey_negate(secp256k1_pubkey *pubkey) { - return secp256k1_ec_pubkey_negate(secp256k1_context_no_precomp, pubkey); + return secp256k1_ec_pubkey_negate(secp256k1_context_static, pubkey); } int pubkey_parse(secp256k1_pubkey *pubkey, const unsigned char *input, size_t input_len) { - return secp256k1_ec_pubkey_parse(secp256k1_context_no_precomp, pubkey, input, input_len); + return secp256k1_ec_pubkey_parse(secp256k1_context_static, pubkey, input, input_len); } int pubkey_serialize(unsigned char *output, size_t *outputlen, const secp256k1_pubkey *pubkey, unsigned int flags) { - return secp256k1_ec_pubkey_serialize(secp256k1_context_no_precomp, output, outputlen, pubkey, flags); + return secp256k1_ec_pubkey_serialize(secp256k1_context_static, output, outputlen, pubkey, flags); } int xpubkey_parse(secp256k1_xonly_pubkey *xpubkey, const unsigned char *input, size_t input_len) { - const secp256k1_context *ctx = secp256k1_context_no_precomp; + const secp256k1_context *ctx = secp256k1_context_static; if (input_len == EC_PUBLIC_KEY_UNCOMPRESSED_LEN) return 0; if (input_len == EC_PUBLIC_KEY_LEN) { @@ -67,33 +67,33 @@ int xpubkey_tweak_add(secp256k1_pubkey *pubkey, const secp256k1_xonly_pubkey *xpubkey, const unsigned char *tweak) { - return secp256k1_xonly_pubkey_tweak_add(secp256k1_context_no_precomp, + return secp256k1_xonly_pubkey_tweak_add(secp256k1_context_static, pubkey, xpubkey, tweak); } int xpubkey_serialize(unsigned char *output, const secp256k1_xonly_pubkey *xpubkey) { - return secp256k1_xonly_pubkey_serialize(secp256k1_context_no_precomp, output, xpubkey); + return secp256k1_xonly_pubkey_serialize(secp256k1_context_static, output, xpubkey); } int seckey_verify(const unsigned char *seckey) { - return secp256k1_ec_seckey_verify(secp256k1_context_no_precomp, seckey); + return secp256k1_ec_seckey_verify(secp256k1_context_static, seckey); } int seckey_negate(unsigned char *seckey) { - return secp256k1_ec_seckey_negate(secp256k1_context_no_precomp, seckey); + return secp256k1_ec_seckey_negate(secp256k1_context_static, seckey); } int seckey_tweak_add(unsigned char *seckey, const unsigned char *tweak) { - return secp256k1_ec_seckey_tweak_add(secp256k1_context_no_precomp, seckey, tweak); + return secp256k1_ec_seckey_tweak_add(secp256k1_context_static, seckey, tweak); } int seckey_tweak_mul(unsigned char *seckey, const unsigned char *tweak) { - return secp256k1_ec_seckey_tweak_mul(secp256k1_context_no_precomp, seckey, tweak); + return secp256k1_ec_seckey_tweak_mul(secp256k1_context_static, seckey, tweak); } int keypair_create(secp256k1_keypair *keypair, const unsigned char *priv_key) @@ -103,17 +103,17 @@ int keypair_create(secp256k1_keypair *keypair, const unsigned char *priv_key) int keypair_xonly_pub(secp256k1_xonly_pubkey *xpubkey, const secp256k1_keypair *keypair) { - return secp256k1_keypair_xonly_pub(secp256k1_context_no_precomp, xpubkey, NULL, keypair); + return secp256k1_keypair_xonly_pub(secp256k1_context_static, xpubkey, NULL, keypair); } int keypair_sec(unsigned char *output, const secp256k1_keypair *keypair) { - return secp256k1_keypair_sec(secp256k1_context_no_precomp, output, keypair); + return secp256k1_keypair_sec(secp256k1_context_static, output, keypair); } int keypair_xonly_tweak_add(secp256k1_keypair *keypair, const unsigned char *tweak) { - return secp256k1_keypair_xonly_tweak_add(secp256k1_context_no_precomp, keypair, tweak); + return secp256k1_keypair_xonly_tweak_add(secp256k1_context_static, keypair, tweak); } #ifndef SWIG diff --git a/src/secp256k1 b/src/secp256k1 index ff33018fe..2192e9d05 160000 --- a/src/secp256k1 +++ b/src/secp256k1 @@ -1 +1 @@ -Subproject commit ff33018fe765df82f8515c564d3fe44d388d3903 +Subproject commit 2192e9d051186754100fd270955fa6e7df26d457 diff --git a/src/sign.c b/src/sign.c index f5b929fee..383e1831f 100644 --- a/src/sign.c +++ b/src/sign.c @@ -222,7 +222,7 @@ int wally_ec_sig_normalize(const unsigned char *sig, size_t sig_len, unsigned char *bytes_out, size_t len) { secp256k1_ecdsa_signature sig_secp, sig_low; - const secp256k1_context *ctx = secp256k1_context_no_precomp; + const secp256k1_context *ctx = secp256k1_context_static; bool ok; ok = sig && sig_len == EC_SIGNATURE_LEN && @@ -248,7 +248,7 @@ int wally_ec_sig_to_der(const unsigned char *sig, size_t sig_len, { secp256k1_ecdsa_signature sig_secp; size_t len_in_out = len; - const secp256k1_context *ctx = secp256k1_context_no_precomp; + const secp256k1_context *ctx = secp256k1_context_static; bool ok; if (written) @@ -275,7 +275,7 @@ int wally_ec_sig_from_der(const unsigned char *bytes, size_t bytes_len, unsigned char *bytes_out, size_t len) { secp256k1_ecdsa_signature sig_secp; - const secp256k1_context *ctx = secp256k1_context_no_precomp; + const secp256k1_context *ctx = secp256k1_context_static; bool ok; ok = bytes && bytes_len && bytes_out && len == EC_SIGNATURE_LEN && diff --git a/src/test/test_transaction.py b/src/test/test_transaction.py index b0d52ff29..f0e10245c 100644 --- a/src/test/test_transaction.py +++ b/src/test/test_transaction.py @@ -320,13 +320,6 @@ def sha256d(hex_): def test_hash_prevouts(self): """Test functions computing hash_prevouts""" - if not wally_is_elements_build()[1]: - # The direct access tx.num_inputs/tx.inputs[i].txhash/tx.inputs[i].index - # below only works if this is an elements build. Skip this test for - # non-elements builds until the tx accessors are available to call - # when SWIG is not defined. - self.skipTest('https://github.com/ElementsProject/libwally-core/issues/388') - out, out_len = make_cbuffer('00'*32) # The first sample tx from BIP-0143 bip143_tx = '0100000002fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f0000000000eeffffffef51e1b804cc89d182d279655c3aa89e815b1b309fe287d9b2b55d57b90ec68a0100000000ffffffff02202cb206000000001976a9148280b37df378db99f66f85c95a783a76ac7a6d5988ac9093510d000000001976a9143bde42dbee7e4dbe6a21b2d50ce2f0167faa815988ac11000000' @@ -349,8 +342,13 @@ def test_hash_prevouts(self): # Compute from the underlying data txhashes, indices = bytearray(), (c_uint * tx.num_inputs)() for i in range(tx.num_inputs): - txhashes.extend(tx.inputs[i].txhash) - indices[i] = tx.inputs[i].index + txhash, txhash_len = make_cbuffer('00' * 32) + ret = wally_tx_get_input_txhash(tx, i, txhash, txhash_len) + self.assertEqual(ret, WALLY_OK) + txhashes.extend(txhash) + ret, txin = wally_tx_get_input_index(tx, i) + self.assertEqual(ret, WALLY_OK) + indices[i] = txin txhashes = bytes(txhashes) ret = wally_get_hash_prevouts(txhashes, len(txhashes), indices, len(indices), out, out_len) diff --git a/tools/msvc/build.bat b/tools/msvc/build.bat index 4ba735a85..b074e616b 100644 --- a/tools/msvc/build.bat +++ b/tools/msvc/build.bat @@ -1,20 +1,10 @@ set LIBWALLY_DIR=%cd% -REM Need to first build gen_context.exe to generate a header file -REM It seems possible to skip this step and remove the definition -REM of USE_ECMULT_STATIC_PRECOMPUTATION from the compiler flags -call "%~dp0\gen_ecmult_static_context.bat" - -REM secp now requires its config header in the source directory -copy src\amalgamation\windows_config\libsecp256k1-config.h src\secp256k1\src\libsecp256k1-config.h - if "%ELEMENTS_BUILD%" == "elements" ( - set ELEMENTS_OPT=/DBUILD_ELEMENTS + set OPTS=/DBUILD_ELEMENTS ) else ( - set ELEMENTS_OPT= + set OPTS= ) REM Compile everything (wally, ccan, libsecp256k) in one lump. -REM Define USE_ECMULT_STATIC_PRECOMPUTATION to pick up the -REM ecmult_static_context.h file generated previously -cl /utf-8 /DUSE_ECMULT_STATIC_PRECOMPUTATION /DECMULT_WINDOW_SIZE=15 /DWALLY_CORE_BUILD %ELEMENTS_OPT% /DHAVE_CONFIG_H /DSECP256K1_BUILD /I%LIBWALLY_DIR%\src\amalgamation\windows_config /I%LIBWALLY_DIR% /I%LIBWALLY_DIR%\src /I%LIBWALLY_DIR%\include /I%LIBWALLY_DIR%\src\ccan /I%LIBWALLY_DIR%\src\ccan\base64 /I%LIBWALLY_DIR%\src\secp256k1 /Zi /LD src/aes.c src/anti_exfil.c src/base_58.c src/base_64.c src/bech32.c src/bip32.c src/bip38.c src/bip39.c src/bip85.c src/blech32.c src/coins.c src/descriptor.c src/ecdh.c src/elements.c src/hex_.c src/hmac.c src/internal.c src/mnemonic.c src/pbkdf2.c src/map.c src/psbt.c src/script.c src/scrypt.c src/sign.c src/symmetric.c src/transaction.c src/wif.c src/wordlist.c src/ccan/ccan/crypto/ripemd160/ripemd160.c src/ccan/ccan/crypto/sha256/sha256.c src/ccan/ccan/crypto/sha512/sha512.c src/ccan/ccan/base64/base64.c src\ccan\ccan\str\hex\hex.c src/secp256k1/src/secp256k1.c src/secp256k1/src/precomputed_ecmult_gen.c src/secp256k1/src/precomputed_ecmult.c /Fewally.dll +cl /utf-8 /DWALLY_CORE_BUILD %OPTS% /I%LIBWALLY_DIR% /I%LIBWALLY_DIR%\src /I%LIBWALLY_DIR%\include /I%LIBWALLY_DIR%\src\ccan /I%LIBWALLY_DIR%\src\ccan\base64 /I%LIBWALLY_DIR%\src\secp256k1 /Zi /LD src/amalgamation/combined.c src/amalgamation/combined_ccan.c src/amalgamation/combined_ccan2.c /Fewally.dll diff --git a/tools/msvc/gen_ecmult_static_context.bat b/tools/msvc/gen_ecmult_static_context.bat deleted file mode 100644 index f0685422c..000000000 --- a/tools/msvc/gen_ecmult_static_context.bat +++ /dev/null @@ -1,2 +0,0 @@ -cl /utf-8 /DWALLY_CORE_BUILD /DHAVE_CONFIG_H /DSECP256K1_BUILD /I%LIBWALLY_DIR%\src\amalgamation\windows_config /I%LIBWALLY_DIR%\ /I%LIBWALLY_DIR%\src /I%LIBWALLY_DIR%\include /I%LIBWALLY_DIR%\src\ccan /I%LIBWALLY_DIR%\src\secp256k1 /Zi %LIBWALLY_DIR%\src/secp256k1/src/precompute_ecmult_gen.c /Fegen_context.exe -gen_context.exe diff --git a/tools/msvc/swig.bat b/tools/msvc/swig.bat index 5cd57dfc9..a9dc66322 100644 --- a/tools/msvc/swig.bat +++ b/tools/msvc/swig.bat @@ -1,5 +1,5 @@ REM You need to set SWIG_PATH to the location where the swig zip REM file is expanded to -%SWIG_PATH%\swig -python -Isrc -I%SWIG_PATH%\Lib\python -DBUILD_ELEMENTS=1 src\swig_python\swig.i +%SWIG_PATH%\swig -python -Isrc -I%SWIG_PATH%\Lib\python -DBUILD_ELEMENTS=1 -outdir src\swig_python -o src\swig_python\swig_python_wrap.c src\swig_python\swig.i copy src\swig_python\wallycore.py + src\swig_python\python_extra.py_in src\swig_python\wallycore\__init__.py /B del src\swig_python\wallycore.py diff --git a/tools/msvc/wheel.bat b/tools/msvc/wheel.bat index 74b10c333..5e54acdf7 100644 --- a/tools/msvc/wheel.bat +++ b/tools/msvc/wheel.bat @@ -1,6 +1,6 @@ REM Run swig to generate the wrapper source files required by REM setup.py build step -call "%~dp0"\wheel_preamble.bat || echo ERRORPREAMBLE && exit /b 1 +call "%~dp0"\swig.bat || echo ERRORSWIG && exit /b 1 REM Install virtualenv - this should possibly be on the CI box python -m pip install virtualenv diff --git a/tools/msvc/wheel_preamble.bat b/tools/msvc/wheel_preamble.bat deleted file mode 100644 index 8dc38fc34..000000000 --- a/tools/msvc/wheel_preamble.bat +++ /dev/null @@ -1,12 +0,0 @@ -REM Run swig to generate the wrapper source files required by -REM setup.py build step -call "%~dp0"\swig.bat || echo ERRORSWIG && exit /b 1 - -REM Set VS 2017 environment -call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat" - -REM Need to first build gen_context.exe to generate a header file -REM It seems possible to skip this step and remove the definition -REM of USE_ECMULT_STATIC_PRECOMPUTATION from the compiler flags -set LIBWALLY_DIR=%cd% -call "%~dp0\gen_ecmult_static_context.bat" || echo ERRORGENCONTEXT && exit /b 1