Skip to content

Added hash Preimages to psbt#465

Merged
apoelstra merged 4 commits intorust-bitcoin:masterfrom
sanket1729:psbt_updates
Sep 11, 2020
Merged

Added hash Preimages to psbt#465
apoelstra merged 4 commits intorust-bitcoin:masterfrom
sanket1729:psbt_updates

Conversation

@sanket1729
Copy link
Copy Markdown
Member

@sanket1729 sanket1729 commented Aug 31, 2020

Added hash preimages to psbt as per modified BIP 174. See bitcoin/bips#955. This will allow rust-miniscript a complete finalizer that can finalize hash preimages. (rust-bitcoin/rust-miniscript#119) .

Since the current version of the BIP does not have any tests for these, I plan to add some roundtrip tests for the changes.

Edit: Added tests

Added hash preimages to psbt as per updated bip174
@sanket1729
Copy link
Copy Markdown
Member Author

Build breaking because of #468. The last commit does not belong in this PR. If it requires tests/more reviews, it can be removed and raised as another PR.

*.iml

#Vscode project files
.vscode
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Heh, sure, ACK this, though I seem to recall arguments about it every time somebody tries to do this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Don't mind removing this commit although I don't see why this is an issue.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

there is a tab or something on this line that should be deleted

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same on this line, trailing whitespace

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

How does one figure out whether there is an empty line or whether it has spaces/tabs?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

More arguments for rustfmt :P . But yeah, I will take care of these things in future.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

On my system git diff highlights trailing whitespace in red. I don't know what setting causes it to do this.

Copy link
Copy Markdown
Collaborator

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

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

Proposing one improvement and few small changes to signature_hash, otherwise utACK

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I assume the line should read "for non-segwit and non-P2SH wrapped segwit outputs" b/c in the current reading it seems that all P2SH (non-wrapped) should fall into this first options as well

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

would

match (inp.non_witness_utxo, inp.witness_utxo) {
    (Some(non_witness_utxo), None) => { ... }
    (None, _) => { ... }
    (Some(_), Some(_)) => { /* error 2 */ }
    _ => { /* error 2 */ }
}

work better since it will cover currently uncovered situation if both non-witness and witness UTXO are present for the same output?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agreed, it would be good to catch this case and error out.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@apoelstra @dr-orlovsky , I tried to follow the specification line by line write https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki#simple-signer-algorithm. I think the specification does not error if both are present and this is the expected behaviour

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In fact, from the BIP. An input can have both PSBT_IN_NON_WITNESS_UTXO and PSBT_IN_WITNESS_UTXO.

Copy link
Copy Markdown
Collaborator

@dr-orlovsky dr-orlovsky Sep 10, 2020

Choose a reason for hiding this comment

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

Ok, but which of them has priority over the other? Here, if non-witness is present, witness is just simply ignored...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ok, at least this is according to the spec... However it's wired, will look into spec to see if there could be an issue with it...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

single space is missing before = if

Comment on lines 155 to 161
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This can be simplified once #387 will be merged - just another reason to have that PR, @apoelstra

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Merged now :)

@dr-orlovsky
Copy link
Copy Markdown
Collaborator

Follow-up PR: #471

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

trailing whitespace here

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This comment should be changed to indicate that it looks at the PSBT data to determine the appropriate sighash mode as well as whether to sign using segwit or legacy. As written it sounds like its primary job is to decide between segwit/non-segwit which isn't true.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can use .to_bytes() instead of .clone().into_bytes()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same down here, use .to_bytes

Copy link
Copy Markdown
Member Author

@sanket1729 sanket1729 Sep 10, 2020

Choose a reason for hiding this comment

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

Yeah, clone().into_bytes() looks silly. Idk why I did this..

@sanket1729
Copy link
Copy Markdown
Member Author

Updated the PR.

dr-orlovsky
dr-orlovsky previously approved these changes Sep 10, 2020
@apoelstra apoelstra added the minor API Change This PR should get a minor version bump label Sep 11, 2020
@apoelstra apoelstra merged commit 3f33bd7 into rust-bitcoin:master Sep 11, 2020
@apoelstra
Copy link
Copy Markdown
Member

Sorry, I merged this by mistake. @sanket1729 can you open a new PR?

@sanket1729
Copy link
Copy Markdown
Member Author

Sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

minor API Change This PR should get a minor version bump

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants