From 5f11673132aeffdb384a7040f0039bd4f3e3ff33 Mon Sep 17 00:00:00 2001 From: bennyhodl Date: Mon, 3 Jun 2024 21:32:55 -0400 Subject: [PATCH] chore: Update `bitcoin` to `0.31.2` --- bitcoin-rpc-provider/Cargo.toml | 8 +- bitcoin-test-utils/Cargo.toml | 6 +- dlc-manager/Cargo.toml | 9 +- dlc-manager/src/channel_updater.rs | 48 +++++----- dlc-manager/src/contract/accepted_contract.rs | 2 +- dlc-manager/src/contract_updater.rs | 20 ++--- dlc-manager/src/conversion_utils.rs | 2 +- dlc-manager/src/error.rs | 10 +++ dlc-manager/src/lib.rs | 6 +- dlc-manager/src/utils.rs | 2 +- dlc-messages/Cargo.toml | 11 +-- dlc-messages/src/ser_impls.rs | 4 +- dlc-sled-storage-provider/Cargo.toml | 7 +- dlc-trie/Cargo.toml | 6 +- dlc/Cargo.toml | 12 +-- dlc/src/channel/mod.rs | 29 +++--- dlc/src/lib.rs | 89 ++++++++++--------- dlc/src/secp_utils.rs | 43 +++++---- dlc/src/util.rs | 34 +++---- electrs-blockchain-provider/Cargo.toml | 4 +- fuzz/Cargo.toml | 2 +- mocks/Cargo.toml | 6 +- p2pd-oracle-client/Cargo.toml | 2 +- sample/Cargo.toml | 6 +- simple-wallet/Cargo.toml | 9 +- 25 files changed, 200 insertions(+), 177 deletions(-) diff --git a/bitcoin-rpc-provider/Cargo.toml b/bitcoin-rpc-provider/Cargo.toml index 2796eb2d..024033bc 100644 --- a/bitcoin-rpc-provider/Cargo.toml +++ b/bitcoin-rpc-provider/Cargo.toml @@ -5,12 +5,12 @@ name = "bitcoin-rpc-provider" version = "0.1.0" [dependencies] -bitcoin = {version = "0.30.2"} -bitcoincore-rpc = {version = "0.17.0"} -bitcoincore-rpc-json = {version = "0.17.0"} +bitcoin = {version = "0.31.2"} +bitcoincore-rpc = {version = "0.19.0"} +bitcoincore-rpc-json = {version = "0.19.0"} dlc-manager = {path = "../dlc-manager"} hex = { package = "hex-conservative", version = "0.1" } -lightning = { version = "0.0.121" } +lightning = { version = "0.0.123" } log = "0.4.14" rust-bitcoin-coin-selection = { version = "0.1.0", git = "https://github.com/p2pderivatives/rust-bitcoin-coin-selection", rev = "405451929568422f7df809e35d6ad8f36fccce90", features = ["rand"] } simple-wallet = {path = "../simple-wallet"} diff --git a/bitcoin-test-utils/Cargo.toml b/bitcoin-test-utils/Cargo.toml index a2cde5b9..3ae75433 100644 --- a/bitcoin-test-utils/Cargo.toml +++ b/bitcoin-test-utils/Cargo.toml @@ -4,6 +4,6 @@ name = "bitcoin-test-utils" version = "0.1.0" [dependencies] -bitcoin = { version = "0.30.2", default-features = false } -bitcoincore-rpc = {version = "0.17"} -bitcoincore-rpc-json = {version = "0.17"} +bitcoin = { version = "0.31.2", default-features = false } +bitcoincore-rpc = {version = "0.19"} +bitcoincore-rpc-json = {version = "0.19"} diff --git a/dlc-manager/Cargo.toml b/dlc-manager/Cargo.toml index 9e696096..c8d344e8 100644 --- a/dlc-manager/Cargo.toml +++ b/dlc-manager/Cargo.toml @@ -17,15 +17,16 @@ use-serde = ["serde", "dlc/use-serde", "dlc-messages/serde", "dlc-trie/use-serde [dependencies] async-trait = "0.1.50" -bitcoin = { version = "0.30.2", default-features = false } +bitcoin = { version = "0.31.2", default-features = false } dlc = { version = "0.4.0", default-features = false, path = "../dlc" } dlc-messages = { version = "0.4.0", default-features = false, path = "../dlc-messages" } dlc-trie = { version = "0.4.0", default-features = false, path = "../dlc-trie" } hex = { package = "hex-conservative", version = "0.1" } -lightning = { version = "0.0.121", default-features = false, features = ["grind_signatures"] } +# lightning = { version = "0.0.123", default-features = false, features = ["grind_signatures"] } +lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", default-features = false, features = ["grind_signatures"] } log = "0.4.14" rand_chacha = {version = "0.3.1", optional = true} -secp256k1-zkp = {version = "0.9.2"} +secp256k1-zkp = {version = "0.10.1"} serde = {version = "1.0", optional = true} [dev-dependencies] @@ -39,7 +40,7 @@ dlc-messages = { path = "../dlc-messages", default-features = false, features = electrs-blockchain-provider = {path = "../electrs-blockchain-provider"} env_logger = "0.9.1" mocks = {path = "../mocks"} -secp256k1-zkp = {version = "0.9.2", features = ["bitcoin_hashes", "rand", "rand-std", "global-context", "serde"]} +secp256k1-zkp = {version = "0.10.1", features = ["rand", "rand-std", "global-context", "serde"]} serde = "1.0" serde_json = "1.0" simple-wallet = {path = "../simple-wallet"} diff --git a/dlc-manager/src/channel_updater.rs b/dlc-manager/src/channel_updater.rs index 681559e7..7f21f58b 100644 --- a/dlc-manager/src/channel_updater.rs +++ b/dlc-manager/src/channel_updater.rs @@ -225,7 +225,7 @@ where let buffer_adaptor_signature = get_tx_adaptor_signature( secp, &buffer_transaction, - dlc_transactions.get_fund_output().value, + dlc_transactions.get_fund_output().value.to_sat(), &dlc_transactions.funding_script_pubkey, &signer.get_secret_key()?, &offer_revoke_params.publish_pk.inner, @@ -237,7 +237,7 @@ where &accept_params, &funding_inputs, &own_secret_key, - buffer_transaction.output[0].value, + buffer_transaction.output[0].value.to_sat(), Some(&buffer_script_pubkey), &dlc_transactions, )?; @@ -359,7 +359,7 @@ where &accept_channel.funding_inputs, &accept_channel.refund_signature, &accept_cet_adaptor_signatures, - buffer_transaction.output[0].value, + buffer_transaction.output[0].value.to_sat(), wallet, &offer_own_sk, Some(&buffer_script_pubkey), @@ -371,7 +371,7 @@ where verify_tx_adaptor_signature( secp, &buffer_transaction, - dlc_transactions.get_fund_output().value, + dlc_transactions.get_fund_output().value.to_sat(), &dlc_transactions.funding_script_pubkey, &signed_contract.accepted_contract.accept_params.fund_pubkey, &offer_revoke_params.publish_pk.inner, @@ -381,7 +381,7 @@ where let own_buffer_adaptor_signature = get_tx_adaptor_signature( secp, &buffer_transaction, - dlc_transactions.get_fund_output().value, + dlc_transactions.get_fund_output().value.to_sat(), &dlc_transactions.funding_script_pubkey, &offer_fund_sk.get_secret_key()?, &accept_revoke_params.publish_pk.inner, @@ -457,7 +457,7 @@ where verify_tx_adaptor_signature( secp, &accepted_channel.buffer_transaction, - accepted_contract.dlc_transactions.get_fund_output().value, + accepted_contract.dlc_transactions.get_fund_output().value.to_sat(), &accepted_contract.dlc_transactions.funding_script_pubkey, &accepted_contract.offered_contract.offer_params.fund_pubkey, &own_publish_pk, @@ -472,7 +472,7 @@ where &sign_channel.refund_signature, &cet_adaptor_signatures, &sign_channel.funding_signatures, - accepted_channel.buffer_transaction.output[0].value, + accepted_channel.buffer_transaction.output[0].value.to_sat(), Some(&accepted_channel.buffer_script_pubkey), Some(counter_own_pk), wallet, @@ -840,7 +840,7 @@ where verify_tx_adaptor_signature( secp, settle_tx, - channel.fund_tx.output[channel.fund_output_index].value, + channel.fund_tx.output[channel.fund_output_index].value.to_sat(), &channel.fund_script_pubkey, &channel.counter_params.fund_pubkey, &accept_revoke_params.publish_pk.inner, @@ -1190,7 +1190,7 @@ where let buffer_adaptor_signature = get_tx_adaptor_signature( secp, &buffer_transaction, - dlc_transactions.get_fund_output().value, + dlc_transactions.get_fund_output().value.to_sat(), &dlc_transactions.funding_script_pubkey, &contract_signer.get_secret_key()?, &offer_revoke_params.publish_pk.inner, @@ -1204,7 +1204,7 @@ where &signed_channel.own_params, &[], &own_secret_key, - buffer_transaction.output[0].value, + buffer_transaction.output[0].value.to_sat(), Some(&buffer_script_pubkey), &dlc_transactions, )?; @@ -1318,7 +1318,7 @@ where &[], &renew_accept.refund_signature, &cet_adaptor_signatures, - buffer_transaction.output[0].value, + buffer_transaction.output[0].value.to_sat(), wallet, &offer_own_sk, Some(&buffer_script_pubkey), @@ -1330,7 +1330,7 @@ where verify_tx_adaptor_signature( secp, &buffer_transaction, - dlc_transactions.get_fund_output().value, + dlc_transactions.get_fund_output().value.to_sat(), &dlc_transactions.funding_script_pubkey, &signed_contract.accepted_contract.accept_params.fund_pubkey, &offer_revoke_params.publish_pk.inner, @@ -1340,7 +1340,7 @@ where let own_buffer_adaptor_signature = get_tx_adaptor_signature( secp, &buffer_transaction, - dlc_transactions.get_fund_output().value, + dlc_transactions.get_fund_output().value.to_sat(), &dlc_transactions.funding_script_pubkey, &contract_signer.get_secret_key()?, &accept_revoke_params.publish_pk.inner, @@ -1416,7 +1416,7 @@ where verify_tx_adaptor_signature( secp, buffer_transaction, - accepted_contract.dlc_transactions.get_fund_output().value, + accepted_contract.dlc_transactions.get_fund_output().value.to_sat(), &accepted_contract.dlc_transactions.funding_script_pubkey, &accepted_contract.offered_contract.offer_params.fund_pubkey, &own_publish_pk, @@ -1431,7 +1431,7 @@ where &FundingSignatures { funding_signatures: Vec::new(), }, - buffer_transaction.output[0].value, + buffer_transaction.output[0].value.to_sat(), Some(buffer_script_pubkey), Some(counter_own_pk), wallet, @@ -1573,7 +1573,7 @@ where let total_collateral = signed_channel.own_params.collateral + signed_channel.counter_params.collateral; let offer_payout = total_collateral - counter_payout; - let fund_output_value = signed_channel.fund_tx.output[signed_channel.fund_output_index].value; + let fund_output_value = signed_channel.fund_tx.output[signed_channel.fund_output_index].value.to_sat(); let close_tx = dlc::channel::create_collaborative_close_transaction( &signed_channel.own_params, @@ -1648,7 +1648,7 @@ where } let offer_payout = total_collateral - close_offer.counter_payout; - let fund_output_value = signed_channel.fund_tx.output[signed_channel.fund_output_index].value; + let fund_output_value = signed_channel.fund_tx.output[signed_channel.fund_output_index].value.to_sat(); let close_tx = dlc::channel::create_collaborative_close_transaction( &signed_channel.counter_params, @@ -1695,7 +1695,7 @@ where keys_id )?; - let fund_out_amount = signed_channel.fund_tx.output[signed_channel.fund_output_index].value; + let fund_out_amount = signed_channel.fund_tx.output[signed_channel.fund_output_index].value.to_sat(); let contract_signer = signer_provider.derive_contract_signer(*keys_id)?; @@ -1771,7 +1771,7 @@ fn get_settle_tx_and_adaptor_sig( accept_payout, csv_timelock, lock_time, - fund_tx.output[fund_vout].value, + fund_tx.output[fund_vout].value.to_sat(), fee_rate_per_vb, )?; @@ -1779,7 +1779,7 @@ fn get_settle_tx_and_adaptor_sig( verify_tx_adaptor_signature( secp, &settle_tx, - fund_tx.output[fund_vout].value, + fund_tx.output[fund_vout].value.to_sat(), funding_script_pubkey, &fund_pk, &offer_revoke_params.publish_pk.inner, @@ -1796,7 +1796,7 @@ fn get_settle_tx_and_adaptor_sig( let settle_adaptor_signature = dlc::channel::get_tx_adaptor_signature( secp, &settle_tx, - fund_tx.output[fund_vout].value, + fund_tx.output[fund_vout].value.to_sat(), funding_script_pubkey, own_fund_sk, &counter_pk, @@ -1878,7 +1878,7 @@ where &signed_channel.counter_params.fund_pubkey, &fund_sk.get_secret_key()?, &signed_channel.fund_script_pubkey, - signed_channel.fund_tx.output[signed_channel.fund_output_index].value, + signed_channel.fund_tx.output[signed_channel.fund_output_index].value.to_sat(), 0, )?; @@ -1951,7 +1951,7 @@ where dlc::channel::sign_cet( secp, &mut cet, - buffer_transaction.output[0].value, + buffer_transaction.output[0].value.to_sat(), &offer_revoke_params, &accept_revoke_params, &own_sk, @@ -2009,7 +2009,7 @@ where &signed_channel.counter_params.fund_pubkey, &fund_sk.get_secret_key()?, &signed_channel.fund_script_pubkey, - signed_channel.fund_tx.output[signed_channel.fund_output_index].value, + signed_channel.fund_tx.output[signed_channel.fund_output_index].value.to_sat(), 0, )?; diff --git a/dlc-manager/src/contract/accepted_contract.rs b/dlc-manager/src/contract/accepted_contract.rs index 1549ce98..030f961d 100644 --- a/dlc-manager/src/contract/accepted_contract.rs +++ b/dlc-manager/src/contract/accepted_contract.rs @@ -89,7 +89,7 @@ impl AcceptedContract { .iter() .find_map(|x| { if &x.script_pubkey == v0_witness_payout_script { - Some(x.value) + Some(x.value.to_sat()) } else { None } diff --git a/dlc-manager/src/contract_updater.rs b/dlc-manager/src/contract_updater.rs index 2f42a49c..b8265227 100644 --- a/dlc-manager/src/contract_updater.rs +++ b/dlc-manager/src/contract_updater.rs @@ -2,7 +2,7 @@ use std::ops::Deref; -use bitcoin::psbt::PartiallySignedTransaction; +use bitcoin::psbt::Psbt; use bitcoin::{consensus::Decodable, Script, Transaction, Witness}; use dlc::{DlcTransactions, PartyParams}; use dlc_messages::FundingInput; @@ -112,7 +112,7 @@ where offered_contract.fund_output_serial_id, )?; - let fund_output_value = dlc_transactions.get_fund_output().value; + let fund_output_value = dlc_transactions.get_fund_output().value.to_sat(); let (accepted_contract, adaptor_sigs) = accept_contract_internal( secp, @@ -272,7 +272,7 @@ where offered_contract.cet_locktime, offered_contract.fund_output_serial_id, )?; - let fund_output_value = dlc_transactions.get_fund_output().value; + let fund_output_value = dlc_transactions.get_fund_output().value.to_sat(); let signer = signer_provider.derive_contract_signer(offered_contract.keys_id)?; let (signed_contract, adaptor_sigs) = verify_accepted_and_sign_contract_internal( @@ -297,7 +297,7 @@ where } fn populate_psbt( - psbt: &mut PartiallySignedTransaction, + psbt: &mut Psbt, all_funding_inputs: &[&FundingInput], ) -> Result<(), Error> { // add witness utxo to fund_psbt for all inputs @@ -344,7 +344,7 @@ where funding_script_pubkey, } = dlc_transactions; - let mut fund_psbt = PartiallySignedTransaction::from_unsigned_tx(fund.clone()) + let mut fund_psbt = Psbt::from_unsigned_tx(fund.clone()) .map_err(|_| Error::InvalidState("Tried to create PSBT from signed tx".to_string()))?; let mut cets = cets.clone(); @@ -536,7 +536,7 @@ where &sign_msg.refund_signature, &cet_adaptor_signatures, &sign_msg.funding_signatures, - accepted_contract.dlc_transactions.get_fund_output().value, + accepted_contract.dlc_transactions.get_fund_output().value.to_sat(), None, None, wallet, @@ -595,7 +595,7 @@ where } let fund_tx = &accepted_contract.dlc_transactions.fund; - let mut fund_psbt = PartiallySignedTransaction::from_unsigned_tx(fund_tx.clone()) + let mut fund_psbt = Psbt::from_unsigned_tx(fund_tx.clone()) .map_err(|_| Error::InvalidState("Tried to create PSBT from signed tx".to_string()))?; // get all funding inputs @@ -655,7 +655,7 @@ where channel_id, }; - Ok((signed_contract, fund_psbt.extract_tx())) + Ok((signed_contract, fund_psbt.extract_tx()?)) } /// Signs and return the CET that can be used to close the given contract. @@ -708,7 +708,7 @@ where .accepted_contract .dlc_transactions .get_fund_output() - .value, + .value.to_sat(), )?; Ok(cet) @@ -726,7 +726,7 @@ where let accepted_contract = &contract.accepted_contract; let offered_contract = &accepted_contract.offered_contract; let funding_script_pubkey = &accepted_contract.dlc_transactions.funding_script_pubkey; - let fund_output_value = accepted_contract.dlc_transactions.get_fund_output().value; + let fund_output_value = accepted_contract.dlc_transactions.get_fund_output().value.to_sat(); let (other_fund_pubkey, other_sig) = if offered_contract.is_offer_party { ( &accepted_contract.accept_params.fund_pubkey, diff --git a/dlc-manager/src/conversion_utils.rs b/dlc-manager/src/conversion_utils.rs index 8642935b..73214f5d 100644 --- a/dlc-manager/src/conversion_utils.rs +++ b/dlc-manager/src/conversion_utils.rs @@ -82,7 +82,7 @@ pub fn get_tx_input_infos( .output .get(vout as usize) .ok_or(Error::InvalidParameters)?; - input_amount += tx_out.value; + input_amount += tx_out.value.to_sat(); inputs.push(TxInputInfo { outpoint: OutPoint { txid: tx.txid(), diff --git a/dlc-manager/src/error.rs b/dlc-manager/src/error.rs index 98409155..9bd0794f 100644 --- a/dlc-manager/src/error.rs +++ b/dlc-manager/src/error.rs @@ -25,6 +25,8 @@ pub enum Error { DlcError(dlc::Error), /// An error occurred in the Secp library. SecpError(secp256k1_zkp::Error), + /// An error occured extracting a PSBT. + ExtractPsbt(bitcoin::psbt::ExtractTxError) } impl fmt::Display for Error { @@ -40,6 +42,7 @@ impl fmt::Display for Error { Error::DlcError(ref e) => write!(f, "Dlc error {}", e), Error::OracleError(ref s) => write!(f, "Oracle error {}", s), Error::SecpError(_) => write!(f, "Secp error"), + Error::ExtractPsbt(_) => write!(f, "PSBT error"), } } } @@ -74,6 +77,12 @@ impl From for Error { } } +impl From for Error { + fn from(e: bitcoin::psbt::ExtractTxError) -> Self { + Error::ExtractPsbt(e) + } +} + #[cfg(feature = "std")] impl std::error::Error for Error { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { @@ -88,6 +97,7 @@ impl std::error::Error for Error { Error::OracleError(_) => None, Error::DlcError(e) => Some(e), Error::SecpError(e) => Some(e), + Error::ExtractPsbt(e) => Some(e) } } } diff --git a/dlc-manager/src/lib.rs b/dlc-manager/src/lib.rs index 524c6951..fc4ab6df 100644 --- a/dlc-manager/src/lib.rs +++ b/dlc-manager/src/lib.rs @@ -36,7 +36,7 @@ pub mod manager; pub mod payout_curve; mod utils; -use bitcoin::psbt::PartiallySignedTransaction; +use bitcoin::psbt::Psbt; use bitcoin::{Address, Block, OutPoint, ScriptBuf, Transaction, TxOut, Txid}; use chain_monitor::ChainMonitor; use channel::offered_channel::OfferedChannel; @@ -164,7 +164,7 @@ pub trait Wallet { /// Signs a transaction input fn sign_psbt_input( &self, - psbt: &mut PartiallySignedTransaction, + psbt: &mut Psbt, input_index: usize, ) -> Result<(), Error>; /// Unlock reserved utxo @@ -176,7 +176,7 @@ pub trait Blockchain { /// Broadcast the given transaction to the bitcoin network. fn send_transaction(&self, transaction: &Transaction) -> Result<(), Error>; /// Returns the network currently used (mainnet, testnet or regtest). - fn get_network(&self) -> Result; + fn get_network(&self) -> Result; /// Returns the height of the blockchain fn get_blockchain_height(&self) -> Result; /// Returns the block at given height diff --git a/dlc-manager/src/utils.rs b/dlc-manager/src/utils.rs index ec9934a5..6dda7f69 100644 --- a/dlc-manager/src/utils.rs +++ b/dlc-manager/src/utils.rs @@ -104,7 +104,7 @@ where max_witness_len, redeem_script: utxo.redeem_script, }; - total_input += prev_tx.output[prev_tx_vout as usize].value; + total_input += prev_tx.output[prev_tx_vout as usize].value.to_sat(); funding_tx_info.push((&funding_input).into()); funding_inputs.push(funding_input); } diff --git a/dlc-messages/Cargo.toml b/dlc-messages/Cargo.toml index 07d476a2..6fe3418f 100644 --- a/dlc-messages/Cargo.toml +++ b/dlc-messages/Cargo.toml @@ -10,19 +10,20 @@ version = "0.4.0" [features] default = ["std"] std = ["dlc/std", "bitcoin/std", "lightning/std"] -no-std = ["bitcoin/no-std", "dlc/no-std", "lightning/no-std"] +no-std = ["dlc/no-std", "lightning/no-std"] use-serde = ["serde", "secp256k1-zkp/serde", "bitcoin/serde"] [dependencies] -bitcoin = { version = "0.30.2", default-features = false } +bitcoin = { version = "0.31.2", default-features = false } dlc = { version = "0.4.0", path = "../dlc", default-features = false } -lightning = { version = "0.0.121", default-features = false } -secp256k1-zkp = {version = "0.9.2"} +# lightning = { version = "0.0.123", default-features = false } +lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", default-features = false } +secp256k1-zkp = {version = "0.10.1"} serde = {version = "1.0", features = ["derive"], optional = true} [dev-dependencies] bitcoin = { version = "0.30.2", default-features = false, features = ["serde"] } dlc-messages = {path = "./", default-features = false, features = ["use-serde"]} -secp256k1-zkp = {version = "0.9.2", features = ["serde", "global-context"]} +secp256k1-zkp = {version = "0.10.1", features = ["serde", "global-context"]} serde = {version = "1.0", features = ["derive"]} serde_json = "1.0" diff --git a/dlc-messages/src/ser_impls.rs b/dlc-messages/src/ser_impls.rs index 0406f3d0..247a66ca 100644 --- a/dlc-messages/src/ser_impls.rs +++ b/dlc-messages/src/ser_impls.rs @@ -1,6 +1,6 @@ //! Set of utility functions to help with serialization. -use bitcoin::network::constants::Network; +use bitcoin::Network; use bitcoin::Address; use dlc::{EnumerationPayout, PartyParams, Payout, TxInputInfo}; use lightning::io::Read; @@ -478,7 +478,7 @@ pub fn write_address( writer: &mut W, ) -> Result<(), ::lightning::io::Error> { address.script_pubkey().write(writer)?; - let net: u8 = match address.network { + let net: u8 = match address.network() { Network::Bitcoin => 0, Network::Testnet => 1, Network::Signet => 2, diff --git a/dlc-sled-storage-provider/Cargo.toml b/dlc-sled-storage-provider/Cargo.toml index f90fc5b9..d193fed3 100644 --- a/dlc-sled-storage-provider/Cargo.toml +++ b/dlc-sled-storage-provider/Cargo.toml @@ -12,9 +12,10 @@ version = "0.1.0" wallet = ["bitcoin", "secp256k1-zkp", "simple-wallet", "lightning"] [dependencies] -bitcoin = {version = "0.30", optional = true} +bitcoin = {version = "0.31.2", optional = true} dlc-manager = {path = "../dlc-manager"} -lightning = {version = "0.0.121", optional = true} -secp256k1-zkp = {version = "0.9", optional = true} +# lightning = {version = "0.0.123", optional = true} +lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", default-features = false, optional = true } +secp256k1-zkp = {version = "0.10.1", optional = true} simple-wallet = {path = "../simple-wallet", optional = true} sled = "0.34" diff --git a/dlc-trie/Cargo.toml b/dlc-trie/Cargo.toml index 746d1ed1..0ba015cd 100644 --- a/dlc-trie/Cargo.toml +++ b/dlc-trie/Cargo.toml @@ -10,13 +10,13 @@ version = "0.4.0" [features] default = ["std"] std = ["dlc/std", "bitcoin/std"] -no-std = ["bitcoin/no-std", "dlc/no-std"] +no-std = ["dlc/no-std"] parallel = ["rayon"] use-serde = ["serde", "dlc/use-serde"] [dependencies] -bitcoin = { version = "0.30.2", default-features = false } +bitcoin = { version = "0.31.2", default-features = false } dlc = {version = "0.4.0", default-features = false, path = "../dlc"} rayon = {version = "1.5", optional = true} -secp256k1-zkp = {version = "0.9.2" } +secp256k1-zkp = {version = "0.10.1" } serde = {version = "1.0", optional = true, default_features = false, features = ["derive"]} diff --git a/dlc/Cargo.toml b/dlc/Cargo.toml index 96f00841..d468877f 100644 --- a/dlc/Cargo.toml +++ b/dlc/Cargo.toml @@ -8,11 +8,11 @@ repository = "https://github.com/p2pderivatives/rust-dlc/tree/master/dlc" version = "0.4.0" [dependencies] -bitcoin = { version = "0.30.2", default-features = false } +bitcoin = { version = "0.31.2", default-features = false } hashbrown = { version = "0.11.2", optional = true } -miniscript = { version = "10", default-features = false } -secp256k1-sys = "0.8.1" -secp256k1-zkp = "0.9.2" +miniscript = { version = "11", default-features = false } +secp256k1-sys = "0.10.0" +secp256k1-zkp = "0.10.1" serde = { version = "1.0", default-features = false, optional = true } [features] @@ -20,7 +20,7 @@ serde = { version = "1.0", default-features = false, optional = true } unstable = [] default = ["std"] std = ["bitcoin/std", "miniscript/std", "secp256k1-zkp/rand-std"] -no-std = ["dep:hashbrown", "miniscript/no-std", "bitcoin/no-std"] +no-std = ["dep:hashbrown", "miniscript/no-std"] use-serde = ["serde", "secp256k1-zkp/serde", "bitcoin/serde"] [dev-dependencies] @@ -28,4 +28,4 @@ bitcoin-test-utils = { path = "../bitcoin-test-utils" } bitcoincore-rpc = { version = "0.17.0" } bitcoincore-rpc-json = { version = "0.17.0" } rayon = "1.5" -secp256k1-zkp = { version = "0.9.2", features = ["bitcoin_hashes", "rand","serde", "global-context"] } +secp256k1-zkp = { version = "0.10.1", features = ["rand", "serde", "global-context"] } diff --git a/dlc/src/channel/mod.rs b/dlc/src/channel/mod.rs index 205e6310..45556d78 100644 --- a/dlc/src/channel/mod.rs +++ b/dlc/src/channel/mod.rs @@ -13,8 +13,7 @@ use crate::{signatures_to_secret, util::get_sig_hash_msg, DlcTransactions, Party use super::Error; use bitcoin::{ - absolute::LockTime, ecdsa::Signature, sighash::EcdsaSighashType, Address, OutPoint, PublicKey, - Script, ScriptBuf, Sequence, Transaction, TxIn, TxOut, Witness, + absolute::LockTime, ecdsa::Signature, sighash::EcdsaSighashType, Address, Amount, OutPoint, PublicKey, Script, ScriptBuf, Sequence, Transaction, TxIn, TxOut, Witness }; use miniscript::Descriptor; use secp256k1_zkp::{ @@ -125,7 +124,7 @@ pub fn create_buffer_transaction( lock_time: LockTime::from_consensus(lock_time), input: vec![fund_tx_in.clone()], output: vec![TxOut { - value: total_collateral, + value: Amount::from_sat(total_collateral), script_pubkey: descriptor.script_pubkey(), }], } @@ -197,11 +196,11 @@ pub fn create_settle_transaction( let mut output = crate::util::discard_dust( vec![ TxOut { - value: offer_payout, + value: Amount::from_sat(offer_payout), script_pubkey: offer_descriptor.script_pubkey(), }, TxOut { - value: accept_payout, + value: Amount::from_sat(accept_payout), script_pubkey: accept_descriptor.script_pubkey(), }, ], @@ -220,7 +219,7 @@ pub fn create_settle_transaction( / (output.len() as u64); for o in &mut output { - o.value += remaining_fee; + o.value += Amount::from_sat(remaining_fee); } Ok(Transaction { @@ -290,7 +289,7 @@ pub fn create_renewal_channel_transactions( super::util::weight_to_fee(BUFFER_TX_WEIGHT + CET_EXTRA_WEIGHT, fee_rate_per_vb)?; let (fund_vout, fund_output) = - super::util::get_output_for_script_pubkey(fund_tx, &funding_script_pubkey.to_v0_p2wsh()) + super::util::get_output_for_script_pubkey(fund_tx, &funding_script_pubkey.to_p2wsh()) .expect("to find the funding script pubkey"); let outpoint = OutPoint { @@ -310,7 +309,7 @@ pub fn create_renewal_channel_transactions( let buffer_transaction = create_buffer_transaction( &tx_in, &buffer_descriptor, - fund_output.value - extra_fee, + fund_output.value.to_sat() - extra_fee, cet_lock_time, ); @@ -426,14 +425,14 @@ pub fn create_and_sign_punish_buffer_transaction( let tx_fee = crate::util::weight_to_fee(PUNISH_BUFFER_INPUT_WEIGHT + output_weight, fee_rate_per_vb)?; - let output_value = prev_tx.output[0].value - tx_fee; + let output_value = prev_tx.output[0].value.to_sat() - tx_fee; let mut tx = Transaction { version: super::TX_VERSION, lock_time: LockTime::from_consensus(lock_time), input: vec![tx_in], output: vec![TxOut { - value: output_value, + value: Amount::from_sat(output_value), script_pubkey: dest_address.script_pubkey(), }], }; @@ -457,7 +456,7 @@ pub fn create_and_sign_punish_buffer_transaction( &tx, 0, &descriptor.script_code()?, - prev_tx.output[0].value, + prev_tx.output[0].value.to_sat(), sk, )?, hash_ty: EcdsaSighashType::All, @@ -508,7 +507,7 @@ pub fn create_and_sign_punish_settle_transaction( witness: Witness::default(), }; - let input_value = prev_tx.output[vout as usize].value; + let input_value = prev_tx.output[vout as usize].value.to_sat(); let dest_script_pk_len = dest_address.script_pubkey().len(); let var_int_prefix_len = crate::util::compute_var_int_prefix_size(dest_script_pk_len); @@ -521,7 +520,7 @@ pub fn create_and_sign_punish_settle_transaction( lock_time: LockTime::from_consensus(lock_time), input: vec![tx_in], output: vec![TxOut { - value: input_value - tx_fee, + value: Amount::from_sat(input_value - tx_fee), script_pubkey: dest_address.script_pubkey(), }], }; @@ -571,12 +570,12 @@ pub fn create_collaborative_close_transaction( //TODO(tibo): add fee re-payment let offer_output = TxOut { - value: offer_payout, + value: Amount::from_sat(offer_payout), script_pubkey: offer_params.payout_script_pubkey.clone(), }; let accept_output = TxOut { - value: accept_payout, + value: Amount::from_sat(accept_payout), script_pubkey: accept_params.payout_script_pubkey.clone(), }; diff --git a/dlc/src/lib.rs b/dlc/src/lib.rs index b29d1f7a..c685caaa 100644 --- a/dlc/src/lib.rs +++ b/dlc/src/lib.rs @@ -21,6 +21,8 @@ pub extern crate secp256k1_zkp; extern crate serde; use bitcoin::secp256k1::Scalar; +use bitcoin::transaction::Version; +use bitcoin::Amount; use bitcoin::{ absolute::LockTime, blockdata::{ @@ -50,7 +52,7 @@ const DUST_LIMIT: u64 = 1000; /// The transaction version /// See: https://github.com/discreetlogcontracts/dlcspecs/blob/master/Transactions.md#funding-transaction -const TX_VERSION: i32 = 2; +const TX_VERSION: Version = Version(2); /// The base weight of a fund transaction /// See: https://github.com/discreetlogcontracts/dlcspecs/blob/master/Transactions.md#fees @@ -132,7 +134,7 @@ pub struct DlcTransactions { impl DlcTransactions { /// Get the fund output in the fund transaction pub fn get_fund_output(&self) -> &TxOut { - let v0_witness_fund_script = self.funding_script_pubkey.to_v0_p2wsh(); + let v0_witness_fund_script = self.funding_script_pubkey.to_p2wsh(); util::get_output_for_script_pubkey(&self.fund, &v0_witness_fund_script) .unwrap() .1 @@ -140,7 +142,7 @@ impl DlcTransactions { /// Get the fund output in the fund transaction pub fn get_fund_output_index(&self) -> usize { - let v0_witness_fund_script = self.funding_script_pubkey.to_v0_p2wsh(); + let v0_witness_fund_script = self.funding_script_pubkey.to_p2wsh(); util::get_output_for_script_pubkey(&self.fund, &v0_witness_fund_script) .unwrap() .0 @@ -333,7 +335,7 @@ impl PartyParams { } let change_output = TxOut { - value: self.input_amount - required_input_funds, + value: Amount::from_sat(self.input_amount - required_input_funds), script_pubkey: self.change_script_pubkey.clone(), }; @@ -380,7 +382,7 @@ pub fn create_dlc_transactions( )?; let fund_outpoint = OutPoint { txid: fund_tx.txid(), - vout: util::get_output_for_script_pubkey(&fund_tx, &funding_script_pubkey.to_v0_p2wsh()) + vout: util::get_output_for_script_pubkey(&fund_tx, &funding_script_pubkey.to_p2wsh()) .expect("to find the funding script pubkey") .0 as u32, }; @@ -418,8 +420,8 @@ pub(crate) fn create_fund_transaction_with_fees( accept_params.get_change_output_and_fees(fee_rate_per_vb, extra_fee)?; let fund_output_value = checked_add!(offer_params.input_amount, accept_params.input_amount)? - - offer_change_output.value - - accept_change_output.value + - offer_change_output.value.to_sat() + - accept_change_output.value.to_sat() - offer_fund_fee - accept_fund_fee - extra_fee; @@ -432,8 +434,8 @@ pub(crate) fn create_fund_transaction_with_fees( assert_eq!( offer_params.input_amount + accept_params.input_amount, fund_output_value - + offer_change_output.value - + accept_change_output.value + + offer_change_output.value.to_sat() + + accept_change_output.value.to_sat() + offer_fund_fee + accept_fund_fee + extra_fee @@ -508,12 +510,12 @@ pub(crate) fn create_cets_and_refund_tx( ); let offer_refund_output = TxOut { - value: offer_params.collateral, + value: Amount::from_sat(offer_params.collateral), script_pubkey: offer_params.payout_script_pubkey.clone(), }; let accept_refund_ouput = TxOut { - value: accept_params.collateral, + value: Amount::from_sat(accept_params.collateral), script_pubkey: accept_params.payout_script_pubkey.clone(), }; @@ -572,11 +574,11 @@ pub fn create_cets( let mut txs: Vec = Vec::new(); for payout in payouts { let offer_output = TxOut { - value: payout.offer, + value: Amount::from_sat(payout.offer), script_pubkey: offer_payout_script_pubkey.to_owned(), }; let accept_output = TxOut { - value: payout.accept, + value: Amount::from_sat(payout.accept), script_pubkey: accept_payout_script_pubkey.to_owned(), }; let tx = create_cet( @@ -610,8 +612,8 @@ pub fn create_funding_transaction( lock_time: u32, ) -> Transaction { let fund_tx_out = TxOut { - value: output_amount, - script_pubkey: funding_script_pubkey.to_v0_p2wsh(), + value: Amount::from_sat(output_amount), + script_pubkey: funding_script_pubkey.to_p2wsh(), }; let output: Vec = { @@ -918,10 +920,10 @@ mod tests { use bitcoin::blockdata::transaction::OutPoint; use bitcoin::consensus::encode::Encodable; use bitcoin::sighash::EcdsaSighashType; - use bitcoin::{network::constants::Network, Address, Txid}; + use bitcoin::{Network, Address, Txid}; use secp256k1_zkp::{ rand::{Rng, RngCore}, - KeyPair, PublicKey, Secp256k1, SecretKey, Signing, + Keypair, PublicKey, Secp256k1, SecretKey, Signing, }; use std::fmt::Write; use std::str::FromStr; @@ -952,12 +954,12 @@ mod tests { fn create_test_tx_io() -> (TxOut, TxOut, TxIn) { let offer = TxOut { - value: DUST_LIMIT + 1, + value: Amount::from_sat(DUST_LIMIT + 1), script_pubkey: ScriptBuf::new(), }; let accept = TxOut { - value: DUST_LIMIT + 2, + value: Amount::from_sat(DUST_LIMIT + 2), script_pubkey: ScriptBuf::new(), }; @@ -976,10 +978,10 @@ mod tests { let (offer, accept, funding) = create_test_tx_io(); let refund_transaction = create_refund_transaction(offer, accept, funding, 0); - assert_eq!(2, refund_transaction.version); + assert_eq!(2, refund_transaction.version.0); assert_eq!(0, refund_transaction.lock_time.to_consensus_u32()); - assert_eq!(DUST_LIMIT + 1, refund_transaction.output[0].value); - assert_eq!(DUST_LIMIT + 2, refund_transaction.output[1].value); + assert_eq!(DUST_LIMIT + 1, refund_transaction.output[0].value.to_sat()); + assert_eq!(DUST_LIMIT + 2, refund_transaction.output[1].value.to_sat()); assert_eq!(3, refund_transaction.input[0].sequence.0); } @@ -990,9 +992,9 @@ mod tests { let offer_inputs = create_txin_vec(Sequence::ZERO); let accept_inputs = create_txin_vec(Sequence(1)); - let change = 1000; + let change = Amount::from_sat(1000); - let total_collateral = 31415; + let total_collateral = Amount::from_sat(31415); let offer_change_output = TxOut { value: change, @@ -1006,7 +1008,7 @@ mod tests { let transaction = create_funding_transaction( &funding_script_pubkey, - total_collateral, + total_collateral.to_sat(), &offer_inputs, &[1], &accept_inputs, @@ -1035,8 +1037,8 @@ mod tests { let offer_inputs = create_txin_vec(Sequence::ZERO); let accept_inputs = create_txin_vec(Sequence(1)); - let total_collateral = 31415; - let change = 999; + let total_collateral = Amount::from_sat(31415); + let change = Amount::from_sat(999); let offer_change_output = TxOut { value: change, @@ -1051,7 +1053,7 @@ mod tests { let transaction = create_funding_transaction( &funding_script_pubkey, - total_collateral, + total_collateral.to_sat(), &offer_inputs, &[1], &accept_inputs, @@ -1071,8 +1073,8 @@ mod tests { #[test] fn create_funding_transaction_serialized_test() { let secp = Secp256k1::new(); - let input_amount = 5000000000; - let change = 4899999719; + let input_amount = Amount::from_sat(5000000000); + let change = Amount::from_sat(4899999719); let total_collateral = 200000312; let offer_change_address = Address::from_str("bcrt1qlgmznucxpdkp5k3ktsct7eh6qrc4tju7ktjukn") @@ -1257,7 +1259,7 @@ mod tests { party_params.get_change_output_and_fees(4, 0).unwrap(); // Assert - assert!(change_out.value > 0 && fund_fee > 0 && cet_fee > 0); + assert!(change_out.value.to_sat() > 0 && fund_fee > 0 && cet_fee > 0); } #[test] @@ -1325,7 +1327,7 @@ mod tests { const NB_OUTCOMES: usize = 2; const NB_DIGITS: usize = 20; let mut oracle_infos: Vec = Vec::with_capacity(NB_ORACLES); - let mut oracle_sks: Vec = Vec::with_capacity(NB_ORACLES); + let mut oracle_sks: Vec = Vec::with_capacity(NB_ORACLES); let mut oracle_sk_nonce: Vec> = Vec::with_capacity(NB_ORACLES); let mut oracle_sigs: Vec> = Vec::with_capacity(NB_ORACLES); let messages: Vec>> = (0..NB_OUTCOMES) @@ -1345,15 +1347,20 @@ mod tests { .collect(); for i in 0..NB_ORACLES { - let oracle_kp = KeyPair::new(&secp, &mut rng); - let oracle_pubkey = oracle_kp.x_only_public_key().0; + + // Fix me with bitcoin::key::Secp + let oracle_kp = unsafe { secp256k1_zkp::secp256k1_zkp_sys::Keypair::new() }; + let bytes = oracle_kp.underlying_bytes(); + let oracle_pubkey = XOnlyPublicKey::from_slice(&bytes).unwrap(); + // Fix me + let mut nonces: Vec = Vec::with_capacity(NB_DIGITS); let mut sk_nonces: Vec<[u8; 32]> = Vec::with_capacity(NB_DIGITS); oracle_sigs.push(Vec::with_capacity(NB_DIGITS)); for j in 0..NB_DIGITS { let mut sk_nonce = [0u8; 32]; rng.fill_bytes(&mut sk_nonce); - let oracle_r_kp = KeyPair::from_seckey_slice(&secp, &sk_nonce).unwrap(); + let oracle_r_kp = Keypair::from_seckey_slice(&secp, &sk_nonce).unwrap(); let nonce = XOnlyPublicKey::from_keypair(&oracle_r_kp).0; let sig = secp_utils::schnorrsig_sign_with_nonce( &secp, @@ -1386,7 +1393,7 @@ mod tests { &oracle_infos, &offer_fund_sk, &funding_script_pubkey, - fund_output_value, + fund_output_value.to_sat(), &messages, ) .unwrap(); @@ -1399,7 +1406,7 @@ mod tests { &accept_fund_sk, &offer_party_params.fund_pubkey, &funding_script_pubkey, - fund_output_value, + fund_output_value.to_sat(), ); let adaptor_secret = signatures_to_secret(&oracle_sigs).unwrap(); @@ -1416,7 +1423,7 @@ mod tests { &oracle_infos, &offer_party_params.fund_pubkey, &funding_script_pubkey, - fund_output_value, + fund_output_value.to_sat(), &messages[i], ) .is_ok())); @@ -1427,7 +1434,7 @@ mod tests { &cets[0], 0, &funding_script_pubkey, - fund_output_value, + fund_output_value.to_sat(), &offer_party_params.fund_pubkey, ) .expect("Invalid decrypted adaptor signature"); @@ -1503,7 +1510,7 @@ mod tests { // Check that fund output are in correct order assert!( dlc_txs.fund.output[case.expected_fund_output_order[0]].script_pubkey - == dlc_txs.funding_script_pubkey.to_v0_p2wsh() + == dlc_txs.funding_script_pubkey.to_p2wsh() ); assert!( dlc_txs.fund.output[case.expected_fund_output_order[1]].script_pubkey @@ -1526,7 +1533,7 @@ mod tests { crate::util::get_output_for_script_pubkey( &dlc_txs.fund, - &dlc_txs.funding_script_pubkey.to_v0_p2wsh(), + &dlc_txs.funding_script_pubkey.to_p2wsh(), ) .expect("Could not find fund output"); } diff --git a/dlc/src/secp_utils.rs b/dlc/src/secp_utils.rs index 606e41d1..8805d3dc 100644 --- a/dlc/src/secp_utils.rs +++ b/dlc/src/secp_utils.rs @@ -3,36 +3,35 @@ use crate::Error; use core::ptr; -use secp256k1_sys::{ - types::{c_int, c_uchar, c_void, size_t}, - CPtr, SchnorrSigExtraParams, -}; -use secp256k1_zkp::hashes::Hash; +use secp256k1_sys::types::{c_int, c_uchar, c_void, size_t}; +use secp256k1_zkp::secp256k1_zkp_sys::CPtr; +// use secp256k1_zkp::hashes::Hash; +// use bitcoin::hashes::sha256t_hash_newtype; use secp256k1_zkp::hashes::*; use secp256k1_zkp::{ - schnorr::Signature as SchnorrSignature, KeyPair, Message, PublicKey, Scalar, Secp256k1, - Signing, Verification, XOnlyPublicKey, + schnorr::Signature as SchnorrSignature, Message, PublicKey, Scalar, Secp256k1, + Signing, Verification, XOnlyPublicKey, secp256k1_zkp_sys::{Keypair, SchnorrSigExtraParams}, }; -const BIP340_MIDSTATE: [u8; 32] = [ - 0x9c, 0xec, 0xba, 0x11, 0x23, 0x92, 0x53, 0x81, 0x11, 0x67, 0x91, 0x12, 0xd1, 0x62, 0x7e, 0x0f, - 0x97, 0xc8, 0x75, 0x50, 0x00, 0x3c, 0xc7, 0x65, 0x90, 0xf6, 0x11, 0x64, 0x33, 0xe9, 0xb6, 0x6a, -]; +// const BIP340_MIDSTATE: [u8; 32] = [ +// 0x9c, 0xec, 0xba, 0x11, 0x23, 0x92, 0x53, 0x81, 0x11, 0x67, 0x91, 0x12, 0xd1, 0x62, 0x7e, 0x0f, +// 0x97, 0xc8, 0x75, 0x50, 0x00, 0x3c, 0xc7, 0x65, 0x90, 0xf6, 0x11, 0x64, 0x33, 0xe9, 0xb6, 0x6a, +// ]; + +sha256t_hash_newtype! { + /// BIP340 Hash Tag + pub struct BIP340HashTag = hash_str("bip340 hash"); -sha256t_hash_newtype!( - BIP340Hash, - BIP340HashTag, - BIP340_MIDSTATE, - 64, - doc = "bip340 hash", - backward -); + /// BIP340 Hash + #[hash_newtype(backward)] + pub struct BIP340Hash(_); +} /// Create a Schnorr signature using the provided nonce instead of generating one. pub fn schnorrsig_sign_with_nonce( secp: &Secp256k1, msg: &Message, - keypair: &KeyPair, + keypair: &Keypair, nonce: &[u8; 32], ) -> SchnorrSignature { unsafe { @@ -41,12 +40,12 @@ pub fn schnorrsig_sign_with_nonce( SchnorrSigExtraParams::new(Some(constant_nonce_fn), nonce.as_c_ptr() as *const c_void); assert_eq!( 1, - secp256k1_sys::secp256k1_schnorrsig_sign_custom( + secp256k1_zkp::secp256k1_zkp_sys::secp256k1_schnorrsig_sign_custom( secp.ctx().as_ref(), sig.as_mut_c_ptr(), msg.as_c_ptr(), 32_usize, - keypair.as_c_ptr(), + keypair, &extra_params, ) ); diff --git a/dlc/src/util.rs b/dlc/src/util.rs index bd910926..94734e9c 100644 --- a/dlc/src/util.rs +++ b/dlc/src/util.rs @@ -1,12 +1,14 @@ //! Utility functions not uniquely related to DLC -use bitcoin::address::{WitnessProgram, WitnessVersion}; +use bitcoin::blockdata::script::witness_program::WitnessProgram; +use bitcoin::blockdata::script::witness_version::WitnessVersion; +use bitcoin::hashes::Hash; use bitcoin::script::PushBytesBuf; use bitcoin::sighash::SighashCache; use bitcoin::{ - address::Payload, hash_types::PubkeyHash, sighash::EcdsaSighashType, Script, Transaction, TxOut, + address::Payload, sighash::EcdsaSighashType, Script, Transaction, TxOut, Amount, }; -use bitcoin::{ScriptBuf, Sequence, Witness}; +use bitcoin::{PubkeyHash, ScriptBuf, Sequence, Witness}; use secp256k1_zkp::{ecdsa::Signature, Message, PublicKey, Secp256k1, SecretKey, Signing}; use crate::Error; @@ -27,13 +29,14 @@ pub(crate) fn get_sig_hash_msg( script_pubkey: &Script, value: u64, ) -> Result { - let sig_hash = SighashCache::new(tx).segwit_signature_hash( - input_index, - script_pubkey, - value, - EcdsaSighashType::All, - )?; - Ok(Message::from_slice(sig_hash.as_ref()).unwrap()) + let sig_hash = SighashCache::new(tx).p2wsh_signature_hash(input_index, script_pubkey, Amount::from_sat(value), EcdsaSighashType::All)?; + // let sig_hash = SighashCache::new(tx).segwit_signature_hash( + // input_index, + // script_pubkey, + // value, + // EcdsaSighashType::All, + // )?; + Ok(Message::from_digest_slice(sig_hash.as_ref())?) } /// Convert a raw signature to DER encoded and append the sighash type, to use @@ -97,9 +100,10 @@ pub fn get_sig_for_p2wpkh_input( /// Returns the fee for the given weight at given fee rate. pub fn weight_to_fee(weight: usize, fee_rate: u64) -> Result { - (f64::ceil((weight as f64) / 4.0) as u64) + let fee = (f64::ceil((weight as f64) / 4.0) as u64) .checked_mul(fee_rate) - .ok_or(Error::InvalidArgument) + .ok_or(Error::InvalidArgument)?; + Ok(fee) } /// Return the common base fee for a DLC for the given fee rate. @@ -109,7 +113,7 @@ pub fn get_common_fee(fee_rate: u64) -> Result { } fn get_pkh_script_pubkey_from_sk(secp: &Secp256k1, sk: &SecretKey) -> ScriptBuf { - use bitcoin::hashes::*; + // use bitcoin::hashes::*; let pk = bitcoin::PublicKey { compressed: true, inner: PublicKey::from_secret_key(secp, sk), @@ -233,7 +237,7 @@ pub fn get_output_for_script_pubkey<'a>( /// Filters the outputs that have a value lower than the given `dust_limit`. pub(crate) fn discard_dust(txs: Vec, dust_limit: u64) -> Vec { - txs.into_iter().filter(|x| x.value >= dust_limit).collect() + txs.into_iter().filter(|x| x.value.to_sat() >= dust_limit).collect() } pub(crate) fn get_sequence(lock_time: u32) -> Sequence { @@ -245,7 +249,7 @@ pub(crate) fn get_sequence(lock_time: u32) -> Sequence { } pub(crate) fn compute_var_int_prefix_size(len: usize) -> usize { - bitcoin::VarInt(len as u64).len() + bitcoin::VarInt(len as u64).size() } /// Validate that the fee rate is not too high diff --git a/electrs-blockchain-provider/Cargo.toml b/electrs-blockchain-provider/Cargo.toml index 5e29da97..39570337 100644 --- a/electrs-blockchain-provider/Cargo.toml +++ b/electrs-blockchain-provider/Cargo.toml @@ -6,10 +6,10 @@ version = "0.1.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bitcoin = {version = "0.30"} +bitcoin = {version = "0.31.2"} bitcoin-test-utils = {path = "../bitcoin-test-utils"} dlc-manager = {path = "../dlc-manager"} -lightning = {version = "0.0.121"} +lightning = {version = "0.0.123"} lightning-block-sync = {version = "0.0.121"} reqwest = {version = "0.11", features = ["blocking", "json"]} serde = {version = "*", features = ["derive"]} diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index aea861b4..22218534 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -10,7 +10,7 @@ cargo-fuzz = true [dependencies] dlc-messages = {path = "../dlc-messages"} honggfuzz = "0.5" -lightning = {version = "0.0.121" } +lightning = {version = "0.0.123" } [workspace] members = ["."] diff --git a/mocks/Cargo.toml b/mocks/Cargo.toml index d543e6ba..5f701461 100644 --- a/mocks/Cargo.toml +++ b/mocks/Cargo.toml @@ -5,10 +5,10 @@ name = "mocks" version = "0.1.0" [dependencies] -bitcoin = "0.30" +bitcoin = "0.31.2" dlc = {path = "../dlc"} dlc-manager = {path = "../dlc-manager"} dlc-messages = {path = "../dlc-messages"} -lightning = {version = "0.0.121"} -secp256k1-zkp = {version = "0.9.2", features = ["bitcoin_hashes", "global-context", "rand", "rand-std"]} +lightning = {version = "0.0.123"} +secp256k1-zkp = {version = "0.10.1", features = ["global-context", "rand", "rand-std"]} simple-wallet = {path = "../simple-wallet"} diff --git a/p2pd-oracle-client/Cargo.toml b/p2pd-oracle-client/Cargo.toml index a28450d5..805e37ed 100644 --- a/p2pd-oracle-client/Cargo.toml +++ b/p2pd-oracle-client/Cargo.toml @@ -12,7 +12,7 @@ chrono = {version = "0.4.19", features = ["serde"]} dlc-manager = {path = "../dlc-manager"} dlc-messages = {path = "../dlc-messages", features = ["use-serde"]} reqwest = {version = "0.11", features = ["blocking", "json"]} -secp256k1-zkp = {version = "0.9.2" } +secp256k1-zkp = {version = "0.10.1" } serde = {version = "*", features = ["derive"]} [dev-dependencies] diff --git a/sample/Cargo.toml b/sample/Cargo.toml index 83f11fcb..2e5d69ec 100644 --- a/sample/Cargo.toml +++ b/sample/Cargo.toml @@ -5,14 +5,14 @@ name = "sample" version = "0.1.0" [dependencies] -bitcoin = {version = "0.30.2"} +bitcoin = {version = "0.31.2"} bitcoin-rpc-provider = {path = "../bitcoin-rpc-provider"} -dlc = {path = "../dlc", features = ["use-serde"]} +dlc = {version = "0.4.0", path = "../dlc", features = ["use-serde"]} dlc-manager = {path = "../dlc-manager", features = ["use-serde", "parallel"]} dlc-messages = {path = "../dlc-messages"} dlc-sled-storage-provider = {path = "../dlc-sled-storage-provider"} futures = "0.3" -lightning = {version = "0.0.121"} +lightning = {version = "0.0.123"} lightning-net-tokio = {version = "0.0.121" } p2pd-oracle-client = {path = "../p2pd-oracle-client"} serde = "1.0" diff --git a/simple-wallet/Cargo.toml b/simple-wallet/Cargo.toml index 1d680023..2104747e 100644 --- a/simple-wallet/Cargo.toml +++ b/simple-wallet/Cargo.toml @@ -6,13 +6,14 @@ version = "0.1.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bitcoin = "0.30" +bitcoin = "0.31.2" dlc = {path = "../dlc"} dlc-manager = {path = "../dlc-manager"} -lightning = {version = "0.0.121"} +# lightning = {version = "0.0.121"} +lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" } bdk = {version = "0.29.0"} -secp256k1-zkp = {version = "0.9.2"} +secp256k1-zkp = {version = "0.10.1"} [dev-dependencies] mocks = {path = "../mocks"} -secp256k1-zkp = {version = "0.9.2", features = ["global-context"]} +secp256k1-zkp = {version = "0.10.1", features = ["global-context"]}