Skip to content

Commit ee5f859

Browse files
committed
Add rule to compare musig key sets deterministically in leaf_cmp
1 parent 7b80557 commit ee5f859

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/common/cleartext.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,17 @@ static int leaf_cmp(const ct_leaf_match_t *a, const ct_leaf_match_t *b) {
514514
if (ka->type == KEY_EXPRESSION_NORMAL) {
515515
if (ka->k.key_index != kb->k.key_index)
516516
return (ka->k.key_index < kb->k.key_index) ? -1 : 1;
517+
} else {
518+
// KEY_EXPRESSION_MUSIG: order by number of keys, then
519+
// left-to-right by key index
520+
const musig_aggr_key_info_t *ma = r_musig_aggr_key_info(&ka->m.musig_info);
521+
const musig_aggr_key_info_t *mb = r_musig_aggr_key_info(&kb->m.musig_info);
522+
if (ma->n != mb->n) return (ma->n < mb->n) ? -1 : 1;
523+
const uint16_t *ia = r_uint16(&ma->key_indexes);
524+
const uint16_t *ib = r_uint16(&mb->key_indexes);
525+
for (uint16_t j = 0; j < ma->n; j++) {
526+
if (ia[j] != ib[j]) return (ia[j] < ib[j]) ? -1 : 1;
527+
}
517528
}
518529
break;
519530
}

0 commit comments

Comments
 (0)