Skip to content

Commit

Permalink
Merge pull request lightningdevkit#387 from whfuyn/fix-invalid-witnes…
Browse files Browse the repository at this point in the history
…s-program-len

Fix invalid witness program length
  • Loading branch information
tnull authored Oct 28, 2024
2 parents e031651 + ec26f06 commit bcea1c2
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,12 @@ where
let script_pubkey = u.txout.script_pubkey;
match script_pubkey.witness_version() {
Some(version @ WitnessVersion::V0) => {
let witness_program = WitnessProgram::new(version, script_pubkey.as_bytes())
.map_err(|e| {
log_error!(self.logger, "Failed to retrieve script payload: {}", e);
})?;
let witness_program =
WitnessProgram::new(version, &script_pubkey.as_bytes()[2..]).map_err(
|e| {
log_error!(self.logger, "Failed to retrieve script payload: {}", e);
},
)?;

let wpkh = WPubkeyHash::from_slice(&witness_program.program().as_bytes())
.map_err(|e| {
Expand All @@ -400,10 +402,12 @@ where
utxos.push(utxo);
},
Some(version @ WitnessVersion::V1) => {
let witness_program = WitnessProgram::new(version, script_pubkey.as_bytes())
.map_err(|e| {
log_error!(self.logger, "Failed to retrieve script payload: {}", e);
})?;
let witness_program =
WitnessProgram::new(version, &script_pubkey.as_bytes()[2..]).map_err(
|e| {
log_error!(self.logger, "Failed to retrieve script payload: {}", e);
},
)?;

XOnlyPublicKey::from_slice(&witness_program.program().as_bytes()).map_err(
|e| {
Expand Down

0 comments on commit bcea1c2

Please sign in to comment.