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

Potential Safety Issue On Script Execution Success Determination #285

Open
salmonberry7 opened this issue Oct 28, 2024 · 0 comments
Open

Comments

@salmonberry7
Copy link

In the function Script.evaluate on p116 and in line 134 in script.py at :
Chapter 6, script.py
would it not be better to have :
if decode_num(stack.pop()) == 0:
instead of :
if stack.pop() == b'':
since the functions decode_num and encode_num in op.py already encapsulate the mapping between byte vectors on the stack and signed integers as described in Bitcoin Wiki. decode_num already has the test if element == b'': return 0. Other representations of zero are possible besides the null length vector, eg 0x00 (1 zero byte), 0x00 0x00 (2 zero bytes), and 0x80 ('minus zero'). It is maybe best to handle all of these within decode_num to keep them all in the one place. If any of these other representations of zero ended up at the top of the stack on completion of the script then Script.evaluate would currently return True and then Tx.verify_input would return True, thus validating an input that maybe should not be considered valid. Not sure if there are any corner cases where this could arise, but maybe a good idea to guard against them anyway - defensive coding. At least it would be tidier to put it through decode_num.

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

No branches or pull requests

1 participant