3 ms·
Possible bug: The instructions BOOLAND and BOOLOR don't interpret the stack values the same way IF, VERIFY etc do. They decode the top stack values as integers
by VMG 12y ago
Possible bug:
The instructions BOOLAND and BOOLOR don't interpret the stack values the same way IF, VERIFY etc do. They decode the top stack values as integers and compare against zero, thus they have to fail when the top stack item size is greater than 4 bytes.
Edit: littleEndian.decode also doesn't seem to respect the size limits
Edit2: .. or signed integers for that matter. So while this is a very cool basic concept, it's not a complete implementation.
The reference client provides test suites
https://github.com/bitcoin/bitcoin/blob/master/src/test/data/script_valid.json https://github.com/bitcoin/bitcoin/blob/master/src/test/data...
https://github.com/bitcoin/bitcoin/blob/master/src/test/data/script_invalid.json https://github.com/bitcoin/bitcoin/blob/master/src/test/data...
- Theyeard 12y agoYes, you're right, numbers treatment is not exactly the same as in Bitcoin Core. The script interpreter supports only basics and it was implemented to show how Bitcoin Script works in general for another article [0]. But it was not clear from this text whether it's a complete implementation or not so it looks like a bug. I've added the annotation [1] and will update the interpreter in the future. Of course if one wanted to use Bitcoin in real projects I'd rather recommend Bitcoin.js [2] but that's another topic. Thanks for comment! [0]: https://curiosity-driven.org/bitcoin-contracts https://curiosity-driven.org/bitcoin-contracts [1]: https://curiosity-driven.org/low-level-bitcoin#operators https://curiosity-driven.org/low-level-bitcoin#operators [2]: http://bitcoinjs.org/ http://bitcoinjs.org/
- VMG 12y agoNo problem - I wasn't sure if this is something you're currently working on or just a demonstration. The script interpreter is a tricky beast that looks easy but has a lot of edge cases. If one client behaves slightly different, a blockchain fork could happen: https://bitcoin.org/en/alert/2013-03-11-chain-fork https://bitcoin.org/en/alert/2013-03-11-chain-fork
- Theyeard 12y agoYes, exactly. And there are a lot of tricky corner cases like SIGHASH_SINGLE when number of inputs != number of outputs with hash 0x01 [0]. Actually the entire implementation (Bitcoin Core) is the specification :) It's interesting from the software design point of view - an extreme case of backwards compatibility. It's hard even within Bitcoin Core as some changes already caused forks [1]. The article is just a demonstration but it won't hurt if it was as accurate as possible (while still being readable) :) [0] https://en.bitcoin.it/wiki/OP_CHECKSIG#Procedure_for_Hashtype_SIGHASH_SINGLE https://en.bitcoin.it/wiki/OP_CHECKSIG#Procedure_for_Hashtyp... [1] http://bitcoinmagazine.com/3668/bitcoin-network-shaken-by-blockchain-fork/ http://bitcoinmagazine.com/3668/bitcoin-network-shaken-by-bl...