lnbase: verify commitment tx'es again

This commit is contained in:
Janus 2018-05-14 15:41:55 +02:00 committed by ThomasV
parent 73a17c93ee
commit 2e23ecb3ca
2 changed files with 22 additions and 19 deletions

View file

@ -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",

View file

@ -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():