Skip to content

Commit 8848b69

Browse files
committed
common/bolt11: Fix BOLT11 hash calculation for unknown fallback address versions
Changelog-Fixed: Fixed hash calculation inconsistency when processing invoices with unknown fallback address versions.
1 parent b97278f commit 8848b69

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

common/bolt11.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,18 @@ static const char *decode_f(struct bolt11 *b11,
375375
size_t orig_len = *field_len;
376376
const char *err;
377377

378+
/* Read version but don't commit to hash yet */
379+
err = pull_uint(NULL, &orig_data, &orig_len, &version, 5);
380+
if (err)
381+
return tal_fmt(b11, "f: %s", err);
382+
383+
bool is_known_version = version == 17 || version == 18 || version < 17;
384+
385+
if (!is_known_version) {
386+
return unknown_field(b11, hu5, data, field_len, 'f');
387+
}
388+
389+
/* For known versions, process with hash */
378390
err = pull_uint(hu5, data, field_len, &version, 5);
379391
if (err)
380392
return tal_fmt(b11, "f: %s", err);
@@ -429,10 +441,9 @@ static const char *decode_f(struct bolt11 *b11,
429441
fallback = scriptpubkey_witness_raw(b11, version,
430442
f, tal_count(f));
431443
} else {
432-
/* Restore version for unknown field! */
433-
*data = orig_data;
434-
*field_len = orig_len;
435-
return unknown_field(b11, hu5, data, field_len, 'f');
444+
// This should be unreachable because all valid versions (17, 18, or <17)
445+
// and invalid versions are caught above.
446+
return tal_fmt(b11, "f: unknown version %"PRIu64, version);
436447
}
437448

438449
if (b11->fallbacks == NULL)
@@ -1372,4 +1383,4 @@ char *bolt11_encode_(const tal_t *ctx,
13721383
output = tal_free(output);
13731384

13741385
return output;
1375-
}
1386+
}

0 commit comments

Comments
 (0)