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 psbt watch-only/cold-storage example #940

Merged
merged 2 commits into from Jul 19, 2022

Conversation

tcharding
Copy link
Member

@tcharding tcharding commented Apr 5, 2022

Add an example PSBT workflow. The workflow we simulate is that of a setup using a watch-only online wallet (contains only public keys) and a cold-storage wallet (contains the private keys).

We create and update a PSBT using the watch-only wallet then pass the PSBT to the cold-storage wallet to sign.

Partially resolves #892 (more done in #935).

Note

This PR includes a sub-module in examples/psbt.rs that implements ECDSA signing. This will hopefully eventually be merged into the main crate by way of #957. We have three PRs that add examples/tests of PSBTs that need to do signing, in order to help us design a good AP in #957 I think it would be beneficial to complete and merge these three PRs.

  1. This PR (PSBT ECDSA example)
  2. PBST ECDSA integration test: Add psbt BIP174 test vectors tests #935
  3. PSBT taproot example: examples: Add taproot PSBT example workflow #999

Note to self, this will need a change to test.sh if #1079 merges.

@tcharding tcharding changed the title Add psbt example Add psbt watch-only/cold-storage example Apr 5, 2022
examples/psbt.rs Outdated Show resolved Hide resolved
examples/psbt.rs Outdated Show resolved Hide resolved
examples/psbt.rs Outdated Show resolved Hide resolved
examples/psbt.rs Outdated Show resolved Hide resolved
@tcharding
Copy link
Member Author

Thanks @DanGould, you the man! I used all your suggestions and everything works now, I was able to broadcast the transaction with bitcoind. I added a Co-authored-by tag!

@tcharding tcharding marked this pull request as ready for review April 6, 2022 03:23
apoelstra
apoelstra previously approved these changes Apr 18, 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 af148d1

Wow! Did not read the code super carefully but skimmed all of it. A very thorough example.

Can me merged before or after 0.28.0, it's completely independent of the release.

@tcharding
Copy link
Member Author

tcharding commented Apr 18, 2022

I'd like to hold off on merging this until the bdk sighash license/upstream stuff is resolved. #957 gets done.

I'd like to merge this before #957 so we can use this as a way to prove signing works as its coded, at least for ECDSA.

@tcharding
Copy link
Member Author

tcharding commented Apr 20, 2022

Converting this to draft until #957 gets sorted.

@tcharding tcharding marked this pull request as draft April 20, 2022 06:14
@tcharding tcharding force-pushed the psbt-bitcoind-example branch 4 times, most recently from d50d2d9 to b5d090d Compare May 25, 2022 05:28
@tcharding tcharding marked this pull request as ready for review June 2, 2022 01:07
@tcharding
Copy link
Member Author

tcharding commented Jun 2, 2022

