Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update bitcoin crate to 0.28.1 #1389

Merged
merged 2 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ stdin_fuzz = []
[dependencies]
afl = { version = "0.4", optional = true }
lightning = { path = "../lightning", features = ["regex"] }
bitcoin = { version = "0.27", features = ["fuzztarget", "secp-lowmemory"] }
bitcoin = { version = "0.28.1", features = ["secp-lowmemory"] }
hex = "0.3"
honggfuzz = { version = "0.5", optional = true }
libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git", optional = true }
Expand Down
4 changes: 2 additions & 2 deletions fuzz/src/chanmon_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ use lightning::routing::router::{Route, RouteHop};
use utils::test_logger::{self, Output};
use utils::test_persister::TestPersister;

use bitcoin::secp256k1::key::{PublicKey,SecretKey};
use bitcoin::secp256k1::recovery::RecoverableSignature;
use bitcoin::secp256k1::{PublicKey,SecretKey};
use bitcoin::secp256k1::ecdsa::RecoverableSignature;
use bitcoin::secp256k1::Secp256k1;

use std::mem;
Expand Down
4 changes: 2 additions & 2 deletions fuzz/src/full_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ use lightning::util::ser::ReadableArgs;
use utils::test_logger;
use utils::test_persister::TestPersister;

use bitcoin::secp256k1::key::{PublicKey,SecretKey};
use bitcoin::secp256k1::recovery::RecoverableSignature;
use bitcoin::secp256k1::{PublicKey,SecretKey};
use bitcoin::secp256k1::ecdsa::RecoverableSignature;
use bitcoin::secp256k1::Secp256k1;

use std::cell::RefCell;
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/peer_crypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use lightning::ln::peer_channel_encryptor::PeerChannelEncryptor;

use bitcoin::secp256k1::key::{PublicKey,SecretKey};
use bitcoin::secp256k1::{PublicKey,SecretKey};

use utils::test_logger;

Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use lightning::util::ser::Readable;
use lightning::routing::network_graph::{NetworkGraph, RoutingFees};

use bitcoin::hashes::Hash;
use bitcoin::secp256k1::key::PublicKey;
use bitcoin::secp256k1::PublicKey;
use bitcoin::network::constants::Network;
use bitcoin::blockdata::constants::genesis_block;

Expand Down
2 changes: 1 addition & 1 deletion lightning-background-processor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
bitcoin = "0.27"
bitcoin = "0.28.1"
lightning = { version = "0.0.106", path = "../lightning", features = ["std"] }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion lightning-block-sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rest-client = [ "serde", "serde_json", "chunked_transfer" ]
rpc-client = [ "serde", "serde_json", "chunked_transfer" ]

[dependencies]
bitcoin = "0.27"
bitcoin = "0.28.1"
lightning = { version = "0.0.106", path = "../lightning" }
futures = { version = "0.3" }
tokio = { version = "1.0", features = [ "io-util", "net", "time" ], optional = true }
Expand Down
17 changes: 15 additions & 2 deletions lightning-block-sync/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use bitcoin::blockdata::constants::genesis_block;
use bitcoin::hash_types::BlockHash;
use bitcoin::network::constants::Network;
use bitcoin::util::uint::Uint256;
use bitcoin::util::hash::bitcoin_merkle_root;
use bitcoin::Transaction;

use lightning::chain;

