elements: fix enable-elements-abi=no build
What changed, and why it matters
This commit fixes compilation errors that occur when libwally-core is built with Elements/Liquid sidechain support disabled (enable-elements-abi=no). It wraps Elements-only code in preprocessor guards and removes an unused variable warning. There is no direct evidence this is a security vulnerability; it is a build-configuration bug fix.
No security action required; treat as ordinary build-fix commit. If maintaining downstream builds with enable-elements-abi=no, verify the build now succeeds and regression tests pass.
Security signals we found
No security-relevant signals in commit message or diff
Build-system/conditional-compilation fix only
No memory safety, cryptographic, or input-validation changes observed
Evidence from the diff
The patch addresses non-Elements builds by: (1) guarding use of utxo->asset/value and psbt->genesis_blockhash with #ifdef BUILD_ELEMENTS in src/psbt.c; (2) marking is_elements as unused in src/tx_io.c when BUILD_ELEMENTS is not defined; and (3) restructuring wally_tx_get_input_signature_hash so it does not call wally_tx_is_elements when Elements support is disabled. These are conditional-compilation fixes, not logic changes in enabled builds.
Changed components
src/psbt.csrc/tx_io.cElements ABI disabled build configurationInspect captured patch +18 / −6
diff --git a/src/psbt.c b/src/psbt.c
index 8e0ab3f..d098000 100644
--- a/src/psbt.c
+++ b/src/psbt.c
@@ -4552,10 +4552,13 @@ static int get_signing_data(const struct wally_psbt *psbt,
if (utxo) {
/* Add items to maps without allocating/copying */
append_signing_data(scripts, i, utxo->script, utxo->script_len);
+#ifdef BUILD_ELEMENTS
if (assets) {
append_signing_data(assets, i, utxo->asset, utxo->asset_len);
append_signing_data(values, i, utxo->value, utxo->value_len);
- } else {
+ } else
+#endif
+ {
append_signing_data(values, i, (unsigned char*)&utxo->satoshi,
sizeof(utxo->satoshi));
}
@@ -4612,7 +4615,11 @@ int wally_psbt_get_input_signature_hash(struct wally_psbt *psbt, size_t index,
&scripts, assets_p, &values,
script, script_len,
0, WALLY_NO_CODESEPARATOR, NULL, 0,
+#ifdef BUILD_ELEMENTS
psbt->genesis_blockhash, sizeof(psbt->genesis_blockhash),
+#else
+ NULL, 0,
+#endif
sighash, sighash_type,
psbt->signing_cache, bytes_out, len);
diff --git a/src/tx_io.c b/src/tx_io.c
index edf19e1..77b4959 100644
--- a/src/tx_io.c
+++ b/src/tx_io.c
@@ -564,6 +564,9 @@ static void txio_hash_tapleaf_hash(cursor_io *io,
bool is_elements)
{
const struct wally_map_item *item;
+#ifndef BUILD_ELEMENTS
+ (void)is_elements;
+#endif
item = io->cache ? wally_map_get(io->cache, tapleaf_script, tapleaf_script_len) : NULL;
if (item) {
hash_bytes(&io->ctx, item->value, item->value_len);
@@ -594,6 +597,9 @@ static int legacy_signature_hash(
const bool sh_none = (sighash & WALLY_SIGHASH_MASK) == WALLY_SIGHASH_NONE;
const bool sh_single = (sighash & WALLY_SIGHASH_MASK) == WALLY_SIGHASH_SINGLE;
cursor_io io;
+#ifndef BUILD_ELEMENTS
+ (void)is_elements;
+#endif
/* Note that script can be empty, so we don't check it here */
if (!tx || !values || BYTES_INVALID(script, script_len) ||
@@ -964,7 +970,6 @@ int wally_tx_get_input_signature_hash(
{
size_t is_elements = 0;
uint32_t sighash_type = flags & WALLY_SIGTYPE_MASK;
- int ret = WALLY_EINVAL;
if (!tx || !tx->num_inputs || !tx->num_outputs || !values ||
BYTES_INVALID(script, script_len) || key_version > 1 ||
@@ -974,11 +979,11 @@ int wally_tx_get_input_signature_hash(
!flags || (flags & ~SIGTYPE_ALL) || !bytes_out || len != SHA256_LEN)
return WALLY_EINVAL;
- if ((ret = wally_tx_is_elements(tx, &is_elements)) != WALLY_OK)
- return ret;
-#ifndef BUILD_ELEMENTS
- if (is_elements)
+#ifdef BUILD_ELEMENTS
+ if (wally_tx_is_elements(tx, &is_elements) != WALLY_OK)
return WALLY_EINVAL;
+#else
+ (void)is_elements;
#endif
switch (sighash) {
Why this scored 19/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.