Skip to content

Commit

Permalink
untested: fix the commit-to-no-taptree musig implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
instagibbs committed Feb 21, 2023
1 parent 9dfb3ef commit 23278da
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 16 additions & 11 deletions bitcoin/signature.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ void bipmusig_finalize_keys(struct pubkey *agg_pk,
int i, ok;
unsigned char taptweak_preimage[64];
secp256k1_xonly_pubkey agg_x_key;
struct pubkey tmp_inner_pubkey;
size_t key_len = 33;
assert(n_pubkeys <= 100);

/* Sorting moves pubkeys themselves, we copy and discard after */
Expand Down Expand Up @@ -244,26 +246,29 @@ void bipmusig_finalize_keys(struct pubkey *agg_pk,

assert(ok);

if (inner_pubkey) {
ok = secp256k1_musig_pubkey_get(secp256k1_ctx,
&inner_pubkey->pubkey,
keyagg_cache);
ok = secp256k1_musig_pubkey_get(secp256k1_ctx,
&tmp_inner_pubkey.pubkey,
keyagg_cache);

assert(ok);
}

ok = secp256k1_xonly_pubkey_serialize(secp256k1_ctx, taptweak_preimage, &agg_x_key);
assert(ok);

assert(ok);
if (inner_pubkey) {
*inner_pubkey = tmp_inner_pubkey;
}

if (!tap_merkle_root) {
/* No-tapscript recommended commitment: Q = P + int(hashTapTweak(bytes(P)))G */
ok = wally_tagged_hash(taptweak_preimage, 32, "TapTweak", tap_tweak_out);
ok = secp256k1_ec_pubkey_serialize(secp256k1_ctx, taptweak_preimage, &key_len, &tmp_inner_pubkey.pubkey, SECP256K1_EC_COMPRESSED);
assert(key_len == 33);
ok = wally_tagged_hash(taptweak_preimage, key_len, "TapTweak", tap_tweak_out);
assert(ok == WALLY_OK);
ok = secp256k1_musig_pubkey_xonly_tweak_add(secp256k1_ctx, &(agg_pk->pubkey), keyagg_cache, tap_tweak_out);
assert(ok);
} else {
/* Otherwise: Q = P + int(hashTapTweak(bytes(P)||tap_merkle_root))G */
ok = secp256k1_xonly_pubkey_serialize(secp256k1_ctx, taptweak_preimage, &agg_x_key);
assert(ok);

/* Otherwise: Q = P + int(hashTapTweak(p||tap_merkle_root))G */
memcpy(taptweak_preimage + 32, tap_merkle_root->u.u8, sizeof(tap_merkle_root->u.u8));
ok = wally_tagged_hash(taptweak_preimage, sizeof(taptweak_preimage), "TapTweak", tap_tweak_out);
assert(ok == WALLY_OK);
Expand Down
2 changes: 2 additions & 0 deletions tests/test_eltoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def test_eltoo_base_reestablishment(node_factory, bitcoind):
l1.daemon.wait_for_log('Reconnected, and reestablished')
l2.daemon.wait_for_log('Reconnected, and reestablished')

from pdb import set_trace
set_trace()
l1_update_tx = l1.rpc.listpeers(l2.info['id'])["peers"][0]["channels"][0]['last_update_tx']
l1_settle_tx = l1.rpc.listpeers(l2.info['id'])["peers"][0]["channels"][0]['last_settle_tx']

Expand Down

0 comments on commit 23278da

Please sign in to comment.