Skip to content

Commit 6d64846

Browse files
committed
abi: force users to explicitly opt-out of exporting Elements functions (1)
Part 1, header changes. As with the previous c-struct change, by default Elements is enabled and elements functions are exported from the library. Using --disable-elements now leaves the Elements functions available, but calling them will always return WALLY_ERROR. This behaviour allows installing a system-wide wally built without Elements support which applications can gracefully detect at runtime via wally_is_elements_build() and handle by degrading functionality or failing to start. To compile the Elements functions out completely, the user must configure with --disable-elements-abi and define WALLY_ABI_NO_ELEMENTS when including library headers. This allows e.g. embeddeded/static builds to eliminate all Elements code entirely. As before, WALLY_ABI_NO_ELEMENTS builds must not be installed as system-wide shared libraries. Doing so may result in either memory corruption at runtime (if no Elements code is used) or linker errors on startup due to missing Elements calls.
1 parent 517fc70 commit 6d64846

10 files changed

+38
-33
lines changed

include/wally_address.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ WALLY_CORE_API int wally_wif_to_address(
274274
uint32_t version,
275275
char **output);
276276

277-
#ifdef BUILD_ELEMENTS
277+
#ifndef WALLY_ABI_NO_ELEMENTS
278278
/**
279279
* Extract the address from a confidential address.
280280
*
@@ -366,7 +366,7 @@ WALLY_CORE_API int wally_confidential_addr_from_addr_segwit(
366366
const unsigned char *pub_key,
367367
size_t pub_key_len,
368368
char **output);
369-
#endif /* BUILD_ELEMENTS */
369+
#endif /* WALLY_ABI_NO_ELEMENTS */
370370

371371
#ifdef __cplusplus
372372
}

include/wally_bip32.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ WALLY_CORE_API int bip32_key_from_parent_path_str_n_alloc(
360360
uint32_t flags,
361361
struct ext_key **output);
362362

363-
#ifdef BUILD_ELEMENTS
363+
#ifndef WALLY_ABI_NO_ELEMENTS
364364
/**
365365
* Derive the pub tweak from a parent extended key and a path.
366366
*
@@ -387,7 +387,7 @@ WALLY_CORE_API int bip32_key_with_tweak_from_parent_path_alloc(
387387
size_t child_path_len,
388388
uint32_t flags,
389389
struct ext_key **output);
390-
#endif /* BUILD_ELEMENTS */
390+
#endif /* WALLY_ABI_NO_ELEMENTS */
391391

392392
/**
393393
* Convert an extended key to base58.

include/wally_coinselection.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extern "C" {
1010
/** The maximum number of asset values that can be returned in a coin selection */
1111
#define WALLY_CS_MAX_ASSETS 256
1212

13-
#ifdef BUILD_ELEMENTS
13+
#ifndef WALLY_ABI_NO_ELEMENTS
1414

1515
/**
1616
* Select input asset values to meet a given payment target.
@@ -47,7 +47,7 @@ WALLY_CORE_API int wally_coinselect_assets(
4747
size_t indices_out_len,
4848
size_t *written);
4949

50-
#endif /* BUILD_ELEMENTS */
50+
#endif /* WALLY_ABI_NO_ELEMENTS */
5151

5252
#ifdef __cplusplus
5353
}

