Separate signature hash types#702
Conversation
304e5ec to
75750a4
Compare
dr-orlovsky
left a comment
There was a problem hiding this comment.
Left some comments and questions
48f15e4 to
d6bd475
Compare
|
Ready for review again. |
src/util/schnorr.rs
Outdated
There was a problem hiding this comment.
This could be written as an ok_or_else after the split_last. That would get rid of the explicit pattern match.
There was a problem hiding this comment.
Also if this is kept, use return Err(...) instead of Err(...)?
src/util/schnorr.rs
Outdated
There was a problem hiding this comment.
Could early return here and get rid of the else block. Would reduce another indentation level of the code below.
src/util/ecdsa.rs
Outdated
There was a problem hiding this comment.
let (hash_ty, sig) = sl.split_last().ok_or(EcdsaSigError::InvalidEcdsaSig)?;
and get rid of indentation
src/util/schnorr.rs
Outdated
There was a problem hiding this comment.
I'm not convinced this helps much. Most people would probably blindly try ? and thus start implicitly relying on it.
There was a problem hiding this comment.
This is how it is done throughout the library. I never really thought if this was useful or not, but have been mechanically adding it whenever I from From error impl
d6bd475 to
72c3a56
Compare
dr-orlovsky
left a comment
There was a problem hiding this comment.
re-ACK with two small improvements since needs rebase anyway
72c3a56 to
ace924e
Compare
|
Rebased |
dr-orlovsky
left a comment
There was a problem hiding this comment.
ACK ace924e1f7095ea3d5f8d366e43dbc1dd862519b
I think all of my comments are just nits on coding style. One really non-stylish thing is returning more clear error from a schnorr witness signature parser, but again I would not postpone further taproot progress just because of error handling UX.
src/util/sighash.rs
Outdated
There was a problem hiding this comment.
Nit: probably we create it from a byte value, not u8. I.e. from_byte may be more "consensus-style"
ace924e to
681acd1
Compare
dr-orlovsky
left a comment
There was a problem hiding this comment.
utACK 681acd18a2f16eaca731da93e6f68fdeb28ea6fe
RCasatta
left a comment
There was a problem hiding this comment.
ACK 681acd18a2f16eaca731da93e6f68fdeb28ea6fe
left a nit, but it's so small I will merge anyway to avoid turnover time
|
can't merge needs rebase |
04c0bc6
04c0bc6 to
3e693cd
Compare
04c0bc6 to
f60b14e
Compare
|
Rebased again |
RCasatta
left a comment
There was a problem hiding this comment.
utACK f60b14e50f2afa849c9019580de8721658d5a99d
|
utACK f60b14e50f2afa849c9019580de8721658d5a99d Was unable to test commit-wise since rust stable panics on one of the commits due to internal error. Command that fails: Commit that fails: ed40f3d |
I can't reproduce, and is it also out of this PR commit's? |
f60b14e to
78df9f4
Compare
|
Rebased again after #721 |
78df9f4 to
5769744
Compare
|
ACK 5769744b74464be67f328e57b3f286a12703f6e6 |
Kixunil
left a comment
There was a problem hiding this comment.
Would've ACKed but I really don't like throwing away of error information. From my experience, it makes debugging harder.
If there's a rationale why throw it away I'd like to know.
src/util/ecdsa.rs
Outdated
There was a problem hiding this comment.
Why throw out the errors?
There was a problem hiding this comment.
The earlier versions of the PR did capture the underlying errors. I did this in order to
- Avoid all but one unreachable error states in
secp256k1::Error. In this scenario, I did check that only one variant of error was being returned in the corresponding secp functions. - It would have required to me have another return error type for empty signature. I don't know if the end-user really cares about this error type when the signature is empty or if the signature is malformed. I want to avoid creating unnecessary error enums that are not useful, but it makes matching with them downstream even harder.
I was recently convinced on rust discord by someone else that I should always capture because in case upstream secp changes error reporting, we might want to capture it. Changing it back to the way it was previously
5769744 to
dc9c201
Compare
|
@Kixunil captured the underlying error types. |
dc9c201 to
8361129
Compare
| let (hash_ty, sig) = sl.split_last() | ||
| .ok_or(EcdsaSigError::EmptySignature)?; | ||
| let hash_ty = EcdsaSigHashType::from_u32_standard(*hash_ty as u32) | ||
| .map_err(|_| EcdsaSigError::NonStandardSigHashType(*hash_ty))?; |
There was a problem hiding this comment.
May be nicer to match on NonStandardSigHashType (map_err(|NonStandardSigHashType| EcdsaSigError::NonStandardSigHashType(*hash_ty)) to protect against possible future refactors but not a big deal.
3eea63e Re-export SigHashType in lib.rs (sanket1729) Pull request description: Using the latest version of rust-bitcoin master on rust-miniscript errors on bitcoin::SigHashType not found. In the original PR, I only renamed the export to ECDSASigHashType, but original re-export should also be there in lib.rs to avoid breaking changes downstream. Fixup to #702 Before this PR, ``` | 89 | required: bitcoin::SigHashType, | ^^^^^^^^^^^ not found in `bitcoin ``` After this PR, ``` warning: use of deprecated type alias `bitcoin::SigHashType`: Please use [`EcdsaSigHashType`] instead --> src/psbt/mod.rs:89:28 | 89 | required: bitcoin::SigHashType, ``` ACKs for top commit: apoelstra: ACK 3eea63e RCasatta: ACK 3eea63e Tree-SHA512: 9cb8683835828e316ffa782c2a249559b4e534aa251b61667f3512b4e872fd88c726615c626ed9abf2061d31dc815ee77bb3d064962c93d0e0befd722fc2ceeb
Fixes #670 . Separates
SchnorrSigHashTypeandLegacySigHashType. Also adds the following new structs:This code is currently minimal to aid reviews. We can at a later point implement (Encodeable, psbt::Serialize, FromHex, ToHex) etc in follow-up PRs.