Browse Source

lnbase: verify commitment tx'es again

dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
Janus 7 years ago
committed by ThomasV
parent
commit
2e23ecb3ca
  1. 37
      lib/lnbase.py
  2. 4
      lib/tests/test_lnbase_online.py

37
lib/lnbase.py

@ -1005,7 +1005,10 @@ class Peer(PrintError):
nonlocal chan nonlocal chan
last_small_num = chan.local_state.ctn last_small_num = chan.local_state.ctn
next_small_num = last_small_num + 2 next_small_num = last_small_num + 2
this_small_num = last_small_num + 1
last_secret = get_per_commitment_secret_from_seed(chan.local_state.per_commitment_secret_seed, 2**48-last_small_num-1) last_secret = get_per_commitment_secret_from_seed(chan.local_state.per_commitment_secret_seed, 2**48-last_small_num-1)
this_secret = get_per_commitment_secret_from_seed(chan.local_state.per_commitment_secret_seed, 2**48-this_small_num-1)
this_point = secret_to_pubkey(int.from_bytes(this_secret, 'big'))
next_secret = get_per_commitment_secret_from_seed(chan.local_state.per_commitment_secret_seed, 2**48-next_small_num-1) next_secret = get_per_commitment_secret_from_seed(chan.local_state.per_commitment_secret_seed, 2**48-next_small_num-1)
next_point = secret_to_pubkey(int.from_bytes(next_secret, 'big')) next_point = secret_to_pubkey(int.from_bytes(next_secret, 'big'))
chan = chan._replace( chan = chan._replace(
@ -1013,7 +1016,7 @@ class Peer(PrintError):
ctn=chan.local_state.ctn + 1 ctn=chan.local_state.ctn + 1
) )
) )
return last_secret, next_point return last_secret, this_point, next_point
their_revstore = chan.remote_state.revocation_store their_revstore = chan.remote_state.revocation_store
@ -1031,12 +1034,12 @@ class Peer(PrintError):
assert amount_msat // 1000 == expected_received_sat assert amount_msat // 1000 == expected_received_sat
payment_hash = htlc["payment_hash"] payment_hash = htlc["payment_hash"]
last_secret, next_point = derive_and_incr() last_secret, this_point, next_point = derive_and_incr()
remote_htlc_pubkey = derive_pubkey(chan.remote_config.htlc_basepoint.pubkey, next_point) remote_htlc_pubkey = derive_pubkey(chan.remote_config.htlc_basepoint.pubkey, this_point)
local_htlc_pubkey = derive_pubkey(chan.local_config.htlc_basepoint.pubkey, next_point) local_htlc_pubkey = derive_pubkey(chan.local_config.htlc_basepoint.pubkey, this_point)
remote_revocation_pubkey = derive_blinded_pubkey(chan.remote_config.revocation_basepoint.pubkey, next_point) remote_revocation_pubkey = derive_blinded_pubkey(chan.remote_config.revocation_basepoint.pubkey, this_point)
htlcs_in_local = [ htlcs_in_local = [
( (
@ -1045,29 +1048,29 @@ class Peer(PrintError):
) )
] ]
new_commitment = make_commitment_using_open_channel(chan, chan.local_state.ctn, True, next_point, new_commitment = make_commitment_using_open_channel(chan, chan.local_state.ctn, True, this_point,
chan.local_state.amount_sat, chan.local_state.amount_sat,
chan.remote_state.amount_sat - expected_received_sat, chan.remote_state.amount_sat - expected_received_sat,
htlcs_in_local) htlcs_in_local)
preimage_hex = new_commitment.serialize_preimage(0) preimage_hex = new_commitment.serialize_preimage(0)
pre_hash = bitcoin.Hash(bfh(preimage_hex)) pre_hash = bitcoin.Hash(bfh(preimage_hex))
#if not bitcoin.verify_signature(chan.remote_config.multisig_key.pubkey, commitment_signed_msg["signature"], pre_hash): if not bitcoin.verify_signature(chan.remote_config.multisig_key.pubkey, commitment_signed_msg["signature"], pre_hash):
# raise Exception('failed verifying signature of our updated commitment transaction') raise Exception('failed verifying signature of our updated commitment transaction')
htlc_sigs_len = len(commitment_signed_msg["htlc_signature"]) htlc_sigs_len = len(commitment_signed_msg["htlc_signature"])
#if htlc_sigs_len != 64: if htlc_sigs_len != 64:
# raise Exception("unexpected number of htlc signatures: " + str(htlc_sigs_len)) raise Exception("unexpected number of htlc signatures: " + str(htlc_sigs_len))
htlc_tx = make_htlc_tx_with_open_channel(chan, next_point, True, True, amount_msat, cltv_expiry, payment_hash, new_commitment, 0) htlc_tx = make_htlc_tx_with_open_channel(chan, this_point, True, True, amount_msat, cltv_expiry, payment_hash, new_commitment, 0)
pre_hash = bitcoin.Hash(bfh(htlc_tx.serialize_preimage(0))) pre_hash = bitcoin.Hash(bfh(htlc_tx.serialize_preimage(0)))
remote_htlc_pubkey = derive_pubkey(chan.remote_config.htlc_basepoint.pubkey, next_point) remote_htlc_pubkey = derive_pubkey(chan.remote_config.htlc_basepoint.pubkey, this_point)
#if not bitcoin.verify_signature(remote_htlc_pubkey, commitment_signed_msg["htlc_signature"], pre_hash): if not bitcoin.verify_signature(remote_htlc_pubkey, commitment_signed_msg["htlc_signature"], pre_hash):
# raise Exception("failed verifying signature an HTLC tx spending from one of our commit tx'es HTLC outputs") raise Exception("failed verifying signature an HTLC tx spending from one of our commit tx'es HTLC outputs")
print("SENDING FIRST REVOKE AND ACK") print("SENDING FIRST REVOKE AND ACK")
#their_revstore.add_next_entry(last_secret) their_revstore.add_next_entry(last_secret)
self.send_message(gen_msg("revoke_and_ack", self.send_message(gen_msg("revoke_and_ack",
channel_id=channel_id, channel_id=channel_id,
@ -1128,9 +1131,9 @@ class Peer(PrintError):
# TODO check commitment_signed results # TODO check commitment_signed results
last_secret, next_point = derive_and_incr() last_secret, _, next_point = derive_and_incr()
#their_revstore.add_next_entry(last_secret) their_revstore.add_next_entry(last_secret)
print("SENDING SECOND REVOKE AND ACK") print("SENDING SECOND REVOKE AND ACK")
self.send_message(gen_msg("revoke_and_ack", self.send_message(gen_msg("revoke_and_ack",

4
lib/tests/test_lnbase_online.py

@ -100,8 +100,8 @@ if __name__ == "__main__":
peer = Peer(host, port, pubkey, privkey, request_initial_sync=False, network=network) peer = Peer(host, port, pubkey, privkey, request_initial_sync=False, network=network)
network.futures.append(asyncio.run_coroutine_threadsafe(peer.main_loop(), network.asyncio_loop)) network.futures.append(asyncio.run_coroutine_threadsafe(peer.main_loop(), network.asyncio_loop))
funding_satoshis = 1000000 funding_satoshis = 2000000
push_msat = 610000000 push_msat = 1000000000
# run blocking test # run blocking test
async def async_test(): async def async_test():

Loading…
Cancel
Save