Browse Source

Merge #713: Bugfix: don't randomize payjoin outputs

e6bc0c1 Bugfix: don't randomize payjoin outputs (Adam Gibson)
master
Adam Gibson 5 years ago
parent
commit
7854c59169
No known key found for this signature in database
GPG Key ID: 141001A1AF77F20B
  1. 24
      jmclient/jmclient/payjoin.py

24
jmclient/jmclient/payjoin.py

@ -16,6 +16,7 @@ from txtorcon.socks import HostUnreachableError
import urllib.parse as urlparse import urllib.parse as urlparse
from urllib.parse import urlencode from urllib.parse import urlencode
import json import json
import random
from io import BytesIO from io import BytesIO
from pprint import pformat from pprint import pformat
from jmbase import BytesProducer, bintohex, jmprint from jmbase import BytesProducer, bintohex, jmprint
@ -903,11 +904,21 @@ class PayjoinServer(Resource):
self.manager.change_out.scriptPubKey))} self.manager.change_out.scriptPubKey))}
# we now know there were one/two outputs and know which is payment. # we now know there were one/two outputs and know which is payment.
# bump payment output with our input: # set the ordering of the outputs correctly.
if change_out: if change_out:
# indices of original payment were set in JMPayjoinManager
# sanity check:
if self.manager.change_out_index == 0 and \
self.manager.pay_out_index == 1:
outs = [change_out, pay_out]
elif self.manager.change_out_index == 1 and \
self.manager.pay_out_index == 0:
outs = [pay_out, change_out] outs = [pay_out, change_out]
else:
assert False, "More than 2 outputs is not supported."
else: else:
outs = [pay_out] outs = [pay_out]
# bump payment output with our input:
our_inputs_val = sum([v["value"] for _, v in receiver_utxos.items()]) our_inputs_val = sum([v["value"] for _, v in receiver_utxos.items()])
pay_out["value"] += our_inputs_val pay_out["value"] += our_inputs_val
log.debug("We bumped the payment output value by: " + str( log.debug("We bumped the payment output value by: " + str(
@ -959,12 +970,15 @@ class PayjoinServer(Resource):
"original-psbt-rejected") "original-psbt-rejected")
# Having checked the sender's conditions, we can apply the fee bump # Having checked the sender's conditions, we can apply the fee bump
# intended (note the outputs will be shuffled next!): # intended:
outs[1]["value"] -= our_fee_bump outs[self.manager.change_out_index]["value"] -= our_fee_bump
# TODO this only works for 2 input transactions, otherwise # TODO this only works for 2 input transactions, otherwise
# pure-shuffle will not be valid as per BIP78 ordering requirement. # reversal [::-1] will not be valid as per BIP78 ordering requirement.
unsigned_payjoin_tx = btc.make_shuffled_tx(payjoin_tx_inputs, outs, # (For outputs, we do nothing since we aren't batching in other payments).
if random.random() < 0.5:
payjoin_tx_inputs = payjoin_tx_inputs[::-1]
unsigned_payjoin_tx = btc.mktx(payjoin_tx_inputs, outs,
version=payment_psbt.unsigned_tx.nVersion, version=payment_psbt.unsigned_tx.nVersion,
locktime=payment_psbt.unsigned_tx.nLockTime) locktime=payment_psbt.unsigned_tx.nLockTime)

Loading…
Cancel
Save