Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: BlackHatCoiner on April 07, 2021, 08:16:18 AM



Title: Why is it necessary to mine the genesis block?
Post by: BlackHatCoiner on April 07, 2021, 08:16:18 AM
On my way to fork Bitcoin Core, I had to either set the nMaxTipAge = DEFAULT_MAX_TIP_AGE * 10000 in validation.cpp (to avoid any gap troubles) or change the genesis block. I tried the first option, but now I want to change the genesis block and I have this query.

Why do I have to mine the genesis block? A forum member had posted an announcement thread of his project ([ANN] Genesis Block Generator (https://bitcointalk.org/index.php?topic=181981.40)), but it is described that you'll have to mine the genesis block.

Isn't mining necessary only when we want to proof a work? There's no proof of work on the genesis block, only the initial conditions to start the chain.


Title: Re: Why is it necessary to mine the genesis block?
Post by: ranochigo on April 07, 2021, 01:44:15 PM
The genesis block is still a valid block and thus still have a valid PoW. The difficulty has to be at a minimum of 1 or a target of 0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff.


Title: Re: Why is it necessary to mine the genesis block?
Post by: Rizzrack on April 07, 2021, 01:53:06 PM
As far as I know you don't mine the genesis block, you hardcode it.


Title: Re: Why is it necessary to mine the genesis block?
Post by: BlackHatCoiner on April 07, 2021, 01:54:04 PM
The genesis block is still a valid block and thus still have a valid PoW.
What do you mean by saying "valid"? How is a valid block defined? Every other block requires PoW to ensure that the majority of the computational power goes to the current chain to prevent double-spending. Why should the genesis require that?

What exactly do you prove once you mine a genesis block? That you can achieve it with a certain target? As I said, you'd do that after to maintain the longest chain. What difference would it make if Satoshi had picked the first hash with nonce=1? There's nothing to be proved in the genesis block.


Title: Re: Why is it necessary to mine the genesis block?
Post by: ranochigo on April 07, 2021, 02:10:03 PM
What do you mean by saying "valid"? How is a valid block defined? Every other block requires PoW to ensure that the majority of the computational power goes to the current chain and to prevent double-spending.
A valid block has to have at least a target above the minimum value as stated or a difficulty of 1. If it has zero difficulty, it is invalid.  

What exactly do you prove once you mine a genesis block? That you can achieve it with difficulty=1? As I said, you'd do that after to maintain the longest chain. What difference would it make if Satoshi had picked the first hash with nonce=1? There's nothing to be proved in the genesis block.
Probably nothing. I'm not sure whether Core skips the checks for a valid block when it comes to the genesis block. I'm not too familiar with the codes for Bitcoin Core but I'm pretty sure I've read somewhere that the genesis block still has to have sufficient PoW and was validated as per normal for at least in the first few release. Perhaps someone can add on to this.


Title: Re: Why is it necessary to mine the genesis block?
Post by: j2002ba2 on April 07, 2021, 03:31:12 PM

What exactly do you prove once you mine a genesis block? That you can achieve it with a certain target? As I said, you'd do that after to maintain the longest chain. What difference would it make if Satoshi had picked the first hash with nonce=1? There's nothing to be proved in the genesis block.


The genesis block was likely mined with difficulty 4000. This makes it hard to mess up the beginning of the chain, giving a head start of a week for bitcoin.

Nowdays mining with difficulty one is easy, just do it on a GPU. It should take about a second or less.



Title: Re: Why is it necessary to mine the genesis block?
Post by: NotATether on April 07, 2021, 04:09:04 PM
What exactly do you prove once you mine a genesis block? That you can achieve it with difficulty=1? As I said, you'd do that after to maintain the longest chain. What difference would it make if Satoshi had picked the first hash with nonce=1? There's nothing to be proved in the genesis block.
Probably nothing. I'm not sure whether Core skips the checks for a valid block when it comes to the genesis block. I'm not too familiar with the codes for Bitcoin Core but I'm pretty sure I've read somewhere that the genesis block still has to have sufficient PoW and was validated as per normal for at least in the first few release. Perhaps someone can add on to this.

It really does skip the validation checks for genesis block, at least for mainnet and signet, and I'm sure that's how testnet works too. mainnet (https://github.com/bitcoin/bitcoin/blob/41a8d2b96ff5cbc2efa9b0996f30228d0a625fdb/src/validation.cpp#L1970) signet (https://github.com/bitcoin/bitcoin/blob/a9d1b40d53ec417eefbe767aa66701ef8e1801d5/src/signet.cpp#L126)



Why do I have to mine the genesis block? A forum member had posted an announcement thread of his project ([ANN] Genesis Block Generator (https://bitcointalk.org/index.php?topic=181981.40)), but it is described that you'll have to mine the genesis block.

You only have to do that if your blockchain is empty (like his), like Satoshi did in the early days.


Title: Re: Why is it necessary to mine the genesis block?
Post by: ranochigo on April 07, 2021, 04:19:43 PM
It really does skip the validation checks for genesis block, at least for mainnet and signet, and I'm sure that's how testnet works too. mainnet (https://github.com/bitcoin/bitcoin/blob/41a8d2b96ff5cbc2efa9b0996f30228d0a625fdb/src/validation.cpp#L1970) signet (https://github.com/bitcoin/bitcoin/blob/a9d1b40d53ec417eefbe767aa66701ef8e1801d5/src/signet.cpp#L126)
Yeah. In the earlier versions, the validation logic doesn't exclude the genesis block or at least that is my understanding of the code.

Do review the codes and let me know if I'm missing something.


Title: Re: Why is it necessary to mine the genesis block?
Post by: BrewMaster on April 07, 2021, 04:25:03 PM
the real answer is that you don't have to do anything, bitcoin's genesis block is defined this way that Satoshi decided to also mine that block too so that block zero also has a valid proof of work. otherwise if you are changing stuff you can also change this little detail so that the software uses an arbitrary block 0 with no proof of work.
there is also no reason to validate block 0 proof of work.


Title: Re: Why is it necessary to mine the genesis block?
Post by: odolvlobo on April 07, 2021, 07:30:32 PM
Why do I have to mine the genesis block?...
Isn't mining necessary only when we want to proof a work? There's no proof of work on the genesis block, only the initial conditions to start the chain.

You can make exceptions for certain blocks, but it is better if you don't.


Title: Re: Why is it necessary to mine the genesis block?
Post by: BlackHatCoiner on April 08, 2021, 04:40:13 PM
You only have to do that if your blockchain is empty (like his), like Satoshi did in the early days.
What difference would it make if it wasn't empty? I'm forking Bitcoin Core and I'm wondering if I can just enter a random hash, since you wrote that it doesn't check it. Also, by the way if you know it, where's the function that performs SHA256 to the genesis conditions and returns the hash?

bitcoin's genesis block is defined this way that Satoshi decided to also mine that block too so that block zero also has a valid proof of work.
And I'm asking again:  What do you mean by saying "valid"? A proof of work is proof only if it's necessary. For example finding hash that doesn't exceed a certain target. Is your proof of work valid if you don't find such hash? You may have worked, but not enough to "prove" something. Satoshi worked, but there wasn't any purpose to do so. There wasn't something to be proved and thus, it's wrong to say that he mined the genesis block.

You can make exceptions for certain blocks, but it is better if you don't.
If you're referring to Bitcoin, it does have an exception. The output of block 0 can't be spent.


Title: Re: Why is it necessary to mine the genesis block?
Post by: BrewMaster on April 08, 2021, 05:19:08 PM
bitcoin's genesis block is defined this way that Satoshi decided to also mine that block too so that block zero also has a valid proof of work.
And I'm asking again:  What do you mean by saying "valid"?
valid means when you compute the hash of genesis block the result is indeed lower than the target (which is minimum value for block 0).

Quote
A proof of work is proof only if it's necessary.
proof of work is just proof that you have worked!
meaning by publishing the nonce (and the combination that is the header) you prove that you have actually performed some work to find that combination so that the hash of it is lower than the target. it is not possible to guess such a combination.

Quote
For example finding hash that doesn't exceed a certain target. Is your proof of work valid if you don't find such hash?
you won't have any proof if the hash is not lower than the target, it might as well be an arbitrary hash.

Quote
Satoshi worked, but there wasn't any purpose to do so. There wasn't something to be proved and thus, it's wrong to say that he mined the genesis block.
that's a different question. Satoshi probably mined genesis block because it is still a valid bitcoin block and he also had enough time to mine it since there was no competition or anything like that.


Title: Re: Why is it necessary to mine the genesis block?
Post by: ranochigo on April 08, 2021, 06:00:35 PM
And I'm asking again:  What do you mean by saying "valid"? A proof of work is proof only if it's necessary. For example finding hash that doesn't exceed a certain target. Is your proof of work valid if you don't find such hash? You may have worked, but not enough to "prove" something. Satoshi worked, but there wasn't any purpose to do so. There wasn't something to be proved and thus, it's wrong to say that he mined the genesis block.
I think I have touched on the validity of a block above?

Proof of work is a concept that proves that someone has expended resources in exchange for finding a hash that meets a target. Satoshi's genesis block proves exactly this and I'm sure he didn't get it by chance.

You really don't have to make the genesis block valid, it is after all just something for your subsequent blocks to reference. You can test it out and construct it without meeting the target but I'm not sure whether it would fail with any validation or not.  There is really no issues as long as you can exclude it from any (if any) PoW checks.


Title: Re: Why is it necessary to mine the genesis block?
Post by: vjudeu on April 09, 2021, 07:05:24 AM
It is necessary to prevent Genesis Block overwriting. Satoshi timestamped Genesis Block with the NY Times message to prove that this block was not mined earlier. In old versions, Genesis Block was not any special case in code. You just started from zero hash and built on top of it. But then, everyone could overwrite the whole chain, including the Genesis Block. And later, Satoshi hardcoded Genesis Block data in the client to prevent that kind of attack. But he forgot about adding that transaction to the database, so it became unspendable.

So, you can start with no Genesis Block at all, just build on top of zero hash and you will get simpler code. But then, overwriting all blocks will be possible, including the first block in the chain.


Title: Re: Why is it necessary to mine the genesis block?
Post by: pooya87 on April 09, 2021, 07:24:41 AM
But then, everyone could overwrite the whole chain, including the Genesis Block.
To "overwrite" the whole chain, one requires the majority hashrate (51% attack) so that they can build a chain that can be longest. With or without a hardcoded genesist block, this attack is always possible as long as one can acquire that much of the hashrate.


Title: Re: Why is it necessary to mine the genesis block?
Post by: vjudeu on April 09, 2021, 10:24:12 AM
Yes, but if you can overwrite the Genesis Block, then you can start the whole chain earlier. So, for example, instead of starting from 2009-01-03, you could start from 1970-01-01. And then, you could pretend that the whole chain existed earlier. So, this block was hardcoded to prevent pretending that Bitcoin was invented before by someone else than Satoshi.


Title: Re: Why is it necessary to mine the genesis block?
Post by: ranochigo on April 09, 2021, 10:43:58 AM
Yes, but if you can overwrite the Genesis Block, then you can start the whole chain earlier. So, for example, instead of starting from 2009-01-03, you could start from 1970-01-01. And then, you could pretend that the whole chain existed earlier. So, this block was hardcoded to prevent pretending that Bitcoin was invented before by someone else than Satoshi.
The inclusion of the scriptsig's message was a reference to the article so yes, that is what Satoshi intended; proving that he started the chain no earlier than the date but it has nothing to do with who invented what, and when was it invented. The genesis block is not important, you can just attack by reorganizing everything after the genesis block and it would achieve the same thing. It is definitely better to have a pre-defined starting point for a blockchain though.

Genesis block was hardcoded for the start, if I'm not wrong. Here's the snippet of the code.
Code:
   //
    // Init with genesis block
    //
    if (mapBlockIndex.empty())
    {
        if (!fAllowNew)
            return false;


        // Genesis Block:
        // GetHash()      = 0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
        // hashMerkleRoot = 0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
        // txNew.vin[0].scriptSig     = 486604799 4 0x736B6E616220726F662074756F6C69616220646E6F63657320666F206B6E697262206E6F20726F6C6C65636E61684320393030322F6E614A2F33302073656D695420656854
        // txNew.vout[0].nValue       = 5000000000
        // txNew.vout[0].scriptPubKey = 0x5F1DF16B2B704C8A578D0BBAF74D385CDE12C11EE50455F3C438EF4C3FBCF649B6DE611FEAE06279A60939E028A8D65C10B73071A6F16719274855FEB0FD8A6704 OP_CHECKSIG
        // block.nVersion = 1
        // block.nTime    = 1231006505
        // block.nBits    = 0x1d00ffff
        // block.nNonce   = 2083236893
        // CBlock(hash=000000000019d6, ver=1, hashPrevBlock=00000000000000, hashMerkleRoot=4a5e1e, nTime=1231006505, nBits=1d00ffff, nNonce=2083236893, vtx=1)
        //   CTransaction(hash=4a5e1e, ver=1, vin.size=1, vout.size=1, nLockTime=0)
        //     CTxIn(COutPoint(000000, -1), coinbase 04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73)
        //     CTxOut(nValue=50.00000000, scriptPubKey=0x5F1DF16B2B704C8A578D0B)
        //   vMerkleTree: 4a5e1e

        // Genesis block
        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>((unsigned char*)pszTimestamp, (unsigned char*)pszTimestamp + strlen(pszTimestamp));
        txNew.vout[0].nValue       = 50 * COIN;
        txNew.vout[0].scriptPubKey = CScript() << CBigNum("0x5F1DF16B2B704C8A578D0BBAF74D385CDE12C11EE50455F3C438EF4C3FBCF649B6DE611FEAE06279A60939E028A8D65C10B73071A6F16719274855FEB0FD8A6704") << 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;


Title: Re: Why is it necessary to mine the genesis block?
Post by: pooya87 on April 10, 2021, 03:37:00 AM
Yes, but if you can overwrite the Genesis Block, then you can start the whole chain earlier. So, for example, instead of starting from 2009-01-03, you could start from 1970-01-01. And then, you could pretend that the whole chain existed earlier. So, this block was hardcoded to prevent pretending that Bitcoin was invented before by someone else than Satoshi.
You keep saying "overwrite" but the bitcoin blockchain is immutable and not a single block can change specially when they are deep. It doesn't matter what the "text" in signature script of a block says, you still have to mine n+1 blocks when the main chain has n blocks to be able to overwrite any of the blocks.

The only purpose that this text serves is that it proves that "Satoshi" didn't mine genesis block in 1970-01-01!


Title: Re: Why is it necessary to mine the genesis block?
Post by: vjudeu on April 10, 2021, 05:53:32 AM
Yes, today the chain is strong and overwriting it is hard. But at the beginning, nothing protected the network from overwriting blocks, even Satoshi mentioned that "The software is still alpha and experimental. There's no guarantee the system's state won't have to be restarted at some point if it becomes necessary, although I've done everything I can to build in extensibility and versioning". Of course in early versions, the longest chain was counted as "valid", but later it was changed to the "heaviest" chain. So, Satoshi always wanted to define "Bitcoin" as "the chain with the most Proof of Work". And in case of disagreement, the Genesis Block with the most proof of work would be treated as the starting point. So, by mining Genesis Block, overwriting everything is just more difficult.

Also, if more than one person is involved in coin creation, then it is possible to use Proof of Work to decide which Genesis Block should be used. Just N people can buy the newspaper on selected date (for example today), include message from it, and start running their PCs to mine the Genesis Block with the most Proof of Work. After some time (for example 24 hours), the best block could be selected and hardcoded into mining software.


Title: Re: Why is it necessary to mine the genesis block?
Post by: GameUnits on April 22, 2021, 08:20:41 PM
As far as I know you don't mine the genesis block, you hardcode it.

Exactly, to calculate the genesis hash you need write your own code within your bitcoin clone. It's a bit complicated for beginners ;)
Cheers


Title: Re: Why is it necessary to mine the genesis block?
Post by: pooya87 on April 23, 2021, 03:12:04 AM
As far as I know you don't mine the genesis block, you hardcode it.

Exactly, to calculate the genesis hash you need write your own code within your bitcoin clone. It's a bit complicated for beginners ;)
Cheers
It is only complicated for those who have no idea how bitcoin and specifically blocks and mining them works. Otherwise the only difference between Genesis block and any other block is that Genesis block's previous block hash is empty! Everything else is the same.


Title: Re: Why is it necessary to mine the genesis block?
Post by: GameUnits on April 23, 2021, 05:29:24 PM
As far as I know you don't mine the genesis block, you hardcode it.

Exactly, to calculate the genesis hash you need write your own code within your bitcoin clone. It's a bit complicated for beginners ;)
Cheers
It is only complicated for those who have no idea how bitcoin and specifically blocks and mining them works. Otherwise the only difference between Genesis block and any other block is that Genesis block's previous block hash is empty! Everything else is the same.

Need to be say, that its the first block. Without it the new chain wouldnt start and it would connect to the chain, which was used or forked from the source before. Indeed its a difference to the original genesis block which was mined before, but not to the following block yes. Normaly the developers calculate it on their own without getting it listed in a code block.


Title: Re: Why is it necessary to mine the genesis block?
Post by: zeuner on May 06, 2021, 10:01:43 AM
It is necessary to prevent Genesis Block overwriting. Satoshi timestamped Genesis Block with the NY Times message to prove that this block was not mined earlier. In old versions, Genesis Block was not any special case in code. You just started from zero hash and built on top of it. But then, everyone could overwrite the whole chain, including the Genesis Block. And later, Satoshi hardcoded Genesis Block data in the client to prevent that kind of attack. But he forgot about adding that transaction to the database, so it became unspendable.

So, you can start with no Genesis Block at all, just build on top of zero hash and you will get simpler code. But then, overwriting all blocks will be possible, including the first block in the chain.

With a new blockchain started in 2021, even if the genesis block is precomputed with a non-zero difficulty, it may still be feasible for someone with considerable mining power to just compute the first X blocks again and replace the block history, if the incentive for doing so is large enough. So, I doubt that the risk of overwriting blocks can be fully eliminated just by having a precomputed genesis block. It may be a part of an effective strategy, though.


Title: Re: Why is it necessary to mine the genesis block?
Post by: NotATether on May 06, 2021, 04:40:46 PM
And later, Satoshi hardcoded Genesis Block data in the client to prevent that kind of attack. But he forgot about adding that transaction to the database, so it became unspendable.

So, I assume that devs can't hardcode this transaction into the client right now without performing a hardfork?


Title: Re: Why is it necessary to mine the genesis block?
Post by: odolvlobo on May 06, 2021, 05:33:51 PM
With a new blockchain started in 2021, even if the genesis block is precomputed with a non-zero difficulty, it may still be feasible for someone with considerable mining power to just compute the first X blocks again and replace the block history...

Not quite. Mining the first 32000 blocks (difficulty 1) would take a little more than 1 second with a S19 pro; however, you still would need 51% to replace all of the blocks.


Title: Re: Why is it necessary to mine the genesis block?
Post by: pooya87 on May 07, 2021, 02:46:32 AM
And later, Satoshi hardcoded Genesis Block data in the client to prevent that kind of attack. But he forgot about adding that transaction to the database, so it became unspendable.

So, I assume that devs can't hardcode this transaction into the client right now without performing a hardfork?
That's correct but it is not about "forgetting", Satoshi may have intentionally avoided adding that transaction to the UTXO database because the genesis block (i.e. block 0) was technically "premined" before the client was released a couple of days later whereas block 1 was mined after release.


Title: Re: Why is it necessary to mine the genesis block?
Post by: zeuner on May 08, 2021, 06:51:33 PM
With a new blockchain started in 2021, even if the genesis block is precomputed with a non-zero difficulty, it may still be feasible for someone with considerable mining power to just compute the first X blocks again and replace the block history...

Not quite. Mining the first 32000 blocks (difficulty 1) would take a little more than 1 second with a S19 pro; however, you still would need 51% to replace all of the blocks.

If you started clandestinely mining an alternative chain from the beginning, you needed 101% of the mining power used for the public chain in order to completely replace it. If you started later, you needed even more. But with the insane amounts of mining power professional miners on a large blockchain have, compared with the mining power the average blockchain started by some random developer would likely have, this is not completely out of sight.