Bitcoin Forum
November 06, 2024, 11:25:16 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Pseudo Code For Generating Bitcoins?  (Read 5189 times)
gigabytecoin (OP)
Sr. Member
****
Offline Offline

Activity: 280
Merit: 252


View Profile
March 16, 2011, 01:16:23 AM
 #1

I am interested in trying to write my own open sourced miner. But have no idea where to start.

I have read through the forum quite a bit and asked a similar question before, but to no avail.

Can anybody provide some pseudo code for generating bitcoins?

I assume it goes something like...

Code:
$hashed_string_to_crack = grab_new_hash();
while($hashed_string_unknown === true) {
  //try to crack hash?
 
  if($hash_cracked) {
    $hashed_string_unkown = false;
  }
}
submit_cracked_hash_to_bitcoin_network($hash_cracked);
repeat;

Or am I better off just to examine the poclbm source code?
grondilu
Legendary
*
Offline Offline

Activity: 1288
Merit: 1080


View Profile
March 16, 2011, 01:51:11 AM
 #2

I think you could use the code I wrote in my thread about a full shell script implementation of bitcoin:

Code:
bigEndianHex2littleEndianHex() {
local s=''
while read -n 2 char
do s=$char$s
done
echo $s
}

bitcoinHash() {
bigEndianHex2littleEndianHex |
xxd -p -r |
openssl dgst -sha256 -binary |
openssl dgst -sha256 -binary |
xxd -p -c 80 |
bigEndianHex2littleEndianHex
}

And then with the following data from the current block:

ver=1
prev_block=0000000000000000000000000000000000000000000000000000000000000000
mrkl_root=4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
bits=486604799

(this is the genesis "data")

You can create a next block by searching a nonce like this:

Code:
nonce=0

while
        time=$(date +%s)
        printf "%08x%08x%08x%064s%064s%08x" $nonce $bits $time $mrkl_root $prev_block $ver |
        bitcoinHash |
        grep "some test I don't know exactly"
do nonce=$(bc <<< "nonce + 1")
done

of course a lot is missing, especially the network part.


gigabytecoin (OP)
Sr. Member
****
Offline Offline

Activity: 280
Merit: 252


View Profile
March 16, 2011, 02:22:53 AM
 #3

Thanks for that grondilu, do you have the link to your original post on hand?

Is the "networking part" that's missing simply grabbing the next block "todo" from the network?

That is the part I am having trouble with mentally, is where/whom do I contact to download the block chain?
Cryptoman
Hero Member
*****
Offline Offline

Activity: 726
Merit: 500



View Profile
March 16, 2011, 02:25:09 AM
 #4

A full shell script implementation of bitcoin: http://bitcointalk.org/index.php?topic=2461.0

"A small body of determined spirits fired by an unquenchable faith in their mission can alter the course of history." --Gandhi
gigabytecoin (OP)
Sr. Member
****
Offline Offline

Activity: 280
Merit: 252


View Profile
March 16, 2011, 04:24:37 AM
 #5

Thanks Cryptoman! You've been quite a help to me today  Shocked
Viceroy
Hero Member
*****
Offline Offline

Activity: 924
Merit: 501


View Profile
April 25, 2013, 06:55:29 PM
Last edit: April 25, 2013, 07:10:56 PM by Viceroy
 #6

Same question for litecoin.  

Has Anyone written pseudocode for mining litecoin?


Or willing to sell me an RTL for the same?    :-)

Here:
https://bitcointalk.org/index.php?topic=187667.0
Remember remember the 5th of November
Legendary
*
Offline Offline

Activity: 1862
Merit: 1011

Reverse engineer from time to time


View Profile
April 25, 2013, 07:04:50 PM
 #7

Hashing for blocks is done in two ways. Either learning the SHA256 algorithm and make use of the midstate to speed up computation, or something along those lines OR read the article on the block hashing algorithm which is basically doublesha256 of the block header, nothing too complex.

You can see the relevant code here from the genesis block generator I wrote https://bitcointalk.org/index.php?topic=181981.0


BTC:1AiCRMxgf1ptVQwx6hDuKMu4f7F27QmJC2
Pages: [1]
  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!