Skip to content

Complete Resource limits #168

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

Merged
merged 10 commits into from
Nov 18, 2020
Merged

Conversation

sanket1729
Copy link
Member

@sanket1729 sanket1729 commented Nov 5, 2020

Completes the resource limit detection of miniscript. Marking as draft, because we should merge this after #150 .

Fixes #134

@sanket1729 sanket1729 force-pushed the resource_limits_new branch 3 times, most recently from df9eba0 to 73a2a4c Compare November 5, 2020 16:15
@sanket1729 sanket1729 force-pushed the resource_limits_new branch 3 times, most recently from bdeb626 to add9523 Compare November 6, 2020 08:00
#[derive(Debug)]
pub enum AnalysisError {
/// Top level is not safe.
TopLevelNonSafe,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should rename

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SiglessBranch maybe?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BranchWithNoSignature is ok actually, it's not crazy long

/// Use this function to check whether the guarantees of library hold.
/// Most functions of the library like would still
/// work, but results cannot be relied upon
pub fn check_safety(&self) -> Result<(), AnalysisError> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should rename

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe sanity_check

And then we could have parse_insane and from_str_insane :P

/// Repeated Pubkeys
RepeatedPubkeys,
/// Miniscript contains atleast one path that exceeds resource limits
ResourceLimitsExceeded,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also should rename to indicate that it's maybe only one branch

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BranchExceedsResourceLimits lol this is getting a bit long..

// extra allocation using clone allows us to reuse
// check safety function from Miniscript fragment instead
// of implemneting more code for safety checks
svm.clone().multi_ms().sanity_check()?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should pull this clone-and-sanity-check logic into its own method on SortedMultiVec. Even though it's internal I think it's confusing to have a method multi_ms which does not sort the keys (and which therefore does not match the actual conversion of the SVM to a miniscript)

Copy link
Member Author

@sanket1729 sanket1729 Nov 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried doing this. The odd part about that I don't have access to Ctx to create a new miniscript which I do not have inside the SortedMultiVec.

That is we don't know whether we have to create a new Miniscript<_, Legacy> or Segwitv0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can parameterize the sanity-check function over Ctx, which will be a bit awkward to call but should work

.map(|pk_pkh| match pk_pkh {
PkPkh::PlainPubkey(pk) => pk.to_pubkeyhash(),
PkPkh::HashedPubkey(h) => h,
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can drop the .map here entirely

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And substitute it with?

@apoelstra
Copy link
Member

utack, except nits, and also there is an IRC discussion about naming for the validity constraints

Updated Bare descriptor to use Bare Ctx

Updated Bare descriptor to user Bare context
for standardness checks instead of previously
incorrect Legacy context

Combine top level checks
Add Russel's doc about multiparty policy
entailment to the repository.
Some of the compiler guanrantees are lost if we
allow repeated keys. The compiler should error on
these keys
@apoelstra apoelstra merged commit f2ac1c4 into rust-bitcoin:master Nov 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Miniscript Resource Limit calculations
2 participants