Bitcoin Forum
May 25, 2019, 12:16:49 PM *
News: Latest Bitcoin Core release: 0.18.0 [Torrent] (New!)
 
  Home Help Search Login Register More  
  Show Posts
Pages: « 1 2 [3]
41  Alternate cryptocurrencies / Altcoin Discussion / *** Complete Guide on How to Create a New Alt Coin – Update 2018 *** on: April 18, 2018, 04:13:45 PM
This post is based on https://bitcointalk.org/index.php?topic=225690.0 and is an update to it.

Disclaimer:
I was trying to setup my own private bitcoin network and understand how it works. Thanks to fisheater’s famous post(150k read!)(https://bitcointalk.org/index.php?topic=225690.0) I could get a start. However, it was created in 2013 and I found some of the changes no longer applies today. So I made this post as an update.
I used the same title, but this is not a post to guide how to make new coins or ICOs, just help to study how bitcoin and blockchain works only.
This post does not include making changes to the qt GUI program, only command line programs.
This post is based on bitcoin core code base, not litecoin.

Preparation:
Download the bitcoin core full source code, if you cloned the source tree, make a new branch to work on. Setup the compiling environment and make a successful build.

Design the coin’s parameters:
Refer to fisheater’s post.

Code change:
1. Name substitution
You could run a search in the whole tree and replace all occurrences of “bitcoin” or “BTC” to your coin name. But this is not important.

2. Network ports
2.1 Change RPC port:
Code:
CBaseChainParams::nRPCPort in chainparamsbase.cpp

2.2 Change deamon port:
Code:
CChainParams::nDefaultPort in chainparams.cpp

3. Message signature
Choose a different message start signature:
Code:
CChainParams::pchMessageStart in chainparams.cpp

pchMessageStart[0] = 0xf0;
pchMessageStart[1] = 0xb0;
pchMessageStart[2] = 0xb0;
pchMessageStart[3] = 0xd0;
This is important, without this change, if you accidentally connect your node to the bitcoin network, it will decide that bitcoin’s chain is longer and starting to download the real bitcoin blocks hence override your coin’s blocks.

4. Address prefixes:
Choose your preferred address prefix letter. Refer to the table in https://en.bitcoin.it/wiki/List_of_address_prefixes, for example, if you want address start with ‘X’, use 75 or 76.
Code:
CChainParams::base58Prefixes in chainparams.cpp.

base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,75);

You can also choose prefixes of segwit address, private keys, and extended keys.

5. Block reward
This decide how many coins are generated for each mined blocks.
Code:
in validation.cpp:

CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
{
    int halvings = nHeight / consensusParams.nSubsidyHalvingInterval;
    // Force block reward to zero when right shift is undefined.
    if (halvings >= 64)
        return 0;

    CAmount nSubsidy =  (1 << 10) * COIN;  // Initial block reward 1024 coins
    // Subsidy is cut in half every 210,000 blocks which will occur approximately every 4 years.
    nSubsidy >>= halvings;
    return nSubsidy;
}

6. Coinbase maturity
This decide how many blocks after could the generated coins be spent.
Code:
in consensus/consensus.h:
static const int COINBASE_MATURITY = 100;

7. Halving interval
How many blocks will block reward be halved.
Code:
CChainParams::nSubsidyHalvingInternal in chainparams.cpp.

8. Max money
Code:
static const CAmount MAX_MONEY = 21000000 * COIN; in amount.h.
Note this isn’t the total supply of the coins, and modify this value won’t limit the total number of coins can be generated. The total coin is controlled by block reward in GetBlockSubsidy, this is just a value to help run sanity checks.

9. Minimum chain work
This is the minimum chain work required to consider the blockchain is updated. Set this to the minimum value otherwise your coin will not mine. When you have mined some blocks, this can be updated to a larger value.
Code:
In chainparams.cpp:
consensus.nMinimumChainWork = uint256S("0000000000000000000000000000000000000000000000000000000100010001");

