Fix usage of NegateSignatureS in script_tests #5784
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
NegateSignatureS is called with a signature which has not yet had the hashtype appended to it, yet the function assumed a hashtype was there and was incorrectly saving and then appending the last byte of its input (ie the last byte of the original S instead of a hashtype).
Only one pair of the test scripts was triggering this bug ("P2PK with high S"), which was actually causing the invalid version of the test to fail in the wrong place -- it was failing in the IsValidSignatureEncoding function rather than further down in IsLowDERSignature where the S value is checked. Fixing NegateSignatureS causes this test to change so that IsLowDERSignature is now being tested as I believe was intended.
Fixing that test resulted in there no longer being code coverage for the check in IsValidSignatureEncoding relating to extra bytes after the S, so the second commit here adds a pair of tests to exercise that check.