Skip to content

Commit

Permalink
bitcoin 0.28.0 - keys
Browse files Browse the repository at this point in the history
  • Loading branch information
devrandom committed Mar 27, 2022
1 parent 6176e2f commit 75eef02
Show file tree
Hide file tree
Showing 33 changed files with 78 additions and 80 deletions.
2 changes: 1 addition & 1 deletion fuzz/src/chanmon_consistency.rs
Expand Up @@ -53,7 +53,7 @@ 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::{PublicKey,SecretKey};
use bitcoin::secp256k1::recovery::RecoverableSignature;
use bitcoin::secp256k1::Secp256k1;

Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/full_stack.rs
Expand Up @@ -50,7 +50,7 @@ use lightning::util::ser::ReadableArgs;
use utils::test_logger;
use utils::test_persister::TestPersister;

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

Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/peer_crypt.rs
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
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-invoice/src/de.rs
Expand Up @@ -20,7 +20,7 @@ use num_traits::{CheckedAdd, CheckedMul};

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

use super::{Invoice, Sha256, TaggedField, ExpiryTime, MinFinalCltvExpiry, Fallback, PayeePubKey, InvoiceSignature, PositiveTimestamp,
SemanticError, PrivateRoute, Description, RawTaggedField, Currency, RawHrp, SiPrefix, RawInvoice, constants, SignedRawInvoice,
Expand Down
16 changes: 8 additions & 8 deletions lightning-invoice/src/lib.rs
Expand Up @@ -47,7 +47,7 @@ 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;

Expand Down Expand Up @@ -123,7 +123,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 @@ -1537,7 +1537,7 @@ mod test {
use TaggedField::*;
use secp256k1::Secp256k1;
use secp256k1::recovery::{RecoveryId, RecoverableSignature};
use secp256k1::key::{SecretKey, PublicKey};
use secp256k1::{SecretKey, PublicKey};
use {SignedRawInvoice, InvoiceSignature, RawInvoice, RawHrp, RawDataPart, Currency, Sha256,
PositiveTimestamp};

Expand Down Expand Up @@ -1606,7 +1606,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 @@ -1724,7 +1724,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 @@ -1778,7 +1778,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 @@ -1892,7 +1892,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 @@ -1918,7 +1918,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 Down
4 changes: 2 additions & 2 deletions lightning-invoice/src/payment.rs
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
2 changes: 1 addition & 1 deletion lightning-invoice/src/utils.rs
Expand Up @@ -18,7 +18,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
4 changes: 2 additions & 2 deletions lightning-net-tokio/src/lib.rs
Expand Up @@ -23,7 +23,7 @@
//! # Example
//! ```
//! use std::net::TcpStream;
//! use bitcoin::secp256k1::key::PublicKey;
//! use bitcoin::secp256k1::PublicKey;
//! use lightning::util::events::{Event, EventHandler, EventsProvider};
//! use std::net::SocketAddr;
//! use std::sync::Arc;
Expand Down Expand Up @@ -71,7 +71,7 @@

#![cfg_attr(docsrs, feature(doc_auto_cfg))]

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

use tokio::net::TcpStream;
use tokio::{io, time};
Expand Down
8 changes: 2 additions & 6 deletions lightning/Cargo.toml
Expand Up @@ -38,9 +38,7 @@ grind_signatures = []
default = ["std", "grind_signatures"]

[dependencies]
bitcoin = { version = "0.27", default-features = false, features = ["secp-recovery"] }
# TODO remove this once rust-bitcoin PR #637 is released
secp256k1 = { version = "0.20.2", default-features = false, features = ["alloc"] }
bitcoin = { version = "0.28.0-rc.1", default-features = false, features = ["secp-recovery"] }

hashbrown = { version = "0.11", optional = true }
hex = { version = "0.4", optional = true }
Expand All @@ -52,10 +50,8 @@ core2 = { version = "0.3.0", optional = true, default-features = false }
[dev-dependencies]
hex = "0.4"
regex = "0.2.11"
# TODO remove this once rust-bitcoin PR #637 is released
secp256k1 = { version = "0.20.2", default-features = false, features = ["alloc"] }

[dev-dependencies.bitcoin]
version = "0.27"
version = "0.28.0-rc.1"
default-features = false
features = ["bitcoinconsensus", "secp-recovery"]
4 changes: 2 additions & 2 deletions lightning/src/chain/channelmonitor.rs
Expand Up @@ -30,7 +30,7 @@ use bitcoin::hashes::sha256::Hash as Sha256;
use bitcoin::hash_types::{Txid, BlockHash, WPubkeyHash};

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

use ln::{PaymentHash, PaymentPreimage};
Expand Down Expand Up @@ -3331,7 +3331,7 @@ mod tests {
use bitcoin::hashes::hex::FromHex;
use bitcoin::hash_types::{BlockHash, Txid};
use bitcoin::network::constants::Network;
use bitcoin::secp256k1::key::{SecretKey,PublicKey};
use bitcoin::secp256k1::{SecretKey,PublicKey};
use bitcoin::secp256k1::Secp256k1;

use hex;
Expand Down
28 changes: 14 additions & 14 deletions lightning/src/chain/keysinterface.rs
Expand Up @@ -25,9 +25,9 @@ use bitcoin::hashes::sha256::Hash as Sha256;
use bitcoin::hashes::sha256d::Hash as Sha256dHash;
use bitcoin::hash_types::WPubkeyHash;

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

use util::{byte_utils, transaction_utils};
Expand Down Expand Up @@ -588,10 +588,10 @@ impl InMemorySigner {
if spend_tx.input[input_idx].previous_output != descriptor.outpoint.into_bitcoin_outpoint() { return Err(()); }

let remotepubkey = self.pubkeys().payment_point;
let witness_script = bitcoin::Address::p2pkh(&::bitcoin::PublicKey{compressed: true, key: remotepubkey}, Network::Testnet).script_pubkey();
let witness_script = bitcoin::Address::p2pkh(&::bitcoin::PublicKey{compressed: true, inner: remotepubkey}, Network::Testnet).script_pubkey();
let sighash = hash_to_message!(&bip143::SigHashCache::new(spend_tx).signature_hash(input_idx, &witness_script, descriptor.output.value, SigHashType::All)[..]);
let remotesig = sign(secp_ctx, &sighash, &self.payment_key);
let payment_script = bitcoin::Address::p2wpkh(&::bitcoin::PublicKey{compressed: true, key: remotepubkey}, Network::Bitcoin).unwrap().script_pubkey();
let payment_script = bitcoin::Address::p2wpkh(&::bitcoin::PublicKey{compressed: true, inner: remotepubkey}, Network::Bitcoin).unwrap().script_pubkey();

if payment_script != descriptor.output.script_pubkey { return Err(()); }

Expand Down Expand Up @@ -884,23 +884,23 @@ impl KeysManager {
// Note that when we aren't serializing the key, network doesn't matter
match ExtendedPrivKey::new_master(Network::Testnet, seed) {
Ok(master_key) => {
let node_secret = master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(0).unwrap()).expect("Your RNG is busted").private_key.key;
let node_secret = master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(0).unwrap()).expect("Your RNG is busted").private_key;
let destination_script = match master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(1).unwrap()) {
Ok(destination_key) => {
let wpubkey_hash = WPubkeyHash::hash(&ExtendedPubKey::from_private(&secp_ctx, &destination_key).public_key.to_bytes());
let wpubkey_hash = WPubkeyHash::hash(&ExtendedPubKey::from_private(&secp_ctx, &destination_key).to_pub().to_bytes());
Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0)
.push_slice(&wpubkey_hash.into_inner())
.into_script()
},
Err(_) => panic!("Your RNG is busted"),
};
let shutdown_pubkey = match master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(2).unwrap()) {
Ok(shutdown_key) => ExtendedPubKey::from_private(&secp_ctx, &shutdown_key).public_key.key,
Ok(shutdown_key) => ExtendedPubKey::from_private(&secp_ctx, &shutdown_key).public_key,
Err(_) => panic!("Your RNG is busted"),
};
let channel_master_key = master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(3).unwrap()).expect("Your RNG is busted");
let rand_bytes_master_key = master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(4).unwrap()).expect("Your RNG is busted");
let inbound_payment_key: SecretKey = master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(5).unwrap()).expect("Your RNG is busted").private_key.key;
let inbound_payment_key: SecretKey = master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(5).unwrap()).expect("Your RNG is busted").private_key;
let mut inbound_pmt_key_bytes = [0; 32];
inbound_pmt_key_bytes.copy_from_slice(&inbound_payment_key[..]);

