mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-03-15 15:39:09 +01:00
Upgrade to secp256k1 v12, bitcoin v16, and crates bitcoin_hashes
This commit is contained in:
parent
8ce8fbe925
commit
12d25576c1
17 changed files with 227 additions and 241 deletions
|
@ -22,13 +22,13 @@ max_level_info = []
|
|||
max_level_debug = []
|
||||
|
||||
[dependencies]
|
||||
bitcoin = "0.15"
|
||||
bitcoin_hashes = { git = "https://github.com/TheBlueMatt/bitcoin_hashes", branch = "rust-lightning-dep" }
|
||||
bitcoin = "0.16"
|
||||
bitcoin_hashes = "0.2"
|
||||
rand = "0.4"
|
||||
secp256k1 = "0.11"
|
||||
secp256k1 = "0.12"
|
||||
|
||||
[dev-dependencies.bitcoin]
|
||||
version = "0.15"
|
||||
version = "0.16"
|
||||
features = ["bitcoinconsensus"]
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
@ -18,11 +18,11 @@ libfuzzer_fuzz = ["libfuzzer-sys"]
|
|||
[dependencies]
|
||||
afl = { version = "0.4", optional = true }
|
||||
lightning = { path = "..", features = ["fuzztarget"] }
|
||||
bitcoin = { version = "0.15", features = ["fuzztarget"] }
|
||||
bitcoin_hashes = { git = "https://github.com/TheBlueMatt/bitcoin_hashes", branch = "rust-lightning-dep", features=["fuzztarget"] }
|
||||
bitcoin = { version = "0.16", features = ["fuzztarget"] }
|
||||
bitcoin_hashes = { version = "0.2", features=["fuzztarget"] }
|
||||
hex = "0.3"
|
||||
honggfuzz = { version = "0.5", optional = true }
|
||||
secp256k1 = { version = "0.11", features=["fuzztarget"] }
|
||||
secp256k1 = { version = "0.12", features=["fuzztarget"] }
|
||||
libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git", optional = true }
|
||||
|
||||
[build-dependencies]
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -5,7 +5,6 @@ use lightning::ln::peer_channel_encryptor::PeerChannelEncryptor;
|
|||
use lightning::util::reset_rng_state;
|
||||
|
||||
use secp256k1::key::{PublicKey,SecretKey};
|
||||
use secp256k1::Secp256k1;
|
||||
|
||||
#[inline]
|
||||
fn slice_to_be16(v: &[u8]) -> u16 {
|
||||
|
@ -31,14 +30,13 @@ pub fn do_test(data: &[u8]) {
|
|||
}
|
||||
}
|
||||
|
||||
let secp_ctx = Secp256k1::new();
|
||||
let our_network_key = match SecretKey::from_slice(&secp_ctx, get_slice!(32)) {
|
||||
let our_network_key = match SecretKey::from_slice(get_slice!(32)) {
|
||||
Ok(key) => key,
|
||||
Err(_) => return,
|
||||
};
|
||||
|
||||
let mut crypter = if get_slice!(1)[0] != 0 {
|
||||
let their_pubkey = match PublicKey::from_slice(&secp_ctx, get_slice!(33)) {
|
||||
let their_pubkey = match PublicKey::from_slice(get_slice!(33)) {
|
||||
Ok(key) => key,
|
||||
Err(_) => return,
|
||||
};
|
||||
|
|
|
@ -15,7 +15,6 @@ use lightning::util::logger::Logger;
|
|||
use lightning::util::ser::Readable;
|
||||
|
||||
use secp256k1::key::PublicKey;
|
||||
use secp256k1::Secp256k1;
|
||||
|
||||
mod utils;
|
||||
|
||||
|
@ -146,10 +145,9 @@ pub fn do_test(data: &[u8]) {
|
|||
}
|
||||
}
|
||||
|
||||
let secp_ctx = Secp256k1::new();
|
||||
macro_rules! get_pubkey {
|
||||
() => {
|
||||
match PublicKey::from_slice(&secp_ctx, get_slice!(33)) {
|
||||
match PublicKey::from_slice(get_slice!(33)) {
|
||||
Ok(key) => key,
|
||||
Err(_) => return,
|
||||
}
|
||||
|
|
|
@ -133,13 +133,13 @@ impl KeysManager {
|
|||
/// RNG is busted) this may panic.
|
||||
pub fn new(seed: &[u8; 32], network: Network, logger: Arc<Logger>) -> KeysManager {
|
||||
let secp_ctx = Secp256k1::new();
|
||||
match ExtendedPrivKey::new_master(&secp_ctx, network.clone(), seed) {
|
||||
match ExtendedPrivKey::new_master(network.clone(), seed) {
|
||||
Ok(master_key) => {
|
||||
let node_secret = master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(0)).expect("Your RNG is busted").secret_key;
|
||||
let destination_script = match master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(1)) {
|
||||
Ok(destination_key) => {
|
||||
let pubkey_hash160 = Hash160::hash(&ExtendedPubKey::from_private(&secp_ctx, &destination_key).public_key.serialize()[..]);
|
||||
Builder::new().push_opcode(opcodes::All::OP_PUSHBYTES_0)
|
||||
Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0)
|
||||
.push_slice(&pubkey_hash160.into_inner())
|
||||
.into_script()
|
||||
},
|
||||
|
@ -215,7 +215,7 @@ impl KeysInterface for KeysManager {
|
|||
sha.input(&seed);
|
||||
sha.input(&$prev_key[..]);
|
||||
sha.input(&$info[..]);
|
||||
SecretKey::from_slice(&self.secp_ctx, &Sha256::from_engine(sha).into_inner()).expect("SHA-256 is busted")
|
||||
SecretKey::from_slice(&Sha256::from_engine(sha).into_inner()).expect("SHA-256 is busted")
|
||||
}}
|
||||
}
|
||||
let funding_key = key_step!(b"funding key", commitment_seed);
|
||||
|
@ -244,6 +244,6 @@ impl KeysInterface for KeysManager {
|
|||
let child_ix = self.session_child_index.fetch_add(1, Ordering::AcqRel);
|
||||
let child_privkey = self.session_master_key.ckd_priv(&self.secp_ctx, ChildNumber::from_hardened_idx(child_ix as u32)).expect("Your RNG is busted");
|
||||
sha.input(&child_privkey.secret_key[..]);
|
||||
SecretKey::from_slice(&self.secp_ctx, &Sha256::from_engine(sha).into_inner()).expect("Your RNG is busted")
|
||||
SecretKey::from_slice(&Sha256::from_engine(sha).into_inner()).expect("Your RNG is busted")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ pub fn derive_private_key<T: secp256k1::Signing>(secp_ctx: &Secp256k1<T>, per_co
|
|||
let res = Sha256::from_engine(sha).into_inner();
|
||||
|
||||
let mut key = base_secret.clone();
|
||||
key.add_assign(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &res)?)?;
|
||||
key.add_assign(&res)?;
|
||||
Ok(key)
|
||||
}
|
||||
|
||||
|
@ -49,8 +49,8 @@ pub fn derive_public_key<T: secp256k1::Signing>(secp_ctx: &Secp256k1<T>, per_com
|
|||
sha.input(&base_point.serialize());
|
||||
let res = Sha256::from_engine(sha).into_inner();
|
||||
|
||||
let hashkey = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &res)?);
|
||||
base_point.combine(&secp_ctx, &hashkey)
|
||||
let hashkey = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&res)?);
|
||||
base_point.combine(&hashkey)
|
||||
}
|
||||
|
||||
/// Derives a revocation key from its constituent parts
|
||||
|
@ -63,21 +63,21 @@ pub fn derive_private_revocation_key<T: secp256k1::Signing>(secp_ctx: &Secp256k1
|
|||
sha.input(&revocation_base_point.serialize());
|
||||
sha.input(&per_commitment_point.serialize());
|
||||
|
||||
SecretKey::from_slice(&secp_ctx, &Sha256::from_engine(sha).into_inner())?
|
||||
Sha256::from_engine(sha).into_inner()
|
||||
};
|
||||
let commit_append_rev_hash_key = {
|
||||
let mut sha = Sha256::engine();
|
||||
sha.input(&per_commitment_point.serialize());
|
||||
sha.input(&revocation_base_point.serialize());
|
||||
|
||||
SecretKey::from_slice(&secp_ctx, &Sha256::from_engine(sha).into_inner())?
|
||||
Sha256::from_engine(sha).into_inner()
|
||||
};
|
||||
|
||||
let mut part_a = revocation_base_secret.clone();
|
||||
part_a.mul_assign(&secp_ctx, &rev_append_commit_hash_key)?;
|
||||
part_a.mul_assign(&rev_append_commit_hash_key)?;
|
||||
let mut part_b = per_commitment_secret.clone();
|
||||
part_b.mul_assign(&secp_ctx, &commit_append_rev_hash_key)?;
|
||||
part_a.add_assign(&secp_ctx, &part_b)?;
|
||||
part_b.mul_assign(&commit_append_rev_hash_key)?;
|
||||
part_a.add_assign(&part_b[..])?;
|
||||
Ok(part_a)
|
||||
}
|
||||
|
||||
|
@ -87,21 +87,21 @@ pub fn derive_public_revocation_key<T: secp256k1::Verification>(secp_ctx: &Secp2
|
|||
sha.input(&revocation_base_point.serialize());
|
||||
sha.input(&per_commitment_point.serialize());
|
||||
|
||||
SecretKey::from_slice(&secp_ctx, &Sha256::from_engine(sha).into_inner())?
|
||||
Sha256::from_engine(sha).into_inner()
|
||||
};
|
||||
let commit_append_rev_hash_key = {
|
||||
let mut sha = Sha256::engine();
|
||||
sha.input(&per_commitment_point.serialize());
|
||||
sha.input(&revocation_base_point.serialize());
|
||||
|
||||
SecretKey::from_slice(&secp_ctx, &Sha256::from_engine(sha).into_inner())?
|
||||
Sha256::from_engine(sha).into_inner()
|
||||
};
|
||||
|
||||
let mut part_a = revocation_base_point.clone();
|
||||
part_a.mul_assign(&secp_ctx, &rev_append_commit_hash_key)?;
|
||||
let mut part_b = per_commitment_point.clone();
|
||||
part_b.mul_assign(&secp_ctx, &commit_append_rev_hash_key)?;
|
||||
part_a.combine(&secp_ctx, &part_b)
|
||||
part_a.combine(&part_b)
|
||||
}
|
||||
|
||||
pub struct TxCreationKeys {
|
||||
|
@ -129,15 +129,15 @@ impl TxCreationKeys {
|
|||
/// Gets the "to_local" output redeemscript, ie the script which is time-locked or spendable by
|
||||
/// the revocation key
|
||||
pub fn get_revokeable_redeemscript(revocation_key: &PublicKey, to_self_delay: u16, delayed_payment_key: &PublicKey) -> Script {
|
||||
Builder::new().push_opcode(opcodes::All::OP_IF)
|
||||
Builder::new().push_opcode(opcodes::all::OP_IF)
|
||||
.push_slice(&revocation_key.serialize())
|
||||
.push_opcode(opcodes::All::OP_ELSE)
|
||||
.push_opcode(opcodes::all::OP_ELSE)
|
||||
.push_int(to_self_delay as i64)
|
||||
.push_opcode(opcodes::OP_CSV)
|
||||
.push_opcode(opcodes::All::OP_DROP)
|
||||
.push_opcode(opcodes::all::OP_DROP)
|
||||
.push_slice(&delayed_payment_key.serialize())
|
||||
.push_opcode(opcodes::All::OP_ENDIF)
|
||||
.push_opcode(opcodes::All::OP_CHECKSIG)
|
||||
.push_opcode(opcodes::all::OP_ENDIF)
|
||||
.push_opcode(opcodes::all::OP_CHECKSIG)
|
||||
.into_script()
|
||||
}
|
||||
|
||||
|
@ -154,63 +154,63 @@ pub struct HTLCOutputInCommitment {
|
|||
pub fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommitment, a_htlc_key: &PublicKey, b_htlc_key: &PublicKey, revocation_key: &PublicKey) -> Script {
|
||||
let payment_hash160 = Ripemd160::hash(&htlc.payment_hash.0[..]).into_inner();
|
||||
if htlc.offered {
|
||||
Builder::new().push_opcode(opcodes::All::OP_DUP)
|
||||
.push_opcode(opcodes::All::OP_HASH160)
|
||||
Builder::new().push_opcode(opcodes::all::OP_DUP)
|
||||
.push_opcode(opcodes::all::OP_HASH160)
|
||||
.push_slice(&Hash160::hash(&revocation_key.serialize())[..])
|
||||
.push_opcode(opcodes::All::OP_EQUAL)
|
||||
.push_opcode(opcodes::All::OP_IF)
|
||||
.push_opcode(opcodes::All::OP_CHECKSIG)
|
||||
.push_opcode(opcodes::All::OP_ELSE)
|
||||
.push_opcode(opcodes::all::OP_EQUAL)
|
||||
.push_opcode(opcodes::all::OP_IF)
|
||||
.push_opcode(opcodes::all::OP_CHECKSIG)
|
||||
.push_opcode(opcodes::all::OP_ELSE)
|
||||
.push_slice(&b_htlc_key.serialize()[..])
|
||||
.push_opcode(opcodes::All::OP_SWAP)
|
||||
.push_opcode(opcodes::All::OP_SIZE)
|
||||
.push_opcode(opcodes::all::OP_SWAP)
|
||||
.push_opcode(opcodes::all::OP_SIZE)
|
||||
.push_int(32)
|
||||
.push_opcode(opcodes::All::OP_EQUAL)
|
||||
.push_opcode(opcodes::All::OP_NOTIF)
|
||||
.push_opcode(opcodes::All::OP_DROP)
|
||||
.push_opcode(opcodes::all::OP_EQUAL)
|
||||
.push_opcode(opcodes::all::OP_NOTIF)
|
||||
.push_opcode(opcodes::all::OP_DROP)
|
||||
.push_int(2)
|
||||
.push_opcode(opcodes::All::OP_SWAP)
|
||||
.push_opcode(opcodes::all::OP_SWAP)
|
||||
.push_slice(&a_htlc_key.serialize()[..])
|
||||
.push_int(2)
|
||||
.push_opcode(opcodes::All::OP_CHECKMULTISIG)
|
||||
.push_opcode(opcodes::All::OP_ELSE)
|
||||
.push_opcode(opcodes::All::OP_HASH160)
|
||||
.push_opcode(opcodes::all::OP_CHECKMULTISIG)
|
||||
.push_opcode(opcodes::all::OP_ELSE)
|
||||
.push_opcode(opcodes::all::OP_HASH160)
|
||||
.push_slice(&payment_hash160)
|
||||
.push_opcode(opcodes::All::OP_EQUALVERIFY)
|
||||
.push_opcode(opcodes::All::OP_CHECKSIG)
|
||||
.push_opcode(opcodes::All::OP_ENDIF)
|
||||
.push_opcode(opcodes::All::OP_ENDIF)
|
||||
.push_opcode(opcodes::all::OP_EQUALVERIFY)
|
||||
.push_opcode(opcodes::all::OP_CHECKSIG)
|
||||
.push_opcode(opcodes::all::OP_ENDIF)
|
||||
.push_opcode(opcodes::all::OP_ENDIF)
|
||||
.into_script()
|
||||
} else {
|
||||
Builder::new().push_opcode(opcodes::All::OP_DUP)
|
||||
.push_opcode(opcodes::All::OP_HASH160)
|
||||
Builder::new().push_opcode(opcodes::all::OP_DUP)
|
||||
.push_opcode(opcodes::all::OP_HASH160)
|
||||
.push_slice(&Hash160::hash(&revocation_key.serialize())[..])
|
||||
.push_opcode(opcodes::All::OP_EQUAL)
|
||||
.push_opcode(opcodes::All::OP_IF)
|
||||
.push_opcode(opcodes::All::OP_CHECKSIG)
|
||||
.push_opcode(opcodes::All::OP_ELSE)
|
||||
.push_opcode(opcodes::all::OP_EQUAL)
|
||||
.push_opcode(opcodes::all::OP_IF)
|
||||
.push_opcode(opcodes::all::OP_CHECKSIG)
|
||||
.push_opcode(opcodes::all::OP_ELSE)
|
||||
.push_slice(&b_htlc_key.serialize()[..])
|
||||
.push_opcode(opcodes::All::OP_SWAP)
|
||||
.push_opcode(opcodes::All::OP_SIZE)
|
||||
.push_opcode(opcodes::all::OP_SWAP)
|
||||
.push_opcode(opcodes::all::OP_SIZE)
|
||||
.push_int(32)
|
||||
.push_opcode(opcodes::All::OP_EQUAL)
|
||||
.push_opcode(opcodes::All::OP_IF)
|
||||
.push_opcode(opcodes::All::OP_HASH160)
|
||||
.push_opcode(opcodes::all::OP_EQUAL)
|
||||
.push_opcode(opcodes::all::OP_IF)
|
||||
.push_opcode(opcodes::all::OP_HASH160)
|
||||
.push_slice(&payment_hash160)
|
||||
.push_opcode(opcodes::All::OP_EQUALVERIFY)
|
||||
.push_opcode(opcodes::all::OP_EQUALVERIFY)
|
||||
.push_int(2)
|
||||
.push_opcode(opcodes::All::OP_SWAP)
|
||||
.push_opcode(opcodes::all::OP_SWAP)
|
||||
.push_slice(&a_htlc_key.serialize()[..])
|
||||
.push_int(2)
|
||||
.push_opcode(opcodes::All::OP_CHECKMULTISIG)
|
||||
.push_opcode(opcodes::All::OP_ELSE)
|
||||
.push_opcode(opcodes::All::OP_DROP)
|
||||
.push_opcode(opcodes::all::OP_CHECKMULTISIG)
|
||||
.push_opcode(opcodes::all::OP_ELSE)
|
||||
.push_opcode(opcodes::all::OP_DROP)
|
||||
.push_int(htlc.cltv_expiry as i64)
|
||||
.push_opcode(opcodes::OP_CLTV)
|
||||
.push_opcode(opcodes::All::OP_DROP)
|
||||
.push_opcode(opcodes::All::OP_CHECKSIG)
|
||||
.push_opcode(opcodes::All::OP_ENDIF)
|
||||
.push_opcode(opcodes::All::OP_ENDIF)
|
||||
.push_opcode(opcodes::all::OP_DROP)
|
||||
.push_opcode(opcodes::all::OP_CHECKSIG)
|
||||
.push_opcode(opcodes::all::OP_ENDIF)
|
||||
.push_opcode(opcodes::all::OP_ENDIF)
|
||||
.into_script()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -714,7 +714,7 @@ impl Channel {
|
|||
|
||||
fn build_local_commitment_secret(&self, idx: u64) -> SecretKey {
|
||||
let res = chan_utils::build_commitment_secret(self.local_keys.commitment_seed, idx);
|
||||
SecretKey::from_slice(&self.secp_ctx, &res).unwrap()
|
||||
SecretKey::from_slice(&res).unwrap()
|
||||
}
|
||||
|
||||
// Utilities to build transactions:
|
||||
|
@ -915,7 +915,7 @@ impl Channel {
|
|||
|
||||
if value_to_b >= (dust_limit_satoshis as i64) {
|
||||
txouts.push((TxOut {
|
||||
script_pubkey: Builder::new().push_opcode(opcodes::All::OP_PUSHBYTES_0)
|
||||
script_pubkey: Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0)
|
||||
.push_slice(&Hash160::hash(&keys.b_payment_key.serialize())[..])
|
||||
.into_script(),
|
||||
value: value_to_b as u64
|
||||
|
@ -947,7 +947,7 @@ impl Channel {
|
|||
#[inline]
|
||||
fn get_closing_scriptpubkey(&self) -> Script {
|
||||
let our_channel_close_key_hash = Hash160::hash(&self.shutdown_pubkey.serialize());
|
||||
Builder::new().push_opcode(opcodes::All::OP_PUSHBYTES_0).push_slice(&our_channel_close_key_hash[..]).into_script()
|
||||
Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_close_key_hash[..]).into_script()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -1045,7 +1045,7 @@ impl Channel {
|
|||
/// pays to get_funding_redeemscript().to_v0_p2wsh()).
|
||||
/// Panics if called before accept_channel/new_from_req
|
||||
pub fn get_funding_redeemscript(&self) -> Script {
|
||||
let builder = Builder::new().push_opcode(opcodes::All::OP_PUSHNUM_2);
|
||||
let builder = Builder::new().push_opcode(opcodes::all::OP_PUSHNUM_2);
|
||||
let our_funding_key = PublicKey::from_secret_key(&self.secp_ctx, &self.local_keys.funding_key).serialize();
|
||||
let their_funding_key = self.their_funding_pubkey.expect("get_funding_redeemscript only allowed after accept_channel").serialize();
|
||||
if our_funding_key[..] < their_funding_key[..] {
|
||||
|
@ -1054,7 +1054,7 @@ impl Channel {
|
|||
} else {
|
||||
builder.push_slice(&their_funding_key)
|
||||
.push_slice(&our_funding_key)
|
||||
}.push_opcode(opcodes::All::OP_PUSHNUM_2).push_opcode(opcodes::All::OP_CHECKMULTISIG).into_script()
|
||||
}.push_opcode(opcodes::all::OP_PUSHNUM_2).push_opcode(opcodes::all::OP_CHECKMULTISIG).into_script()
|
||||
}
|
||||
|
||||
fn sign_commitment_transaction(&self, tx: &mut Transaction, their_sig: &Signature) -> Signature {
|
||||
|
@ -1075,11 +1075,11 @@ impl Channel {
|
|||
let our_funding_key = PublicKey::from_secret_key(&self.secp_ctx, &self.local_keys.funding_key).serialize();
|
||||
let their_funding_key = self.their_funding_pubkey.unwrap().serialize();
|
||||
if our_funding_key[..] < their_funding_key[..] {
|
||||
tx.input[0].witness.push(our_sig.serialize_der(&self.secp_ctx).to_vec());
|
||||
tx.input[0].witness.push(their_sig.serialize_der(&self.secp_ctx).to_vec());
|
||||
tx.input[0].witness.push(our_sig.serialize_der().to_vec());
|
||||
tx.input[0].witness.push(their_sig.serialize_der().to_vec());
|
||||
} else {
|
||||
tx.input[0].witness.push(their_sig.serialize_der(&self.secp_ctx).to_vec());
|
||||
tx.input[0].witness.push(our_sig.serialize_der(&self.secp_ctx).to_vec());
|
||||
tx.input[0].witness.push(their_sig.serialize_der().to_vec());
|
||||
tx.input[0].witness.push(our_sig.serialize_der().to_vec());
|
||||
}
|
||||
tx.input[0].witness[1].push(SigHashType::All as u8);
|
||||
tx.input[0].witness[2].push(SigHashType::All as u8);
|
||||
|
@ -1124,11 +1124,11 @@ impl Channel {
|
|||
tx.input[0].witness.push(Vec::new()); // First is the multisig dummy
|
||||
|
||||
if local_tx { // b, then a
|
||||
tx.input[0].witness.push(their_sig.serialize_der(&self.secp_ctx).to_vec());
|
||||
tx.input[0].witness.push(our_sig.serialize_der(&self.secp_ctx).to_vec());
|
||||
tx.input[0].witness.push(their_sig.serialize_der().to_vec());
|
||||
tx.input[0].witness.push(our_sig.serialize_der().to_vec());
|
||||
} else {
|
||||
tx.input[0].witness.push(our_sig.serialize_der(&self.secp_ctx).to_vec());
|
||||
tx.input[0].witness.push(their_sig.serialize_der(&self.secp_ctx).to_vec());
|
||||
tx.input[0].witness.push(our_sig.serialize_der().to_vec());
|
||||
tx.input[0].witness.push(their_sig.serialize_der().to_vec());
|
||||
}
|
||||
tx.input[0].witness[1].push(SigHashType::All as u8);
|
||||
tx.input[0].witness[2].push(SigHashType::All as u8);
|
||||
|
@ -1919,7 +1919,7 @@ impl Channel {
|
|||
}
|
||||
|
||||
if let Some(their_prev_commitment_point) = self.their_prev_commitment_point {
|
||||
if PublicKey::from_secret_key(&self.secp_ctx, &secp_check!(SecretKey::from_slice(&self.secp_ctx, &msg.per_commitment_secret), "Peer provided an invalid per_commitment_secret")) != their_prev_commitment_point {
|
||||
if PublicKey::from_secret_key(&self.secp_ctx, &secp_check!(SecretKey::from_slice(&msg.per_commitment_secret), "Peer provided an invalid per_commitment_secret")) != their_prev_commitment_point {
|
||||
return Err(ChannelError::Close("Got a revoke commitment secret which didn't correspond to their current pubkey"));
|
||||
}
|
||||
}
|
||||
|
@ -3953,14 +3953,14 @@ mod tests {
|
|||
fn get_node_secret(&self) -> SecretKey { panic!(); }
|
||||
fn get_destination_script(&self) -> Script {
|
||||
let secp_ctx = Secp256k1::signing_only();
|
||||
let channel_monitor_claim_key = SecretKey::from_slice(&secp_ctx, &hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
|
||||
let channel_monitor_claim_key = SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
|
||||
let our_channel_monitor_claim_key_hash = Hash160::from_data(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
|
||||
Builder::new().push_opcode(opcodes::All::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script()
|
||||
Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script()
|
||||
}
|
||||
|
||||
fn get_shutdown_pubkey(&self) -> PublicKey {
|
||||
let secp_ctx = Secp256k1::signing_only();
|
||||
let channel_close_key = SecretKey::from_slice(&secp_ctx, &hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
|
||||
let channel_close_key = SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
|
||||
PublicKey::from_secret_key(&secp_ctx, &channel_close_key)
|
||||
}
|
||||
|
||||
|
@ -3976,20 +3976,20 @@ mod tests {
|
|||
let secp_ctx = Secp256k1::new();
|
||||
|
||||
let chan_keys = ChannelKeys {
|
||||
funding_key: SecretKey::from_slice(&secp_ctx, &hex::decode("30ff4956bbdd3222d44cc5e8a1261dab1e07957bdac5ae88fe3261ef321f3749").unwrap()[..]).unwrap(),
|
||||
payment_base_key: SecretKey::from_slice(&secp_ctx, &hex::decode("1111111111111111111111111111111111111111111111111111111111111111").unwrap()[..]).unwrap(),
|
||||
delayed_payment_base_key: SecretKey::from_slice(&secp_ctx, &hex::decode("3333333333333333333333333333333333333333333333333333333333333333").unwrap()[..]).unwrap(),
|
||||
htlc_base_key: SecretKey::from_slice(&secp_ctx, &hex::decode("1111111111111111111111111111111111111111111111111111111111111111").unwrap()[..]).unwrap(),
|
||||
funding_key: SecretKey::from_slice(&hex::decode("30ff4956bbdd3222d44cc5e8a1261dab1e07957bdac5ae88fe3261ef321f3749").unwrap()[..]).unwrap(),
|
||||
payment_base_key: SecretKey::from_slice(&hex::decode("1111111111111111111111111111111111111111111111111111111111111111").unwrap()[..]).unwrap(),
|
||||
delayed_payment_base_key: SecretKey::from_slice(&hex::decode("3333333333333333333333333333333333333333333333333333333333333333").unwrap()[..]).unwrap(),
|
||||
htlc_base_key: SecretKey::from_slice(&hex::decode("1111111111111111111111111111111111111111111111111111111111111111").unwrap()[..]).unwrap(),
|
||||
|
||||
// These aren't set in the test vectors:
|
||||
revocation_base_key: SecretKey::from_slice(&secp_ctx, &hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap(),
|
||||
revocation_base_key: SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap(),
|
||||
commitment_seed: [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff],
|
||||
};
|
||||
assert_eq!(PublicKey::from_secret_key(&secp_ctx, &chan_keys.funding_key).serialize()[..],
|
||||
hex::decode("023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb").unwrap()[..]);
|
||||
let keys_provider: Arc<KeysInterface> = Arc::new(Keys { chan_keys });
|
||||
|
||||
let their_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap());
|
||||
let their_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
|
||||
let mut config = UserConfig::new();
|
||||
config.channel_options.announced_channel = false;
|
||||
let mut chan = Channel::new_outbound(&feeest, &keys_provider, their_node_id, 10000000, 100000, 42, Arc::clone(&logger), &config).unwrap(); // Nothing uses their network key in this test
|
||||
|
@ -3999,25 +3999,25 @@ mod tests {
|
|||
let funding_info = OutPoint::new(Sha256dHash::from_hex("8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be").unwrap(), 0);
|
||||
chan.channel_monitor.set_funding_info((funding_info, Script::new()));
|
||||
|
||||
chan.their_payment_basepoint = Some(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &hex::decode("4444444444444444444444444444444444444444444444444444444444444444").unwrap()[..]).unwrap()));
|
||||
chan.their_payment_basepoint = Some(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("4444444444444444444444444444444444444444444444444444444444444444").unwrap()[..]).unwrap()));
|
||||
assert_eq!(chan.their_payment_basepoint.unwrap().serialize()[..],
|
||||
hex::decode("032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991").unwrap()[..]);
|
||||
|
||||
chan.their_funding_pubkey = Some(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &hex::decode("1552dfba4f6cf29a62a0af13c8d6981d36d0ef8d61ba10fb0fe90da7634d7e13").unwrap()[..]).unwrap()));
|
||||
chan.their_funding_pubkey = Some(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("1552dfba4f6cf29a62a0af13c8d6981d36d0ef8d61ba10fb0fe90da7634d7e13").unwrap()[..]).unwrap()));
|
||||
assert_eq!(chan.their_funding_pubkey.unwrap().serialize()[..],
|
||||
hex::decode("030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c1").unwrap()[..]);
|
||||
|
||||
chan.their_htlc_basepoint = Some(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &hex::decode("4444444444444444444444444444444444444444444444444444444444444444").unwrap()[..]).unwrap()));
|
||||
chan.their_htlc_basepoint = Some(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("4444444444444444444444444444444444444444444444444444444444444444").unwrap()[..]).unwrap()));
|
||||
assert_eq!(chan.their_htlc_basepoint.unwrap().serialize()[..],
|
||||
hex::decode("032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991").unwrap()[..]);
|
||||
|
||||
chan.their_revocation_basepoint = Some(PublicKey::from_slice(&secp_ctx, &hex::decode("02466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f27").unwrap()[..]).unwrap());
|
||||
chan.their_revocation_basepoint = Some(PublicKey::from_slice(&hex::decode("02466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f27").unwrap()[..]).unwrap());
|
||||
|
||||
// We can't just use build_local_transaction_keys here as the per_commitment_secret is not
|
||||
// derived from a commitment_seed, so instead we copy it here and call
|
||||
// build_commitment_transaction.
|
||||
let delayed_payment_base = PublicKey::from_secret_key(&secp_ctx, &chan.local_keys.delayed_payment_base_key);
|
||||
let per_commitment_secret = SecretKey::from_slice(&secp_ctx, &hex::decode("1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100").unwrap()[..]).unwrap();
|
||||
let per_commitment_secret = SecretKey::from_slice(&hex::decode("1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100").unwrap()[..]).unwrap();
|
||||
let per_commitment_point = PublicKey::from_secret_key(&secp_ctx, &per_commitment_secret);
|
||||
let htlc_basepoint = PublicKey::from_secret_key(&secp_ctx, &chan.local_keys.htlc_base_key);
|
||||
let keys = TxCreationKeys::new(&secp_ctx, &per_commitment_point, &delayed_payment_base, &htlc_basepoint, &chan.their_revocation_basepoint.unwrap(), &chan.their_payment_basepoint.unwrap(), &chan.their_htlc_basepoint.unwrap()).unwrap();
|
||||
|
@ -4033,7 +4033,7 @@ mod tests {
|
|||
.collect();
|
||||
(res.0, htlcs)
|
||||
};
|
||||
let their_signature = Signature::from_der(&secp_ctx, &hex::decode($their_sig_hex).unwrap()[..]).unwrap();
|
||||
let their_signature = Signature::from_der(&hex::decode($their_sig_hex).unwrap()[..]).unwrap();
|
||||
let sighash = Message::from_slice(&bip143::SighashComponents::new(&unsigned_tx.0).sighash_all(&unsigned_tx.0.input[0], &chan.get_funding_redeemscript(), chan.channel_value_satoshis)[..]).unwrap();
|
||||
secp_ctx.verify(&sighash, &their_signature, &chan.their_funding_pubkey.unwrap()).unwrap();
|
||||
|
||||
|
@ -4046,7 +4046,7 @@ mod tests {
|
|||
|
||||
macro_rules! test_htlc_output {
|
||||
( $htlc_idx: expr, $their_sig_hex: expr, $our_sig_hex: expr, $tx_hex: expr ) => {
|
||||
let remote_signature = Signature::from_der(&secp_ctx, &hex::decode($their_sig_hex).unwrap()[..]).unwrap();
|
||||
let remote_signature = Signature::from_der(&hex::decode($their_sig_hex).unwrap()[..]).unwrap();
|
||||
|
||||
let ref htlc = unsigned_tx.1[$htlc_idx];
|
||||
let mut htlc_tx = chan.build_htlc_transaction(&unsigned_tx.0.txid(), &htlc, true, &keys, chan.feerate_per_kw);
|
||||
|
@ -4489,8 +4489,8 @@ mod tests {
|
|||
// Test vectors from BOLT 3 Appendix E:
|
||||
let secp_ctx = Secp256k1::new();
|
||||
|
||||
let base_secret = SecretKey::from_slice(&secp_ctx, &hex::decode("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f").unwrap()[..]).unwrap();
|
||||
let per_commitment_secret = SecretKey::from_slice(&secp_ctx, &hex::decode("1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100").unwrap()[..]).unwrap();
|
||||
let base_secret = SecretKey::from_slice(&hex::decode("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f").unwrap()[..]).unwrap();
|
||||
let per_commitment_secret = SecretKey::from_slice(&hex::decode("1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100").unwrap()[..]).unwrap();
|
||||
|
||||
let base_point = PublicKey::from_secret_key(&secp_ctx, &base_secret);
|
||||
assert_eq!(base_point.serialize()[..], hex::decode("036d6caac248af96f6afa7f904f550253a0f3ef3f5aa2fe6838a95b216691468e2").unwrap()[..]);
|
||||
|
@ -4502,12 +4502,12 @@ mod tests {
|
|||
hex::decode("0235f2dbfaa89b57ec7b055afe29849ef7ddfeb1cefdb9ebdc43f5494984db29e5").unwrap()[..]);
|
||||
|
||||
assert_eq!(chan_utils::derive_private_key(&secp_ctx, &per_commitment_point, &base_secret).unwrap(),
|
||||
SecretKey::from_slice(&secp_ctx, &hex::decode("cbced912d3b21bf196a766651e436aff192362621ce317704ea2f75d87e7be0f").unwrap()[..]).unwrap());
|
||||
SecretKey::from_slice(&hex::decode("cbced912d3b21bf196a766651e436aff192362621ce317704ea2f75d87e7be0f").unwrap()[..]).unwrap());
|
||||
|
||||
assert_eq!(chan_utils::derive_public_revocation_key(&secp_ctx, &per_commitment_point, &base_point).unwrap().serialize()[..],
|
||||
hex::decode("02916e326636d19c33f13e8c0c3a03dd157f332f3e99c317c141dd865eb01f8ff0").unwrap()[..]);
|
||||
|
||||
assert_eq!(chan_utils::derive_private_revocation_key(&secp_ctx, &per_commitment_secret, &base_secret).unwrap(),
|
||||
SecretKey::from_slice(&secp_ctx, &hex::decode("d09ffff62ddb2297ab000cc85bcb4283fdeb6aa052affbc9dddcf33b61078110").unwrap()[..]).unwrap());
|
||||
SecretKey::from_slice(&hex::decode("d09ffff62ddb2297ab000cc85bcb4283fdeb6aa052affbc9dddcf33b61078110").unwrap()[..]).unwrap());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ impl HTLCSource {
|
|||
pub fn dummy() -> Self {
|
||||
HTLCSource::OutboundRoute {
|
||||
route: Route { hops: Vec::new() },
|
||||
session_priv: SecretKey::from_slice(&::secp256k1::Secp256k1::without_caps(), &[1; 32]).unwrap(),
|
||||
session_priv: SecretKey::from_slice(&[1; 32]).unwrap(),
|
||||
first_hop_htlc_msat: 0,
|
||||
}
|
||||
}
|
||||
|
@ -733,7 +733,7 @@ impl ChannelManager {
|
|||
|
||||
let shared_secret = {
|
||||
let mut arr = [0; 32];
|
||||
arr.copy_from_slice(&SharedSecret::new(&self.secp_ctx, &msg.onion_routing_packet.public_key.unwrap(), &self.our_network_key)[..]);
|
||||
arr.copy_from_slice(&SharedSecret::new(&msg.onion_routing_packet.public_key.unwrap(), &self.our_network_key)[..]);
|
||||
arr
|
||||
};
|
||||
let (rho, mu) = onion_utils::gen_rho_mu_from_shared_secret(&shared_secret);
|
||||
|
@ -827,10 +827,10 @@ impl ChannelManager {
|
|||
let mut sha = Sha256::engine();
|
||||
sha.input(&new_pubkey.serialize()[..]);
|
||||
sha.input(&shared_secret);
|
||||
SecretKey::from_slice(&self.secp_ctx, &Sha256::from_engine(sha).into_inner()).expect("SHA-256 is broken?")
|
||||
Sha256::from_engine(sha).into_inner()
|
||||
};
|
||||
|
||||
let public_key = if let Err(e) = new_pubkey.mul_assign(&self.secp_ctx, &blinding_factor) {
|
||||
let public_key = if let Err(e) = new_pubkey.mul_assign(&self.secp_ctx, &blinding_factor[..]) {
|
||||
Err(e)
|
||||
} else { Ok(new_pubkey) };
|
||||
|
||||
|
|
|
@ -913,8 +913,8 @@ impl ChannelMonitor {
|
|||
serialize_htlc_in_commitment!(htlc_output);
|
||||
if let &Some((ref their_sig, ref our_sig)) = sigs {
|
||||
1u8.write(writer)?;
|
||||
writer.write_all(&their_sig.serialize_compact(&self.secp_ctx))?;
|
||||
writer.write_all(&our_sig.serialize_compact(&self.secp_ctx))?;
|
||||
writer.write_all(&their_sig.serialize_compact())?;
|
||||
writer.write_all(&our_sig.serialize_compact())?;
|
||||
} else {
|
||||
0u8.write(writer)?;
|
||||
}
|
||||
|
@ -1037,7 +1037,7 @@ impl ChannelMonitor {
|
|||
let commitment_number = 0xffffffffffff - ((((tx.input[0].sequence as u64 & 0xffffff) << 3*8) | (tx.lock_time as u64 & 0xffffff)) ^ self.commitment_transaction_number_obscure_factor);
|
||||
if commitment_number >= self.get_min_seen_secret() {
|
||||
let secret = self.get_secret(commitment_number).unwrap();
|
||||
let per_commitment_key = ignore_error!(SecretKey::from_slice(&self.secp_ctx, &secret));
|
||||
let per_commitment_key = ignore_error!(SecretKey::from_slice(&secret));
|
||||
let (revocation_pubkey, b_htlc_key, local_payment_key) = match self.key_storage {
|
||||
Storage::Local { ref revocation_base_key, ref htlc_base_key, ref payment_base_key, .. } => {
|
||||
let per_commitment_point = PublicKey::from_secret_key(&self.secp_ctx, &per_commitment_key);
|
||||
|
@ -1065,7 +1065,7 @@ impl ChannelMonitor {
|
|||
// Note that the Network here is ignored as we immediately drop the address for the
|
||||
// script_pubkey version.
|
||||
let payment_hash160 = Hash160::hash(&PublicKey::from_secret_key(&self.secp_ctx, &payment_key).serialize());
|
||||
Some(Builder::new().push_opcode(opcodes::All::OP_PUSHBYTES_0).push_slice(&payment_hash160[..]).into_script())
|
||||
Some(Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&payment_hash160[..]).into_script())
|
||||
} else { None };
|
||||
|
||||
let mut total_value = 0;
|
||||
|
@ -1113,7 +1113,7 @@ impl ChannelMonitor {
|
|||
unimplemented!();
|
||||
}
|
||||
};
|
||||
$input.witness.push(sig.serialize_der(&self.secp_ctx).to_vec());
|
||||
$input.witness.push(sig.serialize_der().to_vec());
|
||||
$input.witness[0].push(SigHashType::All as u8);
|
||||
if $htlc_idx.is_none() {
|
||||
$input.witness.push(vec!(1));
|
||||
|
@ -1335,7 +1335,7 @@ impl ChannelMonitor {
|
|||
unimplemented!();
|
||||
}
|
||||
};
|
||||
$input.witness.push(sig.serialize_der(&self.secp_ctx).to_vec());
|
||||
$input.witness.push(sig.serialize_der().to_vec());
|
||||
$input.witness[0].push(SigHashType::All as u8);
|
||||
$input.witness.push($preimage);
|
||||
$input.witness.push(redeemscript.into_bytes());
|
||||
|
@ -1461,7 +1461,7 @@ impl ChannelMonitor {
|
|||
}
|
||||
|
||||
let secret = if let Some(secret) = self.get_secret(commitment_number) { secret } else { return (None, None); };
|
||||
let per_commitment_key = ignore_error!(SecretKey::from_slice(&self.secp_ctx, &secret));
|
||||
let per_commitment_key = ignore_error!(SecretKey::from_slice(&secret));
|
||||
let per_commitment_point = PublicKey::from_secret_key(&self.secp_ctx, &per_commitment_key);
|
||||
let revocation_pubkey = match self.key_storage {
|
||||
Storage::Local { ref revocation_base_key, .. } => {
|
||||
|
@ -1520,7 +1520,7 @@ impl ChannelMonitor {
|
|||
unimplemented!();
|
||||
}
|
||||
};
|
||||
spend_tx.input[0].witness.push(sig.serialize_der(&self.secp_ctx).to_vec());
|
||||
spend_tx.input[0].witness.push(sig.serialize_der().to_vec());
|
||||
spend_tx.input[0].witness[0].push(SigHashType::All as u8);
|
||||
spend_tx.input[0].witness.push(vec!(1));
|
||||
spend_tx.input[0].witness.push(redeemscript.into_bytes());
|
||||
|
@ -1573,9 +1573,9 @@ impl ChannelMonitor {
|
|||
|
||||
htlc_timeout_tx.input[0].witness.push(Vec::new()); // First is the multisig dummy
|
||||
|
||||
htlc_timeout_tx.input[0].witness.push(their_sig.serialize_der(&self.secp_ctx).to_vec());
|
||||
htlc_timeout_tx.input[0].witness.push(their_sig.serialize_der().to_vec());
|
||||
htlc_timeout_tx.input[0].witness[1].push(SigHashType::All as u8);
|
||||
htlc_timeout_tx.input[0].witness.push(our_sig.serialize_der(&self.secp_ctx).to_vec());
|
||||
htlc_timeout_tx.input[0].witness.push(our_sig.serialize_der().to_vec());
|
||||
htlc_timeout_tx.input[0].witness[2].push(SigHashType::All as u8);
|
||||
|
||||
htlc_timeout_tx.input[0].witness.push(Vec::new());
|
||||
|
@ -1590,9 +1590,9 @@ impl ChannelMonitor {
|
|||
|
||||
htlc_success_tx.input[0].witness.push(Vec::new()); // First is the multisig dummy
|
||||
|
||||
htlc_success_tx.input[0].witness.push(their_sig.serialize_der(&self.secp_ctx).to_vec());
|
||||
htlc_success_tx.input[0].witness.push(their_sig.serialize_der().to_vec());
|
||||
htlc_success_tx.input[0].witness[1].push(SigHashType::All as u8);
|
||||
htlc_success_tx.input[0].witness.push(our_sig.serialize_der(&self.secp_ctx).to_vec());
|
||||
htlc_success_tx.input[0].witness.push(our_sig.serialize_der().to_vec());
|
||||
htlc_success_tx.input[0].witness[2].push(SigHashType::All as u8);
|
||||
|
||||
htlc_success_tx.input[0].witness.push(payment_preimage.0.to_vec());
|
||||
|
@ -1657,7 +1657,7 @@ impl ChannelMonitor {
|
|||
match self.key_storage {
|
||||
Storage::Local { ref shutdown_pubkey, .. } => {
|
||||
let our_channel_close_key_hash = Hash160::hash(&shutdown_pubkey.serialize());
|
||||
let shutdown_script = Builder::new().push_opcode(opcodes::All::OP_PUSHBYTES_0).push_slice(&our_channel_close_key_hash[..]).into_script();
|
||||
let shutdown_script = Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_close_key_hash[..]).into_script();
|
||||
for (idx, output) in tx.output.iter().enumerate() {
|
||||
if shutdown_script == output.script_pubkey {
|
||||
return Some(SpendableOutputDescriptor::StaticOutput {
|
||||
|
@ -2031,7 +2031,7 @@ impl<R: ::std::io::Read> ReadableArgs<R, Arc<Logger>> for (Sha256dHash, ChannelM
|
|||
if second_point_slice[0..32] == [0; 32] && second_point_slice[32] == 0 {
|
||||
Some((first_idx, first_point, None))
|
||||
} else {
|
||||
Some((first_idx, first_point, Some(unwrap_obj!(PublicKey::from_slice(&secp_ctx, &second_point_slice)))))
|
||||
Some((first_idx, first_point, Some(unwrap_obj!(PublicKey::from_slice(&second_point_slice)))))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -2243,7 +2243,7 @@ mod tests {
|
|||
|
||||
{
|
||||
// insert_secret correct sequence
|
||||
monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[45; 32]).unwrap()), 0, Script::new(), logger.clone());
|
||||
monitor = ChannelMonitor::new(&SecretKey::from_slice(&[42; 32]).unwrap(), &SecretKey::from_slice(&[43; 32]).unwrap(), &SecretKey::from_slice(&[44; 32]).unwrap(), &SecretKey::from_slice(&[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap()), 0, Script::new(), logger.clone());
|
||||
secrets.clear();
|
||||
|
||||
secrets.push([0; 32]);
|
||||
|
@ -2289,7 +2289,7 @@ mod tests {
|
|||
|
||||
{
|
||||
// insert_secret #1 incorrect
|
||||
monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[45; 32]).unwrap()), 0, Script::new(), logger.clone());
|
||||
monitor = ChannelMonitor::new(&SecretKey::from_slice(&[42; 32]).unwrap(), &SecretKey::from_slice(&[43; 32]).unwrap(), &SecretKey::from_slice(&[44; 32]).unwrap(), &SecretKey::from_slice(&[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap()), 0, Script::new(), logger.clone());
|
||||
secrets.clear();
|
||||
|
||||
secrets.push([0; 32]);
|
||||
|
@ -2305,7 +2305,7 @@ mod tests {
|
|||
|
||||
{
|
||||
// insert_secret #2 incorrect (#1 derived from incorrect)
|
||||
monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[45; 32]).unwrap()), 0, Script::new(), logger.clone());
|
||||
monitor = ChannelMonitor::new(&SecretKey::from_slice(&[42; 32]).unwrap(), &SecretKey::from_slice(&[43; 32]).unwrap(), &SecretKey::from_slice(&[44; 32]).unwrap(), &SecretKey::from_slice(&[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap()), 0, Script::new(), logger.clone());
|
||||
secrets.clear();
|
||||
|
||||
secrets.push([0; 32]);
|
||||
|
@ -2331,7 +2331,7 @@ mod tests {
|
|||
|
||||
{
|
||||
// insert_secret #3 incorrect
|
||||
monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[45; 32]).unwrap()), 0, Script::new(), logger.clone());
|
||||
monitor = ChannelMonitor::new(&SecretKey::from_slice(&[42; 32]).unwrap(), &SecretKey::from_slice(&[43; 32]).unwrap(), &SecretKey::from_slice(&[44; 32]).unwrap(), &SecretKey::from_slice(&[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap()), 0, Script::new(), logger.clone());
|
||||
secrets.clear();
|
||||
|
||||
secrets.push([0; 32]);
|
||||
|
@ -2357,7 +2357,7 @@ mod tests {
|
|||
|
||||
{
|
||||
// insert_secret #4 incorrect (1,2,3 derived from incorrect)
|
||||
monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[45; 32]).unwrap()), 0, Script::new(), logger.clone());
|
||||
monitor = ChannelMonitor::new(&SecretKey::from_slice(&[42; 32]).unwrap(), &SecretKey::from_slice(&[43; 32]).unwrap(), &SecretKey::from_slice(&[44; 32]).unwrap(), &SecretKey::from_slice(&[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap()), 0, Script::new(), logger.clone());
|
||||
secrets.clear();
|
||||
|
||||
secrets.push([0; 32]);
|
||||
|
@ -2403,7 +2403,7 @@ mod tests {
|
|||
|
||||
{
|
||||
// insert_secret #5 incorrect
|
||||
monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[45; 32]).unwrap()), 0, Script::new(), logger.clone());
|
||||
monitor = ChannelMonitor::new(&SecretKey::from_slice(&[42; 32]).unwrap(), &SecretKey::from_slice(&[43; 32]).unwrap(), &SecretKey::from_slice(&[44; 32]).unwrap(), &SecretKey::from_slice(&[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap()), 0, Script::new(), logger.clone());
|
||||
secrets.clear();
|
||||
|
||||
secrets.push([0; 32]);
|
||||
|
@ -2439,7 +2439,7 @@ mod tests {
|
|||
|
||||
{
|
||||
// insert_secret #6 incorrect (5 derived from incorrect)
|
||||
monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[45; 32]).unwrap()), 0, Script::new(), logger.clone());
|
||||
monitor = ChannelMonitor::new(&SecretKey::from_slice(&[42; 32]).unwrap(), &SecretKey::from_slice(&[43; 32]).unwrap(), &SecretKey::from_slice(&[44; 32]).unwrap(), &SecretKey::from_slice(&[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap()), 0, Script::new(), logger.clone());
|
||||
secrets.clear();
|
||||
|
||||
secrets.push([0; 32]);
|
||||
|
@ -2485,7 +2485,7 @@ mod tests {
|
|||
|
||||
{
|
||||
// insert_secret #7 incorrect
|
||||
monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[45; 32]).unwrap()), 0, Script::new(), logger.clone());
|
||||
monitor = ChannelMonitor::new(&SecretKey::from_slice(&[42; 32]).unwrap(), &SecretKey::from_slice(&[43; 32]).unwrap(), &SecretKey::from_slice(&[44; 32]).unwrap(), &SecretKey::from_slice(&[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap()), 0, Script::new(), logger.clone());
|
||||
secrets.clear();
|
||||
|
||||
secrets.push([0; 32]);
|
||||
|
@ -2531,7 +2531,7 @@ mod tests {
|
|||
|
||||
{
|
||||
// insert_secret #8 incorrect
|
||||
monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[45; 32]).unwrap()), 0, Script::new(), logger.clone());
|
||||
monitor = ChannelMonitor::new(&SecretKey::from_slice(&[42; 32]).unwrap(), &SecretKey::from_slice(&[43; 32]).unwrap(), &SecretKey::from_slice(&[44; 32]).unwrap(), &SecretKey::from_slice(&[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap()), 0, Script::new(), logger.clone());
|
||||
secrets.clear();
|
||||
|
||||
secrets.push([0; 32]);
|
||||
|
@ -2581,7 +2581,7 @@ mod tests {
|
|||
let secp_ctx = Secp256k1::new();
|
||||
let logger = Arc::new(TestLogger::new());
|
||||
|
||||
let dummy_key = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap());
|
||||
let dummy_key = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
|
||||
macro_rules! dummy_keys {
|
||||
() => {
|
||||
{
|
||||
|
@ -2646,7 +2646,7 @@ mod tests {
|
|||
|
||||
// Prune with one old state and a local commitment tx holding a few overlaps with the
|
||||
// old state.
|
||||
let mut monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[45; 32]).unwrap()), 0, Script::new(), logger.clone());
|
||||
let mut monitor = ChannelMonitor::new(&SecretKey::from_slice(&[42; 32]).unwrap(), &SecretKey::from_slice(&[43; 32]).unwrap(), &SecretKey::from_slice(&[44; 32]).unwrap(), &SecretKey::from_slice(&[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap()), 0, Script::new(), logger.clone());
|
||||
monitor.set_their_to_self_delay(10);
|
||||
|
||||
monitor.provide_latest_local_commitment_tx_info(dummy_tx.clone(), dummy_keys!(), 0, preimages_to_local_htlcs!(preimages[0..10]));
|
||||
|
|
|
@ -2107,7 +2107,7 @@ fn do_channel_reserve_test(test_recv: bool) {
|
|||
|
||||
// Need to manually create update_add_htlc message to go around the channel reserve check in send_htlc()
|
||||
let secp_ctx = Secp256k1::new();
|
||||
let session_priv = SecretKey::from_slice(&secp_ctx, &{
|
||||
let session_priv = SecretKey::from_slice(&{
|
||||
let mut session_key = [0; 32];
|
||||
rng::fill_bytes(&mut session_key);
|
||||
session_key
|
||||
|
@ -5170,7 +5170,7 @@ macro_rules! check_spendable_outputs {
|
|||
witness: Vec::new(),
|
||||
};
|
||||
let outp = TxOut {
|
||||
script_pubkey: Builder::new().push_opcode(opcodes::All::OP_RETURN).into_script(),
|
||||
script_pubkey: Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script(),
|
||||
value: output.value,
|
||||
};
|
||||
let mut spend_tx = Transaction {
|
||||
|
@ -5184,7 +5184,7 @@ macro_rules! check_spendable_outputs {
|
|||
let witness_script = Address::p2pkh(&remotepubkey, Network::Testnet).script_pubkey();
|
||||
let sighash = Message::from_slice(&bip143::SighashComponents::new(&spend_tx).sighash_all(&spend_tx.input[0], &witness_script, output.value)[..]).unwrap();
|
||||
let remotesig = secp_ctx.sign(&sighash, key);
|
||||
spend_tx.input[0].witness.push(remotesig.serialize_der(&secp_ctx).to_vec());
|
||||
spend_tx.input[0].witness.push(remotesig.serialize_der().to_vec());
|
||||
spend_tx.input[0].witness[0].push(SigHashType::All as u8);
|
||||
spend_tx.input[0].witness.push(remotepubkey.serialize().to_vec());
|
||||
txn.push(spend_tx);
|
||||
|
@ -5197,7 +5197,7 @@ macro_rules! check_spendable_outputs {
|
|||
witness: Vec::new(),
|
||||
};
|
||||
let outp = TxOut {
|
||||
script_pubkey: Builder::new().push_opcode(opcodes::All::OP_RETURN).into_script(),
|
||||
script_pubkey: Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script(),
|
||||
value: output.value,
|
||||
};
|
||||
let mut spend_tx = Transaction {
|
||||
|
@ -5209,7 +5209,7 @@ macro_rules! check_spendable_outputs {
|
|||
let secp_ctx = Secp256k1::new();
|
||||
let sighash = Message::from_slice(&bip143::SighashComponents::new(&spend_tx).sighash_all(&spend_tx.input[0], witness_script, output.value)[..]).unwrap();
|
||||
let local_delaysig = secp_ctx.sign(&sighash, key);
|
||||
spend_tx.input[0].witness.push(local_delaysig.serialize_der(&secp_ctx).to_vec());
|
||||
spend_tx.input[0].witness.push(local_delaysig.serialize_der().to_vec());
|
||||
spend_tx.input[0].witness[0].push(SigHashType::All as u8);
|
||||
spend_tx.input[0].witness.push(vec!(0));
|
||||
spend_tx.input[0].witness.push(witness_script.clone().into_bytes());
|
||||
|
@ -5224,7 +5224,7 @@ macro_rules! check_spendable_outputs {
|
|||
witness: Vec::new(),
|
||||
};
|
||||
let outp = TxOut {
|
||||
script_pubkey: Builder::new().push_opcode(opcodes::All::OP_RETURN).into_script(),
|
||||
script_pubkey: Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script(),
|
||||
value: output.value,
|
||||
};
|
||||
let mut spend_tx = Transaction {
|
||||
|
@ -5234,7 +5234,7 @@ macro_rules! check_spendable_outputs {
|
|||
output: vec![outp.clone()],
|
||||
};
|
||||
let secret = {
|
||||
match ExtendedPrivKey::new_master(&secp_ctx, Network::Testnet, &$node.node_seed) {
|
||||
match ExtendedPrivKey::new_master(Network::Testnet, &$node.node_seed) {
|
||||
Ok(master_key) => {
|
||||
match master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx($der_idx)) {
|
||||
Ok(key) => key,
|
||||
|
@ -5248,7 +5248,7 @@ macro_rules! check_spendable_outputs {
|
|||
let witness_script = Address::p2pkh(&pubkey, Network::Testnet).script_pubkey();
|
||||
let sighash = Message::from_slice(&bip143::SighashComponents::new(&spend_tx).sighash_all(&spend_tx.input[0], &witness_script, output.value)[..]).unwrap();
|
||||
let sig = secp_ctx.sign(&sighash, &secret.secret_key);
|
||||
spend_tx.input[0].witness.push(sig.serialize_der(&secp_ctx).to_vec());
|
||||
spend_tx.input[0].witness.push(sig.serialize_der().to_vec());
|
||||
spend_tx.input[0].witness[0].push(SigHashType::All as u8);
|
||||
spend_tx.input[0].witness.push(pubkey.serialize().to_vec());
|
||||
txn.push(spend_tx);
|
||||
|
@ -6397,7 +6397,7 @@ fn test_onion_failure() {
|
|||
|
||||
let mut nodes = create_network(3);
|
||||
for node in nodes.iter() {
|
||||
*node.keys_manager.override_session_priv.lock().unwrap() = Some(SecretKey::from_slice(&Secp256k1::without_caps(), &[3; 32]).unwrap());
|
||||
*node.keys_manager.override_session_priv.lock().unwrap() = Some(SecretKey::from_slice(&[3; 32]).unwrap());
|
||||
}
|
||||
let channels = [create_announced_chan_between_nodes(&nodes, 0, 1), create_announced_chan_between_nodes(&nodes, 1, 2)];
|
||||
let (_, payment_hash) = get_payment_preimage_hash!(nodes[0]);
|
||||
|
@ -6407,7 +6407,7 @@ fn test_onion_failure() {
|
|||
|
||||
// intermediate node failure
|
||||
run_onion_failure_test("invalid_realm", 0, &nodes, &route, &payment_hash, |msg| {
|
||||
let session_priv = SecretKey::from_slice(&::secp256k1::Secp256k1::without_caps(), &[3; 32]).unwrap();
|
||||
let session_priv = SecretKey::from_slice(&[3; 32]).unwrap();
|
||||
let cur_height = nodes[0].node.latest_block_height.load(Ordering::Acquire) as u32 + 1;
|
||||
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route, &session_priv).unwrap();
|
||||
let (mut onion_payloads, _htlc_msat, _htlc_cltv) = onion_utils::build_onion_payloads(&route, cur_height).unwrap();
|
||||
|
@ -6417,7 +6417,7 @@ fn test_onion_failure() {
|
|||
|
||||
// final node failure
|
||||
run_onion_failure_test("invalid_realm", 3, &nodes, &route, &payment_hash, |msg| {
|
||||
let session_priv = SecretKey::from_slice(&::secp256k1::Secp256k1::without_caps(), &[3; 32]).unwrap();
|
||||
let session_priv = SecretKey::from_slice(&[3; 32]).unwrap();
|
||||
let cur_height = nodes[0].node.latest_block_height.load(Ordering::Acquire) as u32 + 1;
|
||||
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route, &session_priv).unwrap();
|
||||
let (mut onion_payloads, _htlc_msat, _htlc_cltv) = onion_utils::build_onion_payloads(&route, cur_height).unwrap();
|
||||
|
@ -6433,7 +6433,7 @@ fn test_onion_failure() {
|
|||
msg.amount_msat -= 1;
|
||||
}, |msg| {
|
||||
// and tamper returing error message
|
||||
let session_priv = SecretKey::from_slice(&::secp256k1::Secp256k1::without_caps(), &[3; 32]).unwrap();
|
||||
let session_priv = SecretKey::from_slice(&[3; 32]).unwrap();
|
||||
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route, &session_priv).unwrap();
|
||||
msg.reason = onion_utils::build_first_hop_failure_packet(&onion_keys[0].shared_secret[..], NODE|2, &[0;0]);
|
||||
}, ||{}, true, Some(NODE|2), Some(msgs::HTLCFailChannelUpdate::NodeFailure{node_id: route.hops[0].pubkey, is_permanent: false}));
|
||||
|
@ -6441,7 +6441,7 @@ fn test_onion_failure() {
|
|||
// final node failure
|
||||
run_onion_failure_test_with_fail_intercept("temporary_node_failure", 200, &nodes, &route, &payment_hash, |_msg| {}, |msg| {
|
||||
// and tamper returing error message
|
||||
let session_priv = SecretKey::from_slice(&::secp256k1::Secp256k1::without_caps(), &[3; 32]).unwrap();
|
||||
let session_priv = SecretKey::from_slice(&[3; 32]).unwrap();
|
||||
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route, &session_priv).unwrap();
|
||||
msg.reason = onion_utils::build_first_hop_failure_packet(&onion_keys[1].shared_secret[..], NODE|2, &[0;0]);
|
||||
}, ||{
|
||||
|
@ -6452,14 +6452,14 @@ fn test_onion_failure() {
|
|||
run_onion_failure_test_with_fail_intercept("permanent_node_failure", 100, &nodes, &route, &payment_hash, |msg| {
|
||||
msg.amount_msat -= 1;
|
||||
}, |msg| {
|
||||
let session_priv = SecretKey::from_slice(&::secp256k1::Secp256k1::without_caps(), &[3; 32]).unwrap();
|
||||
let session_priv = SecretKey::from_slice(&[3; 32]).unwrap();
|
||||
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route, &session_priv).unwrap();
|
||||
msg.reason = onion_utils::build_first_hop_failure_packet(&onion_keys[0].shared_secret[..], PERM|NODE|2, &[0;0]);
|
||||
}, ||{}, true, Some(PERM|NODE|2), Some(msgs::HTLCFailChannelUpdate::NodeFailure{node_id: route.hops[0].pubkey, is_permanent: true}));
|
||||
|
||||
// final node failure
|
||||
run_onion_failure_test_with_fail_intercept("permanent_node_failure", 200, &nodes, &route, &payment_hash, |_msg| {}, |msg| {
|
||||
let session_priv = SecretKey::from_slice(&::secp256k1::Secp256k1::without_caps(), &[3; 32]).unwrap();
|
||||
let session_priv = SecretKey::from_slice(&[3; 32]).unwrap();
|
||||
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route, &session_priv).unwrap();
|
||||
msg.reason = onion_utils::build_first_hop_failure_packet(&onion_keys[1].shared_secret[..], PERM|NODE|2, &[0;0]);
|
||||
}, ||{
|
||||
|
@ -6470,7 +6470,7 @@ fn test_onion_failure() {
|
|||
run_onion_failure_test_with_fail_intercept("required_node_feature_missing", 100, &nodes, &route, &payment_hash, |msg| {
|
||||
msg.amount_msat -= 1;
|
||||
}, |msg| {
|
||||
let session_priv = SecretKey::from_slice(&::secp256k1::Secp256k1::without_caps(), &[3; 32]).unwrap();
|
||||
let session_priv = SecretKey::from_slice(&[3; 32]).unwrap();
|
||||
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route, &session_priv).unwrap();
|
||||
msg.reason = onion_utils::build_first_hop_failure_packet(&onion_keys[0].shared_secret[..], PERM|NODE|3, &[0;0]);
|
||||
}, ||{
|
||||
|
@ -6479,7 +6479,7 @@ fn test_onion_failure() {
|
|||
|
||||
// final node failure
|
||||
run_onion_failure_test_with_fail_intercept("required_node_feature_missing", 200, &nodes, &route, &payment_hash, |_msg| {}, |msg| {
|
||||
let session_priv = SecretKey::from_slice(&::secp256k1::Secp256k1::without_caps(), &[3; 32]).unwrap();
|
||||
let session_priv = SecretKey::from_slice(&[3; 32]).unwrap();
|
||||
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route, &session_priv).unwrap();
|
||||
msg.reason = onion_utils::build_first_hop_failure_packet(&onion_keys[1].shared_secret[..], PERM|NODE|3, &[0;0]);
|
||||
}, ||{
|
||||
|
@ -6498,7 +6498,7 @@ fn test_onion_failure() {
|
|||
run_onion_failure_test_with_fail_intercept("temporary_channel_failure", 100, &nodes, &route, &payment_hash, |msg| {
|
||||
msg.amount_msat -= 1;
|
||||
}, |msg| {
|
||||
let session_priv = SecretKey::from_slice(&::secp256k1::Secp256k1::without_caps(), &[3; 32]).unwrap();
|
||||
let session_priv = SecretKey::from_slice(&[3; 32]).unwrap();
|
||||
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route, &session_priv).unwrap();
|
||||
msg.reason = onion_utils::build_first_hop_failure_packet(&onion_keys[0].shared_secret[..], UPDATE|7, &ChannelUpdate::dummy().encode_with_len()[..]);
|
||||
}, ||{}, true, Some(UPDATE|7), Some(msgs::HTLCFailChannelUpdate::ChannelUpdateMessage{msg: ChannelUpdate::dummy()}));
|
||||
|
@ -6506,7 +6506,7 @@ fn test_onion_failure() {
|
|||
run_onion_failure_test_with_fail_intercept("permanent_channel_failure", 100, &nodes, &route, &payment_hash, |msg| {
|
||||
msg.amount_msat -= 1;
|
||||
}, |msg| {
|
||||
let session_priv = SecretKey::from_slice(&::secp256k1::Secp256k1::without_caps(), &[3; 32]).unwrap();
|
||||
let session_priv = SecretKey::from_slice(&[3; 32]).unwrap();
|
||||
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route, &session_priv).unwrap();
|
||||
msg.reason = onion_utils::build_first_hop_failure_packet(&onion_keys[0].shared_secret[..], PERM|8, &[0;0]);
|
||||
// short_channel_id from the processing node
|
||||
|
@ -6515,7 +6515,7 @@ fn test_onion_failure() {
|
|||
run_onion_failure_test_with_fail_intercept("required_channel_feature_missing", 100, &nodes, &route, &payment_hash, |msg| {
|
||||
msg.amount_msat -= 1;
|
||||
}, |msg| {
|
||||
let session_priv = SecretKey::from_slice(&::secp256k1::Secp256k1::without_caps(), &[3; 32]).unwrap();
|
||||
let session_priv = SecretKey::from_slice(&[3; 32]).unwrap();
|
||||
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route, &session_priv).unwrap();
|
||||
msg.reason = onion_utils::build_first_hop_failure_packet(&onion_keys[0].shared_secret[..], PERM|9, &[0;0]);
|
||||
// short_channel_id from the processing node
|
||||
|
@ -6592,7 +6592,7 @@ fn test_onion_failure() {
|
|||
reconnect_nodes(&nodes[1], &nodes[2], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
|
||||
|
||||
run_onion_failure_test("expiry_too_far", 0, &nodes, &route, &payment_hash, |msg| {
|
||||
let session_priv = SecretKey::from_slice(&::secp256k1::Secp256k1::without_caps(), &[3; 32]).unwrap();
|
||||
let session_priv = SecretKey::from_slice(&[3; 32]).unwrap();
|
||||
let mut route = route.clone();
|
||||
let height = 1;
|
||||
route.hops[1].cltv_expiry_delta += CLTV_FAR_FAR_AWAY + route.hops[0].cltv_expiry_delta + 1;
|
||||
|
@ -6769,8 +6769,6 @@ fn test_update_add_htlc_bolt2_receiver_sender_can_afford_amount_sent() {
|
|||
|
||||
#[test]
|
||||
fn test_update_add_htlc_bolt2_receiver_check_max_htlc_limit() {
|
||||
let secp_ctx = Secp256k1::new();
|
||||
|
||||
//BOLT 2 Requirement: if a sending node adds more than its max_accepted_htlcs HTLCs to its local commitment transaction: SHOULD fail the channel
|
||||
//BOLT 2 Requirement: MUST allow multiple HTLCs with the same payment_hash.
|
||||
let mut nodes = create_network(2);
|
||||
|
@ -6778,14 +6776,14 @@ fn test_update_add_htlc_bolt2_receiver_check_max_htlc_limit() {
|
|||
let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &[], 3999999, TEST_FINAL_CLTV).unwrap();
|
||||
let (_, our_payment_hash) = get_payment_preimage_hash!(nodes[0]);
|
||||
|
||||
let session_priv = SecretKey::from_slice(&secp_ctx, &{
|
||||
let session_priv = SecretKey::from_slice(&{
|
||||
let mut session_key = [0; 32];
|
||||
rng::fill_bytes(&mut session_key);
|
||||
session_key
|
||||
}).expect("RNG is bad!");
|
||||
|
||||
let cur_height = nodes[0].node.latest_block_height.load(Ordering::Acquire) as u32 + 1;
|
||||
let onion_keys = onion_utils::construct_onion_keys(&secp_ctx, &route, &session_priv).unwrap();
|
||||
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::signing_only(), &route, &session_priv).unwrap();
|
||||
let (onion_payloads, _htlc_msat, htlc_cltv) = onion_utils::build_onion_payloads(&route, cur_height).unwrap();
|
||||
let onion_packet = onion_utils::construct_onion_packet(onion_payloads, onion_keys, &our_payment_hash);
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
//! track the network on the less-secure system.
|
||||
|
||||
use secp256k1::key::PublicKey;
|
||||
use secp256k1::{Secp256k1, Signature};
|
||||
use secp256k1::Signature;
|
||||
use secp256k1;
|
||||
use bitcoin::util::hash::Sha256dHash;
|
||||
use bitcoin::blockdata::script::Script;
|
||||
|
@ -908,7 +908,7 @@ impl<R: Read> Readable<R> for OnionPacket {
|
|||
public_key: {
|
||||
let mut buf = [0u8;33];
|
||||
r.read_exact(&mut buf)?;
|
||||
PublicKey::from_slice(&Secp256k1::without_caps(), &buf)
|
||||
PublicKey::from_slice(&buf)
|
||||
},
|
||||
hop_data: Readable::read(r)?,
|
||||
hmac: Readable::read(r)?,
|
||||
|
@ -1346,7 +1346,7 @@ mod tests {
|
|||
fn encoding_channel_reestablish_with_secret() {
|
||||
let public_key = {
|
||||
let secp_ctx = Secp256k1::new();
|
||||
PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &hex::decode("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap())
|
||||
PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap())
|
||||
};
|
||||
|
||||
let cr = msgs::ChannelReestablish {
|
||||
|
|
|
@ -69,7 +69,7 @@ pub(super) fn construct_onion_keys_callback<T: secp256k1::Signing, FType: FnMut(
|
|||
let mut blinded_pub = PublicKey::from_secret_key(secp_ctx, &blinded_priv);
|
||||
|
||||
for hop in route.hops.iter() {
|
||||
let shared_secret = SharedSecret::new(secp_ctx, &hop.pubkey, &blinded_priv);
|
||||
let shared_secret = SharedSecret::new(&hop.pubkey, &blinded_priv);
|
||||
|
||||
let mut sha = Sha256::engine();
|
||||
sha.input(&blinded_pub.serialize()[..]);
|
||||
|
@ -78,7 +78,7 @@ pub(super) fn construct_onion_keys_callback<T: secp256k1::Signing, FType: FnMut(
|
|||
|
||||
let ephemeral_pubkey = blinded_pub;
|
||||
|
||||
blinded_priv.mul_assign(secp_ctx, &SecretKey::from_slice(secp_ctx, &blinding_factor)?)?;
|
||||
blinded_priv.mul_assign(&blinding_factor)?;
|
||||
blinded_pub = PublicKey::from_secret_key(secp_ctx, &blinded_priv);
|
||||
|
||||
callback(shared_secret, blinding_factor, ephemeral_pubkey, hop);
|
||||
|
@ -438,29 +438,29 @@ mod tests {
|
|||
let route = Route {
|
||||
hops: vec!(
|
||||
RouteHop {
|
||||
pubkey: PublicKey::from_slice(&secp_ctx, &hex::decode("02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619").unwrap()[..]).unwrap(),
|
||||
pubkey: PublicKey::from_slice(&hex::decode("02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619").unwrap()[..]).unwrap(),
|
||||
short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0 // Test vectors are garbage and not generateble from a RouteHop, we fill in payloads manually
|
||||
},
|
||||
RouteHop {
|
||||
pubkey: PublicKey::from_slice(&secp_ctx, &hex::decode("0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c").unwrap()[..]).unwrap(),
|
||||
pubkey: PublicKey::from_slice(&hex::decode("0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c").unwrap()[..]).unwrap(),
|
||||
short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0 // Test vectors are garbage and not generateble from a RouteHop, we fill in payloads manually
|
||||
},
|
||||
RouteHop {
|
||||
pubkey: PublicKey::from_slice(&secp_ctx, &hex::decode("027f31ebc5462c1fdce1b737ecff52d37d75dea43ce11c74d25aa297165faa2007").unwrap()[..]).unwrap(),
|
||||
pubkey: PublicKey::from_slice(&hex::decode("027f31ebc5462c1fdce1b737ecff52d37d75dea43ce11c74d25aa297165faa2007").unwrap()[..]).unwrap(),
|
||||
short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0 // Test vectors are garbage and not generateble from a RouteHop, we fill in payloads manually
|
||||
},
|
||||
RouteHop {
|
||||
pubkey: PublicKey::from_slice(&secp_ctx, &hex::decode("032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991").unwrap()[..]).unwrap(),
|
||||
pubkey: PublicKey::from_slice(&hex::decode("032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991").unwrap()[..]).unwrap(),
|
||||
short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0 // Test vectors are garbage and not generateble from a RouteHop, we fill in payloads manually
|
||||
},
|
||||
RouteHop {
|
||||
pubkey: PublicKey::from_slice(&secp_ctx, &hex::decode("02edabbd16b41c8371b92ef2f04c1185b4f03b6dcd52ba9b78d9d7c89c8f221145").unwrap()[..]).unwrap(),
|
||||
pubkey: PublicKey::from_slice(&hex::decode("02edabbd16b41c8371b92ef2f04c1185b4f03b6dcd52ba9b78d9d7c89c8f221145").unwrap()[..]).unwrap(),
|
||||
short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0 // Test vectors are garbage and not generateble from a RouteHop, we fill in payloads manually
|
||||
},
|
||||
),
|
||||
};
|
||||
|
||||
let session_priv = SecretKey::from_slice(&secp_ctx, &hex::decode("4141414141414141414141414141414141414141414141414141414141414141").unwrap()[..]).unwrap();
|
||||
let session_priv = SecretKey::from_slice(&hex::decode("4141414141414141414141414141414141414141414141414141414141414141").unwrap()[..]).unwrap();
|
||||
|
||||
let onion_keys = super::construct_onion_keys(&secp_ctx, &route, &session_priv).unwrap();
|
||||
assert_eq!(onion_keys.len(), route.hops.len());
|
||||
|
|
|
@ -75,7 +75,7 @@ impl PeerChannelEncryptor {
|
|||
rng::fill_bytes(&mut key);
|
||||
|
||||
let secp_ctx = Secp256k1::signing_only();
|
||||
let sec_key = SecretKey::from_slice(&secp_ctx, &key).unwrap(); //TODO: nicer rng-is-bad error message
|
||||
let sec_key = SecretKey::from_slice(&key).unwrap(); //TODO: nicer rng-is-bad error message
|
||||
|
||||
let mut sha = Sha256::engine();
|
||||
sha.input(&NOISE_H);
|
||||
|
@ -177,7 +177,7 @@ impl PeerChannelEncryptor {
|
|||
sha.input(&our_pub.serialize()[..]);
|
||||
state.h = Sha256::from_engine(sha).into_inner();
|
||||
|
||||
let ss = SharedSecret::new(secp_ctx, &their_key, &our_key);
|
||||
let ss = SharedSecret::new(&their_key, &our_key);
|
||||
let temp_k = PeerChannelEncryptor::hkdf(state, ss);
|
||||
|
||||
let mut res = [0; 50];
|
||||
|
@ -193,14 +193,14 @@ impl PeerChannelEncryptor {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn inbound_noise_act<T>(secp_ctx: &Secp256k1<T>, state: &mut BidirectionalNoiseState, act: &[u8], our_key: &SecretKey) -> Result<(PublicKey, [u8; 32]), HandleError> {
|
||||
fn inbound_noise_act(state: &mut BidirectionalNoiseState, act: &[u8], our_key: &SecretKey) -> Result<(PublicKey, [u8; 32]), HandleError> {
|
||||
assert_eq!(act.len(), 50);
|
||||
|
||||
if act[0] != 0 {
|
||||
return Err(HandleError{err: "Unknown handshake version number", action: Some(msgs::ErrorAction::DisconnectPeer{ msg: None })});
|
||||
}
|
||||
|
||||
let their_pub = match PublicKey::from_slice(secp_ctx, &act[1..34]) {
|
||||
let their_pub = match PublicKey::from_slice(&act[1..34]) {
|
||||
Err(_) => return Err(HandleError{err: "Invalid public key", action: Some(msgs::ErrorAction::DisconnectPeer{ msg: None })}),
|
||||
Ok(key) => key,
|
||||
};
|
||||
|
@ -210,7 +210,7 @@ impl PeerChannelEncryptor {
|
|||
sha.input(&their_pub.serialize()[..]);
|
||||
state.h = Sha256::from_engine(sha).into_inner();
|
||||
|
||||
let ss = SharedSecret::new(secp_ctx, &their_pub, &our_key);
|
||||
let ss = SharedSecret::new(&their_pub, &our_key);
|
||||
let temp_k = PeerChannelEncryptor::hkdf(state, ss);
|
||||
|
||||
let mut dec = [0; 0];
|
||||
|
@ -255,7 +255,7 @@ impl PeerChannelEncryptor {
|
|||
panic!("Requested act at wrong step");
|
||||
}
|
||||
|
||||
let (their_pub, _) = PeerChannelEncryptor::inbound_noise_act(&self.secp_ctx, bidirectional_state, act_one, &our_node_secret)?;
|
||||
let (their_pub, _) = PeerChannelEncryptor::inbound_noise_act(bidirectional_state, act_one, &our_node_secret)?;
|
||||
ie.get_or_insert(their_pub);
|
||||
|
||||
re.get_or_insert(our_ephemeral);
|
||||
|
@ -276,7 +276,7 @@ impl PeerChannelEncryptor {
|
|||
|
||||
let mut key = [0u8; 32];
|
||||
rng::fill_bytes(&mut key);
|
||||
let our_ephemeral_key = SecretKey::from_slice(&self.secp_ctx, &key).unwrap(); //TODO: nicer rng-is-bad error message
|
||||
let our_ephemeral_key = SecretKey::from_slice(&key).unwrap(); //TODO: nicer rng-is-bad error message
|
||||
self.process_act_one_with_ephemeral_key(act_one, our_node_secret, our_ephemeral_key)
|
||||
}
|
||||
|
||||
|
@ -293,7 +293,7 @@ impl PeerChannelEncryptor {
|
|||
panic!("Requested act at wrong step");
|
||||
}
|
||||
|
||||
let (re, temp_k2) = PeerChannelEncryptor::inbound_noise_act(&self.secp_ctx, bidirectional_state, act_two, &ie)?;
|
||||
let (re, temp_k2) = PeerChannelEncryptor::inbound_noise_act(bidirectional_state, act_two, &ie)?;
|
||||
|
||||
let mut res = [0; 66];
|
||||
let our_node_id = PublicKey::from_secret_key(&self.secp_ctx, &our_node_secret);
|
||||
|
@ -305,7 +305,7 @@ impl PeerChannelEncryptor {
|
|||
sha.input(&res[1..50]);
|
||||
bidirectional_state.h = Sha256::from_engine(sha).into_inner();
|
||||
|
||||
let ss = SharedSecret::new(&self.secp_ctx, &re, our_node_secret);
|
||||
let ss = SharedSecret::new(&re, our_node_secret);
|
||||
let temp_k = PeerChannelEncryptor::hkdf(bidirectional_state, ss);
|
||||
|
||||
PeerChannelEncryptor::encrypt_with_ad(&mut res[50..], 0, &temp_k, &bidirectional_state.h, &[0; 0]);
|
||||
|
@ -349,7 +349,7 @@ impl PeerChannelEncryptor {
|
|||
|
||||
let mut their_node_id = [0; 33];
|
||||
PeerChannelEncryptor::decrypt_with_ad(&mut their_node_id, 1, &temp_k2.unwrap(), &bidirectional_state.h, &act_three[1..50])?;
|
||||
self.their_node_id = Some(match PublicKey::from_slice(&self.secp_ctx, &their_node_id) {
|
||||
self.their_node_id = Some(match PublicKey::from_slice(&their_node_id) {
|
||||
Ok(key) => key,
|
||||
Err(_) => return Err(HandleError{err: "Bad node_id from peer", action: Some(msgs::ErrorAction::DisconnectPeer{ msg: None })}),
|
||||
});
|
||||
|
@ -359,7 +359,7 @@ impl PeerChannelEncryptor {
|
|||
sha.input(&act_three[1..50]);
|
||||
bidirectional_state.h = Sha256::from_engine(sha).into_inner();
|
||||
|
||||
let ss = SharedSecret::new(&self.secp_ctx, &self.their_node_id.unwrap(), &re.unwrap());
|
||||
let ss = SharedSecret::new(&self.their_node_id.unwrap(), &re.unwrap());
|
||||
let temp_k = PeerChannelEncryptor::hkdf(bidirectional_state, ss);
|
||||
|
||||
PeerChannelEncryptor::decrypt_with_ad(&mut [0; 0], 0, &temp_k, &bidirectional_state.h, &act_three[50..])?;
|
||||
|
@ -481,7 +481,6 @@ impl PeerChannelEncryptor {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use secp256k1::Secp256k1;
|
||||
use secp256k1::key::{PublicKey,SecretKey};
|
||||
|
||||
use hex;
|
||||
|
@ -489,14 +488,13 @@ mod tests {
|
|||
use ln::peer_channel_encryptor::{PeerChannelEncryptor,NoiseState,DirectionalNoiseState};
|
||||
|
||||
fn get_outbound_peer_for_initiator_test_vectors() -> PeerChannelEncryptor {
|
||||
let secp_ctx = Secp256k1::new();
|
||||
let their_node_id = PublicKey::from_slice(&secp_ctx, &hex::decode("028d7500dd4c12685d1f568b4c2b5048e8534b873319f3a8daa612b469132ec7f7").unwrap()[..]).unwrap();
|
||||
let their_node_id = PublicKey::from_slice(&hex::decode("028d7500dd4c12685d1f568b4c2b5048e8534b873319f3a8daa612b469132ec7f7").unwrap()[..]).unwrap();
|
||||
|
||||
let mut outbound_peer = PeerChannelEncryptor::new_outbound(their_node_id);
|
||||
match outbound_peer.noise_state {
|
||||
NoiseState::InProgress { state: _, ref mut directional_state, bidirectional_state: _ } => {
|
||||
*directional_state = DirectionalNoiseState::Outbound { // overwrite ie...
|
||||
ie: SecretKey::from_slice(&secp_ctx, &hex::decode("1212121212121212121212121212121212121212121212121212121212121212").unwrap()[..]).unwrap(),
|
||||
ie: SecretKey::from_slice(&hex::decode("1212121212121212121212121212121212121212121212121212121212121212").unwrap()[..]).unwrap(),
|
||||
};
|
||||
},
|
||||
_ => panic!()
|
||||
|
@ -508,8 +506,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn noise_initiator_test_vectors() {
|
||||
let secp_ctx = Secp256k1::new();
|
||||
let our_node_id = SecretKey::from_slice(&secp_ctx, &hex::decode("1111111111111111111111111111111111111111111111111111111111111111").unwrap()[..]).unwrap();
|
||||
let our_node_id = SecretKey::from_slice(&hex::decode("1111111111111111111111111111111111111111111111111111111111111111").unwrap()[..]).unwrap();
|
||||
|
||||
{
|
||||
// transport-initiator successful handshake
|
||||
|
@ -561,9 +558,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn noise_responder_test_vectors() {
|
||||
let secp_ctx = Secp256k1::new();
|
||||
let our_node_id = SecretKey::from_slice(&secp_ctx, &hex::decode("2121212121212121212121212121212121212121212121212121212121212121").unwrap()[..]).unwrap();
|
||||
let our_ephemeral = SecretKey::from_slice(&secp_ctx, &hex::decode("2222222222222222222222222222222222222222222222222222222222222222").unwrap()[..]).unwrap();
|
||||
let our_node_id = SecretKey::from_slice(&hex::decode("2121212121212121212121212121212121212121212121212121212121212121").unwrap()[..]).unwrap();
|
||||
let our_ephemeral = SecretKey::from_slice(&hex::decode("2222222222222222222222222222222222222222222222222222222222222222").unwrap()[..]).unwrap();
|
||||
|
||||
{
|
||||
// transport-responder successful handshake
|
||||
|
@ -663,14 +659,12 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn message_encryption_decryption_test_vectors() {
|
||||
let secp_ctx = Secp256k1::new();
|
||||
|
||||
// We use the same keys as the initiator and responder test vectors, so we copy those tests
|
||||
// here and use them to encrypt.
|
||||
let mut outbound_peer = get_outbound_peer_for_initiator_test_vectors();
|
||||
|
||||
{
|
||||
let our_node_id = SecretKey::from_slice(&secp_ctx, &hex::decode("1111111111111111111111111111111111111111111111111111111111111111").unwrap()[..]).unwrap();
|
||||
let our_node_id = SecretKey::from_slice(&hex::decode("1111111111111111111111111111111111111111111111111111111111111111").unwrap()[..]).unwrap();
|
||||
|
||||
let act_two = hex::decode("0002466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae").unwrap().to_vec();
|
||||
assert_eq!(outbound_peer.process_act_two(&act_two[..], &our_node_id).unwrap().0[..], hex::decode("00b9e3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa22355361aa02e55a8fc28fef5bd6d71ad0c38228dc68b1c466263b47fdf31e560e139ba").unwrap()[..]);
|
||||
|
@ -692,8 +686,8 @@ mod tests {
|
|||
|
||||
{
|
||||
// transport-responder successful handshake
|
||||
let our_node_id = SecretKey::from_slice(&secp_ctx, &hex::decode("2121212121212121212121212121212121212121212121212121212121212121").unwrap()[..]).unwrap();
|
||||
let our_ephemeral = SecretKey::from_slice(&secp_ctx, &hex::decode("2222222222222222222222222222222222222222222222222222222222222222").unwrap()[..]).unwrap();
|
||||
let our_node_id = SecretKey::from_slice(&hex::decode("2121212121212121212121212121212121212121212121212121212121212121").unwrap()[..]).unwrap();
|
||||
let our_ephemeral = SecretKey::from_slice(&hex::decode("2222222222222222222222222222222222222222222222222222222222222222").unwrap()[..]).unwrap();
|
||||
|
||||
inbound_peer = PeerChannelEncryptor::new_inbound(&our_node_id);
|
||||
|
||||
|
|
|
@ -1091,7 +1091,6 @@ mod tests {
|
|||
}
|
||||
|
||||
fn create_network(peer_count: usize) -> Vec<PeerManager<FileDescriptor>> {
|
||||
let secp_ctx = Secp256k1::new();
|
||||
let mut peers = Vec::new();
|
||||
let mut rng = thread_rng();
|
||||
let logger : Arc<Logger> = Arc::new(test_utils::TestLogger::new());
|
||||
|
@ -1102,7 +1101,7 @@ mod tests {
|
|||
let node_id = {
|
||||
let mut key_slice = [0;32];
|
||||
rng.fill_bytes(&mut key_slice);
|
||||
SecretKey::from_slice(&secp_ctx, &key_slice).unwrap()
|
||||
SecretKey::from_slice(&key_slice).unwrap()
|
||||
};
|
||||
let msg_handler = MessageHandler { chan_handler: Arc::new(chan_handler), route_handler: Arc::new(router) };
|
||||
let peer = PeerManager::new(msg_handler, node_id, Arc::clone(&logger));
|
||||
|
|
|
@ -284,10 +284,11 @@ impl RoutingMessageHandler for Router {
|
|||
|
||||
let checked_utxo = match self.chain_monitor.get_chain_utxo(msg.contents.chain_hash, msg.contents.short_channel_id) {
|
||||
Ok((script_pubkey, _value)) => {
|
||||
let expected_script = Builder::new().push_opcode(opcodes::All::OP_PUSHNUM_2)
|
||||
let expected_script = Builder::new().push_opcode(opcodes::all::OP_PUSHNUM_2)
|
||||
.push_slice(&msg.contents.bitcoin_key_1.serialize())
|
||||
.push_slice(&msg.contents.bitcoin_key_2.serialize())
|
||||
.push_opcode(opcodes::All::OP_PUSHNUM_2).push_opcode(opcodes::All::OP_CHECKMULTISIG).into_script().to_v0_p2wsh();
|
||||
.push_opcode(opcodes::all::OP_PUSHNUM_2)
|
||||
.push_opcode(opcodes::all::OP_CHECKMULTISIG).into_script().to_v0_p2wsh();
|
||||
if script_pubkey != expected_script {
|
||||
return Err(HandleError{err: "Channel announcement keys didn't match on-chain script", action: Some(ErrorAction::IgnoreError)});
|
||||
}
|
||||
|
@ -859,7 +860,7 @@ mod tests {
|
|||
#[test]
|
||||
fn route_test() {
|
||||
let secp_ctx = Secp256k1::new();
|
||||
let our_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &hex::decode("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap());
|
||||
let our_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap());
|
||||
let logger: Arc<Logger> = Arc::new(test_utils::TestLogger::new());
|
||||
let chain_monitor = Arc::new(chaininterface::ChainWatchInterfaceUtil::new(Network::Testnet, Arc::clone(&logger)));
|
||||
let router = Router::new(our_id, chain_monitor, Arc::clone(&logger));
|
||||
|
@ -921,14 +922,14 @@ mod tests {
|
|||
// chan11 1-to-2: enabled, 0 fee
|
||||
// chan11 2-to-1: enabled, 0 fee
|
||||
|
||||
let node1 = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &hex::decode("0202020202020202020202020202020202020202020202020202020202020202").unwrap()[..]).unwrap());
|
||||
let node2 = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &hex::decode("0303030303030303030303030303030303030303030303030303030303030303").unwrap()[..]).unwrap());
|
||||
let node3 = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &hex::decode("0404040404040404040404040404040404040404040404040404040404040404").unwrap()[..]).unwrap());
|
||||
let node4 = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &hex::decode("0505050505050505050505050505050505050505050505050505050505050505").unwrap()[..]).unwrap());
|
||||
let node5 = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &hex::decode("0606060606060606060606060606060606060606060606060606060606060606").unwrap()[..]).unwrap());
|
||||
let node6 = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &hex::decode("0707070707070707070707070707070707070707070707070707070707070707").unwrap()[..]).unwrap());
|
||||
let node7 = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &hex::decode("0808080808080808080808080808080808080808080808080808080808080808").unwrap()[..]).unwrap());
|
||||
let node8 = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &hex::decode("0909090909090909090909090909090909090909090909090909090909090909").unwrap()[..]).unwrap());
|
||||
let node1 = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("0202020202020202020202020202020202020202020202020202020202020202").unwrap()[..]).unwrap());
|
||||
let node2 = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("0303030303030303030303030303030303030303030303030303030303030303").unwrap()[..]).unwrap());
|
||||
let node3 = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("0404040404040404040404040404040404040404040404040404040404040404").unwrap()[..]).unwrap());
|
||||
let node4 = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("0505050505050505050505050505050505050505050505050505050505050505").unwrap()[..]).unwrap());
|
||||
let node5 = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("0606060606060606060606060606060606060606060606060606060606060606").unwrap()[..]).unwrap());
|
||||
let node6 = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("0707070707070707070707070707070707070707070707070707070707070707").unwrap()[..]).unwrap());
|
||||
let node7 = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("0808080808080808080808080808080808080808080808080808080808080808").unwrap()[..]).unwrap());
|
||||
let node8 = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("0909090909090909090909090909090909090909090909090909090909090909").unwrap()[..]).unwrap());
|
||||
|
||||
let zero_hash = Sha256dHash::from_data(&[0; 32]);
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::io::{Read, Write};
|
|||
use std::collections::HashMap;
|
||||
use std::hash::Hash;
|
||||
|
||||
use secp256k1::{Secp256k1, Signature};
|
||||
use secp256k1::Signature;
|
||||
use secp256k1::key::{PublicKey, SecretKey};
|
||||
use bitcoin::util::hash::Sha256dHash;
|
||||
use bitcoin::blockdata::script::Script;
|
||||
|
@ -334,7 +334,7 @@ impl Writeable for PublicKey {
|
|||
impl<R: Read> Readable<R> for PublicKey {
|
||||
fn read(r: &mut R) -> Result<Self, DecodeError> {
|
||||
let buf: [u8; 33] = Readable::read(r)?;
|
||||
match PublicKey::from_slice(&Secp256k1::without_caps(), &buf) {
|
||||
match PublicKey::from_slice(&buf) {
|
||||
Ok(key) => Ok(key),
|
||||
Err(_) => return Err(DecodeError::InvalidValue),
|
||||
}
|
||||
|
@ -352,7 +352,7 @@ impl Writeable for SecretKey {
|
|||
impl<R: Read> Readable<R> for SecretKey {
|
||||
fn read(r: &mut R) -> Result<Self, DecodeError> {
|
||||
let buf: [u8; 32] = Readable::read(r)?;
|
||||
match SecretKey::from_slice(&Secp256k1::without_caps(), &buf) {
|
||||
match SecretKey::from_slice(&buf) {
|
||||
Ok(key) => Ok(key),
|
||||
Err(_) => return Err(DecodeError::InvalidValue),
|
||||
}
|
||||
|
@ -374,14 +374,14 @@ impl<R: Read> Readable<R> for Sha256dHash {
|
|||
|
||||
impl Writeable for Signature {
|
||||
fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
|
||||
self.serialize_compact(&Secp256k1::without_caps()).write(w)
|
||||
self.serialize_compact().write(w)
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: Read> Readable<R> for Signature {
|
||||
fn read(r: &mut R) -> Result<Self, DecodeError> {
|
||||
let buf: [u8; 64] = Readable::read(r)?;
|
||||
match Signature::from_compact(&Secp256k1::without_caps(), &buf) {
|
||||
match Signature::from_compact(&buf) {
|
||||
Ok(sig) => Ok(sig),
|
||||
Err(_) => return Err(DecodeError::InvalidValue),
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue