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

psbt: use DER encoded + sighash byte for PSBT_IN_PARTIAL_SIG items #5307

Merged
merged 1 commit into from
Jun 9, 2022

Conversation

jgriffiths
Copy link
Contributor

This fixes the incorrect signature encoding as reported in #5298.

I don't see that the old code could ever have worked: whether signing through wally or any other PSBT signer, the resulting signature in the witness would be of an incorrect form and thus should be rejected by core.

Its probably worth getting submission/validation of a tx produced from signing one of these PSBTs under test.

@cdecker
Copy link
Member

cdecker commented Jun 7, 2022

That is likely because we were using the PSBT format as an internal transport format only, and didn't use libwally primitives to construct the final transaction. This was discovered when we made the previously internal hsmd protocol public to be consumed by VLS.

Thank you very much @jgriffiths, and sorry for causing a false alarm for libwally.

@cdecker
Copy link
Member

cdecker commented Jun 7, 2022

ACK d8bde0a

@cdecker cdecker requested a review from rustyrussell June 7, 2022 17:07
@cdecker cdecker added this to the v0.12 milestone Jun 7, 2022
Copy link
Collaborator

@vincenzopalazzo vincenzopalazzo left a comment

Choose a reason for hiding this comment

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

ACK d8bde0a

Per BIP-0171, the signature map is of pubkey to "The signature as would
be pushed to the stack from a scriptSig or witness".

Fixes 5298

Changelog-Fixed: PSBT: Fix signature encoding to comply with BIP-0171.

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
@jgriffiths
Copy link
Contributor Author

I've squashed the test commit into the actual change for git-bisectability, no further changes.

@cdecker
Copy link
Member

cdecker commented Jun 8, 2022

Hurray, the bot actually did recognize that there were no content changes between the PR versions and reapplied the ACKs :-)

@@ -268,18 +268,20 @@ bool psbt_input_set_signature(struct wally_psbt *psbt, size_t in,
const struct bitcoin_signature *sig)
{
u8 pk_der[PUBKEY_CMPR_LEN];
u8 sig_der[73];
Copy link
Contributor

Choose a reason for hiding this comment

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

is this constant defined anywhere by any chance?

Copy link
Contributor Author

@jgriffiths jgriffiths Jun 8, 2022

Choose a reason for hiding this comment

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

Wally has EC_SIGNATURE_DER_MAX_LEN so EC_SIGNATURE_DER_MAX_LEN + 1 could be used (1 for the sighash byte).

That should be a separate commit if done IMO, also changing the other places below (I just followed the existing examples). Note that this would require wally be exposed in the interface of bitcoin/signature.h which it currently isn't. Perhaps a c-lightning specific define?

bitcoin/script.c:       u8 der[73];
bitcoin/script.c:       u8 der[73];
bitcoin/signature.c:size_t signature_to_der(u8 der[73], const struct bitcoin_signature *sig)
bitcoin/signature.c:    u8 der[73];
bitcoin/signature.h:size_t signature_to_der(u8 der[73], const struct bitcoin_signature *sig);

Copy link
Contributor

Choose a reason for hiding this comment

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

just a nit, doesn't block this PR

ACK

@cdecker cdecker merged commit 572942c into ElementsProject:master Jun 9, 2022
@jgriffiths jgriffiths deleted the psbt_partial_sig_fix branch June 9, 2022 20:52
@devrandom
Copy link
Contributor

confirmed compatible with rust-bitcoin 0.28.1

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.

4 participants