Expand Down Expand Up @@ -951,7 +951,7 @@ impl KeysManager {
// entropy, everything else just ensures uniqueness. We rely on the unique_start (ie
// starting_time provided in the constructor) to be unique.
let child_privkey = self.channel_master_key.ckd_priv(&self.secp_ctx, ChildNumber::from_hardened_idx(chan_id as u32).expect("key space exhausted")).expect("Your RNG is busted");
unique_start.input(&child_privkey.private_key.key[..]);
unique_start.input(&child_privkey.private_key[..]);

let seed = Sha256::from_engine(unique_start).into_inner();

Expand Down Expand Up @@ -1092,20 +1092,20 @@ impl KeysManager {
Err(_) => panic!("Your rng is busted"),
}
};
let pubkey = ExtendedPubKey::from_private(&secp_ctx, &secret).public_key;
let pubkey = ExtendedPubKey::from_private(&secp_ctx, &secret).to_pub();
if derivation_idx == 2 {
assert_eq!(pubkey.key, self.shutdown_pubkey);
assert_eq!(pubkey.inner, self.shutdown_pubkey);
}
let witness_script = bitcoin::Address::p2pkh(&pubkey, Network::Testnet).script_pubkey();
let payment_script = bitcoin::Address::p2wpkh(&pubkey, Network::Testnet).expect("uncompressed key found").script_pubkey();

if payment_script != output.script_pubkey { return Err(()); };

