Documented bug in sign-extension behavior of opcodes OP_AND, OP_OR, and OP_XOR #1868

pull maaku wants to merge 1 commits into bitcoin:master from maaku:and_or_xor_sign_extension changing 1 files +23 −1
  1. maaku commented at 11:46 PM on September 25, 2012: contributor

    Due to a bug in the implementation of MakeSameSize(), using OP_AND, OP_OR, or OP_XOR with signed values of unequal size will result in the sign-bit becoming part of the smaller integer, with nonsensical results. This patch documents the unexpected behavior and provides the basis of a solution should decision be made to fix the bug in the future.

  2. Documented bug in sign-extension behavior of opcodes OP_AND, OP_OR, and OP_XOR.
    Due to a bug in the implementation of MakeSameSize(), using OP_AND, OP_OR, or OP_XOR with signed values of unequal size will result in the sign-value becoming part of the smaller integer, with nonsensical results. This patch documents the unexpected behavior and provides the basis of a solution should decision be made to fix the bug in the future.
    95d7f00295
  3. laanwj commented at 7:37 AM on September 26, 2012: member

    Good catch

  4. BitcoinPullTester commented at 11:58 AM on September 26, 2012: none

    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/95d7f002957a7bb30a2d5d8b07fe8fe3c1f37ec0 for binaries and test log.

  5. gavinandresen commented at 2:36 PM on September 26, 2012: contributor

    I don't like keeping dead code in source files, so I think the right thing to do is to remove MakeSameSize and the code for all of the disabled opcodes from the big switch() statement.

    If we ever resurrect them git will have the history, and, I assume, we'll write thorough unit tests to make sure they actually work correctly.

    So: I'd be ok with pulling this, and then another commit that removed code related to all the disabled opcodes.

  6. jgarzik commented at 3:11 PM on September 26, 2012: contributor

    That's what I said on IRC: delete 'em. It is dead code that requires a hard fork to re-enable.

  7. laanwj commented at 4:59 PM on September 26, 2012: member

    Agree with Gavin, let's pull this as a warning to people if they'll ever resurrect this code, and then in a later pull remove all the code related to disabled opcodes. At the moment, they are only confusing.

  8. gmaxwell commented at 5:12 PM on September 26, 2012: contributor

    @laanwj sounds like a plan.

  9. maaku commented at 5:22 PM on September 26, 2012: contributor

    I will create a new pull-request that surgically removes the disabled opcodes (they will now be caught by the default: return false catch-all).

    EDIT: Sorry for the messy commit references surrounding this comment. Github refuses to forget about amended/removed commits :\

  10. laanwj referenced this in commit 035cb4781d on Sep 28, 2012
  11. laanwj merged this on Sep 28, 2012
  12. laanwj closed this on Sep 28, 2012

  13. xanatos commented at 6:05 AM on April 26, 2013: none

    Just a question... Isn't the proposed patch "wrong"? Negative numbers should be padded with 0xFF, not with 0. For example, in Little Endian, a 16 bit -1 is 0xFFFF, at 24 bits it's 0xFFFFFF, at 32 bits it's 0xFFFFFF. -2 at 16 bits is 0xFEFF, at 24 bits it's 0xFEFFFF...

  14. maaku commented at 4:48 PM on April 26, 2013: contributor

    Bitcoin uses its own big-endian, explicit-bit semantics for BigNums.

  15. KolbyML referenced this in commit fb94ca77d4 on Dec 5, 2020
  16. DrahtBot locked this on Sep 8, 2021

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:16 UTC

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