Expand Down Expand Up @@ -37,16 +39,27 @@ impl Blockchain {
let prev_block = &self.blocks[i - 1];
let prev_blockhash = prev_block.block_hash();
let time = prev_block.header.time + height as u32;
// Must have at least one transaction, because the merkle root is not defined for an empty block
// and we would fail when we later checked, as of bitcoin crate 0.28.0.
// Note that elsewhere in tests we assume that the merkle root of an empty block is all zeros,
// but that's OK because those tests don't trigger the check.
let coinbase = Transaction {
version: 0,
lock_time: 0,
input: vec![],
output: vec![]
};
let merkle_root = bitcoin_merkle_root(vec![coinbase.txid().as_hash()].into_iter()).unwrap();
self.blocks.push(Block {
header: BlockHeader {
version: 0,
prev_blockhash,
merkle_root: Default::default(),
merkle_root: merkle_root.into(),
time,
bits,
nonce: 0,
},
txdata: vec![],
txdata: vec![coinbase],
});
}
self
Expand Down
2 changes: 1 addition & 1 deletion lightning-invoice/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ std = ["bitcoin_hashes/std", "num-traits/std", "lightning/std", "bech32/std"]
[dependencies]
bech32 = { version = "0.8", default-features = false }
lightning = { version = "0.0.106", path = "../lightning", default-features = false }
secp256k1 = { version = "0.20", default-features = false, features = ["recovery", "alloc"] }
secp256k1 = { version = "0.22", default-features = false, features = ["recovery", "alloc"] }
num-traits = { version = "0.2.8", default-features = false }
bitcoin_hashes = { version = "0.10", default-features = false }
hashbrown = { version = "0.11", optional = true }
Expand Down
8 changes: 4 additions & 4 deletions lightning-invoice/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use lightning::routing::router::{RouteHint, RouteHintHop};
use num_traits::{CheckedAdd, CheckedMul};

use secp256k1;
use secp256k1::recovery::{RecoveryId, RecoverableSignature};
use secp256k1::key::PublicKey;
use secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
use secp256k1::PublicKey;

use super::{Invoice, Sha256, TaggedField, ExpiryTime, MinFinalCltvExpiry, Fallback, PayeePubKey, InvoiceSignature, PositiveTimestamp,
SemanticError, PrivateRoute, ParseError, ParseOrSemanticError, Description, RawTaggedField, Currency, RawHrp, SiPrefix, RawInvoice,
Expand Down Expand Up @@ -967,7 +967,7 @@ mod test {
#[test]
fn test_payment_secret_and_features_de_and_ser() {
use lightning::ln::features::InvoiceFeatures;
use secp256k1::recovery::{RecoveryId, RecoverableSignature};
use secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
use TaggedField::*;
use {SiPrefix, SignedRawInvoice, InvoiceSignature, RawInvoice, RawHrp, RawDataPart,
Currency, Sha256, PositiveTimestamp};
Expand Down Expand Up @@ -1014,7 +1014,7 @@ mod test {
#[test]
fn test_raw_signed_invoice_deserialization() {
use TaggedField::*;
use secp256k1::recovery::{RecoveryId, RecoverableSignature};
use secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
use {SignedRawInvoice, InvoiceSignature, RawInvoice, RawHrp, RawDataPart, Currency, Sha256,
PositiveTimestamp};

Expand Down
48 changes: 24 additions & 24 deletions lightning-invoice/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ use lightning::routing::network_graph::RoutingFees;
use lightning::routing::router::RouteHint;
use lightning::util::invoice::construct_invoice_preimage;

use secp256k1::key::PublicKey;
use secp256k1::PublicKey;
use secp256k1::{Message, Secp256k1};
use secp256k1::recovery::RecoverableSignature;
use secp256k1::ecdsa::RecoverableSignature;

use core::fmt::{Display, Formatter, self};
use core::iter::FilterMap;
Expand Down Expand Up @@ -163,7 +163,7 @@ pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY: u64 = 18;
/// use bitcoin_hashes::sha256;
///
/// use secp256k1::Secp256k1;
/// use secp256k1::key::SecretKey;
/// use secp256k1::SecretKey;
///
/// use lightning::ln::PaymentSecret;
///
Expand Down Expand Up @@ -191,7 +191,7 @@ pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY: u64 = 18;
/// .current_timestamp()
/// .min_final_cltv_expiry(144)
/// .build_signed(|hash| {
/// Secp256k1::new().sign_recoverable(hash, &private_key)
/// Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)
/// })
/// .unwrap();
///
Expand Down Expand Up @@ -749,7 +749,7 @@ impl SignedRawInvoice {
let hash = Message::from_slice(&self.hash[..])
.expect("Hash is 32 bytes long, same as MESSAGE_SIZE");

Ok(PayeePubKey(Secp256k1::new().recover(
Ok(PayeePubKey(Secp256k1::new().recover_ecdsa(
&hash,
&self.signature
)?))
Expand All @@ -776,7 +776,7 @@ impl SignedRawInvoice {
.expect("Hash is 32 bytes long, same as MESSAGE_SIZE");

let secp_context = Secp256k1::new();
let verification_result = secp_context.verify(
let verification_result = secp_context.verify_ecdsa(
&hash,
&self.signature.to_standard(),
pub_key
Expand Down Expand Up @@ -1576,8 +1576,8 @@ mod test {
fn test_check_signature() {
use TaggedField::*;
use secp256k1::Secp256k1;
use secp256k1::recovery::{RecoveryId, RecoverableSignature};
use secp256k1::key::{SecretKey, PublicKey};
use secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
use secp256k1::{SecretKey, PublicKey};
use {SignedRawInvoice, InvoiceSignature, RawInvoice, RawHrp, RawDataPart, Currency, Sha256,
PositiveTimestamp};

Expand Down Expand Up @@ -1635,7 +1635,7 @@ mod test {

let (raw_invoice, _, _) = invoice.into_parts();
let new_signed = raw_invoice.sign::<_, ()>(|hash| {
Ok(Secp256k1::new().sign_recoverable(hash, &private_key))
Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key))
}).unwrap();

assert!(new_signed.check_signature());
Expand All @@ -1646,7 +1646,7 @@ mod test {
use TaggedField::*;
use lightning::ln::features::InvoiceFeatures;
use secp256k1::Secp256k1;
use secp256k1::key::SecretKey;
use secp256k1::SecretKey;
use {RawInvoice, RawHrp, RawDataPart, Currency, Sha256, PositiveTimestamp, Invoice,
SemanticError};

Expand Down Expand Up @@ -1677,7 +1677,7 @@ mod test {
let invoice = {
let mut invoice = invoice_template.clone();
invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_recoverable(hash, &private_key)))
invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
}.unwrap();
assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::InvalidFeatures));

Expand All @@ -1686,7 +1686,7 @@ mod test {
let mut invoice = invoice_template.clone();
invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
invoice.data.tagged_fields.push(Features(InvoiceFeatures::empty()).into());
invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_recoverable(hash, &private_key)))
invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
}.unwrap();
assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::InvalidFeatures));

Expand All @@ -1695,30 +1695,30 @@ mod test {
let mut invoice = invoice_template.clone();
invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
invoice.data.tagged_fields.push(Features(InvoiceFeatures::known()).into());
invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_recoverable(hash, &private_key)))
invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
}.unwrap();
assert!(Invoice::from_signed(invoice).is_ok());

// No payment secret or features
let invoice = {
let invoice = invoice_template.clone();
invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_recoverable(hash, &private_key)))
invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
}.unwrap();
assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::NoPaymentSecret));

// No payment secret or feature bits
let invoice = {
let mut invoice = invoice_template.clone();
invoice.data.tagged_fields.push(Features(InvoiceFeatures::empty()).into());
invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_recoverable(hash, &private_key)))
invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
}.unwrap();
assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::NoPaymentSecret));

