Fix CScriptID(const CScript& in) in empty script case #5541

pull petertodd wants to merge 1 commits into bitcoin:master from petertodd:fix-CScriptID-with-empty-scripts changing 1 files +1 −1
  1. petertodd commented at 8:30 AM on December 25, 2014: contributor

    Previously an empty script wouldn't be hashed, and CScriptID would be assigned the incorrect value of 0 instead. This bug can be seen in the RPC decodescript command:

    $ btc decodescript ""
    {
        "asm" : "",
        "type" : "nonstandard",
        "p2sh" : "31h1vYVSYuKP6AhS86fbRdMw9XHieotbST"
    }
    

    Correct output:

    $ btc decodescript ""
    {
        "asm" : "",
        "type" : "nonstandard",
        "p2sh" : "3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy"
    }
    

    This bug was introduced by recent refactoring work in commit 066e2a1403fe306787a2ce0c8571aa9de57386cf I did a grep to check and CScriptID does get used in the consensus-critical CScriptCompressor code, although fortunately not in a way that is affected by this bug.

  2. Fix CScriptID(const CScript& in) in empty script case
    Previously an empty script wouldn't be hashed, and CScriptID would be
    assigned the incorrect value of 0 instead. This bug can be seen in the
    RPC decodescript command:
    
        $ btc decodescript ""
        {
            "asm" : "",
            "type" : "nonstandard",
            "p2sh" : "31h1vYVSYuKP6AhS86fbRdMw9XHieotbST"
        }
    
    Correct output:
    
        $ btc decodescript ""
        {
            "asm" : "",
            "type" : "nonstandard",
            "p2sh" : "3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy"
        }
    d78f0dafd5
  3. gmaxwell added this to the milestone 0.10.0 on Dec 25, 2014
  4. sipa commented at 12:37 PM on December 25, 2014: member

    utACK

  5. theuni commented at 7:19 PM on December 26, 2014: member

    Thanks for catching this. utAck.

  6. laanwj merged this on Dec 27, 2014
  7. laanwj closed this on Dec 27, 2014

  8. laanwj referenced this in commit 3c9daa2f24 on Dec 27, 2014
  9. laanwj commented at 3:07 AM on December 27, 2014: member

    Also need a test to prevent this from happening again.

  10. laanwj referenced this in commit 06ca0651b6 on Dec 27, 2014
  11. dexX7 referenced this in commit c3aa36a45b on Dec 29, 2014
  12. reddink referenced this in commit b89c7a3c3b on May 27, 2020
  13. MarcoFalke locked this on Sep 8, 2021

Milestone
0.10.0


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-17 12:15 UTC

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