SigHashType: add a method to error on non-standard hashtypes#573
SigHashType: add a method to error on non-standard hashtypes#573apoelstra merged 4 commits intorust-bitcoin:masterfrom
Conversation
Super nit, but a hashtype is not specific to a transaction but a signature. Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
sanket1729
left a comment
There was a problem hiding this comment.
We should note that this being applicable only to pre-tapscript ECDSA signatures and not for Schnorr Sigs. This can also be addressed when we actually implement Taproot into rust-bitcoin.
Yes, as these rules actually become Consensus rules with BIP341. |
|
I think we may be mixing two things here. The sighash appears in two contexts when dealing with bitcoin transactions.
I think what we want is SighashType from u8? |
I believe so (see
I believe @apoelstra wanted to mimic Bitcoin-Core behaviour in 38b2cac |
Signed-off-by: Antoine Poinsot <darosior@protonmail.com> Co-Authored-by: sanket1729 <sanket1729@gmail.com>
2db2b49 to
196030b
Compare
|
Ok, i think i either responded or adressed all the review comments. Thanks everyone! Added another documentation commit after a nice deep dive with @sanket1729 about the rationale of masking with |
sanket1729
left a comment
There was a problem hiding this comment.
tACk 196030b445e18104b51ec51d2e6a07f04f6e323a. Left a minor nit about adding Hash
196030b to
fe66d3b
Compare
Right now, any sighash type could be parsed without error, which matches consensus rules. However most of them would be invalid by standardness, so it's a bit footgun-y (even more so for pre-signed transactions protocols for which standardness is critical). This adds `from_u32_standard()`, which takes care to error if we are passed an invalid-by-current-policy-rules SIGHASH type. Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
fe66d3b to
bf98d9f
Compare
…sensus Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
bc6f54f to
e36f3a3
Compare
| 0x81 => Ok(SigHashType::AllPlusAnyoneCanPay), | ||
| 0x82 => Ok(SigHashType::NonePlusAnyoneCanPay), | ||
| 0x83 => Ok(SigHashType::SinglePlusAnyoneCanPay), | ||
| _ => Err(NonStandardSigHashType) |
There was a problem hiding this comment.
E.g. in the PSBT API we'd include the input that was considered invalid in the error, but I don't think we are consistent about it. It's probably the right thing to do for new code though. I'm sorry I only see this now.
sanket1729
left a comment
There was a problem hiding this comment.
tACK e36f3a3 .
This was challeging than adding a simple function :) , but it was good learning experience.
Right now, any sighash type could be parsed without error, which matches
consensus rules. However most of them would be invalid by standardness,
so it's a bit footgun-y (even more so for pre-signed transactions
protocols for which standardness is critical).
This adds
from_u32_standard(), which takes care to error if we arepassed an invalid-by-current-policy-rules SIGHASH type.
(Happy to bikeshed the method name)