wallet: Do not turn OP_1NEGATE in scriptSig into 0x0181 in signing code (sipa) #17204

pull meshcollider wants to merge 2 commits into bitcoin:master from meshcollider:201910_1negate_rebase changing 3 files +24 −0
  1. meshcollider commented at 10:58 AM on October 21, 2019: contributor

    A rebase of #13084 which additionally modifies the test code (unaddressed in the original, assuming sipa is too busy to deal with this at the moment).

    Relatively simple bugfix so it'd be good to have merged soon.

    Turning OP_1NEGATE into 0x0181 results in a larger-than-necessary data push instead of just actually using the OP_1NEGATE opcode (0x4f). This fails the minimal push rule of BIP 62 and makes the result non-standard.

  2. meshcollider added the label Wallet on Oct 21, 2019
  3. laanwj commented at 11:49 AM on October 21, 2019: member

    code review ACK 9ddc07f68208fcf0217df11d72a7a61fd369c297

  4. Empact commented at 1:33 PM on October 21, 2019: member

    How about a test?

  5. laanwj commented at 11:12 AM on October 22, 2019: member

    How about a test?

    The test is updated. If you want a new, separate test for this, I think that doesn't need to be in this PR.

  6. Empact commented at 11:55 AM on October 22, 2019: member

    It’s good practice to include a regression test with any bugfix, both to confirm the new behavior and to ensure the bug isn’t reintroduced.

  7. MarcoFalke renamed this:
    Do not turn OP_1NEGATE in scriptSig into 0x0181 in signing code (sipa)
    wallet: Do not turn OP_1NEGATE in scriptSig into 0x0181 in signing code (sipa)
    on Oct 22, 2019
  8. laanwj commented at 9:54 AM on October 23, 2019: member

    The change in src/test/transaction_tests.cpp is supposed to do this…

  9. practicalswift commented at 2:02 PM on October 23, 2019: contributor

    Update OP to make it explicit what the consequences are of turning OP_1NEGATE in scriptSig into 0x0181 in signing code? :)

  10. Empact commented at 3:33 PM on October 23, 2019: member

    The change in src/test/transaction_tests.cpp is supposed to do this…

    You can confirm that it doesn't exercise the change by compiling without the sign.cpp changes, running the tests and seeing they don't fail:

    $ git co 201910_1negate_rebase
    # revert sign.cpp changes
    $ git diff
    diff --git a/src/script/sign.cpp b/src/script/sign.cpp
    index 7ff06e526..0ed92e8d5 100644
    --- a/src/script/sign.cpp
    +++ b/src/script/sign.cpp
    @@ -181,8 +181,6 @@ static CScript PushAll(const std::vector<valtype>& values)
                 result << OP_0;
             } else if (v.size() == 1 && v[0] >= 1 && v[0] <= 16) {
                 result << CScript::EncodeOP_N(v[0]);
    -        } else if (v.size() == 1 && v[0] == 0x81) {
    -            result << OP_1NEGATE;
             } else {
                 result << v;
             }
    $ make
    $ src/test/test_bitcoin
    Running 373 test cases...
    
    *** No errors detected
    
  11. laanwj commented at 10:06 AM on October 25, 2019: member

    You can confirm that it doesn't exercise the change by compiling without the sign.cpp changes, running the tests and seeing they don't fail:

    Ok, wasn't aware of that, thanks.

  12. laanwj added the label Bug on Nov 1, 2019
  13. luke-jr commented at 8:43 PM on November 9, 2019: member

    If this is rebased on top of e4382fbef56a0e04b0ed834e8b3a3a16f81db149, it is a clean merge to 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, and master ;)

  14. luke-jr commented at 8:45 PM on November 9, 2019: member
  15. laanwj added the label Waiting for author on Nov 10, 2019
  16. meshcollider commented at 8:47 AM on November 20, 2019: contributor

    Rebased as requested, I'll try and add a test for this but this is such a small and obviously correct change that it should just be merged as-is IMO

  17. luke-jr commented at 11:25 PM on December 24, 2019: member

    You rebased in the wrong direction...

    git rebase HEAD^ --onto e4382fbef56
    

    (or just git reset --hard c74d19fcae5)

  18. meshcollider removed the label Waiting for author on Apr 20, 2020
  19. meshcollider commented at 2:58 AM on April 20, 2020: contributor

    Fixed Luke, sorry 👍

  20. jonatack commented at 10:27 AM on July 3, 2020: member

    Wrote a regression test while reviewing this PR and it looks like the issue has been resolved. Proposed the test in #19436.

    EDIT: perhaps not resolved, see #19436 (comment).

  21. jonatack commented at 8:37 AM on July 12, 2020: member

    ACK 45af54fbdc83699fab0a41284a3e8ae6195b0a07

  22. Do not turn OP_1NEGATE in scriptSig into 0x0181 in signing code
    Co-authored-by: Samuel Dobson <dobsonsa68@gmail.com>
    e629d07199
  23. test: ensure OP_1NEGATE satisfies BIP62 minimal push rule
    with a regression test for PR 13084 and PR 17204.
    dca28634d7
  24. luke-jr approved
  25. luke-jr commented at 6:48 AM on July 16, 2020: member

    ACK dca28634d77

  26. jonatack approved
  27. jonatack commented at 7:05 AM on July 16, 2020: member

    ACK dca28634d779c775678cba402a85fe5bb9b3a5a9

  28. fjahr commented at 11:00 AM on July 21, 2020: member

    Code review ACK dca28634d779c775678cba402a85fe5bb9b3a5a9

    I spent some time trying to find out what the test was actually testing but gave up for now. It seems the raw transaction parser used to change the 0x4F in the redeem script to 0x0181 in the script and that was fixed some time ago. It's really hard to figure out because errors from script evaluation seem to have changed as well. I might go back to this but the change is good.

  29. fanquake referenced this in commit c0b1706964 on Aug 14, 2020
  30. laanwj merged this on Aug 14, 2020
  31. laanwj closed this on Aug 14, 2020

  32. meshcollider deleted the branch on Aug 14, 2020
  33. luke-jr referenced this in commit 534c9ef409 on Aug 15, 2020
  34. sidhujag referenced this in commit f8f417028c on Aug 16, 2020
  35. sidhujag referenced this in commit f593e66ad8 on Aug 16, 2020
  36. luke-jr referenced this in commit faeca437f6 on Aug 17, 2020
  37. DrahtBot locked this on Feb 15, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me