Skip to content

Commit 1794af9

Browse files
committed
Adding threshold error on exceeding 1000 ways
Signed-off-by: Harshil Jani <[email protected]>
1 parent 4773718 commit 1794af9

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Diff for: src/descriptor/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,11 @@ impl Descriptor<DescriptorPublicKey>{
615615

616616
/// Get all possible assets for a given descriptor
617617
pub fn get_all_assets(&self) -> Result<Vec<Assets>, Error> {
618-
618+
let threshold = self.count_assets();
619+
if threshold >= 1000 {
620+
return Err(Error::MaxAssetThresholdExceeded);
621+
}
622+
619623
match self {
620624
Descriptor::Bare(k) => Ok(k.as_inner().get_all_assets()),
621625
Descriptor::Pkh(k) => {

Diff for: src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,8 @@ pub enum Error {
558558
/// At least two BIP389 key expressions in the descriptor contain tuples of
559559
/// derivation indexes of different lengths.
560560
MultipathDescLenMismatch,
561+
/// Cannot get assets for this large descriptor. Exceeds 1000 assets.
562+
MaxAssetThresholdExceeded,
561563
}
562564

563565
// https://github.com/sipa/miniscript/pull/5 for discussion on this number
@@ -634,6 +636,7 @@ impl fmt::Display for Error {
634636
Error::TrNoScriptCode => write!(f, "No script code for Tr descriptors"),
635637
Error::TrNoExplicitScript => write!(f, "No script code for Tr descriptors"),
636638
Error::MultipathDescLenMismatch => write!(f, "At least two BIP389 key expressions in the descriptor contain tuples of derivation indexes of different lengths"),
639+
Error::MaxAssetThresholdExceeded => write!(f,"Cannot plan descriptors having more than 1000 possible spend paths."),
637640
}
638641
}
639642
}
@@ -676,6 +679,7 @@ impl error::Error for Error {
676679
| TrNoScriptCode
677680
| TrNoExplicitScript
678681
| MultipathDescLenMismatch => None,
682+
MaxAssetThresholdExceeded => None,
679683
Script(e) => Some(e),
680684
AddrError(e) => Some(e),
681685
BadPubkey(e) => Some(e),

0 commit comments

Comments
 (0)