From a60589c3bc895320e5ea5925ee7b9c83356d1f9d Mon Sep 17 00:00:00 2001 From: Lucas Soriano del Pino Date: Fri, 30 Jul 2021 22:17:50 +1000 Subject: [PATCH 1/3] Update dependencies for stability and compatibility - With the release of `elements-miniscript:0.1.0` we can now release `baru` to `crates.io` once again! - Fixing the git dev-dependency on `elements-harness` to a specific commit hash should prevent unexpected changes from coming in. - Depending directly on `rust-elements:0.17.0` and indirectly via `elements-miniscript` on `rust-elements:0.18.0` caused problems in certain situations (never in CI). Upgrading to version `0.18.0` has fixed this. Given that `baru:0.1.1` could never be released to `crates.io`, didn't include anything other than internal refactorings and wasn't even working in certain environments, we've decided to erase it from history (except in the git history ;). --- CHANGELOG.md | 8 +++++--- Cargo.toml | 8 ++++---- elements-rpc/Cargo.toml | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1523434..03af1a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,7 +28,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `fn liquidation_transaction()` API on `Lender1` is now `async`. - Model the collateral contract's timelock as a `u32`. -## [0.1.1] - 2021-07-23 +### Fixed + +- Squashed an [elusive bug](https://github.com/comit-network/baru/issues/35) preventing users from building version `0.1.0` of this library. + This required updating `rust-elements` to version `0.18`. ## [0.1.0] - 2021-07-16 @@ -36,6 +39,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Loan protocol and swap libraries originally developed in [Project Waves](https://github.com/comit-network/waves). -[Unreleased]: https://github.com/comit-network/baru/compare/0.1.1...HEAD -[0.1.1]: https://github.com/comit-network/baru/compare/0.1.0...0.1.1 +[Unreleased]: https://github.com/comit-network/baru/compare/0.1.0...HEAD [0.1.0]: https://github.com/comit-network/baru/releases/tag/0.1.0 diff --git a/Cargo.toml b/Cargo.toml index 1b0eeac..43f2f07 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ members = [ "elements-rpc" ] [package] name = "baru" -version = "0.1.1" +version = "0.1.0" authors = [ "CoBloX Team " ] edition = "2018" license-file = "LICENSE" @@ -13,8 +13,8 @@ description = "Library to facilitate DeFi on Liquid" anyhow = "1" bitcoin_hashes = "0.9.0" conquer-once = "0.3" -elements = { version = "0.17", features = [ "serde-feature" ] } -elements-miniscript = { git = "http://github.com/ElementsProject/elements-miniscript", features = [ "use-serde" ] } +elements = { version = "0.18", features = [ "serde-feature" ] } +elements-miniscript = { version = "0.1", features = [ "use-serde" ] } env_logger = "0.8.3" hex = "0.4" hmac = "0.10" @@ -29,7 +29,7 @@ sha2 = "0.9" thiserror = "1" [dev-dependencies] -elements-harness = { git = "https://github.com/comit-network/elements-harness" } +elements-harness = { git = "https://github.com/comit-network/elements-harness", rev = "0c28948c124d68e828e0f27c9202ba278dc04421" } elements-rpc = { path = "./elements-rpc" } rand_chacha = "0.1" testcontainers = "0.12" diff --git a/elements-rpc/Cargo.toml b/elements-rpc/Cargo.toml index 7c5c640..fc107d6 100644 --- a/elements-rpc/Cargo.toml +++ b/elements-rpc/Cargo.toml @@ -8,7 +8,7 @@ publish = false [dependencies] anyhow = "1.0" bitcoin_hashes = "0.9.0" -elements = { version = "0.17", features = [ "serde-feature" ] } +elements = { version = "0.18", features = [ "serde-feature" ] } jsonrpc_client = { version = "0.6", features = [ "reqwest" ] } reqwest = "0.11" serde = "1.0" From 0f54da5f24681d8dd6f2b7faafbdbee48a31fbb0 Mon Sep 17 00:00:00 2001 From: Lucas Soriano del Pino Date: Mon, 2 Aug 2021 10:19:50 +1000 Subject: [PATCH 2/3] Appease Clippy 0.1.54 --- src/loan.rs | 10 +++++----- src/loan/protocol_tests.rs | 26 +++++++++++++------------- src/swap.rs | 14 +++++++------- tests/swap_happy_path.rs | 14 +++++++------- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/loan.rs b/src/loan.rs index 8ee3d06..91129b3 100644 --- a/src/loan.rs +++ b/src/loan.rs @@ -286,7 +286,7 @@ impl CollateralContract { let script = &self.raw_script; let sighash = SigHashCache::new(&*transaction).segwitv0_sighash( input_index as usize, - &script, + script, input_value, SigHashType::All, ); @@ -334,10 +334,10 @@ impl CollateralContract { let descriptor_cov = &self.descriptor.as_cov().expect("covenant descriptor"); let cov_sat = CovSatisfier::new_segwitv0( - &transaction, + transaction, input_index, input_value, - &cov_script, + cov_script, SigHashType::All, ); @@ -358,7 +358,7 @@ impl CollateralContract { let script = &self.raw_script; let sighash = SigHashCache::new(&*transaction).segwitv0_sighash( input_index as usize, - &script, + script, input_value, SigHashType::All, ); @@ -1443,7 +1443,7 @@ where { let sk = SecretKey::new(rng); let pk = PublicKey::from_private_key( - &SECP256K1, + SECP256K1, &PrivateKey { compressed: true, network: Network::Regtest, diff --git a/src/loan/protocol_tests.rs b/src/loan/protocol_tests.rs index 5cebb6f..503202b 100644 --- a/src/loan/protocol_tests.rs +++ b/src/loan/protocol_tests.rs @@ -121,7 +121,7 @@ mod tests { let lender = lender .interpret( &mut rng, - &SECP256K1, + SECP256K1, { let client = client.clone(); |amount, asset| async move { find_inputs(&client, asset, amount).await } @@ -133,7 +133,7 @@ mod tests { .unwrap(); let loan_response = lender.loan_response(); - let borrower = borrower.interpret(&SECP256K1, loan_response).unwrap(); + let borrower = borrower.interpret(SECP256K1, loan_response).unwrap(); let loan_transaction = borrower .sign({ let wallet = borrower_wallet.clone(); @@ -160,7 +160,7 @@ mod tests { let loan_repayment_transaction = borrower .loan_repayment_transaction( &mut rng, - &SECP256K1, + SECP256K1, { let borrower_wallet = borrower_wallet.clone(); |amount, asset| async move { borrower_wallet.find_inputs(asset, amount).await } @@ -277,7 +277,7 @@ mod tests { let lender = lender .interpret( &mut rng, - &SECP256K1, + SECP256K1, { let client = client.clone(); |amount, asset| async move { find_inputs(&client, asset, amount).await } @@ -289,7 +289,7 @@ mod tests { .unwrap(); let loan_response = lender.loan_response(); - let borrower = borrower.interpret(&SECP256K1, loan_response).unwrap(); + let borrower = borrower.interpret(SECP256K1, loan_response).unwrap(); let loan_transaction = borrower .sign(|transaction| async move { Ok(borrower_wallet.sign_all_inputs(transaction)) }) .await @@ -309,7 +309,7 @@ mod tests { .unwrap(); let liquidation_transaction = lender - .liquidation_transaction(&mut rng, &SECP256K1, Amount::from_sat(1)) + .liquidation_transaction(&mut rng, SECP256K1, Amount::from_sat(1)) .await .unwrap(); @@ -426,7 +426,7 @@ mod tests { let lender = lender .interpret( &mut rng, - &SECP256K1, + SECP256K1, { let client = client.clone(); |amount, asset| async move { find_inputs(&client, asset, amount).await } @@ -438,7 +438,7 @@ mod tests { .unwrap(); let loan_response = lender.loan_response(); - let borrower = borrower.interpret(&SECP256K1, loan_response).unwrap(); + let borrower = borrower.interpret(SECP256K1, loan_response).unwrap(); let loan_transaction = borrower .sign(|transaction| async move { Ok(borrower_wallet.sign_all_inputs(transaction)) }) .await @@ -474,7 +474,7 @@ mod tests { let liquidation_transaction = lender .dynamic_liquidation_transaction( &mut rng, - &SECP256K1, + SECP256K1, oracle_msg, oracle_sig, Amount::ONE_SAT, @@ -505,7 +505,7 @@ mod tests { let liquidation_transaction = lender .dynamic_liquidation_transaction( &mut rng, - &SECP256K1, + SECP256K1, oracle_msg, oracle_sig, Amount::ONE_SAT, @@ -539,7 +539,7 @@ mod tests { let liquidation_transaction = lender .dynamic_liquidation_transaction( &mut rng, - &SECP256K1, + SECP256K1, oracle_msg, oracle_sig, Amount::ONE_SAT, @@ -570,7 +570,7 @@ mod tests { let liquidation_transaction = lender .dynamic_liquidation_transaction( &mut rng, - &SECP256K1, + SECP256K1, oracle_msg, oracle_sig, Amount::ONE_SAT, @@ -789,7 +789,7 @@ mod tests { { let sk = SecretKey::new(rng); let pk = PublicKey::from_private_key( - &SECP256K1, + SECP256K1, &PrivateKey { compressed: true, network: Network::Regtest, diff --git a/src/swap.rs b/src/swap.rs index d0c7dd5..14d01ef 100644 --- a/src/swap.rs +++ b/src/swap.rs @@ -64,16 +64,16 @@ where let (receive_output_alice, abf_receive_alice, vbf_receive_alice) = TxOut::new_not_last_confidential( rng, - &secp, + secp, alice.receive_amount.as_sat(), alice.address.clone(), alice.receive_asset, - &inputs_not_last_confidential.as_slice(), + inputs_not_last_confidential.as_slice(), )?; let (redeem_output_bob, abf_receive_bob, vbf_receive_bob) = TxOut::new_not_last_confidential( rng, - &secp, + secp, bob.receive_amount.as_sat(), bob.address.clone(), bob.receive_asset, @@ -82,7 +82,7 @@ where let (change_output_alice, abf_change_alice, vbf_change_alice) = TxOut::new_not_last_confidential( rng, - &secp, + secp, change_amount_alice.as_sat(), alice.address.clone(), bob.receive_asset, @@ -112,7 +112,7 @@ where let (change_output_bob, _, _) = TxOut::new_last_confidential( rng, - &secp, + secp, change_amount_bob.as_sat(), bob.address, alice.receive_asset, @@ -176,7 +176,7 @@ pub fn sign_with_key( where C: Signing, { - let input_pk = PublicKey::from_secret_key(&secp, &input_sk); + let input_pk = PublicKey::from_secret_key(secp, input_sk); let hash = hash160::Hash::hash(&input_pk.serialize()); let script = Builder::new() @@ -189,7 +189,7 @@ where let sighash = cache.segwitv0_sighash(index, &script, value, SigHashType::All); - let sig = secp.sign(&Message::from(sighash), &input_sk); + let sig = secp.sign(&Message::from(sighash), input_sk); let mut serialized_signature = sig.serialize_der().to_vec(); serialized_signature.push(SigHashType::All as u8); diff --git a/tests/swap_happy_path.rs b/tests/swap_happy_path.rs index 915cd7f..9b58ebb 100644 --- a/tests/swap_happy_path.rs +++ b/tests/swap_happy_path.rs @@ -87,7 +87,7 @@ async fn collaborative_create_and_sign() { .unwrap(); let alice = Actor::new( - &SECP256K1, + SECP256K1, vec![Input { txin: input_alice.0, original_txout: input_alice.1.clone(), @@ -100,7 +100,7 @@ async fn collaborative_create_and_sign() { .unwrap(); let bob = Actor::new( - &SECP256K1, + SECP256K1, vec![Input { txin: input_bob.0, original_txout: input_bob.1.clone(), @@ -129,7 +129,7 @@ async fn collaborative_create_and_sign() { .context("transaction does not contain input")?; tx.input[input_index_1].witness.script_witness = sign_with_key( - &SECP256K1, + SECP256K1, &mut SigHashCache::new(&tx), input_index_1, &fund_sk_bob, @@ -153,7 +153,7 @@ async fn collaborative_create_and_sign() { .context("transaction does not contain input")?; tx.input[input_index].witness.script_witness = sign_with_key( - &SECP256K1, + SECP256K1, &mut SigHashCache::new(&tx), input_index, &fund_sk_alice, @@ -213,7 +213,7 @@ async fn move_output_to_wallet( let asset_id = previous_output_secrets.asset; let (output, _, _) = TxOut::new_last_confidential( &mut thread_rng(), - &SECP256K1, + SECP256K1, amount_out.as_sat(), move_address, asset_id, @@ -231,7 +231,7 @@ async fn move_output_to_wallet( }; let previous_output_pk = PublicKey::from_private_key( - &SECP256K1, + SECP256K1, &PrivateKey { compressed: true, network: Network::Regtest, @@ -288,7 +288,7 @@ fn extract_input(tx: &Transaction, address: Address) -> Result<(OutPoint, TxOut) fn make_keypair() -> (SecretKey, PublicKey) { let sk = SecretKey::new(&mut thread_rng()); let pk = PublicKey::from_private_key( - &SECP256K1, + SECP256K1, &PrivateKey { compressed: true, network: Network::Regtest, From 03b76e44649a69ba5493ab02e1050f9c12ae8970 Mon Sep 17 00:00:00 2001 From: Lucas Soriano del Pino Date: Fri, 30 Jul 2021 22:20:08 +1000 Subject: [PATCH 3/3] Update baru to version 0.2.0 --- CHANGELOG.md | 5 ++++- Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03af1a6..afd0ca1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.2.0] - 2021-07-30 + ### Added - Dynamic liquidation branch to the loan protocol: @@ -39,5 +41,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Loan protocol and swap libraries originally developed in [Project Waves](https://github.com/comit-network/waves). -[Unreleased]: https://github.com/comit-network/baru/compare/0.1.0...HEAD +[Unreleased]: https://github.com/comit-network/baru/compare/0.2.0...HEAD +[0.2.0]: https://github.com/comit-network/baru/compare/0.1.0...0.2.0 [0.1.0]: https://github.com/comit-network/baru/releases/tag/0.1.0 diff --git a/Cargo.toml b/Cargo.toml index 43f2f07..9257b68 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ members = [ "elements-rpc" ] [package] name = "baru" -version = "0.1.0" +version = "0.2.0" authors = [ "CoBloX Team " ] edition = "2018" license-file = "LICENSE"