From 51dab7ac041aea166f3529cff44ebb5855e3a180 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Wed, 1 Nov 2023 16:56:36 +0000 Subject: [PATCH 1/3] vendor-libsecp: remove util.h patch This patch adds a declaration of the `ecdsa_parse_compact` function to util.h. This function isn't called from within libsecp proper; it is called in lax_der_parse.c (which we patch separately with a declaration) and in example code (which we don't compile at all). --- secp256k1-sys/depend/secp256k1/src/util.h | 4 +--- secp256k1-sys/depend/util.h.patch | 6 ------ secp256k1-sys/vendor-libsecp.sh | 1 - 3 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 secp256k1-sys/depend/util.h.patch diff --git a/secp256k1-sys/depend/secp256k1/src/util.h b/secp256k1-sys/depend/secp256k1/src/util.h index 5de62d4ed..613901ef3 100644 --- a/secp256k1-sys/depend/secp256k1/src/util.h +++ b/secp256k1-sys/depend/secp256k1/src/util.h @@ -8,9 +8,7 @@ #define SECP256K1_UTIL_H #include "../include/secp256k1.h" -extern int rustsecp256k1_v0_9_0_ecdsa_signature_parse_compact( - const rustsecp256k1_v0_9_0_context *ctx, - rustsecp256k1_v0_9_0_ecdsa_signature *sig, const unsigned char *input64); + #include #include #include diff --git a/secp256k1-sys/depend/util.h.patch b/secp256k1-sys/depend/util.h.patch deleted file mode 100644 index 59b23e0df..000000000 --- a/secp256k1-sys/depend/util.h.patch +++ /dev/null @@ -1,6 +0,0 @@ -10c10,12 -< ---- -> extern int secp256k1_ecdsa_signature_parse_compact( -> const secp256k1_context *ctx, -> secp256k1_ecdsa_signature *sig, const unsigned char *input64); diff --git a/secp256k1-sys/vendor-libsecp.sh b/secp256k1-sys/vendor-libsecp.sh index ed437fc07..e48641287 100755 --- a/secp256k1-sys/vendor-libsecp.sh +++ b/secp256k1-sys/vendor-libsecp.sh @@ -97,7 +97,6 @@ echo "$SOURCE_REV" >> ./secp256k1-HEAD-revision.txt patch "$DIR/include/secp256k1.h" "./secp256k1.h.patch" patch "$DIR/src/secp256k1.c" "./secp256k1.c.patch" patch "$DIR/src/scratch_impl.h" "./scratch_impl.h.patch" -patch "$DIR/src/util.h" "./util.h.patch" # Fix a linking error while cross-compiling to windowns with mingw patch "$DIR/contrib/lax_der_parsing.c" "./lax_der_parsing.c.patch" From 942a0e5e2cf35e728dc75a7e20c68dd01c69308e Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Wed, 1 Nov 2023 17:06:16 +0000 Subject: [PATCH 2/3] build.rs: patch out any calls to `printf` --- secp256k1-sys/build.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/secp256k1-sys/build.rs b/secp256k1-sys/build.rs index 8e11a73aa..49d02e35c 100644 --- a/secp256k1-sys/build.rs +++ b/secp256k1-sys/build.rs @@ -20,11 +20,16 @@ fn main() { .include("depend/secp256k1/include") .include("depend/secp256k1/src") .flag_if_supported("-Wno-unused-function") // some ecmult stuff is defined but not used upstream + .flag_if_supported("-Wno-unused-parameter") // patching out printf causes this warning .define("SECP256K1_API", Some("")) .define("ENABLE_MODULE_ECDH", Some("1")) .define("ENABLE_MODULE_SCHNORRSIG", Some("1")) .define("ENABLE_MODULE_EXTRAKEYS", Some("1")) - .define("ENABLE_MODULE_ELLSWIFT", Some("1")); + .define("ENABLE_MODULE_ELLSWIFT", Some("1")) + // upstream sometimes introduces calls to printf, which we cannot compile + // with WASM due to its lack of libc. printf is never necessary and we can + // just #define it away. + .define("printf(...)", Some("")); if cfg!(feature = "lowmemory") { base_config.define("ECMULT_WINDOW_SIZE", Some("4")); // A low-enough value to consume negligible memory From 7a0c60edcd976bd55abf1490aa8454ef2d1a7caf Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Mon, 6 Nov 2023 14:38:49 +0000 Subject: [PATCH 3/3] secp256k1-sys: patch out checked_malloc --- secp256k1-sys/depend/secp256k1/src/util.h | 8 +++----- secp256k1-sys/depend/util.h.patch | 10 ++++++++++ secp256k1-sys/vendor-libsecp.sh | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 secp256k1-sys/depend/util.h.patch diff --git a/secp256k1-sys/depend/secp256k1/src/util.h b/secp256k1-sys/depend/secp256k1/src/util.h index 613901ef3..0835b3f32 100644 --- a/secp256k1-sys/depend/secp256k1/src/util.h +++ b/secp256k1-sys/depend/secp256k1/src/util.h @@ -145,11 +145,9 @@ static const rustsecp256k1_v0_9_0_callback default_error_callback = { #endif static SECP256K1_INLINE void *checked_malloc(const rustsecp256k1_v0_9_0_callback* cb, size_t size) { - void *ret = malloc(size); - if (ret == NULL) { - rustsecp256k1_v0_9_0_callback_call(cb, "Out of memory"); - } - return ret; + (void) cb; + (void) size; + return NULL; } #if defined(__BIGGEST_ALIGNMENT__) diff --git a/secp256k1-sys/depend/util.h.patch b/secp256k1-sys/depend/util.h.patch new file mode 100644 index 000000000..764482596 --- /dev/null +++ b/secp256k1-sys/depend/util.h.patch @@ -0,0 +1,10 @@ +148,152c148,150 +< void *ret = malloc(size); +< if (ret == NULL) { +< secp256k1_callback_call(cb, "Out of memory"); +< } +< return ret; +--- +> (void) cb; +> (void) size; +> return NULL; diff --git a/secp256k1-sys/vendor-libsecp.sh b/secp256k1-sys/vendor-libsecp.sh index e48641287..ed437fc07 100755 --- a/secp256k1-sys/vendor-libsecp.sh +++ b/secp256k1-sys/vendor-libsecp.sh @@ -97,6 +97,7 @@ echo "$SOURCE_REV" >> ./secp256k1-HEAD-revision.txt patch "$DIR/include/secp256k1.h" "./secp256k1.h.patch" patch "$DIR/src/secp256k1.c" "./secp256k1.c.patch" patch "$DIR/src/scratch_impl.h" "./scratch_impl.h.patch" +patch "$DIR/src/util.h" "./util.h.patch" # Fix a linking error while cross-compiling to windowns with mingw patch "$DIR/contrib/lax_der_parsing.c" "./lax_der_parsing.c.patch"