Skip to content

Commit 49c2f29

Browse files
erickcestarirustyrussell
authored andcommitted
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 74489b5 commit 49c2f29

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

common/bolt11.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,18 @@ static const char *decode_f(struct bolt11 *b11,
388388
size_t orig_len = *field_len;
389389
const char *err;
390390

391+
/* Read version but don't commit to hash yet */
392+
err = pull_uint(NULL, &orig_data, &orig_len, &version, 5, false);
393+
if (err)
394+
return tal_fmt(b11, "f: %s", err);
395+
396+
bool is_known_version = version == 17 || version == 18 || version < 17;
397+
398+
if (!is_known_version) {
399+
return unknown_field(b11, hu5, data, field_len, 'f');
400+
}
401+
402+
/* For known versions, process with hash */
391403
err = pull_uint(hu5, data, field_len, &version, 5, false);
392404
if (err)
393405
return tal_fmt(b11, "f: %s", err);
@@ -442,13 +454,9 @@ static const char *decode_f(struct bolt11 *b11,
442454
fallback = scriptpubkey_witness_raw(b11, version,
443455
f, tal_count(f));
444456
} else {
445-
/* BOLT #11:
446-
* - MUST skip over `f` fields that use an unknown `version`.
447-
*/
448-
/* Restore version for unknown field! */
449-
*data = orig_data;
450-
*field_len = orig_len;
451-
return unknown_field(b11, hu5, data, field_len, 'f');
457+
// This should be unreachable because all valid versions (17, 18, or <17)
458+
// and invalid versions are caught above.
459+
return tal_fmt(b11, "f: unknown version %"PRIu64, version);
452460
}
453461

454462
if (b11->fallbacks == NULL)

0 commit comments

Comments
 (0)