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 API to PSBT to enable signing inputs #957

Merged
merged 3 commits into from Oct 20, 2022

Conversation

tcharding
Copy link
Member

@tcharding tcharding commented Apr 19, 2022

Add an API for signing inputs to the PSBT struct. This is work based on code in rust-miniscript and the API design suggestions below from @sanket1729 and @Kixunil.

Please note, this adds an unimplemented! call for taproot inputs. ECDSA signing is complete.

Includes a patch adding the psbt example from #940 updated to use this new api. Run cargo run --example psbt --features=bitcoinconsensus to test it out.

Copy link
Contributor

@DanGould DanGould left a comment

Choose a reason for hiding this comment

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

Concept ACK

src/util/psbt/mod.rs Outdated Show resolved Hide resolved
src/util/psbt/mod.rs Outdated Show resolved Hide resolved
@tcharding tcharding force-pushed the sign-psbt branch 2 times, most recently from 8764c85 to bdf7aa6 Compare May 19, 2022 05:55
@tcharding tcharding marked this pull request as ready for review May 19, 2022 06:08
@tcharding tcharding marked this pull request as draft May 19, 2022 06:12
@tcharding tcharding marked this pull request as ready for review May 20, 2022 02:54
src/util/psbt/mod.rs Outdated Show resolved Hide resolved
src/util/psbt/mod.rs Outdated Show resolved Hide resolved
src/util/psbt/mod.rs Outdated Show resolved Hide resolved
@tcharding
Copy link
Member Author

Thanks for the revew @dunxen, I'll take a look at your suggestions and re-spin the PR.

@tcharding
Copy link
Member Author

Converting to draft because this PR is half baked, it has some taproot functionality and not all of it.

@tcharding tcharding marked this pull request as draft May 24, 2022 06:07
@tcharding tcharding force-pushed the sign-psbt branch 2 times, most recently from d22a8da to a795f43 Compare May 24, 2022 23:55
@DanGould
Copy link
Contributor

It would be useful to advance the project at large to merge this without taproot support then add taproot support after since #940 and #935 depend on this functionality sans-taproot

@dunxen
Copy link
Contributor

dunxen commented May 25, 2022

It would be useful to advance the project at large to merge this without taproot support then add taproot support after since #940 and #935 depend on this functionality sans-taproot

Yeah, I think this is reasonable. Getting taproot support in before next release would probably still be important (and doable). I have have no reservations about having it in a follow up PR :)

@tcharding
Copy link
Member Author

Ok, in line with the two comments above I've updated this PR to explicitly not support taproot by returning an error if psbt.sign is called with a taproot input. Let's see what other reviewers think.

I've rebased #940 on top, perhaps you want to do #935 the same @DanGould, that would lend weight to having this merged.

@tcharding tcharding marked this pull request as ready for review May 25, 2022 05:31
@tcharding
Copy link
Member Author

tcharding commented May 25, 2022

In case its of any use, I had a play with you 935 patch @DanGould, you can look at branch psbt-test-dan-gould on my fork if you want to.

@dunxen
Copy link
Contributor

dunxen commented May 25, 2022

explicitly not support taproot by returning an error if psbt.sign is called with a taproot input.

Great! I was going to suggest exactly that 😃

I'll give this a proper review when I'm back home in a couple hours.

Copy link
Contributor

@dunxen dunxen left a comment

Choose a reason for hiding this comment

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

Light review ACK 6fe41f7

Comment on lines 339 to 402
self.check_index_is_within_bounds(input_index)?;

Copy link
Contributor

Choose a reason for hiding this comment

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

Since we check the bounds higher up in sign(), do we need to do it here too? Same with sighash()? I guess this is pretty defensive as it is now so no big deal :)

Suggested change
self.check_index_is_within_bounds(input_index)?;

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes this is defensive, I personally prefer to see a length check anywhere I see an array access.

@Kixunil
Copy link
Collaborator

Kixunil commented May 26, 2022

Will have to run soon, just a thought: it should be either sign_edsa or provide Taproot too.

@tcharding
Copy link
Member Author

Its set up ready to add taproot, currently sign errors for a taproot input, for other inputs it calls sign_ecdsa. Happy with that?

@Kixunil
Copy link
Collaborator