10. Remove dns seeds
In chainparams.cpp, remove lines start with “vSeeds.emplace_back”

11. Remove checkpoints
In chainparams.cpp, set checkpointData = { };

12. Generate genesis block
Bitcoin’s block have to satisfy certain difficulty, so you cannot just modify genesis parameters and use that arbitrary block hash, you have to mine the genesis block.
12.1 Generate a private key and get its public key, e.g.
Code:
048E794284AD7E4D776919BDA05CDD38447D89B436BDAF5F65EBE9D7AD3A0B084908B88162BB60B1AA5ED6542063A30FC9584A335F656A54CD9F66D6C742B67F55
12.2 Choose a genesis message, like a New York Times headline
NY Times 07/Apr/2018 More Jobs, Faster Growth and Now, the Threat of a Trade War
12.3 Get and compile the genesis block generator from https://github.com/liveblockchain/genesisgen
The program is based on Remember remember the 5th of November’s post  https://bitcointalk.org/index.php?topic=181981.0, with an improvements:
The timestamp string cannot be longer than 91 bytes, since the coinbase transaction’s scriptSig is limited to 100 bytes. Also, when the string is longer than 76 bytes, add OP_PUSHDATA1(0x4c) prefix into the script.
Code:
gcc genesis.c -o genesis -lcrypto
12.4 Feed the data into the program and let it mine the genesis block
Code:
$ ./genesis 048E794284AD7E4D776919BDA05CDD38447D89B436BDAF5F65EBE9D7AD3A0B084908B88162BB60B1AA5ED6542063A30FC9584A335F656A54CD9F66D6C742B67F55 "NY Times 07/Apr/2018 More Jobs, Faster Growth and Now, the Threat of a Trade War" 486604799
nBits: 0x1d00ffff
startNonce: 0
unixtime: 0

Coinbase: 04ffff001d01044c504e592054696d65732030372f4170722f32303138204d6f7265204a6f62732c204661737465722047726f77746820616e64204e6f772c2074686520546872656174206f66206120547261646520576172

PubkeyScript: 41048e794284ad7e4d776919bda05cdd38447d89b436bdaf5f65ebe9d7ad3a0b084908b88162bb60b1aa5ed6542063a30fc9584a335f656a54cd9f66d6c742b67f55ac

Merkle Hash: 63f73f6e72c8355d21b5c198406fde2480acf0263fec63dcbe7f6165d410c2c8
Byteswapped: c8c210d465617fbedc63ec3f26f0ac8024de6f4098c1b5215d35c8726e3ff763
Generating block...
939453 Hashes/s, Nonce 23980758224
Block found!
Hash: 00000000ad913538b8764573d00c3eb4a87723e11d8bd008f9125246c58e0252
Nonce: 2398108787
Unix time: 1524021159
12.5 When it’s done, set the block data in chainparams.cpp
In CMainParams constructor, set the nonce and unittime, block hash and merkle root assertions:
Code:
genesis = CreateGenesisBlock(1524021159, 2398108787, 0x1d00ffff, 1, 50 * COIN);
assert(consensus.hashGenesisBlock == uint256S("0x00000000ad913538b8764573d00c3eb4a87723e11d8bd008f9125246c58e0252"));
assert(genesis.hashMerkleRoot == uint256S("0xc8c210d465617fbedc63ec3f26f0ac8024de6f4098c1b5215d35c8726e3ff763"));
in function static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward), set the timestap string:
Code:
const char* pszTimestamp = "NY Times 07/Apr/2018 More Jobs, Faster Growth and Now, the Threat of a Trade War";
const CScript genesisOutputScript = CScript() << ParseHex("048e794284ad7e4d776919bda05cdd38447d89b436bdaf5f65ebe9d7ad3a0b084908b88162bb60b1aa5ed6542063a30fc9584a335f656a54cd9f66d6c742b67f55") << OP_CHECKSIG;

