Title: Tons of non-standard scripts! Post by: etotheipi on November 01, 2011, 04:17:40 AM I went on a scavenger hunt, looking for non-std scripts I could use to test my script evaluation engine. Unfortunately (?), the main-network is rather boring in this sense, but the testnet has quite a few goodies. I put a complete dump of every non-std script from the testnet onto github/gist:
All non-std scripts in a text-file on gist! (https://gist.github.com/1329788) Now onto my questions:
Just for fun, here's two exciting scripts from the testnet -- the first is a TxOut, the second is the TxIn that spends the TxOut: TxOut Script: Code: 3 TxIn Script: Code: OP_0 Title: Re: Tons of non-standard scripts! Post by: Gavin Andresen on November 01, 2011, 05:55:21 PM 1. TxOut scripts are not evaluated until they are spent-- those are probably unspendable TxOuts.
2. The inputs must be valid (you're looking at coinbase txns with no inputs though). Again, TxOuts aren't evaluated until they are used as inputs in another transaction; as long as they deserialize properly they'll be accepted. 3. I don't know of any other bugs in the scripts ops, but I don't know that anybody has written thorough unit tests for them (anybody looking for a good get-your-feet-wet project that could be a good one to tackle; there are already unit tests for CHECKMULTISIG in the repostitory....). Title: Re: Tons of non-standard scripts! Post by: etotheipi on November 01, 2011, 07:32:53 PM 1. TxOut scripts are not evaluated until they are spent-- those are probably unspendable TxOuts. Fair enough... I was wondering if there was a reason to believe they were spendable, and thus I need to add something to my scripting code to accommodate. I'm really just looking for a sanity check. It sounds like there's no action here.. at least not until someone demonstrates they are spendable and my code would've failed.2. The inputs must be valid (you're looking at coinbase txns with no inputs though). Again, TxOuts aren't evaluated until they are used as inputs in another transaction; as long as they deserialize properly they'll be accepted. Looking back, I see that the transactions are coinbase, but the non-std scripts are in the TxOuts -- which means they could've been put on any transaction, not specific to coinbase. So my response is the same here as in #1 -- I'll just assume they are unspendable and that I don't need to accommodate anything new in script engine. You make a good point that TxOut scripts can be anything, so I'll just always assume they are unspendable until I see evidence otherwise.3. I don't know of any other bugs in the scripts ops, but I don't know that anybody has written thorough unit tests for them (anybody looking for a good get-your-feet-wet project that could be a good one to tackle; there are already unit tests for CHECKMULTISIG in the repostitory....). It sounds like that arbitrary scripts have been run through the client software successfully in the past (such as these testnet scripts), but there hasn't been any rigorous efforts to check that it's robust, etc. I would volunteer, but I'm not sure how to isolate the ref client scripting engine, and then still throw in things like OP_CHECKSIG evaluations which require more than just the script itself (such as the whole Tx and the ECDSA verification methods).Title: Re: Tons of non-standard scripts! Post by: Gavin Andresen on November 01, 2011, 09:37:32 PM It sounds like that arbitrary scripts have been run through the client software successfully in the past (such as these testnet scripts), but there hasn't been any rigorous efforts to check that it's robust, etc. I would volunteer, but I'm not sure how to isolate the ref client scripting engine, and then still throw in things like OP_CHECKSIG evaluations which require more than just the script itself (such as the whole Tx and the ECDSA verification methods). See src/test/script_test.cpp in git HEAD. Or for more examples of testing script operations, the unit tests I wrote here: https://github.com/gavinandresen/bitcoin-git/blob/op_eval/src/test/script_op_eval_tests.cpp https://github.com/gavinandresen/bitcoin-git/blob/op_eval/src/test/multisig_tests.cpp Title: Re: Tons of non-standard scripts! Post by: nibor on November 01, 2011, 11:07:26 PM some are mine... see: https://bitcointalk.org/index.php?topic=43821.msg529672#msg529672 Input non-std transaction: http://blockexplorer.com/testnet/t/6ttfeb55B1 Spent by: http://blockexplorer.com/testnet/t/AFdRB1CHS3 They just insert some text ("bob" in hex I think, then drop it). They are however spendable. At the time I was trying to think of a way you could spend some outputs without Block Explorer realising. As that would be dangerous as I am sure a lot of people put too much faith in Block Explorer always being correct (which it is :)!). But since BE can just look to see if there is a valid transaction that has spent this output it is very hard to fool it. Title: Re: Tons of non-standard scripts! Post by: etotheipi on November 02, 2011, 06:30:49 PM Okay, I am now battling the OP_CHECKMULTISIG example in my original post. I thought the point of OP_CHECKMULTISIG was to be simple and not require two-dozen other op-codes to get an M-of-N transaction. It seems to me that it is simple if you have everyone's public key, but not if you have their address. Is this really the simplest way to do M-of-N with 3 addresses? (see top post)
Second of all, I'm a little confused about the script itself. I am crashing when I try to HASH160 an OP_0 byte, but I can't figure out what my scripting code did wrong. Perhaps someone with scripting experience can point me to my error. This is the exact state of my stack after every OP_CODE: Code: TxIn Script: Can anyone help identify what op-code I mis-applied? These two scripts are straight from the testnet, and the 0.4.0 client accepted them as a valid pair. Title: Re: Tons of non-standard scripts! Post by: ByteCoin on November 02, 2011, 07:22:09 PM I am crashing when I try to HASH160 an OP_0 byte, but I can't figure out what my scripting code did wrong. I believe that "crashing when you try to HASH160 an OP_0 byte" is what your scripting code did wrong. ByteCoin Title: Re: Tons of non-standard scripts! Post by: etotheipi on November 02, 2011, 08:29:41 PM I am crashing when I try to HASH160 an OP_0 byte, but I can't figure out what my scripting code did wrong. I believe that "crashing when you try to HASH160 an OP_0 byte" is what your scripting code did wrong. ByteCoin Gah! That was stupid. I assumed that HASH160 should only ever operate on strings, and thus I must've done something wrong upstream to end up with a HASH160(OP_0). Upon closer inspection, I see that zero is actually a placeholder for the third public key that wasn't supplied. I just need to "define" HASH160(OP_0) to return...anything. That's what I get for making assumptions... Thanks. Title: Re: Tons of non-standard scripts! Post by: Gavin Andresen on November 02, 2011, 08:45:07 PM OP_0 pushes an empty array of bytes onto the stack, so you should RIPEMD160(SHA256([])).
(thanks go genjix for setting me straight, I'd been thinking OP_0 pushed a 0x00 onto the stack, and that isn't right. The scripting engine knows that an empty array is 'False', and FIPS standards make sure hashing empty strings/arrays is well-defined...) Title: Re: Tons of non-standard scripts! Post by: etotheipi on November 02, 2011, 08:53:04 PM Most interesting. If I wasn't about to board a plane right now, I'd go clarify that on the Bitcoin Scripting wiki...
Do all OP_X codes push an empty string onto the stack? Or just OP_0? Is it safe to assume that it is an error if I somehow end up with HASH160(OP_3)? Title: Re: Tons of non-standard scripts! Post by: Gavin Andresen on November 02, 2011, 08:57:26 PM OP_1 through OP_16 push single bytes (0x01 through 0x10) onto the stack.
RE: updating the wiki: good idea, I'll go do that... |