From 0852f9047353739112cd29013b5bbbb1a90ace9c Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Thu, 14 Jan 2021 11:12:27 +1100 Subject: [PATCH 1/4] Remove unused variant --- swap/src/network/request_response.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/swap/src/network/request_response.rs b/swap/src/network/request_response.rs index 28e4d254..cadd0a8d 100644 --- a/swap/src/network/request_response.rs +++ b/swap/src/network/request_response.rs @@ -1,4 +1,3 @@ -use crate::monero; use async_trait::async_trait; use futures::prelude::*; use libp2p::{ @@ -28,7 +27,6 @@ const BUF_SIZE: usize = 1024 * 1024; pub enum BobToAlice { #[serde(with = "::bitcoin::util::amount::serde::as_sat")] AmountsFromBtc(::bitcoin::Amount), - AmountsFromXmr(monero::Amount), Message0(Box), Message1(bob::Message1), Message2(bob::Message2), From 31c63f0c4de954e90a2a0b5ac7ac81d5e68d8c62 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Thu, 14 Jan 2021 11:35:10 +1100 Subject: [PATCH 2/4] Remove dead code --- swap/src/bitcoin/transactions.rs | 4 ---- swap/src/bitcoin/wallet.rs | 2 -- swap/src/lib.rs | 3 +-- swap/src/main.rs | 4 +++- swap/src/monero.rs | 6 ------ swap/src/network/transport.rs | 35 -------------------------------- 6 files changed, 4 insertions(+), 50 deletions(-) diff --git a/swap/src/bitcoin/transactions.rs b/swap/src/bitcoin/transactions.rs index f5242813..d8d2c059 100644 --- a/swap/src/bitcoin/transactions.rs +++ b/swap/src/bitcoin/transactions.rs @@ -469,10 +469,6 @@ impl TxPunish { } } - pub fn txid(&self) -> Txid { - self.inner.txid() - } - pub fn digest(&self) -> SigHash { self.digest } diff --git a/swap/src/bitcoin/wallet.rs b/swap/src/bitcoin/wallet.rs index 0582f84e..6cbc777b 100644 --- a/swap/src/bitcoin/wallet.rs +++ b/swap/src/bitcoin/wallet.rs @@ -16,8 +16,6 @@ use crate::{ config::Config, }; -pub const TX_LOCK_MINE_TIMEOUT: u64 = 3600; - #[derive(Debug)] pub struct Wallet { pub inner: bitcoin_harness::Wallet, diff --git a/swap/src/lib.rs b/swap/src/lib.rs index c33479a7..f7020277 100644 --- a/swap/src/lib.rs +++ b/swap/src/lib.rs @@ -20,10 +20,9 @@ use serde::{Deserialize, Serialize}; use std::fmt::{self, Display}; pub mod bitcoin; -pub mod cli; pub mod config; pub mod database; -pub mod fs; +mod fs; pub mod monero; pub mod network; pub mod protocol; diff --git a/swap/src/main.rs b/swap/src/main.rs index ece38ff7..5ef84e7a 100644 --- a/swap/src/main.rs +++ b/swap/src/main.rs @@ -13,6 +13,7 @@ #![forbid(unsafe_code)] #![allow(non_snake_case)] +use crate::cli::{Command, Options, Resume}; use anyhow::{bail, Context, Result}; use libp2p::{core::Multiaddr, PeerId}; use prettytable::{row, Table}; @@ -21,7 +22,6 @@ use std::sync::Arc; use structopt::StructOpt; use swap::{ bitcoin, - cli::{Command, Options, Resume}, config::Config, database::{Database, Swap}, monero, network, @@ -34,6 +34,8 @@ use swap::{ use tracing::{info, log::LevelFilter}; use uuid::Uuid; +mod cli; + #[macro_use] extern crate prettytable; diff --git a/swap/src/monero.rs b/swap/src/monero.rs index 3c177884..499e248d 100644 --- a/swap/src/monero.rs +++ b/swap/src/monero.rs @@ -23,12 +23,6 @@ pub use wallet::Wallet; pub const PICONERO_OFFSET: u64 = 1_000_000_000_000; -pub fn random_private_key(rng: &mut R) -> PrivateKey { - let scalar = Scalar::random(rng); - - PrivateKey::from_scalar(scalar) -} - pub fn private_key_from_secp256k1_scalar(scalar: bitcoin::Scalar) -> PrivateKey { let mut bytes = scalar.to_bytes(); diff --git a/swap/src/network/transport.rs b/swap/src/network/transport.rs index 5fa715fa..eb025f20 100644 --- a/swap/src/network/transport.rs +++ b/swap/src/network/transport.rs @@ -39,40 +39,5 @@ pub fn build(id_keys: identity::Keypair) -> Result { Ok(transport) } -/// Builds a libp2p transport with Tor and with the following features: -/// - TCP connection over the Tor network -/// - DNS name resolution -/// - authentication via noise -/// - multiplexing via yamux or mplex -pub fn build_tor( - id_keys: identity::Keypair, - address_port_pair: Option<(libp2p::core::Multiaddr, u16)>, -) -> Result { - use libp2p_tokio_socks5::Socks5TokioTcpConfig; - use std::collections::HashMap; - - let mut map = HashMap::new(); - if let Some((addr, port)) = address_port_pair { - map.insert(addr, port); - } - - let dh_keys = noise::Keypair::::new().into_authentic(&id_keys)?; - let noise = NoiseConfig::xx(dh_keys).into_authenticated(); - - let socks = Socks5TokioTcpConfig::default().nodelay(true).onion_map(map); - let dns = DnsConfig::new(socks)?; - - let transport = dns - .upgrade(Version::V1) - .authenticate(noise) - .multiplex(SelectUpgrade::new( - yamux::Config::default(), - MplexConfig::new(), - )) - .map(|(peer, muxer), _| (peer, StreamMuxerBox::new(muxer))) - .boxed(); - - Ok(transport) -} pub type SwapTransport = Boxed<(PeerId, StreamMuxerBox)>; From c5bfbf8da9c5f560c4468df1543fd902e230e9c6 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Thu, 14 Jan 2021 11:48:49 +1100 Subject: [PATCH 3/4] Clarify who is user/SP --- docs/sequence.puml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/sequence.puml b/docs/sequence.puml index cbfd4979..58a00bbb 100644 --- a/docs/sequence.puml +++ b/docs/sequence.puml @@ -1,7 +1,7 @@ @startuml database Bitcoin -actor Bob -Actor Alice +actor Bob as "Bob (User)" +Actor Alice as "Alice (Service Provider)" database Monero group Negotiation From 6003f87301f0cab3384861ce1e62db3b2b0d7354 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Thu, 14 Jan 2021 11:52:16 +1100 Subject: [PATCH 4/4] In phase A, message can be send simultaneously so calling them both 0. --- docs/sequence.puml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/sequence.puml b/docs/sequence.puml index 58a00bbb..189856db 100644 --- a/docs/sequence.puml +++ b/docs/sequence.puml @@ -20,22 +20,22 @@ end group Execution Setup group Phase A [Messages can be exchanged in any order] - Bob -> Alice: Message0 + Bob -> Alice: bob::Message0 note left: Pubkeys\ndleq proof s_b\nxmr viewkey v_b\nbtc refund addr - Alice -> Bob: Message1 + Alice -> Bob: alice::Message0 note right: Pubkeys\ndleq proof s_a\nxmr view key v_a\nbtc redeem addr\nbtc punish addr end group Phase B [Messages must be exchanged in the given order] - Bob -> Alice: Message2 + Bob -> Alice: Message1 note left: unsigned btc lock tx - Alice -> Bob: Message3 + Alice -> Bob: Message2 note right: btc cancel tx sig\nbtc refund tx enc sig S_b - Bob -> Alice: Message4 + Bob -> Alice: Message3 note left: btc punish tx sig\nbtc cancel tx sig end @@ -46,10 +46,10 @@ group Execution Alice ->> Monero: Lock - Alice -> Bob: Message5 + Alice -> Bob: Message4 note right: xmr lock tx transfer proof\nThis can be removed if Bob watches the blockchain. - Bob -> Alice: Message6 + Bob -> Alice: Message5 note left: redeem tx enc sig S_a Alice ->> Bitcoin: Redeem