gene
|
|
February 24, 2011, 01:42:36 PM |
|
What is it with you and bash scripts? Can you do nothing else? I think the scripts are rather useful. They are far more portable than having to mess with wxwidgets or whatever the hell else just to get what should be a simple console application to work. They are also easy to understand. I would love to see many perl, python, and shell implementations of bitcoin.
|
*processing payment* *error 404 : funds not found* Do you want to complain on the forum just to fall for another scam a few days later? | YES | YES |
|
|
|
Nefario
|
|
February 24, 2011, 01:49:55 PM |
|
What is it with you and bash scripts? Can you do nothing else? I think the scripts are rather useful. They are far more portable than having to mess with wxwidgets or whatever the hell else just to get what should be a simple console application to work. They are also easy to understand. I would love to see many perl, python, and shell implementations of bitcoin. I'm sure they can be useful, that's not what I'm saying. I'm saying that everything Grondilu does is in bash, or at least everything he has proposed is in bash. I am sure that he's a bash wizard at this point though.
|
PGP key id at pgp.mit.edu 0xA68F4B7C To get help and support for GLBSE please email support@glbse.com
|
|
|
grondilu (OP)
Legendary
Offline
Activity: 1288
Merit: 1080
|
|
February 24, 2011, 02:01:01 PM |
|
What is it with you and bash scripts? Can you do nothing else? Well actually, no, I can't. I'm not good at anything else indeed. I'm not a very good programmer and bash is the only language in which I manage to do usefull stuffs.
|
|
|
|
Nefario
|
|
February 24, 2011, 02:25:57 PM |
|
What is it with you and bash scripts? Can you do nothing else? Well actually, no, I can't. I'm not good at anything else indeed. I'm not a very good programmer and bash is the only language in which I manage to do usefull stuffs. Well then I join you, except I use Ruby, and pretty much nothing else, I'm also very slow.
|
PGP key id at pgp.mit.edu 0xA68F4B7C To get help and support for GLBSE please email support@glbse.com
|
|
|
grondilu (OP)
Legendary
Offline
Activity: 1288
Merit: 1080
|
|
February 27, 2011, 07:25:11 PM |
|
Here is my first attempt to recompute the hash of the Genesis block: #{ # "hash":"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f", # "ver":1, # "prev_block":"0000000000000000000000000000000000000000000000000000000000000000", # "mrkl_root":"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b", # "time":1231006505, # "bits":486604799, # "nonce":2083236893,
ver=1 prev_block=0000000000000000000000000000000000000000000000000000000000000000 mrkl_root=4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b time=1231006505 bits=486604799 nonce=2083236893
printf "%2x%64s%64s%16x%16x%16x" $ver $prev_block $mrkl_root $time $bits $nonce | sed 's/ /0/g' | xxd -pr | openssl dgst -sha256 -binary | openssl dgst -sha256 -hex | sed 's/^.* //'
So far it doesn't work. Any help appreciated.
|
|
|
|
genjix
Legendary
Offline
Activity: 1232
Merit: 1076
|
|
February 27, 2011, 08:07:07 PM |
|
If you manage to figure out that (recomputing the hashes through shell) then that'd be great for everybody. I'm also curious how to do this.
|
|
|
|
marcus_of_augustus
Legendary
Offline
Activity: 3920
Merit: 2349
Eadem mutata resurgo
|
|
February 27, 2011, 08:21:26 PM |
|
Would that be a bash hash or a hash bash?
Bang hash bash
Hash bang boom!
|
|
|
|
grondilu (OP)
Legendary
Offline
Activity: 1288
Merit: 1080
|
|
February 28, 2011, 09:33:57 AM |
|
I know this is a poor programming method, but I've tried a whole bunch of combinations for the size of each value: #{ # "hash":"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f", # "ver":1, # "prev_block":"0000000000000000000000000000000000000000000000000000000000000000", # "mrkl_root":"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b", # "time":1231006505, # "bits":486604799, # "nonce":2083236893,
ver=1 prev_block=0000000000000000000000000000000000000000000000000000000000000000 mrkl_root=4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b time=1231006505 bits=486604799 nonce=2083236893
for s in - '' do for a in 2 4 do for b in 64 128 do for c in 16 24 32 do printf "%$s${a}x%$s${b}s%$s${b}s%$s${c}x%$s${c}x%$s${c}x" $ver $prev_block $mrkl_root $time $bits $nonce | sed 's/ /0/g' | xxd -pr | openssl dgst -sha256 -binary | openssl dgst -sha256 -hex | sed 's/^.* //' done done done done
None of them works. I pledge 5 BTC to whoever finds the correct way.
|
|
|
|
twobitcoins
|
|
February 28, 2011, 10:16:21 AM |
|
Perhaps this will help:
printf "%s%s%s%s%s%s" 01000000 0000000000000000000000000000000000000000000000000000000000000000 3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a 29ab5f49 ffff001d 1dac2b7c | xxd -r -p | openssl dgst -sha256 -binary | openssl dgst -sha256 -hex
6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000
A key thing you were missing is byte swapping. I manually byte-swapped all the inputs. You'll have to figure out how to script that.
|
|
|
|
kseistrup
|
|
February 28, 2011, 10:17:03 AM |
|
Am I right when I assume that xxd is supposed to produce a binary block that corresponds to the hex stream? If so, then ‘xxd -p -r’ might be what you're looking for. E.g. # A=0x41, B=0x42, C=0x43 $ echo 414243 | xxd -r -p && echo ABC $
Not that it helps much in the actual situation… Cheers,
|
Klaus Alexander Seistrup
|
|
|
grondilu (OP)
Legendary
Offline
Activity: 1288
Merit: 1080
|
|
February 28, 2011, 11:11:24 AM Last edit: February 28, 2011, 12:01:30 PM by grondilu |
|
Thanks, that helped! #{ # "hash":"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f", # "ver":1, # "prev_block":"0000000000000000000000000000000000000000000000000000000000000000", # "mrkl_root":"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b", # "time":1231006505, # "bits":486604799, # "nonce":2083236893,
bigEndianHex2littleEndianHex() { local s='' while read -n 2 char do s=$char$s done echo $s }
ver=1 prev_block=0000000000000000000000000000000000000000000000000000000000000000 mrkl_root=4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b time=1231006505 bits=486604799 nonce=2083236893
printf "%08x%08x%08x%064s%064s%08x" $nonce $bits $time $mrkl_root $prev_block $ver | bigEndianHex2littleEndianHex | xxd -r -p | openssl dgst -sha256 -binary | openssl dgst -sha256 -hex | sed 's/^.* //' | bigEndianHex2littleEndianHex
I can't really give the bounty since the solution was not complete. But thanks again.
|
|
|
|
kseistrup
|
|
February 28, 2011, 11:53:37 AM |
|
Thanks, that helped!
Cool! The following patch might make the script a tad more computationally efficient: diff --git a/bashhash.sh b/bashhash.sh index a99bf9d..1bddd92 100644 --- a/bashhash.sh +++ b/bashhash.sh @@ -24,8 +24,8 @@ time=1231006505 bits=486604799 nonce=2083236893 -printf "%8x%8x%8x%64s%64s%8x" $nonce $bits $time $mrkl_root $prev_block $ver | -sed 's/ /0/g' | +printf "%08x%08x%08x%64s%64s%08x" $nonce $bits $time $mrkl_root $prev_block $ver | +tr ' ' '0' | bigEndianHex2littleEndianHex | xxd -r -p | openssl dgst -sha256 -binary |
If basically uses printf to format the numbers, and uses tr instead of sed. Cheers,
|
Klaus Alexander Seistrup
|
|
|
grondilu (OP)
Legendary
Offline
Activity: 1288
Merit: 1080
|
|
February 28, 2011, 12:02:32 PM |
|
yep, I've edited (we actually don't need tr either, by the way).
I also tested on the second block. I worked fine.
|
|
|
|
kseistrup
|
|
February 28, 2011, 12:05:51 PM |
|
(we actually don't need tr either, by the way)
(You're right, I suppose we can always take for granted that the strings are 64 characters wide…) Cheers,
|
Klaus Alexander Seistrup
|
|
|
marcus_of_augustus
Legendary
Offline
Activity: 3920
Merit: 2349
Eadem mutata resurgo
|
|
February 28, 2011, 09:19:23 PM |
|
grondilu: I also wonder if all communications could not be done using HTTP. Blocks would be published via http GET method (giving the hash of the preceding block), and transactions could be sent via POST method.
One advantage of using http would be that it would be very hard for governments to forbid. Where did you get to with the network connection side of this, netcat could be an option. I agree that a Busybox dependency limitation would be a good place to put some boundaries to begin with.
|
|
|
|
grondilu (OP)
Legendary
Offline
Activity: 1288
Merit: 1080
|
|
March 01, 2011, 09:26:24 PM |
|
Ok now, let's try to make the Merkle tree. The first block with more than one transaction is the block 170. It has two transactions and its Merkle tree is: { "b1fea52486ce0c62bb442b530a3f0132b826c74e473d1f2c220bfa78111c5082", "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", "7dac2c5666815c17a3b36427de37bb9d2e2c5ccec3f8633eb91a4205cb4c10ff" } The third is the Merkle root. My first attempt is this code: { bigEndianHex2littleEndianHex <<<"$a" |xxd -p -r ; bigEndianHex2littleEndianHex <<<"$b" |xxd -p -r ; } |openssl dgst -sha256 -hex
Needless to say, the version without bigEndianHex2littleEndianHex didn't work either.
|
|
|
|
kseistrup
|
|
March 01, 2011, 09:41:09 PM |
|
My first attempt is this code: { bigEndianHex2littleEndianHex <<<"$a" |xxd -p -r ; bigEndianHex2littleEndianHex <<<"$b" |xxd -p -r ; } |openssl dgst -sha256 -hex
Needless to say, the version without bigEndianHex2littleEndianHex didn't work either. You are aware that the bashism <<< appends a LF (ASCII 10) to its argument, right? $ sha256sum </dev/null e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 - $ sha256sum <<< '' 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b - $ printf '\n' | sha256sum 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b - $ hexdump -C <<< a 00000000 61 0a |a.| 00000002 $
In the same vein: perhaps bigEndianHex2littleEndianHex() should use echo -n or printf instead of just echo… Cheers,
|
Klaus Alexander Seistrup
|
|
|
grondilu (OP)
Legendary
Offline
Activity: 1288
Merit: 1080
|
|
March 01, 2011, 09:43:36 PM |
|
You are aware that the bashism <<< appends a LF (ASCII 10) to its argument, right? $ sha256sum </dev/null e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 - $ sha256sum <<< '' 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b - $ printf '\n' | sha256sum 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b - $ hexdump -C <<< a 00000000 61 0a |a.| 00000002 $
In the same vein: perhaps bigEndianHex2littleEndianHex() should use echo -n or printf instead of just echo… I'm pretty sure it doesn't matter, since xxd -p -r does only read hexadecimal characters. echo "A 1" |xxd -p -r |xxd -p a1 echo -n "A 1" |xxd -p -r |xxd -p a1
|
|
|
|
kseistrup
|
|
March 01, 2011, 09:46:54 PM |
|
I'm pretty sure it doesn't matter, since xxd does only read hexadecimal characters. echo "A 1" |xxd -p -r |xxd -p a1 echo -n "A 1" |xxd -p -r |xxd -p a1
Oh, great, I should have checked that, of course… Cheers,
|
Klaus Alexander Seistrup
|
|
|
kseistrup
|
|
March 01, 2011, 09:58:12 PM |
|
{ bigEndianHex2littleEndianHex <<<"$a" |xxd -p -r ; bigEndianHex2littleEndianHex <<<"$b" |xxd -p -r ; } |openssl dgst -sha256 -hex
How about { bigEndianHex2littleEndianHex <<<"$a" | xxd -p -r ; bigEndianHex2littleEndianHex <<<"$b" | xxd -p -r ; } \ | openssl dgst -sha256 -binary \ | openssl dgst -sha256 -hex \ | bigEndianHex2littleEndianHex
That would give the third hash, wouldn't it? Cheers,
|
Klaus Alexander Seistrup
|
|
|
|