13. If you do not want to generate your own genesis block, you can just use the original bitcoin genesis block, but update the DEFAULT_MAX_TIP_AGE value to a larger value.
Code:
In validation.cpp:
int64_t nMaxTipAge = DEFAULT_MAX_TIP_AGE * 4000;
DEFAULT_MAX_TIP_AGE is one day, if the gap between the tip block and current time, the node won’t mine new blocks, so set this at least to the time elapsed since the creation of bitcoin in Jan 2009.

Mining
1. Get cpuminer from https://github.com/pooler/cpuminer and build it
2. Start mining
Code:
./minerd --user rpcuser --pass 111111 --url http://127.0.0.1:6332/ --threads 4 --coinbase-addr XQg3PmNxX9oEbxsymqtQHir6dkPpVPTJ6P --coinbase-sig "my test coins" -a sha256d -D
When a block is mined, you will notice bitcoind will log something like this:
Code:
2018-04-18 02:31:52 UpdateTip: new best=00000000fbf2808044cbcf00ddb54988c600f65c0960dcf5143bc0a1ed84da39 height=1 version=0x20000000 log2_work=33.000022 tx=2 date='2018-04-18 02:31:36' progress=0.000000 cache=0.0MiB(1txo)
2018-04-18 02:31:52 CreateNewBlock(): block weight: 764 txs: 0 fees: 0 sigops 400
2018-04-18 02:31:52 AddToWallet 8663f334ca80d55ed41ebaaf313935163d57ba3eead98399a3e0b4a2cf679b81  new

You have now made your own coins. Enjoy!
42  Other / Beginners & Help / Re: cloning bitcoin MAX_MONEY not working on: April 18, 2018, 08:29:13 AM
The MAX_MONEY does not control the money supply, total coins is controlled by the mining process. In bitcoin, you have to change block reward to achieve what you want.

The comment of MAX_MONEY explained it clealy:
Code:
/** No amount larger than this (in satoshi) is valid.                           
 *                                                                             
 * Note that this constant is *not* the total money supply, which in Bitcoin   
 * currently happens to be less than 21,000,000 BTC for various reasons, but   
 * rather a sanity check. As this sanity check is used by consensus-critical   
 * validation code, the exact value of the MAX_MONEY constant is consensus     
 * critical; in unusual circumstances like a(nother) overflow bug that allowed 
 * for the creation of coins out of thin air modification could lead to a fork.
 * */                                                                           
static const CAmount MAX_MONEY = 21000000 * COIN;                               

In fact, the total coins is calculated by block reward and halving intervals.
Code:
in validation.cpp
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
{
    int halvings = nHeight / consensusParams.nSubsidyHalvingInterval;
    // Force block reward to zero when right shift is undefined.
    if (halvings >= 64)
        return 0;

    CAmount nSubsidy = 50 * COIN;
    // Subsidy is cut in half every 210,000 blocks which will occur approximately every 4 years.
    nSubsidy >>= halvings;
    return nSubsidy;
}

For example, if here you only change nSubsidy from 50 to 100, then max money will be close to 42000000. If you also change consensusParams.nSubsidyHalvingInterval, you will need to take it into calculation too.
43  Alternate cryptocurrencies / Altcoin Discussion / Re: [ANN] Genesis Block Generator on: April 18, 2018, 08:16:02 AM
Thanks, it works great for me. I have made small changes to improve it, see https://github.com/liveblockchain/genesisgen

1. Gets invalid result when the timestamp string is longer than 76 bytes, as it has to use `OP_PUSHDATA1(0x4c)` as prefix of the data.

Code:
if (timestamp_len > 76) {
transaction->scriptSig[scriptSig_pos++] = 0x4c;
}

2. Add command line arguments for nonce and unixtime for quick poc test.

