Author

Topic: How is the genesis block made? (Read 4050 times)

legendary
Activity: 905
Merit: 1012
April 10, 2013, 11:20:24 PM
#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.
legendary
Activity: 1862
Merit: 1011
Reverse engineer from time to time
April 10, 2013, 06:44:50 PM
#4
Doesn't answer where and how that merkle root was made from. Otherwise nice find, thanks Smiley
legendary
Activity: 905
Merit: 1012
hero member
Activity: 728
Merit: 500
April 10, 2013, 05:56:42 PM
#2
Not sure why no one is answering, you can try the altcoin board. They would be familiar with this process I would think.
legendary
Activity: 1862
Merit: 1011
Reverse engineer from time to time
April 09, 2013, 09:30:23 AM
#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((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((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((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?
Jump to: