Skip to content
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

Add example using implementing Extension for APO emulation #32

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

sanket1729
Copy link
Member

@sanket1729 sanket1729 commented Oct 7, 2022

Follows BIP118, without fixing the annex. Annex introspection is not currently supported.

All other descriptor APIs only deal with sane miniscripts
Ideally, we want to do using more granular components defined in the
library. As a simple example, this implements apo as a single fragment.
@@ -1022,7 +1022,8 @@ impl_from_str!(
Ok(tr) => Ok(Descriptor::Tr(tr)),
Err(_) => {
// Try parsing with extensions
let tr = Tr::<Pk, T>::from_str(s)?;
// descriptors are always parsed insane. This will improve once we use upstream ExtParams Api.
let tr = Tr::<Pk, T>::from_str_insane(s)?;
Copy link
Member

Choose a reason for hiding this comment

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

In acced27:

This is a bit eyebrow-raising. This means that Descriptor::from_str will no longer enforce any sanity rules when parsing tapscripts?

This is fine if it's temporary and we're going to fix it when we bring ExtParams down, but the comment should have the text FIXME in it so that we have a reminder to deal with it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, this comment was wrong/incomplete. This was meant to covenant descriptors should be parsed as insane because they are not safe(in the sense there is no signature guarding it).

Parsing regular descriptors should work as expected.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, perfect. Can you update the comment?

/// The data that needs to be signed in apo + all.
/// We can decompose this into into individual parts for fixing version, amt, script pubkey
///
/// This structure is onyl an example of how one might implement extension. We do pay any
Copy link
Member

Choose a reason for hiding this comment

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

In 66aeb41:

nit onyl should be only

Copy link
Member

Choose a reason for hiding this comment

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

Also do pay should be do not pay I think :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Lol :)


use opcodes::all::*;
builder = builder
.push_opcode(OP_INSPECTVERSION).push_slice(&self.version.to_le_bytes()).push_opcode(OP_EQUALVERIFY)
Copy link
Member

Choose a reason for hiding this comment

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

In 66aeb41:

I would really prefer that all the .push_ methods got their own line.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, on closer reading I see that the reason is that you've got INSEPECTXXX <XXX> EQV all on one line ... so I feel less strongly. But I'd still suggest breaking it up across separate lines and maybe adding comments in between to separate the sections.

@apoelstra
Copy link
Member

This looks great! Super cool to see how APO works.

One thing that confuses me here is that it seems you're only validating the one input -- is this how APO is supposed to work? This seems like it's SighashAll + ANYONECANPAY + ANYPREVOUT rather than just all+apo. It also seems unfortunate that you need to commit to the target data in the scriptpubkey, but for an example implementation I think that's fine. (I think what we'd actually like to do is add a csfs combinator which took a pubkey and arbitrary set of ValueExpr/AssetExpr/SpkExpr/NumExprs and hashed them all together, or something, but that's a much more invasive change.)

Done reviewing 66aeb41.

@sanket1729
Copy link
Member Author

This seems like it's SighashAll + ANYONECANPAY + ANYPREVOUT rather than just all+apo

APO is similar to ACP, but not that we do not commit to the previous outpoint here. If this was ACP, we would be committing to Outpoint.

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.

2 participants