Code:
Usage: ./genesis [options] <pubkey> "<timestamp>" <nBits> <startNonce> <unixtime>
$ ./genesis 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks" 486604799 2083236893 1231006505
    nBits: 0x1d00ffff
    startNonce: 2083236893
    unixtime: 1231006505

    Coinbase: 04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73

    PubkeyScript: 4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac

    Merkle Hash: 3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a
    Byteswapped: 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
    Generating block...

    Block found!
    Hash: 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
    Nonce: 2083236893
    Unix time: 1231006505
44  Bitcoin / Bitcoin Technical Support / Re: Network - Calling Blocks on: April 12, 2018, 07:12:17 AM
When a node sends GetBlocks, it includes hashes of its local blocks, so that the peers can find out from which point the sending node is behind, also it does not reply with block data, it replies with hashes of the blocks that the node is missing. When the node receives the hashes, it can request block data from peers with GetData messages.
45  Bitcoin / Development & Technical Discussion / Re: Early stage mining why different address for each blocks mined? on: April 10, 2018, 09:34:07 AM
It was not for safety purpose, but for anonymity.
While bitcoin itself is not anonymous at all (rather pseudonymous), using an address only once increases the anonymity by others not being able to link all of those transactions
until multiple UTXO's (from different addresses) are being spent together.

One of satoshis intentions was to create an partly anonymous digital currency.
Using the same address for every mined block would kind of kill this purpose.


Additionally it can't be said for sure that all of the first blocks have been mined by satoshi.
His miner crashed after 'a few' blocks. Other people were mining in the timeframe of his miner being down.
Wether an address from early mining does belong to satoshi or to other early-early-adpoter can't be told for sure.
 

Ok, so it's the same situation as like one should use a new address for each receiving for privacy.
But what changes now? Because looking at the miner stats, like https://blockchain.info/blocks/BTC.com , https://blockchain.info/blocks/F2Pool , although I didn't check all of their mined blocks, but latest several blocks mined by each are indeed using the same address.
46  Bitcoin / Development & Technical Discussion / Early stage mining why different address for each blocks mined? on: April 10, 2018, 07:40:05 AM
In the early stage of bitcoin, it is said most of the blocks are mined by Satoshi on his laptop, but why each block would use a different addresses for generated coins?
Was it for safety purpose?
47  Bitcoin / Development & Technical Discussion / Re: Why is private key in wallet 214 bytes? on: March 30, 2018, 12:43:48 AM
I see, the 214 bytes is made of version + private key + parameters + public key.
Another question, when the wallet is encrypted, the ckey entry for private keys only contains 48bytes, which is 32 bytes private key + 16 bytes IV, is that right?
Yes

Why the different db store strategy?
For compatibility reasons. Earlier versions of Bitcoin Core (including the original Bitcoin 0.1.0) used OpenSSL to do key operations. When keys were written to disk, they used the OpenSSL format which includes all of this extra data. Later, when key encryption was introduced, it was decided that for encrypted keys we could use a different format (since encrypted keys are already backwards incompatible with earlier versions). So for encrypted private keys, we only store what we need, not the full extra stuff. We could bump the wallet version and change the unencrypted key storage format to just be the private key, but no one has bothered to do that and it really isn't all that important.

Great to know, thanks for answering!
48  Bitcoin / Development & Technical Discussion / Re: Why is private key in wallet 214 bytes? on: March 29, 2018, 07:56:00 AM
Those additional bytes are for the elliptic curve parameters and the full public key. This format is described in http://www.secg.org/sec1-v2.pdf section C.4

I see, the 214 bytes is made of version + private key + parameters + public key.
Another question, when the wallet is encrypted, the ckey entry for private keys only contains 48bytes, which is 32 bytes private key + 16 bytes IV, is that right? Why the different db store strategy?
49  Bitcoin / Development & Technical Discussion / Why is private key in wallet 214 bytes? on: March 28, 2018, 03:43:58 AM
Trying to examine and dump the wallet file, and found out the private key is stored as 214 bytes, rather than 32 bytes, this is true for every key in the file, for example, an raw entry in the wallet file looks like this:

