Bitcoin Forum
March 29, 2024, 06:15:23 AM *
News: Latest Bitcoin Core release: 26.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: « 1 [2] 3 4 »  All
  Print  
Author Topic: A full shell script implementation of bitcoin ?  (Read 14122 times)
gene
Sr. Member
****
Offline Offline

Activity: 252
Merit: 250


View Profile
February 24, 2011, 01:42:36 PM
 #21

What is it with you and bash scripts?  Roll Eyes
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 |
The Bitcoin software, network, and concept is called "Bitcoin" with a capitalized "B". Bitcoin currency units are called "bitcoins" with a lowercase "b" -- this is often abbreviated BTC.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1711692923
Hero Member
*
Offline Offline

Posts: 1711692923

View Profile Personal Message (Offline)

Ignore
1711692923
Reply with quote  #2

1711692923
Report to moderator
1711692923
Hero Member
*
Offline Offline

Posts: 1711692923

View Profile Personal Message (Offline)

Ignore
1711692923
Reply with quote  #2

1711692923
Report to moderator
1711692923
Hero Member
*
Offline Offline

Posts: 1711692923

View Profile Personal Message (Offline)

Ignore
1711692923
Reply with quote  #2

1711692923
Report to moderator
Nefario
Hero Member
*****
Offline Offline

Activity: 602
Merit: 512


GLBSE Support support@glbse.com


View Profile WWW
February 24, 2011, 01:49:55 PM
 #22

What is it with you and bash scripts?  Roll Eyes
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 Offline

Activity: 1288
Merit: 1076


View Profile
February 24, 2011, 02:01:01 PM
 #23

What is it with you and bash scripts?  Roll Eyes
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
Hero Member
*****
Offline Offline

Activity: 602
Merit: 512


GLBSE Support support@glbse.com


View Profile WWW
February 24, 2011, 02:25:57 PM
 #24

What is it with you and bash scripts?  Roll Eyes
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 Offline

Activity: 1288
Merit: 1076


View Profile
February 27, 2011, 07:25:11 PM
 #25

Here is my first attempt to recompute the hash of the Genesis block:

Code:
#{
#  "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
*
expert
Offline Offline

Activity: 1232
Merit: 1071


View Profile
February 27, 2011, 08:07:07 PM
 #26

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 Offline

Activity: 3920
Merit: 2347


Eadem mutata resurgo


View Profile
February 27, 2011, 08:21:26 PM
 #27


Would that be a bash hash or a hash bash?

Bang hash bash

Hash bang boom!

grondilu (OP)
Legendary
*
Offline Offline

Activity: 1288
Merit: 1076


View Profile
February 28, 2011, 09:33:57 AM
 #28


I know this is a poor programming method, but I've tried a whole bunch of combinations for the size of each value:

Code:
#{
#  "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
Full Member
***
Offline Offline

Activity: 144
Merit: 100


View Profile
February 28, 2011, 10:16:21 AM
 #29

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
Hero Member
*****
Offline Offline

Activity: 566
Merit: 500


Unselfish actions pay back better


View Profile WWW
February 28, 2011, 10:17:03 AM
 #30

Code:
  xxd -pr

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.

Code:
# 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 Offline

Activity: 1288
Merit: 1076


View Profile
February 28, 2011, 11:11:24 AM
Last edit: February 28, 2011, 12:01:30 PM by grondilu
 #31

Thanks, that helped!

Code:
#{
#  "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
Hero Member
*****
Offline Offline

Activity: 566
Merit: 500


Unselfish actions pay back better


View Profile WWW
February 28, 2011, 11:53:37 AM
 #32

Thanks, that helped!

Cool!  Smiley

The following patch might make the script a tad more computationally efficient:

Code:
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 Offline

Activity: 1288
Merit: 1076


View Profile
February 28, 2011, 12:02:32 PM
 #33

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
Hero Member
*****
Offline Offline

Activity: 566
Merit: 500


Unselfish actions pay back better


View Profile WWW
February 28, 2011, 12:05:51 PM
 #34

(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 Offline

Activity: 3920
Merit: 2347


Eadem mutata resurgo


View Profile
February 28, 2011, 09:19:23 PM
 #35

grondilu:
Quote
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 Offline

Activity: 1288
Merit: 1076


View Profile
March 01, 2011, 09:26:24 PM
 #36


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:

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
Hero Member
*****
Offline Offline

Activity: 566
Merit: 500


Unselfish actions pay back better


View Profile WWW
March 01, 2011, 09:41:09 PM
 #37

My first attempt is this code:

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?

Code:
$ 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 Offline

Activity: 1288
Merit: 1076


View Profile
March 01, 2011, 09:43:36 PM
 #38

You are aware that the bashism <<< appends a LF (ASCII 10) to its argument, right?

Code:
$ 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
Hero Member
*****
Offline Offline

Activity: 566
Merit: 500


Unselfish actions pay back better


View Profile WWW
March 01, 2011, 09:46:54 PM
 #39


I'm pretty sure it doesn't matter, since xxd does only read hexadecimal characters.

Code:
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
Hero Member
*****
Offline Offline

Activity: 566
Merit: 500


Unselfish actions pay back better


View Profile WWW
March 01, 2011, 09:58:12 PM
 #40

Code:
{ bigEndianHex2littleEndianHex <<<"$a" |xxd -p -r ; bigEndianHex2littleEndianHex <<<"$b" |xxd -p -r ; } |openssl dgst -sha256 -hex

How about

Code:
{ 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
Pages: « 1 [2] 3 4 »  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!