Kixunil commented May 30, 2022

I don't like the implied churn adding and removing error variants in the next release just because of this. Maybe unimplemented!() would be better. At least it'd increase motivation to add implementation soon. :)

@tcharding
Copy link
Member Author

Fair point, I originally put a panic! but then thought an error would be slightly better. Happy to go with an unimplemented if there are no objections to that. Thanks for the review, this signing stuff is obscure (at least for me).

@tcharding
Copy link
Member Author

I can assist with the schnorr signing in a follow-up if you'd like :)

That would be awesome!

@tcharding
Copy link
Member Author

Rebase only, no other changes.

apoelstra
apoelstra previously approved these changes Sep 30, 2022
Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK cabafc5

sanket1729
sanket1729 previously approved these changes Oct 19, 2022
Copy link
Member

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

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

ACK cabafc5. Reviewed the range-diff from a6355d2. I can work on follow-up with the hardcoded tests here.

I think this PR is getting to the point where Github is annoying to deal with. If others have any lingering issues, we can address those in follow ups.

PSBT automation moved this from Review in progress to Ready for merge Oct 19, 2022
@tcharding
Copy link
Member Author

Thanks for all the reviews today @sanket1729, good to have you back here in rust-bitcoin :)

@tcharding
Copy link
Member Author

2 acks, merge baby merge! This one has been open for six months (although admittedly for much of that time it was not in a mergable state)

@apoelstra
Copy link
Member

Needs rebase, sorry!

The import statements in `psbt/mod.rs` are a bit of a mess, re-order
them in an attempt to group like things and separate out things that are
different (e.g. `pub use` from `use`).

Refactor only, no logic changes.
Signing a PSBT requires no knowledge other than what we have here in
this library and the PSBT ready to be signed.

This code was pulled out of `rust-miniscript`.

Add a `sign` method to the `PartiallySignedTransaction`.
We have a PSBT example that includes a custom signing module, we can
remove that now and use the new PSBT signing API.
@tcharding tcharding dismissed stale reviews from sanket1729 and apoelstra via dd8730e October 19, 2022 19:08
PSBT automation moved this from Ready for merge to Review in progress Oct 19, 2022
@tcharding
Copy link
Member Author

Rebase only, no other changes.

Copy link
Contributor

@dunxen dunxen left a comment

Choose a reason for hiding this comment

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

ACK dd8730e

Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK dd8730e

@tcharding
Copy link
Member Author

Re-ack from @sanket1729 please.

Copy link
Member

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

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

reACK dd8730e

PSBT automation moved this from Review in progress to Ready for merge Oct 20, 2022
@sanket1729 sanket1729 merged commit fcf9bd0 into rust-bitcoin:master Oct 20, 2022
PSBT automation moved this from Ready for merge to Done Oct 20, 2022
@tcharding tcharding deleted the sign-psbt branch October 20, 2022 20:01
@tcharding
Copy link
Member Author

So much red and purple in my notifications this morning - nice work crew.

sanket1729 added a commit that referenced this pull request Oct 28, 2022
b8bd31d Promote rust-miniscript finalizer (DanGould)
16bf6f6 Test PSBT integration (DanGould)
6b6ef52 Add OP_0 alias for OP_PUSHBYTES_0 (DanGould)
72935a0 Move test_data/* tests/data (Tobin Harding)

Pull request description:

  resolves #892

  *  Initial patch adds OP_0 alias for OP_PUSHBYTES_0 as [approved here](#935 (comment))
  * Second patch is the bulk of this work. It tests BIP 174 PSBT integration defined at [The BIP's Test Vectors Section](https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki#test-vectors) using #957
  * Third patch points users to rust-miniscript for a more useful finalizer

ACKs for top commit:
  tcharding:
    ACK b8bd31d
  sanket1729:
    ACK b8bd31d. Thanks for sticking with this PR. This looks awesome after #957

Tree-SHA512: dc68e524d4349530b082baf5032460fa56593b0ef192125c0b7d7e00954e5593f386b7f1984fc00106b4b9eafbf29cc80ab368dbd26b710eba0962dbd89e0013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
PSBT
Done
Development

Successfully merging this pull request may close these issues.

None yet

7 participants