From e79ac4563bd87ea2d95d624f7b678d97f070f897 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 25 May 2021 15:31:11 +1000 Subject: [PATCH 1/5] Delete unused code --- swap/src/bitcoin/timelocks.rs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/swap/src/bitcoin/timelocks.rs b/swap/src/bitcoin/timelocks.rs index ab365df8..04f589a9 100644 --- a/swap/src/bitcoin/timelocks.rs +++ b/swap/src/bitcoin/timelocks.rs @@ -17,18 +17,6 @@ impl From for u32 { } } -impl BlockHeight { - pub const fn new(block_height: u32) -> Self { - Self(block_height) - } - pub const fn checked_sub(self, rhs: Self) -> Option { - match self.0.checked_sub(rhs.0) { - Some(result) => Some(BlockHeight(result)), - None => None, - } - } -} - impl TryFrom for BlockHeight { type Error = anyhow::Error; From b8cb9e1b8bf5e52aa748f592669a2d8a92b5cbfd Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 25 May 2021 15:27:57 +1000 Subject: [PATCH 2/5] Update secp256kfun and rand to latest version This will allow us to compile on stable Rust. The latest version of `secp256kfun` uses `curve25519-dalek-ng` instead of the original curve25519-dalek crate. Instead of converting back and forth, we simply switch to this crate as well. Judging from the README it is just a fork because there was trouble between the maintainers of the original crate. --- Cargo.lock | 60 ++++++++++++++++++++++++++++++++----------------- Cargo.toml | 3 +++ swap/Cargo.toml | 10 ++++----- 3 files changed, 47 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fb75c187..5aa31de3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -826,11 +826,24 @@ dependencies = [ "byteorder", "digest 0.9.0", "rand_core 0.5.1", - "serde", "subtle 2.4.0", "zeroize", ] +[[package]] +name = "curve25519-dalek-ng" +version = "4.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "574d8b2cd0bae5434fd50d53280f8299d95557a978686555880aaf5b8f4f81e9" +dependencies = [ + "byteorder", + "digest 0.9.0", + "rand_core 0.6.2", + "serde", + "subtle-ng", + "zeroize", +] + [[package]] name = "data-encoding" version = "2.3.2" @@ -932,11 +945,11 @@ checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" [[package]] name = "ecdsa_fun" -version = "0.4.2-alpha.0" -source = "git+https://github.com/LLFourn/secp256kfun#8538ef22498170960a9769df2700c1986cc540fd" +version = "0.6.2-alpha.0" +source = "git+https://github.com/LLFourn/secp256kfun#84134daf34845434d7f38cdae7ffc31730a3b1e9" dependencies = [ "bincode", - "rand_chacha 0.2.2", + "rand_chacha 0.3.0", "secp256kfun", "serde", "sigma_fun", @@ -2182,11 +2195,10 @@ dependencies = [ [[package]] name = "monero" version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c73108ba5cf025e437600990935234241f95ada3c4621960d50912cde739af6" +source = "git+https://github.com/comit-network/monero-rs?rev=818f38b#818f38b043e2a9fa38d74fec5310a270f510844e" dependencies = [ "base58-monero", - "curve25519-dalek", + "curve25519-dalek-ng", "fixed-hash", "hex 0.4.3", "hex-literal", @@ -3347,24 +3359,24 @@ dependencies = [ [[package]] name = "secp256kfun" -version = "0.4.2-alpha.0" -source = "git+https://github.com/LLFourn/secp256kfun#8538ef22498170960a9769df2700c1986cc540fd" +version = "0.6.2-alpha.0" +source = "git+https://github.com/LLFourn/secp256kfun#84134daf34845434d7f38cdae7ffc31730a3b1e9" dependencies = [ "digest 0.9.0", - "rand_core 0.5.1", + "rand_core 0.6.2", "secp256k1", "secp256kfun_parity_backend", "serde", - "subtle 2.4.0", + "subtle-ng", ] [[package]] name = "secp256kfun_parity_backend" -version = "0.1.4-alpha.0" -source = "git+https://github.com/LLFourn/secp256kfun#8538ef22498170960a9769df2700c1986cc540fd" +version = "0.1.6-alpha.0" +source = "git+https://github.com/LLFourn/secp256kfun#84134daf34845434d7f38cdae7ffc31730a3b1e9" dependencies = [ "crunchy", - "subtle 2.4.0", + "subtle-ng", ] [[package]] @@ -3535,13 +3547,13 @@ dependencies = [ [[package]] name = "sigma_fun" -version = "0.1.3-alpha.0" -source = "git+https://github.com/LLFourn/secp256kfun#8538ef22498170960a9769df2700c1986cc540fd" +version = "0.3.2-alpha.0" +source = "git+https://github.com/LLFourn/secp256kfun#84134daf34845434d7f38cdae7ffc31730a3b1e9" dependencies = [ - "curve25519-dalek", + "curve25519-dalek-ng", "digest 0.9.0", "generic-array 0.14.4", - "rand_core 0.5.1", + "rand_core 0.6.2", "secp256kfun", "serde", ] @@ -3808,6 +3820,12 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" +[[package]] +name = "subtle-ng" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8049cf85f0e715d6af38dde439cb0ccb91f67fb9f5f63c80f8b43e48356e1a3f" + [[package]] name = "swap" version = "0.5.0" @@ -3826,7 +3844,7 @@ dependencies = [ "bmrng", "config", "conquer-once", - "curve25519-dalek", + "curve25519-dalek-ng", "data-encoding", "dialoguer", "directories-next", @@ -3846,8 +3864,8 @@ dependencies = [ "port_check", "prettytable-rs", "proptest", - "rand 0.7.3", - "rand_chacha 0.2.2", + "rand 0.8.3", + "rand_chacha 0.3.0", "reqwest", "rust_decimal", "rust_decimal_macros", diff --git a/Cargo.toml b/Cargo.toml index 56e4fe63..0f654d91 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,5 @@ [workspace] members = [ "monero-harness", "monero-rpc", "swap", "monero-wallet" ] + +[patch.crates-io] +monero = { git = "https://github.com/comit-network/monero-rs", rev = "818f38b" } diff --git a/swap/Cargo.toml b/swap/Cargo.toml index 00eb0d99..5c0463cb 100644 --- a/swap/Cargo.toml +++ b/swap/Cargo.toml @@ -21,11 +21,11 @@ bitcoin = { version = "0.26", features = [ "rand", "use-serde" ] } bmrng = "0.5" config = { version = "0.11", default-features = false, features = [ "toml" ] } conquer-once = "0.3" -curve25519-dalek = "3" +curve25519-dalek = { package = "curve25519-dalek-ng", version = "4" } data-encoding = "2.3" dialoguer = "0.8" directories-next = "2" -ecdsa_fun = { git = "https://github.com/LLFourn/secp256kfun", features = [ "libsecp_compat", "serde" ] } +ecdsa_fun = { git = "https://github.com/LLFourn/secp256kfun", default-features = false, features = [ "libsecp_compat", "serde" ] } ed25519-dalek = "1" futures = { version = "0.3", default-features = false } itertools = "0.10" @@ -37,8 +37,8 @@ monero-rpc = { path = "../monero-rpc" } pem = "0.8" prettytable-rs = "0.8" proptest = "1" -rand = "0.7" -rand_chacha = "0.2" +rand = "0.8" +rand_chacha = "0.3" reqwest = { version = "0.11", features = [ "rustls-tls", "stream", "socks" ], default-features = false } rust_decimal = { version = "1", features = [ "serde-float" ] } rust_decimal_macros = "1" @@ -46,7 +46,7 @@ serde = { version = "1", features = [ "derive" ] } serde_cbor = "0.11" serde_json = "1" sha2 = "0.9" -sigma_fun = { git = "https://github.com/LLFourn/secp256kfun", features = [ "ed25519", "serde" ] } +sigma_fun = { git = "https://github.com/LLFourn/secp256kfun", default-features = false, features = [ "ed25519", "serde" ] } sled = "0.34" structopt = "0.3" strum = { version = "0.20", features = [ "derive" ] } From 694ade11d1eed35868d36ed077641592617f1582 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 25 May 2021 14:40:31 +1000 Subject: [PATCH 3/5] Replace cargo-fmt with dprint If we want to use stable Rust, we can't use cargo-fmt with nightly features. --- .github/workflows/ci.yml | 3 --- dprint.json | 18 +++++++++++++++--- rust-toolchain | 2 +- rustfmt.toml | 12 ------------ 4 files changed, 16 insertions(+), 19 deletions(-) delete mode 100644 rustfmt.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7dc88d9e..f9e9f229 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,9 +17,6 @@ jobs: - uses: Swatinem/rust-cache@v1.2.0 - - name: Check code formatting - run: cargo fmt --all -- --check - - name: Check formatting uses: dprint/check@v1.4 diff --git a/dprint.json b/dprint.json index 5e4931b2..c73d9690 100644 --- a/dprint.json +++ b/dprint.json @@ -4,10 +4,22 @@ "incremental": true, "markdown": { }, - "includes": ["**/*.{md}", "**/*.{toml}"], - "excludes": [ ], + "rustfmt": { + "edition": 2018, + "condense_wildcard_suffixes": true, + "format_macro_matchers": true, + "imports_granularity" : "Module", + "use_field_init_shorthand": true, + "format_code_in_doc_comments": true, + "normalize_comments": true, + "wrap_comments": true, + "overflow_delimited_expr": true + }, + "includes": ["**/*.{md}", "**/*.{toml}", "**/*.{rs}"], + "excludes": [ "target/" ], "plugins": [ "https://plugins.dprint.dev/markdown-0.6.1.wasm", - "https://github.com/thomaseizinger/dprint-plugin-cargo-toml/releases/download/0.1.0/cargo-toml-0.1.0.wasm" + "https://github.com/thomaseizinger/dprint-plugin-cargo-toml/releases/download/0.1.0/cargo-toml-0.1.0.wasm", + "https://plugins.dprint.dev/rustfmt-0.4.0.exe-plugin@c6bb223ef6e5e87580177f6461a0ab0554ac9ea6b54f78ea7ae8bf63b14f5bc2" ] } diff --git a/rust-toolchain b/rust-toolchain index 6a154529..1985a9e4 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] channel = "nightly-2021-01-31" -components = ["rustfmt", "clippy"] +components = ["clippy"] targets = ["armv7-unknown-linux-gnueabihf"] diff --git a/rustfmt.toml b/rustfmt.toml deleted file mode 100644 index 6e3e8004..00000000 --- a/rustfmt.toml +++ /dev/null @@ -1,12 +0,0 @@ -edition = "2018" -condense_wildcard_suffixes = true -format_macro_matchers = true -imports_granularity = "Module" -use_field_init_shorthand = true -format_code_in_doc_comments = true -normalize_comments = true -wrap_comments = true -overflow_delimited_expr = true -ignore = [ - "tokio-tar" -] From 5d7acd39ee19a330474dad9003fab522e7bf2ab3 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 25 May 2021 14:43:29 +1000 Subject: [PATCH 4/5] Use new .toml extension for rust-toolchain file --- rust-toolchain => rust-toolchain.toml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename rust-toolchain => rust-toolchain.toml (100%) diff --git a/rust-toolchain b/rust-toolchain.toml similarity index 100% rename from rust-toolchain rename to rust-toolchain.toml From 8f9d612af203b78b1e21d1be65a16c05ac047ea0 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 25 May 2021 15:31:20 +1000 Subject: [PATCH 5/5] Change to stable Rust 1.52 Fix clippy warnings that are new in this version. --- rust-toolchain.toml | 2 +- swap/src/bin/asb.rs | 2 +- swap/src/protocol/alice/state.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 1985a9e4..242a73de 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2021-01-31" +channel = "1.52" components = ["clippy"] targets = ["armv7-unknown-linux-gnueabihf"] diff --git a/swap/src/bin/asb.rs b/swap/src/bin/asb.rs index afef29f3..1097fb69 100644 --- a/swap/src/bin/asb.rs +++ b/swap/src/bin/asb.rs @@ -353,7 +353,7 @@ async fn register_tor_services( } }) }) - .filter_map(|details| details) + .flatten() .collect::>(); let key = seed.derive_torv3_key(); diff --git a/swap/src/protocol/alice/state.rs b/swap/src/protocol/alice/state.rs index 80f12a0a..42d605d8 100644 --- a/swap/src/protocol/alice/state.rs +++ b/swap/src/protocol/alice/state.rs @@ -308,8 +308,8 @@ impl State2 { let tx_cancel_sig = self.a.sign(tx_cancel.digest()); Message3 { - tx_refund_encsig, tx_cancel_sig, + tx_refund_encsig, } }