include/wally_elements.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
extern "C" {
88
#endif
99

10-
#ifdef BUILD_ELEMENTS
11-
1210
#define ASSET_TAG_LEN 32 /** Length of an Asset Tag */
1311

1412
#define BLINDING_FACTOR_LEN 32 /** Length of a Blinding Factor (or blinder) */
@@ -24,6 +22,7 @@ extern "C" {
2422
#define ASSET_SURJECTIONPROOF_MAX_LEN 162 /** Maximum length of a wally-produced Asset Surjection Proof */
2523
#define ASSET_EXPLICIT_SURJECTIONPROOF_LEN 67 /** Length of an Explicit Asset Surjection Proof */
2624

25+
#ifndef WALLY_ABI_NO_ELEMENTS
2726
/**
2827
* Create an Asset Generator from an either an asset commitment or asset tag plus blinding factor.
2928
*
@@ -657,7 +656,7 @@ WALLY_CORE_API int wally_asset_pak_whitelistproof_len(
657656
size_t summed_key_len,
658657
size_t *written);
659658

660-
#endif /* BUILD_ELEMENTS */
659+
#endif /* WALLY_ABI_NO_ELEMENTS */
661660

662661
#ifdef __cplusplus
663662
}

include/wally_psbt.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ WALLY_CORE_API int wally_psbt_input_set_required_lockheight(
453453
WALLY_CORE_API int wally_psbt_input_clear_required_lockheight(
454454
struct wally_psbt_input *input);
455455

456-
#ifdef BUILD_ELEMENTS
456+
#ifndef WALLY_ABI_NO_ELEMENTS
457457
/**
458458
* Set the unblinded amount in an input.
459459
*
@@ -1254,7 +1254,7 @@ WALLY_CORE_API int wally_psbt_input_generate_explicit_proofs(
12541254
size_t vbf_len,
12551255
const unsigned char *entropy,
12561256
size_t entropy_len);
1257-
#endif /* BUILD_ELEMENTS */
1257+
#endif /* WALLY_ABI_NO_ELEMENTS */
12581258

12591259
/**
12601260
* Determine if a PSBT input is finalized.
@@ -1416,7 +1416,7 @@ WALLY_CORE_API int wally_psbt_output_set_script(
14161416
const unsigned char *script,
14171417
size_t script_len);
14181418

1419-
#ifdef BUILD_ELEMENTS
1419+
#ifndef WALLY_ABI_NO_ELEMENTS
14201420
/**
14211421
* Set the input blinder index in an output.
14221422
*
@@ -1875,7 +1875,7 @@ WALLY_CORE_API int wally_psbt_output_get_blinding_status(
18751875
const struct wally_psbt_output *output,
18761876
uint32_t flags,
18771877
size_t *written);
1878-
#endif /* BUILD_ELEMENTS */
1878+
#endif /* WALLY_ABI_NO_ELEMENTS */
18791879

18801880
/**
18811881
* Allocate and initialize a new PSBT.
@@ -2037,7 +2037,7 @@ WALLY_CORE_API int wally_psbt_set_tx_modifiable_flags(
20372037
struct wally_psbt *psbt,
20382038
uint32_t flags);
20392039

2040-
#ifdef BUILD_ELEMENTS
2040+
#ifndef WALLY_ABI_NO_ELEMENTS
20412041
/**
20422042
* Set the scalar offsets in a PSBT.
20432043
*
@@ -2084,7 +2084,7 @@ WALLY_CORE_API int wally_psbt_find_global_scalar(
20842084
WALLY_CORE_API int wally_psbt_set_pset_modifiable_flags(
20852085
struct wally_psbt *psbt,
20862086
uint32_t flags);
2087-
#endif /* BUILD_ELEMENTS */
2087+
#endif /* WALLY_ABI_NO_ELEMENTS */
20882088

20892089
/**
20902090
* Find the index of the PSBT input that spends a given UTXO.

include/wally_psbt_members.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ WALLY_CORE_API int wally_psbt_get_num_outputs(const struct wally_psbt *psbt, siz
1616
WALLY_CORE_API int wally_psbt_get_fallback_locktime(const struct wally_psbt *psbt, size_t *written);
1717
WALLY_CORE_API int wally_psbt_has_fallback_locktime(const struct wally_psbt *psbt, size_t *written);
1818
WALLY_CORE_API int wally_psbt_get_tx_modifiable_flags(const struct wally_psbt *psbt, size_t *written);
19-
#ifdef BUILD_ELEMENTS
19+
#ifndef WALLY_ABI_NO_ELEMENTS
2020
WALLY_CORE_API int wally_psbt_get_global_scalars_size(const struct wally_psbt *psbt, size_t *written);
2121

2222
/**
@@ -25,7 +25,7 @@ WALLY_CORE_API int wally_psbt_get_global_scalars_size(const struct wally_psbt *p
2525
WALLY_CORE_API int wally_psbt_get_global_scalar(const struct wally_psbt *psbt, size_t index, unsigned char *bytes_out, size_t len);
2626

2727
WALLY_CORE_API int wally_psbt_get_pset_modifiable_flags(const struct wally_psbt *psbt, size_t *written);
28-
#endif /* BUILD_ELEMENTS */
28+
#endif /* WALLY_ABI_NO_ELEMENTS */
2929

3030
/* Inputs */
3131
WALLY_CORE_API int wally_psbt_get_input_utxo_alloc(const struct wally_psbt *psbt, size_t index, struct wally_tx **output);
@@ -92,7 +92,7 @@ WALLY_CORE_API int wally_psbt_has_input_required_locktime(const struct wally_psb
9292
WALLY_CORE_API int wally_psbt_set_input_required_lockheight(struct wally_psbt *psbt, size_t index, uint32_t lockheight);
9393
WALLY_CORE_API int wally_psbt_clear_input_required_lockheight(struct wally_psbt *psbt, size_t index);
9494
WALLY_CORE_API int wally_psbt_has_input_required_lockheight(const struct wally_psbt *psbt, size_t index, size_t *written);
95-
#ifdef BUILD_ELEMENTS
95+
#ifndef WALLY_ABI_NO_ELEMENTS
9696
WALLY_CORE_API int wally_psbt_get_input_amount(const struct wally_psbt *psbt, size_t index, uint64_t *value_out);
9797
WALLY_CORE_API int wally_psbt_get_input_amount_rangeproof(const struct wally_psbt *psbt, size_t index, unsigned char *bytes_out, size_t len, size_t *written);
9898
WALLY_CORE_API int wally_psbt_get_input_amount_rangeproof_len(const struct wally_psbt *psbt, size_t index, size_t *written);
@@ -164,7 +164,7 @@ WALLY_CORE_API int wally_psbt_clear_input_inflation_keys_blinding_rangeproof(str
164164
WALLY_CORE_API int wally_psbt_set_input_utxo_rangeproof(struct wally_psbt *psbt, size_t index, const unsigned char *rangeproof, size_t rangeproof_len);
165165
WALLY_CORE_API int wally_psbt_clear_input_utxo_rangeproof(struct wally_psbt *psbt, size_t index);
166166
WALLY_CORE_API int wally_psbt_generate_input_explicit_proofs(struct wally_psbt *psbt, size_t index, uint64_t satoshi, const unsigned char *asset, size_t asset_len, const unsigned char *abf, size_t abf_len, const unsigned char *vbf, size_t vbf_len, const unsigned char *entropy, size_t entropy_len);
167-
#endif /* BUILD_ELEMENTS */
167+
#endif /* WALLY_ABI_NO_ELEMENTS */
168168

169169
/* Outputs */
170170
WALLY_CORE_API int wally_psbt_get_output_redeem_script(const struct wally_psbt *psbt, size_t index, unsigned char *bytes_out, size_t len, size_t *written);
@@ -192,7 +192,7 @@ WALLY_CORE_API int wally_psbt_set_output_script(struct wally_psbt *psbt, size_t
192192
WALLY_CORE_API int wally_psbt_set_output_amount(struct wally_psbt *psbt, size_t index, uint64_t amount);
193193
WALLY_CORE_API int wally_psbt_clear_output_amount(struct wally_psbt *psbt, size_t index);
194194

195-
#ifdef BUILD_ELEMENTS
195+
#ifndef WALLY_ABI_NO_ELEMENTS
196196
WALLY_CORE_API int wally_psbt_get_output_blinder_index(const struct wally_psbt *psbt, size_t index, uint32_t *value_out);
197197
WALLY_CORE_API int wally_psbt_has_output_blinder_index(const struct wally_psbt *psbt, size_t index, size_t *written);
198198
WALLY_CORE_API int wally_psbt_get_output_value_commitment(const struct wally_psbt *psbt, size_t index, unsigned char *bytes_out, size_t len, size_t *written);
@@ -236,7 +236,7 @@ WALLY_CORE_API int wally_psbt_clear_output_value_blinding_rangeproof(struct wall
236236
WALLY_CORE_API int wally_psbt_set_output_asset_blinding_surjectionproof(struct wally_psbt *psbt, size_t index, const unsigned char *surjectionproof, size_t surjectionproof_len);
237237
WALLY_CORE_API int wally_psbt_clear_output_asset_blinding_surjectionproof(struct wally_psbt *psbt, size_t index);
238238
WALLY_CORE_API int wally_psbt_get_output_blinding_status(const struct wally_psbt *output, size_t index, uint32_t flags, size_t *written);
239-
#endif /* BUILD_ELEMENTS */
239+
#endif /* WALLY_ABI_NO_ELEMENTS */
240240
#ifdef __cplusplus
241241
}
242242
#endif

include/wally_script.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ WALLY_CORE_API int wally_witness_program_from_bytes_and_version(
581581
size_t len,
582582
size_t *written);
583583

584-
#ifdef BUILD_ELEMENTS
584+
#ifndef WALLY_ABI_NO_ELEMENTS
585585
/**
586586
* Get the pegout script size.
587587
*
@@ -649,7 +649,7 @@ WALLY_CORE_API int wally_elements_pegin_contract_script_from_bytes(
649649
unsigned char *bytes_out,
650650
size_t len,
651651
size_t *written);
652-
#endif /* BUILD_ELEMENTS */
652+
#endif /* WALLY_ABI_NO_ELEMENTS */
653653

654654
#ifdef __cplusplus
655655
}

include/wally_transaction.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ WALLY_CORE_API int wally_tx_is_coinbase(
850850
const struct wally_tx *tx,
851851
size_t *written);
852852

853-
#ifdef BUILD_ELEMENTS
853+
#ifndef WALLY_ABI_NO_ELEMENTS
854854
/**
855855
* Set issuance data on an input.
856856
*
@@ -1340,7 +1340,7 @@ WALLY_CORE_API int wally_tx_elements_issuance_calculate_reissuance_token(
13401340
unsigned char *bytes_out,
13411341
size_t len);
13421342

1343-
#endif /* BUILD_ELEMENTS */
1343+
#endif /* WALLY_ABI_NO_ELEMENTS */
13441344

13451345
#ifdef __cplusplus
13461346
}

include/wally_transaction_members.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ WALLY_CORE_API int wally_tx_input_set_witness(struct wally_tx_input *tx_input, c
2727
WALLY_CORE_API int wally_tx_input_set_index(struct wally_tx_input *tx_input, uint32_t index);
2828
WALLY_CORE_API int wally_tx_input_set_sequence(struct wally_tx_input *tx_input, uint32_t sequence);
2929

30-
#ifdef BUILD_ELEMENTS
30+
#ifndef WALLY_ABI_NO_ELEMENTS
3131

3232
/**
3333
* FIXED_SIZED_OUTPUT(len, bytes_out, SHA256_LEN)
@@ -54,7 +54,7 @@ WALLY_CORE_API int wally_tx_input_set_inflation_keys(struct wally_tx_input *tx_i
5454
WALLY_CORE_API int wally_tx_input_set_inflation_keys_rangeproof(struct wally_tx_input *tx_input_in, const unsigned char *inflation_keys_rangeproof, size_t inflation_keys_rangeproof_len);
5555
WALLY_CORE_API int wally_tx_input_set_issuance_amount(struct wally_tx_input *tx_input_in, const unsigned char *issuance_amount, size_t issuance_amount_len);
5656
WALLY_CORE_API int wally_tx_input_set_issuance_amount_rangeproof(struct wally_tx_input *tx_input_in, const unsigned char *issuance_amount_rangeproof, size_t issuance_amount_rangeproof_len);
57-
#endif /* BUILD_ELEMENTS */
57+
#endif /* WALLY_ABI_NO_ELEMENTS */
5858

5959
/* Output */
6060
WALLY_CORE_API int wally_tx_output_get_script(const struct wally_tx_output *tx_output_in, unsigned char *bytes_out, size_t len, size_t *written);
@@ -64,7 +64,7 @@ WALLY_CORE_API int wally_tx_output_get_satoshi(const struct wally_tx_output *tx_
6464
WALLY_CORE_API int wally_tx_output_set_script(struct wally_tx_output *tx_output_in, const unsigned char *script, size_t script_len);
6565
WALLY_CORE_API int wally_tx_output_set_satoshi(struct wally_tx_output *tx_output_in, uint64_t satoshi);
6666

67-
#ifdef BUILD_ELEMENTS
67+
#ifndef WALLY_ABI_NO_ELEMENTS
6868
WALLY_CORE_API int wally_tx_output_get_asset(const struct wally_tx_output *tx_output_in, unsigned char *bytes_out, size_t len);
6969
WALLY_CORE_API int wally_tx_output_get_asset_len(const struct wally_tx_output *tx_output_in, size_t *written);
7070
WALLY_CORE_API int wally_tx_output_get_value(const struct wally_tx_output *tx_output_in, unsigned char *bytes_out, size_t len, size_t *written);
@@ -81,7 +81,7 @@ WALLY_CORE_API int wally_tx_output_set_value(struct wally_tx_output *tx_output_i
8181
WALLY_CORE_API int wally_tx_output_set_nonce(struct wally_tx_output *tx_output_in, const unsigned char *nonce, size_t nonce_len);
8282
WALLY_CORE_API int wally_tx_output_set_surjectionproof(struct wally_tx_output *tx_output_in, const unsigned char *surjectionproof, size_t surjectionproof_len);
8383
WALLY_CORE_API int wally_tx_output_set_rangeproof(struct wally_tx_output *tx_output_in, const unsigned char *rangeproof, size_t rangeproof_len);
84-
#endif /* BUILD_ELEMENTS */
84+
#endif /* WALLY_ABI_NO_ELEMENTS */
8585

8686
/* Transaction */
8787
WALLY_CORE_API int wally_tx_get_version(const struct wally_tx *tx_in, size_t *written);
@@ -107,7 +107,7 @@ WALLY_CORE_API int wally_tx_set_input_index(const struct wally_tx *tx_in, size_t
107107
WALLY_CORE_API int wally_tx_set_input_sequence(const struct wally_tx *tx_in, size_t index, uint32_t sequence);
108108
WALLY_CORE_API int wally_tx_set_input_txhash(const struct wally_tx *tx_in, size_t index, const unsigned char *txhash, size_t txhash_len);
109109

110-
#ifdef BUILD_ELEMENTS
110+
#ifndef WALLY_ABI_NO_ELEMENTS
111111

112112
/**
113113
* FIXED_SIZED_OUTPUT(len, bytes_out, SHA256_LEN)
@@ -134,7 +134,7 @@ WALLY_CORE_API int wally_tx_set_input_inflation_keys(const struct wally_tx *tx_i
134134
WALLY_CORE_API int wally_tx_set_input_inflation_keys_rangeproof(const struct wally_tx *tx_in, size_t index, const unsigned char *inflation_keys_rangeproof, size_t inflation_keys_rangeproof_len);
135135
WALLY_CORE_API int wally_tx_set_input_issuance_amount(const struct wally_tx *tx_in, size_t index, const unsigned char *issuance_amount, size_t issuance_amount_len);
136136
WALLY_CORE_API int wally_tx_set_input_issuance_amount_rangeproof(const struct wally_tx *tx_in, size_t index, const unsigned char *issuance_amount_rangeproof, size_t issuance_amount_rangeproof_len);
137-
#endif /* BUILD_ELEMENTS */
137+
#endif /* WALLY_ABI_NO_ELEMENTS */
138138

139139
/* Transaction Outputs */
140140
WALLY_CORE_API int wally_tx_get_output_script(const struct wally_tx *tx_in, size_t index, unsigned char *bytes_out, size_t len, size_t *written);
@@ -144,7 +144,7 @@ WALLY_CORE_API int wally_tx_get_output_satoshi(const struct wally_tx *tx_in, siz
144144
WALLY_CORE_API int wally_tx_set_output_script(const struct wally_tx *tx_in, size_t index, const unsigned char *script, size_t script_len);
145145
WALLY_CORE_API int wally_tx_set_output_satoshi(const struct wally_tx *tx_in, size_t index, uint64_t satoshi);
146146

147-
#ifdef BUILD_ELEMENTS
147+
#ifndef WALLY_ABI_NO_ELEMENTS
148148

149149
/**
150150
* FIXED_SIZED_OUTPUT(len, bytes_out, WALLY_TX_ASSET_CT_ASSET_LEN)
@@ -173,7 +173,7 @@ WALLY_CORE_API int wally_tx_set_output_value(const struct wally_tx *tx_in, size_
173173
WALLY_CORE_API int wally_tx_set_output_nonce(const struct wally_tx *tx_in, size_t index, const unsigned char *nonce, size_t nonce_len);
174174
WALLY_CORE_API int wally_tx_set_output_surjectionproof(const struct wally_tx *tx_in, size_t index, const unsigned char *surjectionproof, size_t surjectionproof_len);
175175
WALLY_CORE_API int wally_tx_set_output_rangeproof(const struct wally_tx *tx_in, size_t index, const unsigned char *rangeproof, size_t rangeproof_len);
176-
#endif /* BUILD_ELEMENTS */
176+
#endif /* WALLY_ABI_NO_ELEMENTS */
177177

178178

179179
#ifdef __cplusplus

src/internal.h

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
#define LIBWALLY_INTERNAL_H
33

44
#include <include/wally_core.h>
5+
6+
#ifdef BUILD_ELEMENTS
7+
#ifdef WALLY_ABI_NO_ELEMENTS
8+
#error "WALLY_ABI_NO_ELEMENTS cannot be defined if BUILD_ELEMENTS is defined"
9+
#endif
10+
#endif
511
#include "secp256k1/include/secp256k1.h"
612
#include "secp256k1/include/secp256k1_recovery.h"
713
#include "secp256k1/include/secp256k1_extrakeys.h"

0 commit comments

Comments
 (0)