Skip to content

Commit d60078f

Browse files
committed
Merge #968: 13.x: Preserve finalized PSBT inputs
aecd5dc Remove link to doc file (Tobin C. Harding) f24a5b5 13.x: Bump version to 13.0.1 (Noah Joeris) 894fe4a 13.x: Preserve finalized PSBT inputs (Noah Joeris) Pull request description: Backport of #960 and #873 to the 13.x branch. This preserves PSBT inputs that already have `final_script_sig` or `final_script_witness`, avoiding re-finalization failures when finalized inputs no longer contain fields such as `witness_script` or `partial_sigs`. Also bumps the 13.x branch version to 13.0.1 for a new patch release. ACKs for top commit: apoelstra: ACK aecd5dc; successfully ran local tests tcharding: ACK aecd5dc Tree-SHA512: 14143cfedb1a31ea709f8f574ee321331896b8d7c01826ffeeceb392ab58d0d722bca91308b27ecc992069a7f719211bd6889ed29d9f8ea2d5f467493389fae4
2 parents 8990b63 + aecd5dc commit d60078f

5 files changed

Lines changed: 33 additions & 6 deletions

File tree

Cargo-minimal.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ version = "0.0.1"
112112
dependencies = [
113113
"honggfuzz",
114114
"miniscript 12.3.0",
115-
"miniscript 13.0.0",
115+
"miniscript 13.0.1",
116116
"regex",
117117
]
118118

@@ -198,7 +198,7 @@ dependencies = [
198198

199199
[[package]]
200200
name = "miniscript"
201-
version = "13.0.0"
201+
version = "13.0.1"
202202
dependencies = [
203203
"bech32",
204204
"bitcoin",

Cargo-recent.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ version = "0.0.1"
112112
dependencies = [
113113
"honggfuzz",
114114
"miniscript 12.3.0",
115-
"miniscript 13.0.0",
115+
"miniscript 13.0.1",
116116
"regex",
117117
]
118118

@@ -198,7 +198,7 @@ dependencies = [
198198

199199
[[package]]
200200
name = "miniscript"
201-
version = "13.0.0"
201+
version = "13.0.1"
202202
dependencies = [
203203
"bech32",
204204
"bitcoin",

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "miniscript"
3-
version = "13.0.0"
3+
version = "13.0.1"
44
authors = ["Andrew Poelstra <apoelstra@wpsoftware.net>, Sanket Kanjalkar <sanket1729@gmail.com>"]
55
license = "CC0-1.0"
66
homepage = "https://github.com/rust-bitcoin/rust-miniscript/"

src/policy/concrete.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
346346
///
347347
/// It is **not recommended** to use policy as a stable identifier for a miniscript. You should
348348
/// use the policy compiler once, and then use the miniscript output as a stable identifier. See
349-
/// the compiler document in [`doc/compiler.md`] for more details.
349+
/// the compiler document in `./doc/compiler.md` for more details.
350350
#[cfg(feature = "compiler")]
351351
pub fn compile_to_descriptor<Ctx: ScriptContext>(
352352
&self,

src/psbt/finalizer.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,13 @@ pub(super) fn finalize_input<C: secp256k1::Verification>(
431431
secp: &Secp256k1<C>,
432432
allow_mall: bool,
433433
) -> Result<(), super::Error> {
434+
// Preserve previously finalized inputs
435+
if psbt.inputs[index].final_script_sig.is_some()
436+
|| psbt.inputs[index].final_script_witness.is_some()
437+
{
438+
return Ok(());
439+
}
440+
434441
let (witness, script_sig) = finalize_input_helper(psbt, index, secp, allow_mall)?;
435442

436443
// Now mutate the psbt input. Note that we cannot error after this point.
@@ -457,6 +464,7 @@ pub(super) fn finalize_input<C: secp256k1::Verification>(
457464

458465
#[cfg(test)]
459466
mod tests {
467+
use bitcoin::{absolute, transaction, Transaction, TxIn};
460468
use hex;
461469

462470
use super::*;
@@ -472,4 +480,23 @@ mod tests {
472480
let expected = Psbt::deserialize(&hex::decode_to_vec("70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000000100bb0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f6187650000000107da00473044022074018ad4180097b873323c0015720b3684cc8123891048e7dbcd9b55ad679c99022073d369b740e3eb53dcefa33823c8070514ca55a7dd9544f157c167913261118c01483045022100f61038b308dc1da865a34852746f015772934208c6d24454393cd99bdf2217770220056e675a675a6d0a02b85b14e5e29074d8a25a9b5760bea2816f661910a006ea01475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae0001012000c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e8870107232200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b20289030108da0400473044022062eb7a556107a7c73f45ac4ab5a1dddf6f7075fb1275969a7f383efff784bcb202200c05dbb7470dbf2f08557dd356c7325c1ed30913e996cd3840945db12228da5f01473044022065f45ba5998b59a27ffe1a7bed016af1f1f90d54b3aa8f7450aa5f56a25103bd02207f724703ad1edb96680b284b56d4ffcb88f7fb759eabbe08aa30f29b851383d20147522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae00220203a9a4c37f5996d3aa25dbac6b570af0650394492942460b354753ed9eeca5877110d90c6a4f000000800000008004000080002202027f6399757d2eff55a136ad02c684b1838b6556e5f1b6b34282a94b6b5005109610d90c6a4f00000080000000800500008000").unwrap()).unwrap();
473481
assert_eq!(psbt, expected);
474482
}
483+
484+
#[test]
485+
fn finalize_skips_already_finalized_input() {
486+
let tx = Transaction {
487+
version: transaction::Version::ONE,
488+
lock_time: absolute::LockTime::ZERO,
489+
input: vec![TxIn::default()],
490+
output: vec![],
491+
};
492+
let mut psbt = Psbt::from_unsigned_tx(tx).unwrap();
493+
psbt.inputs[0].final_script_witness = Some(Witness::from_slice(&[vec![1]]));
494+
495+
let expected_input = psbt.inputs[0].clone();
496+
let secp = Secp256k1::verification_only();
497+
498+
psbt.finalize_mut(&secp).unwrap();
499+
500+
assert_eq!(psbt.inputs[0], expected_input);
501+
}
475502
}

0 commit comments

Comments
 (0)