show scriptSig signature hash types in transaction decodes. fixes #3166 #5264

pull mruddy wants to merge 1 commits into bitcoin:master from mruddy:iss3166 changing 12 files +206 −49
  1. mruddy commented at 1:56 pm on November 12, 2014: contributor

    show scriptSig signature hash types. fixes #3166

    Please give this a look and let me know if you’d like it changed or if I mis-understood the issue request.

    The fix basically appends the scriptSig signature hash types, within parentheses, onto the end of the signature(s) in the various “asm” json outputs. That’s just the first formatting idea that came to my mind.

    Added some tests for this too.

  2. petertodd commented at 2:53 pm on November 12, 2014: contributor

    NACK

    This will definitely break things, and I don’t see a need given how easy the SIGHASH flags are to remember. All the standard ones can be interpreted by thinking in terms of upper and lower nibbles:

    Upper nibble == 0:

    001 - ALL
    102 - NONE
    203 - SINGLE
    

    Upper nibble == 8:

    081 - ANYONECANPAY | ALL
    182 - ANYONECANPAY | NONE
    283 - ANYONECANPAY | SINGLE
    

    That’s it.

  3. laanwj commented at 3:36 pm on November 12, 2014: member

    @petertodd That’s not really fair. Why was this an open issue, if this is not desirable?

    Where is the risk of breakage? It doesn’t affect consensus code. Do people rely on the exact format of the dumped script format?

  4. laanwj added the label RPC on Nov 12, 2014
  5. petertodd commented at 3:45 pm on November 12, 2014: contributor

    @laanwj They sure do! Granted, maybe we don’t want that, in which case we should delibrately break it. (make a note in the release notes please)

    Why was this an open issue, if this is not desirable?

    Well, I’m telling people why I think it’s not desirable. If I’m outnumbered on this, then I’ll at least ask if we could drop the ‘SIGHASH_’ prefix on this; having the full string is kinda long if it’s not meant to be parsed by anyone other than humans.

  6. in src/script/script.cpp: in 1f028d64b0 outdated
    26+        ;
    27     if (vch.size() <= 4)
    28         return strprintf("%d", CScriptNum(vch, false).getint());
    29     else
    30-        return HexStr(vch);
    31+        return HexStr(vch) + (CheckSignatureEncoding(vch, SCRIPT_VERIFY_STRICTENC) ? ("(" + mapSigHashTypes[vch.back()] + ")") : "");
    


    laanwj commented at 4:18 pm on November 12, 2014:
    Any special reason to use SCRIPT_VERIFY_STRICTENC instead of SCRIPT_VERIFY_DERSIG here?

    mruddy commented at 4:58 pm on November 12, 2014:
    the reason why i went with SCRIPT_VERIFY_STRICTENC was because in CheckSignatureEncoding, SCRIPT_VERIFY_STRICTENC will get us some checking through IsDefinedHashtypeSignature as well in order to make sure that the hash type is one of the defined types. if it’s not a defined hash type, then no decode gets appended to the hex encoding of the signature.
  7. laanwj commented at 4:19 pm on November 12, 2014: member

    @petertodd Yes, let’s see what the others think here. I generally like it when people solve an actual open issue :)

    Agree on dropping the SIGHASH_ prefix and adding mention to doc/release-notes.md.

  8. mruddy commented at 5:06 pm on November 12, 2014: contributor

    @petertodd @laanwj thanks for the feedback.

    I have removed the “SIGHASH_” from the text due to your feedback that it was too verbose. I was back and forth on that before I pushed it up, so I’m happy for your opinions.

    I can see @petertodd’s concern about this being a breaking change for people scripted against it. It’s something to weigh. I don’t know that adding more flags is the answer. From working on another pull request, my understanding is that the JSON is equivalent to “verbose”.

    FWIW, I kind of like the extra decoding output myself because it’s one less thing I have to think about. It’s a simple decode like @petertodd said, but having it just there in plain sight means I don’t have to remember, or go look it up.

    I will add some release notes comments in doc/release-notes.md in a little bit after waiting to hear what other feedback is.

  9. mruddy commented at 6:02 pm on November 12, 2014: contributor
    Added some release notes.
  10. petertodd commented at 6:06 pm on November 12, 2014: contributor
    @mruddy Mind squashing those commits?
  11. mruddy force-pushed on Nov 12, 2014
  12. mruddy commented at 6:23 pm on November 12, 2014: contributor
    sure thing, done
  13. sipa commented at 7:16 pm on November 12, 2014: member
    I don’t think we should be adding this to the existing ‘asm’ output, but perhaps an alternate decoding that goes into lower level detail.
  14. mruddy commented at 10:09 pm on November 12, 2014: contributor
    ok, thanks. if nobody pops up and says that they want this within a day or so, i’ll go ahead and close this. it probably fits better somewhere else.
  15. laanwj commented at 8:15 am on November 13, 2014: member
    @sipa What if the ‘asm’ format grew a way to specify comments?
  16. laanwj commented at 8:50 am on November 13, 2014: member
    @gmaxwell can you comment here? You created #3166, so maybe you can illuminate how it should work
  17. gmaxwell commented at 9:24 pm on November 13, 2014: contributor

    Hm. I don’t have a strong opinion about how it would work. I would have normally assumed some annotation on the asm output, or an additional lower level asm view.

    My goal was mostly that it would be clearly indicated in some manner stronger than squnting at bytes. In particular, squinting fails when you only barely know there is something you need to squint at. An expliact flag list would be much more obvious and discoverable.

    WRT compatiblity of the ASM output, we’ve certantly never promised to hold that encoding constant… it’s fine if things are reading it, but they’ll need to be revised if it changes.

  18. mruddy commented at 1:12 pm on November 18, 2014: contributor
    Closing because there doesn’t seem to be much demand for this fix with the possibility that it breaks things scripted against the “asm” output value.
  19. mruddy closed this on Nov 18, 2014

  20. petertodd commented at 6:27 pm on November 18, 2014: contributor

    @mruddy Actually, I was just asking around, and it looks like people are getting the message and not depending on the asm output format as much as before. As an example Counterparty switched to using python-bitcoinlib for that on my advice.

    Maybe we should reopen this for v0.11 and simultaneously drop the ‘OP_’ prefix from the opcode names in the asm output? That’d likely break the remaining stuff pretty thoroughly in a clear way.

  21. mruddy commented at 4:01 pm on November 19, 2014: contributor
    @petertodd sure, re-opened. I have not gone through and made the “OP_” prefix changes yet. I figure that I’ll have to do a bunch of reference checking to see what all I’m impacting, and then update or make some unit tests when I do that. So, more changes to come for that.
  22. mruddy reopened this on Nov 19, 2014

  23. petertodd commented at 7:38 pm on November 20, 2014: contributor

    @mruddy Great, thanks!

    FWIW a “OP_” prefix dropping change should definitely be in a separate commit so it can be debated separately. Also, if changing stuff like that doesn’t break any tests, keep in mind it’s a sign that maybe depending on the exact format of the asm output is a bad idea. :)

    (yeah, the more I think about this, the more I think my original objection was wrong…)

  24. mruddy force-pushed on Nov 28, 2014
  25. mruddy force-pushed on Nov 28, 2014
  26. mruddy force-pushed on Nov 28, 2014
  27. mruddy commented at 10:36 pm on November 28, 2014: contributor
    @petertodd sorry for my delayed response… i just made #5392 for the “OP_” prefix changes. also, i rebased this request’s commit so that it’ll merge into the upstream once again.
  28. mruddy commented at 11:39 am on December 11, 2014: contributor
    Eh, not important enough to keep open and keep re-basing the commit.
  29. mruddy closed this on Dec 11, 2014

  30. laanwj commented at 11:52 am on December 11, 2014: member
    I still think this makes sense, but after 0.10 obviously. If this is closed unfixed with “don’t bother” then so should #3166.
  31. laanwj reopened this on Dec 11, 2014

  32. in src/script/script.cpp: in 628bbfcd94 outdated
    26+        ;
    27     if (vch.size() <= 4)
    28         return strprintf("%d", CScriptNum(vch, false).getint());
    29     else
    30-        return HexStr(vch);
    31+        return HexStr(vch) + (CheckSignatureEncoding(vch, SCRIPT_VERIFY_STRICTENC, NULL) ? ("(" + mapSigHashTypes[vch.back()] + ")") : "");
    


    laanwj commented at 5:27 pm on December 11, 2014:

    Indexing a std::map with [x] adds an entry with the default value for the type (in this case, an empty string), if the key doesn’t exist in the map. This is not thread-safe, and makes it possible to consume some memory by providing unknown sigHashTypes.

    • please make mapSigHashTypes const
    • use .find(x) instead of [x] to find the value

    mruddy commented at 1:31 pm on December 12, 2014:
    Thanks for the code review. Guarding that lookup with CheckSignatureEncoding I believe prevents that case, but you’re right, I did not realize or intend for the [] operator to act that way. So, it’ll be safer to make the change that you propose in-case someone changes CheckSignatureEncoding to act differently in the future. I’ll get that done today and re-squash the commit.
  33. sipa commented at 2:03 pm on December 12, 2014: member
    I really don’t like a script show function to make assumptions about the data inside it. It feels like a layer violation.
  34. laanwj commented at 2:16 pm on December 12, 2014: member
    @sipa you could argue that, but in practice that’s what disassemblers do, given incomplete semantic information they have to make guesses. As long as the information is only shown in what is an informative comment for the user, I don’t think it hurts.
  35. mruddy force-pushed on Dec 12, 2014
  36. mruddy commented at 4:20 pm on December 12, 2014: contributor
    @laanwj ready for review. i added a couple more test cases, and re-squashed the commit after re-basing to the latest upstream.
  37. mruddy force-pushed on Dec 13, 2014
  38. mruddy commented at 1:12 pm on December 13, 2014: contributor
    While doing more testing, I found that I was able to make some OP_RETURN data look like a signature and cause an erroneous decode. I added some handling for that and did a little re-factoring at the same time. I also changed the parentheses to square brackets for consistency with an existing error case that would output square brackets.
  39. mruddy force-pushed on Dec 20, 2014
  40. mruddy force-pushed on Dec 20, 2014
  41. mruddy commented at 0:22 am on December 21, 2014: contributor
    Tightened up a couple more cases and added unit tests.
  42. in src/script/script.cpp: in 8ec43dce4e outdated
    3@@ -4,20 +4,9 @@
    4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
    5 
    6 #include "script.h"
    7-
    


    Diapolo commented at 1:26 am on December 21, 2014:
    Pleaso don’t remove that line, it is here to separate the own header (script.h) from other core headers.
  43. in src/script/script.cpp: in 8ec43dce4e outdated
    271+    (int(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY), std::string("SINGLE|ANYONECANPAY"))
    272+    ;
    273+
    274+std::string CScript::ValueString(const std::vector<unsigned char>& vch) const
    275+{
    276+    if (vch.size() <= 4)
    


    Diapolo commented at 1:27 am on December 21, 2014:
    Just asking, but isn’t this strictly a signed/unsigned comparison as .size() returns a size_t?
  44. in src/script/script.h: in 8ec43dce4e outdated
     5@@ -6,9 +6,13 @@
     6 #ifndef BITCOIN_SCRIPT_SCRIPT_H
     7 #define BITCOIN_SCRIPT_SCRIPT_H
     8 
     9+#include "script/interpreter.h"
    10+
    11 #include <assert.h>
    12+#include <boost/assign/list_of.hpp>
    


    Diapolo commented at 1:28 am on December 21, 2014:
    Nit: Can you place this after a newline below the standard C/C++ headers?
  45. mruddy force-pushed on Dec 21, 2014
  46. mruddy commented at 11:40 am on December 21, 2014: contributor
    @Diapolo thanks for the review. I’ve addressed your three comments in the latest updated commit.
  47. laanwj commented at 12:33 pm on March 26, 2015: member
    Needs rebase.
  48. in src/script/interpreter.cpp: in afd920e8be outdated
    15@@ -16,8 +16,6 @@
    16 
    17 using namespace std;
    18 
    19-typedef vector<unsigned char> valtype;
    


    laanwj commented at 12:37 pm on March 26, 2015:

    I don’t like exposing valtype externally, the type name is too general. Would prefer to change the function signature to just

    0bool CheckSignatureEncoding(const vector<unsigned char> &vchSig, unsigned int flags, ScriptError* serror) {
    
  49. mruddy force-pushed on Jul 2, 2015
  50. mruddy commented at 2:17 pm on July 2, 2015: contributor
    Rebased, incorporated latest feedback about the function signature, and decided to actually replace the sighash byte on signatures when the decode occurs instead of just appending the decode after the sighash byte.
  51. in src/script/script.cpp: in 4a67b1fcd0 outdated
    239@@ -238,11 +240,11 @@ bool CScript::IsPushOnly() const
    240     return true;
    241 }
    242 
    243-std::string CScript::ToString() const
    


    jtimon commented at 1:22 pm on July 4, 2015:
    why remove std:: ?

    mruddy commented at 5:02 pm on July 4, 2015:
    Just for consistency within the file. That method was the only one using the prefix in that file because of the “using namespace std” up on line 12. That’s all I was thinking when I did that.

    jtimon commented at 5:23 pm on July 4, 2015:
    We’re doing the opposite in other places. That doesn’t mean we should do it here. If you were touching the lines anyway I wouldn’t have said anything, but increasing the diff only for consistency doesn’t seem very interesting in my opinion. Anyway, feel free to ignore, just a small nit.

    mruddy commented at 5:31 pm on July 4, 2015:
    I agree with you, I’m going to put the prefixes back to reduce the diff in the next commit. Thanks for the info and for reviewing these changes.
  52. in src/script/script.h: in 4a67b1fcd0 outdated
    16 #include <stdint.h>
    17 #include <string.h>
    18 #include <string>
    19 #include <vector>
    20 
    21+#include <boost/assign/list_of.hpp>
    


    jtimon commented at 1:25 pm on July 4, 2015:
    Is this actually used in the .h ? If not, why not move it to the cpp or wherever it is used?

    mruddy commented at 5:12 pm on July 4, 2015:
    You might be right. I’ll double check. I might have needed it at one point and then moved things around. If it’s only needed in the cpp, I’ll move it.
  53. mruddy force-pushed on Jul 4, 2015
  54. mruddy commented at 6:04 pm on July 4, 2015: contributor
    @jtimon your two feedback items are incorporated into this latest commit, thanks!
  55. in src/script/script.cpp: in b6c6351069 outdated
    4@@ -5,18 +5,11 @@
    5 
    6 #include "script.h"
    7 
    8+#include "script/interpreter.h"
    


    jtimon commented at 11:39 pm on July 4, 2015:
    Oh, I hadn’t noticed the circular dependence…maybe an additional moveonly commit would solve that? mhmm, moving CheckSignatureEncoding and the flags from interpreter to script would be an option. Maybe move the flags to consensus/consensus instead? Another option is not having anything depending on the flags in script/script: CScript methods can be turned into functions taking a CScript as parameter. Or maybe we can just let the circular dependency be for now. Mhmm, I would like to know what other people think about this…I still don’t even know what option I like more.

    laanwj commented at 5:03 pm on July 20, 2015:
    Yes, script should probably not depend on the interpreter. I think we should move the disassembly logic out of the core/consensus data structure to separate utility functions. E.g. also IsPayToPublicKeyHash() doesn’t belong in CScript itself, it belongs at a higher level.

    jtimon commented at 5:51 pm on July 21, 2015:

    Would it be enough to move the opcode constants from script/interpreter to script/script in this PR to avoid this new include? I haven’t tried to compile that but I think that should be enough.

    About IsPayToPublicKeyHash, do you mean ValueString shouldn’t be a method of CScript ? Otherwise, since CScript::ValueString uses IsPayToPublicKeyHash, it has to be in the same level or below, but not above. If I have to suggest another place, I think I would go with script/standard, where other “static analysis” things are.

  56. jgarzik commented at 6:29 pm on July 23, 2015: contributor

    Leaning towards closing (with the associated comment/act on the related issue). Generally agree w/ the comment that this seems like a layering violation.

    The intent is understandable, but it seems like the script show function is not the right place.

  57. mruddy commented at 6:49 pm on July 23, 2015: contributor
    Yes, it should probably be closed. The more I worked on these changes, the less I liked them. I suppose I’ll wait a day and close it unless someone objects.
  58. jtimon commented at 2:03 am on July 24, 2015: contributor
    I agree the intent is good, and it can be done, just in script/standard rather than script/script. If closing this PR and reopening another one that does the same in another file is clearer, let’s do that.
  59. jgarzik commented at 5:51 am on July 24, 2015: contributor

    TxToUniv() dumps both script hex and script asm.

    I wonder if an optional argument to script.ToString() would suffice?

    Printing out the flags somewhere is certainly useful. bitcoin-tx utility and RPC both call TxToUnix() when dumping the script verbosely.

  60. mruddy commented at 7:10 pm on July 24, 2015: contributor

    I don’t see how an optional argument to CScript::ToString would solve the layering concern.

    That is caused by the script object needing to know if a piece of itself is a signature with a valid hash type. Right now, that logic is in the interpreter.

    I spent some time looking at the layering.

    I think IsValidSignatureEncoding could be moved over to script/bitcoinconsensus.cpp since it is entirely consensus-critical since BIP66.

    Since the sig hash type is not part of consensus, only part of determining if a sig is standard, I think move IsDefinedHashtypeSignature and the sig hash types over to script/standard.cpp and .h respectively.

    IsLowDERSignature is effectively dead code.

    Then, CheckSignatureEncoding could also go to script/standard.cpp since it’s not consensus and does not seem like it could only ever be used by the interpreter.

    I think at that point the layering concern is covered.

    Next, what lead to the klutziness in my code, that I wound up not really liking, was the need to answer the question of if the current script was a scriptSig. A lot of what I did to ValueString was to avoid mis-interpreting non-scriptSig data as a signature.

    It seems like a flag could be set on the script object, or more object oriented, just use a SignatureScript type object when these objects are created (and PubKeyScript objects in other cases). Then this decode ticket would be an override to SignatureScript::ToString.

    But, refactoring all that would obscure this change and is a lot of work for this seemingly low-value sighash decode. It’d turn into a train of refactoring tickets followed by the last ticket to actually do the simple decode. There’s also probably a reason why all that refactoring would be misguided or error-prone that I don’t foresee yet.

    All my hacking to avoid refactoring is what makes me think this should just be closed.

    Also, TxToUniv is only used by bitcoin-tx, CScript::ToString is the common dependency of RPC and bitcoin-tx. The RPC dependencies go through, TxToJSON (decoderawtransaction and getrawtransaction) and ScriptPubKeyToJSON (decodescript). That reason, and thinking that a script should know how to show/display/decode itself, is why I targeted CScript::ToString as the place to make these changes.

  61. jtimon commented at 8:44 pm on July 24, 2015: contributor

    I think IsValidSignatureEncoding could be moved over to script/bitcoinconsensus.cpp since it is entirely consensus-critical since BIP66.

    It is in script/interpreter, so it’s already part of libconsensus, see: https://github.com/bitcoin/bitcoin/blob/master/src/Makefile.am#L365

    Since the sig hash type is not part of consensus… Then, CheckSignatureEncoding could also go to script/standard.cpp since it’s not consensus and does not seem like it could only ever be used by the interpreter.

    The sighash types and CheckSignatureEncoding are definitely part of consensus (and are used by the interpreter), please, just leave them there. The only thing you need to move is the new code for converting to string to script/standard and I think all layering concerns are gone.

  62. mruddy commented at 11:50 am on July 25, 2015: contributor

    It is in script/interpreter, so it’s already part of libconsensus, see: https://github.com/bitcoin/bitcoin/blob/master/src/Makefile.am#L365

    That’s true. I was just thinking that determining whether a signature is validly encoded is generic enough that it could be useful without including the interpreter. Personal preference, I guess.

    The sighash types and CheckSignatureEncoding are definitely part of consensus (and are used by the interpreter), please, just leave them there.

    I was assuming that to begin with, but IsDefinedHashtypeSignature is only called when the flags include SCRIPT_VERIFY_STRICTENC. The comment for SCRIPT_VERIFY_STRICTENC even states, “not used or intended as a consensus rule”. The best I found was that scripts with a bad sighash type would fail to eval (and thus be non-standard), but that if they got into valid blocks we’d still have to accept those blocks. I suppose I could try it and see, but that’s what made me say that the sig hash type is not actually part of consensus. Maybe we’re using the word consensus in two different ways here.

    The only thing you need to move is the new code for converting to string to script/standard and I think all layering concerns are gone.

    Oh, you mean move ValueString and mapSigHashTypes over to script/standard and add the CScript as an argument to ValueString? Yes, that may make sense. And, if we move the sighash stuff from interpreter over to standard, then it’ll all be in the same place.

  63. sipa commented at 12:07 pm on July 25, 2015: member

    STRICTENC is indeed not technically consensus-critical, but it is part of the interpreter (as we want it for evaluation of standardness), which consensus-critical code depends on. I don’t see how you can disconnect it from the interpreter.

    In general I prefer to have the basic data type definitions (script/script, CScript) to have as little dependencies and functionality as possible, as they get pulled into everything, including consensus code. Ideally, they only provide representatiin, serialization, deserialization, and basic construction. Something like ToString() is mostly for debugging purposes IMHO, and should not be used for actual conversion to well-defined other representation. See for example the core_io module for transaction/block conversion code.

  64. jtimon commented at 9:45 pm on July 25, 2015: contributor

    Oh, you mean move ValueString and mapSigHashTypes over to script/standard and add the CScript as an argument to ValueString? Yes, that may make sense.

    Yes. I like this PR, but the code should just be in script/standard instead of script/script or script/interpreter, it’s only that.

    And, if we move the sighash stuff from interpreter over to standard, then it’ll all be in the same place.

    No, the sighash stuff is consensus critical so you don’t want it in script/standard because you don’t want the rest of what’s in there for libconsensus. I wouldn’t oppose to move the sighash flags, SignatureHash, TransactionSignatureChecker and MutableTransactionSignatureChecker to a different file (still required for consensus), but I don’t think that’s a priority and is certainly not needed for this PR (or libconsensus).

  65. mruddy force-pushed on Jul 26, 2015
  66. mruddy commented at 1:38 pm on July 26, 2015: contributor

    @jtimon OK, I just rebased and made the layering changes that I think we were talking about. I didn’t squish them into one commit so that you could easily diff.

    I did look at what @sipa was talking about. I see he added a FormatScript in core_write.cpp that I could probably build off of instead (never saw it before because it’s only referenced by tests). He might be onto something. At quick glance, I think I might be able to make things simpler by going the route he suggested. I’ll look into it more and may open an alternate pull request to this one. But at least the latest commit here kind of avoids the layering concern now, I think.

  67. jtimon commented at 7:47 pm on July 26, 2015: contributor

    Now it’s actually worse because you’re putting the whole script/standard inside libconsensus. In fact, that’s what is giving you errors on travis https://travis-ci.org/bitcoin/bitcoin/jobs/72684953#L2093 because you haven’t adapted makefile.am to include script/standard in libconsensus.

    But you’re very close, you can just move the rest of CScript::ToString to the new function in script/standard. That way you will be able to pass only a const CScript& as parameter (no additional vch param, which is nice) and you will be making libconsensus actually smaller instead of bigger. I’m not sure how many places CScript::ToString is called, but it is just a mechanical replace for ToString(const CScript&) [or whatever you want to call it].

    Sorry if I haven’t clearer earlier about CScript::ToString: if you want to use the new function in script/standard, it cannot be a method of CScript but an independent function instead (because script/script should not depend on neither script/interpreter nor script/standard).

  68. jtimon commented at 9:41 pm on July 26, 2015: contributor

    To try to be clearer: if you need to “de-encapsulate” anything from CScript - by creating a new child class that uses the protected arguments, by creating new getters or even by making a private/protected public - to be able to move CScript::ToString up, I’m totally fine with that. I’m happy with any solution that ends up with equal or less code in libconsensus (https://github.com/bitcoin/bitcoin/blob/master/src/Makefile.am#L365), anything else is secondary to me with rewards to this PR (it also makes it “less risky” [I don’t think your changes are risky even violating the layering]). My preference would be to simply rename CScript::ToString() to script/standard::ToString(const CScript&) - a trivial change using regular expressions or patience (the compiler won’t let you get this little step wrong, anyway: just remove CScript::ToString and make the compiler happy with the new function). But better is better, so my only requirement for an utACK is what I said before: equal or less code in libconsensus (and less is better).

    EDIT: So, to be completely clear. It’s not your fault that CScript::ToString() is in libconsensus, we just don’t want you to make it worse by improving the method/function in-place.

  69. mruddy force-pushed on Jul 28, 2015
  70. mruddy commented at 1:41 am on July 28, 2015: contributor

    @jtimon that’s a lot of useful input, thanks! I took that and actually refactored these changes twice.

    I put each of the two ways into the last two commits.

    The first commit refactored into a couple of formatter classes. It worked, but the second/next idea seemed a little cleaner.

    The second commit does away with the formatter class idea of the previous commit and just moves CScript::ToString out into a function in core_write.cpp.

    I think this last commit converges your input with sipa’s input. I think the last one loops in everyone’s input, doesn’t layer violate, and reduces code from the consensus library.

    I purposefully didn’t choose to sighhash decode some scriptSigs that were just going to be logged since those usages were tangential to what i was trying to actually update for this ticket.

    Let me know what you think of the latest. Thanks!

  71. mruddy commented at 10:53 am on July 28, 2015: contributor
    … or not. I see the travis windows builds failed because primitives/transaction.cpp is still part of libconsensus and references the ScriptToAsmStr for ToString’ing CTxIn and CTxOut objects. Guess I’ll have to move those around too.
  72. jtimon commented at 11:54 am on July 28, 2015: contributor

    You are welcomed. I’m fine with putting new things in core_io as @sipa suggested, just not in libconsensus. CTransaction::ToString now calls ScriptToAsmStr so instead of putting script/standard in libconsensus, now you’re putting core_io instead. The important thing is this: independently of where you chose to put the new code outside of libconsensus, you cannot include that new code from libconsensus. That’s why I keep posting a link to the list of files that are part of libconsensus: https://github.com/bitcoin/bitcoin/blob/master/src/Makefile.am#L365 If you include more things in any of those files, travis will complain (unless you adapt the makefile properly to include the new file, in which case we will complain).

    So, either don’t adapt CTransaction::ToScript to the new code (seems the simpler solution) or also take CTransaction::ToString out of consensus (seems better but also more work).

  73. jtimon commented at 12:00 pm on July 28, 2015: contributor
    Another possibility is to leave the new code in libconsensus like you had at the beginning (not my preference), but it still couldn’t be in script/script since you need script/interpreter and that would cause a circular dependency. So even leaving the new code in libconsensus, you always need to rename CScript::ToString and move it our of script/script.
  74. mruddy force-pushed on Jul 28, 2015
  75. mruddy commented at 11:48 pm on July 28, 2015: contributor
    It turns out that resolving that last dependency was pretty easy. I simply stopped using that script assembly formatting in the CTxIn and CTxOut ToString methods. Those ToString’s were only called by very low value debug and log print statements and the formatted scripts were being truncated immediately too. So, converting to hex instead in those cases isn’t losing much, if anything at all, in my opinion. Doing it this way allowed the removal of the original CScript::ToString from libconsensus.
  76. in src/primitives/transaction.cpp: in ca955e2c8c outdated
    4@@ -5,6 +5,7 @@
    5 
    6 #include "primitives/transaction.h"
    7 
    8+#include "core_io.h"
    


    jtimon commented at 9:57 am on July 29, 2015:
    This is not necessary anymore, right?
  77. in src/bitcoin-tx.cpp: in ca955e2c8c outdated
    11@@ -12,6 +12,7 @@
    12 #include "primitives/transaction.h"
    13 #include "script/script.h"
    14 #include "script/sign.h"
    15+#include "script/standard.h"
    


    jtimon commented at 9:58 am on July 29, 2015:
    This is core_io now.
  78. in src/test/script_tests.cpp: in ca955e2c8c outdated
     8@@ -9,6 +9,7 @@
     9 #include "key.h"
    10 #include "keystore.h"
    11 #include "script/script.h"
    12+#include "script/standard.h"
    


    jtimon commented at 9:58 am on July 29, 2015:
    This is core_io now.
  79. jtimon commented at 10:00 am on July 29, 2015: contributor
    This looks like a reasonable solution. Apart from the latest little nits, consensus-safe-review ACK (I also slightly reviewed the new functions, but didn’t look much at the tests).
  80. mruddy force-pushed on Jul 29, 2015
  81. mruddy commented at 12:46 pm on July 29, 2015: contributor
    @jtimon You are correct about those latest nits. I made the updates and squashed+rebased everything back down to the one latest commit. I also updated the release notes description at the same time. Should be all good now. Thanks for the help, it was good working with you on this!
  82. jtimon commented at 12:55 pm on July 29, 2015: contributor
    Thanks to you for your patience when improving this. Everything looks good, re-utACK.
  83. in src/core_write.cpp: in 3b85be2c37 outdated
    88+        }
    89+        if (0 <= opcode && opcode <= OP_PUSHDATA4) {
    90+            if (vch.size() <= static_cast<vector<unsigned char>::size_type>(4)) {
    91+                str += strprintf("%d", CScriptNum(vch, false).getint());
    92+            } else {
    93+                if (fAttemptSighashDecode) {
    


    sipa commented at 11:45 am on July 30, 2015:
    Nit: the !script.IsUnspendable() check can move here, I believe.
  84. sipa commented at 11:47 am on July 30, 2015: member
    Untested ACK, but the tests look convincing.
  85. Resolve issue 3166.
    These changes decode valid SIGHASH types on signatures in assembly (asm) representations of scriptSig scripts.
    This squashed commit incorporates substantial helpful feedback from jtimon, laanwj, and sipa.
    af3208bfa6
  86. mruddy force-pushed on Jul 31, 2015
  87. mruddy commented at 0:18 am on July 31, 2015: contributor
    @sipa nit addressed. I also added a new test case just to cover a specific low probability case related to the nit to make sure it was covered.
  88. jgarzik commented at 5:27 pm on September 15, 2015: contributor
    ut ACK - looks ready to merge
  89. laanwj merged this on Sep 25, 2015
  90. laanwj closed this on Sep 25, 2015

  91. laanwj referenced this in commit 48efbdbe98 on Sep 25, 2015
  92. mruddy deleted the branch on Sep 29, 2015
  93. zkbot referenced this in commit 3b68ab255f on Apr 17, 2018
  94. in src/primitives/transaction.cpp:39 in af3208bfa6
    35@@ -36,7 +36,7 @@ std::string CTxIn::ToString() const
    36     if (prevout.IsNull())
    37         str += strprintf(", coinbase %s", HexStr(scriptSig));
    38     else
    39-        str += strprintf(", scriptSig=%s", scriptSig.ToString().substr(0,24));
    40+        str += strprintf(", scriptSig=%s", HexStr(scriptSig).substr(0, 24));
    


    arielgabizon commented at 12:33 pm on April 18, 2018:
    was there a reason HexStr wasn’t used here before?

    mruddy commented at 1:04 pm on April 18, 2018:
    It was just more verbose (someone’s personal preference, I guess), see what was removed CScript::ToString: https://github.com/bitcoin/bitcoin/commit/af3208bfa6967d6b35aecf0ba35d9d6bf0f8317e#diff-f7ca24fb80ddba0f291cb66344ca6fcb
  95. zkbot referenced this in commit d408e23ab7 on Apr 18, 2018
  96. zkbot referenced this in commit 0753a0e8a9 on Apr 19, 2018
  97. furszy referenced this in commit 8cd9c592a9 on May 29, 2020
  98. MarcoFalke 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: 2024-11-22 06:12 UTC

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