Skip to content

Commit 9f260b3

Browse files
committed
Update to rust-secp256k1 v0.11 and rust-bitcoin v0.14
1 parent 08038d7 commit 9f260b3

14 files changed

+237
-210
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ max_level_info = []
2323
max_level_debug = []
2424

2525
[dependencies]
26-
bitcoin = "0.13"
26+
bitcoin = "0.14"
2727
rust-crypto = "0.2"
2828
rand = "0.4"
29-
secp256k1 = "0.9"
29+
secp256k1 = "0.11"
3030

3131
[build-dependencies]
3232
cc = "1.0"
3333

3434
[dev-dependencies.bitcoin]
35-
version = "0.13"
35+
version = "0.14"
3636
features = ["bitcoinconsensus"]
3737

3838
[dev-dependencies]

fuzz/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ honggfuzz_fuzz = ["honggfuzz"]
1818
[dependencies]
1919
afl = { version = "0.4", optional = true }
2020
lightning = { path = "..", features = ["fuzztarget"] }
21-
bitcoin = { version = "0.13", features = ["fuzztarget"] }
21+
bitcoin = { version = "0.14", features = ["fuzztarget"] }
2222
hex = "0.3"
2323
honggfuzz = { version = "0.5", optional = true }
2424
rust-crypto = "0.2"
25-
secp256k1 = { version = "0.9", features=["fuzztarget"] }
25+
secp256k1 = { version = "0.11", features=["fuzztarget"] }
2626

2727
[build-dependencies]
2828
cc = "1.0"