// Missing payment secret
let invoice = {
let mut invoice = invoice_template.clone();
invoice.data.tagged_fields.push(Features(InvoiceFeatures::known()).into());
invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_recoverable(hash, &private_key)))
invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
}.unwrap();
assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::NoPaymentSecret));

Expand All @@ -1727,7 +1727,7 @@ mod test {
let mut invoice = invoice_template.clone();
invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_recoverable(hash, &private_key)))
invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
}.unwrap();
assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::MultiplePaymentSecrets));
}
Expand Down Expand Up @@ -1764,7 +1764,7 @@ mod test {
use ::*;
use lightning::routing::router::RouteHintHop;
use std::iter::FromIterator;
use secp256k1::key::PublicKey;
use secp256k1::PublicKey;

let builder = InvoiceBuilder::new(Currency::Bitcoin)
.payment_hash(sha256::Hash::from_slice(&[0;32][..]).unwrap())
Expand Down Expand Up @@ -1818,7 +1818,7 @@ mod test {
use ::*;
use lightning::routing::router::RouteHintHop;
use secp256k1::Secp256k1;
use secp256k1::key::{SecretKey, PublicKey};
use secp256k1::{SecretKey, PublicKey};
use std::time::{UNIX_EPOCH, Duration};

let secp_ctx = Secp256k1::new();
Expand Down Expand Up @@ -1897,7 +1897,7 @@ mod test {
.basic_mpp();

let invoice = builder.clone().build_signed(|hash| {
secp_ctx.sign_recoverable(hash, &private_key)
secp_ctx.sign_ecdsa_recoverable(hash, &private_key)
}).unwrap();

assert!(invoice.check_signature().is_ok());
Expand Down Expand Up @@ -1932,7 +1932,7 @@ mod test {
fn test_default_values() {
use ::*;
use secp256k1::Secp256k1;
use secp256k1::key::SecretKey;
use secp256k1::SecretKey;

let signed_invoice = InvoiceBuilder::new(Currency::Bitcoin)
.description("Test".into())
Expand All @@ -1944,7 +1944,7 @@ mod test {
.sign::<_, ()>(|hash| {
let privkey = SecretKey::from_slice(&[41; 32]).unwrap();
let secp_ctx = Secp256k1::new();
Ok(secp_ctx.sign_recoverable(hash, &privkey))
Ok(secp_ctx.sign_ecdsa_recoverable(hash, &privkey))
})
.unwrap();
let invoice = Invoice::from_signed(signed_invoice).unwrap();
Expand All @@ -1958,7 +1958,7 @@ mod test {
fn test_expiration() {
use ::*;
use secp256k1::Secp256k1;
use secp256k1::key::SecretKey;
use secp256k1::SecretKey;

let signed_invoice = InvoiceBuilder::new(Currency::Bitcoin)
.description("Test".into())
Expand All @@ -1970,7 +1970,7 @@ mod test {
.sign::<_, ()>(|hash| {
let privkey = SecretKey::from_slice(&[41; 32]).unwrap();
let secp_ctx = Secp256k1::new();
Ok(secp_ctx.sign_recoverable(hash, &privkey))
Ok(secp_ctx.sign_ecdsa_recoverable(hash, &privkey))
})
.unwrap();
let invoice = Invoice::from_signed(signed_invoice).unwrap();
Expand Down
10 changes: 5 additions & 5 deletions lightning-invoice/src/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
//! # use lightning::util::ser::{Writeable, Writer};
//! # use lightning_invoice::Invoice;
//! # use lightning_invoice::payment::{InvoicePayer, Payer, RetryAttempts, Router};
//! # use secp256k1::key::PublicKey;
//! # use secp256k1::PublicKey;
//! # use std::cell::RefCell;
//! # use std::ops::Deref;
//! #
Expand Down Expand Up @@ -148,7 +148,7 @@ use lightning::util::events::{Event, EventHandler};
use lightning::util::logger::Logger;
use crate::sync::Mutex;

use secp256k1::key::PublicKey;
use secp256k1::PublicKey;

use core::ops::Deref;
use core::time::Duration;
Expand Down Expand Up @@ -555,7 +555,7 @@ mod tests {
.min_final_cltv_expiry(144)
.amount_milli_satoshis(128)
.build_signed(|hash| {
Secp256k1::new().sign_recoverable(hash, &private_key)
Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)
})
.unwrap()
}
Expand All @@ -580,7 +580,7 @@ mod tests {
.duration_since_epoch(duration_since_epoch())
.min_final_cltv_expiry(144)
.build_signed(|hash| {
Secp256k1::new().sign_recoverable(hash, &private_key)
Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)
})
.unwrap()
}
Expand All @@ -600,7 +600,7 @@ mod tests {
.min_final_cltv_expiry(144)
.amount_milli_satoshis(128)
.build_signed(|hash| {
Secp256k1::new().sign_recoverable(hash, &private_key)
Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)
})
.unwrap()
}
Expand Down
2 changes: 1 addition & 1 deletion lightning-invoice/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use lightning::routing::scoring::Score;
use lightning::routing::network_graph::{NetworkGraph, RoutingFees};
use lightning::routing::router::{Route, RouteHint, RouteHintHop, RouteParameters, find_route};
use lightning::util::logger::Logger;
use secp256k1::key::PublicKey;
use secp256k1::PublicKey;
use core::convert::TryInto;
use core::ops::Deref;
use core::time::Duration;
Expand Down