Skip to content

Commit fa965a9

Browse files
committed
abi: force users to explicitly opt-out of exporting Elements functions (2)
Part 2, source changes, move psbt_blind into the elements ABI, regenerate wrappers.
1 parent 6d64846 commit fa965a9

13 files changed

+580
-212
lines changed

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,12 @@ $ brew install swig
8080
interface. After building, see `src/swig_java/src/com/blockstream/libwally/Wally.java`
8181
for the Java interface definition (default: no).
8282
- `--disable-elements`. Disables support for [Elements](https://elementsproject.org/)
83-
features, including [Liquid](https://blockstream.com/liquid/) support (default: no).
84-
Note that to use Elements API calls from C/C++, the caller must define `BUILD_ELEMENTS`
85-
when including the wally header files.
86-
- `--disable-elements-abi`. Ensures that exposed library structures maintain the same ABI
87-
regardless of `--disable-elements`. If disabled, elements support must be disabled and
88-
the user must define `WALLY_ABI_NO_ELEMENTS` before including all wally header files.
89-
This option *must be set if wally is being installed as a system/shared library*. (default: no).
83+
features, including [Liquid](https://blockstream.com/liquid/) support. Elements
84+
functions exported by the library will always return WALLY_ERROR (default: no).
85+
- `--disable-elements-abi`. Changes the exposed library ABI to completely remove Elements
86+
structure members and exported functions. When configured, elements support must be
87+
disabled and the user must define `WALLY_ABI_NO_ELEMENTS` before including all wally
88+
header files. This option *must not be given if wally is being installed as a system/shared library*. (default: no).
9089
- `--enabled-standard-secp`. Excludes support for features that are unavailable in
9190
the standard [libsecp256k1 library](https://github.com/bitcoin-core/secp256k1).
9291
- `--enable-mbed-tls`. Use mbed-tls hashing functions if available. This typically
@@ -97,10 +96,10 @@ $ brew install swig
9796
need [lcov](http://ltp.sourceforge.net/coverage/lcov.php) installed to
9897
build with this option enabled and generate coverage reports.
9998
- `--disable-shared`. Disables building a shared library and builds a static
100-
library instead.
101-
- `--disable-tests`. Disables building library tests.
99+
library instead. (default: no)
100+
- `--disable-tests`. Disables building library tests. (default: no)
102101
- `--disable-clear-tests`. Disables just the test_clear test (required to pass
103-
the test suite with some compilers).
102+
the test suite with some compilers). (default: no)
104103

105104
### Recommended development configure options
106105

include/wally.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,18 +1150,6 @@ inline int psbt_add_tx_output_at(const PSBT& psbt, uint32_t index, uint32_t flag
11501150
return detail::check_ret(__FUNCTION__, ret);
11511151
}
11521152

1153-
template <class PSBT, class VALUES, class VBFS, class ASSETS, class ABFS, class ENTROPY>
1154-
inline int psbt_blind(const PSBT& psbt, const VALUES& values, const VBFS& vbfs, const ASSETS& assets, const ABFS& abfs, const ENTROPY& entropy, uint32_t output_index, uint32_t flags, struct wally_map* output) {
1155-
int ret = ::wally_psbt_blind(detail::get_p(psbt), detail::get_p(values), detail::get_p(vbfs), detail::get_p(assets), detail::get_p(abfs), entropy.data(), entropy.size(), output_index, flags, output);
1156-
return detail::check_ret(__FUNCTION__, ret);
1157-
}
1158-
1159-
template <class PSBT, class VALUES, class VBFS, class ASSETS, class ABFS, class ENTROPY>
1160-
inline int psbt_blind_alloc(const PSBT& psbt, const VALUES& values, const VBFS& vbfs, const ASSETS& assets, const ABFS& abfs, const ENTROPY& entropy, uint32_t output_index, uint32_t flags, struct wally_map** output) {
1161-
int ret = ::wally_psbt_blind_alloc(detail::get_p(psbt), detail::get_p(values), detail::get_p(vbfs), detail::get_p(assets), detail::get_p(abfs), entropy.data(), entropy.size(), output_index, flags, output);
1162-
return detail::check_ret(__FUNCTION__, ret);
1163-
}
1164-
11651153
inline int psbt_clear_fallback_locktime(struct wally_psbt* psbt) {
11661154
int ret = ::wally_psbt_clear_fallback_locktime(psbt);
11671155
return detail::check_ret(__FUNCTION__, ret);
@@ -2349,6 +2337,18 @@ inline int psbt_add_global_scalar(const PSBT& psbt, const SCALAR& scalar) {
23492337
return detail::check_ret(__FUNCTION__, ret);
23502338
}
23512339

2340+
template <class PSBT, class VALUES, class VBFS, class ASSETS, class ABFS, class ENTROPY>
2341+
inline int psbt_blind(const PSBT& psbt, const VALUES& values, const VBFS& vbfs, const ASSETS& assets, const ABFS& abfs, const ENTROPY& entropy, uint32_t output_index, uint32_t flags, struct wally_map* output) {
2342+
int ret = ::wally_psbt_blind(detail::get_p(psbt), detail::get_p(values), detail::get_p(vbfs), detail::get_p(assets), detail::get_p(abfs), entropy.data(), entropy.size(), output_index, flags, output);
2343+
return detail::check_ret(__FUNCTION__, ret);
2344+
}
2345+
2346+
template <class PSBT, class VALUES, class VBFS, class ASSETS, class ABFS, class ENTROPY>
2347+
inline int psbt_blind_alloc(const PSBT& psbt, const VALUES& values, const VBFS& vbfs, const ASSETS& assets, const ABFS& abfs, const ENTROPY& entropy, uint32_t output_index, uint32_t flags, struct wally_map** output) {
2348+
int ret = ::wally_psbt_blind_alloc(detail::get_p(psbt), detail::get_p(values), detail::get_p(vbfs), detail::get_p(assets), detail::get_p(abfs), entropy.data(), entropy.size(), output_index, flags, output);
2349+
return detail::check_ret(__FUNCTION__, ret);
2350+
}
2351+
23522352
template <class PSBT, class SCALAR>
23532353
inline int psbt_find_global_scalar(const PSBT& psbt, const SCALAR& scalar, size_t* written) {
23542354
int ret = ::wally_psbt_find_global_scalar(detail::get_p(psbt), scalar.data(), scalar.size(), written);

include/wally_psbt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,6 +2419,7 @@ WALLY_CORE_API int wally_psbt_clone_alloc(
24192419
uint32_t flags,
24202420
struct wally_psbt **output);
24212421

2422+
#ifndef WALLY_ABI_NO_ELEMENTS
24222423
/**
24232424
* Blind a PSBT.
24242425
*
@@ -2464,6 +2465,7 @@ WALLY_CORE_API int wally_psbt_blind_alloc(
24642465
uint32_t output_index,
24652466
uint32_t flags,
24662467
struct wally_map **output);
2468+
#endif /* WALLY_ABI_NO_ELEMENTS */
24672469

24682470
/**
24692471
* Sign PSBT inputs corresponding to a given private key.

src/bip32.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -837,13 +837,16 @@ int bip32_key_from_parent_path_alloc(const struct ext_key *hdkey,
837837
return ret;
838838
}
839839

840-
#ifdef BUILD_ELEMENTS
840+
#ifndef WALLY_ABI_NO_ELEMENTS
841841
int bip32_key_with_tweak_from_parent_path(const struct ext_key *hdkey,
842842
const uint32_t *child_path,
843843
size_t child_path_len,
844844
uint32_t flags,
845845
struct ext_key *output)
846846
{
847+
#ifndef BUILD_ELEMENTS
848+
return WALLY_ERROR;
849+
#else
847850
const secp256k1_context *ctx;
848851
secp256k1_pubkey pub_key;
849852
size_t len = EC_PUBLIC_KEY_LEN;
@@ -865,13 +868,17 @@ int bip32_key_with_tweak_from_parent_path(const struct ext_key *hdkey,
865868
return wipe_key_fail(output);
866869

867870
return WALLY_OK;
871+
#endif /* BUILD_ELEMENTS */
868872
}
869873

870874
int bip32_key_with_tweak_from_parent_path_alloc(const struct ext_key *hdkey,
871875
const uint32_t *child_path, size_t child_path_len,
872876
uint32_t flags,
873877
struct ext_key **output)
874878
{
879+
#ifndef BUILD_ELEMENTS
880+
return WALLY_ERROR;
881+
#else
875882
int ret;
876883

877884
ALLOC_KEY();
@@ -882,8 +889,9 @@ int bip32_key_with_tweak_from_parent_path_alloc(const struct ext_key *hdkey,
882889
*output = NULL;
883890
}
884891
return ret;
885-
}
886892
#endif /* BUILD_ELEMENTS */
893+
}
894+
#endif /* WALLY_ABI_NO_ELEMENTS */
887895

888896
int bip32_key_from_parent_path_str_n(const struct ext_key *hdkey,
889897
const char *str, size_t str_len,
@@ -1137,9 +1145,15 @@ GET_B(chain_code)
11371145
GET_B(parent160)
11381146
GET_B(hash160)
11391147
GET_B(pub_key)
1140-
#ifdef BUILD_ELEMENTS
1148+
#ifndef WALLY_ABI_NO_ELEMENTS
1149+
#ifndef BUILD_ELEMENTS
1150+
int bip32_key_get_pub_key_tweak_sum(const struct ext_key *hdkey, unsigned char *bytes_out, size_t len) {
1151+
return WALLY_ERROR;
1152+
}
1153+
#else
11411154
GET_B(pub_key_tweak_sum)
11421155
#endif /* BUILD_ELEMENTS */
1156+
#endif /* WALLY_ABI_NO_ELEMENTS */
11431157

11441158
int bip32_key_get_priv_key(const struct ext_key *hdkey, unsigned char *bytes_out, size_t len) {
11451159
return getb_impl(hdkey, hdkey->priv_key + 1, sizeof(hdkey->priv_key) - 1, bytes_out, len);

src/bip32_int.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ WALLY_CORE_API int bip32_key_get_hash160(const struct ext_key *hdkey, unsigned c
3232
*/
3333
WALLY_CORE_API int bip32_key_get_pub_key(const struct ext_key *hdkey, unsigned char *bytes_out, size_t len);
3434

35-
#ifdef BUILD_ELEMENTS
35+
#ifndef WALLY_ABI_NO_ELEMENTS
3636

3737
/**
3838
* FIXED_SIZED_OUTPUT(len, bytes_out, WALLY_BIP32_TWEAK_SUM_LEN)
3939
*/
4040
WALLY_CORE_API int bip32_key_get_pub_key_tweak_sum(const struct ext_key *hdkey, unsigned char *bytes_out, size_t len);
4141

42-
#endif /* BUILD_ELEMENTS */
42+
#endif /* WALLY_ABI_NO_ELEMENTS */
4343

4444
WALLY_CORE_API int bip32_key_get_depth(const struct ext_key *hdkey, size_t *written);
4545
WALLY_CORE_API int bip32_key_get_child_num(const struct ext_key *hdkey, size_t *written);

src/blech32.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "script.h"
2828

2929
#ifdef BUILD_ELEMENTS
30-
3130
#define CHECKSUM_BLECH32 0x1
3231
#define CHECKSUM_BLECH32M 0x455972a3350f7a1ull
3332

@@ -208,13 +207,18 @@ static int blech32_addr_decode(uint8_t *witver, uint8_t *witdata, size_t *witdat
208207
wally_clear_2(data, sizeof(data), hrp_actual, sizeof(hrp_actual));
209208
return 0;
210209
}
210+
#endif /* BUILD_ELEMENTS */
211211

212+
#ifndef WALLY_ABI_NO_ELEMENTS
212213
int wally_confidential_addr_to_addr_segwit(
213214
const char *address,
214215
const char *confidential_addr_family,
215216
const char *addr_family,
216217
char **output)
217218
{
219+
#ifndef BUILD_ELEMENTS
220+
return WALLY_ERROR;
221+
#else
218222
unsigned char buf[WALLY_BLECH32_MAXLEN];
219223
unsigned char *hash_bytes_p = &buf[EC_PUBLIC_KEY_LEN - 2];
220224
size_t written = 0;
@@ -241,6 +245,7 @@ int wally_confidential_addr_to_addr_segwit(
241245

242246
wally_clear(buf, sizeof(buf));
243247
return ret;
248+
#endif /* BUILD_ELEMENTS */
244249
}
245250

246251
int wally_confidential_addr_segwit_to_ec_public_key(
@@ -249,6 +254,9 @@ int wally_confidential_addr_segwit_to_ec_public_key(
249254
unsigned char *bytes_out,
250255
size_t len)
251256
{
257+
#ifndef BUILD_ELEMENTS
258+
return WALLY_ERROR;
259+
#else
252260
unsigned char buf[WALLY_BLECH32_MAXLEN];
253261
size_t written = 0;
254262
int ret = WALLY_OK;
@@ -266,6 +274,7 @@ int wally_confidential_addr_segwit_to_ec_public_key(
266274

267275
wally_clear(buf, sizeof(buf));
268276
return ret;
277+
#endif /* BUILD_ELEMENTS */
269278
}
270279

271280
int wally_confidential_addr_from_addr_segwit(
@@ -276,6 +285,9 @@ int wally_confidential_addr_from_addr_segwit(
276285
size_t pub_key_len,
277286
char **output)
278287
{
288+
#ifndef BUILD_ELEMENTS
289+
return WALLY_ERROR;
290+
#else
279291
char result[WALLY_BLECH32_MAXLEN + 1];
280292
unsigned char buf[EC_PUBLIC_KEY_LEN + SHA256_LEN];
281293
unsigned char *hash_bytes_p = &buf[EC_PUBLIC_KEY_LEN - 2];
@@ -320,6 +332,6 @@ int wally_confidential_addr_from_addr_segwit(
320332
wally_clear(buf, sizeof(buf));
321333
wally_clear(result, sizeof(result));
322334
return ret;
323-
}
324-
325335
#endif /* BUILD_ELEMENTS */
336+
}
337+
#endif /* WALLY_ABI_NO_ELEMENTS */

0 commit comments

Comments
 (0)