let sighash = hash_to_message!(&bip143::SigHashCache::new(&spend_tx).signature_hash(input_idx, &witness_script, output.value, SigHashType::All)[..]);
let sig = sign(secp_ctx, &sighash, &secret.private_key.key);
let sig = sign(secp_ctx, &sighash, &secret.private_key);
spend_tx.input[input_idx].witness.push(sig.serialize_der().to_vec());
spend_tx.input[input_idx].witness[0].push(SigHashType::All as u8);
spend_tx.input[input_idx].witness.push(pubkey.key.serialize().to_vec());
spend_tx.input[input_idx].witness.push(pubkey.inner.serialize().to_vec());
},
}
input_idx += 1;
Expand Down Expand Up @@ -1157,7 +1157,7 @@ impl KeysInterface for KeysManager {

let child_ix = self.rand_bytes_child_index.fetch_add(1, Ordering::AcqRel);
let child_privkey = self.rand_bytes_master_key.ckd_priv(&self.secp_ctx, ChildNumber::from_hardened_idx(child_ix as u32).expect("key space exhausted")).expect("Your RNG is busted");
sha.input(&child_privkey.private_key.key[..]);
sha.input(&child_privkey.private_key[..]);

sha.input(b"Unique Secure Random Bytes Salt");
Sha256::from_engine(sha).into_inner()
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/chain/package.rs
Expand Up @@ -18,7 +18,7 @@ use bitcoin::blockdata::script::Script;

use bitcoin::hash_types::Txid;

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

use ln::PaymentPreimage;
use ln::chan_utils::{TxCreationKeys, HTLCOutputInCommitment};
Expand Down Expand Up @@ -852,7 +852,7 @@ mod tests {

use bitcoin::hashes::hex::FromHex;

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

macro_rules! dumb_revk_output {
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/chan_utils.rs
Expand Up @@ -26,7 +26,7 @@ use util::ser::{Readable, Writeable, Writer};
use util::{byte_utils, transaction_utils};

use bitcoin::hash_types::WPubkeyHash;
use bitcoin::secp256k1::key::{SecretKey, PublicKey};
use bitcoin::secp256k1::{SecretKey, PublicKey};
use bitcoin::secp256k1::{Secp256k1, Signature, Message};
use bitcoin::secp256k1::Error as SecpError;
use bitcoin::secp256k1;
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/ln/channel.rs
Expand Up @@ -18,7 +18,7 @@ use bitcoin::hashes::sha256d::Hash as Sha256d;
use bitcoin::hash_types::{Txid, BlockHash};

use bitcoin::secp256k1::constants::PUBLIC_KEY_SIZE;
use bitcoin::secp256k1::key::{PublicKey,SecretKey};
use bitcoin::secp256k1::{PublicKey,SecretKey};
use bitcoin::secp256k1::{Secp256k1,Signature};
use bitcoin::secp256k1;

Expand Down Expand Up @@ -6282,8 +6282,8 @@ mod tests {
use util::logger::Logger;
use bitcoin::secp256k1::{Secp256k1, Message, Signature, All};
use bitcoin::secp256k1::ffi::Signature as FFISignature;
use bitcoin::secp256k1::key::{SecretKey,PublicKey};
use bitcoin::secp256k1::recovery::RecoverableSignature;
use bitcoin::secp256k1::{SecretKey,PublicKey};
use bitcoin::secp256k1::ecdsa::RecoverableSignature;
use bitcoin::hashes::sha256::Hash as Sha256;
use bitcoin::hashes::Hash;
use bitcoin::hash_types::{Txid, WPubkeyHash};
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/channelmanager.rs
Expand Up @@ -28,7 +28,7 @@ use bitcoin::hashes::sha256::Hash as Sha256;
use bitcoin::hashes::sha256d::Hash as Sha256dHash;
use bitcoin::hash_types::{BlockHash, Txid};

use bitcoin::secp256k1::key::{SecretKey,PublicKey};
use bitcoin::secp256k1::{SecretKey,PublicKey};
use bitcoin::secp256k1::Secp256k1;
use bitcoin::secp256k1::ecdh::SharedSecret;
use bitcoin::secp256k1;
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/functional_test_utils.rs
Expand Up @@ -35,7 +35,7 @@ use bitcoin::network::constants::Network;

use bitcoin::hash_types::BlockHash;

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

use io;
use prelude::*;
Expand Down
3 changes: 2 additions & 1 deletion lightning/src/ln/functional_tests.rs
Expand Up @@ -42,7 +42,7 @@ use bitcoin::blockdata::constants::genesis_block;
use bitcoin::network::constants::Network;

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

use regex;

Expand Down Expand Up @@ -2551,6 +2551,7 @@ fn claim_htlc_outputs_single_tx() {
check_added_monitors!(nodes[1], 1);
check_closed_event!(nodes[1], 1, ClosureReason::CommitmentTxConfirmed);
let mut events = nodes[0].node.get_and_clear_pending_events();
println!("XXX {:?}", events);
expect_pending_htlcs_forwardable_from_events!(nodes[0], events[0..1], true);
match events[1] {
Event::ChannelClosed { reason: ClosureReason::CommitmentTxConfirmed, .. } => {}
Expand Down

0 comments on commit 75eef02

Please sign in to comment.