-
Notifications
You must be signed in to change notification settings - Fork 38.6k
parse external signer master fp as bytes in ExternalSigner::SignTransaction #25019
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
parse external signer master fp as bytes in ExternalSigner::SignTransaction #25019
Conversation
|
I find it better if HWI corrected this and always normalized to lower-case fingerprints. The other, maybe even better option is that HWI would assert that a fingerprint returned from an external signer script is always lowercase. Edit: cross-posted to bitcoin-core/HWI#599 (comment) |
|
Currently HWI provides all master fingerprints in lowercase (all devices use IMO when comparing byte sequences, we should normalize as they are per se not upper or lower case... |
|
I think normalising to lower case is fine, but doing it only for HWI is not the only potential signer. There's a document that describes how external signer scripts / programs should behave. This currently does not specify if the fingerprint Note that BIP32 doesn't specify how a fingerprint should be represented when used as a hex string. The examples it uses are uppercase and use the |
|
I think if external signer(ES) provides you with the uppercase master fp, changing it lowercase can break the communication with ES, as ES itself can implement no normalization and only expect uppercase.
there are only 2 places where master fp is being compared:
Potential solutions I see:
|
|
Case-ness shouldn't matter. What we should be doing is parsing the fingerprint string as bytes, not converting the bytes fingerprint to hex. |
|
@achow101 is right imo - I updated this PR to instead of playing with upper and lower case parsed master fp from external signer as bytes and comapred with bytes from PSBT... my c++ is non-existent so not sure If it is optimal |
|
That looks better at first glance. Can you squash these three commits? |
c79fd30 to
8f6049c
Compare
|
squashed and rebased on top of current master |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK
I think converting the bytes into an integer is not needed though, and you could simply compare them directly? E.g. with memcmp or something like
if (ParseHex(m_fingerprint) == std::vector<uint8_t>(std::begin(entry.second.fingerprint),
std::end(entry.second.fingerprint))) return true;
// EDIT
if (ParseHex(m_fingerprint) == MakeUCharSpan(entry.second.fingerprint)) return true;
is even shorter and should also work (at least it compiles for me).
73de23e to
e2a38b6
Compare
|
updated based on @theStack comments (and squashed and rebased on top of current master) |
e2a38b6 to
e7d7239
Compare
Thanks. Please make sure that you use spaces instead of tabs in your change, the linter is complaining right now: |
e7d7239 to
99671e5
Compare
|
tab character removed - linter happy |
src/external_signer.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, ParseHex(m_fingerprint) should be done once, outside this lambda.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very good point - thanks (fixed - only parse m_fingerprint once as it does not change)
… caring for lower/upper case in ExternalSigner::SignTransaction
99671e5 to
2a22f03
Compare
luke-jr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK
theStack
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code-review ACK 2a22f03
Sjors
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 2a22f03
|
ACK 2a22f03 |
… caring for lower/upper case in ExternalSigner::SignTransaction Github-Pull: bitcoin#25019 Rebased-From: 2a22f03
…rnalSigner::SignTransaction 2a22f03 parsing external signer master fingerprint string as bytes instead of caring for lower/upper case in ExternalSigner::SignTransaction (avirgovi) Pull request description: Some external signers scripts may provide master fingerprint in uppercase format. In that case core will fail with `Signer fingerprint 00000000 does not match any of the inputs` as it only works with lowercase format. Even if the fingerprints match, yet one is lowercase the other uppercase. ExternalSigner::SignTransaction is the only place where it is needed IMO, as changing it in other places may break the communication with the external signer (i.e. enumerating with lowercase may not find the device). ACKs for top commit: achow101: ACK 2a22f03 theStack: Code-review ACK 2a22f03 Sjors: utACK 2a22f03 Tree-SHA512: f3d84b83fb0b5e06c405eaf9bf20a2fa864bf4172fd4de113b80b9b9a525a76f2f8cf63031b480358b3a7666023a2aef131fb89ff50448c66df3ed541da10f99
Some external signers scripts may provide master fingerprint in uppercase format. In that case core will fail with
Signer fingerprint 00000000 does not match any of the inputsas it only works with lowercase format. Even if the fingerprints match, yet one is lowercase the other uppercase.ExternalSigner::SignTransaction is the only place where it is needed IMO, as changing it in other places may break the communication with the external signer (i.e. enumerating with lowercase may not find the device).