genjix
Legendary
Offline
Activity: 1232
Merit: 1076
|
|
July 27, 2011, 04:46:57 AM |
|
|
|
|
|
genjix
Legendary
Offline
Activity: 1232
Merit: 1076
|
|
July 27, 2011, 04:50:47 AM |
|
01 00 00 00 version 01 number of inputs (var_uint)
input 0: c9 97 a5 e5 6e 10 41 02 fa 20 9c 6a 85 2d d9 06 60 a2 0b 2d 9c 35 24 23
43 size of script (var_uint) 41 push 65 bytes to stack 04 11 db 93 e1 dc db 8a 01 6b 49 84 0f 8c 53 bc 1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb 84 cc f9 74 44 64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 ac OP_CHECKSIG
02 number of outputs (var_uint)
output 0: 00 ca 9a 3b 00 00 00 00 amount = 10.00000000 43 size of script (var_uint) script for output 0: 41 push 65 bytes to stack 04 ae 1a 62 fe 09 c5 f5 1b 13 90 5f 07 f0 6b 99 a2 f7 15 9b 22 25 f3 74 cd 37 8d 71 30 2f a2 84 14 e7 aa b3 73 97 f5 54 a7 df 5f 14 2c 21 c1 b7 30 3b 8a 06 26 f1 ba de d5 c7 2a 70 4f 7e 6c d8 4c ac OP_CHECKSIG
output 1: 00 28 6b ee 00 00 00 00 amount = 40.00000000 43 size of script (var_uint) script for output 1: 41 push 65 bytes to stack 04 11 db 93 e1 dc db 8a 01 6b 49 84 0f 8c 53 bc 1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb 84 cc f9 74 44 64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 ac OP_CHECKSIG
00 00 00 00 locktime 01 00 00 00 hash_code_type (added on)
result = 01 00 00 00 01 c9 97 a5 e5 6e 10 41 02 fa 20 9c 6a 85 2d d9 06 60 a2 0b 2d 9c 35 24 23 ed ce 25 85 7f cd 37 04 00 00 00 00 01 ac 02 00 ca 9a 3b 00 00 00 00 43 41 04 ae 1a 62 fe 09 c5 f5 1b 13 90 5f 07 f0 6b 99 a2 f7 15 9b 22 25 f3 74 cd 37 8d 71 30 2f a2 84 14 e7 aa b3 73 97 f5 54 a7 df 5f 14 2c 21 c1 b7 30 3b 8a 06 26 f1 ba de d5 c7 2a 70 4f 7e 6c d8 4c ac 00 28 6b ee 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 84 0f 8c 53 bc 1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb 84 cc f9 74 44 64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 ac 00 00 00 00 01 00 00 00
Relevant file, https://gitorious.org/libbitcoin/libbitcoin/blobs/master/src/script.cppSee function called script::op_checksig() Also, https://gitorious.org/libbitcoin/libbitcoin/blobs/master/tests/script-test.cpp
|
|
|
|
etotheipi (OP)
Legendary
Offline
Activity: 1428
Merit: 1093
Core Armory Developer
|
|
August 21, 2011, 01:16:36 AM Last edit: August 21, 2011, 01:46:45 AM by etotheipi |
|
I finally got around to updating my code to handle test-network addresses, and so I finally had to figure out how to do the address conversion correctly. Here are the updated diagram! The full size image is here: http://dl.dropbox.com/u/1139081/BitcoinImg/PubKeyToAddr.pngAs before, you can still access the raw SVG data here. I used Inkscape to create this, so there's no guarantees the file is usable unless you also use Inkscape.
|
|
|
|
samr7
Full Member
Offline
Activity: 140
Merit: 430
Firstbits: 1samr7
|
|
August 21, 2011, 01:44:13 AM |
|
I finally got around to updating my code to handle test-network addresses, and so I finally had to figure out how to do the address conversion correctly. Here are the updated diagrams!
+1 Nice work etotheipi!
|
|
|
|
etotheipi (OP)
Legendary
Offline
Activity: 1428
Merit: 1093
Core Armory Developer
|
|
August 23, 2011, 12:49:27 AM |
|
And now I've updated the Transaction bytemap with examples of each TxIn and TxOut type. Once again, I've learned quite a bit about BTC since making the original illustrations, and so I thought it was a good idea to update it. The full size image can be downloaded here: http://dl.dropbox.com/u/1139081/BitcoinImg/TxBinaryMap.pngThe only thing I'm not 100% sure about is the script field on a coinbase generation TxIn. I'm pretty sure I read that mining pools use that field as an extra nonce, so that they can have all the connected workers hashing different things and avoid redundant computations (different script --> different Tx hash --> different merkle tree --> different merkle root).
|
|
|
|
jackjack
Legendary
Offline
Activity: 1176
Merit: 1280
May Bitcoin be touched by his Noodly Appendage
|
|
August 23, 2011, 01:57:32 AM |
|
In TxOut 0, it's hash160(recipientPubkey) instead of recipientAdress
|
Own address: 19QkqAza7BHFTuoz9N8UQkryP4E9jHo4N3 - Pywallet support: 1AQDfx22pKGgXnUZFL1e4UKos3QqvRzNh5 - Bitcointalk++ script support: 1Pxeccscj1ygseTdSV1qUqQCanp2B2NMM2 Pywallet: instructions. Encrypted wallet support, export/import keys/addresses, backup wallets, export/import CSV data from/into wallet, merge wallets, delete/import addresses and transactions, recover altcoins sent to bitcoin addresses, sign/verify messages and files with Bitcoin addresses, recover deleted wallets, etc.
|
|
|
etotheipi (OP)
Legendary
Offline
Activity: 1428
Merit: 1093
Core Armory Developer
|
|
August 23, 2011, 02:34:52 AM |
|
I originally decided not to go into byte-level detail on the TxOut scripts, but I have no idea why. I've updated it to be a complete byte map now. Also changed constants like "30" to "0x30" for clarification. If it's not perfect, it's damned close!
|
|
|
|
jackjack
Legendary
Offline
Activity: 1176
Merit: 1280
May Bitcoin be touched by his Noodly Appendage
|
|
August 23, 2011, 02:47:29 AM |
|
Indeed, it was close: length(hash160) = 20 = 0x14 (not 0x16) It should be perfect now
|
Own address: 19QkqAza7BHFTuoz9N8UQkryP4E9jHo4N3 - Pywallet support: 1AQDfx22pKGgXnUZFL1e4UKos3QqvRzNh5 - Bitcointalk++ script support: 1Pxeccscj1ygseTdSV1qUqQCanp2B2NMM2 Pywallet: instructions. Encrypted wallet support, export/import keys/addresses, backup wallets, export/import CSV data from/into wallet, merge wallets, delete/import addresses and transactions, recover altcoins sent to bitcoin addresses, sign/verify messages and files with Bitcoin addresses, recover deleted wallets, etc.
|
|
|
bcforum
|
|
August 23, 2011, 03:31:51 AM |
|
Second, here's another diagram. It's not nearly as complicated as OP_CHECKSIG, but once I had it mapped out like this, I was able to do a ton of address magic in my code and get it right on the first try. Not having to guess endianness at every step is a big help! Remembering the extra bytes that have to be added here and there helps, too.
IXCoin is using the same leading byte as Bitcoin (yet another example of the laziness of the "developer")
|
If you found this post useful, feel free to share the wealth: 1E35gTBmJzPNJ3v72DX4wu4YtvHTWqNRbM
|
|
|
Nasakioto
Full Member
Offline
Activity: 172
Merit: 283
Thomas Nasakioto
|
|
August 24, 2011, 10:51:13 PM |
|
IXCoin is using the same leading byte as Bitcoin (yet another example of the laziness of the "developer")
That's being addressed in the upcoming update.
|
|
|
|
Red Emerald
|
|
November 17, 2011, 06:10:48 AM |
|
Awesome diagrams! I am really getting interested in scripts. This cleared up some grey areas for me on the "basic" transactions. Thanks!
|
|
|
|
crispy
Newbie
Offline
Activity: 30
Merit: 0
|
|
November 20, 2011, 03:33:03 AM |
|
Thanks for the hard work. Usually the work of documenting software can teach you better than almost any other way how it actually works.
|
|
|
|
etotheipi (OP)
Legendary
Offline
Activity: 1428
Merit: 1093
Core Armory Developer
|
|
November 22, 2011, 06:36:22 AM |
|
Awesome diagrams! I am really getting interested in scripts. This cleared up some grey areas for me on the "basic" transactions. Thanks!
If you're interested in scripts, you might find the following links interesting. The first one is literally every non-std script from the testnet. I was looking for non-standard transactions for testing my scripting code in PyBtcEngine -- and it turns out there's quite a few on the testnet: https://github.com/etotheipi/PyBtcEngine/blob/master/testnetNonStdScript.txthttps://github.com/etotheipi/PyBtcEngine/blob/master/scriptEvalStackState.txtThe second link is a few multi-sig transactions, with the stack state at every step of script evaluation (as produced by my code once I finally got it working). It is a variety of scripts not currently considered "standard" but may become standard in the near future. Seeing the script-evaluation chain for complicated transactions is quite educational (and critical for debugging!). Thanks for the hard work. Usually the work of documenting software can teach you better than almost any other way how it actually works.
Thanks crispy. It was actually the act of implementing all this stuff in code that really taught me about it, and the documentation was my way of giving back for all the knowledge I gained from for the forums. I wish I had documentation like this when I first started down this development path 4 months ago. P.S. - if you found any of this useful, please consider donating. This stuff took a lot of time!
|
|
|
|
marcus_of_augustus
Legendary
Offline
Activity: 3920
Merit: 2349
Eadem mutata resurgo
|
|
March 16, 2012, 09:33:06 PM |
|
tagging
|
|
|
|
Realpra
|
|
November 26, 2012, 06:06:09 PM |
|
Forgive me for being a noob and doing a necro here, but what is "VI"/"scriptlen", it does not say on the wiki either?
|
|
|
|
|
etotheipi (OP)
Legendary
Offline
Activity: 1428
Merit: 1093
Core Armory Developer
|
|
January 13, 2013, 03:58:26 AM |
|
Speaking of VAR_INTs, smtp just pointed out that my OP_CHECKSIG diagram was not showing the VAR_INTs that represent script length in the TxCopy (with blanked scripts). While I think that your Tx class in whatever language you're using should handle that detail for you, the graphic was definitely inconsistent. So I fixed it and re-uploaded it to the wiki, too. https://en.bitcoin.it/wiki/OP_CHECKSIGhttps://bitcointalk.org/index.php?topic=29416.msg370321#msg370321
|
|
|
|
CompNsci
|
|
April 11, 2014, 09:57:01 PM |
|
Can we get the .svg files posted for the OP_CHECKSIG diagram somewhere? The png available at the wiki is quite small and difficult to read.
|
|
|
|
|
etotheipi (OP)
Legendary
Offline
Activity: 1428
Merit: 1093
Core Armory Developer
|
|
July 16, 2014, 04:31:22 AM |
|
This is good. But I'll call you on the length of the pre-base58 address: it's 25 bytes long, not 24, but the upper byte is always 0 for regular bitcoin addresses. Also, the base58 encoding procedure will prepend a 1 for each preceding \x00 byte in the pre-encoded address, not just a single 1. Whoops, I was trying to update the diagrams and accidentally replied instead of editing. Sorry for the spam.... but enjoy the pics!
|
|
|
|
|