Bitcoin Forum
September 29, 2023, 10:12:02 AM *
News: Latest Bitcoin Core release: 25.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How is the genesis block made?  (Read 4024 times)
Remember remember the 5th of November (OP)
Legendary
*
Offline Offline

Activity: 1862
Merit: 1007

Reverse engineer from time to time


View Profile
April 09, 2013, 02:30:23 PM
Merited by vapourminer (2)
 #1

I asked on IRC, tried to understand it as much as I could, but again I got even more confused. But this is what I think it should be.

In main.cpp we have this piece of code
Code:
        const char* pszTimestamp = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";
        CTransaction txNew;
        txNew.vin.resize(1);
        txNew.vout.resize(1);
        txNew.vin[0].scriptSig = CScript() << 486604799 << CBigNum(4) << vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
        txNew.vout[0].nValue = 50 * COIN;
        txNew.vout[0].scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
        CBlock block;
        block.vtx.push_back(txNew);
        block.hashPrevBlock = 0;
        block.hashMerkleRoot = block.BuildMerkleTree();
        block.nVersion = 1;
        block.nTime    = 1231006505;
        block.nBits    = 0x1d00ffff;
        block.nNonce   = 2083236893;

But I believe that when satoshi was creating the genesis block, it likely looked like this

Code:
        const char* pszTimestamp = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";
        CTransaction txNew;
        txNew.vin.resize(1);
        txNew.vout.resize(1);
        txNew.vin[0].scriptSig = CScript() << 486604799 << CBigNum(4) << vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp)); //not sure what << 486604799 << CBigNum(4) would mean
        txNew.vout[0].nValue = 50 * COIN;
        txNew.vout[0].scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG; //ECDSA keypair and the public key pasted here, easy to do
        CBlock block;
        block.vtx.push_back(txNew);
        block.hashPrevBlock = 0;
        block.hashMerkleRoot = block.BuildMerkleTree();
        block.nVersion = 1;
        block.nTime    = 0; //updated later
        block.nBits    = 0; //updated later
        block.nNonce   = 0; //updated later

So he compiled Bitcoin with that piece of code and hashed that(uint256 hash = block.GetHash(); ) "coinbase transaction" I believe it's called, to create a block that would act as the first block in the chain, which he started hashing to finally obtain the REAL genesis block

which is this

Quote
000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f


He then recorded nonce,nbits,ntime of this hash and subsequently updated the code to be

Code:
        const char* pszTimestamp = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";
        CTransaction txNew;
        txNew.vin.resize(1);
        txNew.vout.resize(1);
        txNew.vin[0].scriptSig = CScript() << 486604799 << CBigNum(4) << vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
        txNew.vout[0].nValue = 50 * COIN;
        txNew.vout[0].scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
        CBlock block;
        block.vtx.push_back(txNew);
        block.hashPrevBlock = 0;
        block.hashMerkleRoot = block.BuildMerkleTree();
        block.nVersion = 1;
        block.nTime    = 1231006505;
        block.nBits    = 0x1d00ffff;
        block.nNonce   = 2083236893;

and recompiled Bitcoin once more and basically started the network.

Am I correct in this?

BTC:1AiCRMxgf1ptVQwx6hDuKMu4f7F27QmJC2
1695982322
Hero Member
*
Offline Offline

Posts: 1695982322

View Profile Personal Message (Offline)

Ignore
1695982322
Reply with quote  #2

1695982322
Report to moderator
Bitcoin mining is now a specialized and very risky industry, just like gold mining. Amateur miners are unlikely to make much money, and may even lose money. Bitcoin is much more than just mining, though!
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
bb113
Hero Member
*****
Offline Offline

Activity: 728
Merit: 500


View Profile
April 10, 2013, 10:56:42 PM
Last edit: April 10, 2013, 11:21:57 PM by bb113
 #2

Not sure why no one is answering, you can try the altcoin board. They would be familiar with this process I would think.
maaku
Legendary
*
expert
Offline Offline

Activity: 905
Merit: 1011


View Profile
April 10, 2013, 11:21:20 PM
Merited by vapourminer (2)
 #3

You may find this helpful:

https://github.com/freicoin/freicoin/blob/master/share/find_genesis_block.py

I'm an independent developer working on bitcoin-core, making my living off community donations.
If you like my work, please consider donating yourself: 13snZ4ZyCzaL7358SmgvHGC9AxskqumNxP
Remember remember the 5th of November (OP)
Legendary
*
Offline Offline

Activity: 1862
Merit: 1007

Reverse engineer from time to time


View Profile
April 10, 2013, 11:44:50 PM
 #4

Doesn't answer where and how that merkle root was made from. Otherwise nice find, thanks Smiley

BTC:1AiCRMxgf1ptVQwx6hDuKMu4f7F27QmJC2
maaku
Legendary
*
expert
Offline Offline

Activity: 905
Merit: 1011


View Profile
April 11, 2013, 04:20:24 AM
 #5

The genesis merkle root is output in debug.log. It's calculated in this line:

Code:
block.hashMerkleRoot = block.BuildMerkleTree();

I wrote that Python script I linked to. Ask me if you have any questions.

I'm an independent developer working on bitcoin-core, making my living off community donations.
If you like my work, please consider donating yourself: 13snZ4ZyCzaL7358SmgvHGC9AxskqumNxP
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!