Skip to content

Stack len for legacy max_satisfaction_weight calculations #474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/descriptor/bare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ impl<Pk: MiniscriptKey> Bare<Pk> {
/// When the descriptor is impossible to safisfy (ex: sh(OP_FALSE)).
pub fn max_satisfaction_weight(&self) -> Result<usize, Error> {
let scriptsig_len = self.ms.max_satisfaction_size()?;
Ok(4 * (varint_len(scriptsig_len) + scriptsig_len))
Ok(4 * (varint_len(scriptsig_len) + scriptsig_len) +
// witness stack size varint (always 1WU for non-segwit)
1)
}
}

Expand Down Expand Up @@ -219,7 +221,9 @@ impl<Pk: MiniscriptKey> Pkh<Pk> {
/// sighash suffix. Includes the weight of the VarInts encoding the
/// scriptSig and witness stack length.
pub fn max_satisfaction_weight(&self) -> usize {
4 * (1 + 73 + BareCtx::pk_len(&self.pk))
4 * (1 + 73 + BareCtx::pk_len(&self.pk)) +
// witness stack size varint (always 1 WU for non-segwit)
1
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/descriptor/sh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,19 @@ impl<Pk: MiniscriptKey> Sh<Pk> {
let ss = smv.script_size();
let ps = push_opcode_size(ss);
let scriptsig_len = ps + ss + smv.max_satisfaction_size();
4 * (varint_len(scriptsig_len) + scriptsig_len)
4 * (varint_len(scriptsig_len) + scriptsig_len) +
// witnessData stack length
1
}
// add weighted script sig, len byte stays the same
ShInner::Wpkh(ref wpkh) => 4 * 23 + wpkh.max_satisfaction_weight(),
ShInner::Ms(ref ms) => {
let ss = ms.script_size();
let ps = push_opcode_size(ss);
let scriptsig_len = ps + ss + ms.max_satisfaction_size()?;
4 * (varint_len(scriptsig_len) + scriptsig_len)
4 * (varint_len(scriptsig_len) + scriptsig_len) +
// witnessData stack length
1
}
})
}
Expand Down