Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: the demon malloc on September 26, 2017, 07:41:30 PM



Title: What are these variables in the Genesis Block and how were they determined?
Post by: the demon malloc on September 26, 2017, 07:41:30 PM
Hi all!

I'm currently writing a program to generate a genesis block for a new altcoin fork that I'm coding for fun. So far I've identified a couple of sources that I've been working from, notably Gnaf's GenesisBlockZero (http://github.com/Gnaf/GenesisBlockZero/blob/master/genesisblock.c) and of course the original v8 Bitcoin source.

However I'm stuck at figuring out what the scripSig and scriptPubKey represent in the genesis block and how they are determined. These can be found on lines 2779 and 2781 on the main.cpp code here:

https://github.com/bitcoin/bitcoin/blob/0.8/src/main.cpp

I'll paste them here for convenience:

 txNew.vin[0].scriptSig = CScript() << 486604799 << CBigNum(4) << vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));

 txNew.vout[0].scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3 8c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;

Could anyone help me out in figuring out what the numbers in the first one mean. And for the second one, where is that hash from??

Thanks for your time.


Title: Re: What are these variables in the Genesis Block and how were they determined?
Post by: achow101 on September 26, 2017, 08:23:57 PM
First of all, please do not use or refer to the Bitcoin Core 0.8 codebase. It is extremely outdated and insecure.

Could anyone help me out in figuring out what the numbers in the first one mean.
It is just making a script to put in the scriptSig of the only transaction in the genesis block. The stuff in the script mean nothing and have no consensus meaning except for the fact that they must be there otherwise the genesis block's hash will not match what it is supposed to be.
Code:
 << 486604799 
Push this number to the scriptSig. It just happens to be the decimal version of the nBits of the genesis block.

Code:
<< CBigNum(4) 
Push the number 4 to the scriptSig.

Code:
<< vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
Push the character array pszTimestamp to the scriptSig. This character array is just the string of "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks"

And for the second one, where is that hash from??
That is not a hash. That is a public key. It is a normal Pay to Public Key output.



The forum is doing something weird with the code blocks here.


Title: Re: What are these variables in the Genesis Block and how were they determined?
Post by: DannyHamilton on September 26, 2017, 08:35:26 PM
EDIT:  Looks like achow101 was able to type up a response faster than me.  Since I already went to all the trouble to type this up, I'll just leave this here anyhow.

pszTimestamp is just arbitrary text.  Satoshi chose to use a headline from a newspaper to prove that the blockchain did not start any earlier than the date that newspaper was published.  Specifically, the value is:
Quote
The Times 03/Jan/2009 Chancellor on brink of second bailout for banks

You can see that in the code here:
https://github.com/bitcoin/bitcoin/blob/0.8/src/main.cpp#L2775


486604799 is a decimal representation of the difficulty target that was used.

486604799 in hex is 1D00FFFF and you can see that difficulty target being set here:
https://github.com/bitcoin/bitcoin/blob/0.8/src/main.cpp#L2788

The second one is not a hash.  It is an ECDSA public key. Specifically, it is one of Satoshi's public keys.
The generation transaction of the genesis block (and many blocks after that) do not use bitcoin addresses or P2PKH scripts.  They use P2PK scripts.  This requires 2 pieces of information, the public key and an OP_CHECKSIG op code.