@DanGould I decided to throw this up in a state that can be merged because the PR to add PSBT sign functionality (#957) is proving to be thorny and I do not know how long till it will be mergable. Sorry for all the back and forward on signing but if you like you could cut'n'paste the psbt_sign module out of this into #935 and then try to get it merged as well. I cannot think of a better way to share the signing code than duplication. I now think finishing #957 will be easier with this and #935 merged. What do you rekon?

@tcharding
Copy link
Member Author

Converting back to draft because I've made changes to this over in #957 after review and cannot be bothered maintaining two branches.

@tcharding tcharding marked this pull request as draft June 28, 2022 01:01
@tcharding
Copy link
Member Author

This PSBT example has been hanging around for months now. I've back and forthed, both mentally, and draft/undraft, a million times because of not knowing if its better to do #957 before or after this PR. Also, @DanGould has #935 open with similar confusion. Now @dunxen has #999 going to show taproot psbt signing.

Can we just merge these tests/examples and worry about cleaning them up to use #957 when/if that merges. My arguments are:

  • Its a PITA having these examples/tests in limbo
  • The other two devs are newish contributors and they did a fair bit of work on their PRs, it would be nice to recognize this and merge them instead of waiting on what is quite a curly PR (Add API to PSBT to enable signing inputs #957)
  • We would only be merging into tests/ and examples/ so this is not a risk to the library
  • With three devs looking at this, at least in the short term, I don't think there is an undue a maintenance burden

Cheers

@tcharding tcharding marked this pull request as ready for review June 30, 2022 00:58
@tcharding
Copy link
Member Author

Re-named the example file to examples/ecdsa-psbt.rs in line with #999's usage of taproot-psbt.rs.

apoelstra
apoelstra previously approved these changes Jun 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 a7f2d21

@apoelstra
Copy link
Member

Pretty cool! Yeah, let's just get this in. I could find some things to nit but it's not worth keeping this in limbo.

@tcharding
Copy link
Member Author

sick!

@tcharding
Copy link
Member Author

I could find some things to nit but it's not worth keeping this in limbo.

Please do nit if you think its worth it and if it will help the other psbt example/test PRs. Otherwise I can come back and improve all three after they merge.

@tcharding
Copy link
Member Author

Changes in force push:

  • rebased
  • Removed explicit scope required for Rust 1.29

apoelstra
apoelstra previously approved these changes Jul 17, 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 ee8d06d

tcharding and others added 2 commits July 19, 2022 10:59
Add an example PSBT workflow. The workflow we simulate is that of a
setup using a watch-only online wallet (contains only public keys) and a
cold-storage wallet (contains the private keys).

We create and update a PSBT using the watch-only wallet then pass the
PSBT to the cold-storage wallet to sign.

Co-authored-by: Dan Gould <d@ngould.dev>
We just added a PSBT example file, run it from CI for all test runs.
@tcharding
Copy link
Member Author

Changes in force push:

  • Rebased to pick up Sequence changes
  • Added a line to test.sh to run the example in all test runs (separate patch)

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 cd2369b

@DanGould
Copy link
Contributor

@sanket1729 this needs just one more approval

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 cd2369b. The example is clean, you can address the comments in followups.

A lot of the code would be cleaned up after #957 .

This PR is really big and already has one ACK. In an effort of moving things forward and considering that my comments are really nits, I am merging this and creating an issue for addressing the follow-ups so that we forget them.


let mut script_witness: Witness = Witness::new();
script_witness.push(&sigs[0].serialize());
script_witness.push(self.input_xpub.to_pub().serialize());
Copy link
Member

Choose a reason for hiding this comment

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

nit: You can push pk from the key in the partial_keys map here instead. It seems more natural to use that instead of deriving it again.

examples/ecdsa-psbt.rs Show resolved Hide resolved
/// The xpub derived from `INPUT_UTXO_DERIVATION_PATH`.
input_xpub: ExtendedPubKey,
/// The master extended pubkey fingerprint.
master_fingerprint: Fingerprint,
Copy link
Member

Choose a reason for hiding this comment

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

nit: I think we should save the derivation path for both account_0 and input_xpub instead of global constants.

@@ -62,6 +62,8 @@ do
cargo test --verbose --features="$feature"
done

cargo run --example ecdsa-psbt --features=bitcoinconsensus
Copy link
Member

Choose a reason for hiding this comment

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

Not related to this issue, but I just noted that other examples are not being when "DO_NO_STD" is not set

@sanket1729 sanket1729 merged commit d6d5415 into rust-bitcoin:master Jul 19, 2022
@tcharding tcharding deleted the psbt-bitcoind-example branch July 20, 2022 01:37
ChallengeDev210 pushed a commit to ChallengeDev210/rust-bitcoin that referenced this pull request Aug 1, 2022
… example

cd2369b Run ecdsa-psbt example in test script (Tobin C. Harding)
6967c0e Add psbt example (Tobin Harding)

Pull request description:

  Add an example PSBT workflow. The workflow we simulate is that of a setup using a watch-only online wallet (contains only public keys) and a cold-storage wallet (contains the private keys).

  We create and update a PSBT using the watch-only wallet then pass the PSBT to the cold-storage wallet to sign.

  Partially resolves #892 (more done in #935).

  ## Note

  This PR includes a sub-module in `examples/psbt.rs` that implements ECDSA signing. This will hopefully eventually be merged into the main crate by way of rust-bitcoin/rust-bitcoin#957.  We have three PRs that add examples/tests of PSBTs that need to do signing, in order to help us design a good AP in #957 I think it would be beneficial to complete and merge these three PRs.

  1. This PR (PSBT ECDSA example)
  2. PBST ECDSA integration test: rust-bitcoin/rust-bitcoin#935
  3. PSBT taproot example: rust-bitcoin/rust-bitcoin#999

  Note to self, this will need a change to `test.sh` if #1079 merges.

ACKs for top commit:
  apoelstra:
    ACK cd2369b
  sanket1729:
    ACK cd2369b. The example is clean, you can address the comments in followups.

Tree-SHA512: c4fb8ec631bf8bfc30534e8974b1f6c4bb7cc6def165a4ee2bb7aa73f5aa7fdc11d2000ca25792a4b534b2c5bf1592efe542ada14a9d702c7dfacbaa808f3aea
sanket1729 added a commit that referenced this pull request Oct 20, 2022
dd8730e Use new PSBT signing API in example (Tobin C. Harding)
d2367fb Add PSBT sign functionality (Tobin C. Harding)
b80e5ae Re-order import statements (Tobin C. Harding)

Pull request description:

  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.

ACKs for top commit:
  dunxen:
    ACK dd8730e
  apoelstra:
    ACK dd8730e
  sanket1729:
    reACK dd8730e

Tree-SHA512: 6345571e53cd3aa4b7ad962536da47ae03ab7c0b088107dc4104676bdb64fcf892e8fa60e0b716f3ef158d88d7058938bf267046721ccf74b2d1b092e9b9aaaa
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.

Write an example psbt workflow
4 participants