Code:
Key: type prefix + pubkey

key 02004cc49d5e1dd6fdf3148cc4004bcf2c6f715c5b61a39f9cf93d8ea4d161652b

Value: private key + hash

3081d30201010420c481b015db511aaf9729855e94c7ac9f990a664d76c6bb487af5f4aa22aa387ba08185308182020101302c06072a8648ce3d0101022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f300604010004010704210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141020101a12403220002004cc49d5e1dd6fdf3148cc4004bcf2c6f715c5b61a39f9cf93d8ea4d161652b 38ab424074511b183cd10429725ea312bcf5143d6cc71b8041d678ace5a71779

----------------c481b015db511aaf9729855e94c7ac9f990a664d76c6bb487af5f4aa22aa387b
Actual key^^


(gdb) n
672         unsigned int nSize = ReadCompactSize(is);
(gdb)
673         unsigned int i = 0;
(gdb) p nSize
$3 = 214
(gdb) l
668     void Unserialize_impl(Stream& is, std::vector<T, A>& v, const unsigned char&)
669     {
670         // Limit size per read so bogus size value won't cause out of memory
671         v.clear();
672         unsigned int nSize = ReadCompactSize(is);
673         unsigned int i = 0;
674         while (i < nSize)
675         {
676             unsigned int blk = std::min(nSize - i, (unsigned int)(1 + 4999999 / sizeof(T)));
677             v.resize(i + blk);


Stepping into code also verifies it's 214 bytes data. The actual private key is starting at the 9th byte. Why is this? What are the additional 182 bytes for?

50  Bitcoin / Development & Technical Discussion / What is key pool used for? on: March 24, 2018, 08:52:55 AM
In the wallet file, upon the node's first start up, a HD master key is generated and 2000 keys are created, but dumping the wallet file shows there are also 2000 key pools saved in the wallet file too, what are they used for? It looks a key pool is just a public key plus an additional time variable?

51  Economy / Marketplace / Re: Hottest Airdrop & Bounty List on: March 23, 2018, 04:40:55 PM
In our channel we posting Only fresh and hot Airdrop & Bounty List Everyday

Don't miss your opportunity to get goodful crypto for free

Join to our channel - https://t.me/bounty_List

Most airdrops are worthless, there is no free lunch.
52  Bitcoin / Development & Technical Discussion / Re: What are the markers byte in wallet file on: March 22, 2018, 09:20:59 AM
Hi, is this necessary? my understanding is Berkeley DB already keeps track of data item's length internally, for every db get operation, the Dbt return its data as well as the length.

Having took a look sometimes to dbwrapper in Bitcoin Core, I would say it is not absolutely necessary, but it helps for error checking while reading records, especially badly formatted ones (don't forget some parts of wallet/chainstate/whatever db) can be obfuscated/crypted, and having those kind of metadata helps to know if data is valid or not.

That makes sense, thanks for answering!
53  Bitcoin / Development & Technical Discussion / Re: What are the markers byte in wallet file on: March 22, 2018, 07:44:59 AM
So I tried to figure out the content of the wallet file, and a dump shows that each key value is prefixed with a non-printable mark, even when the data item is valid printable strings, what's the purpose of these markers bytes, like
Code:
\07, \09, \0a
etc.
Those aren't marker bytes. They are length prefixes. The specify the length of the following piece of data.

Hi, is this necessary? my understanding is Berkeley DB already keeps track of data item's length internally, for every db get operation, the Dbt return its data as well as the length.
54  Bitcoin / Development & Technical Discussion / What are the markers byte in wallet file on: March 22, 2018, 02:23:01 AM
So I tried to figure out the content of the wallet file, and a dump shows that each key value is prefixed with a non-printable mark, even when the data item is valid printable strings, what's the purpose of these markers bytes, like
Code:
\07, \09, \0a
etc.

$ db_dump -p wallet.dat
...
 \07keymeta!\03\ff \15\06F0\97a\a4F\e2\15\01\b9;U%\97\d7\8c\0b\0b\e4`\bc\96\b2\ee@\db\8eL
 \0a\00\00\00\ca3\91Z\00\00\00\00\0cm/0'/1'/461'j\11Z\e1t%\14\0d\13\0ai8\11^\8dz\e7bC\13
 \07keymeta!\03\ff*r{\de5\e4/\a2_\f6+rIv\db(\92r\ee\dd\ce\18\daC\13\df\85\e3l6H
 \0a\00\00\00\c93\91Z\00\00\00\00\0cm/0'/0'/254'j\11Z\e1t%\14\0d\13\0ai8\11^\8dz\e7bC\13
 \07keymeta!\03\ffD9Y=\8e\0f\a51\95\ecs\98u\9a\da[A\82v\dd=\95\f9\bbf\a5\eby\18\0b9
 \0a\00\00\00\ca3\91Z\00\00\00\00\0cm/0'/1'/594'j\11Z\e1t%\14\0d\13\0ai8\11^\8dz\e7bC\13
 \07keymeta!\03\ffF\b3\c9\81\d4\1btNv\e9\ad\b3%\bbb\14\93\ff\e2}\9a\b4\dc\05\dc\b01\a5\87\ac^
 \0a\00\00\00\c93\91Z\00\00\00\00\0cm/0'/0'/638'j\11Z\e1t%\14\0d\13\0ai8\11^\8dz\e7bC\13
 \07keymeta!\03\ff\80A\e8\ea\c8*\92DU\e5W\fe\b3\e9]Vk2\b3\e4\fep\10\e4i\d5\1f\\\83\\3
 \0a\00\00\00\cb3\91Z\00\00\00\00\0cm/0'/1'/921'j\11Z\e1t%\14\0d\13\0ai8\11^\8dz\e7bC\13
 \07purpose"18V1UjWhRBEq7Kj3cXtLLjh2imd6UPWz9A
 \07receive
 \07purpose"1H1uEWBtsHe4tMzCRqGL6BkZBbu6xfnsmR
 \07receive
 \07purpose"32AvF5Vmnn9zD6VRf1D3vZXFHPuwdgEKqw
 \07receive
 \07purpose"35gnJvBQD424mgH9j2Udu6zoEsSXhzQkky
 \07receive
 \07purpose"3AMa4ZAh6R83sWRKsFvprpXvhzDuZ34yqm
 \07receive
 \07purpose"3M7vPcw9h6KaiRfpNNBRFC6mc918UaW6NF
 \07receive
 \07purpose*bc1qnfqmg4ty3qgft79gk3zgym3w3hqxmznxg9avup
 \07receive
 \07version
 \ac\97\02\00
 \09bestblock
 \ac\97\02\00\00
 \0aminversion
 \9cp\02\00
...
55  Other / Meta / Re: How can I mark favorite? on: March 21, 2018, 01:02:26 PM
You could use the 'watch' feature at the top right or just bookmark the thread in your browser.

Ok, thanks, I used browser to bookmark good threads but am looking for a better way as the bookmarks folder got too big. Smiley
56  Other / Meta / How can I mark favorite? on: March 21, 2018, 12:31:19 PM
Is there any way to mark a thread as favorite, or to save it in a list somehow, so that I can read it later?
Thanks.
57  Alternate cryptocurrencies / Altcoin Discussion / Re: *** Complete Guide on How to Create a New Alt Coin *** on: March 12, 2018, 02:55:02 AM
Thanks for the post, although it's an old post, but it's a good way to learn how bitcoin and blockchain works.
But one thing I don't quite understand why do you create a guide based on Litecoin, wouldn't it be much better if forking directly from Bitcoin? After all Bitcoin is the Mother Of All Coins(MOAC).
Pages: « 1 2 [3]
Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!