Skip to content

Commit c8ae81e

Browse files
committed
Push slices as AsRef<PushBytes> when building scripts
1 parent ed19eef commit c8ae81e

File tree

6 files changed

+18
-13
lines changed

6 files changed

+18
-13
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ impl SignerProvider for KeyProvider {
274274
let secp_ctx = Secp256k1::signing_only();
275275
let channel_monitor_claim_key = SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, self.node_secret[31]]).unwrap();
276276
let our_channel_monitor_claim_key_hash = WPubkeyHash::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
277-
Ok(Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script())
277+
Ok(Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(our_channel_monitor_claim_key_hash).into_script())
278278
}
279279

280280
fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {

fuzz/src/full_stack.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ impl SignerProvider for KeyProvider {
395395
let secp_ctx = Secp256k1::signing_only();
396396
let channel_monitor_claim_key = SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
397397
let our_channel_monitor_claim_key_hash = WPubkeyHash::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
398-
Ok(Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script())
398+
Ok(Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(our_channel_monitor_claim_key_hash).into_script())
399399
}
400400

401401
fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {

lightning/src/ln/chan_utils.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -603,12 +603,12 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
603603
if htlc.offered {
604604
let mut bldr = Builder::new().push_opcode(opcodes::all::OP_DUP)
605605
.push_opcode(opcodes::all::OP_HASH160)
606-
.push_slice(&PubkeyHash::hash(&revocation_key.serialize())[..])
606+
.push_slice(PubkeyHash::hash(&revocation_key.serialize()))
607607
.push_opcode(opcodes::all::OP_EQUAL)
608608
.push_opcode(opcodes::all::OP_IF)
609609
.push_opcode(opcodes::all::OP_CHECKSIG)
610610
.push_opcode(opcodes::all::OP_ELSE)
611-
.push_slice(&countersignatory_htlc_key.serialize()[..])
611+
.push_slice(countersignatory_htlc_key.serialize())
612612
.push_opcode(opcodes::all::OP_SWAP)
613613
.push_opcode(opcodes::all::OP_SIZE)
614614
.push_int(32)
@@ -617,7 +617,7 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
617617
.push_opcode(opcodes::all::OP_DROP)
618618
.push_int(2)
619619
.push_opcode(opcodes::all::OP_SWAP)
620-
.push_slice(&broadcaster_htlc_key.serialize()[..])
620+
.push_slice(broadcaster_htlc_key.serialize())
621621
.push_int(2)
622622
.push_opcode(opcodes::all::OP_CHECKMULTISIG)
623623
.push_opcode(opcodes::all::OP_ELSE)
@@ -636,12 +636,12 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
636636
} else {
637637
let mut bldr = Builder::new().push_opcode(opcodes::all::OP_DUP)
638638
.push_opcode(opcodes::all::OP_HASH160)
639-
.push_slice(&PubkeyHash::hash(&revocation_key.serialize())[..])
639+
.push_slice(PubkeyHash::hash(&revocation_key.serialize()))
640640
.push_opcode(opcodes::all::OP_EQUAL)
641641
.push_opcode(opcodes::all::OP_IF)
642642
.push_opcode(opcodes::all::OP_CHECKSIG)
643643
.push_opcode(opcodes::all::OP_ELSE)
644-
.push_slice(&countersignatory_htlc_key.serialize()[..])
644+
.push_slice(countersignatory_htlc_key.serialize())
645645
.push_opcode(opcodes::all::OP_SWAP)
646646
.push_opcode(opcodes::all::OP_SIZE)
647647
.push_int(32)
@@ -652,7 +652,7 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
652652
.push_opcode(opcodes::all::OP_EQUALVERIFY)
653653
.push_int(2)
654654
.push_opcode(opcodes::all::OP_SWAP)
655-
.push_slice(&broadcaster_htlc_key.serialize()[..])
655+
.push_slice(broadcaster_htlc_key.serialize())
656656
.push_int(2)
657657
.push_opcode(opcodes::all::OP_CHECKMULTISIG)
658658
.push_opcode(opcodes::all::OP_ELSE)
@@ -688,7 +688,7 @@ pub fn make_funding_redeemscript(broadcaster: &PublicKey, countersignatory: &Pub
688688
make_funding_redeemscript_from_slices(&broadcaster_funding_key, &countersignatory_funding_key)
689689
}
690690

691-
pub(crate) fn make_funding_redeemscript_from_slices(broadcaster_funding_key: &[u8], countersignatory_funding_key: &[u8]) -> ScriptBuf {
691+
pub(crate) fn make_funding_redeemscript_from_slices(broadcaster_funding_key: &[u8; 33], countersignatory_funding_key: &[u8; 33]) -> ScriptBuf {
692692
let builder = Builder::new().push_opcode(opcodes::all::OP_PUSHNUM_2);
693693
if broadcaster_funding_key[..] < countersignatory_funding_key[..] {
694694
builder.push_slice(broadcaster_funding_key)
@@ -818,7 +818,7 @@ pub(crate) fn legacy_deserialization_prevention_marker_for_channel_type_features
818818
#[inline]
819819
pub fn get_to_countersignatory_with_anchors_redeemscript(payment_point: &PublicKey) -> ScriptBuf {
820820
Builder::new()
821-
.push_slice(&payment_point.serialize()[..])
821+
.push_slice(payment_point.serialize())
822822
.push_opcode(opcodes::all::OP_CHECKSIGVERIFY)
823823
.push_int(1)
824824
.push_opcode(opcodes::all::OP_CSV)
@@ -833,7 +833,7 @@ pub fn get_to_countersignatory_with_anchors_redeemscript(payment_point: &PublicK
833833
/// (empty vector required to satisfy compliance with MINIMALIF-standard rule)
834834
#[inline]
835835
pub fn get_anchor_redeemscript(funding_pubkey: &PublicKey) -> ScriptBuf {
836-
Builder::new().push_slice(&funding_pubkey.serialize()[..])
836+
Builder::new().push_slice(funding_pubkey.serialize())
837837
.push_opcode(opcodes::all::OP_CHECKSIG)
838838
.push_opcode(opcodes::all::OP_IFDUP)
839839
.push_opcode(opcodes::all::OP_NOTIF)

lightning/src/ln/channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7867,7 +7867,7 @@ mod tests {
78677867
let secp_ctx = Secp256k1::signing_only();
78687868
let channel_monitor_claim_key = SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
78697869
let channel_monitor_claim_key_hash = WPubkeyHash::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
7870-
Ok(Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&channel_monitor_claim_key_hash[..]).into_script())
7870+
Ok(Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(channel_monitor_claim_key_hash).into_script())
78717871
}
78727872

78737873
fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {

lightning/src/routing/gossip.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ impl NodeId {
8181
&self.0
8282
}
8383

84+
/// Get the public key as an array from this NodeId
85+
pub fn as_array(&self) -> &[u8; PUBLIC_KEY_SIZE] {
86+
&self.0
87+
}
88+
8489
/// Get the public key from this NodeId
8590
pub fn as_pubkey(&self) -> Result<PublicKey, secp256k1::Error> {
8691
PublicKey::from_slice(&self.0)

lightning/src/routing/utxo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ impl PendingChecks {
460460
match res {
461461
Ok(TxOut { value, script_pubkey }) => {
462462
let expected_script =
463-
make_funding_redeemscript_from_slices(msg.bitcoin_key_1.as_slice(), msg.bitcoin_key_2.as_slice()).to_v0_p2wsh();
463+
make_funding_redeemscript_from_slices(msg.bitcoin_key_1.as_array(), msg.bitcoin_key_2.as_array()).to_v0_p2wsh();
464464
if script_pubkey != expected_script {
465465
return Err(LightningError{
466466
err: format!("Channel announcement key ({}) didn't match on-chain script ({})",

0 commit comments

Comments
 (0)