diff --git a/Cargo.toml b/Cargo.toml index 745810ad..4843100a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,5 @@ members = [ "dlc-sled-storage-provider", "electrs-blockchain-provider", ] + +resolver = "2" diff --git a/bitcoin-rpc-provider/Cargo.toml b/bitcoin-rpc-provider/Cargo.toml index 3d6bff11..2796eb2d 100644 --- a/bitcoin-rpc-provider/Cargo.toml +++ b/bitcoin-rpc-provider/Cargo.toml @@ -5,11 +5,12 @@ name = "bitcoin-rpc-provider" version = "0.1.0" [dependencies] -bitcoin = {version = "0.29.2"} -bitcoincore-rpc = {version = "0.16.0"} -bitcoincore-rpc-json = {version = "0.16.0"} +bitcoin = {version = "0.30.2"} +bitcoincore-rpc = {version = "0.17.0"} +bitcoincore-rpc-json = {version = "0.17.0"} dlc-manager = {path = "../dlc-manager"} -lightning = { version = "0.0.118" } +hex = { package = "hex-conservative", version = "0.1" } +lightning = { version = "0.0.121" } 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-rpc-provider/src/lib.rs b/bitcoin-rpc-provider/src/lib.rs index 72a9d402..43b2e217 100644 --- a/bitcoin-rpc-provider/src/lib.rs +++ b/bitcoin-rpc-provider/src/lib.rs @@ -1,28 +1,27 @@ //! # Bitcoin rpc provider -use std::cmp::max; use std::collections::HashMap; use std::sync::atomic::{AtomicU32, Ordering}; use std::sync::{Arc, Mutex}; use std::time::Duration; +use bitcoin::address::NetworkUnchecked; use bitcoin::consensus::encode::Error as EncodeError; -use bitcoin::hashes::hex::ToHex; use bitcoin::hashes::serde; use bitcoin::psbt::PartiallySignedTransaction; use bitcoin::secp256k1::rand::thread_rng; use bitcoin::secp256k1::{PublicKey, SecretKey}; use bitcoin::{ - consensus::Decodable, network::constants::Network, Amount, PrivateKey, Script, Transaction, - Txid, + consensus::Decodable, network::constants::Network, Amount, PrivateKey, Transaction, Txid, }; -use bitcoin::{Address, OutPoint, TxOut}; +use bitcoin::{Address, OutPoint, ScriptBuf, TxOut}; use bitcoincore_rpc::jsonrpc::serde_json; use bitcoincore_rpc::jsonrpc::serde_json::Value; use bitcoincore_rpc::{json, Auth, Client, RpcApi}; use bitcoincore_rpc_json::AddressType; use dlc_manager::error::Error as ManagerError; use dlc_manager::{Blockchain, ContractSignerProvider, SimpleSigner, Utxo, Wallet}; +use hex::DisplayHex; use json::EstimateMode; use lightning::chain::chaininterface::{ConfirmationTarget, FeeEstimator}; use log::error; @@ -108,10 +107,6 @@ impl BitcoinCoreProvider { let client = Arc::new(Mutex::new(rpc_client)); let mut fees: HashMap = HashMap::with_capacity(7); fees.insert(ConfirmationTarget::OnChainSweep, AtomicU32::new(5000)); - fees.insert( - ConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee, - AtomicU32::new(25 * 250), - ); fees.insert( ConfirmationTarget::MinAllowedAnchorChannelRemoteFee, AtomicU32::new(MIN_FEERATE), @@ -184,9 +179,9 @@ impl ContractSignerProvider for BitcoinCoreProvider { .client .lock() .unwrap() - .call::>( + .call::, Value>>( "getaddressesbylabel", - &[Value::String(keys_id.to_hex())], + &[Value::String(keys_id.to_lower_hex_string())], ) .map_err(rpc_err_to_manager_err)?; @@ -199,7 +194,7 @@ impl ContractSignerProvider for BitcoinCoreProvider { .client .lock() .unwrap() - .dump_private_key(address) + .dump_private_key(&address.clone().assume_checked()) .map_err(rpc_err_to_manager_err)?; Ok(SimpleSigner::new(sk.inner)) } else { @@ -214,7 +209,7 @@ impl ContractSignerProvider for BitcoinCoreProvider { network, inner: sk, }, - Some(&keys_id.to_hex()), + Some(&keys_id.to_lower_hex_string()), Some(false), ) .map_err(rpc_err_to_manager_err)?; @@ -263,22 +258,26 @@ impl ContractSignerProvider for BitcoinCoreProvider { impl Wallet for BitcoinCoreProvider { fn get_new_address(&self) -> Result { - self.client + Ok(self + .client .lock() .unwrap() .get_new_address(None, Some(AddressType::Bech32)) - .map_err(rpc_err_to_manager_err) + .map_err(rpc_err_to_manager_err)? + .assume_checked()) } fn get_new_change_address(&self) -> Result { - self.client + Ok(self + .client .lock() .unwrap() - .call( + .call::>( "getrawchangeaddress", &[Value::Null, opt_into_json(Some(AddressType::Bech32))?], ) - .map_err(rpc_err_to_manager_err) + .map_err(rpc_err_to_manager_err)? + .assume_checked()) } fn get_utxos_for_amount( @@ -304,8 +303,16 @@ impl Wallet for BitcoinCoreProvider { txid: x.txid, vout: x.vout, }, - address: x.address.as_ref().ok_or(Error::InvalidState)?.clone(), - redeem_script: x.redeem_script.as_ref().unwrap_or(&Script::new()).clone(), + address: x + .address + .as_ref() + .map(|x| x.clone().assume_checked()) + .ok_or(Error::InvalidState)?, + redeem_script: x + .redeem_script + .as_ref() + .cloned() + .unwrap_or(ScriptBuf::new()), reserved: false, })) }) @@ -536,9 +543,6 @@ fn poll_for_fee_estimates( fees.get(&ConfirmationTarget::OnChainSweep) .unwrap() .store(fee_rate, Ordering::Release); - fees.get(&ConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee) - .unwrap() - .store(max(25 * 250, fee_rate * 10), Ordering::Release); } Err(e) => { error!("Error querying fee estimate: {}", e); diff --git a/bitcoin-test-utils/Cargo.toml b/bitcoin-test-utils/Cargo.toml index e9e9da82..a2cde5b9 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.29.2", default-features = false } -bitcoincore-rpc = {version = "0.16"} -bitcoincore-rpc-json = {version = "0.16"} +bitcoin = { version = "0.30.2", default-features = false } +bitcoincore-rpc = {version = "0.17"} +bitcoincore-rpc-json = {version = "0.17"} diff --git a/bitcoin-test-utils/src/rpc_helpers.rs b/bitcoin-test-utils/src/rpc_helpers.rs index 8f71327a..d48c8128 100644 --- a/bitcoin-test-utils/src/rpc_helpers.rs +++ b/bitcoin-test-utils/src/rpc_helpers.rs @@ -65,13 +65,16 @@ pub fn init_clients() -> (Client, Client, Client) { let offer_address = offer_rpc .get_new_address(None, Some(AddressType::Bech32)) - .unwrap(); + .unwrap() + .assume_checked(); let accept_address = accept_rpc .get_new_address(None, Some(AddressType::Bech32)) - .unwrap(); + .unwrap() + .assume_checked(); let sink_address = sink_rpc .get_new_address(None, Some(AddressType::Bech32)) - .unwrap(); + .unwrap() + .assume_checked(); sink_rpc.generate_to_address(1, &offer_address).unwrap(); sink_rpc.generate_to_address(1, &accept_address).unwrap(); diff --git a/dlc-manager/Cargo.toml b/dlc-manager/Cargo.toml index 4ada9f89..9e696096 100644 --- a/dlc-manager/Cargo.toml +++ b/dlc-manager/Cargo.toml @@ -17,28 +17,29 @@ use-serde = ["serde", "dlc/use-serde", "dlc-messages/serde", "dlc-trie/use-serde [dependencies] async-trait = "0.1.50" -bitcoin = { version = "0.29.2", default-features = false } +bitcoin = { version = "0.30.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" } -lightning = { version = "0.0.118", default-features = false, features = ["grind_signatures"] } +hex = { package = "hex-conservative", version = "0.1" } +lightning = { version = "0.0.121", default-features = false, features = ["grind_signatures"] } log = "0.4.14" rand_chacha = {version = "0.3.1", optional = true} -secp256k1-zkp = {version = "0.7.0"} +secp256k1-zkp = {version = "0.9.2"} serde = {version = "1.0", optional = true} [dev-dependencies] bitcoin-rpc-provider = {path = "../bitcoin-rpc-provider"} bitcoin-test-utils = {path = "../bitcoin-test-utils"} -bitcoincore-rpc = {version = "0.16.0"} -bitcoincore-rpc-json = {version = "0.16.0"} +bitcoincore-rpc = {version = "0.17"} +bitcoincore-rpc-json = {version = "0.17"} criterion = "0.4.0" dlc-manager = { path = ".", default-features = false, features = ["use-serde"] } dlc-messages = { path = "../dlc-messages", default-features = false, features = ["serde"] } electrs-blockchain-provider = {path = "../electrs-blockchain-provider"} env_logger = "0.9.1" mocks = {path = "../mocks"} -secp256k1-zkp = {version = "0.7.0", features = ["bitcoin_hashes", "rand", "rand-std", "global-context", "use-serde"]} +secp256k1-zkp = {version = "0.9.2", features = ["bitcoin_hashes", "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/accepted_channel.rs b/dlc-manager/src/channel/accepted_channel.rs index 2ed3ade1..24a43f56 100644 --- a/dlc-manager/src/channel/accepted_channel.rs +++ b/dlc-manager/src/channel/accepted_channel.rs @@ -1,6 +1,6 @@ //! # Structure and methods for channels that have been accepted. -use bitcoin::{Script, Transaction}; +use bitcoin::{ScriptBuf, Transaction}; use dlc_messages::channel::AcceptChannel; use secp256k1_zkp::{EcdsaAdaptorSignature, PublicKey}; @@ -29,7 +29,7 @@ pub struct AcceptedChannel { /// The buffer transaction for the initial contract in the channel. pub buffer_transaction: Transaction, /// The script pubkey of the buffer transaction output. - pub buffer_script_pubkey: Script, + pub buffer_script_pubkey: ScriptBuf, /// The temporary id of the channel. pub temporary_channel_id: ChannelId, /// The actual id of the channel. @@ -53,7 +53,7 @@ impl AcceptedChannel { funding_pubkey: contract.accept_params.fund_pubkey, payout_spk: contract.accept_params.payout_script_pubkey.clone(), payout_serial_id: contract.accept_params.payout_serial_id, - funding_inputs: contract.funding_inputs.iter().map(|x| x.into()).collect(), + funding_inputs: contract.funding_inputs.clone(), change_spk: contract.accept_params.change_script_pubkey.clone(), change_serial_id: contract.accept_params.change_serial_id, cet_adaptor_signatures: cet_adaptor_signatures.into(), diff --git a/dlc-manager/src/channel/mod.rs b/dlc-manager/src/channel/mod.rs index 7113f1ef..7249b0f1 100644 --- a/dlc-manager/src/channel/mod.rs +++ b/dlc-manager/src/channel/mod.rs @@ -15,6 +15,7 @@ pub mod offered_channel; pub mod party_points; pub mod ser; pub mod signed_channel; +mod utils; /// Enumeration containing the possible state a DLC channel can be in. #[derive(Clone)] diff --git a/dlc-manager/src/channel/offered_channel.rs b/dlc-manager/src/channel/offered_channel.rs index 63d261df..b4dfee9e 100644 --- a/dlc-manager/src/channel/offered_channel.rs +++ b/dlc-manager/src/channel/offered_channel.rs @@ -61,11 +61,7 @@ impl OfferedChannel { payout_spk: offered_contract.offer_params.payout_script_pubkey.clone(), payout_serial_id: offered_contract.offer_params.payout_serial_id, offer_collateral: offered_contract.offer_params.collateral, - funding_inputs: offered_contract - .funding_inputs_info - .iter() - .map(|x| x.into()) - .collect(), + funding_inputs: offered_contract.funding_inputs.clone(), change_spk: offered_contract.offer_params.change_script_pubkey.clone(), change_serial_id: offered_contract.offer_params.change_serial_id, cet_locktime: offered_contract.cet_locktime, @@ -123,11 +119,7 @@ impl OfferedChannel { refund_locktime: offer_channel.refund_locktime, fee_rate_per_vb: offer_channel.fee_rate_per_vb, fund_output_serial_id: offer_channel.fund_output_serial_id, - funding_inputs_info: offer_channel - .funding_inputs - .iter() - .map(|x| x.into()) - .collect(), + funding_inputs: offer_channel.funding_inputs.clone(), total_collateral: offer_channel.contract_info.get_total_collateral(), keys_id, }; diff --git a/dlc-manager/src/channel/party_points.rs b/dlc-manager/src/channel/party_points.rs index ac508e6d..b70b25bd 100644 --- a/dlc-manager/src/channel/party_points.rs +++ b/dlc-manager/src/channel/party_points.rs @@ -2,9 +2,9 @@ //! of states possible. This module contain a structure containing them and methods //! useful for derivation. +use super::utils::{derive_public_key, derive_public_revocation_key}; use bitcoin::PublicKey as BitcoinPublicKey; use dlc::channel::RevokeParams; -use lightning::ln::chan_utils::{derive_public_key, derive_public_revocation_key}; use secp256k1_zkp::{All, PublicKey, Secp256k1, Signing, Verification}; /// Base points used by a party of a DLC channel to derive public and private diff --git a/dlc-manager/src/channel/signed_channel.rs b/dlc-manager/src/channel/signed_channel.rs index f7b82753..4d705f26 100644 --- a/dlc-manager/src/channel/signed_channel.rs +++ b/dlc-manager/src/channel/signed_channel.rs @@ -2,7 +2,7 @@ //! transaction inputs. This module contains the model for a signed channel, //! the possible states in which it can be as well as methods to work with it. -use bitcoin::{Script, Transaction, Txid}; +use bitcoin::{ScriptBuf, Transaction, Txid}; use dlc::PartyParams; use dlc_messages::oracle_msgs::OracleAttestation; use lightning::ln::chan_utils::CounterpartyCommitmentSecrets; @@ -230,7 +230,7 @@ typed_enum!( /// The buffer transaction. buffer_transaction: Transaction, /// The buffer transaction script pubkey. - buffer_script_pubkey: Script, + buffer_script_pubkey: ScriptBuf, /// The adaptor signature for the buffer transaction generated by /// the accept party. accept_buffer_adaptor_signature: EcdsaAdaptorSignature, @@ -256,7 +256,7 @@ typed_enum!( /// The buffer transaction. buffer_transaction: Transaction, /// The buffer transaction script pubkey. - buffer_script_pubkey: Script, + buffer_script_pubkey: ScriptBuf, /// The adaptor signature for the buffer transaction generated by /// the offer party. offer_buffer_adaptor_signature: EcdsaAdaptorSignature, @@ -398,7 +398,7 @@ pub struct SignedChannel { /// The fund transaction for the channel. pub fund_tx: Transaction, /// The script pubkey for the funding output. - pub fund_script_pubkey: Script, + pub fund_script_pubkey: ScriptBuf, /// The vout of the funding output. pub fund_output_index: usize, /// The latest "stable" state in which the channel was (if already in a "stable") diff --git a/dlc-manager/src/channel/utils.rs b/dlc-manager/src/channel/utils.rs index db8eea66..153bd1f9 100644 --- a/dlc-manager/src/channel/utils.rs +++ b/dlc-manager/src/channel/utils.rs @@ -1,37 +1,83 @@ //! # -use bitcoin::PublicKey as BitcoinPublicKey; -use lightning::ln::chan_utils::{derive_public_key, derive_public_revocation_key}; -use secp256k1_zkp::{PublicKey, Secp256k1, Signing, Verification}; +use bitcoin::hashes::HashEngine; +use bitcoin::hashes::{sha256::Hash as Sha256, Hash}; +use secp256k1_zkp::{PublicKey, Scalar, Secp256k1, SecretKey}; -use crate::error::Error; - -pub(crate) fn derive_bitcoin_public_key( - secp: &Secp256k1, +/// Derives a public key from a `base_point` and a `per_commitment_point` as described in BOLT-3 +/// (https://github.com/lightning/bolts/blob/master/03-transactions.md#localpubkey-local_htlcpubkey-remote_htlcpubkey-local_delayedpubkey-and-remote_delayedpubkey-derivation). +/// +/// Taken from a previous version of ldk as it was refactored into something less practical to use +/// externally. +pub(crate) fn derive_public_key( + secp_ctx: &Secp256k1, per_commitment_point: &PublicKey, base_point: &PublicKey, -) -> Result { - let key = derive_public_key(secp, per_commitment_point, base_point) - .map_err(|e| Error::InvalidParameters(format!("Invalid point was given {}", e)))?; - Ok(BitcoinPublicKey { - compressed: true, - key, - }) +) -> PublicKey { + let mut sha = Sha256::engine(); + sha.input(&per_commitment_point.serialize()); + sha.input(&base_point.serialize()); + let res = Sha256::from_engine(sha).to_byte_array(); + + let hashkey = PublicKey::from_secret_key( + secp_ctx, + &SecretKey::from_slice(&res) + .expect("Hashes should always be valid keys unless SHA-256 is broken"), + ); + base_point.combine(&hashkey) + .expect("Addition only fails if the tweak is the inverse of the key. This is not possible when the tweak contains the hash of the key.") } -pub(crate) fn derive_bitcoin_public_revocation_key( - secp: &Secp256k1, +/// Derives a per-commitment-transaction revocation public key from its constituent parts. This is +/// the public equivalent of derive_private_revocation_key - using only public keys to derive a +/// public key instead of private keys. +/// +/// Only the cheating participant owns a valid witness to propagate a revoked +/// commitment transaction, thus per_commitment_point always come from cheater +/// and revocation_base_point always come from punisher, which is the broadcaster +/// of the transaction spending with this key knowledge. +/// +/// Note that this is infallible iff we trust that at least one of the two input keys are randomly +/// generated (ie our own). +/// +/// Taken from a previous version of ldk as it was refactored into something less practical to use +/// externally. +pub fn derive_public_revocation_key( + secp_ctx: &Secp256k1, per_commitment_point: &PublicKey, countersignatory_revocation_base_point: &PublicKey, -) -> Result { - let key = derive_public_revocation_key( - secp, - per_commitment_point, - countersignatory_revocation_base_point, - ) - .map_err(|e| Error::InvalidParameters(format!("Could not derive revocation secret: {}", e)))?; - Ok(BitcoinPublicKey { - compressed: true, - key, - }) +) -> PublicKey { + let rev_append_commit_hash_key = { + let mut sha = Sha256::engine(); + sha.input(&countersignatory_revocation_base_point.serialize()); + sha.input(&per_commitment_point.serialize()); + + Sha256::from_engine(sha).to_byte_array() + }; + let commit_append_rev_hash_key = { + let mut sha = Sha256::engine(); + sha.input(&per_commitment_point.serialize()); + sha.input(&countersignatory_revocation_base_point.serialize()); + + Sha256::from_engine(sha).to_byte_array() + }; + + let countersignatory_contrib = countersignatory_revocation_base_point + .mul_tweak( + secp_ctx, + &Scalar::from_be_bytes(rev_append_commit_hash_key).unwrap(), + ) + .expect( + "Multiplying a valid public key by a hash is expected to never fail per secp256k1 docs", + ); + let broadcaster_contrib = per_commitment_point + .mul_tweak( + secp_ctx, + &Scalar::from_be_bytes(commit_append_rev_hash_key).unwrap(), + ) + .expect( + "Multiplying a valid public key by a hash is expected to never fail per secp256k1 docs", + ); + countersignatory_contrib.combine(&broadcaster_contrib) + .expect("Addition only fails if the tweak is the inverse of the key. This is not possible when the tweak commits to the key.") } diff --git a/dlc-manager/src/channel_updater.rs b/dlc-manager/src/channel_updater.rs index ecd2ff97..681559e7 100644 --- a/dlc-manager/src/channel_updater.rs +++ b/dlc-manager/src/channel_updater.rs @@ -22,7 +22,7 @@ use crate::{ utils::get_new_temporary_id, Blockchain, ContractSigner, ContractSignerProvider, Time, Wallet, }; -use bitcoin::{OutPoint, Script, Sequence, Transaction, TxIn, Witness}; +use bitcoin::{OutPoint, Script, ScriptBuf, Sequence, Transaction, TxIn, Witness}; use dlc::{ channel::{get_tx_adaptor_signature, verify_tx_adaptor_signature, DlcChannelTransactions}, PartyParams, @@ -238,7 +238,7 @@ where &funding_inputs, &own_secret_key, buffer_transaction.output[0].value, - Some(buffer_script_pubkey.clone()), + Some(&buffer_script_pubkey), &dlc_transactions, )?; @@ -356,17 +356,13 @@ where secp, offered_contract, &accept_params, - &accept_channel - .funding_inputs - .iter() - .map(|x| x.into()) - .collect::>(), + &accept_channel.funding_inputs, &accept_channel.refund_signature, &accept_cet_adaptor_signatures, buffer_transaction.output[0].value, wallet, &offer_own_sk, - Some(buffer_script_pubkey), + Some(&buffer_script_pubkey), Some(accept_revoke_params.own_pk.inner), &dlc_transactions, Some(channel_id), @@ -477,7 +473,7 @@ where &cet_adaptor_signatures, &sign_channel.funding_signatures, accepted_channel.buffer_transaction.output[0].value, - Some(accepted_channel.buffer_script_pubkey.clone()), + Some(&accepted_channel.buffer_script_pubkey), Some(counter_own_pk), wallet, Some(accepted_channel.channel_id), @@ -1090,7 +1086,7 @@ where offer_params: signed_channel.counter_params.clone(), total_collateral: signed_channel.own_params.collateral + signed_channel.counter_params.collateral, - funding_inputs_info: Vec::new(), + funding_inputs: Vec::new(), fund_output_serial_id: 0, fee_rate_per_vb: signed_channel.fee_rate_per_vb, cet_locktime: renew_offer.cet_locktime, @@ -1209,7 +1205,7 @@ where &[], &own_secret_key, buffer_transaction.output[0].value, - Some(buffer_script_pubkey.clone()), + Some(&buffer_script_pubkey), &dlc_transactions, )?; @@ -1325,7 +1321,7 @@ where buffer_transaction.output[0].value, wallet, &offer_own_sk, - Some(buffer_script_pubkey.clone()), + Some(&buffer_script_pubkey), Some(accept_revoke_params.own_pk.inner), &dlc_transactions, Some(signed_channel.channel_id), @@ -1436,7 +1432,7 @@ where funding_signatures: Vec::new(), }, buffer_transaction.output[0].value, - Some(buffer_script_pubkey.clone()), + Some(buffer_script_pubkey), Some(counter_own_pk), wallet, Some(signed_channel.channel_id), @@ -1750,7 +1746,7 @@ fn get_settle_tx_and_adaptor_sig( txid: fund_tx.txid(), vout: fund_vout as u32, }, - script_sig: Script::new(), + script_sig: ScriptBuf::new(), sequence: Sequence::MAX, witness: Witness::default(), }; diff --git a/dlc-manager/src/contract/accepted_contract.rs b/dlc-manager/src/contract/accepted_contract.rs index 302f3208..1549ce98 100644 --- a/dlc-manager/src/contract/accepted_contract.rs +++ b/dlc-manager/src/contract/accepted_contract.rs @@ -1,10 +1,10 @@ //! # AcceptedContract use super::offered_contract::OfferedContract; -use super::{AdaptorInfo, FundingInputInfo}; +use super::AdaptorInfo; use bitcoin::Transaction; use dlc::{DlcTransactions, PartyParams}; -use dlc_messages::AcceptDlc; +use dlc_messages::{AcceptDlc, FundingInput}; use secp256k1_zkp::ecdsa::Signature; use secp256k1_zkp::EcdsaAdaptorSignature; @@ -18,7 +18,7 @@ pub struct AcceptedContract { /// The parameters of the accepting party. pub accept_params: PartyParams, /// The funding inputs provided by the accepting party. - pub funding_inputs: Vec, + pub funding_inputs: Vec, /// The adaptor information for the contract storing information about /// the relation between adaptor signatures and outcomes. pub adaptor_infos: Vec, @@ -65,7 +65,7 @@ impl AcceptedContract { funding_pubkey: self.accept_params.fund_pubkey, payout_spk: self.accept_params.payout_script_pubkey.clone(), payout_serial_id: self.accept_params.payout_serial_id, - funding_inputs: self.funding_inputs.iter().map(|x| x.into()).collect(), + funding_inputs: self.funding_inputs.clone(), change_spk: self.accept_params.change_script_pubkey.clone(), change_serial_id: self.accept_params.change_serial_id, cet_adaptor_signatures: ecdsa_adaptor_signatures.into(), diff --git a/dlc-manager/src/contract/contract_input.rs b/dlc-manager/src/contract/contract_input.rs index 91ca2c9a..1b1baccb 100644 --- a/dlc-manager/src/contract/contract_input.rs +++ b/dlc-manager/src/contract/contract_input.rs @@ -104,7 +104,7 @@ impl ContractInput { #[cfg(test)] mod tests { use dlc::{EnumerationPayout, Payout}; - use secp256k1_zkp::{KeyPair, SECP256K1}; + use secp256k1_zkp::{KeyPair, SecretKey, SECP256K1}; use crate::contract::enum_descriptor::EnumDescriptor; @@ -138,7 +138,7 @@ mod tests { public_keys: vec![ XOnlyPublicKey::from_keypair(&KeyPair::from_secret_key( SECP256K1, - &secp256k1_zkp::ONE_KEY, + &SecretKey::from_slice(&secp256k1_zkp::constants::ONE).unwrap(), )) .0, ], diff --git a/dlc-manager/src/contract/mod.rs b/dlc-manager/src/contract/mod.rs index ad54d6cd..4b2b804d 100644 --- a/dlc-manager/src/contract/mod.rs +++ b/dlc-manager/src/contract/mod.rs @@ -2,10 +2,10 @@ use crate::error::Error; use crate::ContractId; -use bitcoin::{Address, Transaction}; +use bitcoin::Transaction; use dlc_messages::{ oracle_msgs::{EventDescriptor, OracleAnnouncement, OracleAttestation}, - AcceptDlc, FundingInput, SignDlc, + AcceptDlc, SignDlc, }; use dlc_trie::multi_oracle_trie::MultiOracleTrie; use dlc_trie::multi_oracle_trie_with_diff::MultiOracleTrieWithDiff; @@ -122,20 +122,6 @@ impl Contract { } } -/// Information about a funding input. -#[derive(Clone, Debug)] -#[cfg_attr( - feature = "serde", - derive(Serialize, Deserialize), - serde(rename_all = "camelCase") -)] -pub struct FundingInputInfo { - /// The funding input as used in messages. - pub funding_input: FundingInput, - /// The address corresponding to the input if it belongs to us. - pub address: Option
, -} - /// Information about a contract that failed while verifying an accept message. #[derive(Clone)] pub struct FailedAcceptContract { diff --git a/dlc-manager/src/contract/offered_contract.rs b/dlc-manager/src/contract/offered_contract.rs index b81ab39f..4fc1b717 100644 --- a/dlc-manager/src/contract/offered_contract.rs +++ b/dlc-manager/src/contract/offered_contract.rs @@ -7,11 +7,11 @@ use crate::utils::get_new_serial_id; use super::contract_info::ContractInfo; use super::contract_input::ContractInput; -use super::{ContractDescriptor, FundingInputInfo}; +use super::ContractDescriptor; use crate::KeysId; use dlc::PartyParams; use dlc_messages::oracle_msgs::OracleAnnouncement; -use dlc_messages::OfferDlc; +use dlc_messages::{FundingInput, OfferDlc}; use secp256k1_zkp::PublicKey; /// Contains information about a contract that was offered. @@ -36,7 +36,7 @@ pub struct OfferedContract { /// The sum of both parties collateral. pub total_collateral: u64, /// Information about the offering party's funding inputs. - pub funding_inputs_info: Vec, + pub funding_inputs: Vec, /// The serial id of the fund output used for output ordering. pub fund_output_serial_id: u64, /// The fee rate to be used to construct the DLC transactions. @@ -82,7 +82,7 @@ impl OfferedContract { contract: &ContractInput, oracle_announcements: Vec>, offer_params: &PartyParams, - funding_inputs_info: &[FundingInputInfo], + funding_inputs: &[FundingInput], counter_party: &PublicKey, refund_delay: u32, cet_locktime: u32, @@ -112,7 +112,7 @@ impl OfferedContract { contract_info, offer_params: offer_params.clone(), total_collateral, - funding_inputs_info: funding_inputs_info.to_vec(), + funding_inputs: funding_inputs.to_vec(), fund_output_serial_id, fee_rate_per_vb: contract.fee_rate, cet_locktime, @@ -150,7 +150,7 @@ impl OfferedContract { refund_locktime: offer_dlc.refund_locktime, fee_rate_per_vb: offer_dlc.fee_rate_per_vb, fund_output_serial_id: offer_dlc.fund_output_serial_id, - funding_inputs_info: offer_dlc.funding_inputs.iter().map(|x| x.into()).collect(), + funding_inputs: offer_dlc.funding_inputs.clone(), total_collateral: offer_dlc.contract_info.get_total_collateral(), counter_party, keys_id, @@ -170,11 +170,7 @@ impl From<&OfferedContract> for OfferDlc { payout_spk: offered_contract.offer_params.payout_script_pubkey.clone(), payout_serial_id: offered_contract.offer_params.payout_serial_id, offer_collateral: offered_contract.offer_params.collateral, - funding_inputs: offered_contract - .funding_inputs_info - .iter() - .map(|x| x.into()) - .collect(), + funding_inputs: offered_contract.funding_inputs.clone(), change_spk: offered_contract.offer_params.change_script_pubkey.clone(), change_serial_id: offered_contract.offer_params.change_serial_id, cet_locktime: offered_contract.cet_locktime, diff --git a/dlc-manager/src/contract/ser.rs b/dlc-manager/src/contract/ser.rs index e22ff19c..d05655ab 100644 --- a/dlc-manager/src/contract/ser.rs +++ b/dlc-manager/src/contract/ser.rs @@ -9,8 +9,7 @@ use crate::contract::offered_contract::OfferedContract; use crate::contract::signed_contract::SignedContract; use crate::contract::AdaptorInfo; use crate::contract::{ - ClosedContract, ContractDescriptor, FailedAcceptContract, FailedSignContract, FundingInputInfo, - PreClosedContract, + ClosedContract, ContractDescriptor, FailedAcceptContract, FailedSignContract, PreClosedContract, }; use crate::payout_curve::{ HyperbolaPayoutCurvePiece, PayoutFunction, PayoutFunctionPiece, PayoutPoint, @@ -81,7 +80,6 @@ impl_dlc_writeable!(HyperbolaPayoutCurvePiece, { }); impl_dlc_writeable_enum!(ContractDescriptor, (0, Enum), (1, Numerical);;;); impl_dlc_writeable!(ContractInfo, { (contract_descriptor, writeable), (oracle_announcements, vec), (threshold, usize)}); -impl_dlc_writeable!(FundingInputInfo, { (funding_input, writeable), (address, {option_cb, dlc_messages::ser_impls::write_address, dlc_messages::ser_impls::read_address}) }); impl_dlc_writeable!(EnumDescriptor, { ( outcome_payouts, @@ -94,7 +92,7 @@ impl_dlc_writeable!(OfferedContract, { (contract_info, vec), (offer_params, { cb_writeable, dlc_messages::ser_impls::party_params::write, dlc_messages::ser_impls::party_params::read }), (total_collateral, writeable), - (funding_inputs_info, vec), + (funding_inputs, vec), (fund_output_serial_id, writeable), (fee_rate_per_vb, writeable), (cet_locktime, writeable), diff --git a/dlc-manager/src/contract_updater.rs b/dlc-manager/src/contract_updater.rs index f3920685..2f42a49c 100644 --- a/dlc-manager/src/contract_updater.rs +++ b/dlc-manager/src/contract_updater.rs @@ -5,6 +5,7 @@ use std::ops::Deref; use bitcoin::psbt::PartiallySignedTransaction; use bitcoin::{consensus::Decodable, Script, Transaction, Witness}; use dlc::{DlcTransactions, PartyParams}; +use dlc_messages::FundingInput; use dlc_messages::{ oracle_msgs::{OracleAnnouncement, OracleAttestation}, AcceptDlc, FundingSignature, FundingSignatures, OfferDlc, SignDlc, WitnessElement, @@ -17,7 +18,7 @@ use crate::{ contract::{ accepted_contract::AcceptedContract, contract_info::ContractInfo, contract_input::ContractInput, offered_contract::OfferedContract, - signed_contract::SignedContract, AdaptorInfo, FundingInputInfo, + signed_contract::SignedContract, AdaptorInfo, }, conversion_utils::get_tx_input_infos, error::Error, @@ -133,16 +134,16 @@ pub(crate) fn accept_contract_internal( secp: &Secp256k1, offered_contract: &OfferedContract, accept_params: &PartyParams, - funding_inputs: &[FundingInputInfo], + funding_inputs: &[FundingInput], adaptor_secret_key: &SecretKey, input_value: u64, - input_script_pubkey: Option