Skip to content

Commit

Permalink
error: remove two more variants which were redundant with threshold e…
Browse files Browse the repository at this point in the history
…rrors
  • Loading branch information
apoelstra committed Nov 13, 2024
1 parent 0d5612d commit 3a20537
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
8 changes: 0 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,6 @@ pub enum Error {
AddrError(bitcoin::address::ParseError),
/// rust-bitcoin p2sh address error
AddrP2shError(bitcoin::address::P2shError),
/// A `CHECKMULTISIG` opcode was preceded by a number > 20
CmsTooManyKeys(u32),
/// A tapscript multi_a cannot support more than Weight::MAX_BLOCK/32 keys
MultiATooManyKeys(u64),
/// While parsing backward, hit beginning of script
UnexpectedStart,
/// Got something we were not expecting
Expand Down Expand Up @@ -504,7 +500,6 @@ impl fmt::Display for Error {
Error::Script(ref e) => fmt::Display::fmt(e, f),
Error::AddrError(ref e) => fmt::Display::fmt(e, f),
Error::AddrP2shError(ref e) => fmt::Display::fmt(e, f),
Error::CmsTooManyKeys(n) => write!(f, "checkmultisig with {} keys", n),
Error::UnexpectedStart => f.write_str("unexpected start of script"),
Error::Unexpected(ref s) => write!(f, "unexpected «{}»", s),
Error::MultiColon(ref s) => write!(f, "«{}» has multiple instances of «:»", s),
Expand Down Expand Up @@ -539,7 +534,6 @@ impl fmt::Display for Error {
Error::PubKeyCtxError(ref pk, ref ctx) => {
write!(f, "Pubkey error: {} under {} scriptcontext", pk, ctx)
}
Error::MultiATooManyKeys(k) => write!(f, "MultiA too many keys {}", k),
Error::TrNoScriptCode => write!(f, "No script code for Tr descriptors"),
Error::MultipathDescLenMismatch => write!(f, "At least two BIP389 key expressions in the descriptor contain tuples of derivation indexes of different lengths"),
Error::AbsoluteLockTime(ref e) => e.fmt(f),
Expand All @@ -560,8 +554,6 @@ impl std::error::Error for Error {
InvalidOpcode(_)
| NonMinimalVerify(_)
| InvalidPush(_)
| CmsTooManyKeys(_)
| MultiATooManyKeys(_)
| UnexpectedStart
| Unexpected(_)
| MultiColon(_)
Expand Down
16 changes: 8 additions & 8 deletions src/miniscript/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,10 +538,10 @@ pub fn parse<Ctx: ScriptContext>(
},
// CHECKMULTISIG based multisig
Tk::CheckMultiSig, Tk::Num(n) => {
// Check size before allocating keys
if n as usize > MAX_PUBKEYS_PER_MULTISIG {
return Err(Error::CmsTooManyKeys(n));
}
// Check size before allocating keys. Note that constructing a
// vector of ()s, no matter the size, takes no allocations.
Threshold::<(), MAX_PUBKEYS_PER_MULTISIG>::new(1, vec![(); n as usize]).map_err(Error::Threshold)?;

let mut keys = Vec::with_capacity(n as usize);
for _ in 0..n {
match_token!(
Expand All @@ -562,10 +562,10 @@ pub fn parse<Ctx: ScriptContext>(
},
// MultiA
Tk::NumEqual, Tk::Num(k) => {
// Check size before allocating keys
if k as usize > MAX_PUBKEYS_IN_CHECKSIGADD {
return Err(Error::MultiATooManyKeys(MAX_PUBKEYS_IN_CHECKSIGADD as u64))
}
// Check size before allocating keys. Note that constructing a
// vector of ()s, no matter the size, takes no allocations.
Threshold::<(), MAX_PUBKEYS_IN_CHECKSIGADD>::new(k as usize, vec![(); k as usize]).map_err(Error::Threshold)?;

let mut keys = Vec::with_capacity(k as usize); // atleast k capacity
while tokens.peek() == Some(&Tk::CheckSigAdd) {
match_token!(
Expand Down

0 comments on commit 3a20537

Please sign in to comment.