fuzz/fuzz_targets/full_stack_target.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ pub fn do_test(data: &[u8], logger: &Arc<Logger>) {
237237
let monitor = channelmonitor::SimpleManyChannelMonitor::new(watch.clone(), broadcast.clone());
238238

239239
let channelmanager = ChannelManager::new(our_network_key, slice_to_be32(get_slice!(4)), get_slice!(1)[0] != 0, Network::Bitcoin, fee_est.clone(), monitor.clone(), watch.clone(), broadcast.clone(), Arc::clone(&logger)).unwrap();
240-
let router = Arc::new(Router::new(PublicKey::from_secret_key(&secp_ctx, &our_network_key).unwrap(), Arc::clone(&logger)));
240+
let router = Arc::new(Router::new(PublicKey::from_secret_key(&secp_ctx, &our_network_key), Arc::clone(&logger)));
241241

242242
let peers = RefCell::new([false; 256]);
243243
let mut loss_detector = MoneyLossDetector::new(&peers, channelmanager.clone(), monitor.clone(), PeerManager::new(MessageHandler {

src/chain/chaininterface.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl ChainWatchInterfaceUtil {
181181
for input in tx.input.iter() {
182182
for outpoint in watched.1.iter() {
183183
let &(outpoint_hash, outpoint_index) = outpoint;
184-
if outpoint_hash == input.prev_hash && outpoint_index == input.prev_index {
184+
if outpoint_hash == input.previous_output.txid && outpoint_index == input.previous_output.vout {
185185
return true;
186186
}
187187
}

src/chain/transaction.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use bitcoin::util::hash::Sha256dHash;
2+
use bitcoin::blockdata::transaction::OutPoint as BitcoinOutPoint;
23

34
/// A reference to a transaction output.
4-
/// Differs from bitcoin::blockdata::transaction::TxOutRef as the index is a u16 instead of usize
5+
/// Differs from bitcoin::blockdata::transaction::OutPoint as the index is a u16 instead of u32
56
/// due to LN's restrictions on index values. Should reduce (possibly) unsafe conversions this way.
67
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
78
pub struct OutPoint {
@@ -25,6 +26,13 @@ impl OutPoint {
2526
res[31] ^= ((self.index >> 0) & 0xff) as u8;
2627
res
2728
}
29+
30+
pub fn into_bitcoin_outpoint(self) -> BitcoinOutPoint {
31+
BitcoinOutPoint {
32+
txid: self.txid,
33+
vout: self.index as u32,
34+
}
35+
}
2836
}
2937

3038
#[cfg(test)]

src/ln/chan_utils.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bitcoin::blockdata::script::{Script,Builder};
22
use bitcoin::blockdata::opcodes;
3-
use bitcoin::blockdata::transaction::{TxIn,TxOut,Transaction};
3+
use bitcoin::blockdata::transaction::{TxIn,TxOut,OutPoint,Transaction};
44
use bitcoin::util::hash::{Hash160,Sha256dHash};
55

66
use secp256k1::key::{PublicKey,SecretKey};
@@ -32,10 +32,10 @@ pub fn build_commitment_secret(commitment_seed: [u8; 32], idx: u64) -> [u8; 32]
3232
res
3333
}
3434

35-
pub fn derive_private_key(secp_ctx: &Secp256k1, per_commitment_point: &PublicKey, base_secret: &SecretKey) -> Result<SecretKey, secp256k1::Error> {
35+
pub fn derive_private_key<T: secp256k1::Signing>(secp_ctx: &Secp256k1<T>, per_commitment_point: &PublicKey, base_secret: &SecretKey) -> Result<SecretKey, secp256k1::Error> {
3636
let mut sha = Sha256::new();
3737
sha.input(&per_commitment_point.serialize());
38-
sha.input(&PublicKey::from_secret_key(&secp_ctx, &base_secret).unwrap().serialize());
38+
sha.input(&PublicKey::from_secret_key(&secp_ctx, &base_secret).serialize());
3939
let mut res = [0; 32];
4040
sha.result(&mut res);
4141

@@ -44,21 +44,21 @@ pub fn derive_private_key(secp_ctx: &Secp256k1, per_commitment_point: &PublicKey
4444
Ok(key)
4545
}
4646

47-
pub fn derive_public_key(secp_ctx: &Secp256k1, per_commitment_point: &PublicKey, base_point: &PublicKey) -> Result<PublicKey, secp256k1::Error> {
47+
pub fn derive_public_key<T: secp256k1::Signing>(secp_ctx: &Secp256k1<T>, per_commitment_point: &PublicKey, base_point: &PublicKey) -> Result<PublicKey, secp256k1::Error> {
4848
let mut sha = Sha256::new();
4949
sha.input(&per_commitment_point.serialize());
5050
sha.input(&base_point.serialize());
5151
let mut res = [0; 32];
5252
sha.result(&mut res);
5353

54-
let hashkey = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &res)?).unwrap();
54+
let hashkey = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &res)?);
5555
base_point.combine(&secp_ctx, &hashkey)
5656
}
5757

5858
/// Derives a revocation key from its constituent parts
59-
pub fn derive_private_revocation_key(secp_ctx: &Secp256k1, per_commitment_secret: &SecretKey, revocation_base_secret: &SecretKey) -> Result<SecretKey, secp256k1::Error> {
60-
let revocation_base_point = PublicKey::from_secret_key(&secp_ctx, &revocation_base_secret).unwrap();
61-
let per_commitment_point = PublicKey::from_secret_key(&secp_ctx, &per_commitment_secret).unwrap();
59+
pub fn derive_private_revocation_key<T: secp256k1::Signing>(secp_ctx: &Secp256k1<T>, per_commitment_secret: &SecretKey, revocation_base_secret: &SecretKey) -> Result<SecretKey, secp256k1::Error> {
60+
let revocation_base_point = PublicKey::from_secret_key(&secp_ctx, &revocation_base_secret);
61+
let per_commitment_point = PublicKey::from_secret_key(&secp_ctx, &per_commitment_secret);
6262

6363
let rev_append_commit_hash_key = {
6464
let mut sha = Sha256::new();
@@ -87,7 +87,7 @@ pub fn derive_private_revocation_key(secp_ctx: &Secp256k1, per_commitment_secret
8787
Ok(part_a)
8888
}
8989

90-
pub fn derive_public_revocation_key(secp_ctx: &Secp256k1, per_commitment_point: &PublicKey, revocation_base_point: &PublicKey) -> Result<PublicKey, secp256k1::Error> {
90+
pub fn derive_public_revocation_key<T: secp256k1::Verification>(secp_ctx: &Secp256k1<T>, per_commitment_point: &PublicKey, revocation_base_point: &PublicKey) -> Result<PublicKey, secp256k1::Error> {
9191
let rev_append_commit_hash_key = {
9292
let mut sha = Sha256::new();
9393
sha.input(&revocation_base_point.serialize());
@@ -124,7 +124,7 @@ pub struct TxCreationKeys {
124124
}
125125

126126
impl TxCreationKeys {
127-
pub fn new(secp_ctx: &Secp256k1, per_commitment_point: &PublicKey, a_delayed_payment_base: &PublicKey, a_htlc_base: &PublicKey, b_revocation_base: &PublicKey, b_payment_base: &PublicKey, b_htlc_base: &PublicKey) -> Result<TxCreationKeys, secp256k1::Error> {
127+
pub fn new<T: secp256k1::Signing + secp256k1::Verification>(secp_ctx: &Secp256k1<T>, per_commitment_point: &PublicKey, a_delayed_payment_base: &PublicKey, a_htlc_base: &PublicKey, b_revocation_base: &PublicKey, b_payment_base: &PublicKey, b_htlc_base: &PublicKey) -> Result<TxCreationKeys, secp256k1::Error> {
128128
Ok(TxCreationKeys {
129129
per_commitment_point: per_commitment_point.clone(),
130130
revocation_key: derive_public_revocation_key(&secp_ctx, &per_commitment_point, &b_revocation_base)?,
@@ -241,8 +241,10 @@ pub fn get_htlc_redeemscript(htlc: &HTLCOutputInCommitment, keys: &TxCreationKey
241241
pub fn build_htlc_transaction(prev_hash: &Sha256dHash, feerate_per_kw: u64, to_self_delay: u16, htlc: &HTLCOutputInCommitment, a_delayed_payment_key: &PublicKey, revocation_key: &PublicKey) -> Transaction {
242242
let mut txins: Vec<TxIn> = Vec::new();
243243
txins.push(TxIn {
244-
prev_hash: prev_hash.clone(),
245-
prev_index: htlc.transaction_output_index,
244+
previous_output: OutPoint {
245+
txid: prev_hash.clone(),
246+
vout: htlc.transaction_output_index,
247+
},
246248
script_sig: Script::new(),
247249
sequence: 0,
248250
witness: Vec::new(),

0 commit comments

Comments
 (0)