CBlock.GetSigOpCount counts vtx[0].vin[0] #596

issue dmgores opened this issue on October 29, 2011
  1. dmgores commented at 6:29 PM on October 29, 2011: none

    CBlock.GetSigOpCount counts vtx[0].vin[0]scriptSig's OpCount. It shouldn't, because the value in vtx[0].vin[0].scriptSig is a random string between 2 and 100 bytes.

  2. gavinandresen commented at 6:36 PM on October 29, 2011: contributor

    It isn't a random string, the scriptSig is a CScript. Standard txIns have only data-pushing opcodes, which count as zero SigOps, but theoretically you could have a scriptSig that included an OP_CHECKSIG.

  3. dmgores commented at 6:39 PM on October 29, 2011: none

    AFAIK it is a random string... see IncrementExtraNonce in main.cpp. We are talking about the Coin Base transaction, and the Coin Base's CTxIn.

  4. gavinandresen commented at 6:48 PM on October 29, 2011: contributor

    Got it, sorry for being dense. You're right, the coinbase scriptSig shouldn't be checked for SigOps.

  5. dmgores commented at 6:51 PM on October 29, 2011: none

    Cheers. :)

  6. luke-jr commented at 5:39 PM on November 21, 2011: member

    Won't changing this make it easy to fork the block chain?

  7. dmgores commented at 12:55 PM on November 22, 2011: none

    luke-jr: Doing an OpCount on random bytes doesn't make any sense.

  8. gavinandresen commented at 2:13 PM on November 22, 2011: contributor

    dmgores: vtx[0].vin[0].scriptSig is not random bytes-- it can be random bytes encoded as a CScript, but it must deserialize as a CScript for the transaction/block to be valid: pblock->vtx[0].vin[0].scriptSig = CScript() << pblock->nTime << CBigNum(nExtraNonce);

    ... is the normal way to create it, and CScript::operator<<() Does The Right Thing (create a script that, if it was ever executed, would do two PUSHDATA operations to put the nTime and nExtraNonce on the stack).

    luke-jr is correct, if we stop counting OP_CHECKSIG/OP_CHECKMULTISIG operations in vtx[0].vin[0] then somebody could try to split the block chain by sending a transaction that is valid under the new code but invalid under the old.

  9. sipa commented at 4:29 PM on November 22, 2011: member

    I don't think the coinbase is ever deserialized.

    EDIT: nevermind - the issue is obvious that it is, when checking the opcodes.

  10. dmgores commented at 11:13 PM on November 22, 2011: none

    I'd argue that forever counting operations on data that is only meant to be random bytes is a waste of CPU time... but if you do not want to at some time break old clients from the chain due to this somewhat minor optimization, I guess I'm ok with that.

  11. luke-jr commented at 11:18 PM on November 22, 2011: member

    At some time. When that happens, I agree this should be fixed. Along with a million other minor bugs.

  12. sipa commented at 6:32 PM on February 19, 2012: member

    How do we deal with this, in light of the proposed adding of nHeight to the coinbase?

  13. luke-jr commented at 6:57 PM on February 19, 2012: member

    I don't see how that's relevant to this...

  14. sipa commented at 7:10 PM on February 19, 2012: member

    Since sigops in the coinbase are counted, adding non-script-serialized data in front of coinbase may cause an invalid deserialization of what follows, causing sigops to be counted where there aren't any. (yes, I know there aren't ever any real sigops in a coinbase, but as most coinbases are currently constructed through script serialization, the invalid interpretation won't occur).

  15. luke-jr commented at 10:14 PM on February 19, 2012: member

    The proposed height addition is script-serialized.

  16. sipa commented at 11:33 PM on February 19, 2012: member

    My mistake, i believed it was different.

  17. laanwj commented at 7:21 AM on May 13, 2014: member

    This is a three-year old issue now. Does this still need to be solved?

  18. sipa commented at 8:08 PM on May 14, 2014: member

    It requires a hard fork to solve it. And there's no reason why it is a problem (rather than inconvenient), as it's easy enough as a miner to never create a sigop in a coinbase.

  19. laanwj commented at 10:29 AM on September 25, 2014: member

    Closing as it is not actually a problem.

  20. laanwj closed this on Sep 25, 2014

  21. nomnombtc referenced this in commit c99fee4c2b on May 18, 2017
  22. dexX7 referenced this in commit 23bfab287a on May 29, 2018
  23. fjahr referenced this in commit 36698dcfee on Jul 24, 2019
  24. elichai referenced this in commit 461acf5c6c on Aug 22, 2019
  25. sipa referenced this in commit 6b9cd1520b on Sep 24, 2019
  26. kallewoof referenced this in commit c866f52e2a on Oct 4, 2019
  27. sipa referenced this in commit 544c1f35e7 on Nov 6, 2019
  28. sipa referenced this in commit d5cd9db7a3 on Nov 19, 2019
  29. sipa referenced this in commit de659898b6 on Jan 21, 2020
  30. sipa referenced this in commit 36362dfb90 on Jan 23, 2020
  31. jnewbery referenced this in commit 85e7d06351 on Mar 17, 2020
  32. sipa referenced this in commit 4977ac14d3 on Mar 18, 2020
  33. sipa referenced this in commit 5bf7fb5baa on Mar 18, 2020
  34. sipa referenced this in commit fb2a05e468 on Mar 19, 2020
  35. sipa referenced this in commit 497fad6f09 on Mar 21, 2020
  36. sipa referenced this in commit eae016f117 on Mar 22, 2020
  37. sipa referenced this in commit 4e37a7c2cb on Mar 27, 2020
  38. jnewbery referenced this in commit 9696dea839 on Apr 16, 2020
  39. jnewbery referenced this in commit a541fd0e87 on Apr 19, 2020
  40. sipa referenced this in commit c308759ea5 on Apr 19, 2020
  41. sipa referenced this in commit 4eaec32f1c on May 2, 2020
  42. sipa referenced this in commit ef7117193c on May 22, 2020
  43. sipa referenced this in commit 67f232b5d8 on Jun 9, 2020
  44. stackman27 referenced this in commit 78cde6f8c7 on Jun 26, 2020
  45. KolbyML referenced this in commit bc86927231 on Sep 4, 2020
  46. 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-22 09:16 UTC

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