-
Notifications
You must be signed in to change notification settings - Fork 5.6k
BIP352: fix loop range issue in get_pubkey_from_input function #1806
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
base: master
Are you sure you want to change the base?
Conversation
Is it possible to add, previously failing and now passing, test vectors? I suppose they could go to this file https://github.com/bitcoin/bips/blob/master/bip-0352/send_and_receive_test_vectors.json |
Agree, and please also make separate commits for (1) test coverage, if any is missing, (2) the proposed fix with updated test coverage, (3) code refactoring, and (4) code style and grammar changes. |
@famouswizard do you plan to update here, based on the feedback? |
Let's close this PR if no author update by May 1. |
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.
Please add an explanation to your commit message describing what problem you discovered and how your code change mitigates.
@@ -32,54 +32,51 @@ def get_pubkey_from_input(vin: VinInfo) -> ECPubKey: | |||
# skip the first 3 op_codes and grab the 20 byte hash | |||
# from the scriptPubKey | |||
spk_hash = vin.prevout[3:3 + 20] | |||
for i in range(len(vin.scriptSig), 0, -1): | |||
if i - 33 >= 0: | |||
for i in range(len(vin.scriptSig) - 33, 0, -1): |
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.
I’m not sure what issue is being fixed here. Before this loop, we have already determined that we are looking at a P2PKH input. The P2PKH input script consists of a signature and the pubkey. The pubkey bytes are the last 33 bytes of the input script. However, P2PKH is malleable and could have additional junk bytes after the pubkey. This loop starts by reading the last 33 bytes and in each iteration goes forward one byte until it finds the pubkey.
If I understand this code and the change right, the changed code skips reading the last 33 bytes which means that it breaks support for P2PKH. I may misunderstand what’s going on, if that is so, please elaborate what problem was discovered that this fixes.
I fixed an issue in the
get_pubkey_from_input
function where the loop for extracting the public key from the scriptSig wasn't correctly handling the range of indices. The loop now starts from the correct index, ensuring that the last 33 bytes of thevin.scriptSig
are properly checked against thescriptPubKey
hash. This change ensures the function works as intended without going out of bounds or missing the correct data.Changes:
vin.scriptSig
.This should resolve the issue with incorrectly processed scriptSig data.