Author

Topic: Bitcoin block creation !!?? (Read 321 times)

legendary
Activity: 3122
Merit: 2178
Playgram - The Telegram Casino
February 06, 2019, 05:11:42 PM
#15
@HeRetiK how is it? A header is just an appendage to show what the block is compatible.

I found a bitcoin wiki article on it yesterday but its gone now..
At the bottom of miner cpp it can also be seen that we hash the merkle root:
pblock->hashMerkleRoot

I don't think there's any other reason to do this unless that's what generates the merkle root but if it did it should be called findMerkleRoot.

If you look closely you'll find that hashMerkleRoot is not the only member being set though Smiley


Here you see the components of the block header as mentioned further upthread:

Code:
class CBlockHeader
{
public:
    // header
    int32_t nVersion;
    uint256 hashPrevBlock;
    uint256 hashMerkleRoot;
    uint32_t nTime;
    uint32_t nBits;
    uint32_t nNonce;

...with hashMerkleRoot being only one of various members set during the mining / block building process.


For example you can see the hash of the previous block, timestamp, difficulty target and an initial nonce being set here:

Code:
    // Fill in header
    pblock->hashPrevBlock  = pindexPrev->GetBlockHash();
    UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
    pblock->nBits          = GetNextWorkRequired(pindexPrev, pblock, chainparams.GetConsensus());
    pblock->nNonce         = 0;


And the version being set here:

Code:
pblock->nVersion = ComputeBlockVersion(pindexPrev, chainparams.GetConsensus());


And for good reason: The nonce nNonce is required to give miners a wide range of values that can be tried during the mining process. The target nBits allows the block to be verifiable in itself and seals the current network target within the blockchain. The timestamp nTime is required to calculate the upcoming difficulty change and makes time warp attacks more difficult. The hash of the previous block hashPrevBlock is necessary for ordering and puts the chain in blockchain. And needless to say hashMerkleRoot ensures transaction integrity. Accordingly you want to ensure the integrity of all of these parameters, hence they are hashed as part of the block header.
copper member
Activity: 2856
Merit: 3071
https://bit.ly/387FXHi lightning theory
February 06, 2019, 09:39:14 AM
#14
@HeRetiK how is it? A header is just an appendage to show what the block is compatible.

I found a bitcoin wiki article on it yesterday but its gone now..
At the bottom of miner cpp it can also be seen that we hash the merkle root:
pblock->hashMerkleRoot

I don't think there's any other reason to do this unless that's what generates the merkle root but if it did it should be called findMerkleRoot.
legendary
Activity: 3122
Merit: 2178
Playgram - The Telegram Casino
February 06, 2019, 04:30:07 AM
#13
bits = random Huh                                                                                                                               NO OK
nonce = random Huh                                                                                                                            NO OK

bits is not random, it's the current difficulty target:
https://en.bitcoin.it/wiki/Target

This will stay the same on the next block unless the difficulty changes, which happens every 2016 blocks (ie. roughly every 2 weeks):
https://en.bitcoin.it/wiki/Difficulty

The nonce is the value that miners are searching for when mining a new block (ie. miners are looking for a nonce that leads to a block hash that is below the difficulty target as denoted by the bit field).


Isn't it just the merkle root you hash?

Edit: it's just the merkle root that is hashed!

What do you mean? The block hash is definitely more than just the merkle root.
copper member
Activity: 2856
Merit: 3071
https://bit.ly/387FXHi lightning theory
February 05, 2019, 08:48:02 PM
#12
Isn't it just the merkle root you hash?

Edit: it's just the merkle root that is hashed!

It blocks act as a merkle tree then to get that hash you do a double hash of the txid of the first transaction.
So you hash the hex digest as a sha256(sha256(genesisTxIDHex+genesisTxIDHex)).

If there's an odd number of nodes like in this case, the last node (incidentally the first) must be duplicated.
newbie
Activity: 14
Merit: 1
February 05, 2019, 09:01:45 AM
#11
Code:
from hashlib import sha256
import hashlib
version = "00000020"
previoushash = "823a1913f9e43541545befa600134906819ea60ecfe71e000000000000000000"
merkleroot = "f717f1770bfcf49e72e58f28f1b7c53247a8235933fea24823687655009265ec"
timestamp = "3983595c"
bits = "15683017"
nonce = "f2a164a0"
header = (str(version) + str(previoushash) + str(merkleroot) + str(timestamp) + str(bits) + str(nonce)).decode('hex')
          
print sha256(sha256(header).digest()).digest()[::-1].encode('hex')

for next block

version = "00000020"                                                                                                                              OK
previoushash = "0000000000000000000a93736d47dbfecc769c598931b56a63f2c7547a700229"   inversed                OK
merkle root = sha256(transaction(s))                                                                                                         OK
timestamp = in the future                                                                                                                        OK
bits = random Huh                                                                                                                               NO OK
nonce = random Huh                                                                                                                            NO OK


create new block possible with genesis :
python genesis.py -z "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks" -n 2083236893 -t 1231006505
legendary
Activity: 2352
Merit: 6089
bitcoindata.science
February 05, 2019, 08:46:54 AM
#10
Why algo for next Block ??
And Can we find a block 2 months ago

You can track any block since Genesis block (2009) using any block explorer, such as blockchain.info
Just Go browsing through blocks and look at timestamp to see the date.
newbie
Activity: 14
Merit: 1
February 05, 2019, 08:10:50 AM
#9
Why algo for next Block ??
And Can we find a block 2 months ago
newbie
Activity: 14
Merit: 1
February 04, 2019, 10:38:52 AM
#8
but what is the actual calculation used?
sha256 (number of transactions + nonce + prev bloc)..............................?

It's:
SHA256( SHA256( Version + hashPrevBlock + hashMerkleRoot + Time + Target + Nonce ) )

With the Merkle Root being the set of all transactions reduced to a single a hash:
https://www.mycryptopedia.com/merkle-tree-merkle-root-explained/

The Bitcoin wiki has a good description of what is contained in the block header:
https://en.bitcoin.it/wiki/Block_hashing_algorithm


okok thank you

legendary
Activity: 3122
Merit: 2178
Playgram - The Telegram Casino
February 04, 2019, 10:23:18 AM
#7
but what is the actual calculation used?
sha256 (number of transactions + nonce + prev bloc)..............................?

It's:
SHA256( SHA256( Version + hashPrevBlock + hashMerkleRoot + Time + Target + Nonce ) )

With the Merkle Root being the set of all transactions reduced to a single a hash:
https://www.mycryptopedia.com/merkle-tree-merkle-root-explained/

The Bitcoin wiki has a good description of what is contained in the block header:
https://en.bitcoin.it/wiki/Block_hashing_algorithm
legendary
Activity: 3038
Merit: 4418
Crypto Swap Exchange
February 04, 2019, 09:32:44 AM
#6
sha256(sha256(000000000000000000141653129dd4eb836978acc3c60e10e13ae53788aff716))       

result = next block  Roll Eyes
The result you will get is just a (double) hash of the hash of another block header. This won't yield you anything at all.

You need to hash an actual block header (complete with all of the components of the blocks you are mining) for the block to be valid. The network will obtain the block header and hash it. If it doesn't meet the target, then it would be rejected.
newbie
Activity: 14
Merit: 1
February 04, 2019, 09:02:43 AM
#5
sha256(sha256(000000000000000000141653129dd4eb836978acc3c60e10e13ae53788aff716))       

result = next block  Roll Eyes
legendary
Activity: 3038
Merit: 4418
Crypto Swap Exchange
February 04, 2019, 08:55:42 AM
#4
but what is the actual calculation used?
sha256 (number of transactions + nonce + prev bloc)..............................?
Bitcoin uses SHA256D. The actual hash is just SHA256(SHA256 (Block Header)). The block header consists of the version, nounce, timestamp, merkle root, hash of previous block and target.
newbie
Activity: 14
Merit: 1
February 04, 2019, 08:50:48 AM
#3
but what is the actual calculation used?
sha256 (number of transactions + nonce + prev bloc)..............................?
legendary
Activity: 3038
Merit: 4418
Crypto Swap Exchange
February 04, 2019, 08:16:12 AM
#2
The miner assembles a set of transaction and hashes them. This creates a merkle root which is ultimately included in the block header of the block. With the block header, the hash of the block is obtained by hashing the block header. Only if the hash meets the target of the network, then it would be considered valid.

This doesn't emcompass the whole process but it does roughly cover the idea about how the transactions is used in the block hashing.

The miner has the rights to the number of transactions and which transaction he wishes to include. The least number of transaction is 1 and the maximum is up till the block weight is reached.
newbie
Activity: 14
Merit: 1
February 04, 2019, 08:12:28 AM
#1
Hello someone would know how a bitcoin block is made it is

I know you have to take all the transactions but I don't know what to do with them afterwards.

and can we create a block with the desired number of transactions?

thank you to you
Jump to: